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) { |
vabr (Chromium)
2014/09/30 09:38:31
pending_request_id_(0)
Mike West
2014/09/30 09:44:49
Done.
| |
24 DCHECK(web_contents); | 25 DCHECK(web_contents); |
25 } | 26 } |
26 | 27 |
27 ContentCredentialManagerDispatcher::~ContentCredentialManagerDispatcher() {} | 28 ContentCredentialManagerDispatcher::~ContentCredentialManagerDispatcher() {} |
28 | 29 |
29 bool ContentCredentialManagerDispatcher::OnMessageReceived( | 30 bool ContentCredentialManagerDispatcher::OnMessageReceived( |
30 const IPC::Message& message) { | 31 const IPC::Message& message) { |
31 bool handled = true; | 32 bool handled = true; |
32 IPC_BEGIN_MESSAGE_MAP(ContentCredentialManagerDispatcher, message) | 33 IPC_BEGIN_MESSAGE_MAP(ContentCredentialManagerDispatcher, message) |
33 IPC_MESSAGE_HANDLER(CredentialManagerHostMsg_NotifyFailedSignIn, | 34 IPC_MESSAGE_HANDLER(CredentialManagerHostMsg_NotifyFailedSignIn, |
(...skipping 28 matching lines...) Expand all Loading... | |
62 } | 63 } |
63 | 64 |
64 void ContentCredentialManagerDispatcher::OnNotifySignedOut(int request_id) { | 65 void ContentCredentialManagerDispatcher::OnNotifySignedOut(int request_id) { |
65 // TODO(mkwst): This is a stub. | 66 // TODO(mkwst): This is a stub. |
66 web_contents()->GetRenderViewHost()->Send( | 67 web_contents()->GetRenderViewHost()->Send( |
67 new CredentialManagerMsg_AcknowledgeSignedOut( | 68 new CredentialManagerMsg_AcknowledgeSignedOut( |
68 web_contents()->GetRenderViewHost()->GetRoutingID(), request_id)); | 69 web_contents()->GetRenderViewHost()->GetRoutingID(), request_id)); |
69 } | 70 } |
70 | 71 |
71 void ContentCredentialManagerDispatcher::OnRequestCredential( | 72 void ContentCredentialManagerDispatcher::OnRequestCredential( |
72 int request_id, | 73 int request_id, |
vabr (Chromium)
2014/09/30 09:38:31
Should you DCHECK(request_id)?
Mike West
2014/09/30 09:44:49
Hrm. That's actually a good question. I don't know
| |
73 bool zero_click_only, | 74 bool /* zero_click_only */, |
74 const std::vector<GURL>& federations) { | 75 const std::vector<GURL>& federations) { |
75 // TODO(mkwst): This is a stub. | 76 PasswordStore* store = GetPasswordStore(); |
77 if (pending_request_id_ || !store) { | |
78 // TODO(mkwst): Reject the promise if we can't get to the password store, or | |
79 // if we're already requesting credentials. | |
vabr (Chromium)
2014/09/30 09:38:32
Did you want to add a return here?
(Maybe to avoid
Mike West
2014/09/30 09:44:49
I should have done it here, but I'm now doing it i
| |
80 } | |
81 | |
82 pending_request_id_ = request_id; | |
83 | |
84 autofill::PasswordForm form; | |
85 form.scheme = autofill::PasswordForm::SCHEME_HTML; | |
86 form.origin = web_contents()->GetLastCommittedURL().GetOrigin(); | |
87 form.signon_realm = form.origin.spec(); | |
88 | |
89 store->GetLogins(form, PasswordStore::DISALLOW_PROMPT, this); | |
90 } | |
91 | |
92 void ContentCredentialManagerDispatcher::OnGetPasswordStoreResults( | |
93 const std::vector<autofill::PasswordForm*>& results) { | |
94 DCHECK(pending_request_id_); | |
95 | |
96 // TODO(mkwst): This is a stub. We should be looking at |results| here. Baby | |
97 // steps. | |
76 password_manager::CredentialInfo info(base::ASCIIToUTF16("id"), | 98 password_manager::CredentialInfo info(base::ASCIIToUTF16("id"), |
77 base::ASCIIToUTF16("name"), | 99 base::ASCIIToUTF16("name"), |
78 GURL("https://example.com/image.png")); | 100 GURL("https://example.com/image.png")); |
79 web_contents()->GetRenderViewHost()->Send( | 101 web_contents()->GetRenderViewHost()->Send( |
80 new CredentialManagerMsg_SendCredential( | 102 new CredentialManagerMsg_SendCredential( |
81 web_contents()->GetRenderViewHost()->GetRoutingID(), | 103 web_contents()->GetRenderViewHost()->GetRoutingID(), |
82 request_id, | 104 pending_request_id_, |
83 info)); | 105 info)); |
106 pending_request_id_ = 0; | |
107 } | |
108 | |
109 PasswordStore* ContentCredentialManagerDispatcher::GetPasswordStore() { | |
110 return client_ ? client_->GetPasswordStore() : nullptr; | |
84 } | 111 } |
85 | 112 |
86 } // namespace password_manager | 113 } // namespace password_manager |
OLD | NEW |