if (aFocusController) { nsCOMPtr<nsIDOMWindowInternal> focusedWindow; aFocusController->GetFocusedWindow(getter_AddRefs(focusedWindow));     if (focusedWindow) { nsCOMPtr<nsIDOMDocument> domDoc; focusedWindow->GetDocument(getter_AddRefs(domDoc)); if (!domDoc) {   focusedWindow = do_QueryInterface(aOurWindow); aFocusController->SetFocusedWindow(focusedWindow); } }
static void CheckForFocus(nsPIDOMWindow* aOurWindow, nsIFocusController* aFocusController, nsIDocument* aDocument){  // Now that we have a root frame, set focus in to the presshell, but  // only do this if our window is currently focused  // Restore focus if we're the active window or a parent of a previously  // active window.  if (aFocusController) {    nsCOMPtr<nsIDOMWindowInternal> focusedWindow;    aFocusController->GetFocusedWindow(getter_AddRefs(focusedWindow));        // See if the command dispatcher is holding on to an orphan window.    // This happens when you move from an inner frame to an outer frame    // (e.g., _parent, _top)    if (focusedWindow) {      nsCOMPtr<nsIDOMDocument> domDoc;      focusedWindow->GetDocument(getter_AddRefs(domDoc));      if (!domDoc) {        // We're pointing to garbage. Go ahead and let this        // presshell take the focus.        focusedWindow = do_QueryInterface(aOurWindow);        aFocusController->SetFocusedWindow(focusedWindow);      }    }    nsCOMPtr<nsIDOMWindowInternal> domWindow = do_QueryInterface(aOurWindow);    if (domWindow == focusedWindow) {      PRBool active;      aFocusController->GetActive(&active);      if(active) {        // We need to restore focus to the window.        domWindow->Focus();      }    }  }}