Bug 1044351 - prevent popup blocker from blocking windows opened by loaded javascript: URIs by allowing popups for such loads from the location bar. r=mak/mrbkap

This commit is contained in:
Gijs Kruitbosch 2015-06-16 16:26:36 -04:00
parent c202ec98d9
commit 6ac096ebe6
6 changed files with 84 additions and 2 deletions

View File

@ -351,7 +351,8 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
allowThirdPartyFixup: true,
disallowInheritPrincipal: !mayInheritPrincipal,
allowPinnedTabHostChange: true,
postData: postData
postData: postData,
allowPopups: url.startsWith("javascript:"),
});
// Ensure the start of the URL is visible for UX reasons:
this.selectionStart = this.selectionEnd = 0;

View File

@ -188,6 +188,7 @@ function whereToOpenLink( e, ignoreButton, ignoreAlt )
* relatedToCurrent (boolean)
* skipTabAnimation (boolean)
* allowPinnedTabHostChange (boolean)
* allowPopups (boolean)
*/
function openUILinkIn(url, where, aAllowThirdPartyFixup, aPostData, aReferrerURI) {
var params;
@ -230,6 +231,7 @@ function openLinkIn(url, where, params) {
var aSkipTabAnimation = params.skipTabAnimation;
var aAllowPinnedTabHostChange = !!params.allowPinnedTabHostChange;
var aNoReferrer = params.noReferrer;
var aAllowPopups = !!params.allowPopups;
if (where == "save") {
if (!aInitiatingDoc) {
@ -342,8 +344,13 @@ function openLinkIn(url, where, params) {
// i.e. it causes them not to load at all. Callers should strip
// "javascript:" from pasted strings to protect users from malicious URIs
// (see stripUnsafeProtocolOnPaste).
if (aDisallowInheritPrincipal && !(uriObj && uriObj.schemeIs("javascript")))
if (aDisallowInheritPrincipal && !(uriObj && uriObj.schemeIs("javascript"))) {
flags |= Ci.nsIWebNavigation.LOAD_FLAGS_DISALLOW_INHERIT_OWNER;
}
if (aAllowPopups) {
flags |= Ci.nsIWebNavigation.LOAD_FLAGS_ALLOW_POPUPS;
}
w.gBrowser.loadURIWithFlags(url, {
flags: flags,

View File

@ -868,6 +868,7 @@ this.PlacesUIUtils = {
}
aWindow.openUILinkIn(aNode.uri, aWhere, {
allowPopups: aNode.uri.startsWith("javascript:"),
inBackground: Services.prefs.getBoolPref("browser.tabs.loadBookmarksInBackground"),
private: aPrivate,
});

View File

@ -21,6 +21,9 @@ support-files =
[browser_475045.js]
[browser_555547.js]
[browser_bookmarkProperties_addKeywordForThisSearch.js]
[browser_bookmarklet_windowOpen.js]
support-files =
pageopeningwindow.html
[browser_bookmarksProperties.js]
[browser_drag_bookmarks_on_toolbar.js]
skip-if = e10s # Bug ?????? - test fails - "Number of dragged items should be the same. - Got 0, expected 1"

View File

@ -0,0 +1,61 @@
"use strict";
const TEST_URL = 'http://example.com/browser/browser/components/places/tests/browser/pageopeningwindow.html';
function makeBookmarkFor(url, keyword) {
return Promise.all([
PlacesUtils.bookmarks.insert({ parentGuid: PlacesUtils.bookmarks.unfiledGuid,
title: "bookmarklet",
url: url }),
PlacesUtils.keywords.insert({url: url,
keyword: keyword})
]);
}
add_task(function openKeywordBookmarkWithWindowOpen() {
// This is the current default, but let's not assume that...
yield new Promise((resolve, reject) => {
SpecialPowers.pushPrefEnv({ 'set': [[ 'browser.link.open_newwindow', 3 ],
[ 'dom.disable_open_during_load', true ]] },
resolve);
});
let moztab;
let tabOpened = BrowserTestUtils.openNewForegroundTab(gBrowser, "about:mozilla")
.then((tab) => { moztab = tab; });
let keywordForBM = "openmeatab";
let bookmarkInfo;
let bookmarkCreated =
makeBookmarkFor("javascript:void open('" + TEST_URL + "')", keywordForBM)
.then((values) => {
bookmarkInfo = values[0];
});
yield Promise.all([tabOpened, bookmarkCreated]);
registerCleanupFunction(function() {
return Promise.all([
PlacesUtils.bookmarks.remove(bookmarkInfo),
PlacesUtils.keywords.remove(keywordForBM)
]);
});
gURLBar.value = keywordForBM;
gURLBar.focus();
let tabCreatedPromise = BrowserTestUtils.waitForEvent(gBrowser.tabContainer, "TabOpen");
EventUtils.synthesizeKey("VK_RETURN", {});
info("Waiting for tab being created");
let {target: tab} = yield tabCreatedPromise;
info("Got tab");
let browser = tab.linkedBrowser;
if (!browser.currentURI || browser.currentURI.spec != TEST_URL) {
info("Waiting for browser load");
yield BrowserTestUtils.browserLoaded(browser);
}
is(browser.currentURI && browser.currentURI.spec, TEST_URL, "Tab with expected URL loaded.");
info("Waiting to remove tab");
yield Promise.all([ BrowserTestUtils.removeTab(tab),
BrowserTestUtils.removeTab(moztab) ]);
});

View File

@ -0,0 +1,9 @@
<meta charset="UTF-8">
Hi, I was opened via a <script>document.write(location.search ?
"popup call from the opened window... uh oh, that shouldn't happen!" :
"bookmarklet, and I will open a new window myself.")</script><br>
<script>
if (!location.search) {
open(location.href + "?donotopen=true", '_blank');
}
</script>