Fix focus issue when opening site settings in another browser window.

Needed to take the reason for bubble closing into account - if focus
passed to another window we shouldn't reset the focus.

Bug: 962411
Change-Id: Ic88a1151706613287e3f1bcb2f3c8dff39feb9dc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1610307
Reviewed-by: Elly Fong-Jones <[email protected]>
Commit-Queue: Dana Fried <[email protected]>
Cr-Commit-Position: refs/heads/master@{#659546}
diff --git a/chrome/browser/ui/browser_command_controller.cc b/chrome/browser/ui/browser_command_controller.cc
index bbfb1ce1..79d61d43 100644
--- a/chrome/browser/ui/browser_command_controller.cc
+++ b/chrome/browser/ui/browser_command_controller.cc
@@ -107,11 +107,18 @@
 // Ensures that - if we have not popped up an infobar to prompt the user to e.g.
 // reload the current page - that the content pane of the browser is refocused.
 void AppInfoDialogClosedCallback(content::WebContents* web_contents,
-                                 views::Widget::ClosedReason /* unused */,
+                                 views::Widget::ClosedReason closed_reason,
                                  bool reload_prompt) {
   if (reload_prompt)
     return;
 
+  // If the user clicked on something specific or focus was changed, don't
+  // override the focus.
+  if (closed_reason != views::Widget::ClosedReason::kEscKeyPressed &&
+      closed_reason != views::Widget::ClosedReason::kCloseButtonClicked) {
+    return;
+  }
+
   // Ensure that the web contents handle we have is still valid. It's possible
   // (though unlikely) that either the browser or web contents has been pulled
   // out from underneath us.