According to the finding of bug 1113592, smart system app tries to focus an app window while the iframe is not loaded. This behavior doesn't set the focus to iframe correctly. We set focus when the app window is opened, currently. The `opened` state means that: 1. the iframe is created 2. the DOM elements and iframe is resized to correct size 3. the animation is end. I will make a patch to set focus only when 1. the iframe is loaded, 2. app window is opened and 3. app window is the active one.
Created attachment 8541383 [details] [review] focus app window when it is active and loaded Rex, Please review this patch. Sean, Please apply this patch and validate if we focus the app only when it is loaded at your environment.
Comment on attachment 8541383 [details] [review] focus app window when it is active and loaded It works at my environment (B2G desktop build on Ubuntu).
Some technical details about this issue FYI: 1. |nsFocusManager| checks if the content is focusable before actually setting focus on it.  2. "Frames are never directly focused; instead focusing a frame means focus what is inside the frame. To do this, the descendant content within the frame is retrieved and that will be focused instead."  3. There appears a sub-document and app-deck frame is visible, so the content node is used to determine focusability.  4. While |nsFocusManager| determines focusability of the content node, the correspondent document hasn't been focusable since its docshell is still busy loading the page. (So it has one zombie content viewer and the new content structure hasn't been ready yet.)  http://dxr.mozilla.org/mozilla-central/source/dom/base/nsFocusManager.cpp#1164  http://dxr.mozilla.org/mozilla-central/source/dom/base/nsFocusManager.cpp#1168-1171  http://dxr.mozilla.org/mozilla-central/source/dom/base/nsFocusManager.cpp#1562-1572  http://dxr.mozilla.org/mozilla-central/source/dom/base/nsContentUtils.cpp#6175-6192
Looks reasonable to me but I don't have the environment to reproduce the problem. I didn't found any problem while testing so r+ for Sean has already tested it.
merged to master: https://github.com/mozilla-b2g/gaia/commit/fa225ad6ee36a8d9f3f3d26340ef85c70c845b58 gaia try is all green: https://treeherder.mozilla.org/ui/#/jobs?repo=gaia-try&revision=ccd204678fe1