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> |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 #include "chrome/browser/ui/chrome_pages.h" | 46 #include "chrome/browser/ui/chrome_pages.h" |
47 #include "chrome/browser/ui/sync/one_click_signin_histogram.h" | 47 #include "chrome/browser/ui/sync/one_click_signin_histogram.h" |
48 #include "chrome/browser/ui/sync/one_click_signin_sync_starter.h" | 48 #include "chrome/browser/ui/sync/one_click_signin_sync_starter.h" |
49 #include "chrome/browser/ui/sync/signin_histogram.h" | 49 #include "chrome/browser/ui/sync/signin_histogram.h" |
50 #include "chrome/browser/ui/tab_modal_confirm_dialog.h" | 50 #include "chrome/browser/ui/tab_modal_confirm_dialog.h" |
51 #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h" | 51 #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h" |
52 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 52 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
53 #include "chrome/common/chrome_switches.h" | 53 #include "chrome/common/chrome_switches.h" |
54 #include "chrome/common/chrome_version_info.h" | 54 #include "chrome/common/chrome_version_info.h" |
55 #include "chrome/common/net/url_util.h" | 55 #include "chrome/common/net/url_util.h" |
56 #include "chrome/common/one_click_signin_messages.h" | |
57 #include "chrome/common/pref_names.h" | 56 #include "chrome/common/pref_names.h" |
58 #include "chrome/common/url_constants.h" | 57 #include "chrome/common/url_constants.h" |
59 #include "content/public/browser/browser_thread.h" | 58 #include "content/public/browser/browser_thread.h" |
60 #include "content/public/browser/navigation_entry.h" | 59 #include "content/public/browser/navigation_entry.h" |
61 #include "content/public/browser/page_navigator.h" | 60 #include "content/public/browser/page_navigator.h" |
62 #include "content/public/browser/render_process_host.h" | 61 #include "content/public/browser/render_process_host.h" |
63 #include "content/public/browser/web_contents.h" | 62 #include "content/public/browser/web_contents.h" |
64 #include "content/public/browser/web_contents_view.h" | 63 #include "content/public/browser/web_contents_view.h" |
65 #include "content/public/common/frame_navigate_params.h" | 64 #include "content/public/common/frame_navigate_params.h" |
66 #include "content/public/common/page_transition_types.h" | 65 #include "content/public/common/page_transition_types.h" |
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 } // namespace | 543 } // namespace |
545 | 544 |
546 | 545 |
547 // OneClickSigninHelper ------------------------------------------------------- | 546 // OneClickSigninHelper ------------------------------------------------------- |
548 | 547 |
549 DEFINE_WEB_CONTENTS_USER_DATA_KEY(OneClickSigninHelper); | 548 DEFINE_WEB_CONTENTS_USER_DATA_KEY(OneClickSigninHelper); |
550 | 549 |
551 // static | 550 // static |
552 const int OneClickSigninHelper::kMaxNavigationsSince = 10; | 551 const int OneClickSigninHelper::kMaxNavigationsSince = 10; |
553 | 552 |
554 OneClickSigninHelper::OneClickSigninHelper(content::WebContents* web_contents) | 553 OneClickSigninHelper::OneClickSigninHelper(content::WebContents* web_contents, |
| 554 PasswordManager* password_manager) |
555 : content::WebContentsObserver(web_contents), | 555 : content::WebContentsObserver(web_contents), |
556 showing_signin_(false), | 556 showing_signin_(false), |
557 auto_accept_(AUTO_ACCEPT_NONE), | 557 auto_accept_(AUTO_ACCEPT_NONE), |
558 source_(SyncPromoUI::SOURCE_UNKNOWN), | 558 source_(SyncPromoUI::SOURCE_UNKNOWN), |
559 switched_to_advanced_(false), | 559 switched_to_advanced_(false), |
560 original_source_(SyncPromoUI::SOURCE_UNKNOWN), | 560 original_source_(SyncPromoUI::SOURCE_UNKNOWN), |
561 untrusted_navigations_since_signin_visit_(0), | 561 untrusted_navigations_since_signin_visit_(0), |
562 untrusted_confirmation_required_(false), | 562 untrusted_confirmation_required_(false), |
563 do_not_clear_pending_email_(false) { | 563 do_not_clear_pending_email_(false) { |
| 564 if (password_manager) |
| 565 password_manager->AddSubmissionObserver(this); |
564 } | 566 } |
565 | 567 |
566 OneClickSigninHelper::~OneClickSigninHelper() { | 568 OneClickSigninHelper::~OneClickSigninHelper() { |
567 content::WebContents* contents = web_contents(); | 569 content::WebContents* contents = web_contents(); |
568 if (contents) { | 570 if (contents) { |
569 Profile* profile = | 571 Profile* profile = |
570 Profile::FromBrowserContext(contents->GetBrowserContext()); | 572 Profile::FromBrowserContext(contents->GetBrowserContext()); |
571 ProfileSyncService* sync_service = | 573 ProfileSyncService* sync_service = |
572 ProfileSyncServiceFactory::GetForProfile(profile); | 574 ProfileSyncServiceFactory::GetForProfile(profile); |
573 if (sync_service && sync_service->HasObserver(this)) | 575 if (sync_service && sync_service->HasObserver(this)) |
574 sync_service->RemoveObserver(this); | 576 sync_service->RemoveObserver(this); |
575 } | 577 } |
576 } | 578 } |
577 | 579 |
578 // static | 580 // static |
| 581 void OneClickSigninHelper::CreateForWebContentsWithPasswordManager( |
| 582 content::WebContents* contents, |
| 583 PasswordManager* password_manager) { |
| 584 if (!FromWebContents(contents)) { |
| 585 contents->SetUserData(UserDataKey(), |
| 586 new OneClickSigninHelper(contents, password_manager)); |
| 587 } |
| 588 } |
| 589 |
| 590 // static |
579 bool OneClickSigninHelper::CanOffer(content::WebContents* web_contents, | 591 bool OneClickSigninHelper::CanOffer(content::WebContents* web_contents, |
580 CanOfferFor can_offer_for, | 592 CanOfferFor can_offer_for, |
581 const std::string& email, | 593 const std::string& email, |
582 std::string* error_message) { | 594 std::string* error_message) { |
583 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 595 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
584 VLOG(1) << "OneClickSigninHelper::CanOffer"; | 596 VLOG(1) << "OneClickSigninHelper::CanOffer"; |
585 | 597 |
586 if (error_message) | 598 if (error_message) |
587 error_message->clear(); | 599 error_message->clear(); |
588 | 600 |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
978 if (!do_not_clear_pending_email_) { | 990 if (!do_not_clear_pending_email_) { |
979 Profile* profile = | 991 Profile* profile = |
980 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 992 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
981 content::BrowserThread::PostTask( | 993 content::BrowserThread::PostTask( |
982 content::BrowserThread::IO, FROM_HERE, | 994 content::BrowserThread::IO, FROM_HERE, |
983 base::Bind(&ClearPendingEmailOnIOThread, | 995 base::Bind(&ClearPendingEmailOnIOThread, |
984 base::Unretained(profile->GetResourceContext()))); | 996 base::Unretained(profile->GetResourceContext()))); |
985 } | 997 } |
986 } | 998 } |
987 | 999 |
988 bool OneClickSigninHelper::OnMessageReceived(const IPC::Message& message) { | 1000 void OneClickSigninHelper::PasswordSubmitted( |
989 bool handled = true; | 1001 const content::PasswordForm& form) { |
990 IPC_BEGIN_MESSAGE_MAP(OneClickSigninHelper, message) | |
991 IPC_MESSAGE_HANDLER(OneClickSigninHostMsg_FormSubmitted, OnFormSubmitted) | |
992 IPC_MESSAGE_UNHANDLED(handled = false) | |
993 IPC_END_MESSAGE_MAP() | |
994 | |
995 return handled; | |
996 } | |
997 | |
998 bool OneClickSigninHelper::OnFormSubmitted(const content::PasswordForm& form) { | |
999 // |password_| used to be set in DidNavigateAnyFrame, this is too late because | 1002 // |password_| used to be set in DidNavigateAnyFrame, this is too late because |
1000 // it is not executed until the end of redirect chains and password may | 1003 // it is not executed until the end of redirect chains and password may |
1001 // get lost if one of the redirects requires context swap. | 1004 // get lost if one of the redirects requires context swap. |
1002 | 1005 |
1003 // We only need to scrape the password for Gaia logins. | 1006 // We only need to scrape the password for Gaia logins. |
1004 if (form.origin.is_valid() && | 1007 if (gaia::IsGaiaSignonRealm(GURL(form.signon_realm))) { |
1005 gaia::IsGaiaSignonRealm(GURL(form.signon_realm))) { | |
1006 VLOG(1) << "OneClickSigninHelper::DidNavigateAnyFrame: got password"; | 1008 VLOG(1) << "OneClickSigninHelper::DidNavigateAnyFrame: got password"; |
1007 password_ = UTF16ToUTF8(form.password_value); | 1009 password_ = UTF16ToUTF8(form.password_value); |
1008 } | 1010 } |
1009 | |
1010 return true; | |
1011 } | 1011 } |
1012 | 1012 |
1013 void OneClickSigninHelper::SetDoNotClearPendingEmailForTesting() { | 1013 void OneClickSigninHelper::SetDoNotClearPendingEmailForTesting() { |
1014 do_not_clear_pending_email_ = true; | 1014 do_not_clear_pending_email_ = true; |
1015 } | 1015 } |
1016 | 1016 |
1017 void OneClickSigninHelper::NavigateToPendingEntry( | 1017 void OneClickSigninHelper::NavigateToPendingEntry( |
1018 const GURL& url, | 1018 const GURL& url, |
1019 content::NavigationController::ReloadType reload_type) { | 1019 content::NavigationController::ReloadType reload_type) { |
1020 VLOG(1) << "OneClickSigninHelper::NavigateToPendingEntry: url=" << url.spec(); | 1020 VLOG(1) << "OneClickSigninHelper::NavigateToPendingEntry: url=" << url.spec(); |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1337 content::Referrer(), | 1337 content::Referrer(), |
1338 content::PAGE_TRANSITION_AUTO_TOPLEVEL, | 1338 content::PAGE_TRANSITION_AUTO_TOPLEVEL, |
1339 std::string()); | 1339 std::string()); |
1340 } | 1340 } |
1341 } | 1341 } |
1342 | 1342 |
1343 // Clear the redirect URL. | 1343 // Clear the redirect URL. |
1344 redirect_url_ = GURL(); | 1344 redirect_url_ = GURL(); |
1345 sync_service->RemoveObserver(this); | 1345 sync_service->RemoveObserver(this); |
1346 } | 1346 } |
OLD | NEW |