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 13 matching lines...) Expand all Loading... |
24 #include "chrome/browser/sync/profile_sync_service.h" | 24 #include "chrome/browser/sync/profile_sync_service.h" |
25 #include "chrome/browser/sync/profile_sync_service_factory.h" | 25 #include "chrome/browser/sync/profile_sync_service_factory.h" |
26 #include "chrome/browser/ui/browser.h" | 26 #include "chrome/browser/ui/browser.h" |
27 #include "chrome/browser/ui/browser_dialogs.h" | 27 #include "chrome/browser/ui/browser_dialogs.h" |
28 #include "chrome/browser/ui/browser_finder.h" | 28 #include "chrome/browser/ui/browser_finder.h" |
29 #include "chrome/browser/ui/browser_list.h" | 29 #include "chrome/browser/ui/browser_list.h" |
30 #include "chrome/browser/ui/browser_navigator.h" | 30 #include "chrome/browser/ui/browser_navigator.h" |
31 #include "chrome/browser/ui/browser_tabstrip.h" | 31 #include "chrome/browser/ui/browser_tabstrip.h" |
32 #include "chrome/browser/ui/browser_window.h" | 32 #include "chrome/browser/ui/browser_window.h" |
33 #include "chrome/browser/ui/chrome_pages.h" | 33 #include "chrome/browser/ui/chrome_pages.h" |
| 34 #include "chrome/browser/ui/sync/one_click_signin_sync_observer.h" |
34 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 35 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
35 #include "chrome/browser/ui/webui/signin/login_ui_service.h" | 36 #include "chrome/browser/ui/webui/signin/login_ui_service.h" |
36 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 37 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
37 #include "chrome/browser/ui/webui/signin/profile_signin_confirmation_dialog.h" | 38 #include "chrome/browser/ui/webui/signin/profile_signin_confirmation_dialog.h" |
38 #include "chrome/common/url_constants.h" | 39 #include "chrome/common/url_constants.h" |
39 #include "components/signin/core/browser/signin_manager.h" | 40 #include "components/signin/core/browser/signin_manager.h" |
40 #include "components/signin/core/common/profile_management_switches.h" | 41 #include "components/signin/core/common/profile_management_switches.h" |
41 #include "components/sync_driver/sync_prefs.h" | 42 #include "components/sync_driver/sync_prefs.h" |
42 #include "grit/chromium_strings.h" | 43 #include "grit/chromium_strings.h" |
43 #include "grit/generated_resources.h" | 44 #include "grit/generated_resources.h" |
44 #include "ui/base/l10n/l10n_util.h" | 45 #include "ui/base/l10n/l10n_util.h" |
45 #include "ui/base/resource/resource_bundle.h" | 46 #include "ui/base/resource/resource_bundle.h" |
46 | 47 |
47 OneClickSigninSyncStarter::OneClickSigninSyncStarter( | 48 OneClickSigninSyncStarter::OneClickSigninSyncStarter( |
48 Profile* profile, | 49 Profile* profile, |
49 Browser* browser, | 50 Browser* browser, |
50 const std::string& email, | 51 const std::string& email, |
51 const std::string& password, | 52 const std::string& password, |
52 const std::string& refresh_token, | 53 const std::string& refresh_token, |
53 StartSyncMode start_mode, | 54 StartSyncMode start_mode, |
54 content::WebContents* web_contents, | 55 content::WebContents* web_contents, |
55 ConfirmationRequired confirmation_required, | 56 ConfirmationRequired confirmation_required, |
| 57 const GURL& continue_url, |
56 Callback sync_setup_completed_callback) | 58 Callback sync_setup_completed_callback) |
57 : content::WebContentsObserver(web_contents), | 59 : content::WebContentsObserver(web_contents), |
58 start_mode_(start_mode), | 60 start_mode_(start_mode), |
59 desktop_type_(chrome::HOST_DESKTOP_TYPE_NATIVE), | 61 desktop_type_(chrome::HOST_DESKTOP_TYPE_NATIVE), |
60 confirmation_required_(confirmation_required), | 62 confirmation_required_(confirmation_required), |
| 63 continue_url_(continue_url), |
61 sync_setup_completed_callback_(sync_setup_completed_callback), | 64 sync_setup_completed_callback_(sync_setup_completed_callback), |
62 weak_pointer_factory_(this) { | 65 weak_pointer_factory_(this) { |
63 DCHECK(profile); | 66 DCHECK(profile); |
| 67 DCHECK(web_contents || continue_url.is_empty()); |
64 BrowserList::AddObserver(this); | 68 BrowserList::AddObserver(this); |
65 | 69 |
66 Initialize(profile, browser); | 70 Initialize(profile, browser); |
67 | 71 |
68 // Policy is enabled, so pass in a callback to do extra policy-related UI | 72 // Policy is enabled, so pass in a callback to do extra policy-related UI |
69 // before signin completes. | 73 // before signin completes. |
70 SigninManagerFactory::GetForProfile(profile_)-> | 74 SigninManagerFactory::GetForProfile(profile_)-> |
71 StartSignInWithRefreshToken( | 75 StartSignInWithRefreshToken( |
72 refresh_token, email, password, | 76 refresh_token, email, password, |
73 base::Bind(&OneClickSigninSyncStarter::ConfirmSignin, | 77 base::Bind(&OneClickSigninSyncStarter::ConfirmSignin, |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 DisplayFinalConfirmationBubble(message); | 397 DisplayFinalConfirmationBubble(message); |
394 } | 398 } |
395 break; | 399 break; |
396 } | 400 } |
397 case CONFIGURE_SYNC_FIRST: | 401 case CONFIGURE_SYNC_FIRST: |
398 ShowSettingsPage(true); // Show sync config UI. | 402 ShowSettingsPage(true); // Show sync config UI. |
399 break; | 403 break; |
400 case SHOW_SETTINGS_WITHOUT_CONFIGURE: | 404 case SHOW_SETTINGS_WITHOUT_CONFIGURE: |
401 ShowSettingsPage(false); // Don't show sync config UI. | 405 ShowSettingsPage(false); // Don't show sync config UI. |
402 break; | 406 break; |
403 default: | 407 case UNDO_SYNC: |
404 NOTREACHED(); | 408 NOTREACHED(); |
405 } | 409 } |
| 410 |
| 411 // Navigate to the |continue_url_| if one is set, unless the user first needs |
| 412 // to configure Sync. |
| 413 if (web_contents() && !continue_url_.is_empty() && |
| 414 start_mode_ != CONFIGURE_SYNC_FIRST) { |
| 415 LoadContinueUrl(); |
| 416 } |
| 417 |
406 delete this; | 418 delete this; |
407 } | 419 } |
408 | 420 |
409 void OneClickSigninSyncStarter::DisplayFinalConfirmationBubble( | 421 void OneClickSigninSyncStarter::DisplayFinalConfirmationBubble( |
410 const base::string16& custom_message) { | 422 const base::string16& custom_message) { |
411 browser_ = EnsureBrowser(browser_, profile_, desktop_type_); | 423 browser_ = EnsureBrowser(browser_, profile_, desktop_type_); |
412 browser_->window()->ShowOneClickSigninBubble( | 424 browser_->window()->ShowOneClickSigninBubble( |
413 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE, | 425 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE, |
414 base::string16(), // No email required - this is not a SAML confirmation. | 426 base::string16(), // No email required - this is not a SAML confirmation. |
415 custom_message, | 427 custom_message, |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 // advanced sync settings. However, in the case of re-authentication, | 488 // advanced sync settings. However, in the case of re-authentication, |
477 // return the user to the settings page without showing any config UI. | 489 // return the user to the settings page without showing any config UI. |
478 if (configure_sync) { | 490 if (configure_sync) { |
479 chrome::ShowSettingsSubPage(browser_, chrome::kSyncSetupSubPage); | 491 chrome::ShowSettingsSubPage(browser_, chrome::kSyncSetupSubPage); |
480 } else { | 492 } else { |
481 FinishProfileSyncServiceSetup(); | 493 FinishProfileSyncServiceSetup(); |
482 chrome::ShowSettings(browser_); | 494 chrome::ShowSettings(browser_); |
483 } | 495 } |
484 } | 496 } |
485 } else { | 497 } else { |
486 // Sync is disabled - just display the settings page. | 498 // Sync is disabled - just display the settings page or redirect to the |
| 499 // |continue_url_|. |
487 FinishProfileSyncServiceSetup(); | 500 FinishProfileSyncServiceSetup(); |
488 if (use_same_tab) | 501 if (!use_same_tab) |
| 502 chrome::ShowSettings(browser_); |
| 503 else if (!continue_url_.is_empty()) |
| 504 LoadContinueUrl(); |
| 505 else |
489 ShowSettingsPageInWebContents(web_contents(), std::string()); | 506 ShowSettingsPageInWebContents(web_contents(), std::string()); |
490 else | |
491 chrome::ShowSettings(browser_); | |
492 } | 507 } |
493 } | 508 } |
494 } | 509 } |
495 | 510 |
496 ProfileSyncService* OneClickSigninSyncStarter::GetProfileSyncService() { | 511 ProfileSyncService* OneClickSigninSyncStarter::GetProfileSyncService() { |
497 ProfileSyncService* service = NULL; | 512 ProfileSyncService* service = NULL; |
498 if (profile_->IsSyncAccessible()) | 513 if (profile_->IsSyncAccessible()) |
499 service = ProfileSyncServiceFactory::GetForProfile(profile_); | 514 service = ProfileSyncServiceFactory::GetForProfile(profile_); |
500 return service; | 515 return service; |
501 } | 516 } |
502 | 517 |
503 void OneClickSigninSyncStarter::FinishProfileSyncServiceSetup() { | 518 void OneClickSigninSyncStarter::FinishProfileSyncServiceSetup() { |
504 ProfileSyncService* service = | 519 ProfileSyncService* service = |
505 ProfileSyncServiceFactory::GetForProfile(profile_); | 520 ProfileSyncServiceFactory::GetForProfile(profile_); |
506 if (service) | 521 if (service) |
507 service->SetSetupInProgress(false); | 522 service->SetSetupInProgress(false); |
508 } | 523 } |
509 | 524 |
510 void OneClickSigninSyncStarter::ShowSettingsPageInWebContents( | 525 void OneClickSigninSyncStarter::ShowSettingsPageInWebContents( |
511 content::WebContents* contents, | 526 content::WebContents* contents, |
512 const std::string& sub_page) { | 527 const std::string& sub_page) { |
| 528 if (!continue_url_.is_empty()) { |
| 529 // The observer deletes itself once it's done. |
| 530 DCHECK(!sub_page.empty()); |
| 531 new OneClickSigninSyncObserver(contents, continue_url_); |
| 532 } |
| 533 |
513 GURL url = chrome::GetSettingsUrl(sub_page); | 534 GURL url = chrome::GetSettingsUrl(sub_page); |
514 content::OpenURLParams params(url, | 535 content::OpenURLParams params(url, |
515 content::Referrer(), | 536 content::Referrer(), |
516 CURRENT_TAB, | 537 CURRENT_TAB, |
517 content::PAGE_TRANSITION_AUTO_TOPLEVEL, | 538 content::PAGE_TRANSITION_AUTO_TOPLEVEL, |
518 false); | 539 false); |
519 contents->OpenURL(params); | 540 contents->OpenURL(params); |
520 | 541 |
521 // Activate the tab. | 542 // Activate the tab. |
522 Browser* browser = chrome::FindBrowserWithWebContents(contents); | 543 Browser* browser = chrome::FindBrowserWithWebContents(contents); |
523 int content_index = | 544 int content_index = |
524 browser->tab_strip_model()->GetIndexOfWebContents(contents); | 545 browser->tab_strip_model()->GetIndexOfWebContents(contents); |
525 browser->tab_strip_model()->ActivateTabAt(content_index, | 546 browser->tab_strip_model()->ActivateTabAt(content_index, |
526 false /* user_gesture */); | 547 false /* user_gesture */); |
527 } | 548 } |
| 549 |
| 550 void OneClickSigninSyncStarter::LoadContinueUrl() { |
| 551 web_contents()->GetController().LoadURL( |
| 552 continue_url_, |
| 553 content::Referrer(), |
| 554 content::PAGE_TRANSITION_AUTO_TOPLEVEL, |
| 555 std::string()); |
| 556 } |
OLD | NEW |