Index: chrome/browser/ui/webui/signin/signin_error_handler.cc |
diff --git a/chrome/browser/ui/webui/signin/signin_error_handler.cc b/chrome/browser/ui/webui/signin/signin_error_handler.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..1f8563e5b8dcb3bb47df793da324978c3e689c80 |
--- /dev/null |
+++ b/chrome/browser/ui/webui/signin/signin_error_handler.cc |
@@ -0,0 +1,91 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/ui/webui/signin/signin_error_handler.h" |
+ |
+#include "base/bind.h" |
+#include "chrome/browser/profiles/profile_attributes_entry.h" |
+#include "chrome/browser/profiles/profile_manager.h" |
+#include "chrome/browser/profiles/profile_window.h" |
+#include "chrome/browser/signin/signin_ui_util.h" |
+#include "chrome/browser/ui/browser_finder.h" |
+#include "chrome/browser/ui/browser_window.h" |
+#include "content/public/browser/web_ui.h" |
+#include "url/gurl.h" |
+ |
+void SigninErrorHandler::RegisterMessages() { |
+ web_ui()->RegisterMessageCallback( |
+ "confirm", |
+ base::Bind(&SigninErrorHandler::HandleConfirm, base::Unretained(this))); |
+ web_ui()->RegisterMessageCallback( |
+ "switch", |
+ base::Bind(&SigninErrorHandler::HandleSwitch, base::Unretained(this))); |
+ web_ui()->RegisterMessageCallback( |
+ "learnMore", |
+ base::Bind(&SigninErrorHandler::HandleLearnMore, base::Unretained(this))); |
+ web_ui()->RegisterMessageCallback( |
+ "initializedWithSize", |
+ base::Bind(&SigninErrorHandler::HandleInitializedWithSize, |
+ base::Unretained(this))); |
+} |
+ |
+void SigninErrorHandler::set_duplicate_profile_entry( |
+ const ProfileAttributesEntry* duplicate_profile_entry) { |
+ duplicate_profile_entry_ = duplicate_profile_entry; |
+} |
+ |
+void SigninErrorHandler::HandleSwitch(const base::ListValue* args) { |
+ if (!duplicate_profile_entry_) |
+ return; |
+ CloseDialog(); |
+ profiles::SwitchToProfile(duplicate_profile_entry_->GetPath(), |
+ false, /* reuse any existing windows */ |
anthonyvd
2016/08/22 14:58:46
Is not using an existing window a conscious design
Jane
2016/08/22 20:48:31
This bool is always_create and setting it to false
|
+ ProfileManager::CreateCallback(), |
+ ProfileMetrics::SWITCH_PROFILE_DUPLICATE); |
+} |
+ |
+void SigninErrorHandler::HandleConfirm(const base::ListValue* args) { |
+ CloseDialog(); |
+} |
+ |
+void SigninErrorHandler::HandleLearnMore(const base::ListValue* args) { |
+ Browser* browser = GetDesktopBrowser(); |
+ browser->CloseModalSigninWindow(); |
+ signin_ui_util::ShowSigninErrorLearnMorePage(browser->profile()); |
+} |
+ |
+void SigninErrorHandler::HandleInitializedWithSize( |
+ const base::ListValue* args) { |
+ if (!duplicate_profile_entry_) |
+ web_ui()->CallJavascriptFunctionUnsafe("signin.error.removeSwitchButton"); |
+ |
+ double height; |
+ bool success = args->GetDouble(0, &height); |
+ DCHECK(success); |
+ |
+ Browser* browser = GetDesktopBrowser(); |
+ browser->signin_view_controller()->SetModalSigninHeight( |
+ static_cast<int>(height)); |
+ |
+ // After the dialog is shown, some platforms might have an element focused. |
+ // To be consistent, clear the focused element on all platforms. |
+ // TODO(anthonyvd): Figure out why this is needed on Mac and not other |
+ // platforms and if there's a way to start unfocused while avoiding this |
+ // workaround. |
+ web_ui()->CallJavascriptFunctionUnsafe("signin.error.clearFocus"); |
+} |
+ |
+Browser* SigninErrorHandler::GetDesktopBrowser() { |
anthonyvd
2016/08/22 14:58:46
This code seems to be written in a few places. Can
Jane
2016/08/22 20:48:31
Done, good point! I couldn't find a good place to
|
+ Browser* browser = |
+ chrome::FindBrowserWithWebContents(web_ui()->GetWebContents()); |
+ if (!browser) |
+ browser = chrome::FindLastActiveWithProfile(Profile::FromWebUI(web_ui())); |
+ DCHECK(browser); |
+ return browser; |
+} |
+ |
+void SigninErrorHandler::CloseDialog() { |
+ Browser* browser = GetDesktopBrowser(); |
+ browser->CloseModalSigninWindow(); |
+} |