Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(711)

Side by Side Diff: chrome/browser/ui/sync/one_click_signin_sync_starter.cc

Issue 196783002: Export a private webstore API to call into the new inline sign-in flow. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Redirect to the continue URL when Sync is disabled Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 12 matching lines...) Expand all
23 #include "chrome/browser/sync/profile_sync_service.h" 23 #include "chrome/browser/sync/profile_sync_service.h"
24 #include "chrome/browser/sync/profile_sync_service_factory.h" 24 #include "chrome/browser/sync/profile_sync_service_factory.h"
25 #include "chrome/browser/ui/browser.h" 25 #include "chrome/browser/ui/browser.h"
26 #include "chrome/browser/ui/browser_dialogs.h" 26 #include "chrome/browser/ui/browser_dialogs.h"
27 #include "chrome/browser/ui/browser_finder.h" 27 #include "chrome/browser/ui/browser_finder.h"
28 #include "chrome/browser/ui/browser_list.h" 28 #include "chrome/browser/ui/browser_list.h"
29 #include "chrome/browser/ui/browser_navigator.h" 29 #include "chrome/browser/ui/browser_navigator.h"
30 #include "chrome/browser/ui/browser_tabstrip.h" 30 #include "chrome/browser/ui/browser_tabstrip.h"
31 #include "chrome/browser/ui/browser_window.h" 31 #include "chrome/browser/ui/browser_window.h"
32 #include "chrome/browser/ui/chrome_pages.h" 32 #include "chrome/browser/ui/chrome_pages.h"
33 #include "chrome/browser/ui/sync/one_click_signin_sync_observer.h"
33 #include "chrome/browser/ui/tabs/tab_strip_model.h" 34 #include "chrome/browser/ui/tabs/tab_strip_model.h"
34 #include "chrome/browser/ui/webui/signin/login_ui_service.h" 35 #include "chrome/browser/ui/webui/signin/login_ui_service.h"
35 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" 36 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
36 #include "chrome/browser/ui/webui/signin/profile_signin_confirmation_dialog.h" 37 #include "chrome/browser/ui/webui/signin/profile_signin_confirmation_dialog.h"
37 #include "chrome/common/profile_management_switches.h" 38 #include "chrome/common/profile_management_switches.h"
38 #include "chrome/common/url_constants.h" 39 #include "chrome/common/url_constants.h"
39 #include "components/sync_driver/sync_prefs.h" 40 #include "components/sync_driver/sync_prefs.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
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 LoadContinueUrl();
414 }
415
404 delete this; 416 delete this;
405 } 417 }
406 418
407 void OneClickSigninSyncStarter::DisplayFinalConfirmationBubble( 419 void OneClickSigninSyncStarter::DisplayFinalConfirmationBubble(
408 const base::string16& custom_message) { 420 const base::string16& custom_message) {
409 browser_ = EnsureBrowser(browser_, profile_, desktop_type_); 421 browser_ = EnsureBrowser(browser_, profile_, desktop_type_);
410 browser_->window()->ShowOneClickSigninBubble( 422 browser_->window()->ShowOneClickSigninBubble(
411 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE, 423 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE,
412 base::string16(), // No email required - this is not a SAML confirmation. 424 base::string16(), // No email required - this is not a SAML confirmation.
413 custom_message, 425 custom_message,
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 // advanced sync settings. However, in the case of re-authentication, 486 // advanced sync settings. However, in the case of re-authentication,
475 // return the user to the settings page without showing any config UI. 487 // return the user to the settings page without showing any config UI.
476 if (configure_sync) { 488 if (configure_sync) {
477 chrome::ShowSettingsSubPage(browser_, chrome::kSyncSetupSubPage); 489 chrome::ShowSettingsSubPage(browser_, chrome::kSyncSetupSubPage);
478 } else { 490 } else {
479 FinishProfileSyncServiceSetup(); 491 FinishProfileSyncServiceSetup();
480 chrome::ShowSettings(browser_); 492 chrome::ShowSettings(browser_);
481 } 493 }
482 } 494 }
483 } else { 495 } else {
484 // Sync is disabled - just display the settings page. 496 // Sync is disabled - just display the settings page or redirect to the
497 // |continue_url_|.
485 FinishProfileSyncServiceSetup(); 498 FinishProfileSyncServiceSetup();
486 if (use_same_tab) 499 if (!use_same_tab)
500 chrome::ShowSettings(browser_);
501 else if (!continue_url_.is_empty())
502 LoadContinueUrl();
503 else
487 ShowSettingsPageInWebContents(web_contents(), std::string()); 504 ShowSettingsPageInWebContents(web_contents(), std::string());
488 else
489 chrome::ShowSettings(browser_);
490 } 505 }
491 } 506 }
492 } 507 }
493 508
494 ProfileSyncService* OneClickSigninSyncStarter::GetProfileSyncService() { 509 ProfileSyncService* OneClickSigninSyncStarter::GetProfileSyncService() {
495 ProfileSyncService* service = NULL; 510 ProfileSyncService* service = NULL;
496 if (profile_->IsSyncAccessible()) 511 if (profile_->IsSyncAccessible())
497 service = ProfileSyncServiceFactory::GetForProfile(profile_); 512 service = ProfileSyncServiceFactory::GetForProfile(profile_);
498 return service; 513 return service;
499 } 514 }
500 515
501 void OneClickSigninSyncStarter::FinishProfileSyncServiceSetup() { 516 void OneClickSigninSyncStarter::FinishProfileSyncServiceSetup() {
502 ProfileSyncService* service = 517 ProfileSyncService* service =
503 ProfileSyncServiceFactory::GetForProfile(profile_); 518 ProfileSyncServiceFactory::GetForProfile(profile_);
504 if (service) 519 if (service)
505 service->SetSetupInProgress(false); 520 service->SetSetupInProgress(false);
506 } 521 }
507 522
508 void OneClickSigninSyncStarter::ShowSettingsPageInWebContents( 523 void OneClickSigninSyncStarter::ShowSettingsPageInWebContents(
509 content::WebContents* contents, 524 content::WebContents* contents,
510 const std::string& sub_page) { 525 const std::string& sub_page) {
526 if (!continue_url_.is_empty()) {
527 // This case should only be reachable when configuring Sync.
528 // The observer deletes itself once it's done.
529 DCHECK_EQ(sub_page, chrome::kSyncSetupSubPage);
530 new OneClickSigninSyncObserver(contents, continue_url_);
531 }
532
511 GURL url = chrome::GetSettingsUrl(sub_page); 533 GURL url = chrome::GetSettingsUrl(sub_page);
512 content::OpenURLParams params(url, 534 content::OpenURLParams params(url,
513 content::Referrer(), 535 content::Referrer(),
514 CURRENT_TAB, 536 CURRENT_TAB,
515 content::PAGE_TRANSITION_AUTO_TOPLEVEL, 537 content::PAGE_TRANSITION_AUTO_TOPLEVEL,
516 false); 538 false);
517 contents->OpenURL(params); 539 contents->OpenURL(params);
518 540
519 // Activate the tab. 541 // Activate the tab.
520 Browser* browser = chrome::FindBrowserWithWebContents(contents); 542 Browser* browser = chrome::FindBrowserWithWebContents(contents);
521 int content_index = 543 int content_index =
522 browser->tab_strip_model()->GetIndexOfWebContents(contents); 544 browser->tab_strip_model()->GetIndexOfWebContents(contents);
523 browser->tab_strip_model()->ActivateTabAt(content_index, 545 browser->tab_strip_model()->ActivateTabAt(content_index,
524 false /* user_gesture */); 546 false /* user_gesture */);
525 } 547 }
548
549 void OneClickSigninSyncObserver::LoadContinueUrl() {
550 web_contents()->GetController().LoadURL(
551 continue_url_,
552 content::Referrer(),
553 content::PAGE_TRANSITION_AUTO_TOPLEVEL,
554 std::string());
555 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698