Bug 821724 - Implement a menuitem for places/bookmarks to open them in a private window. r=mak

This commit is contained in:
Tom Schuster 2015-01-13 21:18:33 +01:00
parent 6410881e35
commit f718d2c2f7
6 changed files with 34 additions and 5 deletions

View File

@ -826,12 +826,12 @@ this.PlacesUIUtils = {
* web panel.
* see also openUILinkIn
*/
openNodeIn: function PUIU_openNodeIn(aNode, aWhere, aView) {
openNodeIn: function PUIU_openNodeIn(aNode, aWhere, aView, aPrivate) {
let window = aView.ownerWindow;
this._openNodeIn(aNode, aWhere, window);
this._openNodeIn(aNode, aWhere, window, aPrivate);
},
_openNodeIn: function PUIU_openNodeIn(aNode, aWhere, aWindow) {
_openNodeIn: function PUIU_openNodeIn(aNode, aWhere, aWindow, aPrivate=false) {
if (aNode && PlacesUtils.nodeIsURI(aNode) &&
this.checkURLSecurity(aNode, aWindow)) {
let isBookmark = PlacesUtils.nodeIsBookmark(aNode);
@ -855,8 +855,10 @@ this.PlacesUIUtils = {
}
}
}
aWindow.openUILinkIn(aNode.uri, aWhere, {
inBackground: Services.prefs.getBoolPref("browser.tabs.loadBookmarksInBackground")
inBackground: Services.prefs.getBoolPref("browser.tabs.loadBookmarksInBackground"),
private: aPrivate,
});
}
},

View File

@ -7,6 +7,8 @@ XPCOMUtils.defineLazyModuleGetter(this, "ForgetAboutSite",
"resource://gre/modules/ForgetAboutSite.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "NetUtil",
"resource://gre/modules/NetUtil.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "PrivateBrowsingUtils",
"resource://gre/modules/PrivateBrowsingUtils.jsm");
// XXXmano: we should move most/all of these constants to PlacesUtils
const ORGANIZER_ROOT_BOOKMARKS = "place:folder=BOOKMARKS_MENU&excludeItems=1&queryType=1";
@ -178,6 +180,7 @@ PlacesController.prototype = {
return false;
case "placesCmd_open":
case "placesCmd_open:window":
case "placesCmd_open:privatewindow":
case "placesCmd_open:tab":
var selectedNode = this._view.selectedNode;
return selectedNode && PlacesUtils.nodeIsURI(selectedNode);
@ -263,6 +266,9 @@ PlacesController.prototype = {
case "placesCmd_open:window":
PlacesUIUtils.openNodeIn(this._view.selectedNode, "window", this._view);
break;
case "placesCmd_open:privatewindow":
PlacesUIUtils.openNodeIn(this._view.selectedNode, "window", this._view, true);
break;
case "placesCmd_open:tab":
PlacesUIUtils.openNodeIn(this._view.selectedNode, "tab", this._view);
break;
@ -601,7 +607,10 @@ PlacesController.prototype = {
// We allow pasting into tag containers, so special case that.
var hideIfNoIP = item.getAttribute("hideifnoinsertionpoint") == "true" &&
noIp && !(ip && ip.isTag && item.id == "placesContext_paste");
var shouldHideItem = hideIfNoIP || !this._shouldShowMenuItem(item, metadata);
var hideIfPrivate = item.getAttribute("hideifprivatebrowsing") == "true" &&
PrivateBrowsingUtils.isWindowPrivate(window);
var shouldHideItem = hideIfNoIP || hideIfPrivate ||
!this._shouldShowMenuItem(item, metadata);
item.hidden = item.disabled = shouldHideItem;
if (!item.hidden) {
@ -1690,6 +1699,7 @@ function goUpdatePlacesCommands() {
updatePlacesCommand("placesCmd_open");
updatePlacesCommand("placesCmd_open:window");
updatePlacesCommand("placesCmd_open:privatewindow");
updatePlacesCommand("placesCmd_open:tab");
updatePlacesCommand("placesCmd_new:folder");
updatePlacesCommand("placesCmd_new:bookmark");

View File

@ -54,6 +54,8 @@
oncommand="goDoPlacesCommand('placesCmd_open');"/>
<command id="placesCmd_open:window"
oncommand="goDoPlacesCommand('placesCmd_open:window');"/>
<command id="placesCmd_open:privatewindow"
oncommand="goDoPlacesCommand('placesCmd_open:privatewindow');"/>
<command id="placesCmd_open:tab"
oncommand="goDoPlacesCommand('placesCmd_open:tab');"/>
@ -129,6 +131,13 @@
accesskey="&cmd.open_window.accesskey;"
selectiontype="single"
selection="link"/>
<menuitem id="placesContext_open:newprivatewindow"
command="placesCmd_open:privatewindow"
label="&cmd.open_private_window.label;"
accesskey="&cmd.open_private_window.accesskey;"
selectiontype="single"
selection="link"
hideifprivatebrowsing="true"/>
<menuseparator id="placesContext_openSeparator"/>
<menuitem id="placesContext_new:bookmark"
command="placesCmd_new:bookmark"

View File

@ -52,6 +52,8 @@
<!ENTITY cmd.open.accesskey "O">
<!ENTITY cmd.open_window.label "Open in a New Window">
<!ENTITY cmd.open_window.accesskey "N">
<!ENTITY cmd.open_private_window.label "Open in a New Private Window">
<!ENTITY cmd.open_private_window.accesskey "P">
<!ENTITY cmd.open_tab.label "Open in a New Tab">
<!ENTITY cmd.open_tab.accesskey "w">
<!ENTITY cmd.open_all_in_tabs.label "Open All in Tabs">

View File

@ -533,6 +533,7 @@ menuitem:not([type]):not(.menuitem-tooltip):not(.menuitem-iconic-tooltip) {
list-style-image: url("moz-icon://stock/gtk-info?size=menu");
}
#placesContext_open\:newprivatewindow,
#privateBrowsingItem {
list-style-image: url("chrome://browser/skin/Privacy-16.png");
}

View File

@ -200,6 +200,11 @@ menuitem[command="placesCmd_open:window"] {
-moz-image-region: rect(0px 80px 16px 64px);
}
#placesContext_open\:newprivatewindow,
menuitem[command="placesCmd_open:privatewindow"] {
list-style-image: url("chrome://browser/skin/Privacy-16.png");
}
#placesContext_open\:newtab,
menuitem[command="placesCmd_open:tab"] {
list-style-image: url("chrome://browser/skin/Toolbar-small.png");