Bug 1234118 - Delete code for supporting 'do-command' and 'copypaste-docommand'. r=mtseng, r=smaug
These two events are the leftovers for support copy/paste/cut/selectall
operations from old text_selection_dialog.js in Gaia. The code for
handling them can be removed since text_selection_dialog.js was removed
in
bug 1221462.
--- a/dom/browser-element/BrowserElementChildPreload.js
+++ b/dom/browser-element/BrowserElementChildPreload.js
@@ -63,25 +63,16 @@ var CERTIFICATE_ERROR_PAGE_PREF = 'secur
const OBSERVED_EVENTS = [
'xpcom-shutdown',
'audio-playback',
'activity-done',
'invalid-widget'
];
-const COMMAND_MAP = {
- 'cut': 'cmd_cut',
- 'copy': 'cmd_copyAndCollapseToEnd',
- 'copyImage': 'cmd_copyImage',
- 'copyLink': 'cmd_copyLink',
- 'paste': 'cmd_paste',
- 'selectall': 'cmd_selectAll'
-};
-
/**
* The BrowserElementChild implements one half of <iframe mozbrowser>.
* (The other half is, unsurprisingly, BrowserElementParent.)
*
* This script is injected into an <iframe mozbrowser> via
* nsIMessageManager::LoadFrameScript().
*
* Our job here is to listen for events within this frame and bubble them up to
@@ -273,17 +264,16 @@ BrowserElementChild.prototype = {
"unblock-modal-prompt": this._recvStopWaiting,
"fire-ctx-callback": this._recvFireCtxCallback,
"owner-visibility-change": this._recvOwnerVisibilityChange,
"entered-fullscreen": this._recvEnteredFullscreen,
"exit-fullscreen": this._recvExitFullscreen.bind(this),
"activate-next-paint-listener": this._activateNextPaintListener.bind(this),
"set-input-method-active": this._recvSetInputMethodActive.bind(this),
"deactivate-next-paint-listener": this._deactivateNextPaintListener.bind(this),
- "do-command": this._recvDoCommand,
"find-all": this._recvFindAll.bind(this),
"find-next": this._recvFindNext.bind(this),
"clear-match": this._recvClearMatch.bind(this),
"execute-script": this._recvExecuteScript,
"get-audio-channel-volume": this._recvGetAudioChannelVolume,
"set-audio-channel-volume": this._recvSetAudioChannelVolume,
"get-audio-channel-muted": this._recvGetAudioChannelMuted,
"set-audio-channel-muted": this._recvSetAudioChannelMuted,
@@ -402,25 +392,16 @@ BrowserElementChild.prototype = {
if (args.promptType == 'prompt' ||
args.promptType == 'confirm' ||
args.promptType == 'custom-prompt') {
return returnValue;
}
},
- _isCommandEnabled: function(cmd) {
- let command = COMMAND_MAP[cmd];
- if (!command) {
- return false;
- }
-
- return docShell.isCommandEnabled(command);
- },
-
/**
* Spin in a nested event loop until we receive a unblock-modal-prompt message for
* this window.
*/
_waitForResult: function(win) {
debug("_waitForResult(" + win + ")");
let utils = win.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
@@ -1191,24 +1172,26 @@ BrowserElementChild.prototype = {
successRv: blob
});
}, mimeType);
},
_recvFireCtxCallback: function(data) {
debug("Received fireCtxCallback message: (" + data.json.menuitem + ")");
+ let doCommandIfEnabled = (command) => {
+ if (docShell.isCommandEnabled(command)) {
+ docShell.doCommand(command);
+ }
+ };
+
if (data.json.menuitem == 'copy-image') {
- // Set command
- data.json.command = 'copyImage';
- this._recvDoCommand(data);
+ doCommandIfEnabled('cmd_copyImage');
} else if (data.json.menuitem == 'copy-link') {
- // Set command
- data.json.command = 'copyLink';
- this._recvDoCommand(data);
+ doCommandIfEnabled('cmd_copyLink');
} else if (data.json.menuitem in this._ctxHandlers) {
this._ctxHandlers[data.json.menuitem].click();
this._ctxHandlers = {};
} else {
// We silently ignore if the embedder uses an incorrect id in the callback
debug("Ignored invalid contextmenu invocation");
}
},
@@ -1377,22 +1360,16 @@ BrowserElementChild.prototype = {
let webNav = docShell.QueryInterface(Ci.nsIWebNavigation);
webNav.stop(webNav.STOP_NETWORK);
},
_recvZoom: function(data) {
docShell.contentViewer.fullZoom = data.json.zoom;
},
- _recvDoCommand: function(data) {
- if (this._isCommandEnabled(data.json.command)) {
- docShell.doCommand(COMMAND_MAP[data.json.command]);
- }
- },
-
_recvGetAudioChannelVolume: function(data) {
debug("Received getAudioChannelVolume message: (" + data.json.id + ")");
let volume = acs.getAudioChannelVolume(content,
data.json.args.audioChannel);
sendAsyncMsg('got-audio-channel-volume', {
id: data.json.id, successRv: volume
});
--- a/dom/browser-element/BrowserElementCopyPaste.js
+++ b/dom/browser-element/BrowserElementCopyPaste.js
@@ -25,17 +25,17 @@ var CopyPasteAssistent = {
/* wantsUntrusted = */ false);
addMessageListener('browser-element-api:call', this._browserAPIHandler.bind(this));
},
_browserAPIHandler: function(e) {
switch (e.data.msg_name) {
case 'copypaste-do-command':
if (this._isCommandEnabled(e.data.command)) {
- docShell.doCommand(COMMAND_MAP[e.data.command]);
+ docShell.doCommand(this.COMMAND_MAP[e.data.command]);
}
break;
}
},
_isCommandEnabled: function(cmd) {
let command = this.COMMAND_MAP[cmd];
if (!command) {
--- a/dom/browser-element/BrowserElementParent.js
+++ b/dom/browser-element/BrowserElementParent.js
@@ -245,17 +245,16 @@ function BrowserElementParent() {
this._domRequestReady = false;
this._pendingAPICalls = [];
this._pendingDOMRequests = {};
this._pendingSetInputMethodActive = [];
this._nextPaintListeners = [];
this._pendingDOMFullscreen = false;
Services.obs.addObserver(this, 'oop-frameloader-crashed', /* ownsWeak = */ true);
- Services.obs.addObserver(this, 'copypaste-docommand', /* ownsWeak = */ true);
Services.obs.addObserver(this, 'ask-children-to-execute-copypaste-command', /* ownsWeak = */ true);
Services.obs.addObserver(this, 'back-docommand', /* ownsWeak = */ true);
this.proxyCallHandler = new BrowserElementParentProxyCallHandler();
}
BrowserElementParent.prototype = {
@@ -1290,21 +1289,16 @@ BrowserElementParent.prototype = {
observe: function(subject, topic, data) {
switch(topic) {
case 'oop-frameloader-crashed':
if (this._isAlive() && subject == this._frameLoader) {
this._fireFatalError();
}
break;
- case 'copypaste-docommand':
- if (this._isAlive() && this._frameElement.isEqualNode(subject.wrappedJSObject)) {
- this._sendAsyncMsg('do-command', { command: data });
- }
- break;
case 'ask-children-to-execute-copypaste-command':
if (this._isAlive() && this._frameElement == subject.wrappedJSObject) {
this._sendAsyncMsg('copypaste-do-command', { command: data });
}
break;
case 'back-docommand':
if (this._isAlive() && this._frameLoader.visible) {
this.goBack();
--- a/dom/browser-element/mochitest/browserElement_CopyPaste.js
+++ b/dom/browser-element/mochitest/browserElement_CopyPaste.js
@@ -81,18 +81,24 @@ function runTest() {
iframeInner = iframeOuter;
mm = SpecialPowers.getBrowserFrameMessageManager(iframeInner);
dispatchTest(e);
}
});
}
function doCommand(cmd) {
- Services.obs.notifyObservers({wrappedJSObject: SpecialPowers.unwrap(iframeInner)},
- 'copypaste-docommand', cmd);
+ var COMMAND_MAP = {
+ 'cut': 'cmd_cut',
+ 'copy': 'cmd_copyAndCollapseToEnd',
+ 'paste': 'cmd_paste',
+ 'selectall': 'cmd_selectAll'
+ };
+ var script = 'data:,docShell.doCommand("' + COMMAND_MAP[cmd] + '");';
+ mm.loadFrameScript(script, false);
}
function dispatchTest(e) {
iframeInner.addEventListener("mozbrowserloadend", function onloadend2(e) {
iframeInner.removeEventListener("mozbrowserloadend", onloadend2);
iframeInner.focus();
SimpleTest.executeSoon(function() { testSelectAll(e); });
});