Chromium Code Reviews| 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_factory.h" | 24 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 25 #include "chrome/browser/sync/sync_prefs.h" | 25 #include "chrome/browser/sync/sync_prefs.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/profile_management_switches.h" | 39 #include "chrome/common/profile_management_switches.h" |
| 39 #include "chrome/common/url_constants.h" | 40 #include "chrome/common/url_constants.h" |
| 40 #include "grit/chromium_strings.h" | 41 #include "grit/chromium_strings.h" |
| 41 #include "grit/generated_resources.h" | 42 #include "grit/generated_resources.h" |
| 42 #include "ui/base/l10n/l10n_util.h" | 43 #include "ui/base/l10n/l10n_util.h" |
| 43 #include "ui/base/resource/resource_bundle.h" | 44 #include "ui/base/resource/resource_bundle.h" |
| 44 | 45 |
| 45 OneClickSigninSyncStarter::OneClickSigninSyncStarter( | 46 OneClickSigninSyncStarter::OneClickSigninSyncStarter( |
| 46 Profile* profile, | 47 Profile* profile, |
| 47 Browser* browser, | 48 Browser* browser, |
| 48 const std::string& email, | 49 const std::string& email, |
| 49 const std::string& password, | 50 const std::string& password, |
| 50 const std::string& refresh_token, | 51 const std::string& refresh_token, |
| 51 StartSyncMode start_mode, | 52 StartSyncMode start_mode, |
| 52 content::WebContents* web_contents, | 53 content::WebContents* web_contents, |
| 53 ConfirmationRequired confirmation_required, | 54 ConfirmationRequired confirmation_required, |
| 55 const GURL& continue_url, | |
| 54 Callback sync_setup_completed_callback) | 56 Callback sync_setup_completed_callback) |
| 55 : content::WebContentsObserver(web_contents), | 57 : content::WebContentsObserver(web_contents), |
| 56 start_mode_(start_mode), | 58 start_mode_(start_mode), |
| 57 desktop_type_(chrome::HOST_DESKTOP_TYPE_NATIVE), | 59 desktop_type_(chrome::HOST_DESKTOP_TYPE_NATIVE), |
| 58 confirmation_required_(confirmation_required), | 60 confirmation_required_(confirmation_required), |
| 61 continue_url_(continue_url), | |
| 59 sync_setup_completed_callback_(sync_setup_completed_callback), | 62 sync_setup_completed_callback_(sync_setup_completed_callback), |
| 60 weak_pointer_factory_(this) { | 63 weak_pointer_factory_(this) { |
| 61 DCHECK(profile); | 64 DCHECK(profile); |
| 65 DCHECK(web_contents || continue_url.is_empty()); | |
| 62 BrowserList::AddObserver(this); | 66 BrowserList::AddObserver(this); |
| 63 | 67 |
| 64 Initialize(profile, browser); | 68 Initialize(profile, browser); |
| 65 | 69 |
| 66 // Policy is enabled, so pass in a callback to do extra policy-related UI | 70 // Policy is enabled, so pass in a callback to do extra policy-related UI |
| 67 // before signin completes. | 71 // before signin completes. |
| 68 SigninManagerFactory::GetForProfile(profile_)-> | 72 SigninManagerFactory::GetForProfile(profile_)-> |
| 69 StartSignInWithRefreshToken( | 73 StartSignInWithRefreshToken( |
| 70 refresh_token, email, password, | 74 refresh_token, email, password, |
| 71 base::Bind(&OneClickSigninSyncStarter::ConfirmSignin, | 75 base::Bind(&OneClickSigninSyncStarter::ConfirmSignin, |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 391 DisplayFinalConfirmationBubble(message); | 395 DisplayFinalConfirmationBubble(message); |
| 392 } | 396 } |
| 393 break; | 397 break; |
| 394 } | 398 } |
| 395 case CONFIGURE_SYNC_FIRST: | 399 case CONFIGURE_SYNC_FIRST: |
| 396 ShowSettingsPage(true); // Show sync config UI. | 400 ShowSettingsPage(true); // Show sync config UI. |
| 397 break; | 401 break; |
| 398 case SHOW_SETTINGS_WITHOUT_CONFIGURE: | 402 case SHOW_SETTINGS_WITHOUT_CONFIGURE: |
| 399 ShowSettingsPage(false); // Don't show sync config UI. | 403 ShowSettingsPage(false); // Don't show sync config UI. |
| 400 break; | 404 break; |
| 401 default: | 405 case UNDO_SYNC: |
| 402 NOTREACHED(); | 406 NOTREACHED(); |
| 403 } | 407 } |
| 408 | |
| 409 // Navigate to the |continue_url_| if one is set, unless the user first needs | |
| 410 // to configure Sync. | |
| 411 if (web_contents() && !continue_url_.is_empty() && | |
| 412 start_mode_ != CONFIGURE_SYNC_FIRST) { | |
| 413 web_contents()->GetController().LoadURL( | |
| 414 continue_url_, | |
| 415 content::Referrer(), | |
| 416 content::PAGE_TRANSITION_AUTO_TOPLEVEL, | |
| 417 std::string()); | |
| 418 } | |
| 419 | |
| 404 delete this; | 420 delete this; |
| 405 } | 421 } |
| 406 | 422 |
| 407 void OneClickSigninSyncStarter::DisplayFinalConfirmationBubble( | 423 void OneClickSigninSyncStarter::DisplayFinalConfirmationBubble( |
| 408 const base::string16& custom_message) { | 424 const base::string16& custom_message) { |
| 409 browser_ = EnsureBrowser(browser_, profile_, desktop_type_); | 425 browser_ = EnsureBrowser(browser_, profile_, desktop_type_); |
| 410 browser_->window()->ShowOneClickSigninBubble( | 426 browser_->window()->ShowOneClickSigninBubble( |
| 411 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE, | 427 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE, |
| 412 base::string16(), // No email required - this is not a SAML confirmation. | 428 base::string16(), // No email required - this is not a SAML confirmation. |
| 413 custom_message, | 429 custom_message, |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 501 void OneClickSigninSyncStarter::FinishProfileSyncServiceSetup() { | 517 void OneClickSigninSyncStarter::FinishProfileSyncServiceSetup() { |
| 502 ProfileSyncService* service = | 518 ProfileSyncService* service = |
| 503 ProfileSyncServiceFactory::GetForProfile(profile_); | 519 ProfileSyncServiceFactory::GetForProfile(profile_); |
| 504 if (service) | 520 if (service) |
| 505 service->SetSetupInProgress(false); | 521 service->SetSetupInProgress(false); |
| 506 } | 522 } |
| 507 | 523 |
| 508 void OneClickSigninSyncStarter::ShowSettingsPageInWebContents( | 524 void OneClickSigninSyncStarter::ShowSettingsPageInWebContents( |
| 509 content::WebContents* contents, | 525 content::WebContents* contents, |
| 510 const std::string& sub_page) { | 526 const std::string& sub_page) { |
| 527 if (!continue_url_.is_empty()) { | |
| 528 // The observer deletes itself once it's done. | |
| 529 // TODO(isherman): Perhaps only do this when the |sub_page| is the | |
| 530 // configuration page? | |
|
Ilya Sherman
2014/03/20 08:41:45
^^^
guohui
2014/03/21 19:04:15
|sub_page| is not configuration page only if sync
Ilya Sherman
2014/03/22 00:06:28
Done.
| |
| 531 new OneClickSigninSyncObserver(contents, continue_url_); | |
| 532 } | |
| 533 | |
| 511 std::string url = std::string(chrome::kChromeUISettingsURL) + sub_page; | 534 std::string url = std::string(chrome::kChromeUISettingsURL) + sub_page; |
| 512 content::OpenURLParams params(GURL(url), | 535 content::OpenURLParams params(GURL(url), |
| 513 content::Referrer(), | 536 content::Referrer(), |
| 514 CURRENT_TAB, | 537 CURRENT_TAB, |
| 515 content::PAGE_TRANSITION_AUTO_TOPLEVEL, | 538 content::PAGE_TRANSITION_AUTO_TOPLEVEL, |
| 516 false); | 539 false); |
| 517 contents->OpenURL(params); | 540 contents->OpenURL(params); |
| 518 | 541 |
| 519 // Activate the tab. | 542 // Activate the tab. |
| 520 Browser* browser = chrome::FindBrowserWithWebContents(contents); | 543 Browser* browser = chrome::FindBrowserWithWebContents(contents); |
| 521 int content_index = | 544 int content_index = |
| 522 browser->tab_strip_model()->GetIndexOfWebContents(contents); | 545 browser->tab_strip_model()->GetIndexOfWebContents(contents); |
| 523 browser->tab_strip_model()->ActivateTabAt(content_index, | 546 browser->tab_strip_model()->ActivateTabAt(content_index, |
| 524 false /* user_gesture */); | 547 false /* user_gesture */); |
| 525 } | 548 } |
| OLD | NEW |