Bug 791654 - Add Save Video/Audio to context menus. r=wesj

This commit is contained in:
Jinsu Oh 2013-01-24 18:36:25 -08:00
parent 132caaa2c6
commit 05533aa7f8
2 changed files with 33 additions and 0 deletions

View File

@ -499,6 +499,30 @@ var BrowserApp = {
}
});
});
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() {
@ -1546,6 +1570,13 @@ var NativeWindow = {
}
},
mediaSaveableContext: {
matches: function mediaSaveableContextMatches(aElement) {
return (aElement instanceof HTMLVideoElement ||
aElement instanceof HTMLAudioElement);
}
},
mediaContext: function(aMode) {
return {
matches: function(aElt) {

View File

@ -235,6 +235,8 @@ 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