Bug 1022025, r=bholley,mfinkle, a=sylvestre
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Sat, 14 Jun 2014 22:01:55 +0100
changeset 200586 e0453381c014f4bd63ecc6f4ac231be224c246c2
parent 200585 ebba60c06474de1752493552e5d153095723983c
child 200587 423cd6386bd29a5fe20f975b11917f4726a6f4c2
push id486
push userasasaki@mozilla.com
push dateMon, 14 Jul 2014 18:39:42 +0000
treeherdermozilla-release@d33428174ff1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley, mfinkle, sylvestre
bugs1022025
milestone31.0
Bug 1022025, r=bholley,mfinkle, a=sylvestre
content/html/content/public/HTMLMediaElement.h
content/html/content/src/HTMLMediaElement.cpp
dom/webidl/HTMLMediaElement.webidl
mobile/android/chrome/content/CastingApps.js
toolkit/content/widgets/videocontrols.xml
--- a/content/html/content/public/HTMLMediaElement.h
+++ b/content/html/content/public/HTMLMediaElement.h
@@ -472,16 +472,36 @@ public:
     return mStatsShowing;
   }
 
   void SetMozMediaStatisticsShowing(bool aShow)
   {
     mStatsShowing = aShow;
   }
 
+  bool MozAllowCasting() const
+  {
+    return mAllowCasting;
+  }
+
+  void SetMozAllowCasting(bool aShow)
+  {
+    mAllowCasting = aShow;
+  }
+
+  bool MozIsCasting() const
+  {
+    return mIsCasting;
+  }
+
+  void SetMozIsCasting(bool aShow)
+  {
+    mIsCasting = aShow;
+  }
+
   already_AddRefed<DOMMediaStream> GetMozSrcObject() const;
 
   void SetMozSrcObject(DOMMediaStream& aValue);
 
   bool MozPreservesPitch() const
   {
     return mPreservesPitch;
   }
@@ -1058,16 +1078,24 @@ protected:
   };
 
   uint32_t mMuted;
 
   // True if the media statistics are currently being shown by the builtin
   // video controls
   bool mStatsShowing;
 
+  // The following two fields are here for the private storage of the builtin
+  // video controls, and control 'casting' of the video to external devices
+  // (TVs, projectors etc.)
+  // True if casting is currently allowed
+  bool mAllowCasting;
+  // True if currently casting this video
+  bool mIsCasting;
+
   // True if the sound is being captured.
   bool mAudioCaptured;
 
   // If TRUE then the media element was actively playing before the currently
   // in progress seeking. If FALSE then the media element is either not seeking
   // or was not actively playing before the current seek. Used to decide whether
   // to raise the 'waiting' event as per 4.7.1.8 in HTML 5 specification.
   bool mPlayingBeforeSeek;
--- a/content/html/content/src/HTMLMediaElement.cpp
+++ b/content/html/content/src/HTMLMediaElement.cpp
@@ -1980,16 +1980,18 @@ HTMLMediaElement::HTMLMediaElement(alrea
     mCurrentPlayRangeStart(-1.0),
     mBegun(false),
     mLoadedFirstFrame(false),
     mAutoplaying(true),
     mAutoplayEnabled(true),
     mPaused(true),
     mMuted(0),
     mStatsShowing(false),
+    mAllowCasting(false),
+    mIsCasting(false),
     mAudioCaptured(false),
     mPlayingBeforeSeek(false),
     mPausedForInactiveDocumentOrChannel(false),
     mEventDeliveryPaused(false),
     mWaitingFired(false),
     mIsRunningLoadMethod(false),
     mIsLoadingFromSourceChildren(false),
     mDelayingLoadEvent(false),
--- a/dom/webidl/HTMLMediaElement.webidl
+++ b/dom/webidl/HTMLMediaElement.webidl
@@ -99,16 +99,18 @@ interface HTMLMediaElement : HTMLElement
 // Mozilla extensions:
 partial interface HTMLMediaElement {
   attribute MediaStream? mozSrcObject;
   attribute boolean mozPreservesPitch;
   readonly attribute boolean mozAutoplayEnabled;
 
   // NB: for internal use with the video controls:
   [Func="IsChromeOrXBL"] attribute boolean mozMediaStatisticsShowing;
+  [Func="IsChromeOrXBL"] attribute boolean mozAllowCasting;
+  [Func="IsChromeOrXBL"] attribute boolean mozIsCasting;
 
   // Mozilla extension: stream capture
   [Throws]
   MediaStream mozCaptureStream();
   [Throws]
   MediaStream mozCaptureStreamUntilEnded();
   readonly attribute boolean mozAudioCaptured;
 
--- a/mobile/android/chrome/content/CastingApps.js
+++ b/mobile/android/chrome/content/CastingApps.js
@@ -237,38 +237,36 @@ var CastingApps = {
       let browser = BrowserApp.selectedBrowser;
       if (!browser) {
         return;
       }
 
       // Look for a castable <video> that is playing, and start casting it
       let videos = browser.contentDocument.querySelectorAll("video");
       for (let video of videos) {
-        let unwrappedVideo = XPCNativeWrapper.unwrap(video);
-        if (!video.paused && unwrappedVideo.mozAllowCasting) {
+        if (!video.paused && video.mozAllowCasting) {
           CastingApps.openExternal(video, 0, 0);
           return;
         }
       }
     }
   },
 
   _findCastableVideo: function _findCastableVideo(aBrowser) {
       // Scan for a <video> being actively cast. Also look for a castable <video>
       // on the page.
       let castableVideo = null;
       let videos = aBrowser.contentDocument.querySelectorAll("video");
       for (let video of videos) {
-        let unwrappedVideo = XPCNativeWrapper.unwrap(video);
-        if (unwrappedVideo.mozIsCasting) {
+        if (video.mozIsCasting) {
           // This <video> is cast-active. Break out of loop.
           return video;
         }
 
-        if (!video.paused && unwrappedVideo.mozAllowCasting) {
+        if (!video.paused && video.mozAllowCasting) {
           // This <video> is cast-ready. Keep looking so cast-active could be found.
           castableVideo = video;
         }
       }
 
       // Could be null
       return castableVideo;
   },
@@ -306,25 +304,24 @@ var CastingApps = {
     if (BrowserApp.selectedTab != BrowserApp.getTabForWindow(aVideo.ownerDocument.defaultView.top)) {
       return;
     }
 
     // We check for two state here:
     // 1. The video is actively being cast
     // 2. The video is allowed to be cast and is currently playing
     // Both states have the same action: Show the cast page action
-    let unwrappedVideo = XPCNativeWrapper.unwrap(aVideo);
-    if (unwrappedVideo.mozIsCasting) {
+    if (aVideo.mozIsCasting) {
       this.pageAction.id = NativeWindow.pageactions.add({
         title: Strings.browser.GetStringFromName("contextmenu.castToScreen"),
         icon: "drawable://casting_active",
         clickCallback: this.pageAction.click,
         important: true
       });
-    } else if (unwrappedVideo.mozAllowCasting) {
+    } else if (aVideo.mozAllowCasting) {
       this.pageAction.id = NativeWindow.pageactions.add({
         title: Strings.browser.GetStringFromName("contextmenu.castToScreen"),
         icon: "drawable://casting",
         clickCallback: this.pageAction.click,
         important: true
       });
     }
   },
--- a/toolkit/content/widgets/videocontrols.xml
+++ b/toolkit/content/widgets/videocontrols.xml
@@ -1644,53 +1644,44 @@
             },
 
             terminateEventListeners : function () {
               for each (var event in this.videoEvents)
                 this.Utils.video.removeEventListener(event, this, false);
             },
 
             isVideoCasting : function () {
-              let unwrappedVideo = XPCNativeWrapper.unwrap(this.video);
-              if (unwrappedVideo.mozIsCasting)
+              if (this.video.mozIsCasting)
                 return true;
               return false;
             },
 
             updateCasting : function (eventDetail) {
-              let unwrappedVideo = XPCNativeWrapper.unwrap(this.video);
               let castingData = JSON.parse(eventDetail);
               if ("allow" in castingData) {
-                if (castingData.allow)
-                  unwrappedVideo.mozAllowCasting = true;
-                else
-                  delete unwrappedVideo.mozAllowCasting;
+                this.video.mozAllowCasting = !!castingData.allow;
               }
 
               if ("active" in castingData) {
-                if (castingData.active)
-                  unwrappedVideo.mozIsCasting = true;
-                else
-                  delete unwrappedVideo.mozIsCasting;
+                this.video.mozIsCasting = !!castingData.active;
               }
               this.setCastButtonState();
             },
 
             startCasting : function () {
               this.videocontrols.dispatchEvent(new CustomEvent("VideoBindingCast"));
             },
 
             setCastButtonState : function () {
-              let unwrappedVideo = XPCNativeWrapper.unwrap(this.video);
-              if (this.isAudioOnly || !unwrappedVideo.mozAllowCasting) {
+              if (this.isAudioOnly || !this.video.mozAllowCasting) {
                 this.castingButton.hidden = true;
                 return;
               }
 
-              if (unwrappedVideo.mozIsCasting) {
+              if (this.video.mozIsCasting) {
                 this.castingButton.setAttribute("active", "true");
               } else {
                 this.castingButton.removeAttribute("active");
               }
 
               this.castingButton.hidden = false;
             },