Bug 902695 - Implement openURIInFrame in nsBrowserAccess (r=felipe)

This commit is contained in:
Bill McCloskey 2013-08-08 14:01:45 -07:00
parent c1bf9a2cec
commit a715205de5

View File

@ -4285,6 +4285,44 @@ function nsBrowserAccess() { }
nsBrowserAccess.prototype = { nsBrowserAccess.prototype = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsIBrowserDOMWindow, Ci.nsISupports]), 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) { openURI: function (aURI, aOpener, aWhere, aContext) {
var newWindow = null; var newWindow = null;
var isExternal = (aContext == Ci.nsIBrowserDOMWindow.OPEN_EXTERNAL); var isExternal = (aContext == Ci.nsIBrowserDOMWindow.OPEN_EXTERNAL);
@ -4311,41 +4349,8 @@ nsBrowserAccess.prototype = {
newWindow = openDialog(getBrowserURL(), "_blank", "all,dialog=no", url, null, null, null); newWindow = openDialog(getBrowserURL(), "_blank", "all,dialog=no", url, null, null, null);
break; break;
case Ci.nsIBrowserDOMWindow.OPEN_NEWTAB : case Ci.nsIBrowserDOMWindow.OPEN_NEWTAB :
let win, needToFocusWin; let browser = this._openURIInNewTab(aURI, aOpener, isExternal);
// 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);
newWindow = browser.contentWindow; newWindow = browser.contentWindow;
if (needToFocusWin || (!loadInBackground && isExternal))
newWindow.focus();
break; break;
default : // OPEN_CURRENTWINDOW or an illegal value default : // OPEN_CURRENTWINDOW or an illegal value
newWindow = content; newWindow = content;
@ -4362,6 +4367,17 @@ nsBrowserAccess.prototype = {
return newWindow; 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) { isTabContentWindow: function (aWindow) {
return gBrowser.browsers.some(function (browser) browser.contentWindow == aWindow); return gBrowser.browsers.some(function (browser) browser.contentWindow == aWindow);
}, },