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/password_manager/password_manager_delegate_impl.h" | 5 #include "chrome/browser/password_manager/password_manager_delegate_impl.h" |
6 | 6 |
7 #include "base/memory/singleton.h" | 7 #include "base/memory/singleton.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" | 10 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 DEFINE_WEB_CONTENTS_USER_DATA_KEY(PasswordManagerDelegateImpl); | 31 DEFINE_WEB_CONTENTS_USER_DATA_KEY(PasswordManagerDelegateImpl); |
32 | 32 |
33 // After a successful *new* login attempt, we take the PasswordFormManager in | 33 // After a successful *new* login attempt, we take the PasswordFormManager in |
34 // provisional_save_manager_ and move it to a SavePasswordInfoBarDelegate while | 34 // provisional_save_manager_ and move it to a SavePasswordInfoBarDelegate while |
35 // the user makes up their mind with the "save password" infobar. Note if the | 35 // the user makes up their mind with the "save password" infobar. Note if the |
36 // login is one we already know about, the end of the line is | 36 // login is one we already know about, the end of the line is |
37 // provisional_save_manager_ because we just update it on success and so such | 37 // provisional_save_manager_ because we just update it on success and so such |
38 // forms never end up in an infobar. | 38 // forms never end up in an infobar. |
39 class SavePasswordInfoBarDelegate : public ConfirmInfoBarDelegate { | 39 class SavePasswordInfoBarDelegate : public ConfirmInfoBarDelegate { |
40 public: | 40 public: |
41 SavePasswordInfoBarDelegate(InfoBarService* infobar_service, | 41 // If we won't be showing the one-click signin infobar, creates a save |
42 PasswordFormManager* form_to_save); | 42 // password delegate and adds it to the InfoBarService for |web_contents|. |
| 43 static void Create(content::WebContents* web_contents, |
| 44 PasswordFormManager* form_to_save); |
43 | 45 |
44 private: | 46 private: |
45 enum ResponseType { | 47 enum ResponseType { |
46 NO_RESPONSE = 0, | 48 NO_RESPONSE = 0, |
47 REMEMBER_PASSWORD, | 49 REMEMBER_PASSWORD, |
48 DONT_REMEMBER_PASSWORD, | 50 DONT_REMEMBER_PASSWORD, |
49 NUM_RESPONSE_TYPES, | 51 NUM_RESPONSE_TYPES, |
50 }; | 52 }; |
51 | 53 |
| 54 SavePasswordInfoBarDelegate(InfoBarService* infobar_service, |
| 55 PasswordFormManager* form_to_save); |
52 virtual ~SavePasswordInfoBarDelegate(); | 56 virtual ~SavePasswordInfoBarDelegate(); |
53 | 57 |
54 // ConfirmInfoBarDelegate | 58 // ConfirmInfoBarDelegate |
55 virtual gfx::Image* GetIcon() const OVERRIDE; | 59 virtual gfx::Image* GetIcon() const OVERRIDE; |
56 virtual Type GetInfoBarType() const OVERRIDE; | 60 virtual Type GetInfoBarType() const OVERRIDE; |
57 virtual string16 GetMessageText() const OVERRIDE; | 61 virtual string16 GetMessageText() const OVERRIDE; |
58 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; | 62 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; |
59 virtual bool Accept() OVERRIDE; | 63 virtual bool Accept() OVERRIDE; |
60 virtual bool Cancel() OVERRIDE; | 64 virtual bool Cancel() OVERRIDE; |
61 | 65 |
62 virtual InfoBarAutomationType GetInfoBarAutomationType() const OVERRIDE; | 66 virtual InfoBarAutomationType GetInfoBarAutomationType() const OVERRIDE; |
63 | 67 |
64 // The PasswordFormManager managing the form we're asking the user about, | 68 // The PasswordFormManager managing the form we're asking the user about, |
65 // and should update as per her decision. | 69 // and should update as per her decision. |
66 scoped_ptr<PasswordFormManager> form_to_save_; | 70 scoped_ptr<PasswordFormManager> form_to_save_; |
67 | 71 |
68 // Used to track the results we get from the info bar. | 72 // Used to track the results we get from the info bar. |
69 ResponseType infobar_response_; | 73 ResponseType infobar_response_; |
70 | 74 |
71 DISALLOW_COPY_AND_ASSIGN(SavePasswordInfoBarDelegate); | 75 DISALLOW_COPY_AND_ASSIGN(SavePasswordInfoBarDelegate); |
72 }; | 76 }; |
73 | 77 |
| 78 // static |
| 79 void SavePasswordInfoBarDelegate::Create(content::WebContents* web_contents, |
| 80 PasswordFormManager* form_to_save) { |
| 81 #if defined(ENABLE_ONE_CLICK_SIGNIN) |
| 82 // Don't show the password manager infobar if this form is for a google |
| 83 // account and we are going to show the one-click singin infobar. |
| 84 // For now, one-click signin is fully implemented only on windows. |
| 85 GURL realm(form_to_save->realm()); |
| 86 // TODO(mathp): Checking only against associated_username() causes a bug |
| 87 // referenced here: crbug.com/133275 |
| 88 if ((realm == GURL(GaiaUrls::GetInstance()->gaia_login_form_realm()) || |
| 89 realm == GURL("https://www.google.com/")) && |
| 90 OneClickSigninHelper::CanOffer( |
| 91 web_contents, |
| 92 OneClickSigninHelper::CAN_OFFER_FOR_INTERSTITAL_ONLY, |
| 93 UTF16ToUTF8(form_to_save->associated_username()), NULL)) { |
| 94 return; |
| 95 } |
| 96 #endif |
| 97 |
| 98 InfoBarService* infobar_service = |
| 99 InfoBarService::FromWebContents(web_contents); |
| 100 infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( |
| 101 new SavePasswordInfoBarDelegate(infobar_service, form_to_save))); |
| 102 } |
| 103 |
74 SavePasswordInfoBarDelegate::SavePasswordInfoBarDelegate( | 104 SavePasswordInfoBarDelegate::SavePasswordInfoBarDelegate( |
75 InfoBarService* infobar_service, | 105 InfoBarService* infobar_service, |
76 PasswordFormManager* form_to_save) | 106 PasswordFormManager* form_to_save) |
77 : ConfirmInfoBarDelegate(infobar_service), | 107 : ConfirmInfoBarDelegate(infobar_service), |
78 form_to_save_(form_to_save), | 108 form_to_save_(form_to_save), |
79 infobar_response_(NO_RESPONSE) { | 109 infobar_response_(NO_RESPONSE) { |
80 } | 110 } |
81 | 111 |
82 SavePasswordInfoBarDelegate::~SavePasswordInfoBarDelegate() { | 112 SavePasswordInfoBarDelegate::~SavePasswordInfoBarDelegate() { |
83 UMA_HISTOGRAM_ENUMERATION("PasswordManager.InfoBarResponse", | 113 UMA_HISTOGRAM_ENUMERATION("PasswordManager.InfoBarResponse", |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 | 170 |
141 web_contents_->GetRenderViewHost()->Send( | 171 web_contents_->GetRenderViewHost()->Send( |
142 new AutofillMsg_FillPasswordForm( | 172 new AutofillMsg_FillPasswordForm( |
143 web_contents_->GetRenderViewHost()->GetRoutingID(), | 173 web_contents_->GetRenderViewHost()->GetRoutingID(), |
144 form_data, | 174 form_data, |
145 disable_popup)); | 175 disable_popup)); |
146 } | 176 } |
147 | 177 |
148 void PasswordManagerDelegateImpl::AddSavePasswordInfoBarIfPermitted( | 178 void PasswordManagerDelegateImpl::AddSavePasswordInfoBarIfPermitted( |
149 PasswordFormManager* form_to_save) { | 179 PasswordFormManager* form_to_save) { |
150 // Don't show the password manager infobar if this form is for a google | 180 SavePasswordInfoBarDelegate::Create(web_contents_, form_to_save); |
151 // account and we are going to show the one-click singin infobar. | |
152 // For now, one-click signin is fully implemented only on windows. | |
153 #if defined(ENABLE_ONE_CLICK_SIGNIN) | |
154 GURL realm(form_to_save->realm()); | |
155 // TODO(mathp): Checking only against associated_username() causes a bug | |
156 // referenced here: crbug.com/133275 | |
157 if ((realm == GURL(GaiaUrls::GetInstance()->gaia_login_form_realm()) || | |
158 realm == GURL("https://www.google.com/")) && | |
159 OneClickSigninHelper::CanOffer(web_contents_, | |
160 OneClickSigninHelper::CAN_OFFER_FOR_INTERSTITAL_ONLY, | |
161 UTF16ToUTF8(form_to_save->associated_username()), NULL)) { | |
162 return; | |
163 } | |
164 #endif | |
165 | |
166 InfoBarService* infobar_service = | |
167 InfoBarService::FromWebContents(web_contents_); | |
168 infobar_service->AddInfoBar( | |
169 new SavePasswordInfoBarDelegate(infobar_service, form_to_save)); | |
170 } | 181 } |
171 | 182 |
172 Profile* PasswordManagerDelegateImpl::GetProfile() { | 183 Profile* PasswordManagerDelegateImpl::GetProfile() { |
173 return Profile::FromBrowserContext(web_contents_->GetBrowserContext()); | 184 return Profile::FromBrowserContext(web_contents_->GetBrowserContext()); |
174 } | 185 } |
175 | 186 |
176 bool PasswordManagerDelegateImpl::DidLastPageLoadEncounterSSLErrors() { | 187 bool PasswordManagerDelegateImpl::DidLastPageLoadEncounterSSLErrors() { |
177 content::NavigationEntry* entry = | 188 content::NavigationEntry* entry = |
178 web_contents_->GetController().GetActiveEntry(); | 189 web_contents_->GetController().GetActiveEntry(); |
179 if (!entry) { | 190 if (!entry) { |
180 NOTREACHED(); | 191 NOTREACHED(); |
181 return false; | 192 return false; |
182 } | 193 } |
183 | 194 |
184 return net::IsCertStatusError(entry->GetSSL().cert_status); | 195 return net::IsCertStatusError(entry->GetSSL().cert_status); |
185 } | 196 } |
OLD | NEW |