2012-11-07 15:53:24 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
this.EXPORTED_SYMBOLS = ['Keyboard'];
|
|
|
|
|
|
|
|
const Cu = Components.utils;
|
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
|
|
|
|
Cu.import('resource://gre/modules/Services.jsm');
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "ppmm",
|
|
|
|
"@mozilla.org/parentprocessmessagemanager;1", "nsIMessageBroadcaster");
|
|
|
|
|
2014-04-07 17:59:48 +04:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "SystemAppProxy",
|
|
|
|
"resource://gre/modules/SystemAppProxy.jsm");
|
|
|
|
|
2014-12-09 22:20:40 +03:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "appsService", function() {
|
|
|
|
return Cc["@mozilla.org/AppsService;1"].getService(Ci.nsIAppsService);
|
|
|
|
});
|
|
|
|
|
2015-09-15 21:19:45 +03:00
|
|
|
var Utils = {
|
2014-12-09 22:20:40 +03:00
|
|
|
getMMFromMessage: function u_getMMFromMessage(msg) {
|
|
|
|
let mm;
|
|
|
|
try {
|
|
|
|
mm = msg.target.QueryInterface(Ci.nsIFrameLoaderOwner)
|
|
|
|
.frameLoader.messageManager;
|
|
|
|
} catch(e) {
|
|
|
|
mm = msg.target;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mm;
|
|
|
|
},
|
|
|
|
checkPermissionForMM: function u_checkPermissionForMM(mm, permName) {
|
|
|
|
return mm.assertPermission(permName);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-09-17 19:11:57 +04:00
|
|
|
this.Keyboard = {
|
2014-08-07 10:44:46 +04:00
|
|
|
_formMM: null, // The current web page message manager.
|
|
|
|
_keyboardMM: null, // The keyboard app message manager.
|
|
|
|
_keyboardID: -1, // The keyboard app's ID number. -1 = invalid
|
|
|
|
_nextKeyboardID: 0, // The ID number counter.
|
2015-09-16 23:11:00 +03:00
|
|
|
_systemMMs: [], // The message managers registered to handle system async
|
|
|
|
// messages.
|
2015-09-10 23:29:00 +03:00
|
|
|
_supportsSwitchingTypes: [],
|
|
|
|
_systemMessageNames: [
|
|
|
|
'SetValue', 'RemoveFocus', 'SetSelectedOption', 'SetSelectedOptions',
|
2015-09-16 23:11:00 +03:00
|
|
|
'SetSupportsSwitchingTypes', 'RegisterSync', 'Unregister'
|
2014-03-31 06:38:45 +04:00
|
|
|
],
|
|
|
|
|
2012-11-07 15:53:24 +04:00
|
|
|
_messageNames: [
|
2014-04-25 03:16:00 +04:00
|
|
|
'RemoveFocus',
|
2013-08-01 21:16:43 +04:00
|
|
|
'SetSelectionRange', 'ReplaceSurroundingText', 'ShowInputMethodPicker',
|
2013-08-08 04:07:41 +04:00
|
|
|
'SwitchToNextInputMethod', 'HideInputMethod',
|
2013-08-30 16:07:16 +04:00
|
|
|
'GetText', 'SendKey', 'GetContext',
|
2014-02-13 10:29:50 +04:00
|
|
|
'SetComposition', 'EndComposition',
|
2015-09-16 23:11:00 +03:00
|
|
|
'RegisterSync', 'Unregister'
|
2012-11-07 15:53:24 +04:00
|
|
|
],
|
|
|
|
|
2014-02-13 10:29:50 +04:00
|
|
|
get formMM() {
|
|
|
|
if (this._formMM && !Cu.isDeadWrapper(this._formMM))
|
|
|
|
return this._formMM;
|
2012-11-07 15:53:24 +04:00
|
|
|
|
2013-09-23 17:40:59 +04:00
|
|
|
return null;
|
2012-11-07 15:53:24 +04:00
|
|
|
},
|
|
|
|
|
2014-02-13 10:29:50 +04:00
|
|
|
set formMM(mm) {
|
|
|
|
this._formMM = mm;
|
2012-11-07 15:53:24 +04:00
|
|
|
},
|
|
|
|
|
2014-02-13 10:29:50 +04:00
|
|
|
sendToForm: function(name, data) {
|
2015-09-10 23:29:00 +03:00
|
|
|
if (!this.formMM) {
|
|
|
|
dump("Keyboard.jsm: Attempt to send message " + name +
|
|
|
|
" to form but no message manager exists.\n");
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2013-09-06 22:18:48 +04:00
|
|
|
try {
|
2014-02-13 10:29:50 +04:00
|
|
|
this.formMM.sendAsyncMessage(name, data);
|
|
|
|
} catch(e) { }
|
|
|
|
},
|
|
|
|
|
|
|
|
sendToKeyboard: function(name, data) {
|
|
|
|
try {
|
|
|
|
this._keyboardMM.sendAsyncMessage(name, data);
|
2013-09-06 22:18:48 +04:00
|
|
|
} catch(e) { }
|
|
|
|
},
|
|
|
|
|
2015-09-16 23:11:00 +03:00
|
|
|
sendToSystem: function(name, data) {
|
|
|
|
if (!this._systemMMs.length) {
|
|
|
|
dump("Keyboard.jsm: Attempt to send message " + name +
|
|
|
|
" to system but no message manager registered.\n");
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._systemMMs.forEach((mm, i) => {
|
|
|
|
data.inputManageId = i;
|
|
|
|
mm.sendAsyncMessage(name, data);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2012-11-07 15:53:24 +04:00
|
|
|
init: function keyboardInit() {
|
2014-02-21 02:19:18 +04:00
|
|
|
Services.obs.addObserver(this, 'inprocess-browser-shown', false);
|
|
|
|
Services.obs.addObserver(this, 'remote-browser-shown', false);
|
2013-05-24 13:58:24 +04:00
|
|
|
Services.obs.addObserver(this, 'oop-frameloader-crashed', false);
|
2015-06-12 08:41:00 +03:00
|
|
|
Services.obs.addObserver(this, 'message-manager-close', false);
|
2012-11-07 15:53:24 +04:00
|
|
|
|
2014-03-31 06:38:45 +04:00
|
|
|
for (let name of this._messageNames) {
|
2012-11-07 15:53:24 +04:00
|
|
|
ppmm.addMessageListener('Keyboard:' + name, this);
|
2014-03-31 06:38:45 +04:00
|
|
|
}
|
|
|
|
|
2015-09-10 23:29:00 +03:00
|
|
|
for (let name of this._systemMessageNames) {
|
2014-03-31 06:38:45 +04:00
|
|
|
ppmm.addMessageListener('System:' + name, this);
|
|
|
|
}
|
2014-12-09 22:20:40 +03:00
|
|
|
|
|
|
|
this.inputRegistryGlue = new InputRegistryGlue();
|
2012-11-07 15:53:24 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
observe: function keyboardObserve(subject, topic, data) {
|
2015-06-12 08:41:00 +03:00
|
|
|
let frameLoader = null;
|
|
|
|
let mm = null;
|
2013-05-24 13:58:24 +04:00
|
|
|
|
2015-06-12 08:41:00 +03:00
|
|
|
if (topic == 'message-manager-close') {
|
|
|
|
mm = subject;
|
|
|
|
} else {
|
|
|
|
frameLoader = subject.QueryInterface(Ci.nsIFrameLoader);
|
|
|
|
mm = frameLoader.messageManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (topic == 'oop-frameloader-crashed' ||
|
2015-09-10 23:29:00 +03:00
|
|
|
topic == 'message-manager-close') {
|
2014-02-13 10:29:50 +04:00
|
|
|
if (this.formMM == mm) {
|
2013-05-24 13:58:24 +04:00
|
|
|
// The application has been closed unexpectingly. Let's tell the
|
|
|
|
// keyboard app that the focus has been lost.
|
2015-09-10 23:27:00 +03:00
|
|
|
this.sendToKeyboard('Keyboard:Blur', {});
|
2015-03-18 03:24:00 +03:00
|
|
|
// Notify system app to hide keyboard.
|
2015-09-16 23:11:00 +03:00
|
|
|
this.sendToSystem('System:Blur', {});
|
|
|
|
// XXX: To be removed when content migrate away from mozChromeEvents.
|
2015-03-18 03:24:00 +03:00
|
|
|
SystemAppProxy.dispatchEvent({
|
|
|
|
type: 'inputmethod-contextchange',
|
|
|
|
inputType: 'blur'
|
|
|
|
});
|
2015-09-16 23:11:00 +03:00
|
|
|
|
|
|
|
this.formMM = null;
|
2013-05-24 13:58:24 +04:00
|
|
|
}
|
|
|
|
} else {
|
2014-02-21 02:19:18 +04:00
|
|
|
// Ignore notifications that aren't from a BrowserOrApp
|
|
|
|
if (!frameLoader.ownerIsBrowserOrAppFrame) {
|
|
|
|
return;
|
|
|
|
}
|
2013-11-11 18:11:43 +04:00
|
|
|
this.initFormsFrameScript(mm);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
initFormsFrameScript: function(mm) {
|
2015-09-10 23:27:00 +03:00
|
|
|
mm.addMessageListener('Forms:Focus', this);
|
|
|
|
mm.addMessageListener('Forms:Blur', this);
|
2013-11-11 18:11:43 +04:00
|
|
|
mm.addMessageListener('Forms:SelectionChange', this);
|
|
|
|
mm.addMessageListener('Forms:GetText:Result:OK', this);
|
|
|
|
mm.addMessageListener('Forms:GetText:Result:Error', this);
|
|
|
|
mm.addMessageListener('Forms:SetSelectionRange:Result:OK', this);
|
2014-03-20 14:37:00 +04:00
|
|
|
mm.addMessageListener('Forms:SetSelectionRange:Result:Error', this);
|
2013-11-11 18:11:43 +04:00
|
|
|
mm.addMessageListener('Forms:ReplaceSurroundingText:Result:OK', this);
|
2014-03-20 14:37:00 +04:00
|
|
|
mm.addMessageListener('Forms:ReplaceSurroundingText:Result:Error', this);
|
2013-11-11 18:11:43 +04:00
|
|
|
mm.addMessageListener('Forms:SendKey:Result:OK', this);
|
2014-01-02 19:39:26 +04:00
|
|
|
mm.addMessageListener('Forms:SendKey:Result:Error', this);
|
2013-11-11 18:11:43 +04:00
|
|
|
mm.addMessageListener('Forms:SequenceError', this);
|
|
|
|
mm.addMessageListener('Forms:GetContext:Result:OK', this);
|
|
|
|
mm.addMessageListener('Forms:SetComposition:Result:OK', this);
|
|
|
|
mm.addMessageListener('Forms:EndComposition:Result:OK', this);
|
2012-11-07 15:53:24 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
receiveMessage: function keyboardReceiveMessage(msg) {
|
2014-03-31 06:38:45 +04:00
|
|
|
// If we get a 'Keyboard:XXX'/'System:XXX' message, check that the sender
|
|
|
|
// has the required permission.
|
2014-02-13 10:29:50 +04:00
|
|
|
let mm;
|
2013-09-23 17:40:59 +04:00
|
|
|
|
2015-09-10 23:29:00 +03:00
|
|
|
// Assert the permission based on the prefix of the message.
|
|
|
|
let permName;
|
|
|
|
if (msg.name.startsWith("Keyboard:")) {
|
|
|
|
permName = "input";
|
|
|
|
} else if (msg.name.startsWith("System:")) {
|
|
|
|
permName = "input-manage";
|
|
|
|
}
|
2013-02-16 00:35:18 +04:00
|
|
|
|
2015-09-10 23:29:00 +03:00
|
|
|
// There is no permission to check (nor we need to get the mm)
|
|
|
|
// for Form: messages.
|
|
|
|
if (permName) {
|
|
|
|
mm = Utils.getMMFromMessage(msg);
|
2013-02-16 00:35:18 +04:00
|
|
|
if (!mm) {
|
2015-09-10 23:29:00 +03:00
|
|
|
dump("Keyboard.jsm: Message " + msg.name + " has no message manager.");
|
2013-02-16 00:35:18 +04:00
|
|
|
return;
|
|
|
|
}
|
2015-09-10 23:29:00 +03:00
|
|
|
if (!Utils.checkPermissionForMM(mm, permName)) {
|
|
|
|
dump("Keyboard.jsm: Message " + msg.name +
|
2015-11-11 00:17:00 +03:00
|
|
|
" from a content process with no '" + permName + "' privileges.\n");
|
2013-02-16 00:35:18 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-07 10:44:46 +04:00
|
|
|
// we don't process kb messages (other than register)
|
|
|
|
// if they come from a kb that we're currently not regsitered for.
|
|
|
|
// this decision is made with the kbID kept by us and kb app
|
|
|
|
let kbID = null;
|
|
|
|
if ('kbID' in msg.data) {
|
|
|
|
kbID = msg.data.kbID;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (0 === msg.name.indexOf('Keyboard:') &&
|
2015-09-16 23:11:00 +03:00
|
|
|
('Keyboard:RegisterSync' !== msg.name && this._keyboardID !== kbID)
|
2014-08-07 10:44:46 +04:00
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-11-07 15:53:24 +04:00
|
|
|
switch (msg.name) {
|
2015-09-10 23:27:00 +03:00
|
|
|
case 'Forms:Focus':
|
|
|
|
this.handleFocus(msg);
|
|
|
|
break;
|
|
|
|
case 'Forms:Blur':
|
|
|
|
this.handleBlur(msg);
|
2012-11-07 15:53:24 +04:00
|
|
|
break;
|
2013-03-15 16:28:51 +04:00
|
|
|
case 'Forms:SelectionChange':
|
2013-08-08 04:07:41 +04:00
|
|
|
case 'Forms:GetText:Result:OK':
|
|
|
|
case 'Forms:GetText:Result:Error':
|
|
|
|
case 'Forms:SetSelectionRange:Result:OK':
|
|
|
|
case 'Forms:ReplaceSurroundingText:Result:OK':
|
|
|
|
case 'Forms:SendKey:Result:OK':
|
2014-01-02 19:39:26 +04:00
|
|
|
case 'Forms:SendKey:Result:Error':
|
2013-08-08 04:07:41 +04:00
|
|
|
case 'Forms:SequenceError':
|
|
|
|
case 'Forms:GetContext:Result:OK':
|
2013-08-30 16:07:16 +04:00
|
|
|
case 'Forms:SetComposition:Result:OK':
|
|
|
|
case 'Forms:EndComposition:Result:OK':
|
2014-03-20 14:37:00 +04:00
|
|
|
case 'Forms:SetSelectionRange:Result:Error':
|
|
|
|
case 'Forms:ReplaceSurroundingText:Result:Error':
|
2013-08-08 04:07:41 +04:00
|
|
|
let name = msg.name.replace(/^Forms/, 'Keyboard');
|
|
|
|
this.forwardEvent(name, msg);
|
2013-03-15 16:28:51 +04:00
|
|
|
break;
|
2013-08-08 04:07:41 +04:00
|
|
|
|
2014-03-31 06:38:45 +04:00
|
|
|
case 'System:SetValue':
|
2012-11-07 15:53:24 +04:00
|
|
|
this.setValue(msg);
|
|
|
|
break;
|
|
|
|
case 'Keyboard:RemoveFocus':
|
2014-03-31 06:38:45 +04:00
|
|
|
case 'System:RemoveFocus':
|
2012-11-07 15:53:24 +04:00
|
|
|
this.removeFocus();
|
2015-09-16 23:11:00 +03:00
|
|
|
break;
|
|
|
|
case 'System:RegisterSync': {
|
|
|
|
if (this._systemMMs.length !== 0) {
|
|
|
|
dump('Keyboard.jsm Warning: There are more than one content page ' +
|
|
|
|
'with input-manage permission. There will be undeterministic ' +
|
|
|
|
'responses to addInput()/removeInput() if both content pages are ' +
|
|
|
|
'trying to respond to the same request event.\n');
|
|
|
|
}
|
|
|
|
|
|
|
|
let id = this._systemMMs.length;
|
|
|
|
this._systemMMs.push(mm);
|
|
|
|
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 'System:Unregister':
|
|
|
|
this._systemMMs.splice(msg.data.id, 1);
|
|
|
|
|
2012-11-07 15:53:24 +04:00
|
|
|
break;
|
2014-03-31 06:38:45 +04:00
|
|
|
case 'System:SetSelectedOption':
|
2012-11-07 15:53:24 +04:00
|
|
|
this.setSelectedOption(msg);
|
|
|
|
break;
|
2014-03-31 06:38:45 +04:00
|
|
|
case 'System:SetSelectedOptions':
|
2012-11-07 15:53:24 +04:00
|
|
|
this.setSelectedOption(msg);
|
|
|
|
break;
|
2015-09-10 23:29:00 +03:00
|
|
|
case 'System:SetSupportsSwitchingTypes':
|
|
|
|
this.setSupportsSwitchingTypes(msg);
|
|
|
|
break;
|
2013-03-15 16:28:51 +04:00
|
|
|
case 'Keyboard:SetSelectionRange':
|
|
|
|
this.setSelectionRange(msg);
|
|
|
|
break;
|
2013-04-13 18:53:41 +04:00
|
|
|
case 'Keyboard:ReplaceSurroundingText':
|
|
|
|
this.replaceSurroundingText(msg);
|
|
|
|
break;
|
2013-08-01 21:16:43 +04:00
|
|
|
case 'Keyboard:SwitchToNextInputMethod':
|
|
|
|
this.switchToNextInputMethod();
|
|
|
|
break;
|
|
|
|
case 'Keyboard:ShowInputMethodPicker':
|
|
|
|
this.showInputMethodPicker();
|
|
|
|
break;
|
2013-08-08 04:07:41 +04:00
|
|
|
case 'Keyboard:GetText':
|
|
|
|
this.getText(msg);
|
|
|
|
break;
|
|
|
|
case 'Keyboard:SendKey':
|
|
|
|
this.sendKey(msg);
|
|
|
|
break;
|
|
|
|
case 'Keyboard:GetContext':
|
|
|
|
this.getContext(msg);
|
|
|
|
break;
|
2013-08-30 16:07:16 +04:00
|
|
|
case 'Keyboard:SetComposition':
|
|
|
|
this.setComposition(msg);
|
|
|
|
break;
|
|
|
|
case 'Keyboard:EndComposition':
|
|
|
|
this.endComposition(msg);
|
|
|
|
break;
|
2015-09-16 23:11:00 +03:00
|
|
|
case 'Keyboard:RegisterSync':
|
2014-02-13 10:29:50 +04:00
|
|
|
this._keyboardMM = mm;
|
2015-07-03 00:47:00 +03:00
|
|
|
if (kbID) {
|
2014-08-07 10:44:46 +04:00
|
|
|
// keyboard identifies itself, use its kbID
|
|
|
|
// this msg would be async, so no need to return
|
|
|
|
this._keyboardID = kbID;
|
|
|
|
}else{
|
|
|
|
// generate the id for the keyboard
|
|
|
|
this._keyboardID = this._nextKeyboardID;
|
|
|
|
this._nextKeyboardID++;
|
|
|
|
// this msg is sync,
|
|
|
|
// and we want to return the id back to inputmethod
|
|
|
|
return this._keyboardID;
|
|
|
|
}
|
2014-02-13 10:29:50 +04:00
|
|
|
break;
|
|
|
|
case 'Keyboard:Unregister':
|
|
|
|
this._keyboardMM = null;
|
2014-08-07 10:44:46 +04:00
|
|
|
this._keyboardID = -1;
|
2014-02-13 10:29:50 +04:00
|
|
|
break;
|
2012-11-07 15:53:24 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-09-10 23:27:00 +03:00
|
|
|
handleFocus: function keyboardHandleFocus(msg) {
|
|
|
|
// Set the formMM to the new message manager received.
|
2014-10-29 06:47:00 +03:00
|
|
|
let mm = msg.target.QueryInterface(Ci.nsIFrameLoaderOwner)
|
|
|
|
.frameLoader.messageManager;
|
2015-09-10 23:27:00 +03:00
|
|
|
this.formMM = mm;
|
2013-03-15 16:28:51 +04:00
|
|
|
|
2015-09-16 23:11:00 +03:00
|
|
|
// Notify the current active input app to gain focus.
|
2015-09-10 23:27:00 +03:00
|
|
|
this.forwardEvent('Keyboard:Focus', msg);
|
2013-08-09 22:01:28 +04:00
|
|
|
|
2015-09-16 23:11:00 +03:00
|
|
|
// Notify System app, used also to render value selectors for now;
|
|
|
|
// that's why we need the info about choices / min / max here as well...
|
|
|
|
this.sendToSystem('System:Focus', msg.data);
|
|
|
|
|
|
|
|
// XXX: To be removed when content migrate away from mozChromeEvents.
|
2014-04-07 17:59:48 +04:00
|
|
|
SystemAppProxy.dispatchEvent({
|
2013-08-09 22:01:28 +04:00
|
|
|
type: 'inputmethod-contextchange',
|
2015-09-10 23:27:00 +03:00
|
|
|
inputType: msg.data.inputType,
|
2013-10-17 19:08:55 +04:00
|
|
|
value: msg.data.value,
|
|
|
|
choices: JSON.stringify(msg.data.choices),
|
|
|
|
min: msg.data.min,
|
|
|
|
max: msg.data.max
|
2013-08-09 22:01:28 +04:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-09-10 23:27:00 +03:00
|
|
|
handleBlur: function keyboardHandleBlur(msg) {
|
|
|
|
let mm = msg.target.QueryInterface(Ci.nsIFrameLoaderOwner)
|
|
|
|
.frameLoader.messageManager;
|
|
|
|
// A blur message can't be sent to the keyboard if the focus has
|
|
|
|
// already been taken away at first place.
|
|
|
|
// This check is here to prevent problem caused by out-of-order
|
|
|
|
// ipc messages from two processes.
|
|
|
|
if (mm !== this.formMM) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// unset formMM
|
|
|
|
this.formMM = null;
|
|
|
|
|
|
|
|
this.forwardEvent('Keyboard:Blur', msg);
|
2015-09-16 23:11:00 +03:00
|
|
|
this.sendToSystem('System:Blur', {});
|
2015-09-10 23:27:00 +03:00
|
|
|
|
2015-09-16 23:11:00 +03:00
|
|
|
// XXX: To be removed when content migrate away from mozChromeEvents.
|
2015-09-10 23:27:00 +03:00
|
|
|
SystemAppProxy.dispatchEvent({
|
|
|
|
type: 'inputmethod-contextchange',
|
|
|
|
inputType: 'blur'
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
forwardEvent: function keyboardForwardEvent(newEventName, msg) {
|
|
|
|
this.sendToKeyboard(newEventName, msg.data);
|
|
|
|
},
|
|
|
|
|
2012-11-07 15:53:24 +04:00
|
|
|
setSelectedOption: function keyboardSetSelectedOption(msg) {
|
2014-02-13 10:29:50 +04:00
|
|
|
this.sendToForm('Forms:Select:Choice', msg.data);
|
2012-11-07 15:53:24 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
setSelectedOptions: function keyboardSetSelectedOptions(msg) {
|
2014-02-13 10:29:50 +04:00
|
|
|
this.sendToForm('Forms:Select:Choice', msg.data);
|
2012-11-07 15:53:24 +04:00
|
|
|
},
|
|
|
|
|
2013-03-15 16:28:51 +04:00
|
|
|
setSelectionRange: function keyboardSetSelectionRange(msg) {
|
2014-02-13 10:29:50 +04:00
|
|
|
this.sendToForm('Forms:SetSelectionRange', msg.data);
|
2013-03-15 16:28:51 +04:00
|
|
|
},
|
|
|
|
|
2012-11-07 15:53:24 +04:00
|
|
|
setValue: function keyboardSetValue(msg) {
|
2014-02-13 10:29:50 +04:00
|
|
|
this.sendToForm('Forms:Input:Value', msg.data);
|
2012-11-07 15:53:24 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
removeFocus: function keyboardRemoveFocus() {
|
2015-09-10 23:29:00 +03:00
|
|
|
if (!this.formMM) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-13 10:29:50 +04:00
|
|
|
this.sendToForm('Forms:Select:Blur', {});
|
2013-04-13 18:53:41 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
replaceSurroundingText: function keyboardReplaceSurroundingText(msg) {
|
2014-02-13 10:29:50 +04:00
|
|
|
this.sendToForm('Forms:ReplaceSurroundingText', msg.data);
|
2013-08-01 21:16:43 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
showInputMethodPicker: function keyboardShowInputMethodPicker() {
|
2015-09-16 23:11:00 +03:00
|
|
|
this.sendToSystem('System:ShowAll', {});
|
|
|
|
|
|
|
|
// XXX: To be removed with mozContentEvent support from shell.js
|
2014-04-07 17:59:48 +04:00
|
|
|
SystemAppProxy.dispatchEvent({
|
2013-08-09 22:01:28 +04:00
|
|
|
type: "inputmethod-showall"
|
2013-08-01 21:16:43 +04:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
switchToNextInputMethod: function keyboardSwitchToNextInputMethod() {
|
2015-09-16 23:11:00 +03:00
|
|
|
this.sendToSystem('System:Next', {});
|
|
|
|
|
|
|
|
// XXX: To be removed with mozContentEvent support from shell.js
|
2014-04-07 17:59:48 +04:00
|
|
|
SystemAppProxy.dispatchEvent({
|
2013-08-09 22:01:28 +04:00
|
|
|
type: "inputmethod-next"
|
2013-08-01 21:16:43 +04:00
|
|
|
});
|
2013-08-08 04:07:41 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
getText: function keyboardGetText(msg) {
|
2014-02-13 10:29:50 +04:00
|
|
|
this.sendToForm('Forms:GetText', msg.data);
|
2013-08-08 04:07:41 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
sendKey: function keyboardSendKey(msg) {
|
2014-02-13 10:29:50 +04:00
|
|
|
this.sendToForm('Forms:Input:SendKey', msg.data);
|
2013-08-08 04:07:41 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
getContext: function keyboardGetContext(msg) {
|
2015-09-10 23:29:00 +03:00
|
|
|
if (!this.formMM) {
|
|
|
|
return;
|
2013-09-12 21:02:36 +04:00
|
|
|
}
|
|
|
|
|
2015-09-10 23:29:00 +03:00
|
|
|
this.sendToKeyboard('Keyboard:SupportsSwitchingTypesChange', {
|
|
|
|
types: this._supportsSwitchingTypes
|
|
|
|
});
|
|
|
|
|
2014-02-13 10:29:50 +04:00
|
|
|
this.sendToForm('Forms:GetContext', msg.data);
|
2013-08-30 16:07:16 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
setComposition: function keyboardSetComposition(msg) {
|
2014-02-13 10:29:50 +04:00
|
|
|
this.sendToForm('Forms:SetComposition', msg.data);
|
2013-08-30 16:07:16 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
endComposition: function keyboardEndComposition(msg) {
|
2014-02-13 10:29:50 +04:00
|
|
|
this.sendToForm('Forms:EndComposition', msg.data);
|
2013-09-12 21:02:36 +04:00
|
|
|
},
|
|
|
|
|
2015-09-10 23:29:00 +03:00
|
|
|
setSupportsSwitchingTypes: function setSupportsSwitchingTypes(msg) {
|
|
|
|
this._supportsSwitchingTypes = msg.data.types;
|
|
|
|
this.sendToKeyboard('Keyboard:SupportsSwitchingTypesChange', msg.data);
|
|
|
|
},
|
|
|
|
// XXX: To be removed with mozContentEvent support from shell.js
|
|
|
|
setLayouts: function keyboardSetLayouts(layouts) {
|
2013-09-12 21:02:36 +04:00
|
|
|
// The input method plugins may not have loaded yet,
|
|
|
|
// cache the layouts so on init we can respond immediately instead
|
|
|
|
// of going back and forth between keyboard_manager
|
2015-09-10 23:29:00 +03:00
|
|
|
var types = [];
|
2013-09-12 21:02:36 +04:00
|
|
|
|
2015-09-10 23:29:00 +03:00
|
|
|
Object.keys(layouts).forEach((type) => {
|
|
|
|
if (layouts[type] > 1) {
|
|
|
|
types.push(type);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
this._supportsSwitchingTypes = types;
|
|
|
|
|
|
|
|
this.sendToKeyboard('Keyboard:SupportsSwitchingTypesChange', {
|
|
|
|
types: types
|
|
|
|
});
|
2012-11-07 15:53:24 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-12-09 22:20:40 +03:00
|
|
|
function InputRegistryGlue() {
|
|
|
|
this._messageId = 0;
|
|
|
|
this._msgMap = new Map();
|
|
|
|
|
|
|
|
ppmm.addMessageListener('InputRegistry:Add', this);
|
|
|
|
ppmm.addMessageListener('InputRegistry:Remove', this);
|
2015-09-16 23:11:00 +03:00
|
|
|
ppmm.addMessageListener('System:InputRegistry:Add:Done', this);
|
|
|
|
ppmm.addMessageListener('System:InputRegistry:Remove:Done', this);
|
2014-12-09 22:20:40 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
InputRegistryGlue.prototype.receiveMessage = function(msg) {
|
|
|
|
let mm = Utils.getMMFromMessage(msg);
|
|
|
|
|
2015-09-16 23:11:00 +03:00
|
|
|
let permName = msg.name.startsWith("System:") ? "input-mgmt" : "input";
|
|
|
|
if (!Utils.checkPermissionForMM(mm, permName)) {
|
2014-12-09 22:20:40 +03:00
|
|
|
dump("InputRegistryGlue message " + msg.name +
|
2015-09-16 23:11:00 +03:00
|
|
|
" from a content process with no " + permName + " privileges.");
|
2014-12-09 22:20:40 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (msg.name) {
|
|
|
|
case 'InputRegistry:Add':
|
|
|
|
this.addInput(msg, mm);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'InputRegistry:Remove':
|
|
|
|
this.removeInput(msg, mm);
|
|
|
|
|
2015-09-16 23:11:00 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'System:InputRegistry:Add:Done':
|
|
|
|
case 'System:InputRegistry:Remove:Done':
|
|
|
|
this.returnMessage(msg.data);
|
|
|
|
|
2014-12-09 22:20:40 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
InputRegistryGlue.prototype.addInput = function(msg, mm) {
|
|
|
|
let msgId = this._messageId++;
|
|
|
|
this._msgMap.set(msgId, {
|
|
|
|
mm: mm,
|
|
|
|
requestId: msg.data.requestId
|
|
|
|
});
|
|
|
|
|
|
|
|
let manifestURL = appsService.getManifestURLByLocalId(msg.data.appId);
|
|
|
|
|
2015-09-16 23:11:00 +03:00
|
|
|
Keyboard.sendToSystem('System:InputRegistry:Add', {
|
|
|
|
id: msgId,
|
|
|
|
manifestURL: manifestURL,
|
|
|
|
inputId: msg.data.inputId,
|
|
|
|
inputManifest: msg.data.inputManifest
|
|
|
|
});
|
|
|
|
|
|
|
|
// XXX: To be removed when content migrate away from mozChromeEvents.
|
2014-12-09 22:20:40 +03:00
|
|
|
SystemAppProxy.dispatchEvent({
|
|
|
|
type: 'inputregistry-add',
|
|
|
|
id: msgId,
|
|
|
|
manifestURL: manifestURL,
|
|
|
|
inputId: msg.data.inputId,
|
|
|
|
inputManifest: msg.data.inputManifest
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
InputRegistryGlue.prototype.removeInput = function(msg, mm) {
|
|
|
|
let msgId = this._messageId++;
|
|
|
|
this._msgMap.set(msgId, {
|
|
|
|
mm: mm,
|
|
|
|
requestId: msg.data.requestId
|
|
|
|
});
|
|
|
|
|
|
|
|
let manifestURL = appsService.getManifestURLByLocalId(msg.data.appId);
|
|
|
|
|
2015-09-16 23:11:00 +03:00
|
|
|
Keyboard.sendToSystem('System:InputRegistry:Remove', {
|
|
|
|
id: msgId,
|
|
|
|
manifestURL: manifestURL,
|
|
|
|
inputId: msg.data.inputId
|
|
|
|
});
|
|
|
|
|
|
|
|
// XXX: To be removed when content migrate away from mozChromeEvents.
|
2014-12-09 22:20:40 +03:00
|
|
|
SystemAppProxy.dispatchEvent({
|
|
|
|
type: 'inputregistry-remove',
|
|
|
|
id: msgId,
|
|
|
|
manifestURL: manifestURL,
|
|
|
|
inputId: msg.data.inputId
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
InputRegistryGlue.prototype.returnMessage = function(detail) {
|
|
|
|
if (!this._msgMap.has(detail.id)) {
|
2015-09-16 23:11:00 +03:00
|
|
|
dump('InputRegistryGlue: Ignoring already handled message response. ' +
|
|
|
|
'id=' + detail.id + '\n');
|
2014-12-09 22:20:40 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let { mm, requestId } = this._msgMap.get(detail.id);
|
|
|
|
this._msgMap.delete(detail.id);
|
|
|
|
|
|
|
|
if (Cu.isDeadWrapper(mm)) {
|
2015-09-16 23:11:00 +03:00
|
|
|
dump('InputRegistryGlue: Message manager has already died.\n');
|
2014-12-09 22:20:40 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!('error' in detail)) {
|
|
|
|
mm.sendAsyncMessage('InputRegistry:Result:OK', {
|
|
|
|
requestId: requestId
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
mm.sendAsyncMessage('InputRegistry:Result:Error', {
|
|
|
|
error: detail.error,
|
|
|
|
requestId: requestId
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-09-17 19:11:57 +04:00
|
|
|
this.Keyboard.init();
|