Chromium Code Reviews| OLD | NEW |
|---|---|
| (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_window.h" | |
| 13 #include "chrome/browser/ui/webui/signin/get_desktop_browser.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 "switchToExistingProfile", | |
| 23 base::Bind(&SigninErrorHandler::HandleSwitchToExistingProfile, | |
| 24 base::Unretained(this))); | |
| 25 web_ui()->RegisterMessageCallback( | |
| 26 "learnMore", | |
| 27 base::Bind(&SigninErrorHandler::HandleLearnMore, base::Unretained(this))); | |
| 28 web_ui()->RegisterMessageCallback( | |
| 29 "initializedWithSize", | |
| 30 base::Bind(&SigninErrorHandler::HandleInitializedWithSize, | |
| 31 base::Unretained(this))); | |
| 32 } | |
| 33 | |
| 34 void SigninErrorHandler::set_duplicate_profile_entry( | |
| 35 const ProfileAttributesEntry* duplicate_profile_entry) { | |
| 36 duplicate_profile_entry_ = duplicate_profile_entry; | |
| 37 } | |
| 38 | |
| 39 void SigninErrorHandler::HandleSwitchToExistingProfile( | |
| 40 const base::ListValue* args) { | |
| 41 if (!duplicate_profile_entry_) | |
| 42 return; | |
| 43 CloseDialog(); | |
| 44 // Switch to the existing duplicate profile. Do not create a new window when | |
| 45 // any existing ones can be reused. | |
| 46 profiles::SwitchToProfile(duplicate_profile_entry_->GetPath(), false, | |
| 47 ProfileManager::CreateCallback(), | |
| 48 ProfileMetrics::SWITCH_PROFILE_DUPLICATE); | |
| 49 } | |
| 50 | |
| 51 void SigninErrorHandler::HandleConfirm(const base::ListValue* args) { | |
| 52 CloseDialog(); | |
| 53 } | |
| 54 | |
| 55 void SigninErrorHandler::HandleLearnMore(const base::ListValue* args) { | |
| 56 Browser* browser = signin::GetDesktopBrowser(web_ui()); | |
| 57 DCHECK(browser); | |
| 58 browser->CloseModalSigninWindow(); | |
| 59 signin_ui_util::ShowSigninErrorLearnMorePage(browser->profile()); | |
| 60 } | |
| 61 | |
| 62 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
| |
| 63 const base::ListValue* args) { | |
| 64 if (!duplicate_profile_entry_) | |
| 65 web_ui()->CallJavascriptFunctionUnsafe("signin.error.removeSwitchButton"); | |
| 66 | |
| 67 double height; | |
| 68 bool success = args->GetDouble(0, &height); | |
| 69 DCHECK(success); | |
| 70 | |
| 71 Browser* browser = signin::GetDesktopBrowser(web_ui()); | |
| 72 DCHECK(browser); | |
| 73 browser->signin_view_controller()->SetModalSigninHeight( | |
| 74 static_cast<int>(height)); | |
| 75 | |
| 76 // After the dialog is shown, some platforms might have an element focused. | |
| 77 // To be consistent, clear the focused element on all platforms. | |
| 78 // TODO(anthonyvd): Figure out why this is needed on Mac and not other | |
| 79 // platforms and if there's a way to start unfocused while avoiding this | |
| 80 // workaround. | |
| 81 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.
| |
| 82 } | |
| 83 | |
| 84 void SigninErrorHandler::CloseDialog() { | |
| 85 Browser* browser = signin::GetDesktopBrowser(web_ui()); | |
| 86 DCHECK(browser); | |
| 87 browser->CloseModalSigninWindow(); | |
| 88 } | |
| OLD | NEW |