Make |track_| in MediaStreamTrack const. and a couple of other cosmetic changes.
[chromium-blink-merge.git] / components / password_manager / content / browser / content_credential_manager_dispatcher.cc
blobfc498d707ce9e06f57bc4d240d92192006f003fa
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
3 // found in the LICENSE file.
5 #include "components/password_manager/content/browser/content_credential_manager_dispatcher.h"
7 #include "base/strings/string16.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "components/autofill/core/common/password_form.h"
10 #include "components/password_manager/content/browser/credential_manager_password_form_manager.h"
11 #include "components/password_manager/content/common/credential_manager_messages.h"
12 #include "components/password_manager/content/common/credential_manager_types.h"
13 #include "components/password_manager/core/browser/password_manager_client.h"
14 #include "components/password_manager/core/browser/password_store.h"
15 #include "content/public/browser/render_view_host.h"
16 #include "content/public/browser/web_contents.h"
17 #include "ipc/ipc_message_macros.h"
19 namespace password_manager {
21 ContentCredentialManagerDispatcher::ContentCredentialManagerDispatcher(
22 content::WebContents* web_contents,
23 PasswordManagerClient* client)
24 : WebContentsObserver(web_contents),
25 client_(client),
26 pending_request_id_(0) {
27 DCHECK(web_contents);
30 ContentCredentialManagerDispatcher::~ContentCredentialManagerDispatcher() {}
32 bool ContentCredentialManagerDispatcher::OnMessageReceived(
33 const IPC::Message& message) {
34 bool handled = true;
35 IPC_BEGIN_MESSAGE_MAP(ContentCredentialManagerDispatcher, message)
36 IPC_MESSAGE_HANDLER(CredentialManagerHostMsg_NotifyFailedSignIn,
37 OnNotifyFailedSignIn);
38 IPC_MESSAGE_HANDLER(CredentialManagerHostMsg_NotifySignedIn,
39 OnNotifySignedIn);
40 IPC_MESSAGE_HANDLER(CredentialManagerHostMsg_NotifySignedOut,
41 OnNotifySignedOut);
42 IPC_MESSAGE_HANDLER(CredentialManagerHostMsg_RequestCredential,
43 OnRequestCredential);
44 IPC_MESSAGE_UNHANDLED(handled = false)
45 IPC_END_MESSAGE_MAP()
46 return handled;
49 void ContentCredentialManagerDispatcher::OnNotifyFailedSignIn(
50 int request_id, const CredentialInfo&) {
51 DCHECK(request_id);
52 // TODO(mkwst): This is a stub.
53 web_contents()->GetRenderViewHost()->Send(
54 new CredentialManagerMsg_AcknowledgeFailedSignIn(
55 web_contents()->GetRenderViewHost()->GetRoutingID(), request_id));
58 void ContentCredentialManagerDispatcher::OnNotifySignedIn(
59 int request_id,
60 const password_manager::CredentialInfo& credential) {
61 DCHECK(request_id);
62 scoped_ptr<autofill::PasswordForm> form(
63 CreatePasswordFormFromCredentialInfo(credential,
64 web_contents()->GetLastCommittedURL().GetOrigin()));
66 // TODO(mkwst): This is a stub; we should be checking the PasswordStore to
67 // determine whether or not the credential exists, and calling UpdateLogin
68 // accordingly.
69 form_manager_.reset(
70 new CredentialManagerPasswordFormManager(client_, *form, this));
72 web_contents()->GetRenderViewHost()->Send(
73 new CredentialManagerMsg_AcknowledgeSignedIn(
74 web_contents()->GetRenderViewHost()->GetRoutingID(), request_id));
77 void ContentCredentialManagerDispatcher::OnProvisionalSaveComplete() {
78 DCHECK(form_manager_);
79 client_->PromptUserToSavePassword(form_manager_.Pass());
82 void ContentCredentialManagerDispatcher::OnNotifySignedOut(int request_id) {
83 DCHECK(request_id);
84 // TODO(mkwst): This is a stub.
85 web_contents()->GetRenderViewHost()->Send(
86 new CredentialManagerMsg_AcknowledgeSignedOut(
87 web_contents()->GetRenderViewHost()->GetRoutingID(), request_id));
90 void ContentCredentialManagerDispatcher::OnRequestCredential(
91 int request_id,
92 bool /* zero_click_only */,
93 const std::vector<GURL>& federations) {
94 DCHECK(request_id);
95 PasswordStore* store = GetPasswordStore();
96 if (pending_request_id_ || !store) {
97 web_contents()->GetRenderViewHost()->Send(
98 new CredentialManagerMsg_RejectCredentialRequest(
99 web_contents()->GetRenderViewHost()->GetRoutingID(),
100 request_id,
101 pending_request_id_
102 ? blink::WebCredentialManagerError::ErrorTypePendingRequest
103 : blink::WebCredentialManagerError::
104 ErrorTypePasswordStoreUnavailable));
105 return;
108 pending_request_id_ = request_id;
110 autofill::PasswordForm form;
111 form.scheme = autofill::PasswordForm::SCHEME_HTML;
112 form.origin = web_contents()->GetLastCommittedURL().GetOrigin();
113 form.signon_realm = form.origin.spec();
115 store->GetLogins(form, PasswordStore::DISALLOW_PROMPT, this);
118 void ContentCredentialManagerDispatcher::OnGetPasswordStoreResults(
119 const std::vector<autofill::PasswordForm*>& results) {
120 DCHECK(pending_request_id_);
122 // Take ownership of all the password form objects in the |results| vector.
123 ScopedVector<autofill::PasswordForm> entries;
124 entries.assign(results.begin(), results.end());
126 // TODO(mkwst): This is a stub. We're just grabbing the first result and
127 // piping it down into Blink. Really, we should be kicking off some sort
128 // of UI full of magic moments and delight. Also, we should deal with
129 // federated login types.
130 CredentialInfo info = results.empty() ? CredentialInfo()
131 : CredentialInfo(*entries[0]);
132 web_contents()->GetRenderViewHost()->Send(
133 new CredentialManagerMsg_SendCredential(
134 web_contents()->GetRenderViewHost()->GetRoutingID(),
135 pending_request_id_,
136 info));
137 pending_request_id_ = 0;
140 PasswordStore* ContentCredentialManagerDispatcher::GetPasswordStore() {
141 return client_ ? client_->GetPasswordStore() : nullptr;
144 } // namespace password_manager