Bug 1274919 - part1 : send the msg "Browser:UnselectedTabHover" when the cursor is hovering over or leaving the unselected tab r=mikedeboer
authorAlastor Wu <alwu@mozilla.com>
Thu, 20 Jul 2017 14:13:08 +0800
changeset 418820 0db83e6e2fac5ddc35df68b83583bda33abbce26
parent 418819 571f64d55017da40ee05e0beafdb6bcc4e46fa2a
child 418821 2b788dca1f6081f5abd432b624d078fc8d9464b9
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmikedeboer
bugs1274919
milestone56.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 1274919 - part1 : send the msg "Browser:UnselectedTabHover" when the cursor is hovering over or leaving the unselected tab r=mikedeboer This msg is used to notify the status whether the cursor is hovering over the unselected tab or not. It's used for the media's feature, resuming the background video decoding. MozReview-Commit-ID: GuAyLNdH10c
browser/base/content/tabbrowser.xml
toolkit/content/browser-content.js
toolkit/content/widgets/browser.xml
--- a/browser/base/content/tabbrowser.xml
+++ b/browser/base/content/tabbrowser.xml
@@ -7579,32 +7579,38 @@
             let candidate = visibleTabs[tabIndex + 1];
             if (!candidate.selected) {
               tabContainer._afterHoveredTab = candidate;
               candidate.setAttribute("afterhovered", "true");
             }
           }
 
           tabContainer._hoveredTab = this;
+          if (this.linkedPanel && !this.selected) {
+            this.linkedBrowser.unselectedTabHover(true);
+          }
         ]]></body>
       </method>
 
       <method name="_mouseleave">
         <body><![CDATA[
           let tabContainer = this.parentNode;
           if (tabContainer._beforeHoveredTab) {
             tabContainer._beforeHoveredTab.removeAttribute("beforehovered");
             tabContainer._beforeHoveredTab = null;
           }
           if (tabContainer._afterHoveredTab) {
             tabContainer._afterHoveredTab.removeAttribute("afterhovered");
             tabContainer._afterHoveredTab = null;
           }
 
           tabContainer._hoveredTab = null;
+          if (this.linkedPanel && !this.selected) {
+            this.linkedBrowser.unselectedTabHover(false);
+          }
         ]]></body>
       </method>
 
       <method name="startMediaBlockTimer">
         <body><![CDATA[
           TelemetryStopwatch.start("TAB_MEDIA_BLOCKING_TIME_MS", this);
         ]]></body>
       </method>
--- a/toolkit/content/browser-content.js
+++ b/toolkit/content/browser-content.js
@@ -977,16 +977,20 @@ addMessageListener("WebChannelMessageToC
     } else {
       Cu.reportError("WebChannel message failed. Principal mismatch.");
     }
   } else {
     Cu.reportError("WebChannel message failed. No message data.");
   }
 });
 
+addMessageListener("Browser:UnselectedTabHover", message => {
+  Services.obs.notifyObservers(content.window, "unselected-tab-hover", message.data.hovered);
+});
+
 var AudioPlaybackListener = {
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]),
 
   init() {
     Services.obs.addObserver(this, "audio-playback");
 
     addMessageListener("AudioPlayback", this);
     addEventListener("unload", () => {
--- a/toolkit/content/widgets/browser.xml
+++ b/toolkit/content/widgets/browser.xml
@@ -845,16 +845,27 @@
               let event = document.createEvent("Events");
               event.initEvent("DOMAudioPlaybackBlockStopped", true, false);
               this.dispatchEvent(event);
             }
           ]]>
         </body>
       </method>
 
+      <method name="unselectedTabHover">
+        <parameter name="hovered"/>
+        <body>
+          <![CDATA[
+            // TODO : only dispatch event when someone is waiting for this message
+            this.messageManager.sendAsyncMessage("Browser:UnselectedTabHover",
+              { hovered });
+          ]]>
+        </body>
+      </method>
+
       <property name="securityUI">
         <getter>
           <![CDATA[
             if (!this.docShell.securityUI) {
               const SECUREBROWSERUI_CONTRACTID = "@mozilla.org/secure_browser_ui;1";
               if (!this.hasAttribute("disablesecurity") &&
                   SECUREBROWSERUI_CONTRACTID in Components.classes) {
                 var securityUI = Components.classes[SECUREBROWSERUI_CONTRACTID]