Bug 637031 - Add "bookmark link" to context menu [r=vingtetun, uir=madhava]
--- a/mobile/chrome/content/ContextCommands.js
+++ b/mobile/chrome/content/ContextCommands.js
@@ -68,16 +68,33 @@ var ContextCommands = {
let state = ContextHelper.popupState;
SharingUI.show(state.linkURL, state.linkTitle);
},
shareMedia: function cc_shareMedia() {
SharingUI.show(ContextHelper.popupState.mediaURL, null);
},
+ bookmarkLink: function cc_bookmarkLink() {
+ let state = ContextHelper.popupState;
+ let bookmarks = PlacesUtils.bookmarks;
+ try {
+ bookmarks.insertBookmark(BookmarkList.panel.mobileRoot,
+ Util.makeURI(state.linkURL),
+ bookmarks.DEFAULT_INDEX,
+ state.linkTitle || state.linkURL);
+ } catch (e) {
+ return;
+ }
+
+ let message = Strings.browser.GetStringFromName("alertLinkBookmarked");
+ let toaster = Cc["@mozilla.org/toaster-alerts-service;1"].getService(Ci.nsIAlertsService);
+ toaster.showAlertNotification(null, message, "", false, "", null);
+ },
+
sendCommand: function cc_playVideo(aCommand) {
let browser = ContextHelper.popupState.target;
browser.messageManager.sendAsyncMessage("Browser:ContextCommand", { command: aCommand });
},
editBookmark: function cc_editBookmark() {
let target = ContextHelper.popupState.target;
target.startEditing();
--- a/mobile/chrome/content/browser.xul
+++ b/mobile/chrome/content/browser.xul
@@ -607,16 +607,19 @@
<label value="&paste.label;"/>
</richlistitem>
<richlistitem class="context-command" id="context-select-all" type="select-all" onclick="ContextCommands.selectAll();">
<label value="&selectAll.label;"/>
</richlistitem>
<richlistitem class="context-command" id="context-openinnewtab" type="link-openable" onclick="ContextCommands.openInNewTab();">
<label value="&contextOpenInNewTab.label;"/>
</richlistitem>
+ <richlistitem class="context-command" id="context-bookmark-link" type="link" onclick="ContextCommands.bookmarkLink();">
+ <label value="&contextBookmarkLink.label;"/>
+ </richlistitem>
<richlistitem class="context-command" id="context-savelink" type="link-saveable" onclick="ContextCommands.saveLink();">
<label value="&contextSaveLink.label;"/>
</richlistitem>
<richlistitem class="context-command" id="context-saveimage" type="image-loaded" onclick="ContextCommands.saveImage();">
<label value="&contextSaveImage.label;"/>
</richlistitem>
<richlistitem class="context-command" id="context-share-link" type="link-shareable" onclick="ContextCommands.shareLink();">
<label value="&contextShareLink.label;"/>
--- a/mobile/chrome/content/content.js
+++ b/mobile/chrome/content/content.js
@@ -926,16 +926,20 @@ var ContextHandler = {
/** Remove all handlers registered for a given type. */
unregisterType: function unregisterType(aName) {
this._types = this._types.filter(function(type) type.name != aName);
}
};
ContextHandler.init();
+ContextHandler.registerType("link", function(aState, aElement) {
+ return !!aState.linkURL;
+});
+
ContextHandler.registerType("mailto", function(aState, aElement) {
return aState.linkProtocol == "mailto";
});
ContextHandler.registerType("callto", function(aState, aElement) {
let protocol = aState.linkProtocol;
return protocol == "tel" || protocol == "callto" || protocol == "sip" || protocol == "voipto";
});
--- a/mobile/locales/en-US/chrome/browser.dtd
+++ b/mobile/locales/en-US/chrome/browser.dtd
@@ -90,16 +90,17 @@
<!ENTITY consoleErrLine.label "Line:">
<!ENTITY consoleErrColumn.label "Column:">
<!ENTITY contextOpenInNewTab.label "Open Link in New Tab">
<!ENTITY contextSaveLink.label "Save Link">
<!ENTITY contextSaveImage.label "Save Image">
<!ENTITY contextShareLink.label "Share Link">
<!ENTITY contextShareImage.label "Share Image">
+<!ENTITY contextBookmarkLink.label "Bookmark Link">
<!ENTITY contextSaveVideo.label "Save Video">
<!ENTITY contextShareVideo.label "Share Video">
<!ENTITY contextPlayMedia.label "Play">
<!ENTITY contextPauseMedia.label "Pause">
<!ENTITY contextFullScreen.label "Full Screen">
<!ENTITY contextEditBookmark.label "Edit">
<!ENTITY contextRemoveBookmark.label "Remove">
--- a/mobile/locales/en-US/chrome/browser.properties
+++ b/mobile/locales/en-US/chrome/browser.properties
@@ -86,16 +86,17 @@ downloadsDeleteTitle=Delete File
# Alerts
alertAddons=Add-ons
alertAddonsDownloading=Downloading add-on
alertAddonsInstalling=Installing add-on
alertAddonsInstalled=Installation complete. Restart required.
alertAddonsInstalledNoRestart=Installation complete
alertAddonsFail=Installation failed
+alertLinkBookmarked=Bookmark added
alertLockScreen=Screen Orientation
alertLockScreen.locked=Locked
alertLockScreen.unlocked=Unlocked
# LOCALIZATION NOTE (alertAddonsDisabled): Semi-colon list of plural forms.
# See: http://developer.mozilla.org/en/docs/Localization_and_Plurals
# #1 number of add-ons
alertAddonsDisabled=#1 incompatible add-on was disabled;#1 incompatible add-ons were disabled