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_password_manager_driver.h"
7 #include "components/autofill/content/browser/content_autofill_driver.h"
8 #include "components/autofill/content/common/autofill_messages.h"
9 #include "components/autofill/core/common/form_data.h"
10 #include "components/autofill/core/common/password_form.h"
11 #include "components/password_manager/core/browser/password_manager_client.h"
12 #include "content/public/browser/browser_context.h"
13 #include "content/public/browser/navigation_details.h"
14 #include "content/public/browser/navigation_entry.h"
15 #include "content/public/browser/render_view_host.h"
16 #include "content/public/browser/web_contents.h"
17 #include "content/public/common/ssl_status.h"
18 #include "ipc/ipc_message_macros.h"
19 #include "net/cert/cert_status_flags.h"
21 namespace password_manager
{
23 ContentPasswordManagerDriver::ContentPasswordManagerDriver(
24 content::WebContents
* web_contents
,
25 PasswordManagerClient
* client
,
26 autofill::AutofillClient
* autofill_client
)
27 : WebContentsObserver(web_contents
),
28 password_manager_(client
),
29 password_generation_manager_(client
),
30 password_autofill_manager_(client
, autofill_client
) {
34 ContentPasswordManagerDriver::~ContentPasswordManagerDriver() {}
36 void ContentPasswordManagerDriver::FillPasswordForm(
37 const autofill::PasswordFormFillData
& form_data
) {
38 DCHECK(web_contents());
39 web_contents()->GetRenderViewHost()->Send(new AutofillMsg_FillPasswordForm(
40 web_contents()->GetRenderViewHost()->GetRoutingID(), form_data
));
43 void ContentPasswordManagerDriver::AllowPasswordGenerationForForm(
44 const autofill::PasswordForm
& form
) {
45 content::RenderViewHost
* host
= web_contents()->GetRenderViewHost();
46 host
->Send(new AutofillMsg_FormNotBlacklisted(host
->GetRoutingID(), form
));
49 void ContentPasswordManagerDriver::AccountCreationFormsFound(
50 const std::vector
<autofill::FormData
>& forms
) {
51 content::RenderViewHost
* host
= web_contents()->GetRenderViewHost();
52 host
->Send(new AutofillMsg_AccountCreationFormsDetected(host
->GetRoutingID(),
56 void ContentPasswordManagerDriver::FillSuggestion(
57 const base::string16
& username
,
58 const base::string16
& password
) {
59 content::RenderViewHost
* host
= web_contents()->GetRenderViewHost();
61 new AutofillMsg_FillPasswordSuggestion(host
->GetRoutingID(),
66 void ContentPasswordManagerDriver::PreviewSuggestion(
67 const base::string16
& username
,
68 const base::string16
& password
) {
69 content::RenderViewHost
* host
= web_contents()->GetRenderViewHost();
71 new AutofillMsg_PreviewPasswordSuggestion(host
->GetRoutingID(),
76 void ContentPasswordManagerDriver::ClearPreviewedForm() {
77 content::RenderViewHost
* host
= web_contents()->GetRenderViewHost();
79 new AutofillMsg_ClearPreviewedForm(host
->GetRoutingID()));
82 bool ContentPasswordManagerDriver::DidLastPageLoadEncounterSSLErrors() {
83 DCHECK(web_contents());
84 // TODO(vabr): This is a wrong entry to look at for HTTP basic auth,
85 // http://crbug.com/388246.
86 content::NavigationEntry
* entry
=
87 web_contents()->GetController().GetLastCommittedEntry();
92 return net::IsCertStatusError(entry
->GetSSL().cert_status
);
95 bool ContentPasswordManagerDriver::IsOffTheRecord() {
96 DCHECK(web_contents());
97 return web_contents()->GetBrowserContext()->IsOffTheRecord();
100 PasswordGenerationManager
*
101 ContentPasswordManagerDriver::GetPasswordGenerationManager() {
102 return &password_generation_manager_
;
105 PasswordManager
* ContentPasswordManagerDriver::GetPasswordManager() {
106 return &password_manager_
;
109 PasswordAutofillManager
*
110 ContentPasswordManagerDriver::GetPasswordAutofillManager() {
111 return &password_autofill_manager_
;
114 void ContentPasswordManagerDriver::DidNavigateMainFrame(
115 const content::LoadCommittedDetails
& details
,
116 const content::FrameNavigateParams
& params
) {
117 password_manager_
.DidNavigateMainFrame(details
.is_in_page
);
120 bool ContentPasswordManagerDriver::OnMessageReceived(
121 const IPC::Message
& message
) {
123 IPC_BEGIN_MESSAGE_MAP(PasswordManager
, message
)
124 IPC_MESSAGE_FORWARD(AutofillHostMsg_PasswordFormsParsed
,
126 PasswordManager::OnPasswordFormsParsed
)
127 IPC_MESSAGE_FORWARD(AutofillHostMsg_PasswordFormsRendered
,
129 PasswordManager::OnPasswordFormsRendered
)
130 IPC_MESSAGE_FORWARD(AutofillHostMsg_PasswordFormSubmitted
,
132 PasswordManager::OnPasswordFormSubmitted
)
133 IPC_MESSAGE_FORWARD(AutofillHostMsg_ShowPasswordSuggestions
,
134 &password_autofill_manager_
,
135 PasswordAutofillManager::OnShowPasswordSuggestions
)
136 IPC_MESSAGE_FORWARD(AutofillHostMsg_AddPasswordFormMapping
,
137 &password_autofill_manager_
,
138 PasswordAutofillManager::OnAddPasswordFormMapping
)
139 IPC_MESSAGE_FORWARD(AutofillHostMsg_RecordSavePasswordProgress
,
140 password_manager_
.client(),
141 PasswordManagerClient::LogSavePasswordProgress
)
142 IPC_MESSAGE_UNHANDLED(handled
= false)
143 IPC_END_MESSAGE_MAP()
148 autofill::AutofillManager
* ContentPasswordManagerDriver::GetAutofillManager() {
149 autofill::ContentAutofillDriver
* driver
=
150 autofill::ContentAutofillDriver::FromWebContents(web_contents());
151 return driver
? driver
->autofill_manager() : NULL
;
154 } // namespace password_manager