зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
3f827bd303
Коммит
515bccb840
|
@ -2281,18 +2281,17 @@ function BrowserTryToCloseWindow()
|
||||||
window.close(); // WindowIsClosing does all the necessary checks
|
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 {
|
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);
|
gBrowser.loadURIWithFlags(uri, flags, referrer, null, postData);
|
||||||
} catch (e) {
|
} catch (e) {}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getShortcutOrURI(aURL, aPostDataRef, aMayInheritPrincipal) {
|
function getShortcutOrURI(aURL, aPostDataRef, aMayInheritPrincipal) {
|
||||||
|
@ -5647,7 +5646,8 @@ function middleMousePaste(event) {
|
||||||
// bar's behavior (stripsurroundingwhitespace)
|
// bar's behavior (stripsurroundingwhitespace)
|
||||||
clipboard = clipboard.replace(/\s*\n\s*/g, "");
|
clipboard = clipboard.replace(/\s*\n\s*/g, "");
|
||||||
|
|
||||||
let url = getShortcutOrURI(clipboard);
|
let mayInheritPrincipal = { value: false };
|
||||||
|
let url = getShortcutOrURI(clipboard, mayInheritPrincipal);
|
||||||
try {
|
try {
|
||||||
makeURI(url);
|
makeURI(url);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
|
@ -5663,9 +5663,10 @@ function middleMousePaste(event) {
|
||||||
Cu.reportError(ex);
|
Cu.reportError(ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
openUILink(url,
|
// FIXME: Bug 631500, use openUILink directly
|
||||||
event,
|
let where = whereToOpenLink(event, true);
|
||||||
true /* ignore the fact this is a middle click */);
|
openUILinkIn(url, where,
|
||||||
|
{ disallowInheritPrincipal: !mayInheritPrincipal.value });
|
||||||
|
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
}
|
}
|
||||||
|
|
|
@ -249,6 +249,7 @@ _BROWSER_FILES = \
|
||||||
test_wyciwyg_copying.html \
|
test_wyciwyg_copying.html \
|
||||||
authenticate.sjs \
|
authenticate.sjs \
|
||||||
browser_minimize.js \
|
browser_minimize.js \
|
||||||
|
browser_middleMouse_inherit.js \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
ifneq (cocoa,$(MOZ_WIDGET_TOOLKIT))
|
ifneq (cocoa,$(MOZ_WIDGET_TOOLKIT))
|
||||||
|
|
|
@ -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 aReferrerURI = params.referrerURI;
|
||||||
var aRelatedToCurrent = params.relatedToCurrent;
|
var aRelatedToCurrent = params.relatedToCurrent;
|
||||||
var aInBackground = params.inBackground;
|
var aInBackground = params.inBackground;
|
||||||
|
var aDisallowInheritPrincipal = params.disallowInheritPrincipal;
|
||||||
|
|
||||||
if (where == "save") {
|
if (where == "save") {
|
||||||
saveURL(url, null, null, true, null, aReferrerURI);
|
saveURL(url, null, null, true, null, aReferrerURI);
|
||||||
|
@ -264,7 +265,12 @@ function openLinkIn(url, where, params) {
|
||||||
|
|
||||||
switch (where) {
|
switch (where) {
|
||||||
case "current":
|
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;
|
break;
|
||||||
case "tabshifted":
|
case "tabshifted":
|
||||||
loadInBackground = !loadInBackground;
|
loadInBackground = !loadInBackground;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче