Bug 620982 - focus is cleared when there is an XHR in the background [r=mfinkle]
authorVivien Nicolas <21@vingtetun.org>
Wed, 22 Dec 2010 18:55:45 +0100
changeset 67156 4ae2982737aacc9921116a6ba7b16bdccee5263e
parent 67155 e505487cc15e9fbb1daf3ca47c5a3bacf7de03e1
child 67157 be9046794ff37d8979cdc195357c9f8d3c1adddf
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs620982
Bug 620982 - focus is cleared when there is an XHR in the background [r=mfinkle]
mobile/chrome/content/bindings/browser.js
mobile/chrome/content/forms.js
--- a/mobile/chrome/content/bindings/browser.js
+++ b/mobile/chrome/content/bindings/browser.js
@@ -241,17 +241,18 @@ let DOMEvents =  {
         let json = {
           windowId: util.outerWindowID,
           persisted: aEvent.persisted
         };
 
         // Clear onload focus to prevent the VKB to be shown unexpectingly
         // but only if the location has really changed and not only the
         // fragment identifier
-        if (!WebProgressListener.hashChanged) {
+        let contentWindowID = content.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils).currentInnerWindowID;
+        if (!WebProgressListener.hashChanged && contentWindowID == util.currentInnerWindowID) {
           let focusManager = Cc["@mozilla.org/focus-manager;1"].getService(Ci.nsIFocusManager);
           focusManager.clearFocus(content);
         }
 
         sendAsyncMessage(aEvent.type, json);
         break;
       }
 
--- a/mobile/chrome/content/forms.js
+++ b/mobile/chrome/content/forms.js
@@ -66,16 +66,18 @@ function FormAssistant() {
   addMessageListener("FormAssist:Next", this);
   addMessageListener("FormAssist:ChoiceSelect", this);
   addMessageListener("FormAssist:ChoiceChange", this);
   addMessageListener("FormAssist:AutoComplete", this);
   addMessageListener("Content:SetWindowSize", this);
 
   addEventListener("keyup", this, false);
   addEventListener("focus", this, true);
+  addEventListener("DOMWindowCreated", this, false);
+  addEventListener("pageshow", this, false);
 
   this._enabled = Services.prefs.getBoolPref("formhelper.enabled");
 };
 
 FormAssistant.prototype = {
   _selectWrapper: null,
   _currentIndex: -1,
   _elements: [],
@@ -249,20 +251,26 @@ FormAssistant.prototype = {
         return true;
       }
     }
     return false;
   },
 
   focusSync: false,
   handleEvent: function formHelperHandleEvent(aEvent) {
-    if (!this._enabled || (!this.currentElement && (aEvent.type != "focus" || !this.focusSync)))
+    if (!this._enabled || (!this.currentElement && aEvent.type != "focus") || (aEvent.type == "focus" && !this.focusSync))
       return;
 
     switch (aEvent.type) {
+      case "DOMWindowCreated":
+        this.focusSync = false;
+        break;
+      case "pageshow":
+        this.focusSync = true;
+        break;
       case "focus":
         let focusedElement = gFocusManager.getFocusedElementForWindow(content, true, {}) || aEvent.target;
 
         // If a body element is editable and the body is the child of an
         // iframe we can assume this is an advanced HTML editor, so let's 
         // redirect the form helper selection to the iframe element
         if (focusedElement && this._isEditable(focusedElement)) {
           let editableElement = this._getTopLevelEditable(focusedElement);