Bug 989198, Patch 4: Dispatch both chrome event and key event for hardward keys, and add new permission, r=fabrice.
---
b2g/chrome/content/shell.js | 13 ++++++++-----
dom/apps/PermissionsTable.jsm | 6 ++++++
testing/mochitest/manifest.webapp | 3 ++-
3 files changed, 16 insertions(+), 6 deletions(-)
--- a/b2g/chrome/content/shell.js
+++ b/b2g/chrome/content/shell.js
@@ -319,16 +319,18 @@ var shell = {
// Capture all key events so we can filter out hardware buttons
// And send them to Gaia via mozChromeEvents.
// Ideally, hardware buttons wouldn't generate key events at all, or
// if they did, they would use keycodes that conform to DOM 3 Events.
// See discussion in https://bugzilla.mozilla.org/show_bug.cgi?id=762362
chromeEventHandler.addEventListener('keydown', this, true);
chromeEventHandler.addEventListener('keypress', this, true);
chromeEventHandler.addEventListener('keyup', this, true);
+ chromeEventHandler.addEventListener('mozbrowserbeforekeydown', this, true);
+ chromeEventHandler.addEventListener('mozbrowserbeforekeyup', this, true);
window.addEventListener('MozApplicationManifest', this);
window.addEventListener('mozfullscreenchange', this);
window.addEventListener('MozAfterPaint', this);
window.addEventListener('sizemodechange', this);
window.addEventListener('unload', this);
this.contentBrowser.addEventListener('mozbrowserloadstart', this, true);
this.contentBrowser.addEventListener('mozbrowserselectionchange', this, true);
@@ -351,16 +353,18 @@ var shell = {
ppmm.addMessageListener("file-picker", this);
},
stop: function shell_stop() {
window.removeEventListener('unload', this);
window.removeEventListener('keydown', this, true);
window.removeEventListener('keypress', this, true);
window.removeEventListener('keyup', this, true);
+ window.removeEventListener('mozbrowserbeforekeydown', this, true);
+ window.removeEventListener('mozbrowserbeforekeyup', this, true);
window.removeEventListener('MozApplicationManifest', this);
window.removeEventListener('mozfullscreenchange', this);
window.removeEventListener('sizemodechange', this);
this.contentBrowser.removeEventListener('mozbrowserloadstart', this, true);
this.contentBrowser.removeEventListener('mozbrowserselectionchange', this, true);
this.contentBrowser.removeEventListener('mozbrowserscrollviewchange', this, true);
this.contentBrowser.removeEventListener('mozbrowsertouchcarettap', this, true);
ppmm.removeMessageListener("content-handler", this);
@@ -415,27 +419,24 @@ var shell = {
isMediaKey = true;
type = mediaKeys[evt.key];
}
if (!type) {
return;
}
- // If we didn't return, then the key event represents a hardware key
- // and we need to prevent it from propagating to Gaia
- evt.stopImmediatePropagation();
- evt.preventDefault(); // Prevent keypress events (when #501496 is fixed).
-
// If it is a key down or key up event, we send a chrome event to Gaia.
// If it is a keypress event we just ignore it.
switch (evt.type) {
+ case 'mozbrowserbeforekeydown':
case 'keydown':
type = type + '-press';
break;
+ case 'mozbrowserbeforekeyup':
case 'keyup':
type = type + '-release';
break;
case 'keypress':
return;
}
// Let applications receive the headset button key press/release event.
@@ -468,16 +469,18 @@ var shell = {
visibleNormalAudioActive: false,
handleEvent: function shell_handleEvent(evt) {
let content = this.contentBrowser.contentWindow;
switch (evt.type) {
case 'keydown':
case 'keyup':
case 'keypress':
+ case 'mozbrowserbeforekeydown':
+ case 'mozbrowserbeforekeyup':
this.filterHardwareKeys(evt);
break;
case 'mozfullscreenchange':
// When the screen goes fullscreen make sure to set the focus to the
// main window so noboby can prevent the ESC key to get out fullscreen
// mode
if (document.mozFullScreen)
Services.fm.focusedWindow = window;
--- a/dom/apps/PermissionsTable.jsm
+++ b/dom/apps/PermissionsTable.jsm
@@ -488,16 +488,22 @@ this.PermissionsTable = { geolocation:
access: ["read", "write"],
additional: ["settings-api"]
},
"engineering-mode": {
app: DENY_ACTION,
trusted: DENY_ACTION,
privileged: DENY_ACTION,
certified: ALLOW_ACTION
+ },
+ "before-after-keyboard-event": {
+ app: DENY_ACTION,
+ trusted: DENY_ACTION,
+ privileged: DENY_ACTION,
+ certified: ALLOW_ACTION
}
};
/**
* Append access modes to the permission name as suffixes.
* e.g. permission name 'contacts' with ['read', 'write'] =
* ['contacts-read', contacts-write']
* @param string aPermName
--- a/testing/mochitest/manifest.webapp
+++ b/testing/mochitest/manifest.webapp
@@ -22,17 +22,18 @@
"camera":{},
"geolocation":{},
"wifi-manage":{},
"desktop-notification":{},
"idle":{},
"network-events":{},
"embed-apps":{},
"audio-channel-content":{},
- "audio-channel-alarm":{}
+ "audio-channel-alarm":{},
+ "before-after-keyboard-event":{}
},
"locales": {
"en-US": {
"name": "Mochitest",
"description": "Mochitests"
}
},
"datastores-access" : {