diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index bdac8a8d19de..58f5674ecd6a 100644 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -2281,18 +2281,17 @@ function BrowserTryToCloseWindow() window.close(); // WindowIsClosing does all the necessary checks } -function loadURI(uri, referrer, postData, allowThirdPartyFixup) -{ +function loadURI(uri, referrer, postData, allowThirdPartyFixup) { + if (postData === undefined) + postData = null; + + var flags = nsIWebNavigation.LOAD_FLAGS_NONE; + if (allowThirdPartyFixup) + flags |= nsIWebNavigation.LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP; + try { - if (postData === undefined) - postData = null; - var flags = nsIWebNavigation.LOAD_FLAGS_NONE; - if (allowThirdPartyFixup) { - flags = nsIWebNavigation.LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP; - } gBrowser.loadURIWithFlags(uri, flags, referrer, null, postData); - } catch (e) { - } + } catch (e) {} } function getShortcutOrURI(aURL, aPostDataRef, aMayInheritPrincipal) { @@ -5647,7 +5646,8 @@ function middleMousePaste(event) { // bar's behavior (stripsurroundingwhitespace) clipboard = clipboard.replace(/\s*\n\s*/g, ""); - let url = getShortcutOrURI(clipboard); + let mayInheritPrincipal = { value: false }; + let url = getShortcutOrURI(clipboard, mayInheritPrincipal); try { makeURI(url); } catch (ex) { @@ -5663,9 +5663,10 @@ function middleMousePaste(event) { Cu.reportError(ex); } - openUILink(url, - event, - true /* ignore the fact this is a middle click */); + // FIXME: Bug 631500, use openUILink directly + let where = whereToOpenLink(event, true); + openUILinkIn(url, where, + { disallowInheritPrincipal: !mayInheritPrincipal.value }); event.stopPropagation(); } diff --git a/browser/base/content/test/Makefile.in b/browser/base/content/test/Makefile.in index 724c6be831dd..dd7444851727 100644 --- a/browser/base/content/test/Makefile.in +++ b/browser/base/content/test/Makefile.in @@ -249,6 +249,7 @@ _BROWSER_FILES = \ test_wyciwyg_copying.html \ authenticate.sjs \ browser_minimize.js \ + browser_middleMouse_inherit.js \ $(NULL) ifneq (cocoa,$(MOZ_WIDGET_TOOLKIT)) diff --git a/browser/base/content/test/browser_middleMouse_inherit.js b/browser/base/content/test/browser_middleMouse_inherit.js new file mode 100644 index 000000000000..121cb6da2e10 --- /dev/null +++ b/browser/base/content/test/browser_middleMouse_inherit.js @@ -0,0 +1,55 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +const middleMousePastePref = "middlemouse.contentLoadURL"; +const autoScrollPref = "general.autoScroll"; +function test() { + waitForExplicitFinish(); + + Services.prefs.setBoolPref(middleMousePastePref, true); + Services.prefs.setBoolPref(autoScrollPref, false); + let tab = gBrowser.selectedTab = gBrowser.addTab(); + + registerCleanupFunction(function () { + Services.prefs.clearUserPref(middleMousePastePref); + Services.prefs.clearUserPref(autoScrollPref); + gBrowser.removeTab(tab); + }); + + addPageShowListener(function () { + let pagePrincipal = gBrowser.contentPrincipal; + + // copy javascript URI to the clipboard + let url = "javascript:1+1"; + waitForClipboard(url, + function() { + Components.classes["@mozilla.org/widget/clipboardhelper;1"] + .getService(Components.interfaces.nsIClipboardHelper) + .copyString(url); + }, + function () { + // Middle click on the content area + info("Middle clicking"); + EventUtils.sendMouseEvent({type: "click", button: 1}, gBrowser); + }, + function() { + ok(false, "Failed to copy URL to the clipboard"); + finish(); + } + ); + + addPageShowListener(function () { + is(gBrowser.currentURI.spec, url, "url loaded by middle click"); + ok(!gBrowser.contentPrincipal.equals(pagePrincipal), + "middle click load of " + url + " should produce a page with a different principal"); + finish(); + }); + }); +} + +function addPageShowListener(func) { + gBrowser.selectedBrowser.addEventListener("pageshow", function loadListener() { + gBrowser.selectedBrowser.removeEventListener("pageshow", loadListener, false); + func(); + }); +} diff --git a/browser/base/content/utilityOverlay.js b/browser/base/content/utilityOverlay.js index 778d71d9a00f..e869f13c65a4 100644 --- a/browser/base/content/utilityOverlay.js +++ b/browser/base/content/utilityOverlay.js @@ -196,6 +196,7 @@ function openLinkIn(url, where, params) { var aReferrerURI = params.referrerURI; var aRelatedToCurrent = params.relatedToCurrent; var aInBackground = params.inBackground; + var aDisallowInheritPrincipal = params.disallowInheritPrincipal; if (where == "save") { saveURL(url, null, null, true, null, aReferrerURI); @@ -264,7 +265,12 @@ function openLinkIn(url, where, params) { switch (where) { case "current": - w.loadURI(url, aReferrerURI, aPostData, aAllowThirdPartyFixup); + let flags = Ci.nsIWebNavigation.LOAD_FLAGS_NONE; + if (aAllowThirdPartyFixup) + flags |= Ci.nsIWebNavigation.LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP; + if (aDisallowInheritPrincipal) + flags |= Ci.nsIWebNavigation.LOAD_FLAGS_DISALLOW_INHERIT_OWNER; + w.gBrowser.loadURIWithFlags(url, flags, aReferrerURI, null, aPostData); break; case "tabshifted": loadInBackground = !loadInBackground;