Skip to content

Commit

Permalink
Bug 868859 - Make chromeWindow.content work in e10s. r=bz
Browse files Browse the repository at this point in the history
  • Loading branch information
evilpie committed May 8, 2013
1 parent 1d95c56 commit b82cb64
Show file tree
Hide file tree
Showing 12 changed files with 95 additions and 7 deletions.
4 changes: 4 additions & 0 deletions browser/base/content/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -4432,6 +4432,10 @@ nsBrowserAccess.prototype = {

isTabContentWindow: function (aWindow) {
return gBrowser.browsers.some(function (browser) browser.contentWindow == aWindow);
},

get contentWindow() {
return gBrowser.contentWindow;
}
}

Expand Down
4 changes: 4 additions & 0 deletions browser/metro/base/content/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1205,6 +1205,10 @@ nsBrowserAccess.prototype = {

isTabContentWindow: function(aWindow) {
return Browser.browsers.some(function (browser) browser.contentWindow == aWindow);
},

get contentWindow() {
return Browser.selectedBrowser.contentWindow;
}
};

Expand Down
5 changes: 4 additions & 1 deletion docshell/base/nsIDocShellTreeOwner.idl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

interface nsIDocShellTreeItem;

[scriptable, uuid(932f9f93-8e21-4728-a527-cafc64b4d831)]
[scriptable, uuid(6cd89e60-1060-491e-8c31-ce969435ec56)]
interface nsIDocShellTreeOwner : nsISupports
{
/*
Expand Down Expand Up @@ -64,6 +64,9 @@ interface nsIDocShellTreeOwner : nsISupports
*/
readonly attribute nsIDocShellTreeItem primaryContentShell;

[implicit_jscontext]
readonly attribute jsval contentWindow;

/*
Tells the tree owner to size its window or parent window in such a way
that the shell passed along will be the size specified.
Expand Down
22 changes: 22 additions & 0 deletions dom/base/nsGlobalWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3623,6 +3623,28 @@ nsGlobalWindow::GetContent(nsIDOMWindow** aContent)
return NS_OK;
}

NS_IMETHODIMP
nsGlobalWindow::GetScriptableContent(JSContext* aCx, JS::Value* aVal)
{
nsCOMPtr<nsIDOMWindow> content;
nsresult rv = GetContent(getter_AddRefs(content));
NS_ENSURE_SUCCESS(rv, rv);

if (content || !nsContentUtils::IsCallerChrome() || !IsChromeWindow()) {
JS::Rooted<JSObject*> global(aCx, JS_GetGlobalForScopeChain(aCx));
if (content && global) {
nsCOMPtr<nsIXPConnectJSObjectHolder> wrapper;
return nsContentUtils::WrapNative(aCx, global, content, aVal,
getter_AddRefs(wrapper));
}
return NS_ERROR_FAILURE;
}

// Something tries to get .content on a ChromeWindow, try to fetch the CPOW.
nsCOMPtr<nsIDocShellTreeOwner> treeOwner = GetTreeOwner();
NS_ENSURE_TRUE(treeOwner, NS_ERROR_FAILURE);
return treeOwner->GetContentWindow(aCx, aVal);
}

NS_IMETHODIMP
nsGlobalWindow::GetPrompter(nsIPrompt** aPrompt)
Expand Down
9 changes: 8 additions & 1 deletion dom/interfaces/base/nsIBrowserDOMWindow.idl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface nsIDOMWindow;
interface nsIURI;
interface nsIFrameLoaderOwner;

[scriptable, uuid(3ab89888-eb41-4dc8-b347-115555f47c80)]
[scriptable, uuid(e420bd32-b8c4-4b47-8cca-09e0bddbb0c3)]

/**
* The C++ source has access to the browser script source through
Expand Down Expand Up @@ -92,5 +92,12 @@ interface nsIBrowserDOMWindow : nsISupports
* currently open tab in this toplevel browser window.
*/
boolean isTabContentWindow(in nsIDOMWindow aWindow);

/**
* The contentWindow property of the currently selected browser.
* This is used to implement .content in remote-Firefox.
*/

readonly attribute jsval contentWindow;
};

5 changes: 4 additions & 1 deletion dom/interfaces/base/nsIDOMJSWindow.idl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include "domstubs.idl"

[scriptable, uuid(35b653f4-e679-4843-8391-89cb2f5a9ba4)]
[scriptable, uuid(f28c92a2-302a-4448-b589-46af599de352)]
interface nsIDOMJSWindow : nsISupports
{
void dump(in DOMString str);
Expand Down Expand Up @@ -66,4 +66,7 @@ interface nsIDOMJSWindow : nsISupports
* This property is "replaceable" in JavaScript.
*/
readonly attribute nsIDOMWindow frames;

[implicit_jscontext, binaryname(ScriptableContent)]
readonly attribute jsval content;
};
4 changes: 2 additions & 2 deletions dom/interfaces/base/nsIDOMWindow.idl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ interface nsIVariant;
* @see <http://www.whatwg.org/html/#window>
*/

[scriptable, uuid(be62660a-e3f6-409c-a4a9-378364a9526f)]
[scriptable, uuid(db8ea3c8-6997-460a-8715-0a1cbf20f15d)]
interface nsIDOMWindow : nsISupports
{
// the current browsing context
Expand Down Expand Up @@ -360,7 +360,7 @@ interface nsIDOMWindow : nsISupports
void sizeToContent();

/* [replaceable] content */
readonly attribute nsIDOMWindow content;
[noscript] readonly attribute nsIDOMWindow content;

/* [replaceable] prompter */
[noscript] readonly attribute nsIPrompt prompter;
Expand Down
3 changes: 3 additions & 0 deletions dom/ipc/test.xul
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@
},
openDialog: function(aType, aName, aFeatures, aArguments, aFrameElement) {
alert(aType + ", " + aName + ", " + aFeatures + ", " + aArguments + ", " + aFrameElement);
},
get contentWindow() {
return null;
}
}

Expand Down
11 changes: 10 additions & 1 deletion embedding/browser/webBrowser/nsDocShellTreeOwner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ nsDocShellTreeOwner::GetPrimaryContentShell(nsIDocShellTreeItem** aShell)
{
NS_ENSURE_ARG_POINTER(aShell);

if(mTreeOwner)
if (mTreeOwner)
return mTreeOwner->GetPrimaryContentShell(aShell);

*aShell = (mPrimaryContentShell ? mPrimaryContentShell : mWebBrowser->mDocShell);
Expand All @@ -362,6 +362,15 @@ nsDocShellTreeOwner::GetPrimaryContentShell(nsIDocShellTreeItem** aShell)
return NS_OK;
}

NS_IMETHODIMP
nsDocShellTreeOwner::GetContentWindow(JSContext* aCx, JS::Value* aVal)
{
if (mTreeOwner)
return mTreeOwner->GetContentWindow(aCx, aVal);

return NS_ERROR_NOT_IMPLEMENTED;
}

NS_IMETHODIMP
nsDocShellTreeOwner::SizeShellTo(nsIDocShellTreeItem* aShellItem,
int32_t aCX, int32_t aCY)
Expand Down
4 changes: 4 additions & 0 deletions mobile/android/chrome/content/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2521,6 +2521,10 @@ nsBrowserAccess.prototype = {

isTabContentWindow: function(aWindow) {
return BrowserApp.getBrowserForWindow(aWindow) != null;
},

get contentWindow() {
return BrowserApp.selectedBrowser.contentWindow;
}
};

Expand Down
21 changes: 21 additions & 0 deletions xpfe/appshell/src/nsChromeTreeOwner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
// Interfaces needed to include
#include "nsIPrompt.h"
#include "nsIAuthPrompt.h"
#include "nsIBrowserDOMWindow.h"
#include "nsIWebProgress.h"
#include "nsIWindowMediator.h"
#include "nsIDOMChromeWindow.h"
#include "nsIDOMNode.h"
#include "nsIDOMElement.h"
#include "nsIDOMNodeList.h"
Expand Down Expand Up @@ -248,6 +250,25 @@ NS_IMETHODIMP nsChromeTreeOwner::GetPrimaryContentShell(nsIDocShellTreeItem** aS
return mXULWindow->GetPrimaryContentShell(aShell);
}

NS_IMETHODIMP
nsChromeTreeOwner::GetContentWindow(JSContext* aCx, JS::Value* aVal)
{
NS_ENSURE_STATE(mXULWindow);

nsCOMPtr<nsIDOMWindow> domWin;
mXULWindow->GetWindowDOMWindow(getter_AddRefs(domWin));
nsCOMPtr<nsIDOMChromeWindow> chromeWin = do_QueryInterface(domWin);
if (!chromeWin)
return NS_OK;

nsCOMPtr<nsIBrowserDOMWindow> browserDOMWin;
chromeWin->GetBrowserDOMWindow(getter_AddRefs(browserDOMWin));
if (!browserDOMWin)
return NS_OK;

return browserDOMWin->GetContentWindow(aVal);
}

NS_IMETHODIMP nsChromeTreeOwner::SizeShellTo(nsIDocShellTreeItem* aShellItem,
int32_t aCX, int32_t aCY)
{
Expand Down
10 changes: 9 additions & 1 deletion xpfe/appshell/src/nsContentTreeOwner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,12 +293,20 @@ nsContentTreeOwner::ContentShellRemoved(nsIDocShellTreeItem* aContentShell)
return mXULWindow->ContentShellRemoved(aContentShell);
}

NS_IMETHODIMP nsContentTreeOwner::GetPrimaryContentShell(nsIDocShellTreeItem** aShell)
NS_IMETHODIMP
nsContentTreeOwner::GetPrimaryContentShell(nsIDocShellTreeItem** aShell)
{
NS_ENSURE_STATE(mXULWindow);
return mXULWindow->GetPrimaryContentShell(aShell);
}

NS_IMETHODIMP
nsContentTreeOwner::GetContentWindow(JSContext* aCx, JS::Value* aVal)
{
NS_ENSURE_STATE(mXULWindow);
return NS_ERROR_NOT_IMPLEMENTED;
}

NS_IMETHODIMP nsContentTreeOwner::SizeShellTo(nsIDocShellTreeItem* aShellItem,
int32_t aCX, int32_t aCY)
{
Expand Down

0 comments on commit b82cb64

Please sign in to comment.