Bug 1530402 - Emit |location-change| from mobile's TabTracker. r=snorp
☠☠ backed out by 61ebc1a22544 ☠ ☠
authorAgi Sferro <agi@sferro.dev>
Fri, 15 Nov 2019 16:33:55 +0000
changeset 502230 352068fe68bc25e84aa65845acded4c6cf57a5fc
parent 502229 e0ae4f16f7eda0839925ddd8402b926a70c9f898
child 502231 597e32ad2f5b95e47aa1f4e03dff78b1bd0b7b39
push id114172
push userdluca@mozilla.com
push dateTue, 19 Nov 2019 11:31:10 +0000
treeherdermozilla-inbound@b5c5ba07d3db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1530402
milestone72.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1530402 - Emit |location-change| from mobile's TabTracker. r=snorp This matches desktop's TabTracker. Also, remove Tab:Selected which is an event that was coming from Fennec. Differential Revision: https://phabricator.services.mozilla.com/D52252
mobile/android/components/extensions/ext-utils.js
--- a/mobile/android/components/extensions/ext-utils.js
+++ b/mobile/android/components/extensions/ext-utils.js
@@ -399,60 +399,62 @@ class Tab extends TabBase {
   }
 }
 
 // Manages tab-specific context data and dispatches tab select and close events.
 class TabContext extends EventEmitter {
   constructor(getDefaultPrototype) {
     super();
 
+    windowTracker.addListener("progress", this);
+
     this.getDefaultPrototype = getDefaultPrototype;
     this.tabData = new Map();
+  }
 
-    GlobalEventDispatcher.registerListener(this, [
-      "Tab:Selected",
-      "Tab:Closed",
-    ]);
+  onLocationChange(browser, webProgress, request, locationURI, flags) {
+    if (!webProgress.isTopLevel) {
+      // Only pageAction and browserAction are consuming the "location-change" event
+      // to update their per-tab status, and they should only do so in response of
+      // location changes related to the top level frame (See Bug 1493470 for a rationale).
+      return;
+    }
+    const gBrowser = browser.ownerGlobal.gBrowser;
+    const tab = gBrowser.getTabForBrowser(browser);
+    // fromBrowse will be false in case of e.g. a hash change or history.pushState
+    const fromBrowse = !(
+      flags & Ci.nsIWebProgressListener.LOCATION_CHANGE_SAME_DOCUMENT
+    );
+    this.emit(
+      "location-change",
+      {
+        id: tab.id,
+        linkedBrowser: browser,
+        // TODO: we don't support selected so we just alway say we are
+        selected: true,
+      },
+      fromBrowse
+    );
   }
 
   get(tabId) {
     if (!this.tabData.has(tabId)) {
       let data = Object.create(this.getDefaultPrototype(tabId));
       this.tabData.set(tabId, data);
     }
 
     return this.tabData.get(tabId);
   }
 
   clear(tabId) {
     this.tabData.delete(tabId);
   }
 
-  /**
-   * Required by the GlobalEventDispatcher module. This event will get
-   * called whenever one of the registered listeners fires.
-   * @param {string} event The event which fired.
-   * @param {object} data Information about the event which fired.
-   */
-  onEvent(event, data) {
-    switch (event) {
-      case "Tab:Selected":
-        this.emit("tab-selected", data.id);
-        break;
-      case "Tab:Closed":
-        this.emit("tab-closed", data.tabId);
-        break;
-    }
-  }
-
   shutdown() {
-    GlobalEventDispatcher.unregisterListener(this, [
-      "Tab:Selected",
-      "Tab:Closed",
-    ]);
+    windowTracker.removeListener("progress", this);
   }
 }
 
 class Window extends WindowBase {
   get focused() {
     return this.window.document.hasFocus();
   }