Bug 1162713 - Implement "Save Link to Pocket" context menu item. r+a=dolske, l10n=dolske
This commit is contained in:
@@ -79,6 +79,10 @@
|
|||||||
label="&saveLinkCmd.label;"
|
label="&saveLinkCmd.label;"
|
||||||
accesskey="&saveLinkCmd.accesskey;"
|
accesskey="&saveLinkCmd.accesskey;"
|
||||||
oncommand="gContextMenu.saveLink();"/>
|
oncommand="gContextMenu.saveLink();"/>
|
||||||
|
<menuitem id="context-savelinktopocket"
|
||||||
|
label="&saveLinkToPocketCmd.label;"
|
||||||
|
accesskey="&saveLinkToPocketCmd.accesskey;"
|
||||||
|
oncommand="gContextMenu.saveLinkToPocket();"/>
|
||||||
<menu id="context-marklinkMenu" label="&social.marklinkMenu.label;"
|
<menu id="context-marklinkMenu" label="&social.marklinkMenu.label;"
|
||||||
accesskey="&social.marklinkMenu.accesskey;">
|
accesskey="&social.marklinkMenu.accesskey;">
|
||||||
<menupopup/>
|
<menupopup/>
|
||||||
@@ -269,7 +273,7 @@
|
|||||||
<menuitem id="context-pocket"
|
<menuitem id="context-pocket"
|
||||||
label="&saveToPocketCmd.label;"
|
label="&saveToPocketCmd.label;"
|
||||||
accesskey="&saveToPocketCmd.accesskey;"
|
accesskey="&saveToPocketCmd.accesskey;"
|
||||||
oncommand="gContextMenu.saveToPocket();"/>
|
oncommand="gContextMenu.savePageToPocket();"/>
|
||||||
<menu id="context-markpageMenu" label="&social.markpageMenu.label;"
|
<menu id="context-markpageMenu" label="&social.markpageMenu.label;"
|
||||||
accesskey="&social.markpageMenu.accesskey;">
|
accesskey="&social.markpageMenu.accesskey;">
|
||||||
<menupopup/>
|
<menupopup/>
|
||||||
|
|||||||
@@ -11,4 +11,6 @@ pocket-button.tooltiptext = Bei Pocket speichern
|
|||||||
# From browser-pocket.dtd
|
# From browser-pocket.dtd
|
||||||
saveToPocketCmd.label = Seite bei Pocket speichern
|
saveToPocketCmd.label = Seite bei Pocket speichern
|
||||||
saveToPocketCmd.accesskey = k
|
saveToPocketCmd.accesskey = k
|
||||||
|
saveLinkToPocketCmd.label = Link in Pocket speichern
|
||||||
|
saveLinkToPocketCmd.accesskey = o
|
||||||
pocketMenuitem.label = Pocket-Liste anzeigen
|
pocketMenuitem.label = Pocket-Liste anzeigen
|
||||||
|
|||||||
@@ -11,4 +11,6 @@ pocket-button.tooltiptext = Guardar en Pocket
|
|||||||
# From browser-pocket.dtd
|
# From browser-pocket.dtd
|
||||||
saveToPocketCmd.label = Guardar página en Pocket
|
saveToPocketCmd.label = Guardar página en Pocket
|
||||||
saveToPocketCmd.accesskey = k
|
saveToPocketCmd.accesskey = k
|
||||||
|
saveLinkToPocketCmd.label = Guardar enlace en Pocket
|
||||||
|
saveLinkToPocketCmd.accesskey = k
|
||||||
pocketMenuitem.label = Ver lista de Pocket
|
pocketMenuitem.label = Ver lista de Pocket
|
||||||
|
|||||||
@@ -11,4 +11,6 @@ pocket-button.tooltiptext = Pocket に保存
|
|||||||
# From browser-pocket.dtd
|
# From browser-pocket.dtd
|
||||||
saveToPocketCmd.label = Pocket にページを保存
|
saveToPocketCmd.label = Pocket にページを保存
|
||||||
saveToPocketCmd.accesskey = k
|
saveToPocketCmd.accesskey = k
|
||||||
|
saveLinkToPocketCmd.label = Pocket にリンクを保存
|
||||||
|
saveLinkToPocketCmd.accesskey = o
|
||||||
pocketMenuitem.label = Pocket のマイリストを表示
|
pocketMenuitem.label = Pocket のマイリストを表示
|
||||||
|
|||||||
@@ -11,4 +11,6 @@ pocket-button.tooltiptext = Сохранить в Pocket
|
|||||||
# From browser-pocket.dtd
|
# From browser-pocket.dtd
|
||||||
saveToPocketCmd.label = Сохранить страницу в Pocket
|
saveToPocketCmd.label = Сохранить страницу в Pocket
|
||||||
saveToPocketCmd.accesskey = х
|
saveToPocketCmd.accesskey = х
|
||||||
|
saveLinkToPocketCmd.label = Сохранить ссылку в Pocket
|
||||||
|
saveLinkToPocketCmd.accesskey = P
|
||||||
pocketMenuitem.label = Показать список Pocket
|
pocketMenuitem.label = Показать список Pocket
|
||||||
|
|||||||
@@ -7,4 +7,6 @@
|
|||||||
|
|
||||||
<!ENTITY saveToPocketCmd.label "Save Page to Pocket">
|
<!ENTITY saveToPocketCmd.label "Save Page to Pocket">
|
||||||
<!ENTITY saveToPocketCmd.accesskey "k">
|
<!ENTITY saveToPocketCmd.accesskey "k">
|
||||||
|
<!ENTITY saveLinkToPocketCmd.label "Save Link to Pocket">
|
||||||
|
<!ENTITY saveLinkToPocketCmd.accesskey "o">
|
||||||
<!ENTITY pocketMenuitem.label "View Pocket List">
|
<!ENTITY pocketMenuitem.label "View Pocket List">
|
||||||
|
|||||||
@@ -6,6 +6,12 @@
|
|||||||
Components.utils.import("resource://gre/modules/PrivateBrowsingUtils.jsm");
|
Components.utils.import("resource://gre/modules/PrivateBrowsingUtils.jsm");
|
||||||
Components.utils.import("resource://gre/modules/InlineSpellChecker.jsm");
|
Components.utils.import("resource://gre/modules/InlineSpellChecker.jsm");
|
||||||
Components.utils.import("resource://gre/modules/BrowserUtils.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;
|
var gContextMenuContentData = null;
|
||||||
|
|
||||||
@@ -229,14 +235,20 @@ nsContextMenu.prototype = {
|
|||||||
CastingApps.getServicesForVideo(this.target).length > 0;
|
CastingApps.getServicesForVideo(this.target).length > 0;
|
||||||
this.setItemAttr("context-castvideo", "disabled", !shouldShowCast);
|
this.setItemAttr("context-castvideo", "disabled", !shouldShowCast);
|
||||||
|
|
||||||
let canPocket = false;
|
this.initPocketItems();
|
||||||
if (shouldShow && window.gBrowser &&
|
},
|
||||||
this.browser.getTabBrowser() == window.gBrowser) {
|
|
||||||
let uri = this.browser.currentURI;
|
initPocketItems: function CM_initPocketItems() {
|
||||||
canPocket =
|
var showSaveCurrentPageToPocket = !(this.onTextInput || this.onLink ||
|
||||||
CustomizableUI.getPlacementOfWidget("pocket-button") &&
|
this.isContentSelected || this.onImage ||
|
||||||
(uri.schemeIs("http") || uri.schemeIs("https") ||
|
this.onCanvas || this.onVideo || this.onAudio);
|
||||||
(uri.schemeIs("about") && ReaderMode.getOriginalUrl(uri.spec)));
|
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) {
|
if (canPocket) {
|
||||||
let locale = Cc["@mozilla.org/chrome/chrome-registry;1"].
|
let locale = Cc["@mozilla.org/chrome/chrome-registry;1"].
|
||||||
getService(Ci.nsIXULChromeRegistry).
|
getService(Ci.nsIXULChromeRegistry).
|
||||||
@@ -246,10 +258,13 @@ nsContextMenu.prototype = {
|
|||||||
locale = "ja";
|
locale = "ja";
|
||||||
let url = "chrome://browser/content/browser-pocket-" + locale + ".properties";
|
let url = "chrome://browser/content/browser-pocket-" + locale + ".properties";
|
||||||
let bundle = Services.strings.createBundle(url);
|
let bundle = Services.strings.createBundle(url);
|
||||||
let item = document.getElementById("context-pocket");
|
let saveToPocketItem = document.getElementById("context-pocket");
|
||||||
|
let saveLinkToPocketItem = document.getElementById("context-savelinktopocket");
|
||||||
try {
|
try {
|
||||||
item.setAttribute("label", bundle.GetStringFromName("saveToPocketCmd.label"));
|
saveToPocketItem.setAttribute("label", bundle.GetStringFromName("saveToPocketCmd.label"));
|
||||||
item.setAttribute("accesskey", bundle.GetStringFromName("saveToPocketCmd.accesskey"));
|
saveToPocketItem.setAttribute("accesskey", bundle.GetStringFromName("saveToPocketCmd.accesskey"));
|
||||||
|
saveLinkToPocketItem.setAttribute("label", bundle.GetStringFromName("saveLinkToPocketCmd.label"));
|
||||||
|
saveLinkToPocketItem.setAttribute("accesskey", bundle.GetStringFromName("saveLinkToPocketCmd.accesskey"));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// GetStringFromName throws when the bundle doesn't exist. In that
|
// GetStringFromName throws when the bundle doesn't exist. In that
|
||||||
// case, the item will retain the browser-pocket.dtd en-US string that
|
// case, the item will retain the browser-pocket.dtd en-US string that
|
||||||
@@ -257,8 +272,10 @@ nsContextMenu.prototype = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
this.showItem("context-pocket", canPocket && showSaveCurrentPageToPocket);
|
||||||
this.showItem("context-pocket", canPocket && window.pktApi && window.pktApi.isUserLoggedIn());
|
let showSaveLinkToPocket = canPocket && !showSaveCurrentPageToPocket &&
|
||||||
|
(this.onSaveableLink || this.onPlainTextLink);
|
||||||
|
this.showItem("context-savelinktopocket", showSaveLinkToPocket);
|
||||||
},
|
},
|
||||||
|
|
||||||
initViewItems: function CM_initViewItems() {
|
initViewItems: function CM_initViewItems() {
|
||||||
@@ -1678,20 +1695,12 @@ nsContextMenu.prototype = {
|
|||||||
saveDocument(this.browser.contentDocumentAsCPOW);
|
saveDocument(this.browser.contentDocumentAsCPOW);
|
||||||
},
|
},
|
||||||
|
|
||||||
saveToPocket: function CM_saveToPocket() {
|
saveLinkToPocket: function CM_saveLinkToPocket() {
|
||||||
let pocketWidget = document.getElementById("pocket-button");
|
Pocket.savePage(this.browser, this.linkURL);
|
||||||
let placement = CustomizableUI.getPlacementOfWidget("pocket-button");
|
},
|
||||||
if (!placement)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (placement.area == CustomizableUI.AREA_PANEL) {
|
savePageToPocket: function CM_saveToPocket() {
|
||||||
PanelUI.show().then(function() {
|
Pocket.savePage(this.browser, this.browser.currentURI.spec, this.browser.contentTitle);
|
||||||
pocketWidget = document.getElementById("pocket-button");
|
|
||||||
pocketWidget.doCommand();
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
pocketWidget.doCommand();
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
printFrame: function CM_printFrame() {
|
printFrame: function CM_printFrame() {
|
||||||
|
|||||||
@@ -27,14 +27,21 @@ let Pocket = {
|
|||||||
let window = document.defaultView;
|
let window = document.defaultView;
|
||||||
let iframe = document.getElementById('pocket-panel-iframe');
|
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,
|
// ViewShowing fires immediately before it creates the contents,
|
||||||
// in lieu of an AfterViewShowing event, just spin the event loop.
|
// in lieu of an AfterViewShowing event, just spin the event loop.
|
||||||
window.setTimeout(function() {
|
window.setTimeout(function() {
|
||||||
|
if (urlToSave) {
|
||||||
|
window.pktUI.tryToSaveUrl(urlToSave, titleToSave);
|
||||||
|
} else {
|
||||||
window.pktUI.pocketButtonOnCommand();
|
window.pktUI.pocketButtonOnCommand();
|
||||||
|
}
|
||||||
|
|
||||||
if (iframe.contentDocument &&
|
if (iframe.contentDocument &&
|
||||||
iframe.contentDocument.readyState == "complete")
|
iframe.contentDocument.readyState == "complete") {
|
||||||
{
|
|
||||||
window.pktUI.pocketPanelDidShow();
|
window.pktUI.pocketPanelDidShow();
|
||||||
} else {
|
} else {
|
||||||
// iframe didn't load yet. This seems to always be the case when in
|
// 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();
|
||||||
|
}
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user