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 LoginUIServiceFactory::GetForProfile(browser->profile())-> | 68 if (browser) { |
69 SyncConfirmationUIClosed(LoginUIService::ABORT_SIGNIN); | 69 LoginUIServiceFactory::GetForProfile(browser->profile())-> |
70 SigninManagerFactory::GetForProfile(Profile::FromWebUI(web_ui()))->SignOut( | 70 SyncConfirmationUIClosed(LoginUIService::ABORT_SIGNIN); |
71 signin_metrics::ABORT_SIGNIN, | 71 SigninManagerFactory::GetForProfile(Profile::FromWebUI(web_ui()))->SignOut( |
72 signin_metrics::SignoutDelete::IGNORE_METRIC); | 72 signin_metrics::ABORT_SIGNIN, |
73 browser->CloseModalSigninWindow(); | 73 signin_metrics::SignoutDelete::IGNORE_METRIC); |
| 74 browser->CloseModalSigninWindow(); |
| 75 } |
74 } | 76 } |
75 | 77 |
76 void SyncConfirmationHandler::SetUserImageURL(const std::string& picture_url) { | 78 void SyncConfirmationHandler::SetUserImageURL(const std::string& picture_url) { |
77 GURL url; | 79 GURL url; |
78 if (profiles::GetImageURLWithThumbnailSize(GURL(picture_url), | 80 if (profiles::GetImageURLWithThumbnailSize(GURL(picture_url), |
79 kProfileImageSize, | 81 kProfileImageSize, |
80 &url)) { | 82 &url)) { |
81 base::StringValue picture_url_value(url.spec()); | 83 base::StringValue picture_url_value(url.spec()); |
82 web_ui()->CallJavascriptFunctionUnsafe("sync.confirmation.setUserImageURL", | 84 web_ui()->CallJavascriptFunctionUnsafe("sync.confirmation.setUserImageURL", |
83 picture_url_value); | 85 picture_url_value); |
84 } | 86 } |
85 } | 87 } |
86 | 88 |
87 void SyncConfirmationHandler::OnAccountUpdated(const AccountInfo& info) { | 89 void SyncConfirmationHandler::OnAccountUpdated(const AccountInfo& info) { |
88 DCHECK(info.IsValid()); | 90 DCHECK(info.IsValid()); |
89 Profile* profile = Profile::FromWebUI(web_ui()); | 91 Profile* profile = Profile::FromWebUI(web_ui()); |
90 AccountTrackerServiceFactory::GetForProfile(profile)->RemoveObserver(this); | 92 AccountTrackerServiceFactory::GetForProfile(profile)->RemoveObserver(this); |
91 | 93 |
92 SetUserImageURL(info.picture_url); | 94 SetUserImageURL(info.picture_url); |
93 } | 95 } |
94 | 96 |
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( | 97 void SyncConfirmationHandler::CloseModalSigninWindow( |
105 LoginUIService::SyncConfirmationUIClosedResult result) { | 98 LoginUIService::SyncConfirmationUIClosedResult result) { |
106 Browser* browser = GetDesktopBrowser(); | 99 Browser* browser = signin::GetDesktopBrowser(web_ui()); |
107 LoginUIServiceFactory::GetForProfile(browser->profile())-> | 100 if (browser) { |
108 SyncConfirmationUIClosed(result); | 101 LoginUIServiceFactory::GetForProfile(browser->profile())-> |
109 browser->CloseModalSigninWindow(); | 102 SyncConfirmationUIClosed(result); |
| 103 browser->CloseModalSigninWindow(); |
| 104 } |
110 } | 105 } |
111 | 106 |
112 void SyncConfirmationHandler::HandleInitializedWithSize( | 107 void SyncConfirmationHandler::HandleInitializedWithSize( |
113 const base::ListValue* args) { | 108 const base::ListValue* args) { |
114 Browser* browser = GetDesktopBrowser(); | 109 Browser* browser = signin::GetDesktopBrowser(web_ui()); |
| 110 if (!browser) |
| 111 return; |
| 112 |
115 Profile* profile = browser->profile(); | 113 Profile* profile = browser->profile(); |
116 std::vector<AccountInfo> accounts = | 114 std::vector<AccountInfo> accounts = |
117 AccountTrackerServiceFactory::GetForProfile(profile)->GetAccounts(); | 115 AccountTrackerServiceFactory::GetForProfile(profile)->GetAccounts(); |
118 | 116 |
119 if (accounts.empty()) | 117 if (accounts.empty()) |
120 return; | 118 return; |
121 | 119 |
122 AccountInfo primary_account_info = accounts[0]; | 120 AccountInfo primary_account_info = accounts[0]; |
123 | 121 |
124 if (!primary_account_info.IsValid()) | 122 if (!primary_account_info.IsValid()) |
125 AccountTrackerServiceFactory::GetForProfile(profile)->AddObserver(this); | 123 AccountTrackerServiceFactory::GetForProfile(profile)->AddObserver(this); |
126 else | 124 else |
127 SetUserImageURL(primary_account_info.picture_url); | 125 SetUserImageURL(primary_account_info.picture_url); |
128 | 126 |
129 double height; | 127 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 | 128 |
136 // After the dialog is shown, some platforms might have an element focused. | 129 // After the dialog is shown, some platforms might have an element focused. |
137 // To be consistent, clear the focused element on all platforms. | 130 // To be consistent, clear the focused element on all platforms. |
138 // TODO(anthonyvd): Figure out why this is needed on Mac and not other | 131 // 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 | 132 // platforms and if there's a way to start unfocused while avoiding this |
140 // workaround. | 133 // workaround. |
141 web_ui()->CallJavascriptFunctionUnsafe("sync.confirmation.clearFocus"); | 134 web_ui()->CallJavascriptFunctionUnsafe("sync.confirmation.clearFocus"); |
142 } | 135 } |
OLD | NEW |