mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-21 17:59:34 +00:00
Bug 674161: middle mouse paste should prevent inheriting the current page's principal, r=dao
--HG-- extra : transplant_source : p%9Eg%80%9D%A5%C5%A8%F1%A7%3F5%3B%93%C0%03%9A%D7%CE%5B
This commit is contained in:
parent
3f827bd303
commit
515bccb840
@ -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();
|
||||
}
|
||||
|
@ -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))
|
||||
|
55
browser/base/content/test/browser_middleMouse_inherit.js
Normal file
55
browser/base/content/test/browser_middleMouse_inherit.js
Normal file
@ -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();
|
||||
});
|
||||
}
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user