Bug 1287649: Don't hide pageAction when only hash fragment changes. r?aswan draft
authorKris Maglione <maglione.k@gmail.com>
Tue, 26 Jul 2016 17:28:29 -0700
changeset 393079 ac87c1771c010785741af23b9be228e9c0d7b780
parent 393078 462dc6b44adb4573e8ce6b0dd688c206ebd516f7
child 526489 5e036498416262772d20b7a31df72031b489713c
push id24208
push usermaglione.k@gmail.com
push dateWed, 27 Jul 2016 00:28:50 +0000
reviewersaswan
bugs1287649
milestone50.0a1
Bug 1287649: Don't hide pageAction when only hash fragment changes. r?aswan MozReview-Commit-ID: EvufryoPgcs
browser/components/extensions/ext-utils.js
browser/components/extensions/test/browser/browser_ext_pageAction_context.js
--- a/browser/components/extensions/ext-utils.js
+++ b/browser/components/extensions/ext-utils.js
@@ -294,16 +294,17 @@ global.ViewPopup = class ViewPopup exten
 
 // Manages tab-specific context data, and dispatching tab select events
 // across all windows.
 global.TabContext = function TabContext(getDefaults, extension) {
   this.extension = extension;
   this.getDefaults = getDefaults;
 
   this.tabData = new WeakMap();
+  this.lastLocation = new WeakMap();
 
   AllWindowEvents.addListener("progress", this);
   AllWindowEvents.addListener("TabSelect", this);
 
   EventEmitter.decorate(this);
 };
 
 TabContext.prototype = {
@@ -322,22 +323,34 @@ TabContext.prototype = {
   handleEvent(event) {
     if (event.type == "TabSelect") {
       let tab = event.target;
       this.emit("tab-select", tab);
       this.emit("location-change", tab);
     }
   },
 
+  onStateChange(browser, webProgress, request, stateFlags, statusCode) {
+    let flags = Ci.nsIWebProgressListener;
+
+    if (!(~stateFlags & (flags.STATE_IS_WINDOW | flags.STATE_START) ||
+          this.lastLocation.has(browser))) {
+      this.lastLocation.set(browser, request.URI);
+    }
+  },
+
   onLocationChange(browser, webProgress, request, locationURI, flags) {
     let gBrowser = browser.ownerGlobal.gBrowser;
-    if (browser === gBrowser.selectedBrowser) {
+    let lastLocation = this.lastLocation.get(browser);
+    if (browser === gBrowser.selectedBrowser &&
+        !(lastLocation && lastLocation.equalsExceptRef(browser.currentURI))) {
       let tab = gBrowser.getTabForBrowser(browser);
       this.emit("location-change", tab, true);
     }
+    this.lastLocation.set(browser, browser.currentURI);
   },
 
   shutdown() {
     AllWindowEvents.removeListener("progress", this);
     AllWindowEvents.removeListener("TabSelect", this);
   },
 };
 
--- a/browser/components/extensions/test/browser/browser_ext_pageAction_context.js
+++ b/browser/components/extensions/test/browser/browser_ext_pageAction_context.js
@@ -243,16 +243,25 @@ add_task(function* testTabSwitchContext(
             browser.pageAction.setIcon({tabId, path: "2.png"});
             browser.pageAction.setPopup({tabId, popup: "2.html"});
             browser.pageAction.setTitle({tabId, title: "Title 2"});
 
             expect(details[2]);
           });
         },
         expect => {
+          browser.test.log("Change the hash. Expect same properties.");
+
+          promiseTabLoad({id: tabs[1], url: "about:blank?0#ref"}).then(() => {
+            expect(details[2]);
+          });
+
+          browser.tabs.update(tabs[1], {url: "about:blank?0#ref"});
+        },
+        expect => {
           browser.test.log("Clear the title. Expect default title.");
           browser.pageAction.setTitle({tabId: tabs[1], title: ""});
 
           expect(details[3]);
         },
         expect => {
           browser.test.log("Navigate to a new page. Expect icon hidden.");