Bug 754140 - Set mozapp status on iframe by sync message on the parent instead of injecting a script. r=jlebar

This commit is contained in:
Mounir Lamouri 2012-05-11 13:03:51 -07:00
parent 194d0680ac
commit a5f8d18abf
2 changed files with 22 additions and 15 deletions

View File

@ -16,6 +16,10 @@ function sendAsyncMsg(msg, data) {
sendAsyncMessage('browser-element-api:' + msg, data);
}
function sendSyncMsg(msg, data) {
return sendSyncMessage('browser-element-api:' + msg, data);
}
/**
* The BrowserElementChild implements one half of <iframe mozbrowser>.
* (The other half is, unsurprisingly, BrowserElementParent.)
@ -48,9 +52,12 @@ BrowserElementChild.prototype = {
//
// This is because mozapp iframes have some privileges which we don't want
// to extend to untrusted mozbrowser content.
//
// Set the window's isApp state by asking our parent if our iframe has the
// 'mozapp' attribute.
content.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindowUtils)
.setIsApp(false);
.setIsApp(sendSyncMsg('get-mozapp')[0]);
addEventListener('DOMTitleChanged',
this._titleChangedHandler.bind(this),

View File

@ -67,17 +67,17 @@ BrowserElementParent.prototype = {
}
},
_observeInProcessBrowserFrameShown: function(frameLoader, isMozApp) {
_observeInProcessBrowserFrameShown: function(frameLoader, data) {
debug("In-process browser frame shown " + frameLoader);
this._setUpMessageManagerListeners(frameLoader, isMozApp);
this._setUpMessageManagerListeners(frameLoader, data);
},
_observeRemoteBrowserFrameShown: function(frameLoader, isMozApp) {
_observeRemoteBrowserFrameShown: function(frameLoader, data) {
debug("Remote browser frame shown " + frameLoader);
this._setUpMessageManagerListeners(frameLoader, isMozApp);
this._setUpMessageManagerListeners(frameLoader, data);
},
_setUpMessageManagerListeners: function(frameLoader, isMozApp) {
_setUpMessageManagerListeners: function(frameLoader, data) {
let frameElement = frameLoader.QueryInterface(Ci.nsIFrameLoader).ownerElement;
if (!frameElement) {
debug("No frame element?");
@ -89,8 +89,9 @@ BrowserElementParent.prototype = {
// Messages we receive are handled by functions with parameters
// (frameElement, data), where |data| is the message manager's data object.
let self = this;
function addMessageListener(msg, handler) {
mm.addMessageListener('browser-element-api:' + msg, handler.bind(this, frameElement));
mm.addMessageListener('browser-element-api:' + msg, handler.bind(self, frameElement));
}
addMessageListener("hello", this._recvHello);
@ -99,15 +100,10 @@ BrowserElementParent.prototype = {
addMessageListener("loadend", this._fireEventFromMsg);
addMessageListener("titlechange", this._fireEventFromMsg);
addMessageListener("iconchange", this._fireEventFromMsg);
addMessageListener("get-mozapp", this._sendAppState);
mm.loadFrameScript("chrome://global/content/BrowserElementChild.js",
/* allowDelayedLoad = */ true);
if (isMozApp) {
mm.loadFrameScript("data:,content.QueryInterface(Ci.nsIInterfaceRequestor)" +
" .getInterface(Components.interfaces.nsIDOMWindowUtils)" +
" .setIsApp(true);",
/* allowDelayedLoad = */ true);
}
},
_recvHello: function(frameElement, data) {
@ -139,6 +135,10 @@ BrowserElementParent.prototype = {
frameElement.dispatchEvent(evt);
},
_sendAppState: function(frameElement, data) {
return frameElement.hasAttribute('mozapp');
},
observe: function(subject, topic, data) {
switch(topic) {
case 'app-startup':
@ -150,10 +150,10 @@ BrowserElementParent.prototype = {
}
break;
case 'remote-browser-frame-shown':
this._observeRemoteBrowserFrameShown(subject, data == "is-moz-app:true");
this._observeRemoteBrowserFrameShown(subject, data);
break;
case 'in-process-browser-frame-shown':
this._observeInProcessBrowserFrameShown(subject, data == "is-moz-app:true");
this._observeInProcessBrowserFrameShown(subject, data);
break;
case 'content-document-global-created':
this._observeContentGlobalCreated(subject);