Bug 766275 - Remove browser actions from the Webapps context menu. r=mfinkle

This commit is contained in:
Wes Johnston 2012-07-20 11:14:43 -07:00
parent eb683fd0cf
commit cf60fc9a3f

View File

@ -206,7 +206,6 @@ var BrowserApp = {
ClipboardHelper.init();
PermissionsHelper.init();
CharacterEncoding.init();
SearchEngines.init();
ActivityObserver.init();
WebappsUI.init();
RemoteDebugger.init();
@ -243,8 +242,12 @@ var BrowserApp = {
}
let updated = this.isAppUpdated();
if (pinned)
if (pinned) {
WebAppRT.init(updated);
} else {
SearchEngines.init();
this.addBrowserContextMenuItems();
}
if (url == "about:empty")
loadParams.flags = Ci.nsIWebNavigation.LOAD_FLAGS_BYPASS_HISTORY;
@ -347,6 +350,87 @@ var BrowserApp = {
return "";
},
addBrowserContextMenuItems: function ba_addBrowserContextMenuItems() {
// TODO: These should eventually move into more appropriate classes
NativeWindow.contextmenus.add(Strings.browser.GetStringFromName("contextmenu.openInNewTab"),
NativeWindow.contextmenus.linkOpenableContext,
function(aTarget) {
let url = NativeWindow.contextmenus._getLinkURL(aTarget);
BrowserApp.addTab(url, { selected: false, parentId: BrowserApp.selectedTab.id });
let newtabStrings = Strings.browser.GetStringFromName("newtabpopup.opened");
let label = PluralForm.get(1, newtabStrings).replace("#1", 1);
NativeWindow.toast.show(label, "short");
});
NativeWindow.contextmenus.add(Strings.browser.GetStringFromName("contextmenu.shareLink"),
NativeWindow.contextmenus.linkShareableContext,
function(aTarget) {
let url = NativeWindow.contextmenus._getLinkURL(aTarget);
let title = aTarget.textContent || aTarget.title;
let sharing = Cc["@mozilla.org/uriloader/external-sharing-app-service;1"].getService(Ci.nsIExternalSharingAppService);
sharing.shareWithDefault(url, "text/plain", title);
});
NativeWindow.contextmenus.add(Strings.browser.GetStringFromName("contextmenu.bookmarkLink"),
NativeWindow.contextmenus.linkBookmarkableContext,
function(aTarget) {
let url = NativeWindow.contextmenus._getLinkURL(aTarget);
let title = aTarget.textContent || aTarget.title || url;
sendMessageToJava({
gecko: {
type: "Bookmark:Insert",
url: url,
title: 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.shareImage"),
NativeWindow.contextmenus.imageSaveableContext,
function(aTarget) {
let imageCache = Cc["@mozilla.org/image/cache;1"].getService(Ci.imgICache);
let props = imageCache.findEntryProperties(aTarget.currentURI, aTarget.ownerDocument.characterSet);
let src = aTarget.src;
let type = "";
try {
type = String(props.get("type", Ci.nsISupportsCString));
} catch(ex) {
type = "";
}
sendMessageToJava({
gecko: {
type: "Share:Image",
url: src,
mime: type,
}
});
});
NativeWindow.contextmenus.add(Strings.browser.GetStringFromName("contextmenu.saveImage"),
NativeWindow.contextmenus.imageSaveableContext,
function(aTarget) {
let imageCache = Cc["@mozilla.org/image/cache;1"].getService(Ci.imgICache);
let props = imageCache.findEntryProperties(aTarget.currentURI, aTarget.ownerDocument.characterSet);
let contentDisposition = "";
let type = "";
try {
contentDisposition = String(props.get("content-disposition", Ci.nsISupportsCString));
type = String(props.get("type", Ci.nsISupportsCString));
} catch(ex) {
contentDisposition = "";
type = "";
}
ContentAreaUtils.internalSave(aTarget.currentURI.spec, null, null, contentDisposition, type, false, "SaveImageTitle", null, aTarget.ownerDocument.documentURIObject, true, null);
});
},
onAppUpdated: function() {
// initialize the form history and passwords databases on upgrades
Services.obs.notifyObservers(null, "FormHistory:Init", "");
@ -1115,93 +1199,6 @@ var NativeWindow = {
init: function() {
Services.obs.addObserver(this, "Gesture:LongPress", false);
// TODO: These should eventually move into more appropriate classes
this.add(Strings.browser.GetStringFromName("contextmenu.openInNewTab"),
this.linkOpenableContext,
function(aTarget) {
let url = NativeWindow.contextmenus._getLinkURL(aTarget);
BrowserApp.addTab(url, { selected: false, parentId: BrowserApp.selectedTab.id });
let newtabStrings = Strings.browser.GetStringFromName("newtabpopup.opened");
let label = PluralForm.get(1, newtabStrings).replace("#1", 1);
NativeWindow.toast.show(label, "short");
});
this.add(Strings.browser.GetStringFromName("contextmenu.copyLink"),
this.linkCopyableContext,
function(aTarget) {
let url = NativeWindow.contextmenus._getLinkURL(aTarget);
let clipboard = Cc["@mozilla.org/widget/clipboardhelper;1"].getService(Ci.nsIClipboardHelper);
clipboard.copyString(url);
});
this.add(Strings.browser.GetStringFromName("contextmenu.shareLink"),
this.linkShareableContext,
function(aTarget) {
let url = NativeWindow.contextmenus._getLinkURL(aTarget);
let title = aTarget.textContent || aTarget.title;
let sharing = Cc["@mozilla.org/uriloader/external-sharing-app-service;1"].getService(Ci.nsIExternalSharingAppService);
sharing.shareWithDefault(url, "text/plain", title);
});
this.add(Strings.browser.GetStringFromName("contextmenu.bookmarkLink"),
this.linkBookmarkableContext,
function(aTarget) {
let url = NativeWindow.contextmenus._getLinkURL(aTarget);
let title = aTarget.textContent || aTarget.title || url;
sendMessageToJava({
gecko: {
type: "Bookmark:Insert",
url: url,
title: title
}
});
});
this.add(Strings.browser.GetStringFromName("contextmenu.fullScreen"),
this.SelectorContext("video:not(:-moz-full-screen)"),
function(aTarget) {
aTarget.mozRequestFullScreen();
});
this.add(Strings.browser.GetStringFromName("contextmenu.shareImage"),
this.imageSaveableContext,
function(aTarget) {
let imageCache = Cc["@mozilla.org/image/cache;1"].getService(Ci.imgICache);
let props = imageCache.findEntryProperties(aTarget.currentURI, aTarget.ownerDocument.characterSet);
let src = aTarget.src;
let type = "";
try {
type = String(props.get("type", Ci.nsISupportsCString));
} catch(ex) {
type = "";
}
sendMessageToJava({
gecko: {
type: "Share:Image",
url: src,
mime: type,
}
});
});
this.add(Strings.browser.GetStringFromName("contextmenu.saveImage"),
this.imageSaveableContext,
function(aTarget) {
let imageCache = Cc["@mozilla.org/image/cache;1"].getService(Ci.imgICache);
let props = imageCache.findEntryProperties(aTarget.currentURI, aTarget.ownerDocument.characterSet);
let contentDisposition = "";
let type = "";
try {
contentDisposition = String(props.get("content-disposition", Ci.nsISupportsCString));
type = String(props.get("type", Ci.nsISupportsCString));
} catch(ex) {
contentDisposition = "";
type = "";
}
ContentAreaUtils.internalSave(aTarget.currentURI.spec, null, null, contentDisposition, type, false, "SaveImageTitle", null, aTarget.ownerDocument.documentURIObject, true, null);
});
},
uninit: function() {