Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / components / password_manager / content / browser / content_password_manager_driver.cc
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.
4
5 #include "components/password_manager/content/browser/content_password_manager_driver.h"
6
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"
21
22 namespace password_manager {
23
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) {
32   DCHECK(web_contents);
33 }
34
35 ContentPasswordManagerDriver::~ContentPasswordManagerDriver() {}
36
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));
42 }
43
44 void ContentPasswordManagerDriver::AllowPasswordGenerationForForm(
45     autofill::PasswordForm* form) {
46   content::RenderViewHost* host = web_contents()->GetRenderViewHost();
47   host->Send(new AutofillMsg_FormNotBlacklisted(host->GetRoutingID(), *form));
48 }
49
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(),
54                                                           forms));
55 }
56
57 void ContentPasswordManagerDriver::AcceptPasswordAutofillSuggestion(
58     const base::string16& username,
59     const base::string16& password) {
60   content::RenderViewHost* host = web_contents()->GetRenderViewHost();
61   host->Send(
62       new AutofillMsg_AcceptPasswordAutofillSuggestion(host->GetRoutingID(),
63                                                        username,
64                                                        password));
65 }
66
67 bool ContentPasswordManagerDriver::DidLastPageLoadEncounterSSLErrors() {
68   DCHECK(web_contents());
69   content::NavigationEntry* entry =
70       web_contents()->GetController().GetLastCommittedEntry();
71   if (!entry) {
72     NOTREACHED();
73     return false;
74   }
75
76   return net::IsCertStatusError(entry->GetSSL().cert_status);
77 }
78
79 bool ContentPasswordManagerDriver::IsOffTheRecord() {
80   DCHECK(web_contents());
81   return web_contents()->GetBrowserContext()->IsOffTheRecord();
82 }
83
84 PasswordGenerationManager*
85 ContentPasswordManagerDriver::GetPasswordGenerationManager() {
86   return &password_generation_manager_;
87 }
88
89 PasswordManager* ContentPasswordManagerDriver::GetPasswordManager() {
90   return &password_manager_;
91 }
92
93 PasswordAutofillManager*
94 ContentPasswordManagerDriver::GetPasswordAutofillManager() {
95   return &password_autofill_manager_;
96 }
97
98 void ContentPasswordManagerDriver::DidNavigateMainFrame(
99     const content::LoadCommittedDetails& details,
100     const content::FrameNavigateParams& params) {
101   password_manager_.DidNavigateMainFrame(details.is_in_page);
102 }
103
104 bool ContentPasswordManagerDriver::OnMessageReceived(
105     const IPC::Message& message) {
106   bool handled = true;
107   IPC_BEGIN_MESSAGE_MAP(PasswordManager, message)
108   IPC_MESSAGE_FORWARD(AutofillHostMsg_PasswordFormsParsed,
109                       &password_manager_,
110                       PasswordManager::OnPasswordFormsParsed)
111   IPC_MESSAGE_FORWARD(AutofillHostMsg_PasswordFormsRendered,
112                       &password_manager_,
113                       PasswordManager::OnPasswordFormsRendered)
114   IPC_MESSAGE_FORWARD(AutofillHostMsg_PasswordFormSubmitted,
115                       &password_manager_,
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()
128
129   return handled;
130 }
131
132 autofill::AutofillManager* ContentPasswordManagerDriver::GetAutofillManager() {
133   autofill::ContentAutofillDriver* driver =
134       autofill::ContentAutofillDriver::FromWebContents(web_contents());
135   return driver ? driver->autofill_manager() : NULL;
136 }
137
138 }  // namespace password_manager