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 <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | 10 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
11 #include "chrome/browser/signin/account_tracker_service_factory.h" | 11 #include "chrome/browser/signin/account_tracker_service_factory.h" |
12 #include "chrome/browser/signin/signin_manager_factory.h" | 12 #include "chrome/browser/signin/signin_manager_factory.h" |
13 #include "chrome/browser/ui/browser_finder.h" | |
14 #include "chrome/browser/ui/browser_window.h" | 13 #include "chrome/browser/ui/browser_window.h" |
15 #include "chrome/browser/ui/signin_view_controller_delegate.h" | 14 #include "chrome/browser/ui/signin_view_controller_delegate.h" |
16 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 15 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
| 16 #include "chrome/browser/ui/webui/signin/signin_utils.h" |
17 #include "components/signin/core/browser/account_tracker_service.h" | 17 #include "components/signin/core/browser/account_tracker_service.h" |
18 #include "content/public/browser/user_metrics.h" | 18 #include "content/public/browser/user_metrics.h" |
19 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
20 #include "content/public/browser/web_ui.h" | 20 #include "content/public/browser/web_ui.h" |
21 #include "url/gurl.h" | 21 #include "url/gurl.h" |
22 | 22 |
23 const int kProfileImageSize = 128; | 23 const int kProfileImageSize = 128; |
24 | 24 |
25 SyncConfirmationHandler::SyncConfirmationHandler() | 25 SyncConfirmationHandler::SyncConfirmationHandler() |
26 : did_user_explicitly_interact(false) {} | 26 : did_user_explicitly_interact(false) {} |
(...skipping 30 matching lines...) Expand all Loading... |
57 } | 57 } |
58 | 58 |
59 void SyncConfirmationHandler::HandleGoToSettings(const base::ListValue* args) { | 59 void SyncConfirmationHandler::HandleGoToSettings(const base::ListValue* args) { |
60 did_user_explicitly_interact = true; | 60 did_user_explicitly_interact = true; |
61 CloseModalSigninWindow(LoginUIService::CONFIGURE_SYNC_FIRST); | 61 CloseModalSigninWindow(LoginUIService::CONFIGURE_SYNC_FIRST); |
62 } | 62 } |
63 | 63 |
64 void SyncConfirmationHandler::HandleUndo(const base::ListValue* args) { | 64 void SyncConfirmationHandler::HandleUndo(const base::ListValue* args) { |
65 did_user_explicitly_interact = true; | 65 did_user_explicitly_interact = true; |
66 content::RecordAction(base::UserMetricsAction("Signin_Undo_Signin")); | 66 content::RecordAction(base::UserMetricsAction("Signin_Undo_Signin")); |
67 Browser* browser = GetDesktopBrowser(); | 67 Browser* browser = signin::GetDesktopBrowser(web_ui()); |
| 68 DCHECK(browser); |
68 LoginUIServiceFactory::GetForProfile(browser->profile())-> | 69 LoginUIServiceFactory::GetForProfile(browser->profile())-> |
69 SyncConfirmationUIClosed(LoginUIService::ABORT_SIGNIN); | 70 SyncConfirmationUIClosed(LoginUIService::ABORT_SIGNIN); |
70 SigninManagerFactory::GetForProfile(Profile::FromWebUI(web_ui()))->SignOut( | 71 SigninManagerFactory::GetForProfile(Profile::FromWebUI(web_ui()))->SignOut( |
71 signin_metrics::ABORT_SIGNIN, | 72 signin_metrics::ABORT_SIGNIN, |
72 signin_metrics::SignoutDelete::IGNORE_METRIC); | 73 signin_metrics::SignoutDelete::IGNORE_METRIC); |
73 browser->CloseModalSigninWindow(); | 74 browser->CloseModalSigninWindow(); |
74 } | 75 } |
75 | 76 |
76 void SyncConfirmationHandler::SetUserImageURL(const std::string& picture_url) { | 77 void SyncConfirmationHandler::SetUserImageURL(const std::string& picture_url) { |
77 GURL url; | 78 GURL url; |
78 if (profiles::GetImageURLWithThumbnailSize(GURL(picture_url), | 79 if (profiles::GetImageURLWithThumbnailSize(GURL(picture_url), |
79 kProfileImageSize, | 80 kProfileImageSize, |
80 &url)) { | 81 &url)) { |
81 base::StringValue picture_url_value(url.spec()); | 82 base::StringValue picture_url_value(url.spec()); |
82 web_ui()->CallJavascriptFunctionUnsafe("sync.confirmation.setUserImageURL", | 83 web_ui()->CallJavascriptFunctionUnsafe("sync.confirmation.setUserImageURL", |
83 picture_url_value); | 84 picture_url_value); |
84 } | 85 } |
85 } | 86 } |
86 | 87 |
87 void SyncConfirmationHandler::OnAccountUpdated(const AccountInfo& info) { | 88 void SyncConfirmationHandler::OnAccountUpdated(const AccountInfo& info) { |
88 DCHECK(info.IsValid()); | 89 DCHECK(info.IsValid()); |
89 Profile* profile = Profile::FromWebUI(web_ui()); | 90 Profile* profile = Profile::FromWebUI(web_ui()); |
90 AccountTrackerServiceFactory::GetForProfile(profile)->RemoveObserver(this); | 91 AccountTrackerServiceFactory::GetForProfile(profile)->RemoveObserver(this); |
91 | 92 |
92 SetUserImageURL(info.picture_url); | 93 SetUserImageURL(info.picture_url); |
93 } | 94 } |
94 | 95 |
95 Browser* SyncConfirmationHandler::GetDesktopBrowser() { | |
96 Browser* browser = chrome::FindBrowserWithWebContents( | |
97 web_ui()->GetWebContents()); | |
98 if (!browser) | |
99 browser = chrome::FindLastActiveWithProfile(Profile::FromWebUI(web_ui())); | |
100 DCHECK(browser); | |
101 return browser; | |
102 } | |
103 | |
104 void SyncConfirmationHandler::CloseModalSigninWindow( | 96 void SyncConfirmationHandler::CloseModalSigninWindow( |
105 LoginUIService::SyncConfirmationUIClosedResult result) { | 97 LoginUIService::SyncConfirmationUIClosedResult result) { |
106 Browser* browser = GetDesktopBrowser(); | 98 Browser* browser = signin::GetDesktopBrowser(web_ui()); |
| 99 DCHECK(browser); |
107 LoginUIServiceFactory::GetForProfile(browser->profile())-> | 100 LoginUIServiceFactory::GetForProfile(browser->profile())-> |
108 SyncConfirmationUIClosed(result); | 101 SyncConfirmationUIClosed(result); |
109 browser->CloseModalSigninWindow(); | 102 browser->CloseModalSigninWindow(); |
110 } | 103 } |
111 | 104 |
112 void SyncConfirmationHandler::HandleInitializedWithSize( | 105 void SyncConfirmationHandler::HandleInitializedWithSize( |
113 const base::ListValue* args) { | 106 const base::ListValue* args) { |
114 Browser* browser = GetDesktopBrowser(); | 107 Browser* browser = signin::GetDesktopBrowser(web_ui()); |
| 108 DCHECK(browser); |
115 Profile* profile = browser->profile(); | 109 Profile* profile = browser->profile(); |
116 std::vector<AccountInfo> accounts = | 110 std::vector<AccountInfo> accounts = |
117 AccountTrackerServiceFactory::GetForProfile(profile)->GetAccounts(); | 111 AccountTrackerServiceFactory::GetForProfile(profile)->GetAccounts(); |
118 | 112 |
119 if (accounts.empty()) | 113 if (accounts.empty()) |
120 return; | 114 return; |
121 | 115 |
122 AccountInfo primary_account_info = accounts[0]; | 116 AccountInfo primary_account_info = accounts[0]; |
123 | 117 |
124 if (!primary_account_info.IsValid()) | 118 if (!primary_account_info.IsValid()) |
125 AccountTrackerServiceFactory::GetForProfile(profile)->AddObserver(this); | 119 AccountTrackerServiceFactory::GetForProfile(profile)->AddObserver(this); |
126 else | 120 else |
127 SetUserImageURL(primary_account_info.picture_url); | 121 SetUserImageURL(primary_account_info.picture_url); |
128 | 122 |
129 double height; | 123 signin::SetInitializedModalHeight(web_ui(), args); |
130 bool success = args->GetDouble(0, &height); | |
131 DCHECK(success); | |
132 | |
133 browser->signin_view_controller()->SetModalSigninHeight( | |
134 static_cast<int>(height)); | |
135 | 124 |
136 // After the dialog is shown, some platforms might have an element focused. | 125 // After the dialog is shown, some platforms might have an element focused. |
137 // To be consistent, clear the focused element on all platforms. | 126 // To be consistent, clear the focused element on all platforms. |
138 // TODO(anthonyvd): Figure out why this is needed on Mac and not other | 127 // TODO(anthonyvd): Figure out why this is needed on Mac and not other |
139 // platforms and if there's a way to start unfocused while avoiding this | 128 // platforms and if there's a way to start unfocused while avoiding this |
140 // workaround. | 129 // workaround. |
141 web_ui()->CallJavascriptFunctionUnsafe("sync.confirmation.clearFocus"); | 130 web_ui()->CallJavascriptFunctionUnsafe("sync.confirmation.clearFocus"); |
142 } | 131 } |
OLD | NEW |