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 "chrome/browser/password_manager/content_password_manager_driver.h"
7 #include "components/autofill/content/browser/autofill_driver_impl.h"
8 #include "components/autofill/content/common/autofill_messages.h"
9 #include "components/autofill/core/common/password_form.h"
10 #include "content/public/browser/browser_context.h"
11 #include "content/public/browser/navigation_details.h"
12 #include "content/public/browser/navigation_entry.h"
13 #include "content/public/browser/render_view_host.h"
14 #include "content/public/browser/web_contents.h"
15 #include "content/public/common/page_transition_types.h"
16 #include "content/public/common/ssl_status.h"
17 #include "ipc/ipc_message_macros.h"
18 #include "net/cert/cert_status_flags.h"
20 ContentPasswordManagerDriver::ContentPasswordManagerDriver(
21 content::WebContents
* web_contents
,
22 PasswordManagerClient
* client
)
23 : WebContentsObserver(web_contents
),
24 password_manager_(client
),
25 password_generation_manager_(web_contents
, client
) {
29 ContentPasswordManagerDriver::~ContentPasswordManagerDriver() {}
31 void ContentPasswordManagerDriver::FillPasswordForm(
32 const autofill::PasswordFormFillData
& form_data
) {
33 DCHECK(web_contents());
34 web_contents()->GetRenderViewHost()->Send(new AutofillMsg_FillPasswordForm(
35 web_contents()->GetRenderViewHost()->GetRoutingID(), form_data
));
38 bool ContentPasswordManagerDriver::DidLastPageLoadEncounterSSLErrors() {
39 DCHECK(web_contents());
40 content::NavigationEntry
* entry
=
41 web_contents()->GetController().GetActiveEntry();
47 return net::IsCertStatusError(entry
->GetSSL().cert_status
);
50 bool ContentPasswordManagerDriver::IsOffTheRecord() {
51 DCHECK(web_contents());
52 return web_contents()->GetBrowserContext()->IsOffTheRecord();
55 PasswordGenerationManager
*
56 ContentPasswordManagerDriver::GetPasswordGenerationManager() {
57 return &password_generation_manager_
;
60 PasswordManager
* ContentPasswordManagerDriver::GetPasswordManager() {
61 return &password_manager_
;
64 void ContentPasswordManagerDriver::DidNavigateMainFrame(
65 const content::LoadCommittedDetails
& details
,
66 const content::FrameNavigateParams
& params
) {
67 password_manager_
.DidNavigateMainFrame(details
.is_in_page
);
70 bool ContentPasswordManagerDriver::OnMessageReceived(
71 const IPC::Message
& message
) {
73 IPC_BEGIN_MESSAGE_MAP(PasswordManager
, message
)
74 IPC_MESSAGE_FORWARD(AutofillHostMsg_PasswordFormsParsed
,
76 PasswordManager::OnPasswordFormsParsed
)
77 IPC_MESSAGE_FORWARD(AutofillHostMsg_PasswordFormsRendered
,
79 PasswordManager::OnPasswordFormsRendered
)
80 IPC_MESSAGE_FORWARD(AutofillHostMsg_PasswordFormSubmitted
,
82 PasswordManager::OnPasswordFormSubmitted
)
83 IPC_MESSAGE_FORWARD(AutofillHostMsg_ShowPasswordGenerationPopup
,
84 &password_generation_manager_
,
85 PasswordGenerationManager::OnShowPasswordGenerationPopup
)
86 IPC_MESSAGE_FORWARD(AutofillHostMsg_ShowPasswordEditingPopup
,
87 &password_generation_manager_
,
88 PasswordGenerationManager::OnShowPasswordEditingPopup
)
89 IPC_MESSAGE_FORWARD(AutofillHostMsg_HidePasswordGenerationPopup
,
90 &password_generation_manager_
,
91 PasswordGenerationManager::OnHidePasswordGenerationPopup
)
92 IPC_MESSAGE_UNHANDLED(handled
= false)
98 autofill::AutofillManager
* ContentPasswordManagerDriver::GetAutofillManager() {
99 autofill::AutofillDriverImpl
* driver
=
100 autofill::AutofillDriverImpl::FromWebContents(web_contents());
101 return driver
? driver
->autofill_manager() : NULL
;
104 void ContentPasswordManagerDriver::AllowPasswordGenerationForForm(
105 autofill::PasswordForm
* form
) {
106 content::RenderViewHost
* host
= web_contents()->GetRenderViewHost();
107 host
->Send(new AutofillMsg_FormNotBlacklisted(host
->GetRoutingID(), *form
));