Close tray bubble before disabling UI for sign-in.

During Chrome OS sign-in we temperoraly block the UI, to prevent user
from interracting with UI elements, particullary with the system tray
menu. However, if system tray menu is opened before disabling the UI,
it remains opened after. Fixed this by closing the menu together with
disabling the UI.

BUG=497080
TEST=manually

Review URL: https://codereview.chromium.org/1187593006

Cr-Commit-Position: refs/heads/master@{#335133}

Review URL: https://codereview.chromium.org/1194053003

Cr-Commit-Position: refs/heads/master@{#335562}
diff --git a/chrome/browser/chromeos/login/ui/webui_login_view.cc b/chrome/browser/chromeos/login/ui/webui_login_view.cc
index 3a93f00..eda03e48 100644
--- a/chrome/browser/chromeos/login/ui/webui_login_view.cc
+++ b/chrome/browser/chromeos/login/ui/webui_login_view.cc
@@ -343,7 +343,19 @@
 
 void WebUILoginView::SetUIEnabled(bool enabled) {
   forward_keyboard_event_ = enabled;
-  ash::Shell::GetInstance()->GetPrimarySystemTray()->SetEnabled(enabled);
+  ash::SystemTray* tray = ash::Shell::GetInstance()->GetPrimarySystemTray();
+
+  // We disable the UI to prevent user from interracting with UI elements,
+  // particullary with the system tray menu. However, in case if the system tray
+  // bubble is opened at this point, it remains opened and interactictive even
+  // after SystemTray::SetEnabled(false) call, which can be dangerous
+  // (http://crbug.com/497080). Close the menu to fix it. Calling
+  // SystemTray::SetEnabled(false) guarantees, that the menu will not be opened
+  // until the UI is enabled again.
+  if (!enabled && tray->HasSystemBubble())
+    tray->CloseSystemBubble();
+
+  tray->SetEnabled(enabled);
 }
 
 void WebUILoginView::AddFrameObserver(FrameObserver* frame_observer) {