| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/webui/signin/sync_confirmation_handler.h" | 5 #include "chrome/browser/ui/webui/signin/sync_confirmation_handler.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | 8 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
| 9 #include "chrome/browser/signin/account_tracker_service_factory.h" | 9 #include "chrome/browser/signin/account_tracker_service_factory.h" |
| 10 #include "chrome/browser/signin/signin_manager_factory.h" | 10 #include "chrome/browser/signin/signin_manager_factory.h" |
| 11 #include "chrome/browser/ui/browser_finder.h" | 11 #include "chrome/browser/ui/browser_finder.h" |
| 12 #include "chrome/browser/ui/browser_window.h" | 12 #include "chrome/browser/ui/browser_window.h" |
| 13 #include "chrome/browser/ui/signin_view_controller_delegate.h" |
| 13 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 14 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
| 14 #include "components/signin/core/browser/account_tracker_service.h" | 15 #include "components/signin/core/browser/account_tracker_service.h" |
| 15 #include "content/public/browser/user_metrics.h" | 16 #include "content/public/browser/user_metrics.h" |
| 16 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
| 17 #include "content/public/browser/web_ui.h" | 18 #include "content/public/browser/web_ui.h" |
| 18 #include "url/gurl.h" | 19 #include "url/gurl.h" |
| 19 | 20 |
| 20 const int kProfileImageSize = 128; | 21 const int kProfileImageSize = 128; |
| 21 | 22 |
| 22 SyncConfirmationHandler::SyncConfirmationHandler() {} | 23 SyncConfirmationHandler::SyncConfirmationHandler() {} |
| 23 | 24 |
| 24 SyncConfirmationHandler::~SyncConfirmationHandler() { | 25 SyncConfirmationHandler::~SyncConfirmationHandler() { |
| 25 Profile* profile = Profile::FromWebUI(web_ui()); | 26 Profile* profile = Profile::FromWebUI(web_ui()); |
| 26 AccountTrackerServiceFactory::GetForProfile(profile)->RemoveObserver(this); | 27 AccountTrackerServiceFactory::GetForProfile(profile)->RemoveObserver(this); |
| 27 } | 28 } |
| 28 | 29 |
| 29 void SyncConfirmationHandler::RegisterMessages() { | 30 void SyncConfirmationHandler::RegisterMessages() { |
| 30 web_ui()->RegisterMessageCallback("confirm", | 31 web_ui()->RegisterMessageCallback("confirm", |
| 31 base::Bind(&SyncConfirmationHandler::HandleConfirm, | 32 base::Bind(&SyncConfirmationHandler::HandleConfirm, |
| 32 base::Unretained(this))); | 33 base::Unretained(this))); |
| 33 web_ui()->RegisterMessageCallback("undo", | 34 web_ui()->RegisterMessageCallback("undo", |
| 34 base::Bind(&SyncConfirmationHandler::HandleUndo, base::Unretained(this))); | 35 base::Bind(&SyncConfirmationHandler::HandleUndo, base::Unretained(this))); |
| 35 web_ui()->RegisterMessageCallback("initialized", | |
| 36 base::Bind(&SyncConfirmationHandler::HandleInitialized, | |
| 37 base::Unretained(this))); | |
| 38 web_ui()->RegisterMessageCallback("goToSettings", | 36 web_ui()->RegisterMessageCallback("goToSettings", |
| 39 base::Bind(&SyncConfirmationHandler::HandleGoToSettings, | 37 base::Bind(&SyncConfirmationHandler::HandleGoToSettings, |
| 40 base::Unretained(this))); | 38 base::Unretained(this))); |
| 39 web_ui()->RegisterMessageCallback("initializedWithSize", |
| 40 base::Bind(&SyncConfirmationHandler::HandleInitializedWithSize, |
| 41 base::Unretained(this))); |
| 41 } | 42 } |
| 42 | 43 |
| 43 void SyncConfirmationHandler::HandleConfirm(const base::ListValue* args) { | 44 void SyncConfirmationHandler::HandleConfirm(const base::ListValue* args) { |
| 44 CloseModalSigninWindow(LoginUIService::SYNC_WITH_DEFAULT_SETTINGS); | 45 CloseModalSigninWindow(LoginUIService::SYNC_WITH_DEFAULT_SETTINGS); |
| 45 } | 46 } |
| 46 | 47 |
| 47 void SyncConfirmationHandler::HandleGoToSettings(const base::ListValue* args) { | 48 void SyncConfirmationHandler::HandleGoToSettings(const base::ListValue* args) { |
| 48 CloseModalSigninWindow(LoginUIService::CONFIGURE_SYNC_FIRST); | 49 CloseModalSigninWindow(LoginUIService::CONFIGURE_SYNC_FIRST); |
| 49 } | 50 } |
| 50 | 51 |
| 51 void SyncConfirmationHandler::HandleUndo(const base::ListValue* args) { | 52 void SyncConfirmationHandler::HandleUndo(const base::ListValue* args) { |
| 52 content::RecordAction(base::UserMetricsAction("Signin_Undo_Signin")); | 53 content::RecordAction(base::UserMetricsAction("Signin_Undo_Signin")); |
| 53 Browser* browser = GetDesktopBrowser(); | 54 Browser* browser = GetDesktopBrowser(); |
| 54 LoginUIServiceFactory::GetForProfile(browser->profile())-> | 55 LoginUIServiceFactory::GetForProfile(browser->profile())-> |
| 55 SyncConfirmationUIClosed(LoginUIService::ABORT_SIGNIN); | 56 SyncConfirmationUIClosed(LoginUIService::ABORT_SIGNIN); |
| 56 SigninManagerFactory::GetForProfile(Profile::FromWebUI(web_ui()))->SignOut( | 57 SigninManagerFactory::GetForProfile(Profile::FromWebUI(web_ui()))->SignOut( |
| 57 signin_metrics::ABORT_SIGNIN, | 58 signin_metrics::ABORT_SIGNIN, |
| 58 signin_metrics::SignoutDelete::IGNORE_METRIC); | 59 signin_metrics::SignoutDelete::IGNORE_METRIC); |
| 59 browser->CloseModalSigninWindow(); | 60 browser->CloseModalSigninWindow(); |
| 60 } | 61 } |
| 61 | 62 |
| 62 void SyncConfirmationHandler::HandleInitialized(const base::ListValue* args) { | |
| 63 Browser* browser = GetDesktopBrowser(); | |
| 64 Profile* profile = browser->profile(); | |
| 65 std::vector<AccountInfo> accounts = | |
| 66 AccountTrackerServiceFactory::GetForProfile(profile)->GetAccounts(); | |
| 67 | |
| 68 if (accounts.empty()) | |
| 69 return; | |
| 70 | |
| 71 AccountInfo primary_account_info = accounts[0]; | |
| 72 | |
| 73 if (!primary_account_info.IsValid()) | |
| 74 AccountTrackerServiceFactory::GetForProfile(profile)->AddObserver(this); | |
| 75 else | |
| 76 SetUserImageURL(primary_account_info.picture_url); | |
| 77 } | |
| 78 | |
| 79 void SyncConfirmationHandler::SetUserImageURL(const std::string& picture_url) { | 63 void SyncConfirmationHandler::SetUserImageURL(const std::string& picture_url) { |
| 80 GURL url; | 64 GURL url; |
| 81 if (profiles::GetImageURLWithThumbnailSize(GURL(picture_url), | 65 if (profiles::GetImageURLWithThumbnailSize(GURL(picture_url), |
| 82 kProfileImageSize, | 66 kProfileImageSize, |
| 83 &url)) { | 67 &url)) { |
| 84 base::StringValue picture_url_value(url.spec()); | 68 base::StringValue picture_url_value(url.spec()); |
| 85 web_ui()->CallJavascriptFunction( | 69 web_ui()->CallJavascriptFunction( |
| 86 "sync.confirmation.setUserImageURL", picture_url_value); | 70 "sync.confirmation.setUserImageURL", picture_url_value); |
| 87 } | 71 } |
| 88 } | 72 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 104 return browser; | 88 return browser; |
| 105 } | 89 } |
| 106 | 90 |
| 107 void SyncConfirmationHandler::CloseModalSigninWindow( | 91 void SyncConfirmationHandler::CloseModalSigninWindow( |
| 108 LoginUIService::SyncConfirmationUIClosedResults results) { | 92 LoginUIService::SyncConfirmationUIClosedResults results) { |
| 109 Browser* browser = GetDesktopBrowser(); | 93 Browser* browser = GetDesktopBrowser(); |
| 110 LoginUIServiceFactory::GetForProfile(browser->profile())-> | 94 LoginUIServiceFactory::GetForProfile(browser->profile())-> |
| 111 SyncConfirmationUIClosed(results); | 95 SyncConfirmationUIClosed(results); |
| 112 browser->CloseModalSigninWindow(); | 96 browser->CloseModalSigninWindow(); |
| 113 } | 97 } |
| 98 |
| 99 void SyncConfirmationHandler::HandleInitializedWithSize( |
| 100 const base::ListValue* args) { |
| 101 Browser* browser = GetDesktopBrowser(); |
| 102 Profile* profile = browser->profile(); |
| 103 std::vector<AccountInfo> accounts = |
| 104 AccountTrackerServiceFactory::GetForProfile(profile)->GetAccounts(); |
| 105 |
| 106 if (accounts.empty()) |
| 107 return; |
| 108 |
| 109 AccountInfo primary_account_info = accounts[0]; |
| 110 |
| 111 if (!primary_account_info.IsValid()) |
| 112 AccountTrackerServiceFactory::GetForProfile(profile)->AddObserver(this); |
| 113 else |
| 114 SetUserImageURL(primary_account_info.picture_url); |
| 115 |
| 116 double height; |
| 117 bool success = args->GetDouble(0, &height); |
| 118 DCHECK(success); |
| 119 |
| 120 browser->signin_view_controller()->delegate()->ResizeNativeView( |
| 121 static_cast<int>(height)); |
| 122 } |
| OLD | NEW |