Bug 637031 - Add "bookmark link" to context menu [r=vingtetun, uir=madhava]
authorMatt Brubeck <mbrubeck@mozilla.com>
Mon, 21 Mar 2011 10:28:34 -0700
changeset 67531 bd05aa44a67b51c4ac1ffbad35d181d38cad565f
parent 67530 c9f894ae705d0fc5a5f1de550a9cb16bbd3d6780
child 67532 a98cf562e0cbae073d5577d8c2a84e84b02f34eb
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvingtetun
bugs637031
Bug 637031 - Add "bookmark link" to context menu [r=vingtetun, uir=madhava]
mobile/chrome/content/ContextCommands.js
mobile/chrome/content/browser.xul
mobile/chrome/content/content.js
mobile/locales/en-US/chrome/browser.dtd
mobile/locales/en-US/chrome/browser.properties
--- 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