Bug 456884 - Provide a way to open a link into private browsing mode; r=dao ui-r=madhava

This commit is contained in:
Ehsan Akhgari 2012-11-27 10:09:24 -05:00
parent b3dae48947
commit a3f8347fd1
7 changed files with 125 additions and 37 deletions

View File

@ -28,6 +28,12 @@
label="&openLinkCmd.label;"
accesskey="&openLinkCmd.accesskey;"
oncommand="gContextMenu.openLink();"/>
#ifdef MOZ_PER_WINDOW_PRIVATE_BROWSING
<menuitem id="context-openlinkprivate"
label="&openLinkInPrivateWindowCmd.label;"
accesskey="&openLinkInPrivateWindowCmd.accesskey;"
oncommand="gContextMenu.openLinkInPrivateWindow();"/>
#endif
<menuseparator id="context-sep-open"/>
<menuitem id="context-bookmarklink"
label="&bookmarkThisLinkCmd.label;"

View File

@ -138,7 +138,13 @@ nsContextMenu.prototype = {
}
var shouldShow = this.onSaveableLink || isMailtoInternal || this.onPlainTextLink;
#ifdef MOZ_PER_WINDOW_PRIVATE_BROWSING
var isWindowPrivate = PrivateBrowsingUtils.isWindowPrivate(window);
this.showItem("context-openlink", shouldShow && !isWindowPrivate);
this.showItem("context-openlinkprivate", shouldShow);
#else
this.showItem("context-openlink", shouldShow);
#endif
this.showItem("context-openlinkintab", shouldShow);
this.showItem("context-openlinkincurrent", this.onPlainTextLink);
this.showItem("context-sep-open", shouldShow);
@ -676,6 +682,16 @@ nsContextMenu.prototype = {
referrerURI: doc.documentURIObject });
},
// Open linked-to URL in a new private window.
openLinkInPrivateWindow : function () {
var doc = this.target.ownerDocument;
urlSecurityCheck(this.linkURL, doc.nodePrincipal);
openLinkIn(this.linkURL, "window",
{ charset: doc.characterSet,
referrerURI: doc.documentURIObject,
private: true });
},
// Open linked-to URL in a new tab.
openLinkInTab: function() {
var doc = this.target.ownerDocument;

View File

@ -50,6 +50,11 @@ MOCHITEST_FILES += \
test_contextmenu.html \
subtst_contextmenu.html \
$(NULL)
ifdef MOZ_PER_WINDOW_PRIVATE_BROWSING
MOCHITEST_FILES += \
privateBrowsingMode.js \
$(NULL)
endif
endif
# The following tests are disabled because they are unreliable:

View File

@ -0,0 +1,3 @@
// This file is only present in per-window private browsing buikds.
var perWindowPrivateBrowsing = true;

View File

@ -14,6 +14,8 @@ Browser context menu tests.
</div>
<pre id="test">
<script> var perWindowPrivateBrowsing = false; </script>
<script type="text/javascript" src="privateBrowsingMode.js"></script>
<script class="testbody" type="text/javascript">
/** Test for Login Manager: multiple login autocomplete. **/
@ -292,13 +294,24 @@ function runTest(testNum) {
case 3:
// Context menu for text link
checkContextMenu(["context-openlinkintab", true,
"context-openlink", true,
"---", null,
"context-bookmarklink", true,
"context-savelink", true,
"context-copylink", true
].concat(inspectItems));
if (perWindowPrivateBrowsing) {
checkContextMenu(["context-openlinkintab", true,
"context-openlink", true,
"context-openlinkprivate", true,
"---", null,
"context-bookmarklink", true,
"context-savelink", true,
"context-copylink", true
].concat(inspectItems));
} else {
checkContextMenu(["context-openlinkintab", true,
"context-openlink", true,
"---", null,
"context-bookmarklink", true,
"context-savelink", true,
"context-copylink", true
].concat(inspectItems));
}
closeContextMenu();
openContextMenuFor(mailto); // Invoke context menu for next test.
break;
@ -750,18 +763,34 @@ function runTest(testNum) {
// Context menu for selected text which matches valid URL pattern
if (SpecialPowers.Services.appinfo.OS == "Darwin") {
// This test is only enabled on Mac due to bug 736399.
checkContextMenu(["context-openlinkincurrent", true,
"context-openlinkintab", true,
"context-openlink", true,
"---", null,
"context-bookmarklink", true,
"context-savelink", true,
"context-copy", true,
"context-selectall", true,
"---", null,
"context-searchselect", true,
"context-viewpartialsource-selection", true
].concat(inspectItems));
if (perWindowPrivateBrowsing) {
checkContextMenu(["context-openlinkincurrent", true,
"context-openlinkintab", true,
"context-openlink", true,
"context-openlinkprivate", true,
"---", null,
"context-bookmarklink", true,
"context-savelink", true,
"context-copy", true,
"context-selectall", true,
"---", null,
"context-searchselect", true,
"context-viewpartialsource-selection", true
].concat(inspectItems));
} else {
checkContextMenu(["context-openlinkincurrent", true,
"context-openlinkintab", true,
"context-openlink", true,
"---", null,
"context-bookmarklink", true,
"context-savelink", true,
"context-copy", true,
"context-selectall", true,
"---", null,
"context-searchselect", true,
"context-viewpartialsource-selection", true
].concat(inspectItems));
}
}
closeContextMenu();
// clear the selection because following tests don't expect any selection
@ -772,22 +801,42 @@ function runTest(testNum) {
case 26:
// Context menu for image link
checkContextMenu(["context-openlinkintab", true,
"context-openlink", true,
"---", null,
"context-bookmarklink", true,
"context-savelink", true,
"context-copylink", true,
"---", null,
"context-viewimage", true,
"context-copyimage-contents", true,
"context-copyimage", true,
"---", null,
"context-saveimage", true,
"context-sendimage", true,
"context-setDesktopBackground", true,
"context-viewimageinfo", true
].concat(inspectItems));
if (perWindowPrivateBrowsing) {
checkContextMenu(["context-openlinkintab", true,
"context-openlink", true,
"context-openlinkprivate", true,
"---", null,
"context-bookmarklink", true,
"context-savelink", true,
"context-copylink", true,
"---", null,
"context-viewimage", true,
"context-copyimage-contents", true,
"context-copyimage", true,
"---", null,
"context-saveimage", true,
"context-sendimage", true,
"context-setDesktopBackground", true,
"context-viewimageinfo", true
].concat(inspectItems));
} else {
checkContextMenu(["context-openlinkintab", true,
"context-openlink", true,
"---", null,
"context-bookmarklink", true,
"context-savelink", true,
"context-copylink", true,
"---", null,
"context-viewimage", true,
"context-copyimage-contents", true,
"context-copyimage", true,
"---", null,
"context-saveimage", true,
"context-sendimage", true,
"context-setDesktopBackground", true,
"context-viewimageinfo", true
].concat(inspectItems));
}
closeContextMenu();
selectInputText(select_inputtext); // Select text prior to opening context menu.
openContextMenuFor(select_inputtext); // Invoke context menu for next test.

View File

@ -222,6 +222,7 @@ function openLinkIn(url, where, params) {
// Currently, this parameter works only for where=="tab" or "current"
var aIsUTF8 = params.isUTF8;
var aInitiatingDoc = params.initiatingDoc;
var isPrivate = params.private;
if (where == "save") {
if (!aInitiatingDoc) {
@ -267,8 +268,14 @@ function openLinkIn(url, where, params) {
sa.AppendElement(aPostData);
sa.AppendElement(allowThirdPartyFixupSupports);
Services.ww.openWindow(w || window, getBrowserURL(),
null, "chrome,dialog=no,all", sa);
let features = "chrome,dialog=no,all";
#ifdef MOZ_PER_WINDOW_PRIVATE_BROWSING
if (isPrivate) {
features += ",private";
}
#endif
Services.ww.openWindow(w || window, getBrowserURL(), null, features, sa);
return;
}

View File

@ -387,6 +387,8 @@ These should match what Safari and other Apple applications use on OS X Lion. --
<!ENTITY openLinkCmdInTab.accesskey "T">
<!ENTITY openLinkCmd.label "Open Link in New Window">
<!ENTITY openLinkCmd.accesskey "W">
<!ENTITY openLinkInPrivateWindowCmd.label "Open Link in New Private Window">
<!ENTITY openLinkInPrivateWindowCmd.accesskey "P">
<!ENTITY openLinkCmdInCurrent.label "Open Link">
<!ENTITY openLinkCmdInCurrent.accesskey "O">
<!ENTITY openFrameCmdInTab.label "Open Frame in New Tab">