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_helper.h" | 5 #include "chrome/browser/ui/sync/one_click_signin_helper.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <functional> | 8 #include <functional> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/callback_forward.h" | 13 #include "base/callback_forward.h" |
14 #include "base/callback_helpers.h" | 14 #include "base/callback_helpers.h" |
15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
16 #include "base/metrics/field_trial.h" | 16 #include "base/metrics/field_trial.h" |
17 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
18 #include "base/prefs/pref_service.h" | 18 #include "base/prefs/pref_service.h" |
19 #include "base/strings/string_split.h" | 19 #include "base/strings/string_split.h" |
20 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
21 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
22 #include "base/supports_user_data.h" | 22 #include "base/supports_user_data.h" |
23 #include "base/values.h" | 23 #include "base/values.h" |
24 #include "chrome/browser/browser_process.h" | 24 #include "chrome/browser/browser_process.h" |
25 #include "chrome/browser/chrome_notification_types.h" | 25 #include "chrome/browser/chrome_notification_types.h" |
26 #include "chrome/browser/defaults.h" | 26 #include "chrome/browser/defaults.h" |
27 #include "chrome/browser/google/google_util.h" | 27 #include "chrome/browser/google/google_util.h" |
| 28 #include "chrome/browser/password_manager/password_manager.h" |
28 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 29 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
29 #include "chrome/browser/profiles/profile.h" | 30 #include "chrome/browser/profiles/profile.h" |
30 #include "chrome/browser/profiles/profile_info_cache.h" | 31 #include "chrome/browser/profiles/profile_info_cache.h" |
31 #include "chrome/browser/profiles/profile_io_data.h" | 32 #include "chrome/browser/profiles/profile_io_data.h" |
32 #include "chrome/browser/profiles/profile_manager.h" | 33 #include "chrome/browser/profiles/profile_manager.h" |
33 #include "chrome/browser/search/search.h" | 34 #include "chrome/browser/search/search.h" |
34 #include "chrome/browser/signin/chrome_signin_manager_delegate.h" | 35 #include "chrome/browser/signin/chrome_signin_manager_delegate.h" |
35 #include "chrome/browser/signin/signin_global_error.h" | 36 #include "chrome/browser/signin/signin_global_error.h" |
36 #include "chrome/browser/signin/signin_manager.h" | 37 #include "chrome/browser/signin/signin_manager.h" |
37 #include "chrome/browser/signin/signin_manager_delegate.h" | 38 #include "chrome/browser/signin/signin_manager_delegate.h" |
38 #include "chrome/browser/signin/signin_manager_factory.h" | 39 #include "chrome/browser/signin/signin_manager_factory.h" |
39 #include "chrome/browser/signin/signin_names_io_thread.h" | 40 #include "chrome/browser/signin/signin_names_io_thread.h" |
40 #include "chrome/browser/sync/profile_sync_service.h" | 41 #include "chrome/browser/sync/profile_sync_service.h" |
41 #include "chrome/browser/sync/profile_sync_service_factory.h" | 42 #include "chrome/browser/sync/profile_sync_service_factory.h" |
42 #include "chrome/browser/sync/sync_prefs.h" | 43 #include "chrome/browser/sync/sync_prefs.h" |
43 #include "chrome/browser/tab_contents/tab_util.h" | 44 #include "chrome/browser/tab_contents/tab_util.h" |
44 #include "chrome/browser/ui/browser_finder.h" | 45 #include "chrome/browser/ui/browser_finder.h" |
45 #include "chrome/browser/ui/browser_window.h" | 46 #include "chrome/browser/ui/browser_window.h" |
46 #include "chrome/browser/ui/chrome_pages.h" | 47 #include "chrome/browser/ui/chrome_pages.h" |
47 #include "chrome/browser/ui/sync/one_click_signin_histogram.h" | 48 #include "chrome/browser/ui/sync/one_click_signin_histogram.h" |
48 #include "chrome/browser/ui/sync/one_click_signin_sync_starter.h" | 49 #include "chrome/browser/ui/sync/one_click_signin_sync_starter.h" |
49 #include "chrome/browser/ui/sync/signin_histogram.h" | 50 #include "chrome/browser/ui/sync/signin_histogram.h" |
50 #include "chrome/browser/ui/tab_modal_confirm_dialog.h" | 51 #include "chrome/browser/ui/tab_modal_confirm_dialog.h" |
51 #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h" | 52 #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h" |
52 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 53 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
53 #include "chrome/common/chrome_switches.h" | 54 #include "chrome/common/chrome_switches.h" |
54 #include "chrome/common/chrome_version_info.h" | 55 #include "chrome/common/chrome_version_info.h" |
55 #include "chrome/common/net/url_util.h" | 56 #include "chrome/common/net/url_util.h" |
56 #include "chrome/common/one_click_signin_messages.h" | |
57 #include "chrome/common/pref_names.h" | 57 #include "chrome/common/pref_names.h" |
58 #include "chrome/common/url_constants.h" | 58 #include "chrome/common/url_constants.h" |
59 #include "content/public/browser/browser_thread.h" | 59 #include "content/public/browser/browser_thread.h" |
60 #include "content/public/browser/navigation_entry.h" | 60 #include "content/public/browser/navigation_entry.h" |
61 #include "content/public/browser/page_navigator.h" | 61 #include "content/public/browser/page_navigator.h" |
62 #include "content/public/browser/render_process_host.h" | 62 #include "content/public/browser/render_process_host.h" |
63 #include "content/public/browser/web_contents.h" | 63 #include "content/public/browser/web_contents.h" |
64 #include "content/public/browser/web_contents_view.h" | 64 #include "content/public/browser/web_contents_view.h" |
65 #include "content/public/common/frame_navigate_params.h" | 65 #include "content/public/common/frame_navigate_params.h" |
66 #include "content/public/common/page_transition_types.h" | 66 #include "content/public/common/page_transition_types.h" |
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 } // namespace | 544 } // namespace |
545 | 545 |
546 | 546 |
547 // OneClickSigninHelper ------------------------------------------------------- | 547 // OneClickSigninHelper ------------------------------------------------------- |
548 | 548 |
549 DEFINE_WEB_CONTENTS_USER_DATA_KEY(OneClickSigninHelper); | 549 DEFINE_WEB_CONTENTS_USER_DATA_KEY(OneClickSigninHelper); |
550 | 550 |
551 // static | 551 // static |
552 const int OneClickSigninHelper::kMaxNavigationsSince = 10; | 552 const int OneClickSigninHelper::kMaxNavigationsSince = 10; |
553 | 553 |
554 OneClickSigninHelper::OneClickSigninHelper(content::WebContents* web_contents) | 554 OneClickSigninHelper::OneClickSigninHelper(content::WebContents* web_contents, |
| 555 PasswordManager* password_manager) |
555 : content::WebContentsObserver(web_contents), | 556 : content::WebContentsObserver(web_contents), |
556 showing_signin_(false), | 557 showing_signin_(false), |
557 auto_accept_(AUTO_ACCEPT_NONE), | 558 auto_accept_(AUTO_ACCEPT_NONE), |
558 source_(signin::SOURCE_UNKNOWN), | 559 source_(signin::SOURCE_UNKNOWN), |
559 switched_to_advanced_(false), | 560 switched_to_advanced_(false), |
560 untrusted_navigations_since_signin_visit_(0), | 561 untrusted_navigations_since_signin_visit_(0), |
561 untrusted_confirmation_required_(false), | 562 untrusted_confirmation_required_(false), |
562 do_not_clear_pending_email_(false) { | 563 do_not_clear_pending_email_(false) { |
| 564 // May be NULL during testing. |
| 565 if (password_manager) { |
| 566 password_manager->AddSubmissionCallback( |
| 567 base::Bind(&OneClickSigninHelper::PasswordSubmitted, |
| 568 base::Unretained(this))); |
| 569 } |
563 } | 570 } |
564 | 571 |
565 OneClickSigninHelper::~OneClickSigninHelper() { | 572 OneClickSigninHelper::~OneClickSigninHelper() { |
566 content::WebContents* contents = web_contents(); | 573 content::WebContents* contents = web_contents(); |
567 if (contents) { | 574 if (contents) { |
568 Profile* profile = | 575 Profile* profile = |
569 Profile::FromBrowserContext(contents->GetBrowserContext()); | 576 Profile::FromBrowserContext(contents->GetBrowserContext()); |
570 ProfileSyncService* sync_service = | 577 ProfileSyncService* sync_service = |
571 ProfileSyncServiceFactory::GetForProfile(profile); | 578 ProfileSyncServiceFactory::GetForProfile(profile); |
572 if (sync_service && sync_service->HasObserver(this)) | 579 if (sync_service && sync_service->HasObserver(this)) |
573 sync_service->RemoveObserver(this); | 580 sync_service->RemoveObserver(this); |
574 } | 581 } |
575 } | 582 } |
576 | 583 |
577 // static | 584 // static |
| 585 void OneClickSigninHelper::CreateForWebContentsWithPasswordManager( |
| 586 content::WebContents* contents, |
| 587 PasswordManager* password_manager) { |
| 588 if (!FromWebContents(contents)) { |
| 589 contents->SetUserData(UserDataKey(), |
| 590 new OneClickSigninHelper(contents, password_manager)); |
| 591 } |
| 592 } |
| 593 |
| 594 // static |
578 bool OneClickSigninHelper::CanOffer(content::WebContents* web_contents, | 595 bool OneClickSigninHelper::CanOffer(content::WebContents* web_contents, |
579 CanOfferFor can_offer_for, | 596 CanOfferFor can_offer_for, |
580 const std::string& email, | 597 const std::string& email, |
581 std::string* error_message) { | 598 std::string* error_message) { |
582 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 599 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
583 VLOG(1) << "OneClickSigninHelper::CanOffer"; | 600 VLOG(1) << "OneClickSigninHelper::CanOffer"; |
584 | 601 |
585 if (error_message) | 602 if (error_message) |
586 error_message->clear(); | 603 error_message->clear(); |
587 | 604 |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
982 if (!do_not_clear_pending_email_) { | 999 if (!do_not_clear_pending_email_) { |
983 Profile* profile = | 1000 Profile* profile = |
984 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 1001 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
985 content::BrowserThread::PostTask( | 1002 content::BrowserThread::PostTask( |
986 content::BrowserThread::IO, FROM_HERE, | 1003 content::BrowserThread::IO, FROM_HERE, |
987 base::Bind(&ClearPendingEmailOnIOThread, | 1004 base::Bind(&ClearPendingEmailOnIOThread, |
988 base::Unretained(profile->GetResourceContext()))); | 1005 base::Unretained(profile->GetResourceContext()))); |
989 } | 1006 } |
990 } | 1007 } |
991 | 1008 |
992 bool OneClickSigninHelper::OnMessageReceived(const IPC::Message& message) { | 1009 void OneClickSigninHelper::PasswordSubmitted( |
993 bool handled = true; | 1010 const content::PasswordForm& form) { |
994 IPC_BEGIN_MESSAGE_MAP(OneClickSigninHelper, message) | |
995 IPC_MESSAGE_HANDLER(OneClickSigninHostMsg_FormSubmitted, OnFormSubmitted) | |
996 IPC_MESSAGE_UNHANDLED(handled = false) | |
997 IPC_END_MESSAGE_MAP() | |
998 | |
999 return handled; | |
1000 } | |
1001 | |
1002 bool OneClickSigninHelper::OnFormSubmitted(const content::PasswordForm& form) { | |
1003 // |password_| used to be set in DidNavigateAnyFrame, this is too late because | |
1004 // it is not executed until the end of redirect chains and password may | |
1005 // get lost if one of the redirects requires context swap. | |
1006 | |
1007 // We only need to scrape the password for Gaia logins. | 1011 // We only need to scrape the password for Gaia logins. |
1008 if (form.origin.is_valid() && | 1012 if (gaia::IsGaiaSignonRealm(GURL(form.signon_realm))) { |
1009 gaia::IsGaiaSignonRealm(GURL(form.signon_realm))) { | |
1010 VLOG(1) << "OneClickSigninHelper::DidNavigateAnyFrame: got password"; | 1013 VLOG(1) << "OneClickSigninHelper::DidNavigateAnyFrame: got password"; |
1011 password_ = UTF16ToUTF8(form.password_value); | 1014 password_ = UTF16ToUTF8(form.password_value); |
1012 } | 1015 } |
1013 | |
1014 return true; | |
1015 } | 1016 } |
1016 | 1017 |
1017 void OneClickSigninHelper::SetDoNotClearPendingEmailForTesting() { | 1018 void OneClickSigninHelper::SetDoNotClearPendingEmailForTesting() { |
1018 do_not_clear_pending_email_ = true; | 1019 do_not_clear_pending_email_ = true; |
1019 } | 1020 } |
1020 | 1021 |
1021 void OneClickSigninHelper::NavigateToPendingEntry( | 1022 void OneClickSigninHelper::NavigateToPendingEntry( |
1022 const GURL& url, | 1023 const GURL& url, |
1023 content::NavigationController::ReloadType reload_type) { | 1024 content::NavigationController::ReloadType reload_type) { |
1024 VLOG(1) << "OneClickSigninHelper::NavigateToPendingEntry: url=" << url.spec(); | 1025 VLOG(1) << "OneClickSigninHelper::NavigateToPendingEntry: url=" << url.spec(); |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1334 content::PAGE_TRANSITION_AUTO_TOPLEVEL, | 1335 content::PAGE_TRANSITION_AUTO_TOPLEVEL, |
1335 std::string()); | 1336 std::string()); |
1336 } | 1337 } |
1337 } | 1338 } |
1338 | 1339 |
1339 // Clears |original_continue_url_| here instead of in CleanTransientState, | 1340 // Clears |original_continue_url_| here instead of in CleanTransientState, |
1340 // because it is used in OnStateChanged which occurs later. | 1341 // because it is used in OnStateChanged which occurs later. |
1341 original_continue_url_ = GURL(); | 1342 original_continue_url_ = GURL(); |
1342 sync_service->RemoveObserver(this); | 1343 sync_service->RemoveObserver(this); |
1343 } | 1344 } |
OLD | NEW |