Bug 1051995 - Use observer services to prevent ContentParent leak. r=fabrice

This commit is contained in:
Morris Tseng 2014-09-23 00:10:00 -04:00
parent b7dae97a82
commit f579fdf912
3 changed files with 9 additions and 23 deletions

View File

@ -738,7 +738,8 @@ let DoCommandHelper = {
handleEvent: function docommand_handleEvent(cmd) {
if (this._event) {
shell.sendEvent(this._event.target, 'mozdocommand', { cmd: cmd });
Services.obs.notifyObservers({ wrappedJSObject: this._event.target },
'copypaste-docommand', cmd);
this._event = null;
}
}

View File

@ -85,6 +85,7 @@ function BrowserElementParent(frameLoader, hasRemoteFrame, isPendingFrame) {
Services.obs.addObserver(this, 'ask-children-to-exit-fullscreen', /* ownsWeak = */ true);
Services.obs.addObserver(this, 'oop-frameloader-crashed', /* ownsWeak = */ true);
Services.obs.addObserver(this, 'copypaste-docommand', /* ownsWeak = */ true);
let defineMethod = function(name, fn) {
XPCNativeWrapper.unwrap(self._frameElement)[name] = function() {
@ -169,14 +170,6 @@ function BrowserElementParent(frameLoader, hasRemoteFrame, isPendingFrame) {
/* wantsUntrusted = */ false);
}
this._doCommandHandlerBinder = this._doCommandHandler.bind(this);
this._frameElement.addEventListener('mozdocommand',
this._doCommandHandlerBinder,
/* useCapture = */ false,
/* wantsUntrusted = */ false);
Services.obs.addObserver(this, 'ipc:browser-destroyed', /* ownsWeak = */ true);
this._window._browserElementParents.set(this, null);
// Insert ourself into the prompt service.
@ -498,11 +491,6 @@ BrowserElementParent.prototype = {
this._frameElement.dispatchEvent(evt);
},
_doCommandHandler: function(e) {
e.stopPropagation();
this._sendAsyncMsg('do-command', { command: e.detail.cmd });
},
_createEvent: function(evtName, detail, cancelable) {
// This will have to change if we ever want to send a CustomEvent with null
// detail. For now, it's OK.
@ -926,11 +914,9 @@ BrowserElementParent.prototype = {
}
Services.obs.removeObserver(this, 'remote-browser-frame-shown');
}
case 'ipc:browser-destroyed':
if (this._isAlive() && subject == this._frameLoader) {
Services.obs.removeObserver(this, 'ipc:browser-destroyed');
this._frameElement.removeEventListener('mozdocommand',
this._doCommandHandlerBinder)
case 'copypaste-docommand':
if (this._isAlive() && this._frameElement.isEqualNode(subject.wrappedJSObject)) {
this._sendAsyncMsg('do-command', { command: data });
}
break;
default:

View File

@ -8,6 +8,7 @@ SimpleTest.waitForExplicitFinish();
browserElementTestHelpers.setEnabledPref(true);
browserElementTestHelpers.setSelectionChangeEnabledPref(true);
browserElementTestHelpers.addPermission();
const { Services } = SpecialPowers.Cu.import('resource://gre/modules/Services.jsm');
var gTextarea = null;
var mm;
var iframe;
@ -60,10 +61,8 @@ function runTest() {
}
function doCommand(cmd) {
let doc = iframe.ownerDocument;
let event = doc.createEvent('CustomEvent');
event.initCustomEvent('mozdocommand', true, true, { cmd: cmd });
SpecialPowers.wrap(iframe).dispatchEvent(event);
Services.obs.notifyObservers({wrappedJSObject: iframe},
'copypaste-docommand', cmd);
}
function dispatchTest(e) {