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

Side by Side Diff: chrome/browser/ui/webui/signin/signin_error_handler.cc

Issue 2255413002: [Signin Error Dialog] (3/3) Added the triggering code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleared up Get/SetLastLoginErrorEmail 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/webui/signin/signin_error_handler.h"
6
7 #include "base/bind.h"
8 #include "chrome/browser/profiles/profile_attributes_entry.h"
9 #include "chrome/browser/profiles/profile_manager.h"
10 #include "chrome/browser/profiles/profile_window.h"
11 #include "chrome/browser/signin/signin_ui_util.h"
12 #include "chrome/browser/ui/browser_finder.h"
13 #include "chrome/browser/ui/browser_window.h"
14 #include "content/public/browser/web_ui.h"
15 #include "url/gurl.h"
16
17 void SigninErrorHandler::RegisterMessages() {
18 web_ui()->RegisterMessageCallback(
19 "confirm",
20 base::Bind(&SigninErrorHandler::HandleConfirm, base::Unretained(this)));
21 web_ui()->RegisterMessageCallback(
22 "switch",
23 base::Bind(&SigninErrorHandler::HandleSwitch, base::Unretained(this)));
24 web_ui()->RegisterMessageCallback(
25 "learnMore",
26 base::Bind(&SigninErrorHandler::HandleLearnMore, base::Unretained(this)));
27 web_ui()->RegisterMessageCallback(
28 "initializedWithSize",
29 base::Bind(&SigninErrorHandler::HandleInitializedWithSize,
30 base::Unretained(this)));
31 }
32
33 void SigninErrorHandler::set_duplicate_profile_entry(
34 const ProfileAttributesEntry* duplicate_profile_entry) {
35 duplicate_profile_entry_ = duplicate_profile_entry;
36 }
37
38 void SigninErrorHandler::HandleSwitch(const base::ListValue* args) {
39 if (!duplicate_profile_entry_)
40 return;
41 CloseDialog();
42 profiles::SwitchToProfile(duplicate_profile_entry_->GetPath(),
43 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
44 ProfileManager::CreateCallback(),
45 ProfileMetrics::SWITCH_PROFILE_DUPLICATE);
46 }
47
48 void SigninErrorHandler::HandleConfirm(const base::ListValue* args) {
49 CloseDialog();
50 }
51
52 void SigninErrorHandler::HandleLearnMore(const base::ListValue* args) {
53 Browser* browser = GetDesktopBrowser();
54 browser->CloseModalSigninWindow();
55 signin_ui_util::ShowSigninErrorLearnMorePage(browser->profile());
56 }
57
58 void SigninErrorHandler::HandleInitializedWithSize(
59 const base::ListValue* args) {
60 if (!duplicate_profile_entry_)
61 web_ui()->CallJavascriptFunctionUnsafe("signin.error.removeSwitchButton");
62
63 double height;
64 bool success = args->GetDouble(0, &height);
65 DCHECK(success);
66
67 Browser* browser = GetDesktopBrowser();
68 browser->signin_view_controller()->SetModalSigninHeight(
69 static_cast<int>(height));
70
71 // After the dialog is shown, some platforms might have an element focused.
72 // To be consistent, clear the focused element on all platforms.
73 // TODO(anthonyvd): Figure out why this is needed on Mac and not other
74 // platforms and if there's a way to start unfocused while avoiding this
75 // workaround.
76 web_ui()->CallJavascriptFunctionUnsafe("signin.error.clearFocus");
77 }
78
79 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
80 Browser* browser =
81 chrome::FindBrowserWithWebContents(web_ui()->GetWebContents());
82 if (!browser)
83 browser = chrome::FindLastActiveWithProfile(Profile::FromWebUI(web_ui()));
84 DCHECK(browser);
85 return browser;
86 }
87
88 void SigninErrorHandler::CloseDialog() {
89 Browser* browser = GetDesktopBrowser();
90 browser->CloseModalSigninWindow();
91 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698