| 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 "content/public/browser/render_view_host.h" | 20 #include "content/public/browser/render_view_host.h" |
| 20 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
| 21 #include "ipc/ipc_message_macros.h" | 22 #include "ipc/ipc_message_macros.h" |
| 22 | 23 |
| 23 namespace password_manager { | 24 namespace password_manager { |
| 24 | 25 |
| 25 struct CredentialManagerDispatcher::PendingRequestParameters { | 26 struct CredentialManagerDispatcher::PendingRequestParameters { |
| 26 PendingRequestParameters(int request_id, | 27 PendingRequestParameters(int request_id, |
| 27 bool request_zero_click_only, | 28 bool request_zero_click_only, |
| 28 GURL request_origin, | 29 GURL request_origin, |
| 29 const std::vector<GURL>& request_federations) | 30 const std::vector<GURL>& request_federations) |
| 30 : id(request_id), | 31 : id(request_id), |
| 31 zero_click_only(request_zero_click_only), | 32 zero_click_only(request_zero_click_only), |
| 32 origin(request_origin), | 33 origin(request_origin), |
| 33 federations(request_federations) {} | 34 federations(request_federations) {} |
| 34 | 35 |
| 35 int id; | 36 int id; |
| 36 bool zero_click_only; | 37 bool zero_click_only; |
| 37 GURL origin; | 38 GURL origin; |
| 38 std::vector<GURL> federations; | 39 std::vector<GURL> federations; |
| 39 }; | 40 }; |
| 40 | 41 |
| 41 CredentialManagerDispatcher::CredentialManagerDispatcher( | 42 CredentialManagerDispatcher::CredentialManagerDispatcher( |
| 42 content::WebContents* web_contents, | 43 content::WebContents* web_contents, |
| 43 PasswordManagerClient* client) | 44 PasswordManagerClient* client) |
| 44 : WebContentsObserver(web_contents), client_(client) { | 45 : WebContentsObserver(web_contents), client_(client) { |
| 45 DCHECK(web_contents); | 46 DCHECK(web_contents); |
| 47 auto_signin_enabled_.Init(prefs::kPasswordManagerAutoSignin, |
| 48 client_->GetPrefs()); |
| 46 } | 49 } |
| 47 | 50 |
| 48 CredentialManagerDispatcher::~CredentialManagerDispatcher() { | 51 CredentialManagerDispatcher::~CredentialManagerDispatcher() { |
| 49 } | 52 } |
| 50 | 53 |
| 51 bool CredentialManagerDispatcher::OnMessageReceived( | 54 bool CredentialManagerDispatcher::OnMessageReceived( |
| 52 const IPC::Message& message) { | 55 const IPC::Message& message) { |
| 53 bool handled = true; | 56 bool handled = true; |
| 54 IPC_BEGIN_MESSAGE_MAP(CredentialManagerDispatcher, message) | 57 IPC_BEGIN_MESSAGE_MAP(CredentialManagerDispatcher, message) |
| 55 IPC_MESSAGE_HANDLER(CredentialManagerHostMsg_NotifyFailedSignIn, | 58 IPC_MESSAGE_HANDLER(CredentialManagerHostMsg_NotifyFailedSignIn, |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 PasswordStore* CredentialManagerDispatcher::GetPasswordStore() { | 199 PasswordStore* CredentialManagerDispatcher::GetPasswordStore() { |
| 197 return client_ ? client_->GetPasswordStore() : nullptr; | 200 return client_ ? client_->GetPasswordStore() : nullptr; |
| 198 } | 201 } |
| 199 | 202 |
| 200 bool CredentialManagerDispatcher::IsSavingEnabledForCurrentPage() const { | 203 bool CredentialManagerDispatcher::IsSavingEnabledForCurrentPage() const { |
| 201 // TODO(vasilii): add more, see http://crbug.com/450583. | 204 // TODO(vasilii): add more, see http://crbug.com/450583. |
| 202 return !client_->IsOffTheRecord(); | 205 return !client_->IsOffTheRecord(); |
| 203 } | 206 } |
| 204 | 207 |
| 205 bool CredentialManagerDispatcher::IsZeroClickAllowed() const { | 208 bool CredentialManagerDispatcher::IsZeroClickAllowed() const { |
| 206 return !client_->IsOffTheRecord() && client_->IsZeroClickEnabled(); | 209 return *auto_signin_enabled_ && !client_->IsOffTheRecord(); |
| 207 } | 210 } |
| 208 | 211 |
| 209 base::WeakPtr<PasswordManagerDriver> CredentialManagerDispatcher::GetDriver() { | 212 base::WeakPtr<PasswordManagerDriver> CredentialManagerDispatcher::GetDriver() { |
| 210 ContentPasswordManagerDriverFactory* driver_factory = | 213 ContentPasswordManagerDriverFactory* driver_factory = |
| 211 ContentPasswordManagerDriverFactory::FromWebContents(web_contents()); | 214 ContentPasswordManagerDriverFactory::FromWebContents(web_contents()); |
| 212 DCHECK(driver_factory); | 215 DCHECK(driver_factory); |
| 213 PasswordManagerDriver* driver = | 216 PasswordManagerDriver* driver = |
| 214 driver_factory->GetDriverForFrame(web_contents()->GetMainFrame()); | 217 driver_factory->GetDriverForFrame(web_contents()->GetMainFrame()); |
| 215 return driver->AsWeakPtr(); | 218 return driver->AsWeakPtr(); |
| 216 } | 219 } |
| 217 | 220 |
| 218 void CredentialManagerDispatcher::SendCredential(int request_id, | 221 void CredentialManagerDispatcher::SendCredential(int request_id, |
| 219 const CredentialInfo& info) { | 222 const CredentialInfo& info) { |
| 220 DCHECK(pending_request_); | 223 DCHECK(pending_request_); |
| 221 DCHECK_EQ(pending_request_->id, request_id); | 224 DCHECK_EQ(pending_request_->id, request_id); |
| 222 web_contents()->GetRenderViewHost()->Send( | 225 web_contents()->GetRenderViewHost()->Send( |
| 223 new CredentialManagerMsg_SendCredential( | 226 new CredentialManagerMsg_SendCredential( |
| 224 web_contents()->GetRenderViewHost()->GetRoutingID(), | 227 web_contents()->GetRenderViewHost()->GetRoutingID(), |
| 225 pending_request_->id, info)); | 228 pending_request_->id, info)); |
| 226 pending_request_.reset(); | 229 pending_request_.reset(); |
| 227 } | 230 } |
| 228 | 231 |
| 229 } // namespace password_manager | 232 } // namespace password_manager |
| OLD | NEW |