Bug 791654 - Add Save Video/Audio to context menus. r=wesj
authorJinsu Oh <heyjinsu@gmail.com>
Thu, 24 Jan 2013 18:36:25 -0800
changeset 119873 ce79b39c6e0e66b522eb10a8115565324a9586c2
parent 119872 5197fd7963037347ab71ec9307d8812d0c2bc77a
child 119874 f28ae1d9b685f1f1fb1ffd4a1dc78eb136a3b4a9
push id1317
push userryanvm@gmail.com
push dateSun, 27 Jan 2013 02:21:57 +0000
treeherderfx-team@47684913d63d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswesj
bugs791654
milestone21.0a1
Bug 791654 - Add Save Video/Audio to context menus. 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
@@ -494,16 +494,40 @@ var BrowserApp = {
         let src = aTarget.src;
         sendMessageToJava({
           gecko: {
             type: "Wallpaper:Set",
             url: src
           }
         });
       });
+
+    NativeWindow.contextmenus.add(
+      function(aTarget) {
+        if (aTarget instanceof HTMLVideoElement) {
+          // If a video element is zero width or height, its essentially
+          // an HTMLAudioElement.
+          if (aTarget.videoWidth == 0 || aTarget.videoHeight == 0 )
+            return Strings.browser.GetStringFromName("contextmenu.saveAudio");
+          return Strings.browser.GetStringFromName("contextmenu.saveVideo");
+        } else if (aTarget instanceof HTMLAudioElement) {
+          return Strings.browser.GetStringFromName("contextmenu.saveAudio");
+        }
+        return Strings.browser.GetStringFromName("contextmenu.saveVideo");
+      }, NativeWindow.contextmenus.mediaSaveableContext,
+      function(aTarget) {
+        let url = aTarget.currentSrc || aTarget.src;
+        let filePickerTitleKey = (aTarget instanceof HTMLVideoElement &&
+                                  (aTarget.videoWidth != 0 && aTarget.videoHeight != 0))
+                                  ? "SaveVideoTitle" : "SaveAudioTitle";
+        // Skipped trying to pull MIME type out of cache for now
+        ContentAreaUtils.internalSave(url, null, null, null, null, false,
+                                      filePickerTitleKey, null, aTarget.ownerDocument.documentURIObject,
+                                      aTarget.ownerDocument, true, null);
+      });
   },
 
   onAppUpdated: function() {
     // initialize the form history and passwords databases on upgrades
     Services.obs.notifyObservers(null, "FormHistory:Init", "");
     Services.obs.notifyObservers(null, "Passwords:Init", "");
   },
 
@@ -1541,16 +1565,23 @@ 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;
       }
     },
 
+    mediaSaveableContext: {
+      matches: function mediaSaveableContextMatches(aElement) {
+        return (aElement instanceof HTMLVideoElement ||
+               aElement instanceof HTMLAudioElement);
+      }
+    },
+
     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;
 
--- a/mobile/android/locales/en-US/chrome/browser.properties
+++ b/mobile/android/locales/en-US/chrome/browser.properties
@@ -230,16 +230,18 @@ contextmenu.copyImageLocation=Copy Image
 contextmenu.shareImage=Share Image
 contextmenu.saveImage=Save Image
 contextmenu.setWallpaper=Set as Wallpaper
 contextmenu.addSearchEngine=Add Search Engine
 contextmenu.playMedia=Play
 contextmenu.pauseMedia=Pause
 contextmenu.shareMedia=Share Video
 contextmenu.showControls2=Show Controls
+contextmenu.saveVideo=Save Video
+contextmenu.saveAudio=Save Audio
 
 contextmenu.copy=Copy
 contextmenu.copyAll=Copy All
 contextmenu.selectWord=Select Word
 contextmenu.selectAll=Select All
 contextmenu.paste=Paste
 
 # Select UI