Bug 1051017 - Add browser.contentWindowAsCPOW and browser.contentDocumentAsCPOW (r=mconley,mrbkap)

This commit is contained in:
Bill McCloskey 2014-08-20 12:49:11 -07:00
parent 8652680f22
commit a15b49d6f6
15 changed files with 51 additions and 90 deletions

View File

@ -38,7 +38,7 @@
<commandset id="editMenuCommands"/>
<command id="View:PageSource" oncommand="BrowserViewSourceOfDocument(content.document);" observes="isImage"/>
<command id="View:PageSource" oncommand="BrowserViewSourceOfDocument(window.gBrowser.selectedBrowser.contentDocumentAsCPOW);" observes="isImage"/>
<command id="View:PageInfo" oncommand="BrowserPageInfo();"/>
<command id="View:FullScreen" oncommand="BrowserFullScreen();"/>
<command id="cmd_find"

View File

@ -1120,11 +1120,15 @@ var gBrowserInit = {
// This pageshow listener needs to be registered before we may call
// swapBrowsersAndCloseOther() to receive pageshow events fired by that.
gBrowser.addEventListener("pageshow", function(event) {
// Filter out events that are not about the document load we are interested in
if (content && event.target == content.document)
setTimeout(pageShowEventHandlers, 0, event.persisted);
}, true);
if (!gMultiProcessBrowser) {
// pageshow handlers are being migrated to
// content.js. Eventually this code should be removed.
gBrowser.addEventListener("pageshow", function(event) {
// Filter out events that are not about the document load we are interested in
if (content && event.target == content.document)
setTimeout(pageShowEventHandlers, 0, event.persisted);
}, true);
}
if (uriToLoad && uriToLoad != "about:blank") {
if (uriToLoad instanceof Ci.nsISupportsArray) {
@ -2266,7 +2270,7 @@ function BrowserPageInfo(doc, initialTab, imageElement) {
var args = {doc: doc, initialTab: initialTab, imageElement: imageElement};
var windows = Services.wm.getEnumerator("Browser:page-info");
var documentURL = doc ? doc.location : window.content.document.location;
var documentURL = doc ? doc.location : window.gBrowser.selectedBrowser.contentDocumentAsCPOW.location;
// Check for windows matching the url
while (windows.hasMoreElements()) {
@ -4377,10 +4381,6 @@ nsBrowserAccess.prototype = {
isTabContentWindow: function (aWindow) {
return gBrowser.browsers.some(function (browser) browser.contentWindow == aWindow);
},
get contentWindow() {
return gBrowser.contentWindow;
}
}
function getTogglableToolbars() {

View File

@ -129,8 +129,6 @@ chatBrowserAccess.prototype = {
},
isTabContentWindow: function (aWindow) this.contentWindow == aWindow,
get contentWindow() document.getElementById("chatter").contentWindow
};
</script>

View File

@ -1087,10 +1087,6 @@ nsBrowserAccess.prototype = {
isTabContentWindow: function(aWindow) {
return Browser.browsers.some(function (browser) browser.contentWindow == aWindow);
},
get contentWindow() {
return Browser.selectedBrowser.contentWindow;
}
};
/**

View File

@ -12,7 +12,7 @@
interface nsIDocShellTreeItem;
[scriptable, uuid(6cd89e60-1060-491e-8c31-ce969435ec56)]
[scriptable, uuid(05b5b240-1f61-11e4-8c21-0800200c9a66)]
interface nsIDocShellTreeOwner : nsISupports
{
/*
@ -64,9 +64,6 @@ 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.

View File

@ -3995,25 +3995,8 @@ nsGlobalWindow::GetContent(JSContext* aCx,
return;
}
if (!nsContentUtils::IsCallerChrome() || !IsChromeWindow()) {
aError.Throw(NS_ERROR_FAILURE);
return;
}
// Something tries to get .content on a ChromeWindow, try to fetch the CPOW.
nsCOMPtr<nsIDocShellTreeOwner> treeOwner = GetTreeOwner();
if (!treeOwner) {
aError.Throw(NS_ERROR_FAILURE);
return;
}
JS::Rooted<JS::Value> val(aCx, JS::NullValue());
aError = treeOwner->GetContentWindow(aCx, &val);
if (aError.Failed()) {
return;
}
aRetval.set(val.toObjectOrNull());
aRetval.set(nullptr);
return;
}
already_AddRefed<nsIDOMWindow>

View File

@ -9,7 +9,7 @@ interface nsIDOMWindow;
interface nsIURI;
interface nsIFrameLoaderOwner;
[scriptable, uuid(e420bd32-b8c4-4b47-8cca-09e0bddbb0c3)]
[scriptable, uuid(699b8f60-2898-11e4-8c21-0800200c9a66)]
/**
* The C++ source has access to the browser script source through
@ -92,12 +92,5 @@ 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;
};

View File

@ -361,16 +361,6 @@ nsDocShellTreeOwner::GetPrimaryContentShell(nsIDocShellTreeItem** aShell)
return NS_OK;
}
NS_IMETHODIMP
nsDocShellTreeOwner::GetContentWindow(JSContext* aCx,
JS::MutableHandle<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)

View File

@ -3028,10 +3028,6 @@ nsBrowserAccess.prototype = {
isTabContentWindow: function(aWindow) {
return BrowserApp.getBrowserForWindow(aWindow) != null;
},
get contentWindow() {
return BrowserApp.selectedBrowser.contentWindow;
}
};

View File

@ -625,6 +625,20 @@ RemoteBrowserElementInterposition.getters.docShell = function(addon, target) {
return remoteChromeGlobal.docShell;
};
RemoteBrowserElementInterposition.getters.contentWindow = function(addon, target) {
return target.contentWindowAsCPOW;
};
RemoteBrowserElementInterposition.getters.contentDocument = function(addon, target) {
return target.contentDocumentAsCPOW;
};
let ChromeWindowInterposition = new Interposition(EventTargetInterposition);
ChromeWindowInterposition.getters.content = function(addon, target) {
return target.gBrowser.selectedBrowser.contentWindowAsCPOW;
};
let RemoteAddonsParent = {
init: function() {
let mm = Cc["@mozilla.org/globalmessagemanager;1"].getService(Ci.nsIMessageListenerManager);
@ -660,6 +674,7 @@ let RemoteAddonsParent = {
register("ContentDocShellTreeItem", ContentDocShellTreeItemInterposition);
register("ContentDocument", ContentDocumentInterposition);
register("RemoteBrowserElement", RemoteBrowserElementInterposition);
register("ChromeWindow", ChromeWindowInterposition);
return result;
},

View File

@ -94,6 +94,10 @@ AddonInterpositionService.prototype = {
return "RemoteBrowserElement";
}
if (target instanceof Ci.nsIDOMChromeWindow) {
return "ChromeWindow";
}
if (target instanceof Ci.nsIDOMEventTarget) {
return "EventTarget";
}

View File

@ -402,6 +402,10 @@
readonly="true"
onget="return this._contentWindow || (this._contentWindow = this.docShell.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIDOMWindow));"/>
<property name="contentWindowAsCPOW"
readonly="true"
onget="return this.contentWindow;"/>
<property name="sessionHistory"
onget="return this.webNavigation.sessionHistory;"
readonly="true"/>
@ -422,6 +426,10 @@
onget="return this.webNavigation.document;"
readonly="true"/>
<property name="contentDocumentAsCPOW"
onget="return this.contentDocument;"
readonly="true"/>
<property name="contentTitle"
onget="return this.contentDocument.title;"
readonly="true"/>

View File

@ -124,11 +124,19 @@
<field name="_contentWindow">null</field>
<property name="contentWindow"
onget="return null"
readonly="true"/>
<property name="contentWindowAsCPOW"
onget="return this._contentWindow"
readonly="true"/>
<property name="contentDocument"
onget="return this.contentWindow ? this.contentWindow.document : null"
onget="return null"
readonly="true"/>
<property name="contentDocumentAsCPOW"
onget="return this.contentWindowAsCPOW ? this.contentWindowAsCPOW.document : null"
readonly="true"/>
<field name="_syncHandler">null</field>

View File

@ -250,25 +250,6 @@ NS_IMETHODIMP nsChromeTreeOwner::GetPrimaryContentShell(nsIDocShellTreeItem** aS
return mXULWindow->GetPrimaryContentShell(aShell);
}
NS_IMETHODIMP
nsChromeTreeOwner::GetContentWindow(JSContext* aCx, JS::MutableHandle<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)
{

View File

@ -312,14 +312,6 @@ nsContentTreeOwner::GetPrimaryContentShell(nsIDocShellTreeItem** aShell)
return mXULWindow->GetPrimaryContentShell(aShell);
}
NS_IMETHODIMP
nsContentTreeOwner::GetContentWindow(JSContext* aCx,
JS::MutableHandle<JS::Value> aVal)
{
NS_ENSURE_STATE(mXULWindow);
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsContentTreeOwner::SizeShellTo(nsIDocShellTreeItem* aShellItem,
int32_t aCX, int32_t aCY)
{