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 | |
| 116 // PasswordStoreConsumer implementation. | |
| 117 void OnGetPasswordStoreResults( | |
| 118 const std::vector<autofill::PasswordForm*>& results) override; | |
| 119 | |
| 120 private: | |
| 121 // Backlink to the CredentialManagerDispatcher that owns this object. | |
| 122 CredentialManagerDispatcher* const dispatcher_; | |
| 123 | |
| 124 const int id_; | |
| 125 const GURL origin_; | |
| 126 | |
| 127 DISALLOW_COPY_AND_ASSIGN(PendingSignedOutTask); | |
| 128 }; | |
| 129 | |
| 130 CredentialManagerDispatcher::PendingSignedOutTask( | |
|
vabr (Chromium)
2015/02/05 14:06:48
CredentialManagerDispatcher::PendingSignedOutTask:
| |
| 131 CredentialManagerDispatcher* const dispatcher, | |
| 132 int request_id, | |
| 133 const GURL& origin) | |
| 134 : dispatcher_(dispatcher), id_(request_id), origin_(origin) { | |
| 135 } | |
| 136 | |
| 137 void CredentialManagerDispatcher::PendingSignedOutTask:: | |
| 138 OnGetPasswordStoreResults( | |
| 139 const std::vector<autofill::PasswordForm*>& results) { | |
|
vabr (Chromium)
2015/02/05 14:06:48
Also, "The implementation owns all PasswordForms i
| |
| 140 PasswordStore* store = dispatcher_->GetPasswordStore(); | |
| 141 for (autofill::PasswordForm* form : results) { | |
| 142 if (form->origin == origin_) { | |
| 143 form->skip_zero_click = true; | |
| 144 store->UpdateLogin(*form); | |
| 145 } | |
| 146 } | |
| 147 } | |
| 148 | |
| 149 // CredentialManagerDispatcher ------------------------------------------------- | |
| 150 | |
| 105 CredentialManagerDispatcher::CredentialManagerDispatcher( | 151 CredentialManagerDispatcher::CredentialManagerDispatcher( |
| 106 content::WebContents* web_contents, | 152 content::WebContents* web_contents, |
| 107 PasswordManagerClient* client) | 153 PasswordManagerClient* client) |
| 108 : WebContentsObserver(web_contents), client_(client) { | 154 : WebContentsObserver(web_contents), client_(client) { |
| 109 DCHECK(web_contents); | 155 DCHECK(web_contents); |
| 110 auto_signin_enabled_.Init(prefs::kPasswordManagerAutoSignin, | 156 auto_signin_enabled_.Init(prefs::kPasswordManagerAutoSignin, |
| 111 client_->GetPrefs()); | 157 client_->GetPrefs()); |
| 112 } | 158 } |
| 113 | 159 |
| 114 CredentialManagerDispatcher::~CredentialManagerDispatcher() { | 160 CredentialManagerDispatcher::~CredentialManagerDispatcher() { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 DCHECK(request_id); | 192 DCHECK(request_id); |
| 147 web_contents()->GetRenderViewHost()->Send( | 193 web_contents()->GetRenderViewHost()->Send( |
| 148 new CredentialManagerMsg_AcknowledgeSignedIn( | 194 new CredentialManagerMsg_AcknowledgeSignedIn( |
| 149 web_contents()->GetRenderViewHost()->GetRoutingID(), request_id)); | 195 web_contents()->GetRenderViewHost()->GetRoutingID(), request_id)); |
| 150 | 196 |
| 151 if (!IsSavingEnabledForCurrentPage()) | 197 if (!IsSavingEnabledForCurrentPage()) |
| 152 return; | 198 return; |
| 153 | 199 |
| 154 scoped_ptr<autofill::PasswordForm> form(CreatePasswordFormFromCredentialInfo( | 200 scoped_ptr<autofill::PasswordForm> form(CreatePasswordFormFromCredentialInfo( |
| 155 credential, web_contents()->GetLastCommittedURL().GetOrigin())); | 201 credential, web_contents()->GetLastCommittedURL().GetOrigin())); |
| 202 form->skip_zero_click = !IsZeroClickAllowed(); | |
| 156 | 203 |
| 157 // TODO(mkwst): This is a stub; we should be checking the PasswordStore to | 204 // TODO(mkwst): This is a stub; we should be checking the PasswordStore to |
| 158 // determine whether or not the credential exists, and calling UpdateLogin | 205 // determine whether or not the credential exists, and calling UpdateLogin |
| 159 // accordingly. | 206 // accordingly. |
| 160 form_manager_.reset(new CredentialManagerPasswordFormManager( | 207 form_manager_.reset(new CredentialManagerPasswordFormManager( |
| 161 client_, GetDriver(), *form, this)); | 208 client_, GetDriver(), *form, this)); |
| 162 } | 209 } |
| 163 | 210 |
| 164 void CredentialManagerDispatcher::OnProvisionalSaveComplete() { | 211 void CredentialManagerDispatcher::OnProvisionalSaveComplete() { |
| 165 DCHECK(form_manager_); | 212 DCHECK(form_manager_); |
| 166 client_->PromptUserToSavePassword(form_manager_.Pass()); | 213 client_->PromptUserToSavePassword(form_manager_.Pass()); |
| 167 } | 214 } |
| 168 | 215 |
| 169 void CredentialManagerDispatcher::OnNotifySignedOut(int request_id) { | 216 void CredentialManagerDispatcher::OnNotifySignedOut(int request_id) { |
| 170 DCHECK(request_id); | 217 DCHECK(request_id); |
| 171 // TODO(mkwst): This is a stub. | 218 |
| 219 PasswordStore* store = GetPasswordStore(); | |
| 220 if (!pending_sign_out_ && store) { | |
| 221 pending_sign_out_.reset(new PendingSignedOutTask( | |
| 222 this, request_id, web_contents()->GetLastCommittedURL().GetOrigin())); | |
| 223 | |
| 224 // This will result in a callback to | |
| 225 // PendingSignedOutTask::OnGetPasswordStoreResults(). | |
| 226 store->GetAutofillableLogins(pending_sign_out_.get()); | |
| 227 } | |
| 228 | |
| 172 web_contents()->GetRenderViewHost()->Send( | 229 web_contents()->GetRenderViewHost()->Send( |
| 173 new CredentialManagerMsg_AcknowledgeSignedOut( | 230 new CredentialManagerMsg_AcknowledgeSignedOut( |
| 174 web_contents()->GetRenderViewHost()->GetRoutingID(), request_id)); | 231 web_contents()->GetRenderViewHost()->GetRoutingID(), request_id)); |
| 175 } | 232 } |
| 176 | 233 |
| 177 void CredentialManagerDispatcher::OnRequestCredential( | 234 void CredentialManagerDispatcher::OnRequestCredential( |
| 178 int request_id, | 235 int request_id, |
| 179 bool zero_click_only, | 236 bool zero_click_only, |
| 180 const std::vector<GURL>& federations) { | 237 const std::vector<GURL>& federations) { |
| 181 DCHECK(request_id); | 238 DCHECK(request_id); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 227 DCHECK(driver_factory); | 284 DCHECK(driver_factory); |
| 228 PasswordManagerDriver* driver = | 285 PasswordManagerDriver* driver = |
| 229 driver_factory->GetDriverForFrame(web_contents()->GetMainFrame()); | 286 driver_factory->GetDriverForFrame(web_contents()->GetMainFrame()); |
| 230 return driver->AsWeakPtr(); | 287 return driver->AsWeakPtr(); |
| 231 } | 288 } |
| 232 | 289 |
| 233 void CredentialManagerDispatcher::SendCredential(int request_id, | 290 void CredentialManagerDispatcher::SendCredential(int request_id, |
| 234 const CredentialInfo& info) { | 291 const CredentialInfo& info) { |
| 235 DCHECK(pending_request_); | 292 DCHECK(pending_request_); |
| 236 DCHECK_EQ(pending_request_->id(), request_id); | 293 DCHECK_EQ(pending_request_->id(), request_id); |
| 294 // TODO(mkwst): We need to update the underlying PasswordForm if the user | |
| 295 // has enabled zeroclick globally, and clicks through a non-zeroclick form | |
| 296 // for an origin. | |
| 237 web_contents()->GetRenderViewHost()->Send( | 297 web_contents()->GetRenderViewHost()->Send( |
| 238 new CredentialManagerMsg_SendCredential( | 298 new CredentialManagerMsg_SendCredential( |
| 239 web_contents()->GetRenderViewHost()->GetRoutingID(), | 299 web_contents()->GetRenderViewHost()->GetRoutingID(), |
| 240 pending_request_->id(), info)); | 300 pending_request_->id(), info)); |
| 241 pending_request_.reset(); | 301 pending_request_.reset(); |
| 242 } | 302 } |
| 243 | 303 |
| 244 } // namespace password_manager | 304 } // namespace password_manager |
| OLD | NEW |