Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: components/password_manager/content/browser/content_credential_manager_dispatcher.cc

Issue 802303002: Credential Manager: Switch 'request()' to GetAutofillableLogins(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/bind.h" 7 #include "base/bind.h"
8 #include "base/strings/string16.h" 8 #include "base/strings/string16.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "components/autofill/core/common/password_form.h" 10 #include "components/autofill/core/common/password_form.h"
11 #include "components/password_manager/content/browser/content_password_manager_d river.h" 11 #include "components/password_manager/content/browser/content_password_manager_d river.h"
12 #include "components/password_manager/content/browser/content_password_manager_d river_factory.h" 12 #include "components/password_manager/content/browser/content_password_manager_d river_factory.h"
13 #include "components/password_manager/content/browser/credential_manager_passwor d_form_manager.h" 13 #include "components/password_manager/content/browser/credential_manager_passwor d_form_manager.h"
14 #include "components/password_manager/content/common/credential_manager_messages .h" 14 #include "components/password_manager/content/common/credential_manager_messages .h"
15 #include "components/password_manager/content/common/credential_manager_types.h" 15 #include "components/password_manager/content/common/credential_manager_types.h"
16 #include "components/password_manager/core/browser/password_manager_client.h" 16 #include "components/password_manager/core/browser/password_manager_client.h"
17 #include "components/password_manager/core/browser/password_store.h" 17 #include "components/password_manager/core/browser/password_store.h"
18 #include "content/public/browser/render_view_host.h" 18 #include "content/public/browser/render_view_host.h"
19 #include "content/public/browser/web_contents.h" 19 #include "content/public/browser/web_contents.h"
20 #include "ipc/ipc_message_macros.h" 20 #include "ipc/ipc_message_macros.h"
21 21
22 namespace password_manager { 22 namespace password_manager {
23 23
24 struct ContentCredentialManagerDispatcher::PendingRequestParameters {
25 PendingRequestParameters(int request_id,
26 bool request_zero_click_only,
27 GURL request_origin,
28 const std::vector<GURL>& request_federations)
29 : id(request_id),
30 zero_click_only(request_zero_click_only),
31 origin(request_origin),
32 federations(request_federations) {}
33
34 int id;
35 bool zero_click_only;
36 GURL origin;
37 std::vector<GURL> federations;
38 };
39
24 ContentCredentialManagerDispatcher::ContentCredentialManagerDispatcher( 40 ContentCredentialManagerDispatcher::ContentCredentialManagerDispatcher(
25 content::WebContents* web_contents, 41 content::WebContents* web_contents,
26 PasswordManagerClient* client) 42 PasswordManagerClient* client)
27 : WebContentsObserver(web_contents), 43 : WebContentsObserver(web_contents), client_(client) {
28 client_(client),
29 pending_request_id_(0) {
30 DCHECK(web_contents); 44 DCHECK(web_contents);
31 } 45 }
32 46
33 ContentCredentialManagerDispatcher::~ContentCredentialManagerDispatcher() {} 47 ContentCredentialManagerDispatcher::~ContentCredentialManagerDispatcher() {}
34 48
35 bool ContentCredentialManagerDispatcher::OnMessageReceived( 49 bool ContentCredentialManagerDispatcher::OnMessageReceived(
36 const IPC::Message& message) { 50 const IPC::Message& message) {
37 bool handled = true; 51 bool handled = true;
38 IPC_BEGIN_MESSAGE_MAP(ContentCredentialManagerDispatcher, message) 52 IPC_BEGIN_MESSAGE_MAP(ContentCredentialManagerDispatcher, message)
39 IPC_MESSAGE_HANDLER(CredentialManagerHostMsg_NotifyFailedSignIn, 53 IPC_MESSAGE_HANDLER(CredentialManagerHostMsg_NotifyFailedSignIn,
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 void ContentCredentialManagerDispatcher::OnNotifySignedOut(int request_id) { 100 void ContentCredentialManagerDispatcher::OnNotifySignedOut(int request_id) {
87 DCHECK(request_id); 101 DCHECK(request_id);
88 // TODO(mkwst): This is a stub. 102 // TODO(mkwst): This is a stub.
89 web_contents()->GetRenderViewHost()->Send( 103 web_contents()->GetRenderViewHost()->Send(
90 new CredentialManagerMsg_AcknowledgeSignedOut( 104 new CredentialManagerMsg_AcknowledgeSignedOut(
91 web_contents()->GetRenderViewHost()->GetRoutingID(), request_id)); 105 web_contents()->GetRenderViewHost()->GetRoutingID(), request_id));
92 } 106 }
93 107
94 void ContentCredentialManagerDispatcher::OnRequestCredential( 108 void ContentCredentialManagerDispatcher::OnRequestCredential(
95 int request_id, 109 int request_id,
96 bool /* zero_click_only */, 110 bool zero_click_only,
97 const std::vector<GURL>& /* federations */) { 111 const std::vector<GURL>& federations) {
98 DCHECK(request_id); 112 DCHECK(request_id);
99 PasswordStore* store = GetPasswordStore(); 113 PasswordStore* store = GetPasswordStore();
100 if (pending_request_id_ || !store) { 114 if (pending_request_ || !store) {
101 web_contents()->GetRenderViewHost()->Send( 115 web_contents()->GetRenderViewHost()->Send(
102 new CredentialManagerMsg_RejectCredentialRequest( 116 new CredentialManagerMsg_RejectCredentialRequest(
103 web_contents()->GetRenderViewHost()->GetRoutingID(), 117 web_contents()->GetRenderViewHost()->GetRoutingID(), request_id,
104 request_id, 118 pending_request_
105 pending_request_id_
106 ? blink::WebCredentialManagerError::ErrorTypePendingRequest 119 ? blink::WebCredentialManagerError::ErrorTypePendingRequest
107 : blink::WebCredentialManagerError:: 120 : blink::WebCredentialManagerError::
108 ErrorTypePasswordStoreUnavailable)); 121 ErrorTypePasswordStoreUnavailable));
109 return; 122 return;
110 } 123 }
111 124
112 pending_request_id_ = request_id; 125 pending_request_.reset(new PendingRequestParameters(
126 request_id, zero_click_only,
127 web_contents()->GetLastCommittedURL().GetOrigin(), federations));
113 128
114 // TODO(mkwst): we should deal with federated login types. 129 store->GetAutofillableLogins(this);
115 autofill::PasswordForm form;
116 form.scheme = autofill::PasswordForm::SCHEME_HTML;
117 form.origin = web_contents()->GetLastCommittedURL().GetOrigin();
118 form.signon_realm = form.origin.spec();
119
120 store->GetLogins(form, PasswordStore::DISALLOW_PROMPT, this);
121 } 130 }
122 131
123 void ContentCredentialManagerDispatcher::OnGetPasswordStoreResults( 132 void ContentCredentialManagerDispatcher::OnGetPasswordStoreResults(
124 const std::vector<autofill::PasswordForm*>& results) { 133 const std::vector<autofill::PasswordForm*>& results) {
125 DCHECK(pending_request_id_); 134 DCHECK(pending_request_);
126 135
127 if (results.empty() || 136 std::vector<autofill::PasswordForm*> filtered_results;
128 !client_->PromptUserToChooseCredentials(results, base::Bind( 137 for (autofill::PasswordForm* form : results) {
129 &ContentCredentialManagerDispatcher::SendCredential, 138 // TODO(mkwst): Extend this filter to include federations.
130 base::Unretained(this), 139 if (form->origin == pending_request_->origin)
131 pending_request_id_))) { 140 filtered_results.push_back(form);
132 SendCredential(pending_request_id_, CredentialInfo()); 141 }
142
143 if (filtered_results.empty() ||
vabr (Chromium) 2014/12/15 10:47:22 An optional "BTW" nit: It is important that in thi
Mike West 2014/12/15 12:59:24 I'll take a look at that in the next CL when I pok
144 web_contents()->GetLastCommittedURL().GetOrigin() !=
145 pending_request_->origin ||
146 !client_->PromptUserToChooseCredentials(
147 filtered_results,
148 base::Bind(&ContentCredentialManagerDispatcher::SendCredential,
149 base::Unretained(this), pending_request_->id))) {
150 SendCredential(pending_request_->id, CredentialInfo());
133 } 151 }
134 } 152 }
135 153
136 PasswordStore* ContentCredentialManagerDispatcher::GetPasswordStore() { 154 PasswordStore* ContentCredentialManagerDispatcher::GetPasswordStore() {
137 return client_ ? client_->GetPasswordStore() : nullptr; 155 return client_ ? client_->GetPasswordStore() : nullptr;
138 } 156 }
139 157
140 base::WeakPtr<PasswordManagerDriver> 158 base::WeakPtr<PasswordManagerDriver>
141 ContentCredentialManagerDispatcher::GetDriver() { 159 ContentCredentialManagerDispatcher::GetDriver() {
142 ContentPasswordManagerDriverFactory* driver_factory = 160 ContentPasswordManagerDriverFactory* driver_factory =
143 ContentPasswordManagerDriverFactory::FromWebContents(web_contents()); 161 ContentPasswordManagerDriverFactory::FromWebContents(web_contents());
144 DCHECK(driver_factory); 162 DCHECK(driver_factory);
145 PasswordManagerDriver* driver = 163 PasswordManagerDriver* driver =
146 driver_factory->GetDriverForFrame(web_contents()->GetMainFrame()); 164 driver_factory->GetDriverForFrame(web_contents()->GetMainFrame());
147 return driver->AsWeakPtr(); 165 return driver->AsWeakPtr();
148 } 166 }
149 167
150 void ContentCredentialManagerDispatcher::SendCredential( 168 void ContentCredentialManagerDispatcher::SendCredential(
151 int request_id, const CredentialInfo& info) { 169 int request_id, const CredentialInfo& info) {
152 DCHECK(pending_request_id_); 170 DCHECK(pending_request_);
153 DCHECK_EQ(pending_request_id_, request_id); 171 DCHECK_EQ(pending_request_->id, request_id);
154 web_contents()->GetRenderViewHost()->Send( 172 web_contents()->GetRenderViewHost()->Send(
155 new CredentialManagerMsg_SendCredential( 173 new CredentialManagerMsg_SendCredential(
156 web_contents()->GetRenderViewHost()->GetRoutingID(), 174 web_contents()->GetRenderViewHost()->GetRoutingID(),
157 pending_request_id_, 175 pending_request_->id, info));
158 info)); 176 pending_request_.reset();
159 pending_request_id_ = 0;
160 } 177 }
161 178
162 } // namespace password_manager 179 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698