Skip to content

Commit 876ed4f

Browse files
committed
Fire pageAction only from tabs.onUpdated/onReplaced
pageAction is responsible for adding the HTTPS Everywhere icon next to the URL bar. We used to display this only on pages w/ applicable rules (almost every page), but that logic was messy and slow. Now we display the icon all the time. This might get called once or twice per-tab, but it's relatively low cost. At least we're no longer calling it multiple times for every request :) Signed-off-by: Nick Semenkovich <semenko@alum.mit.edu>
1 parent c671aa2 commit 876ed4f

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

‎chromium/background.js‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ for (r in rs) {
1414
}
1515
*/
1616

17-
// If a ruleset could apply to a tab, then add the little HTTPS
18-
// Everywhere icon to the address bar.
17+
// Add the HTTPS Everywhere icon to the URL address bar.
18+
// TODO: Switch from pageAction to browserAction?
1919
function displayPageAction(tabId) {
20-
if (tabId !== -1 && this.activeRulesets.getRulesets(tabId)) {
20+
if (tabId !== -1) {
2121
chrome.tabs.get(tabId, function(tab) {
2222
if(typeof(tab) === "undefined") {
2323
log(DBUG, "Not a real tab. Skipping showing pageAction.");
@@ -137,8 +137,6 @@ function onBeforeRequest(details) {
137137
}
138138
}
139139

140-
displayPageAction(details.tabId);
141-
142140
if (newuristr) {
143141
// re-insert userpass info which was stripped temporarily
144142
// while rules were applied
@@ -279,11 +277,20 @@ wr.onHeadersReceived.addListener(onHeadersReceived, {urls: ["https://*/*"]},
279277
wr.onResponseStarted.addListener(onResponseStarted,
280278
{urls: ["https://*/*", "http://*/*"]});
281279

282-
// Add the small HTTPS Everywhere icon in the address bar if any rules apply to this tab.
280+
281+
// Add the small HTTPS Everywhere icon in the address bar.
282+
// Note: We can't use any other hook (onCreated, onActivated, etc.) because Chrome resets the
283+
// pageActions on URL change. We should strongly consider switching from pageAction to browserAction.
283284
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
284285
displayPageAction(tabId);
285286
});
286287

288+
// Pre-rendered tabs / instant experiments sometimes skip onUpdated.
289+
// See http://crbug.com/109557
290+
chrome.tabs.onReplaced.addListener(function(addedTabId, removedTabId) {
291+
displayPageAction(addedTabId);
292+
});
293+
287294
// Listen for cookies set/updated and secure them if applicable. This function is async/nonblocking,
288295
// so we also use onBeforeSendHeaders to prevent a small window where cookies could be stolen.
289296
chrome.cookies.onChanged.addListener(onCookieChanged);

0 commit comments

Comments
 (0)