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/content_credential_manager
_dispatcher.h" | 5 #include "components/password_manager/content/browser/content_credential_manager
_dispatcher.h" |
6 | 6 |
7 #include "base/strings/string16.h" | 7 #include "base/strings/string16.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "components/autofill/core/common/password_form.h" | 9 #include "components/autofill/core/common/password_form.h" |
10 #include "components/password_manager/content/common/credential_manager_messages
.h" | 10 #include "components/password_manager/content/common/credential_manager_messages
.h" |
11 #include "components/password_manager/content/common/credential_manager_types.h" | 11 #include "components/password_manager/content/common/credential_manager_types.h" |
12 #include "components/password_manager/core/browser/password_manager_client.h" | 12 #include "components/password_manager/core/browser/password_manager_client.h" |
| 13 #include "components/password_manager/core/browser/password_store.h" |
13 #include "content/public/browser/render_view_host.h" | 14 #include "content/public/browser/render_view_host.h" |
14 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
15 #include "ipc/ipc_message_macros.h" | 16 #include "ipc/ipc_message_macros.h" |
16 | 17 |
17 namespace password_manager { | 18 namespace password_manager { |
18 | 19 |
19 ContentCredentialManagerDispatcher::ContentCredentialManagerDispatcher( | 20 ContentCredentialManagerDispatcher::ContentCredentialManagerDispatcher( |
20 content::WebContents* web_contents, | 21 content::WebContents* web_contents, |
21 PasswordManagerClient* client) | 22 PasswordManagerClient* client) |
22 : WebContentsObserver(web_contents), | 23 : WebContentsObserver(web_contents), |
23 client_(client) { | 24 client_(client), |
| 25 pending_request_id_(0) { |
24 DCHECK(web_contents); | 26 DCHECK(web_contents); |
25 } | 27 } |
26 | 28 |
27 ContentCredentialManagerDispatcher::~ContentCredentialManagerDispatcher() {} | 29 ContentCredentialManagerDispatcher::~ContentCredentialManagerDispatcher() {} |
28 | 30 |
29 bool ContentCredentialManagerDispatcher::OnMessageReceived( | 31 bool ContentCredentialManagerDispatcher::OnMessageReceived( |
30 const IPC::Message& message) { | 32 const IPC::Message& message) { |
31 bool handled = true; | 33 bool handled = true; |
32 IPC_BEGIN_MESSAGE_MAP(ContentCredentialManagerDispatcher, message) | 34 IPC_BEGIN_MESSAGE_MAP(ContentCredentialManagerDispatcher, message) |
33 IPC_MESSAGE_HANDLER(CredentialManagerHostMsg_NotifyFailedSignIn, | 35 IPC_MESSAGE_HANDLER(CredentialManagerHostMsg_NotifyFailedSignIn, |
(...skipping 29 matching lines...) Expand all Loading... |
63 | 65 |
64 void ContentCredentialManagerDispatcher::OnNotifySignedOut(int request_id) { | 66 void ContentCredentialManagerDispatcher::OnNotifySignedOut(int request_id) { |
65 // TODO(mkwst): This is a stub. | 67 // TODO(mkwst): This is a stub. |
66 web_contents()->GetRenderViewHost()->Send( | 68 web_contents()->GetRenderViewHost()->Send( |
67 new CredentialManagerMsg_AcknowledgeSignedOut( | 69 new CredentialManagerMsg_AcknowledgeSignedOut( |
68 web_contents()->GetRenderViewHost()->GetRoutingID(), request_id)); | 70 web_contents()->GetRenderViewHost()->GetRoutingID(), request_id)); |
69 } | 71 } |
70 | 72 |
71 void ContentCredentialManagerDispatcher::OnRequestCredential( | 73 void ContentCredentialManagerDispatcher::OnRequestCredential( |
72 int request_id, | 74 int request_id, |
73 bool zero_click_only, | 75 bool /* zero_click_only */, |
74 const std::vector<GURL>& federations) { | 76 const std::vector<GURL>& federations) { |
75 // TODO(mkwst): This is a stub. | 77 DCHECK(request_id); |
| 78 PasswordStore* store = GetPasswordStore(); |
| 79 if (pending_request_id_ || !store) { |
| 80 // TODO(mkwst): Reject the promise if we can't get to the password store, or |
| 81 // if we're already requesting credentials. |
| 82 } |
| 83 |
| 84 pending_request_id_ = request_id; |
| 85 |
| 86 autofill::PasswordForm form; |
| 87 form.scheme = autofill::PasswordForm::SCHEME_HTML; |
| 88 form.origin = web_contents()->GetLastCommittedURL().GetOrigin(); |
| 89 form.signon_realm = form.origin.spec(); |
| 90 |
| 91 store->GetLogins(form, PasswordStore::DISALLOW_PROMPT, this); |
| 92 } |
| 93 |
| 94 void ContentCredentialManagerDispatcher::OnGetPasswordStoreResults( |
| 95 const std::vector<autofill::PasswordForm*>& results) { |
| 96 DCHECK(pending_request_id_); |
| 97 |
| 98 // TODO(mkwst): This is a stub. We should be looking at |results| here. Baby |
| 99 // steps. |
76 password_manager::CredentialInfo info(base::ASCIIToUTF16("id"), | 100 password_manager::CredentialInfo info(base::ASCIIToUTF16("id"), |
77 base::ASCIIToUTF16("name"), | 101 base::ASCIIToUTF16("name"), |
78 GURL("https://example.com/image.png")); | 102 GURL("https://example.com/image.png")); |
79 web_contents()->GetRenderViewHost()->Send( | 103 web_contents()->GetRenderViewHost()->Send( |
80 new CredentialManagerMsg_SendCredential( | 104 new CredentialManagerMsg_SendCredential( |
81 web_contents()->GetRenderViewHost()->GetRoutingID(), | 105 web_contents()->GetRenderViewHost()->GetRoutingID(), |
82 request_id, | 106 pending_request_id_, |
83 info)); | 107 info)); |
| 108 pending_request_id_ = 0; |
| 109 } |
| 110 |
| 111 PasswordStore* ContentCredentialManagerDispatcher::GetPasswordStore() { |
| 112 return client_ ? client_->GetPasswordStore() : nullptr; |
84 } | 113 } |
85 | 114 |
86 } // namespace password_manager | 115 } // namespace password_manager |
OLD | NEW |