@@ -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?
1919function 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." ) ;
@@ -242,32 +242,20 @@ wr.onBeforeSendHeaders.addListener(onBeforeSendHeaders, {urls: ["http://*/*"]},
242242wr . onResponseStarted . addListener ( onResponseStarted ,
243243 { urls : [ "https://*/*" , "http://*/*" ] } ) ;
244244
245- // Add the small HTTPS Everywhere icon in the address bar if any rules apply to this tab.
245+
246+ // Add the small HTTPS Everywhere icon in the address bar.
247+ // Note: We can't use any other hook (onCreated, onActivated, etc.) because Chrome resets the
248+ // pageActions on URL change. We should strongly consider switching from pageAction to browserAction.
246249chrome . tabs . onUpdated . addListener ( function ( tabId , changeInfo , tab ) {
247250 displayPageAction ( tabId ) ;
248251} ) ;
249252
253+ // Pre-rendered tabs / instant experiments sometimes skip onUpdated.
254+ // See http://crbug.com/109557
255+ chrome . tabs . onReplaced . addListener ( function ( addedTabId , removedTabId ) {
256+ displayPageAction ( addedTabId ) ;
257+ } ) ;
258+
250259// Listen for cookies set/updated and secure them if applicable. This function is async/nonblocking,
251260// so we also use onBeforeSendHeaders to prevent a small window where cookies could be stolen.
252261chrome . cookies . onChanged . addListener ( onCookieChanged ) ;
253-
254-
255- // Intermittently call displayPageAction(). chrome.tabs.onUpdated (above) adds the HTTPS Everywhere icon
256- // via displayPageAction to 99.9% of pages. In the /rare/ case where /absolutely no elements/ of a tab have
257- // any applicable rulesets, but the page later loads one (without triggering chrome.tabs.onUpdated), this will
258- // add the HTTPS Everywhere icon.
259- //
260- // In practice, this is incredibly rare. If people don't mind the HTTPS Everywhere icon being always visible in
261- // either the address bar or via pageAction, we could consider having it /always/ visible (it usually is anyway),
262- // or adding a browser_action instead, which would change the UI/UX slightly.
263- function periodically_displayPageAction ( ) {
264- // Get all available active tabs
265- chrome . tabs . query ( { active : true } ,
266- function ( tabs_array ) {
267- // Pass active tabIDs to displayPageAction
268- tabs_array . map ( function ( tab ) { return tab . id } ) . map ( displayPageAction ) ;
269- } ) ;
270- // Call ourself every 10 seconds.
271- setTimeout ( periodically_displayPageAction , 10000 ) ;
272- }
273- periodically_displayPageAction ( ) ;
0 commit comments