diff --git a/browser/base/content/browser-context.inc b/browser/base/content/browser-context.inc index 83928616d030..d7c7992debee 100644 --- a/browser/base/content/browser-context.inc +++ b/browser/base/content/browser-context.inc @@ -79,6 +79,10 @@ label="&saveLinkCmd.label;" accesskey="&saveLinkCmd.accesskey;" oncommand="gContextMenu.saveLink();"/> + @@ -269,7 +273,7 @@ + oncommand="gContextMenu.savePageToPocket();"/> diff --git a/browser/base/content/browser-pocket-de.properties b/browser/base/content/browser-pocket-de.properties index dfa90ed985f0..6c788dea91e2 100644 --- a/browser/base/content/browser-pocket-de.properties +++ b/browser/base/content/browser-pocket-de.properties @@ -11,4 +11,6 @@ pocket-button.tooltiptext = Bei Pocket speichern # From browser-pocket.dtd saveToPocketCmd.label = Seite bei Pocket speichern saveToPocketCmd.accesskey = k +saveLinkToPocketCmd.label = Link in Pocket speichern +saveLinkToPocketCmd.accesskey = o pocketMenuitem.label = Pocket-Liste anzeigen diff --git a/browser/base/content/browser-pocket-es-ES.properties b/browser/base/content/browser-pocket-es-ES.properties index c55c4ba6b540..419e1cbbfed3 100644 --- a/browser/base/content/browser-pocket-es-ES.properties +++ b/browser/base/content/browser-pocket-es-ES.properties @@ -11,4 +11,6 @@ pocket-button.tooltiptext = Guardar en Pocket # From browser-pocket.dtd saveToPocketCmd.label = Guardar página en Pocket saveToPocketCmd.accesskey = k +saveLinkToPocketCmd.label = Guardar enlace en Pocket +saveLinkToPocketCmd.accesskey = k pocketMenuitem.label = Ver lista de Pocket diff --git a/browser/base/content/browser-pocket-ja.properties b/browser/base/content/browser-pocket-ja.properties index 5c839a26b004..94c85ee6114f 100644 --- a/browser/base/content/browser-pocket-ja.properties +++ b/browser/base/content/browser-pocket-ja.properties @@ -11,4 +11,6 @@ pocket-button.tooltiptext = Pocket に保存 # From browser-pocket.dtd saveToPocketCmd.label = Pocket にページを保存 saveToPocketCmd.accesskey = k +saveLinkToPocketCmd.label = Pocket にリンクを保存 +saveLinkToPocketCmd.accesskey = o pocketMenuitem.label = Pocket のマイリストを表示 diff --git a/browser/base/content/browser-pocket-ru.properties b/browser/base/content/browser-pocket-ru.properties index cc1f737cc5c0..eb15bf6bc4f5 100644 --- a/browser/base/content/browser-pocket-ru.properties +++ b/browser/base/content/browser-pocket-ru.properties @@ -11,4 +11,6 @@ pocket-button.tooltiptext = Сохранить в Pocket # From browser-pocket.dtd saveToPocketCmd.label = Сохранить страницу в Pocket saveToPocketCmd.accesskey = х +saveLinkToPocketCmd.label = Сохранить ссылку в Pocket +saveLinkToPocketCmd.accesskey = P pocketMenuitem.label = Показать список Pocket diff --git a/browser/base/content/browser-pocket.dtd b/browser/base/content/browser-pocket.dtd index c92e479946c6..460866f777ba 100644 --- a/browser/base/content/browser-pocket.dtd +++ b/browser/base/content/browser-pocket.dtd @@ -7,4 +7,6 @@ + + diff --git a/browser/base/content/nsContextMenu.js b/browser/base/content/nsContextMenu.js index ab2e4ec22987..cb45adce07b4 100644 --- a/browser/base/content/nsContextMenu.js +++ b/browser/base/content/nsContextMenu.js @@ -6,6 +6,12 @@ Components.utils.import("resource://gre/modules/PrivateBrowsingUtils.jsm"); Components.utils.import("resource://gre/modules/InlineSpellChecker.jsm"); Components.utils.import("resource://gre/modules/BrowserUtils.jsm"); +Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); + +XPCOMUtils.defineLazyModuleGetter(this, "CustomizableUI", + "resource:///modules/CustomizableUI.jsm"); +XPCOMUtils.defineLazyModuleGetter(this, "Pocket", + "resource:///modules/Pocket.jsm"); var gContextMenuContentData = null; @@ -178,36 +184,47 @@ nsContextMenu.prototype = { CastingApps.getServicesForVideo(this.target).length > 0; this.setItemAttr("context-castvideo", "disabled", !shouldShowCast); - let canPocket = false; - if (shouldShow && window.gBrowser && - this.browser.getTabBrowser() == window.gBrowser) { - let uri = this.browser.currentURI; - canPocket = - CustomizableUI.getPlacementOfWidget("pocket-button") && - (uri.schemeIs("http") || uri.schemeIs("https") || - (uri.schemeIs("about") && ReaderMode.getOriginalUrl(uri.spec))); - if (canPocket) { - let locale = Cc["@mozilla.org/chrome/chrome-registry;1"]. - getService(Ci.nsIXULChromeRegistry). - getSelectedLocale("browser"); - if (locale != "en-US") { - if (locale == "ja-JP-mac") - locale = "ja"; - let url = "chrome://browser/content/browser-pocket-" + locale + ".properties"; - let bundle = Services.strings.createBundle(url); - let item = document.getElementById("context-pocket"); - try { - item.setAttribute("label", bundle.GetStringFromName("saveToPocketCmd.label")); - item.setAttribute("accesskey", bundle.GetStringFromName("saveToPocketCmd.accesskey")); - } catch (err) { - // GetStringFromName throws when the bundle doesn't exist. In that - // case, the item will retain the browser-pocket.dtd en-US string that - // it has in the markup. - } + this.initPocketItems(); + }, + + initPocketItems: function CM_initPocketItems() { + var showSaveCurrentPageToPocket = !(this.onTextInput || this.onLink || + this.isContentSelected || this.onImage || + this.onCanvas || this.onVideo || this.onAudio); + let targetURI = (this.onSaveableLink || this.onPlainTextLink) ? this.linkURI : this.browser.currentURI; + let canPocket = CustomizableUI.getPlacementOfWidget("pocket-button") && + window.pktApi && window.pktApi.isUserLoggedIn(); + canPocket = canPocket && (targetURI.schemeIs("http") || targetURI.schemeIs("https") || + (targetURI.schemeIs("about") && ReaderMode.getOriginalUrl(targetURI.spec))); + canPocket = canPocket && window.gBrowser && this.browser.getTabBrowser() == window.gBrowser; + + if (canPocket) { + let locale = Cc["@mozilla.org/chrome/chrome-registry;1"]. + getService(Ci.nsIXULChromeRegistry). + getSelectedLocale("browser"); + if (locale != "en-US") { + if (locale == "ja-JP-mac") + locale = "ja"; + let url = "chrome://browser/content/browser-pocket-" + locale + ".properties"; + let bundle = Services.strings.createBundle(url); + let saveToPocketItem = document.getElementById("context-pocket"); + let saveLinkToPocketItem = document.getElementById("context-savelinktopocket"); + try { + saveToPocketItem.setAttribute("label", bundle.GetStringFromName("saveToPocketCmd.label")); + saveToPocketItem.setAttribute("accesskey", bundle.GetStringFromName("saveToPocketCmd.accesskey")); + saveLinkToPocketItem.setAttribute("label", bundle.GetStringFromName("saveLinkToPocketCmd.label")); + saveLinkToPocketItem.setAttribute("accesskey", bundle.GetStringFromName("saveLinkToPocketCmd.accesskey")); + } catch (err) { + // GetStringFromName throws when the bundle doesn't exist. In that + // case, the item will retain the browser-pocket.dtd en-US string that + // it has in the markup. } } } - this.showItem("context-pocket", canPocket && window.pktApi && window.pktApi.isUserLoggedIn()); + this.showItem("context-pocket", canPocket && showSaveCurrentPageToPocket); + let showSaveLinkToPocket = canPocket && !showSaveCurrentPageToPocket && + (this.onSaveableLink || this.onPlainTextLink); + this.showItem("context-savelinktopocket", showSaveLinkToPocket); }, initViewItems: function CM_initViewItems() { @@ -1661,20 +1678,12 @@ nsContextMenu.prototype = { saveDocument(this.browser.contentDocumentAsCPOW); }, - saveToPocket: function CM_saveToPocket() { - let pocketWidget = document.getElementById("pocket-button"); - let placement = CustomizableUI.getPlacementOfWidget("pocket-button"); - if (!placement) - return; + saveLinkToPocket: function CM_saveLinkToPocket() { + Pocket.savePage(this.browser, this.linkURL); + }, - if (placement.area == CustomizableUI.AREA_PANEL) { - PanelUI.show().then(function() { - pocketWidget = document.getElementById("pocket-button"); - pocketWidget.doCommand(); - }); - } else { - pocketWidget.doCommand(); - } + savePageToPocket: function CM_saveToPocket() { + Pocket.savePage(this.browser, this.browser.currentURI.spec, this.browser.contentTitle); }, printFrame: function CM_printFrame() { diff --git a/browser/components/pocket/Pocket.jsm b/browser/components/pocket/Pocket.jsm index c2ee64be70ce..03cddf3e8f11 100644 --- a/browser/components/pocket/Pocket.jsm +++ b/browser/components/pocket/Pocket.jsm @@ -27,14 +27,21 @@ let Pocket = { let window = document.defaultView; let iframe = document.getElementById('pocket-panel-iframe'); + let urlToSave = Pocket._urlToSave; + let titleToSave = Pocket._titleToSave; + Pocket._urlToSave = null; + Pocket._titleToSave = null; // ViewShowing fires immediately before it creates the contents, // in lieu of an AfterViewShowing event, just spin the event loop. window.setTimeout(function() { - window.pktUI.pocketButtonOnCommand(); + if (urlToSave) { + window.pktUI.tryToSaveUrl(urlToSave, titleToSave); + } else { + window.pktUI.pocketButtonOnCommand(); + } if (iframe.contentDocument && - iframe.contentDocument.readyState == "complete") - { + iframe.contentDocument.readyState == "complete") { window.pktUI.pocketPanelDidShow(); } else { // iframe didn't load yet. This seems to always be the case when in @@ -82,4 +89,26 @@ let Pocket = { } } }, + + _urlToSave: null, + _titleToSave: null, + savePage(browser, url, title) { + let document = browser.ownerDocument; + let pocketWidget = document.getElementById("pocket-button"); + let placement = CustomizableUI.getPlacementOfWidget("pocket-button"); + if (!placement) + return; + + this._urlToSave = url; + this._titleToSave = title; + if (placement.area == CustomizableUI.AREA_PANEL) { + let win = document.defaultView; + win.PanelUI.show().then(function() { + pocketWidget = document.getElementById("pocket-button"); + pocketWidget.doCommand(); + }); + } else { + pocketWidget.doCommand(); + } + }, };