Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3957)

Unified Diff: chrome/browser/ui/webui/signin/signin_error_handler.cc

Issue 2275883003: [Signin Error Dialog] (2/3) Added handlers and UI constructors (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@error-modal-web
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..503b0ea63cacf08c948bc902bc01d9ed79ddc069
--- /dev/null
+++ b/chrome/browser/ui/webui/signin/signin_error_handler.cc
@@ -0,0 +1,88 @@
+// 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_window.h"
+#include "chrome/browser/ui/webui/signin/get_desktop_browser.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(
+ "switchToExistingProfile",
+ base::Bind(&SigninErrorHandler::HandleSwitchToExistingProfile,
+ 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::HandleSwitchToExistingProfile(
+ const base::ListValue* args) {
+ if (!duplicate_profile_entry_)
+ return;
+ CloseDialog();
+ // Switch to the existing duplicate profile. Do not create a new window when
+ // any existing ones can be reused.
+ profiles::SwitchToProfile(duplicate_profile_entry_->GetPath(), false,
+ ProfileManager::CreateCallback(),
+ ProfileMetrics::SWITCH_PROFILE_DUPLICATE);
+}
+
+void SigninErrorHandler::HandleConfirm(const base::ListValue* args) {
+ CloseDialog();
+}
+
+void SigninErrorHandler::HandleLearnMore(const base::ListValue* args) {
+ Browser* browser = signin::GetDesktopBrowser(web_ui());
+ DCHECK(browser);
+ browser->CloseModalSigninWindow();
+ signin_ui_util::ShowSigninErrorLearnMorePage(browser->profile());
+}
+
+void SigninErrorHandler::HandleInitializedWithSize(
tommycli 2016/08/24 17:36:41 Is this strictly speaking necessary? Could the dia
Jane 2016/08/25 19:19:35 I'm not exactly sure why, but the dialog doesn't s
tommycli 2016/08/25 19:40:03 It seems that the height here is responding to the
Jane 2016/08/25 21:23:53 Talked to anthony, and the rationale is that the h
tommycli 2016/08/25 21:25:35 That's a good reason. If there's some way to refac
Jane 2016/08/26 14:18:04 Done. Refactored the height initialization part in
+ 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 = signin::GetDesktopBrowser(web_ui());
+ DCHECK(browser);
+ 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");
tommycli 2016/08/24 17:36:41 Yes, it seems odd to me that we're clearing the fo
Jane 2016/08/25 19:19:35 We discussed this on the upstream CL.
+}
+
+void SigninErrorHandler::CloseDialog() {
+ Browser* browser = signin::GetDesktopBrowser(web_ui());
+ DCHECK(browser);
+ browser->CloseModalSigninWindow();
+}

Powered by Google App Engine
This is Rietveld 408576698