OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/signin/chrome_signin_helper.h" | 5 #include "chrome/browser/signin/chrome_signin_helper.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
10 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 10 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
11 #include "chrome/browser/profiles/profile_io_data.h" | 11 #include "chrome/browser/profiles/profile_io_data.h" |
12 #include "chrome/browser/signin/account_reconcilor_factory.h" | 12 #include "chrome/browser/signin/account_reconcilor_factory.h" |
13 #include "chrome/browser/signin/chrome_signin_client.h" | 13 #include "chrome/browser/signin/chrome_signin_client.h" |
| 14 #include "chrome/browser/signin/chrome_signin_client_factory.h" |
| 15 #include "chrome/browser/signin/dice_response_handler.h" |
14 #include "chrome/browser/tab_contents/tab_util.h" | 16 #include "chrome/browser/tab_contents/tab_util.h" |
15 #include "chrome/browser/ui/browser_window.h" | 17 #include "chrome/browser/ui/browser_window.h" |
16 #include "chrome/common/url_constants.h" | 18 #include "chrome/common/url_constants.h" |
17 #include "components/signin/core/browser/account_reconcilor.h" | 19 #include "components/signin/core/browser/account_reconcilor.h" |
18 #include "components/signin/core/browser/chrome_connected_header_helper.h" | 20 #include "components/signin/core/browser/chrome_connected_header_helper.h" |
19 #include "components/signin/core/browser/signin_header_helper.h" | 21 #include "components/signin/core/browser/signin_header_helper.h" |
20 #include "components/signin/core/common/profile_management_switches.h" | 22 #include "components/signin/core/common/profile_management_switches.h" |
21 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
22 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
23 #include "google_apis/gaia/gaia_auth_util.h" | 25 #include "google_apis/gaia/gaia_auth_util.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, false)); | 100 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, false)); |
99 } else { | 101 } else { |
100 signin_metrics::LogAccountReconcilorStateOnGaiaResponse( | 102 signin_metrics::LogAccountReconcilorStateOnGaiaResponse( |
101 account_reconcilor->GetState()); | 103 account_reconcilor->GetState()); |
102 AccountManagementScreenHelper::OpenAccountManagementScreen(profile, | 104 AccountManagementScreenHelper::OpenAccountManagementScreen(profile, |
103 service_type); | 105 service_type); |
104 } | 106 } |
105 #endif // !defined(OS_ANDROID) | 107 #endif // !defined(OS_ANDROID) |
106 } | 108 } |
107 | 109 |
| 110 #if !defined(OS_ANDROID) |
| 111 void ProcessDiceHeaderUIThread( |
| 112 const DiceResponseParams& dice_params, |
| 113 const content::ResourceRequestInfo::WebContentsGetter& |
| 114 web_contents_getter) { |
| 115 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 116 DCHECK_EQ(switches::AccountConsistencyMethod::kDice, |
| 117 switches::GetAccountConsistencyMethod()); |
| 118 |
| 119 content::WebContents* web_contents = web_contents_getter.Run(); |
| 120 if (!web_contents) |
| 121 return; |
| 122 |
| 123 Profile* profile = |
| 124 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 125 DCHECK(!profile->IsOffTheRecord()); |
| 126 |
| 127 DiceResponseHandler* dice_response_handler = |
| 128 DiceResponseHandler::GetForProfile(profile); |
| 129 dice_response_handler->ProcessDiceHeader(dice_params); |
| 130 } |
| 131 #endif // !defined(OS_ANDROID) |
| 132 |
108 // Looks for the X-Chrome-Manage-Accounts response header, and if found, | 133 // Looks for the X-Chrome-Manage-Accounts response header, and if found, |
109 // tries to show the avatar bubble in the browser identified by the | 134 // tries to show the avatar bubble in the browser identified by the |
110 // child/route id. Must be called on IO thread. | 135 // child/route id. Must be called on IO thread. |
111 void ProcessMirrorResponseHeaderIfExists( | 136 void ProcessMirrorResponseHeaderIfExists( |
112 net::URLRequest* request, | 137 net::URLRequest* request, |
113 ProfileIOData* io_data, | 138 ProfileIOData* io_data, |
114 const content::ResourceRequestInfo::WebContentsGetter& | 139 const content::ResourceRequestInfo::WebContentsGetter& |
115 web_contents_getter) { | 140 web_contents_getter) { |
116 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 141 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
117 | 142 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 // garbage, then |service_type| is set to |GAIA_SERVICE_TYPE_NONE|. | 176 // garbage, then |service_type| is set to |GAIA_SERVICE_TYPE_NONE|. |
152 if (params.service_type == GAIA_SERVICE_TYPE_NONE) | 177 if (params.service_type == GAIA_SERVICE_TYPE_NONE) |
153 return; | 178 return; |
154 | 179 |
155 content::BrowserThread::PostTask( | 180 content::BrowserThread::PostTask( |
156 content::BrowserThread::UI, FROM_HERE, | 181 content::BrowserThread::UI, FROM_HERE, |
157 base::Bind(ProcessMirrorHeaderUIThread, params, web_contents_getter)); | 182 base::Bind(ProcessMirrorHeaderUIThread, params, web_contents_getter)); |
158 } | 183 } |
159 | 184 |
160 #if !defined(OS_ANDROID) | 185 #if !defined(OS_ANDROID) |
161 void ProcessDiceResponseHeaderIfExists(net::URLRequest* request, | 186 void ProcessDiceResponseHeaderIfExists( |
162 ProfileIOData* io_data) { | 187 net::URLRequest* request, |
| 188 ProfileIOData* io_data, |
| 189 const content::ResourceRequestInfo::WebContentsGetter& |
| 190 web_contents_getter) { |
163 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 191 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
164 | 192 |
165 if (io_data->IsOffTheRecord()) | 193 if (io_data->IsOffTheRecord()) |
166 return; | 194 return; |
167 | 195 |
168 const content::ResourceRequestInfo* info = | 196 const content::ResourceRequestInfo* info = |
169 content::ResourceRequestInfo::ForRequest(request); | 197 content::ResourceRequestInfo::ForRequest(request); |
170 if (!(info && info->GetResourceType() == content::RESOURCE_TYPE_MAIN_FRAME)) | 198 if (!(info && info->GetResourceType() == content::RESOURCE_TYPE_MAIN_FRAME)) |
171 return; | 199 return; |
172 | 200 |
(...skipping 14 matching lines...) Expand all Loading... |
187 &header_value)) { | 215 &header_value)) { |
188 return; | 216 return; |
189 } | 217 } |
190 | 218 |
191 DiceResponseParams params = BuildDiceResponseParams(header_value); | 219 DiceResponseParams params = BuildDiceResponseParams(header_value); |
192 // If the request does not have a response header or if the header contains | 220 // If the request does not have a response header or if the header contains |
193 // garbage, then |user_intention| is set to |NONE|. | 221 // garbage, then |user_intention| is set to |NONE|. |
194 if (params.user_intention == DiceAction::NONE) | 222 if (params.user_intention == DiceAction::NONE) |
195 return; | 223 return; |
196 | 224 |
197 // TODO(droger): Process the Dice header: on sign-in, exchange the | 225 content::BrowserThread::PostTask( |
198 // authorization code for a refresh token, on sign-out just follow the | 226 content::BrowserThread::UI, FROM_HERE, |
199 // sign-out URL. | 227 base::Bind(ProcessDiceHeaderUIThread, params, web_contents_getter)); |
200 } | 228 } |
201 #endif // !defined(OS_ANDROID) | 229 #endif // !defined(OS_ANDROID) |
202 | 230 |
203 } // namespace | 231 } // namespace |
204 | 232 |
205 void FixAccountConsistencyRequestHeader(net::URLRequest* request, | 233 void FixAccountConsistencyRequestHeader(net::URLRequest* request, |
206 const GURL& redirect_url, | 234 const GURL& redirect_url, |
207 ProfileIOData* io_data, | 235 ProfileIOData* io_data, |
208 int child_id, | 236 int child_id, |
209 int route_id) { | 237 int route_id) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 const GURL& redirect_url, | 273 const GURL& redirect_url, |
246 ProfileIOData* io_data, | 274 ProfileIOData* io_data, |
247 const content::ResourceRequestInfo::WebContentsGetter& | 275 const content::ResourceRequestInfo::WebContentsGetter& |
248 web_contents_getter) { | 276 web_contents_getter) { |
249 if (redirect_url.is_empty()) { | 277 if (redirect_url.is_empty()) { |
250 // This is not a redirect. | 278 // This is not a redirect. |
251 | 279 |
252 // See if the response contains the X-Chrome-Manage-Accounts header. If so | 280 // See if the response contains the X-Chrome-Manage-Accounts header. If so |
253 // show the profile avatar bubble so that user can complete signin/out | 281 // show the profile avatar bubble so that user can complete signin/out |
254 // action the native UI. | 282 // action the native UI. |
255 signin::ProcessMirrorResponseHeaderIfExists(request, io_data, | 283 ProcessMirrorResponseHeaderIfExists(request, io_data, web_contents_getter); |
256 web_contents_getter); | |
257 } else { | 284 } else { |
258 // This is a redirect. | 285 // This is a redirect. |
259 | 286 |
260 #if !defined(OS_ANDROID) | 287 #if !defined(OS_ANDROID) |
261 // Process the Dice header: on sign-in, exchange the authorization code for | 288 // Process the Dice header: on sign-in, exchange the authorization code for |
262 // a refresh token, on sign-out just follow the sign-out URL. | 289 // a refresh token, on sign-out just follow the sign-out URL. |
263 signin::ProcessDiceResponseHeaderIfExists(request, io_data); | 290 ProcessDiceResponseHeaderIfExists(request, io_data, web_contents_getter); |
264 #endif | 291 #endif |
265 } | 292 } |
266 } | 293 } |
267 | 294 |
268 } // namespace signin | 295 } // namespace signin |
OLD | NEW |