OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/sync/one_click_signin_sync_starter.h" | 5 #include "chrome/browser/ui/sync/one_click_signin_sync_starter.h" |
6 | 6 |
7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
10 | 10 |
(...skipping 30 matching lines...) Expand all Loading... |
41 #include "ui/base/l10n/l10n_util.h" | 41 #include "ui/base/l10n/l10n_util.h" |
42 #include "ui/base/resource/resource_bundle.h" | 42 #include "ui/base/resource/resource_bundle.h" |
43 | 43 |
44 OneClickSigninSyncStarter::OneClickSigninSyncStarter( | 44 OneClickSigninSyncStarter::OneClickSigninSyncStarter( |
45 Profile* profile, | 45 Profile* profile, |
46 Browser* browser, | 46 Browser* browser, |
47 const std::string& session_index, | 47 const std::string& session_index, |
48 const std::string& email, | 48 const std::string& email, |
49 const std::string& password, | 49 const std::string& password, |
50 StartSyncMode start_mode, | 50 StartSyncMode start_mode, |
51 bool force_same_tab_navigation, | 51 content::WebContents* web_contents, |
52 ConfirmationRequired confirmation_required, | 52 ConfirmationRequired confirmation_required, |
53 signin::Source source, | 53 signin::Source source, |
54 Callback sync_setup_completed_callback) | 54 Callback sync_setup_completed_callback) |
55 : start_mode_(start_mode), | 55 : content::WebContentsObserver(web_contents), |
56 force_same_tab_navigation_(force_same_tab_navigation), | 56 start_mode_(start_mode), |
57 confirmation_required_(confirmation_required), | 57 confirmation_required_(confirmation_required), |
58 source_(source), | 58 source_(source), |
59 sync_setup_completed_callback_(sync_setup_completed_callback), | 59 sync_setup_completed_callback_(sync_setup_completed_callback), |
60 weak_pointer_factory_(this) { | 60 weak_pointer_factory_(this) { |
61 DCHECK(profile); | 61 DCHECK(profile); |
62 BrowserList::AddObserver(this); | 62 BrowserList::AddObserver(this); |
63 | 63 |
64 Initialize(profile, browser); | 64 Initialize(profile, browser); |
65 | 65 |
66 // Start the signin process using the cookies in the cookie jar. | 66 // Start the signin process using the cookies in the cookie jar. |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 // to start up until after the configure UI is displayed (the configure UI | 417 // to start up until after the configure UI is displayed (the configure UI |
418 // will clear the flag when the user is done setting up sync). | 418 // will clear the flag when the user is done setting up sync). |
419 ProfileSyncService* profile_sync_service = GetProfileSyncService(); | 419 ProfileSyncService* profile_sync_service = GetProfileSyncService(); |
420 LoginUIService* login_ui = LoginUIServiceFactory::GetForProfile(profile_); | 420 LoginUIService* login_ui = LoginUIServiceFactory::GetForProfile(profile_); |
421 if (login_ui->current_login_ui()) { | 421 if (login_ui->current_login_ui()) { |
422 login_ui->current_login_ui()->FocusUI(); | 422 login_ui->current_login_ui()->FocusUI(); |
423 } else { | 423 } else { |
424 EnsureBrowser(); | 424 EnsureBrowser(); |
425 if (profile_sync_service) { | 425 if (profile_sync_service) { |
426 // Need to navigate to the settings page and display the sync UI. | 426 // Need to navigate to the settings page and display the sync UI. |
427 if (force_same_tab_navigation_) { | 427 if (web_contents()) { |
428 ShowSyncSettingsPageOnSameTab(); | 428 ShowSyncSettingsPageInWebContents(web_contents()); |
429 } else { | 429 } else { |
430 // If the user is setting up sync for the first time, let them configure | 430 // If the user is setting up sync for the first time, let them configure |
431 // advanced sync settings. However, in the case of re-authentication, | 431 // advanced sync settings. However, in the case of re-authentication, |
432 // return the user to the settings page without showing any config UI. | 432 // return the user to the settings page without showing any config UI. |
433 if (configure_sync) { | 433 if (configure_sync) { |
434 chrome::ShowSettingsSubPage(browser_, chrome::kSyncSetupSubPage); | 434 chrome::ShowSettingsSubPage(browser_, chrome::kSyncSetupSubPage); |
435 } else { | 435 } else { |
436 FinishProfileSyncServiceSetup(); | 436 FinishProfileSyncServiceSetup(); |
437 chrome::ShowSettings(browser_); | 437 chrome::ShowSettings(browser_); |
438 } | 438 } |
(...skipping 13 matching lines...) Expand all Loading... |
452 return service; | 452 return service; |
453 } | 453 } |
454 | 454 |
455 void OneClickSigninSyncStarter::FinishProfileSyncServiceSetup() { | 455 void OneClickSigninSyncStarter::FinishProfileSyncServiceSetup() { |
456 ProfileSyncService* service = | 456 ProfileSyncService* service = |
457 ProfileSyncServiceFactory::GetForProfile(profile_); | 457 ProfileSyncServiceFactory::GetForProfile(profile_); |
458 if (service) | 458 if (service) |
459 service->SetSetupInProgress(false); | 459 service->SetSetupInProgress(false); |
460 } | 460 } |
461 | 461 |
462 void OneClickSigninSyncStarter::ShowSyncSettingsPageOnSameTab() { | 462 void OneClickSigninSyncStarter::ShowSyncSettingsPageInWebContents( |
| 463 content::WebContents* contents) { |
463 std::string url = std::string(chrome::kChromeUISettingsURL) + | 464 std::string url = std::string(chrome::kChromeUISettingsURL) + |
464 chrome::kSyncSetupSubPage; | 465 chrome::kSyncSetupSubPage; |
465 chrome::NavigateParams params( | 466 content::OpenURLParams params(GURL(url), |
466 browser_, GURL(url), content::PAGE_TRANSITION_AUTO_TOPLEVEL); | 467 content::Referrer(), |
467 params.disposition = CURRENT_TAB; | 468 CURRENT_TAB, |
468 params.window_action = chrome::NavigateParams::SHOW_WINDOW; | 469 content::PAGE_TRANSITION_AUTO_TOPLEVEL, |
469 chrome::Navigate(¶ms); | 470 false); |
| 471 contents->OpenURL(params); |
| 472 |
| 473 // Activate the tab. |
| 474 Browser* browser = chrome::FindBrowserWithWebContents(contents); |
| 475 int content_index = |
| 476 browser->tab_strip_model()->GetIndexOfWebContents(contents); |
| 477 browser->tab_strip_model()->ActivateTabAt(content_index, |
| 478 false /* user_gesture */); |
470 } | 479 } |
OLD | NEW |