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/signin_utils.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::HandleSwitchToExistingProfile( |
| 35 const base::ListValue* args) { |
| 36 if (!duplicate_profile_entry_) |
| 37 return; |
| 38 CloseDialog(); |
| 39 // Switch to the existing duplicate profile. Do not create a new window when |
| 40 // any existing ones can be reused. |
| 41 profiles::SwitchToProfile(duplicate_profile_entry_->GetPath(), false, |
| 42 ProfileManager::CreateCallback(), |
| 43 ProfileMetrics::SWITCH_PROFILE_DUPLICATE); |
| 44 } |
| 45 |
| 46 void SigninErrorHandler::HandleConfirm(const base::ListValue* args) { |
| 47 CloseDialog(); |
| 48 } |
| 49 |
| 50 void SigninErrorHandler::HandleLearnMore(const base::ListValue* args) { |
| 51 Browser* browser = signin::GetDesktopBrowser(web_ui()); |
| 52 DCHECK(browser); |
| 53 browser->CloseModalSigninWindow(); |
| 54 signin_ui_util::ShowSigninErrorLearnMorePage(browser->profile()); |
| 55 } |
| 56 |
| 57 void SigninErrorHandler::HandleInitializedWithSize( |
| 58 const base::ListValue* args) { |
| 59 if (!duplicate_profile_entry_) |
| 60 web_ui()->CallJavascriptFunctionUnsafe("signin.error.removeSwitchButton"); |
| 61 |
| 62 signin::SetInitializedModalHeight(web_ui(), args); |
| 63 |
| 64 // After the dialog is shown, some platforms might have an element focused. |
| 65 // To be consistent, clear the focused element on all platforms. |
| 66 // TODO(anthonyvd): Figure out why this is needed on Mac and not other |
| 67 // platforms and if there's a way to start unfocused while avoiding this |
| 68 // workaround. |
| 69 web_ui()->CallJavascriptFunctionUnsafe("signin.error.clearFocus"); |
| 70 } |
| 71 |
| 72 void SigninErrorHandler::CloseDialog() { |
| 73 Browser* browser = signin::GetDesktopBrowser(web_ui()); |
| 74 DCHECK(browser); |
| 75 browser->CloseModalSigninWindow(); |
| 76 } |
OLD | NEW |