зеркало из https://github.com/mozilla/gecko-dev.git
Bug 902695 - Implement openURIInFrame in nsBrowserAccess (r=felipe)
This commit is contained in:
Родитель
c1bf9a2cec
Коммит
a715205de5
|
@ -4285,6 +4285,44 @@ function nsBrowserAccess() { }
|
|||
nsBrowserAccess.prototype = {
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIBrowserDOMWindow, Ci.nsISupports]),
|
||||
|
||||
_openURIInNewTab: function(aURI, aOpener, aIsExternal) {
|
||||
let win, needToFocusWin;
|
||||
|
||||
// try the current window. if we're in a popup, fall back on the most recent browser window
|
||||
if (window.toolbar.visible)
|
||||
win = window;
|
||||
else {
|
||||
let isPrivate = PrivateBrowsingUtils.isWindowPrivate(aOpener || window);
|
||||
win = RecentWindow.getMostRecentBrowserWindow({private: isPrivate});
|
||||
needToFocusWin = true;
|
||||
}
|
||||
|
||||
if (!win) {
|
||||
// we couldn't find a suitable window, a new one needs to be opened.
|
||||
return null;
|
||||
}
|
||||
|
||||
if (aIsExternal && (!aURI || aURI.spec == "about:blank")) {
|
||||
win.BrowserOpenTab(); // this also focuses the location bar
|
||||
win.focus();
|
||||
return win.gBrowser.selectedBrowser;
|
||||
}
|
||||
|
||||
let loadInBackground = gPrefService.getBoolPref("browser.tabs.loadDivertedInBackground");
|
||||
let referrer = aOpener ? makeURI(aOpener.location.href) : null;
|
||||
|
||||
let tab = win.gBrowser.loadOneTab(aURI ? aURI.spec : "about:blank", {
|
||||
referrerURI: referrer,
|
||||
fromExternal: aIsExternal,
|
||||
inBackground: loadInBackground});
|
||||
let browser = win.gBrowser.getBrowserForTab(tab);
|
||||
|
||||
if (needToFocusWin || (!loadInBackground && aIsExternal))
|
||||
win.focus();
|
||||
|
||||
return browser;
|
||||
},
|
||||
|
||||
openURI: function (aURI, aOpener, aWhere, aContext) {
|
||||
var newWindow = null;
|
||||
var isExternal = (aContext == Ci.nsIBrowserDOMWindow.OPEN_EXTERNAL);
|
||||
|
@ -4311,41 +4349,8 @@ nsBrowserAccess.prototype = {
|
|||
newWindow = openDialog(getBrowserURL(), "_blank", "all,dialog=no", url, null, null, null);
|
||||
break;
|
||||
case Ci.nsIBrowserDOMWindow.OPEN_NEWTAB :
|
||||
let win, needToFocusWin;
|
||||
|
||||
// try the current window. if we're in a popup, fall back on the most recent browser window
|
||||
if (window.toolbar.visible)
|
||||
win = window;
|
||||
else {
|
||||
let isPrivate = PrivateBrowsingUtils.isWindowPrivate(aOpener || window);
|
||||
win = RecentWindow.getMostRecentBrowserWindow({private: isPrivate});
|
||||
needToFocusWin = true;
|
||||
}
|
||||
|
||||
if (!win) {
|
||||
// we couldn't find a suitable window, a new one needs to be opened.
|
||||
return null;
|
||||
}
|
||||
|
||||
if (isExternal && (!aURI || aURI.spec == "about:blank")) {
|
||||
win.BrowserOpenTab(); // this also focuses the location bar
|
||||
win.focus();
|
||||
newWindow = win.content;
|
||||
break;
|
||||
}
|
||||
|
||||
let loadInBackground = gPrefService.getBoolPref("browser.tabs.loadDivertedInBackground");
|
||||
let referrer = aOpener ? makeURI(aOpener.location.href) : null;
|
||||
|
||||
let tab = win.gBrowser.loadOneTab(aURI ? aURI.spec : "about:blank", {
|
||||
referrerURI: referrer,
|
||||
fromExternal: isExternal,
|
||||
inBackground: loadInBackground});
|
||||
let browser = win.gBrowser.getBrowserForTab(tab);
|
||||
|
||||
let browser = this._openURIInNewTab(aURI, aOpener, isExternal);
|
||||
newWindow = browser.contentWindow;
|
||||
if (needToFocusWin || (!loadInBackground && isExternal))
|
||||
newWindow.focus();
|
||||
break;
|
||||
default : // OPEN_CURRENTWINDOW or an illegal value
|
||||
newWindow = content;
|
||||
|
@ -4362,6 +4367,17 @@ nsBrowserAccess.prototype = {
|
|||
return newWindow;
|
||||
},
|
||||
|
||||
openURIInFrame: function browser_openURIInFrame(aURI, aOpener, aWhere, aContext) {
|
||||
if (aWhere != Ci.nsIBrowserDOMWindow.OPEN_NEWTAB) {
|
||||
dump("Error: openURIInFrame can only open in new tabs");
|
||||
return null;
|
||||
}
|
||||
|
||||
var isExternal = (aContext == Ci.nsIBrowserDOMWindow.OPEN_EXTERNAL);
|
||||
let browser = this._openURIInNewTab(aURI, aOpener, isExternal);
|
||||
return browser.QueryInterface(Ci.nsIFrameLoaderOwner);
|
||||
},
|
||||
|
||||
isTabContentWindow: function (aWindow) {
|
||||
return gBrowser.browsers.some(function (browser) browser.contentWindow == aWindow);
|
||||
},
|
||||
|
|
Загрузка…
Ссылка в новой задаче