Bug 1083617 - Block the blur message if focus is already removed from remote frame. r=yxl
authorTim Chien <timdream@gmail.com>
Tue, 28 Oct 2014 23:47:00 -0400
changeset 212887 52cdf66f6666be1c296ca3d878c117d05047d2ec
parent 212886 0f7fd7a22708cddd947c73b1de162eb1206fea7b
child 212888 2c5d603aa12f6f7e294ee3cac6fc6f6e081f5343
push id51080
push userryanvm@gmail.com
push dateWed, 29 Oct 2014 15:45:02 +0000
treeherdermozilla-inbound@f8b29993a76c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersyxl
bugs1083617
milestone36.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1083617 - Block the blur message if focus is already removed from remote frame. r=yxl
dom/inputmethod/Keyboard.jsm
--- a/dom/inputmethod/Keyboard.jsm
+++ b/dom/inputmethod/Keyboard.jsm
@@ -244,24 +244,44 @@ this.Keyboard = {
       case 'Keyboard:Unregister':
         this._keyboardMM = null;
         this._keyboardID = -1;
         break;
     }
   },
 
   forwardEvent: function keyboardForwardEvent(newEventName, msg) {
-    this.formMM = msg.target.QueryInterface(Ci.nsIFrameLoaderOwner)
-                            .frameLoader.messageManager;
+    let mm = msg.target.QueryInterface(Ci.nsIFrameLoaderOwner)
+                .frameLoader.messageManager;
+    if (newEventName === 'Keyboard:FocusChange' &&
+        msg.data.type === 'blur') {
+      // A blur message can't be sent to the keyboard if the focus has
+      // already 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 false;
+      }
+
+      this.sendToKeyboard(newEventName, msg.data);
+      return true;
+    }
+
+    this.formMM = mm;
 
     this.sendToKeyboard(newEventName, msg.data);
+    return true;
   },
 
   handleFocusChange: function keyboardHandleFocusChange(msg) {
-    this.forwardEvent('Keyboard:FocusChange', msg);
+    let isSent = this.forwardEvent('Keyboard:FocusChange', msg);
+
+    if (!isSent) {
+      return;
+    }
 
     // Chrome event, used also to render value selectors; that's why we need
     // the info about choices / min / max here as well...
     SystemAppProxy.dispatchEvent({
       type: 'inputmethod-contextchange',
       inputType: msg.data.type,
       value: msg.data.value,
       choices: JSON.stringify(msg.data.choices),