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/ui/webui/inline_login_ui.h" | 5 #include "chrome/browser/ui/webui/inline_login_ui.h" |
6 | 6 |
7 #include "base/atomic_sequence_num.h" | 7 #include "base/atomic_sequence_num.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/command_line.h" | |
10 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
11 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
12 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
13 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
14 #include "base/values.h" | 13 #include "base/values.h" |
15 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
16 #include "chrome/browser/extensions/tab_helper.h" | 15 #include "chrome/browser/extensions/tab_helper.h" |
17 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/signin/profile_oauth2_token_service.h" | 17 #include "chrome/browser/signin/profile_oauth2_token_service.h" |
19 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 18 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
20 #include "chrome/browser/signin/signin_global_error.h" | 19 #include "chrome/browser/signin/signin_global_error.h" |
21 #include "chrome/browser/signin/signin_names_io_thread.h" | 20 #include "chrome/browser/signin/signin_names_io_thread.h" |
22 #include "chrome/browser/signin/signin_oauth_helper.h" | 21 #include "chrome/browser/signin/signin_oauth_helper.h" |
23 #include "chrome/browser/signin/signin_promo.h" | 22 #include "chrome/browser/signin/signin_promo.h" |
24 #include "chrome/browser/sync/profile_sync_service.h" | 23 #include "chrome/browser/sync/profile_sync_service.h" |
25 #include "chrome/browser/sync/profile_sync_service_factory.h" | 24 #include "chrome/browser/sync/profile_sync_service_factory.h" |
26 #include "chrome/browser/ui/browser_finder.h" | 25 #include "chrome/browser/ui/browser_finder.h" |
27 #include "chrome/browser/ui/sync/one_click_signin_helper.h" | 26 #include "chrome/browser/ui/sync/one_click_signin_helper.h" |
28 #include "chrome/browser/ui/sync/one_click_signin_sync_starter.h" | 27 #include "chrome/browser/ui/sync/one_click_signin_sync_starter.h" |
29 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 28 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
30 #include "chrome/common/profile_management_switches.h" | |
31 #include "chrome/common/url_constants.h" | 29 #include "chrome/common/url_constants.h" |
32 #include "content/public/browser/storage_partition.h" | 30 #include "content/public/browser/storage_partition.h" |
33 #include "content/public/browser/web_contents.h" | 31 #include "content/public/browser/web_contents.h" |
34 #include "content/public/browser/web_ui.h" | 32 #include "content/public/browser/web_ui.h" |
35 #include "content/public/browser/web_ui_data_source.h" | 33 #include "content/public/browser/web_ui_data_source.h" |
36 #include "content/public/browser/web_ui_message_handler.h" | 34 #include "content/public/browser/web_ui_message_handler.h" |
37 #include "google_apis/gaia/gaia_auth_consumer.h" | 35 #include "google_apis/gaia/gaia_auth_consumer.h" |
38 #include "google_apis/gaia/gaia_auth_fetcher.h" | 36 #include "google_apis/gaia/gaia_auth_fetcher.h" |
39 #include "google_apis/gaia/gaia_constants.h" | 37 #include "google_apis/gaia/gaia_constants.h" |
40 #include "google_apis/gaia/gaia_switches.h" | 38 #include "google_apis/gaia/gaia_switches.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 | 128 |
131 void LoadAuthExtension() { | 129 void LoadAuthExtension() { |
132 base::DictionaryValue params; | 130 base::DictionaryValue params; |
133 | 131 |
134 const std::string& app_locale = g_browser_process->GetApplicationLocale(); | 132 const std::string& app_locale = g_browser_process->GetApplicationLocale(); |
135 params.SetString("hl", app_locale); | 133 params.SetString("hl", app_locale); |
136 | 134 |
137 GaiaUrls* gaiaUrls = GaiaUrls::GetInstance(); | 135 GaiaUrls* gaiaUrls = GaiaUrls::GetInstance(); |
138 params.SetString("gaiaUrl", gaiaUrls->gaia_url().spec()); | 136 params.SetString("gaiaUrl", gaiaUrls->gaia_url().spec()); |
139 | 137 |
140 bool enable_inline = switches::IsEnableInlineSignin(); | |
141 params.SetInteger("authMode", | |
142 enable_inline ? kInlineAuthMode : kDefaultAuthMode); | |
143 | 138 |
144 // Set parameters specific for inline signin flow. | 139 #if defined(OS_CHROMEOS) |
145 #if !defined(OS_CHROMEOS) | 140 params.SetInteger("authMode", kDefaultAuthMode); |
146 if (enable_inline) { | 141 #else |
| 142 params.SetInteger("authMode", kInlineAuthMode); |
147 | 143 |
148 const GURL& current_url = web_ui()->GetWebContents()->GetURL(); | 144 const GURL& current_url = web_ui()->GetWebContents()->GetURL(); |
149 signin::Source source = signin::GetSourceForPromoURL(current_url); | 145 signin::Source source = signin::GetSourceForPromoURL(current_url); |
150 DCHECK(source != signin::SOURCE_UNKNOWN); | 146 DCHECK(source != signin::SOURCE_UNKNOWN); |
151 if (source == signin::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT || | 147 if (source == signin::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT || |
152 source == signin::SOURCE_AVATAR_BUBBLE_SIGN_IN) { | 148 source == signin::SOURCE_AVATAR_BUBBLE_SIGN_IN) { |
153 // Drop the leading slash in the path. | 149 // Drop the leading slash in the path. |
154 params.SetString("gaiaPath", | 150 params.SetString("gaiaPath", |
155 gaiaUrls->embedded_signin_url().path().substr(1)); | 151 gaiaUrls->embedded_signin_url().path().substr(1)); |
156 } | 152 } |
157 | 153 |
158 params.SetString("service", "chromiumsync"); | 154 params.SetString("service", "chromiumsync"); |
159 params.SetString("continueUrl", | 155 params.SetString("continueUrl", |
160 signin::GetLandingURL("source", static_cast<int>(source)).spec()); | 156 signin::GetLandingURL("source", static_cast<int>(source)).spec()); |
161 | 157 |
162 std::string email; | 158 std::string email; |
163 net::GetValueForKeyInQuery(current_url, "Email", &email); | 159 net::GetValueForKeyInQuery(current_url, "Email", &email); |
164 if (!email.empty()) | 160 if (!email.empty()) |
165 params.SetString("email", email); | 161 params.SetString("email", email); |
166 | 162 |
167 std::string frame_url; | 163 std::string frame_url; |
168 net::GetValueForKeyInQuery(current_url, "frameUrl", &frame_url); | 164 net::GetValueForKeyInQuery(current_url, "frameUrl", &frame_url); |
169 if (!frame_url.empty()) | 165 if (!frame_url.empty()) |
170 params.SetString("frameUrl", frame_url); | 166 params.SetString("frameUrl", frame_url); |
171 | 167 |
172 std::string is_constrained; | 168 std::string is_constrained; |
173 net::GetValueForKeyInQuery(current_url, "constrained", &is_constrained); | 169 net::GetValueForKeyInQuery(current_url, "constrained", &is_constrained); |
174 if (!is_constrained.empty()) | 170 if (!is_constrained.empty()) |
175 params.SetString("constrained", is_constrained); | 171 params.SetString("constrained", is_constrained); |
176 | 172 |
177 net::GetValueForKeyInQuery(current_url, "partitionId", &partition_id_); | 173 net::GetValueForKeyInQuery(current_url, "partitionId", &partition_id_); |
178 if (partition_id_.empty()) { | 174 if (partition_id_.empty()) { |
179 partition_id_ = | 175 partition_id_ = |
180 "gaia-webview-" + base::IntToString(next_partition_id.GetNext()); | 176 "gaia-webview-" + base::IntToString(next_partition_id.GetNext()); |
181 } | |
182 params.SetString("partitionId", partition_id_); | |
183 } | 177 } |
| 178 params.SetString("partitionId", partition_id_); |
184 #endif // OS_CHROMEOS | 179 #endif // OS_CHROMEOS |
185 | 180 |
186 web_ui()->CallJavascriptFunction("inline.login.loadAuthExtension", params); | 181 web_ui()->CallJavascriptFunction("inline.login.loadAuthExtension", params); |
187 } | 182 } |
188 | 183 |
189 // JS callback: | 184 // JS callback: |
190 void HandleInitialize(const base::ListValue* args) { | 185 void HandleInitialize(const base::ListValue* args) { |
191 LoadAuthExtension(); | 186 LoadAuthExtension(); |
192 } | 187 } |
193 | 188 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 sync_service && sync_service->HasSyncSetupCompleted()) ? | 287 sync_service && sync_service->HasSyncSetupCompleted()) ? |
293 OneClickSigninSyncStarter::SHOW_SETTINGS_WITHOUT_CONFIGURE : | 288 OneClickSigninSyncStarter::SHOW_SETTINGS_WITHOUT_CONFIGURE : |
294 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST : | 289 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST : |
295 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS; | 290 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS; |
296 OneClickSigninSyncStarter::ConfirmationRequired confirmation_required = | 291 OneClickSigninSyncStarter::ConfirmationRequired confirmation_required = |
297 source == signin::SOURCE_SETTINGS || | 292 source == signin::SOURCE_SETTINGS || |
298 source == signin::SOURCE_WEBSTORE_INSTALL || | 293 source == signin::SOURCE_WEBSTORE_INSTALL || |
299 choose_what_to_sync_? | 294 choose_what_to_sync_? |
300 OneClickSigninSyncStarter::NO_CONFIRMATION : | 295 OneClickSigninSyncStarter::NO_CONFIRMATION : |
301 OneClickSigninSyncStarter::CONFIRM_AFTER_SIGNIN; | 296 OneClickSigninSyncStarter::CONFIRM_AFTER_SIGNIN; |
302 // Call OneClickSigninSyncStarter to exchange oauth code for tokens. | 297 OneClickSigninSyncStarter::Callback sync_callback = base::Bind( |
303 // OneClickSigninSyncStarter will delete itself once the job is done. | 298 &InlineLoginUIHandler::SyncStarterCallback, |
304 new OneClickSigninSyncStarter( | 299 weak_factory_.GetWeakPtr()); |
305 profile_, NULL, "" /* session_index, not used */, | 300 |
306 email_, password_, oauth_code, | 301 bool cross_account_error_handled = |
307 start_mode, | 302 OneClickSigninHelper::HandleCrossAccountError( |
308 contents, | 303 contents, "" /* session_index, not used */, |
309 confirmation_required, | 304 email_, password_, oauth_code, |
310 base::Bind(&InlineLoginUIHandler::SyncStarterCallback, | 305 OneClickSigninHelper::AUTO_ACCEPT_EXPLICIT, |
311 weak_factory_.GetWeakPtr())); | 306 source, start_mode, sync_callback); |
| 307 |
| 308 if (!cross_account_error_handled) { |
| 309 // Call OneClickSigninSyncStarter to exchange oauth code for tokens. |
| 310 // OneClickSigninSyncStarter will delete itself once the job is done. |
| 311 new OneClickSigninSyncStarter( |
| 312 profile_, NULL, "" /* session_index, not used */, |
| 313 email_, password_, oauth_code, |
| 314 start_mode, |
| 315 contents, |
| 316 confirmation_required, |
| 317 sync_callback); |
| 318 } |
312 } | 319 } |
313 | 320 |
314 email_.clear(); | 321 email_.clear(); |
315 password_.clear(); | 322 password_.clear(); |
316 web_ui()->CallJavascriptFunction("inline.login.closeDialog"); | 323 web_ui()->CallJavascriptFunction("inline.login.closeDialog"); |
317 #endif // OS_CHROMEOS | 324 #endif // OS_CHROMEOS |
318 } | 325 } |
319 | 326 |
320 // GaiaAuthConsumer override. | 327 // GaiaAuthConsumer override. |
321 virtual void OnClientOAuthCodeFailure(const GoogleServiceAuthError& error) | 328 virtual void OnClientOAuthCodeFailure(const GoogleServiceAuthError& error) |
(...skipping 17 matching lines...) Expand all Loading... |
339 if (browser) | 346 if (browser) |
340 OneClickSigninHelper::ShowSigninErrorBubble(browser, error_msg); | 347 OneClickSigninHelper::ShowSigninErrorBubble(browser, error_msg); |
341 | 348 |
342 email_.clear(); | 349 email_.clear(); |
343 password_.clear(); | 350 password_.clear(); |
344 } | 351 } |
345 | 352 |
346 void SyncStarterCallback(OneClickSigninSyncStarter::SyncSetupResult result) { | 353 void SyncStarterCallback(OneClickSigninSyncStarter::SyncSetupResult result) { |
347 content::WebContents* contents = web_ui()->GetWebContents(); | 354 content::WebContents* contents = web_ui()->GetWebContents(); |
348 const GURL& current_url = contents->GetURL(); | 355 const GURL& current_url = contents->GetURL(); |
349 bool auto_close = signin::IsAutoCloseEnabledInURL(current_url); | 356 |
350 signin::Source source = signin::GetSourceForPromoURL(current_url); | 357 if (signin::IsAutoCloseEnabledInURL(current_url)) { |
351 if (auto_close) { | |
352 base::MessageLoop::current()->PostTask( | 358 base::MessageLoop::current()->PostTask( |
353 FROM_HERE, | 359 FROM_HERE, |
354 base::Bind( | 360 base::Bind( |
355 &InlineLoginUIHandler::CloseTab, weak_factory_.GetWeakPtr())); | 361 &InlineLoginUIHandler::CloseTab, weak_factory_.GetWeakPtr())); |
356 return; | 362 } else { |
| 363 signin::Source source = signin::GetSourceForPromoURL(current_url); |
| 364 DCHECK(source != signin::SOURCE_UNKNOWN); |
| 365 OneClickSigninHelper::RedirectToNtpOrAppsPageIfNecessary( |
| 366 contents, source); |
357 } | 367 } |
358 | |
359 OneClickSigninHelper::RedirectToNtpOrAppsPageIfNecessary(contents, source); | |
360 } | 368 } |
361 | 369 |
362 void CloseTab() { | 370 void CloseTab() { |
363 content::WebContents* tab = web_ui()->GetWebContents(); | 371 content::WebContents* tab = web_ui()->GetWebContents(); |
364 Browser* browser = chrome::FindBrowserWithWebContents(tab); | 372 Browser* browser = chrome::FindBrowserWithWebContents(tab); |
365 if (browser) { | 373 if (browser) { |
366 TabStripModel* tab_strip_model = browser->tab_strip_model(); | 374 TabStripModel* tab_strip_model = browser->tab_strip_model(); |
367 if (tab_strip_model) { | 375 if (tab_strip_model) { |
368 int index = tab_strip_model->GetIndexOfWebContents(tab); | 376 int index = tab_strip_model->GetIndexOfWebContents(tab); |
369 if (index != TabStripModel::kNoTab) { | 377 if (index != TabStripModel::kNoTab) { |
(...skipping 30 matching lines...) Expand all Loading... |
400 content::WebUIDataSource::Add(profile, CreateWebUIDataSource()); | 408 content::WebUIDataSource::Add(profile, CreateWebUIDataSource()); |
401 | 409 |
402 web_ui->AddMessageHandler(new InlineLoginUIHandler(profile)); | 410 web_ui->AddMessageHandler(new InlineLoginUIHandler(profile)); |
403 // Required for intercepting extension function calls when the page is loaded | 411 // Required for intercepting extension function calls when the page is loaded |
404 // in a bubble (not a full tab, thus tab helpers are not registered | 412 // in a bubble (not a full tab, thus tab helpers are not registered |
405 // automatically). | 413 // automatically). |
406 extensions::TabHelper::CreateForWebContents(web_ui->GetWebContents()); | 414 extensions::TabHelper::CreateForWebContents(web_ui->GetWebContents()); |
407 } | 415 } |
408 | 416 |
409 InlineLoginUI::~InlineLoginUI() {} | 417 InlineLoginUI::~InlineLoginUI() {} |
OLD | NEW |