зеркало из https://github.com/mozilla/gecko-dev.git
Bug 606678 - use openLinkIn in nsContextMenu ("Open Link in New Tab" shouldn't add tabs to popups). r=gavin a=b
--HG-- extra : rebase_source : c76eb56bdcdb55bf965b5c3adebfeb6720a733db
This commit is contained in:
Родитель
f8ba8b5653
Коммит
eddb3a79c9
|
@ -5200,8 +5200,7 @@ function handleLinkClick(event, href, linkNode) {
|
|||
}
|
||||
|
||||
urlSecurityCheck(href, doc.nodePrincipal);
|
||||
openLinkIn(href, where, { fromContent: true,
|
||||
referrerURI: doc.documentURIObject,
|
||||
openLinkIn(href, where, { referrerURI: doc.documentURIObject,
|
||||
charset: doc.characterSet });
|
||||
event.preventDefault();
|
||||
return true;
|
||||
|
|
|
@ -683,18 +683,29 @@ nsContextMenu.prototype = {
|
|||
|
||||
// Open linked-to URL in a new window.
|
||||
openLink : function () {
|
||||
openNewWindowWith(this.linkURL, this.target.ownerDocument, null, false);
|
||||
var doc = this.target.ownerDocument;
|
||||
urlSecurityCheck(this.linkURL, doc.nodePrincipal);
|
||||
openLinkIn(this.linkURL, "window",
|
||||
{ charset: doc.characterSet,
|
||||
referrerURI: doc.documentURIObject });
|
||||
},
|
||||
|
||||
// Open linked-to URL in a new tab.
|
||||
openLinkInTab: function() {
|
||||
openNewTabWith(this.linkURL, this.target.ownerDocument, null, null, false);
|
||||
var doc = this.target.ownerDocument;
|
||||
urlSecurityCheck(this.linkURL, doc.nodePrincipal);
|
||||
openLinkIn(this.linkURL, "tab",
|
||||
{ charset: doc.characterSet,
|
||||
referrerURI: doc.documentURIObject });
|
||||
},
|
||||
|
||||
// open URL in current tab
|
||||
openLinkInCurrent: function() {
|
||||
openUILinkIn(this.linkURL, "current", null, null,
|
||||
this.target.ownerDocument.documentURIObject);
|
||||
var doc = this.target.ownerDocument;
|
||||
urlSecurityCheck(this.linkURL, doc.nodePrincipal);
|
||||
openLinkIn(this.linkURL, "current",
|
||||
{ charset: doc.characterSet,
|
||||
referrerURI: doc.documentURIObject });
|
||||
},
|
||||
|
||||
// Open frame in a new tab.
|
||||
|
@ -702,9 +713,9 @@ nsContextMenu.prototype = {
|
|||
var doc = this.target.ownerDocument;
|
||||
var frameURL = doc.location.href;
|
||||
var referrer = doc.referrer;
|
||||
|
||||
return openNewTabWith(frameURL, null, null, null, false,
|
||||
referrer ? makeURI(referrer) : null);
|
||||
openLinkIn(frameURL, "tab",
|
||||
{ charset: doc.characterSet,
|
||||
referrerURI: referrer ? makeURI(referrer) : null });
|
||||
},
|
||||
|
||||
// Reload clicked-in frame.
|
||||
|
@ -717,9 +728,9 @@ nsContextMenu.prototype = {
|
|||
var doc = this.target.ownerDocument;
|
||||
var frameURL = doc.location.href;
|
||||
var referrer = doc.referrer;
|
||||
|
||||
return openNewWindowWith(frameURL, null, null, false,
|
||||
referrer ? makeURI(referrer) : null);
|
||||
openLinkIn(frameURL, "window",
|
||||
{ charset: doc.characterSet,
|
||||
referrerURI: referrer ? makeURI(referrer) : null });
|
||||
},
|
||||
|
||||
// Open clicked-in frame in the same window.
|
||||
|
|
|
@ -71,9 +71,12 @@ function test2Setup() {
|
|||
var contentAreaContextMenu = document.getElementById("contentAreaContextMenu");
|
||||
var contextMenu = new nsContextMenu(contentAreaContextMenu, gBrowser);
|
||||
|
||||
test2tab = contextMenu.openFrameInTab();
|
||||
ok(test2tab instanceof XULElement, "openFrameInTab() should return an element (non-null)");
|
||||
is(test2tab.tagName, "tab", "openFrameInTab() should return a *tab* element");
|
||||
gBrowser.tabContainer.addEventListener("TabOpen", function (event) {
|
||||
test2tab = event.target;
|
||||
gBrowser.tabContainer.removeEventListener("TabOpen", arguments.callee, false);
|
||||
}, false);
|
||||
contextMenu.openFrameInTab();
|
||||
ok(test2tab, "openFrameInTab() opened a tab");
|
||||
|
||||
gBrowser.selectedTab = test2tab;
|
||||
|
||||
|
@ -104,16 +107,22 @@ function test3Setup() {
|
|||
var contentAreaContextMenu = document.getElementById("contentAreaContextMenu");
|
||||
var contextMenu = new nsContextMenu(contentAreaContextMenu, gBrowser);
|
||||
|
||||
test3window = contextMenu.openFrame();
|
||||
ok(test3window instanceof Window, "openFrame() should return a window (non-null) ");
|
||||
Services.ww.registerNotification(function (aSubject, aTopic, aData) {
|
||||
if (aTopic == "domwindowopened")
|
||||
test3window = aSubject;
|
||||
Services.ww.unregisterNotification(arguments.callee);
|
||||
});
|
||||
|
||||
contextMenu.openFrame();
|
||||
|
||||
intervalID = setInterval(testOpenFrame, 3000);
|
||||
}
|
||||
|
||||
function testOpenFrame() {
|
||||
if (test3window.content.location.href == "about:blank")
|
||||
// Wait another cycle
|
||||
if (!test3window || test3window.content.location.href == "about:blank") {
|
||||
info("testOpenFrame: Wait another cycle");
|
||||
return;
|
||||
}
|
||||
|
||||
clearInterval(intervalID);
|
||||
|
||||
|
|
|
@ -174,7 +174,7 @@ function openUILinkIn(url, where, aAllowThirdPartyFixup, aPostData, aReferrerURI
|
|||
};
|
||||
}
|
||||
|
||||
params.fromContent = false;
|
||||
params.fromChrome = true;
|
||||
|
||||
openLinkIn(url, where, params);
|
||||
}
|
||||
|
@ -183,7 +183,7 @@ function openLinkIn(url, where, params) {
|
|||
if (!where || !url)
|
||||
return;
|
||||
|
||||
var aFromContent = params.fromContent;
|
||||
var aFromChrome = params.fromChrome;
|
||||
var aAllowThirdPartyFixup = params.allowThirdPartyFixup;
|
||||
var aPostData = params.postData;
|
||||
var aCharset = params.charset;
|
||||
|
@ -229,21 +229,14 @@ function openLinkIn(url, where, params) {
|
|||
sa.AppendElement(aPostData);
|
||||
sa.AppendElement(allowThirdPartyFixupSupports);
|
||||
|
||||
var ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
|
||||
getService(Ci.nsIWindowWatcher);
|
||||
|
||||
ww.openWindow(w || window,
|
||||
getBrowserURL(),
|
||||
null,
|
||||
"chrome,dialog=no,all",
|
||||
sa);
|
||||
|
||||
Services.ww.openWindow(w || window, getBrowserURL(),
|
||||
null, "chrome,dialog=no,all", sa);
|
||||
return;
|
||||
}
|
||||
|
||||
var loadInBackground = aFromContent ?
|
||||
getBoolPref("browser.tabs.loadInBackground") :
|
||||
getBoolPref("browser.tabs.loadBookmarksInBackground");
|
||||
var loadInBackground = aFromChrome ?
|
||||
getBoolPref("browser.tabs.loadBookmarksInBackground") :
|
||||
getBoolPref("browser.tabs.loadInBackground");
|
||||
|
||||
if (where == "current" && w.gBrowser.selectedTab.pinned) {
|
||||
try {
|
||||
|
@ -535,37 +528,25 @@ function makeURLAbsolute(aBase, aUrl)
|
|||
* There will be no security check.
|
||||
*/
|
||||
function openNewTabWith(aURL, aDocument, aPostData, aEvent,
|
||||
aAllowThirdPartyFixup, aReferrer)
|
||||
{
|
||||
aAllowThirdPartyFixup, aReferrer) {
|
||||
if (aDocument)
|
||||
urlSecurityCheck(aURL, aDocument.nodePrincipal);
|
||||
|
||||
var loadInBackground = getBoolPref("browser.tabs.loadInBackground");
|
||||
|
||||
if (aEvent && aEvent.shiftKey)
|
||||
loadInBackground = !loadInBackground;
|
||||
|
||||
// As in openNewWindowWith(), we want to pass the charset of the
|
||||
// current document over to a new tab.
|
||||
var wintype = document.documentElement.getAttribute("windowtype");
|
||||
var originCharset;
|
||||
if (wintype == "navigator:browser")
|
||||
// current document over to a new tab.
|
||||
var originCharset = aDocument && aDocument.characterSet;
|
||||
if (!originCharset &&
|
||||
document.documentElement.getAttribute("windowtype") == "navigator:browser")
|
||||
originCharset = window.content.document.characterSet;
|
||||
|
||||
// open link in new tab
|
||||
var referrerURI = aDocument ? aDocument.documentURIObject : aReferrer;
|
||||
var browser = top.document.getElementById("content");
|
||||
return browser.loadOneTab(aURL, {
|
||||
referrerURI: referrerURI,
|
||||
charset: originCharset,
|
||||
postData: aPostData,
|
||||
inBackground: loadInBackground,
|
||||
allowThirdPartyFixup: aAllowThirdPartyFixup});
|
||||
openLinkIn(aURL, aEvent && aEvent.shiftKey ? "tabshifted" : "tab",
|
||||
{ charset: originCharset,
|
||||
postData: aPostData,
|
||||
allowThirdPartyFixup: aAllowThirdPartyFixup,
|
||||
referrerURI: aDocument ? aDocument.documentURIObject : aReferrer });
|
||||
}
|
||||
|
||||
function openNewWindowWith(aURL, aDocument, aPostData, aAllowThirdPartyFixup,
|
||||
aReferrer)
|
||||
{
|
||||
function openNewWindowWith(aURL, aDocument, aPostData, aAllowThirdPartyFixup, aReferrer) {
|
||||
if (aDocument)
|
||||
urlSecurityCheck(aURL, aDocument.nodePrincipal);
|
||||
|
||||
|
@ -573,15 +554,16 @@ function openNewWindowWith(aURL, aDocument, aPostData, aAllowThirdPartyFixup,
|
|||
// document with a character set, then extract the current charset menu
|
||||
// setting from the current document and use it to initialize the new browser
|
||||
// window...
|
||||
var charsetArg = null;
|
||||
var wintype = document.documentElement.getAttribute("windowtype");
|
||||
if (wintype == "navigator:browser")
|
||||
charsetArg = "charset=" + window.content.document.characterSet;
|
||||
var originCharset = aDocument && aDocument.characterSet;
|
||||
if (!originCharset &&
|
||||
document.documentElement.getAttribute("windowtype") == "navigator:browser")
|
||||
originCharset = window.content.document.characterSet;
|
||||
|
||||
var referrerURI = aDocument ? aDocument.documentURIObject : aReferrer;
|
||||
return window.openDialog(getBrowserURL(), "_blank", "chrome,all,dialog=no",
|
||||
aURL, charsetArg, referrerURI, aPostData,
|
||||
aAllowThirdPartyFixup);
|
||||
openLinkIn(aURL, "window",
|
||||
{ charset: originCharset,
|
||||
postData: aPostData,
|
||||
allowThirdPartyFixup: aAllowThirdPartyFixup,
|
||||
referrerURI: aDocument ? aDocument.documentURIObject : aReferrer });
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Загрузка…
Ссылка в новой задаче