Bug 1287649: Don't hide pageAction when only hash fragment changes. r?aswan
MozReview-Commit-ID: EvufryoPgcs
--- 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.");