Skip to content

Commit

Permalink
Bug 1261842 - Make initial browser remote sooner if we're defaulting …
Browse files Browse the repository at this point in the history
…to using remote tabs. r=felipe

MozReview-Commit-ID: 9KVzuOkJFpW
  • Loading branch information
mikeconley committed Jun 8, 2016
1 parent b628cff commit 571c88b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 19 deletions.
62 changes: 44 additions & 18 deletions browser/base/content/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,30 @@ function RedirectLoad({ target: browser, data }) {
}
}

addEventListener("DOMContentLoaded", function onDCL() {
removeEventListener("DOMContentLoaded", onDCL);

// There are some windows, like macBrowserOverlay.xul, that
// load browser.js, but never load tabbrowser.xml. We can ignore
// those cases.
if (!gBrowser || !gBrowser.updateBrowserRemoteness) {
return;
}

window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(nsIWebNavigation)
.QueryInterface(Ci.nsIDocShellTreeItem).treeOwner
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIXULWindow)
.XULBrowserWindow = window.XULBrowserWindow;
window.QueryInterface(Ci.nsIDOMChromeWindow).browserDOMWindow =
new nsBrowserAccess();

let initBrowser =
document.getAnonymousElementByAttribute(gBrowser, "anonid", "initialBrowser");
gBrowser.updateBrowserRemoteness(initBrowser, gMultiProcessBrowser);
});

var gBrowserInit = {
delayedStartupFinished: false,

Expand Down Expand Up @@ -944,19 +968,11 @@ var gBrowserInit = {
mm.loadFrameScript("chrome://browser/content/content-UITour.js", true);
mm.loadFrameScript("chrome://global/content/manifestMessages.js", true);

window.messageManager.addMessageListener("Browser:LoadURI", RedirectLoad);

// initialize observers and listeners
// and give C++ access to gBrowser
XULBrowserWindow.init();
window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(nsIWebNavigation)
.QueryInterface(Ci.nsIDocShellTreeItem).treeOwner
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIXULWindow)
.XULBrowserWindow = window.XULBrowserWindow;
window.QueryInterface(Ci.nsIDOMChromeWindow).browserDOMWindow =
new nsBrowserAccess();

window.messageManager.addMessageListener("Browser:LoadURI", RedirectLoad);

if (!gMultiProcessBrowser) {
// There is a Content:Click message manually sent from content.
Expand Down Expand Up @@ -1103,6 +1119,13 @@ var gBrowserInit = {
// make sure it has a docshell
gBrowser.docShell;

// We must set usercontextid before updateBrowserRemoteness()
// so that the newly created remote tab child has correct usercontextid
if (tabToOpen.hasAttribute("usercontextid")) {
let usercontextid = tabToOpen.getAttribute("usercontextid");
gBrowser.selectedBrowser.setAttribute("usercontextid", usercontextid);
}

// If the browser that we're swapping in was remote, then we'd better
// be able to support remote browsers, and then make our selectedTab
// remote.
Expand All @@ -1112,14 +1135,12 @@ var gBrowserInit = {
throw new Error("Cannot drag a remote browser into a window " +
"without the remote tabs load context.");
}

// We must set usercontextid before updateBrowserRemoteness()
// so that the newly created remote tab child has correct usercontextid
if (tabToOpen.hasAttribute("usercontextid")) {
let usercontextid = tabToOpen.getAttribute("usercontextid");
gBrowser.selectedBrowser.setAttribute("usercontextid", usercontextid);
}
gBrowser.updateBrowserRemoteness(gBrowser.selectedBrowser, true);
} else if (gBrowser.selectedBrowser.isRemoteBrowser) {
// If the browser is remote, then it's implied that
// gMultiProcessBrowser is true. We need to flip the remoteness
// of this tab to false in order for the tab drag to work.
gBrowser.updateBrowserRemoteness(gBrowser.selectedBrowser, false);
}
gBrowser.swapBrowsersAndCloseOther(gBrowser.selectedTab, tabToOpen);
} catch(e) {
Expand Down Expand Up @@ -4198,10 +4219,15 @@ var XULBrowserWindow = {
forceInitialBrowserRemote: function() {
let initBrowser =
document.getAnonymousElementByAttribute(gBrowser, "anonid", "initialBrowser");
gBrowser.updateBrowserRemoteness(initBrowser, true);
return initBrowser.frameLoader.tabParent;
},

forceInitialBrowserNonRemote: function() {
let initBrowser =
document.getAnonymousElementByAttribute(gBrowser, "anonid", "initialBrowser");
gBrowser.updateBrowserRemoteness(initBrowser, false);
},

setDefaultStatus: function (status) {
this.defaultStatus = status;
this.updateStatusField();
Expand Down
1 change: 1 addition & 0 deletions xpfe/appshell/nsIXULBrowserWindow.idl
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ interface nsIXULBrowserWindow : nsISupports
*
*/
nsITabParent forceInitialBrowserRemote();
void forceInitialBrowserNonRemote();

/**
* Determines whether a load should continue.
Expand Down
2 changes: 1 addition & 1 deletion xpfe/appshell/nsXULWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1921,7 +1921,7 @@ NS_IMETHODIMP nsXULWindow::CreateNewContentWindow(int32_t aChromeFlags,
}
}

NS_ENSURE_STATE(xulWin->mPrimaryContentShell);
NS_ENSURE_STATE(xulWin->mPrimaryContentShell || xulWin->mPrimaryTabParent);

*_retval = newWindow;
NS_ADDREF(*_retval);
Expand Down

0 comments on commit 571c88b

Please sign in to comment.