Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / components / autofill / content / browser / content_autofill_driver.cc
blobf8c7729e5a4914bf9e8ffb895f6bb829b13e0857
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/autofill/content/browser/content_autofill_driver.h"
7 #include "base/command_line.h"
8 #include "base/threading/sequenced_worker_pool.h"
9 #include "components/autofill/content/common/autofill_messages.h"
10 #include "components/autofill/core/browser/autofill_client.h"
11 #include "components/autofill/core/browser/autofill_external_delegate.h"
12 #include "components/autofill/core/browser/autofill_manager.h"
13 #include "components/autofill/core/browser/form_structure.h"
14 #include "components/autofill/core/common/autofill_switches.h"
15 #include "content/public/browser/browser_context.h"
16 #include "content/public/browser/browser_thread.h"
17 #include "content/public/browser/navigation_controller.h"
18 #include "content/public/browser/navigation_details.h"
19 #include "content/public/browser/render_frame_host.h"
20 #include "content/public/browser/render_view_host.h"
21 #include "content/public/browser/site_instance.h"
22 #include "ipc/ipc_message_macros.h"
24 namespace autofill {
26 ContentAutofillDriver::ContentAutofillDriver(
27 content::RenderFrameHost* render_frame_host,
28 AutofillClient* client,
29 const std::string& app_locale,
30 AutofillManager::AutofillDownloadManagerState enable_download_manager)
31 : render_frame_host_(render_frame_host),
32 client_(client),
33 autofill_manager_(new AutofillManager(this,
34 client,
35 app_locale,
36 enable_download_manager)),
37 autofill_external_delegate_(autofill_manager_.get(), this),
38 request_autocomplete_manager_(this) {
39 autofill_manager_->SetExternalDelegate(&autofill_external_delegate_);
42 ContentAutofillDriver::~ContentAutofillDriver() {}
44 bool ContentAutofillDriver::IsOffTheRecord() const {
45 return render_frame_host_->GetSiteInstance()
46 ->GetBrowserContext()
47 ->IsOffTheRecord();
50 net::URLRequestContextGetter* ContentAutofillDriver::GetURLRequestContext() {
51 return render_frame_host_->GetSiteInstance()
52 ->GetBrowserContext()
53 ->GetRequestContext();
56 base::SequencedWorkerPool* ContentAutofillDriver::GetBlockingPool() {
57 return content::BrowserThread::GetBlockingPool();
60 bool ContentAutofillDriver::RendererIsAvailable() {
61 return render_frame_host_->GetRenderViewHost() != NULL;
64 void ContentAutofillDriver::SendFormDataToRenderer(
65 int query_id,
66 RendererFormDataAction action,
67 const FormData& data) {
68 if (!RendererIsAvailable())
69 return;
70 switch (action) {
71 case FORM_DATA_ACTION_FILL:
72 render_frame_host_->Send(new AutofillMsg_FillForm(
73 render_frame_host_->GetRoutingID(), query_id, data));
74 break;
75 case FORM_DATA_ACTION_PREVIEW:
76 render_frame_host_->Send(new AutofillMsg_PreviewForm(
77 render_frame_host_->GetRoutingID(), query_id, data));
78 break;
82 void ContentAutofillDriver::PingRenderer() {
83 if (!RendererIsAvailable())
84 return;
85 render_frame_host_->Send(
86 new AutofillMsg_Ping(render_frame_host_->GetRoutingID()));
89 void ContentAutofillDriver::PropagateAutofillPredictions(
90 const std::vector<FormStructure*>& forms) {
91 autofill_manager_->client()->PropagateAutofillPredictions(render_frame_host_,
92 forms);
95 void ContentAutofillDriver::SendAutofillTypePredictionsToRenderer(
96 const std::vector<FormStructure*>& forms) {
97 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
98 switches::kShowAutofillTypePredictions))
99 return;
101 if (!RendererIsAvailable())
102 return;
104 std::vector<FormDataPredictions> type_predictions =
105 FormStructure::GetFieldTypePredictions(forms);
106 render_frame_host_->Send(new AutofillMsg_FieldTypePredictionsAvailable(
107 render_frame_host_->GetRoutingID(), type_predictions));
110 void ContentAutofillDriver::RendererShouldAcceptDataListSuggestion(
111 const base::string16& value) {
112 if (!RendererIsAvailable())
113 return;
114 render_frame_host_->Send(new AutofillMsg_AcceptDataListSuggestion(
115 render_frame_host_->GetRoutingID(), value));
118 void ContentAutofillDriver::RendererShouldClearFilledForm() {
119 if (!RendererIsAvailable())
120 return;
121 render_frame_host_->Send(
122 new AutofillMsg_ClearForm(render_frame_host_->GetRoutingID()));
125 void ContentAutofillDriver::RendererShouldClearPreviewedForm() {
126 if (!RendererIsAvailable())
127 return;
128 render_frame_host_->Send(
129 new AutofillMsg_ClearPreviewedForm(render_frame_host_->GetRoutingID()));
132 void ContentAutofillDriver::RendererShouldFillFieldWithValue(
133 const base::string16& value) {
134 if (!RendererIsAvailable())
135 return;
136 render_frame_host_->Send(new AutofillMsg_FillFieldWithValue(
137 render_frame_host_->GetRoutingID(), value));
140 void ContentAutofillDriver::RendererShouldPreviewFieldWithValue(
141 const base::string16& value) {
142 if (!RendererIsAvailable())
143 return;
144 render_frame_host_->Send(new AutofillMsg_PreviewFieldWithValue(
145 render_frame_host_->GetRoutingID(), value));
148 void ContentAutofillDriver::PopupHidden() {
149 // If the unmask prompt is showing, keep showing the preview. The preview
150 // will be cleared when the prompt closes.
151 if (!autofill_manager_->IsShowingUnmaskPrompt())
152 RendererShouldClearPreviewedForm();
155 bool ContentAutofillDriver::HandleMessage(const IPC::Message& message) {
156 bool handled = true;
157 IPC_BEGIN_MESSAGE_MAP(ContentAutofillDriver, message)
158 IPC_MESSAGE_FORWARD(AutofillHostMsg_FirstUserGestureObserved, client_,
159 AutofillClient::OnFirstUserGestureObserved)
160 IPC_MESSAGE_FORWARD(AutofillHostMsg_FormsSeen,
161 autofill_manager_.get(),
162 AutofillManager::OnFormsSeen)
163 IPC_MESSAGE_FORWARD(AutofillHostMsg_WillSubmitForm, autofill_manager_.get(),
164 AutofillManager::OnWillSubmitForm)
165 IPC_MESSAGE_FORWARD(AutofillHostMsg_FormSubmitted,
166 autofill_manager_.get(),
167 AutofillManager::OnFormSubmitted)
168 IPC_MESSAGE_FORWARD(AutofillHostMsg_TextFieldDidChange,
169 autofill_manager_.get(),
170 AutofillManager::OnTextFieldDidChange)
171 IPC_MESSAGE_FORWARD(AutofillHostMsg_QueryFormFieldAutofill,
172 autofill_manager_.get(),
173 AutofillManager::OnQueryFormFieldAutofill)
174 IPC_MESSAGE_FORWARD(AutofillHostMsg_DidPreviewAutofillFormData,
175 autofill_manager_.get(),
176 AutofillManager::OnDidPreviewAutofillFormData)
177 IPC_MESSAGE_FORWARD(AutofillHostMsg_PingAck,
178 &autofill_external_delegate_,
179 AutofillExternalDelegate::OnPingAck)
180 IPC_MESSAGE_FORWARD(AutofillHostMsg_DidFillAutofillFormData,
181 autofill_manager_.get(),
182 AutofillManager::OnDidFillAutofillFormData)
183 IPC_MESSAGE_FORWARD(AutofillHostMsg_DidEndTextFieldEditing,
184 autofill_manager_.get(),
185 AutofillManager::OnDidEndTextFieldEditing)
186 IPC_MESSAGE_FORWARD(AutofillHostMsg_HidePopup,
187 autofill_manager_.get(),
188 AutofillManager::OnHidePopup)
189 IPC_MESSAGE_FORWARD(AutofillHostMsg_SetDataList,
190 autofill_manager_.get(),
191 AutofillManager::OnSetDataList)
192 IPC_MESSAGE_FORWARD(AutofillHostMsg_RequestAutocomplete,
193 &request_autocomplete_manager_,
194 RequestAutocompleteManager::OnRequestAutocomplete)
195 IPC_MESSAGE_UNHANDLED(handled = false)
196 IPC_END_MESSAGE_MAP()
197 return handled;
200 void ContentAutofillDriver::DidNavigateFrame(
201 const content::LoadCommittedDetails& details,
202 const content::FrameNavigateParams& params) {
203 if (details.is_navigation_to_different_page())
204 autofill_manager_->Reset();
207 void ContentAutofillDriver::SetAutofillManager(
208 scoped_ptr<AutofillManager> manager) {
209 autofill_manager_ = manager.Pass();
210 autofill_manager_->SetExternalDelegate(&autofill_external_delegate_);
213 } // namespace autofill