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/page_transition_types.h"
18 #include "content/public/common/ssl_status.h"
19 #include "ipc/ipc_message_macros.h"
20 #include "net/cert/cert_status_flags.h"
22 namespace password_manager {
24 ContentPasswordManagerDriver::ContentPasswordManagerDriver(
25 content::WebContents* web_contents,
26 PasswordManagerClient* client,
27 autofill::AutofillManagerDelegate* autofill_manager_delegate)
28 : WebContentsObserver(web_contents),
29 password_manager_(client),
30 password_generation_manager_(client),
31 password_autofill_manager_(client, autofill_manager_delegate) {
35 ContentPasswordManagerDriver::~ContentPasswordManagerDriver() {}
37 void ContentPasswordManagerDriver::FillPasswordForm(
38 const autofill::PasswordFormFillData& form_data) {
39 DCHECK(web_contents());
40 web_contents()->GetRenderViewHost()->Send(new AutofillMsg_FillPasswordForm(
41 web_contents()->GetRenderViewHost()->GetRoutingID(), form_data));
44 void ContentPasswordManagerDriver::AllowPasswordGenerationForForm(
45 autofill::PasswordForm* form) {
46 content::RenderViewHost* host = web_contents()->GetRenderViewHost();
47 host->Send(new AutofillMsg_FormNotBlacklisted(host->GetRoutingID(), *form));
50 void ContentPasswordManagerDriver::AccountCreationFormsFound(
51 const std::vector<autofill::FormData>& forms) {
52 content::RenderViewHost* host = web_contents()->GetRenderViewHost();
53 host->Send(new AutofillMsg_AccountCreationFormsDetected(host->GetRoutingID(),
57 void ContentPasswordManagerDriver::AcceptPasswordAutofillSuggestion(
58 const base::string16& username,
59 const base::string16& password) {
60 content::RenderViewHost* host = web_contents()->GetRenderViewHost();
62 new AutofillMsg_AcceptPasswordAutofillSuggestion(host->GetRoutingID(),
67 bool ContentPasswordManagerDriver::DidLastPageLoadEncounterSSLErrors() {
68 DCHECK(web_contents());
69 content::NavigationEntry* entry =
70 web_contents()->GetController().GetLastCommittedEntry();
76 return net::IsCertStatusError(entry->GetSSL().cert_status);
79 bool ContentPasswordManagerDriver::IsOffTheRecord() {
80 DCHECK(web_contents());
81 return web_contents()->GetBrowserContext()->IsOffTheRecord();
84 PasswordGenerationManager*
85 ContentPasswordManagerDriver::GetPasswordGenerationManager() {
86 return &password_generation_manager_;
89 PasswordManager* ContentPasswordManagerDriver::GetPasswordManager() {
90 return &password_manager_;
93 PasswordAutofillManager*
94 ContentPasswordManagerDriver::GetPasswordAutofillManager() {
95 return &password_autofill_manager_;
98 void ContentPasswordManagerDriver::DidNavigateMainFrame(
99 const content::LoadCommittedDetails& details,
100 const content::FrameNavigateParams& params) {
101 password_manager_.DidNavigateMainFrame(details.is_in_page);
104 bool ContentPasswordManagerDriver::OnMessageReceived(
105 const IPC::Message& message) {
107 IPC_BEGIN_MESSAGE_MAP(PasswordManager, message)
108 IPC_MESSAGE_FORWARD(AutofillHostMsg_PasswordFormsParsed,
110 PasswordManager::OnPasswordFormsParsed)
111 IPC_MESSAGE_FORWARD(AutofillHostMsg_PasswordFormsRendered,
113 PasswordManager::OnPasswordFormsRendered)
114 IPC_MESSAGE_FORWARD(AutofillHostMsg_PasswordFormSubmitted,
116 PasswordManager::OnPasswordFormSubmitted)
117 IPC_MESSAGE_FORWARD(AutofillHostMsg_ShowPasswordSuggestions,
118 &password_autofill_manager_,
119 PasswordAutofillManager::OnShowPasswordSuggestions)
120 IPC_MESSAGE_FORWARD(AutofillHostMsg_AddPasswordFormMapping,
121 &password_autofill_manager_,
122 PasswordAutofillManager::OnAddPasswordFormMapping)
123 IPC_MESSAGE_FORWARD(AutofillHostMsg_RecordSavePasswordProgress,
124 password_manager_.client(),
125 PasswordManagerClient::LogSavePasswordProgress)
126 IPC_MESSAGE_UNHANDLED(handled = false)
127 IPC_END_MESSAGE_MAP()
132 autofill::AutofillManager* ContentPasswordManagerDriver::GetAutofillManager() {
133 autofill::ContentAutofillDriver* driver =
134 autofill::ContentAutofillDriver::FromWebContents(web_contents());
135 return driver ? driver->autofill_manager() : NULL;
138 } // namespace password_manager