Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/password_manager/content/browser/credential_manager_dispatc her.h" | 5 #include "components/password_manager/content/browser/credential_manager_dispatc her.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/scoped_vector.h" | 8 #include "base/memory/scoped_vector.h" |
| 9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "components/autofill/core/common/password_form.h" | 11 #include "components/autofill/core/common/password_form.h" |
| 12 #include "components/password_manager/content/browser/content_password_manager_d river.h" | 12 #include "components/password_manager/content/browser/content_password_manager_d river.h" |
| 13 #include "components/password_manager/content/browser/content_password_manager_d river_factory.h" | 13 #include "components/password_manager/content/browser/content_password_manager_d river_factory.h" |
| 14 #include "components/password_manager/content/browser/credential_manager_passwor d_form_manager.h" | 14 #include "components/password_manager/content/browser/credential_manager_passwor d_form_manager.h" |
| 15 #include "components/password_manager/content/common/credential_manager_messages .h" | 15 #include "components/password_manager/content/common/credential_manager_messages .h" |
| 16 #include "components/password_manager/content/common/credential_manager_types.h" | 16 #include "components/password_manager/content/common/credential_manager_types.h" |
| 17 #include "components/password_manager/core/browser/password_manager_client.h" | 17 #include "components/password_manager/core/browser/password_manager_client.h" |
| 18 #include "components/password_manager/core/browser/password_store.h" | 18 #include "components/password_manager/core/browser/password_store.h" |
| 19 #include "components/password_manager/core/common/password_manager_pref_names.h" | 19 #include "components/password_manager/core/common/password_manager_pref_names.h" |
| 20 #include "content/public/browser/render_view_host.h" | 20 #include "content/public/browser/render_view_host.h" |
| 21 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
| 22 #include "ipc/ipc_message_macros.h" | 22 #include "ipc/ipc_message_macros.h" |
| 23 | 23 |
| 24 namespace password_manager { | 24 namespace password_manager { |
| 25 | 25 |
| 26 // CredentialManagerDispatcher::PendingRequestTask ----------------------------- | |
| 27 | |
| 26 class CredentialManagerDispatcher::PendingRequestTask | 28 class CredentialManagerDispatcher::PendingRequestTask |
| 27 : public PasswordStoreConsumer { | 29 : public PasswordStoreConsumer { |
| 28 public: | 30 public: |
| 29 PendingRequestTask(CredentialManagerDispatcher* const dispatcher, | 31 PendingRequestTask(CredentialManagerDispatcher* const dispatcher, |
| 30 int request_id, | 32 int request_id, |
| 31 bool request_zero_click_only, | 33 bool request_zero_click_only, |
| 32 const GURL& request_origin, | 34 const GURL& request_origin, |
| 33 const std::vector<GURL>& request_federations) | 35 const std::vector<GURL>& request_federations) |
| 34 : dispatcher_(dispatcher), | 36 : dispatcher_(dispatcher), |
| 35 id_(request_id), | 37 id_(request_id), |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 CredentialManagerDispatcher* const dispatcher_; | 97 CredentialManagerDispatcher* const dispatcher_; |
| 96 | 98 |
| 97 const int id_; | 99 const int id_; |
| 98 const bool zero_click_only_; | 100 const bool zero_click_only_; |
| 99 const GURL origin_; | 101 const GURL origin_; |
| 100 std::set<std::string> federations_; | 102 std::set<std::string> federations_; |
| 101 | 103 |
| 102 DISALLOW_COPY_AND_ASSIGN(PendingRequestTask); | 104 DISALLOW_COPY_AND_ASSIGN(PendingRequestTask); |
| 103 }; | 105 }; |
| 104 | 106 |
| 107 // CredentialManagerDispatcher::PendingSignedOutTask --------------------------- | |
| 108 | |
| 109 class CredentialManagerDispatcher::PendingSignedOutTask | |
| 110 : public PasswordStoreConsumer { | |
| 111 public: | |
| 112 PendingSignedOutTask(CredentialManagerDispatcher* const dispatcher, | |
| 113 int request_id, | |
| 114 const GURL& origin) | |
| 115 : dispatcher_(dispatcher), id_(request_id), origin_(origin) {} | |
|
vabr (Chromium)
2015/02/05 10:27:10
As discussed before on engedy's CL https://coderev
| |
| 116 | |
| 117 // PasswordStoreConsumer implementation. | |
| 118 void OnGetPasswordStoreResults( | |
|
vabr (Chromium)
2015/02/05 10:27:10
A heads-up: This will conflict with a change in si
| |
| 119 const std::vector<autofill::PasswordForm*>& results) override { | |
| 120 PasswordStore* store = dispatcher_->GetPasswordStore(); | |
| 121 for (autofill::PasswordForm* form : results) { | |
| 122 if (form->origin == origin_) { | |
| 123 form->skip_zero_click = true; | |
| 124 store->UpdateLogin(*form); | |
| 125 } | |
| 126 } | |
| 127 } | |
| 128 | |
| 129 private: | |
| 130 // Backlink to the CredentialManagerDispatcher that owns this object. | |
| 131 CredentialManagerDispatcher* const dispatcher_; | |
| 132 | |
| 133 const int id_; | |
| 134 const GURL origin_; | |
| 135 | |
| 136 DISALLOW_COPY_AND_ASSIGN(PendingSignedOutTask); | |
| 137 }; | |
| 138 | |
| 139 // CredentialManagerDispatcher ------------------------------------------------- | |
| 140 | |
| 105 CredentialManagerDispatcher::CredentialManagerDispatcher( | 141 CredentialManagerDispatcher::CredentialManagerDispatcher( |
| 106 content::WebContents* web_contents, | 142 content::WebContents* web_contents, |
| 107 PasswordManagerClient* client) | 143 PasswordManagerClient* client) |
| 108 : WebContentsObserver(web_contents), client_(client) { | 144 : WebContentsObserver(web_contents), client_(client) { |
| 109 DCHECK(web_contents); | 145 DCHECK(web_contents); |
| 110 auto_signin_enabled_.Init(prefs::kPasswordManagerAutoSignin, | 146 auto_signin_enabled_.Init(prefs::kPasswordManagerAutoSignin, |
| 111 client_->GetPrefs()); | 147 client_->GetPrefs()); |
| 112 } | 148 } |
| 113 | 149 |
| 114 CredentialManagerDispatcher::~CredentialManagerDispatcher() { | 150 CredentialManagerDispatcher::~CredentialManagerDispatcher() { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 DCHECK(request_id); | 182 DCHECK(request_id); |
| 147 web_contents()->GetRenderViewHost()->Send( | 183 web_contents()->GetRenderViewHost()->Send( |
| 148 new CredentialManagerMsg_AcknowledgeSignedIn( | 184 new CredentialManagerMsg_AcknowledgeSignedIn( |
| 149 web_contents()->GetRenderViewHost()->GetRoutingID(), request_id)); | 185 web_contents()->GetRenderViewHost()->GetRoutingID(), request_id)); |
| 150 | 186 |
| 151 if (!IsSavingEnabledForCurrentPage()) | 187 if (!IsSavingEnabledForCurrentPage()) |
| 152 return; | 188 return; |
| 153 | 189 |
| 154 scoped_ptr<autofill::PasswordForm> form(CreatePasswordFormFromCredentialInfo( | 190 scoped_ptr<autofill::PasswordForm> form(CreatePasswordFormFromCredentialInfo( |
| 155 credential, web_contents()->GetLastCommittedURL().GetOrigin())); | 191 credential, web_contents()->GetLastCommittedURL().GetOrigin())); |
| 192 form->skip_zero_click = !IsZeroClickAllowed(); | |
| 156 | 193 |
| 157 // TODO(mkwst): This is a stub; we should be checking the PasswordStore to | 194 // TODO(mkwst): This is a stub; we should be checking the PasswordStore to |
| 158 // determine whether or not the credential exists, and calling UpdateLogin | 195 // determine whether or not the credential exists, and calling UpdateLogin |
| 159 // accordingly. | 196 // accordingly. |
| 160 form_manager_.reset(new CredentialManagerPasswordFormManager( | 197 form_manager_.reset(new CredentialManagerPasswordFormManager( |
| 161 client_, GetDriver(), *form, this)); | 198 client_, GetDriver(), *form, this)); |
| 162 } | 199 } |
| 163 | 200 |
| 164 void CredentialManagerDispatcher::OnProvisionalSaveComplete() { | 201 void CredentialManagerDispatcher::OnProvisionalSaveComplete() { |
| 165 DCHECK(form_manager_); | 202 DCHECK(form_manager_); |
| 166 client_->PromptUserToSavePassword(form_manager_.Pass()); | 203 client_->PromptUserToSavePassword(form_manager_.Pass()); |
| 167 } | 204 } |
| 168 | 205 |
| 169 void CredentialManagerDispatcher::OnNotifySignedOut(int request_id) { | 206 void CredentialManagerDispatcher::OnNotifySignedOut(int request_id) { |
| 170 DCHECK(request_id); | 207 DCHECK(request_id); |
| 171 // TODO(mkwst): This is a stub. | 208 |
| 209 PasswordStore* store = GetPasswordStore(); | |
| 210 if (!pending_sign_out_ && store) { | |
| 211 pending_sign_out_.reset(new PendingSignedOutTask( | |
| 212 this, request_id, web_contents()->GetLastCommittedURL().GetOrigin())); | |
| 213 | |
| 214 // This will result in a callback to | |
| 215 // PendingSignedOutTask::OnGetPasswordStoreResults(). | |
| 216 store->GetAutofillableLogins(pending_sign_out_.get()); | |
| 217 } | |
| 218 | |
| 172 web_contents()->GetRenderViewHost()->Send( | 219 web_contents()->GetRenderViewHost()->Send( |
| 173 new CredentialManagerMsg_AcknowledgeSignedOut( | 220 new CredentialManagerMsg_AcknowledgeSignedOut( |
| 174 web_contents()->GetRenderViewHost()->GetRoutingID(), request_id)); | 221 web_contents()->GetRenderViewHost()->GetRoutingID(), request_id)); |
| 175 } | 222 } |
| 176 | 223 |
| 177 void CredentialManagerDispatcher::OnRequestCredential( | 224 void CredentialManagerDispatcher::OnRequestCredential( |
| 178 int request_id, | 225 int request_id, |
| 179 bool zero_click_only, | 226 bool zero_click_only, |
| 180 const std::vector<GURL>& federations) { | 227 const std::vector<GURL>& federations) { |
| 181 DCHECK(request_id); | 228 DCHECK(request_id); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 227 DCHECK(driver_factory); | 274 DCHECK(driver_factory); |
| 228 PasswordManagerDriver* driver = | 275 PasswordManagerDriver* driver = |
| 229 driver_factory->GetDriverForFrame(web_contents()->GetMainFrame()); | 276 driver_factory->GetDriverForFrame(web_contents()->GetMainFrame()); |
| 230 return driver->AsWeakPtr(); | 277 return driver->AsWeakPtr(); |
| 231 } | 278 } |
| 232 | 279 |
| 233 void CredentialManagerDispatcher::SendCredential(int request_id, | 280 void CredentialManagerDispatcher::SendCredential(int request_id, |
| 234 const CredentialInfo& info) { | 281 const CredentialInfo& info) { |
| 235 DCHECK(pending_request_); | 282 DCHECK(pending_request_); |
| 236 DCHECK_EQ(pending_request_->id(), request_id); | 283 DCHECK_EQ(pending_request_->id(), request_id); |
| 284 // TODO(mkwst): We need to update the underlying PasswordForm if the user | |
| 285 // has enabled zeroclick globally, and clicks through a non-zeroclick form | |
| 286 // for an origin. | |
| 237 web_contents()->GetRenderViewHost()->Send( | 287 web_contents()->GetRenderViewHost()->Send( |
| 238 new CredentialManagerMsg_SendCredential( | 288 new CredentialManagerMsg_SendCredential( |
| 239 web_contents()->GetRenderViewHost()->GetRoutingID(), | 289 web_contents()->GetRenderViewHost()->GetRoutingID(), |
| 240 pending_request_->id(), info)); | 290 pending_request_->id(), info)); |
| 241 pending_request_.reset(); | 291 pending_request_.reset(); |
| 242 } | 292 } |
| 243 | 293 |
| 244 } // namespace password_manager | 294 } // namespace password_manager |
| OLD | NEW |