Bug 701785 - Missing html5 video/audio controls in context menu r=wesj
authorMark Finkle <mfinkle@mozilla.com>
Tue, 27 Nov 2012 21:27:24 -0500
changeset 114318 bc0d354ed0285c7deea0005ab792c5a81fd9a385
parent 114317 a2ee1d41edff7db6ea7573f90c0fe228adb39ac6
child 114319 0db3b8d8ed8f4ea145f592cd30f9e5b00bfe792a
push id23913
push useremorley@mozilla.com
push dateWed, 28 Nov 2012 17:11:31 +0000
treeherdermozilla-central@17c267a881cf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswesj
bugs701785
milestone20.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 701785 - Missing html5 video/audio controls in context menu r=wesj
mobile/android/chrome/content/browser.js
mobile/android/locales/en-US/chrome/browser.properties
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -390,16 +390,36 @@ var BrowserApp = {
           gecko: {
             type: "Bookmark:Insert",
             url: url,
             title: title
           }
         });
       });
 
+    NativeWindow.contextmenus.add(Strings.browser.GetStringFromName("contextmenu.playMedia"),
+      NativeWindow.contextmenus.mediaContext("media-paused"),
+      function(aTarget) {
+        aTarget.play();
+      });
+
+    NativeWindow.contextmenus.add(Strings.browser.GetStringFromName("contextmenu.pauseMedia"),
+      NativeWindow.contextmenus.mediaContext("media-playing"),
+      function(aTarget) {
+        aTarget.pause();
+      });
+
+    NativeWindow.contextmenus.add(Strings.browser.GetStringFromName("contextmenu.shareMedia"),
+      NativeWindow.contextmenus.SelectorContext("video"),
+      function(aTarget) {
+        let url = (aTarget.currentSrc || aTarget.src);
+        let title = aTarget.textContent || aTarget.title;
+        NativeWindow.contextmenus._shareStringWithDefault(url, title);
+      });
+
     NativeWindow.contextmenus.add(Strings.browser.GetStringFromName("contextmenu.fullScreen"),
       NativeWindow.contextmenus.SelectorContext("video:not(:-moz-full-screen)"),
       function(aTarget) {
         aTarget.mozRequestFullScreen();
       });
 
     NativeWindow.contextmenus.add(Strings.browser.GetStringFromName("contextmenu.copyImageLocation"),
       NativeWindow.contextmenus.imageLocationCopyableContext,
@@ -1393,16 +1413,35 @@ var NativeWindow = {
           // The image must be loaded to allow saving
           let request = aElement.getRequest(Ci.nsIImageLoadingContent.CURRENT_REQUEST);
           return (request && (request.imageStatus & request.STATUS_SIZE_AVAILABLE));
         }
         return false;
       }
     },
 
+    mediaContext: function(aMode) {
+      return {
+        matches: function(aElt) {
+          if (aElt instanceof Ci.nsIDOMHTMLMediaElement) {
+            let hasError = aElt.error != null || aElt.networkState == aElt.NETWORK_NO_SOURCE;
+            if (hasError)
+              return false;
+
+            let paused = aElt.paused || aElt.ended;
+            if (paused && aMode == "media-paused")
+              return true;
+            if (!paused && aMode == "media-playing")
+              return true;
+          }
+          return false;
+        }
+      }
+    },
+
     _sendToContent: function(aX, aY) {
       // initially we look for nearby clickable elements. If we don't find one we fall back to using whatever this click was on
       let rootElement = ElementTouchHelper.elementFromPoint(aX, aY);
       if (!rootElement)
         rootElement = ElementTouchHelper.anyElementFromPoint(aX, aY)
 
       this.menuitems = {};
       let menuitemsSet = false;
--- a/mobile/android/locales/en-US/chrome/browser.properties
+++ b/mobile/android/locales/en-US/chrome/browser.properties
@@ -219,16 +219,19 @@ contextmenu.shareEmailAddress=Share Emai
 contextmenu.copyPhoneNumber=Copy Phone Number
 contextmenu.sharePhoneNumber=Share Phone Number
 contextmenu.changeInputMethod=Select Input Method
 contextmenu.fullScreen=Full Screen
 contextmenu.copyImageLocation=Copy Image Location
 contextmenu.shareImage=Share Image
 contextmenu.saveImage=Save Image
 contextmenu.addSearchEngine=Add Search Engine
+contextmenu.playMedia=Play
+contextmenu.pauseMedia=Pause
+contextmenu.shareMedia=Share Video
 
 contextmenu.copy=Copy
 contextmenu.copyAll=Copy All
 contextmenu.selectWord=Select Word
 contextmenu.selectAll=Select All
 contextmenu.paste=Paste
 
 # Select UI