Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(884)

Side by Side Diff: components/autofill/content/browser/content_autofill_driver.cc

Issue 2745803003: autofill-try
Patch Set: autofill-try Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/autofill/content/browser/content_autofill_driver.h" 5 #include "components/autofill/content/browser/content_autofill_driver.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "components/autofill/content/browser/content_autofill_driver_factory.h" 10 #include "components/autofill/content/browser/content_autofill_driver_factory.h"
11 #include "components/autofill/core/browser/autofill_client.h" 11 #include "components/autofill/core/browser/autofill_client.h"
12 #include "components/autofill/core/browser/autofill_external_delegate.h" 12 #include "components/autofill/core/browser/autofill_external_delegate.h"
13 #include "components/autofill/core/browser/autofill_handler_proxy.h"
13 #include "components/autofill/core/browser/autofill_manager.h" 14 #include "components/autofill/core/browser/autofill_manager.h"
14 #include "components/autofill/core/browser/form_structure.h" 15 #include "components/autofill/core/browser/form_structure.h"
15 #include "components/autofill/core/common/autofill_switches.h" 16 #include "components/autofill/core/common/autofill_switches.h"
16 #include "content/public/browser/browser_context.h" 17 #include "content/public/browser/browser_context.h"
17 #include "content/public/browser/navigation_controller.h" 18 #include "content/public/browser/navigation_controller.h"
18 #include "content/public/browser/navigation_handle.h" 19 #include "content/public/browser/navigation_handle.h"
19 #include "content/public/browser/render_frame_host.h" 20 #include "content/public/browser/render_frame_host.h"
20 #include "content/public/browser/render_view_host.h" 21 #include "content/public/browser/render_view_host.h"
21 #include "content/public/browser/render_widget_host.h" 22 #include "content/public/browser/render_widget_host.h"
22 #include "content/public/browser/render_widget_host_view.h" 23 #include "content/public/browser/render_widget_host_view.h"
23 #include "content/public/browser/site_instance.h" 24 #include "content/public/browser/site_instance.h"
24 #include "content/public/browser/storage_partition.h" 25 #include "content/public/browser/storage_partition.h"
25 #include "content/public/browser/web_contents.h" 26 #include "content/public/browser/web_contents.h"
26 #include "services/service_manager/public/cpp/interface_provider.h" 27 #include "services/service_manager/public/cpp/interface_provider.h"
27 #include "ui/gfx/geometry/size_f.h" 28 #include "ui/gfx/geometry/size_f.h"
28 29
29 namespace autofill { 30 namespace autofill {
30 31
31 ContentAutofillDriver::ContentAutofillDriver( 32 ContentAutofillDriver::ContentAutofillDriver(
32 content::RenderFrameHost* render_frame_host, 33 content::RenderFrameHost* render_frame_host,
33 AutofillClient* client, 34 AutofillClient* client,
34 const std::string& app_locale, 35 const std::string& app_locale,
35 AutofillManager::AutofillDownloadManagerState enable_download_manager) 36 AutofillManager::AutofillDownloadManagerState enable_download_manager,
37 AutofillProvider* provider)
36 : render_frame_host_(render_frame_host), 38 : render_frame_host_(render_frame_host),
37 autofill_manager_(new AutofillManager(this, 39 autofill_manager_(nullptr),
38 client,
39 app_locale,
40 enable_download_manager)),
41 autofill_external_delegate_(autofill_manager_.get(), this),
42 key_press_handler_manager_(this), 40 key_press_handler_manager_(this),
43 binding_(this) { 41 binding_(this) {
44 autofill_manager_->SetExternalDelegate(&autofill_external_delegate_); 42 // AutofillManager isn't used if provider is valid, Autofill provider is
43 // currently used by Android only.
44 if (provider) {
45 autofill_handler_ = base::MakeUnique<AutofillHandlerProxy>(this, provider);
46 } else {
47 autofill_handler_ = base::MakeUnique<AutofillManager>(
48 this, client, app_locale, enable_download_manager);
49 autofill_manager_ = static_cast<AutofillManager*>(autofill_handler_.get());
50 autofill_external_delegate_ =
51 base::MakeUnique<AutofillExternalDelegate>(autofill_manager_, this);
52 autofill_manager_->SetExternalDelegate(autofill_external_delegate_.get());
53 }
45 } 54 }
46 55
47 ContentAutofillDriver::~ContentAutofillDriver() {} 56 ContentAutofillDriver::~ContentAutofillDriver() {}
48 57
49 // static 58 // static
50 ContentAutofillDriver* ContentAutofillDriver::GetForRenderFrameHost( 59 ContentAutofillDriver* ContentAutofillDriver::GetForRenderFrameHost(
51 content::RenderFrameHost* render_frame_host) { 60 content::RenderFrameHost* render_frame_host) {
52 ContentAutofillDriverFactory* factory = 61 ContentAutofillDriverFactory* factory =
53 ContentAutofillDriverFactory::FromWebContents( 62 ContentAutofillDriverFactory::FromWebContents(
54 content::WebContents::FromRenderFrameHost(render_frame_host)); 63 content::WebContents::FromRenderFrameHost(render_frame_host));
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 void ContentAutofillDriver::RendererShouldPreviewFieldWithValue( 150 void ContentAutofillDriver::RendererShouldPreviewFieldWithValue(
142 const base::string16& value) { 151 const base::string16& value) {
143 if (!RendererIsAvailable()) 152 if (!RendererIsAvailable())
144 return; 153 return;
145 GetAutofillAgent()->PreviewFieldWithValue(value); 154 GetAutofillAgent()->PreviewFieldWithValue(value);
146 } 155 }
147 156
148 void ContentAutofillDriver::PopupHidden() { 157 void ContentAutofillDriver::PopupHidden() {
149 // If the unmask prompt is showing, keep showing the preview. The preview 158 // If the unmask prompt is showing, keep showing the preview. The preview
150 // will be cleared when the prompt closes. 159 // will be cleared when the prompt closes.
151 if (!autofill_manager_->IsShowingUnmaskPrompt()) 160 if (autofill_manager_ && !autofill_manager_->IsShowingUnmaskPrompt())
152 RendererShouldClearPreviewedForm(); 161 RendererShouldClearPreviewedForm();
153 } 162 }
154 163
155 gfx::RectF ContentAutofillDriver::TransformBoundingBoxToViewportCoordinates( 164 gfx::RectF ContentAutofillDriver::TransformBoundingBoxToViewportCoordinates(
156 const gfx::RectF& bounding_box) { 165 const gfx::RectF& bounding_box) {
157 content::RenderWidgetHostView* view = render_frame_host_->GetView(); 166 content::RenderWidgetHostView* view = render_frame_host_->GetView();
158 if (!view) 167 if (!view)
159 return bounding_box; 168 return bounding_box;
160 169
161 gfx::Point orig_point(bounding_box.x(), bounding_box.y()); 170 gfx::Point orig_point(bounding_box.x(), bounding_box.y());
162 gfx::Point transformed_point = 171 gfx::Point transformed_point =
163 view->TransformPointToRootCoordSpace(orig_point); 172 view->TransformPointToRootCoordSpace(orig_point);
164 return gfx::RectF(transformed_point.x(), transformed_point.y(), 173 return gfx::RectF(transformed_point.x(), transformed_point.y(),
165 bounding_box.width(), bounding_box.height()); 174 bounding_box.width(), bounding_box.height());
166 } 175 }
167 176
168 void ContentAutofillDriver::DidInteractWithCreditCardForm() { 177 void ContentAutofillDriver::DidInteractWithCreditCardForm() {
169 // Notify the WebContents about credit card inputs on HTTP pages. 178 // Notify the WebContents about credit card inputs on HTTP pages.
170 content::WebContents* contents = 179 content::WebContents* contents =
171 content::WebContents::FromRenderFrameHost(render_frame_host_); 180 content::WebContents::FromRenderFrameHost(render_frame_host_);
172 if (contents->GetVisibleURL().SchemeIsCryptographic()) 181 if (contents->GetVisibleURL().SchemeIsCryptographic())
173 return; 182 return;
174 contents->OnCreditCardInputShownOnHttp(); 183 contents->OnCreditCardInputShownOnHttp();
175 } 184 }
176 185
177 void ContentAutofillDriver::FormsSeen(const std::vector<FormData>& forms, 186 void ContentAutofillDriver::FormsSeen(const std::vector<FormData>& forms,
178 base::TimeTicks timestamp) { 187 base::TimeTicks timestamp) {
179 autofill_manager_->OnFormsSeen(forms, timestamp); 188 autofill_handler_->OnFormsSeen(forms, timestamp);
180 } 189 }
181 190
182 void ContentAutofillDriver::WillSubmitForm(const FormData& form, 191 void ContentAutofillDriver::WillSubmitForm(const FormData& form,
183 base::TimeTicks timestamp) { 192 base::TimeTicks timestamp) {
184 autofill_manager_->OnWillSubmitForm(form, timestamp); 193 autofill_handler_->OnWillSubmitForm(form, timestamp);
185 } 194 }
186 195
187 void ContentAutofillDriver::FormSubmitted(const FormData& form) { 196 void ContentAutofillDriver::FormSubmitted(const FormData& form) {
188 autofill_manager_->OnFormSubmitted(form); 197 autofill_handler_->OnFormSubmitted(form);
189 } 198 }
190 199
191 void ContentAutofillDriver::TextFieldDidChange(const FormData& form, 200 void ContentAutofillDriver::TextFieldDidChange(const FormData& form,
192 const FormFieldData& field, 201 const FormFieldData& field,
193 base::TimeTicks timestamp) { 202 base::TimeTicks timestamp) {
194 autofill_manager_->OnTextFieldDidChange(form, field, timestamp); 203 autofill_handler_->OnTextFieldDidChange(form, field, timestamp);
195 } 204 }
196 205
197 void ContentAutofillDriver::QueryFormFieldAutofill( 206 void ContentAutofillDriver::QueryFormFieldAutofill(
198 int32_t id, 207 int32_t id,
199 const FormData& form, 208 const FormData& form,
200 const FormFieldData& field, 209 const FormFieldData& field,
201 const gfx::RectF& bounding_box) { 210 const gfx::RectF& bounding_box) {
202 autofill_manager_->OnQueryFormFieldAutofill(id, form, field, bounding_box); 211 autofill_handler_->OnQueryFormFieldAutofill(id, form, field, bounding_box);
203 } 212 }
204 213
205 void ContentAutofillDriver::HidePopup() { 214 void ContentAutofillDriver::HidePopup() {
206 autofill_manager_->OnHidePopup(); 215 autofill_handler_->OnHidePopup();
207 } 216 }
208 217
209 void ContentAutofillDriver::FocusNoLongerOnForm() { 218 void ContentAutofillDriver::FocusNoLongerOnForm() {
210 autofill_manager_->OnFocusNoLongerOnForm(); 219 autofill_handler_->OnFocusNoLongerOnForm();
211 } 220 }
212 221
213 void ContentAutofillDriver::DidFillAutofillFormData(const FormData& form, 222 void ContentAutofillDriver::DidFillAutofillFormData(const FormData& form,
214 base::TimeTicks timestamp) { 223 base::TimeTicks timestamp) {
215 autofill_manager_->OnDidFillAutofillFormData(form, timestamp); 224 autofill_handler_->OnDidFillAutofillFormData(form, timestamp);
216 } 225 }
217 226
218 void ContentAutofillDriver::DidPreviewAutofillFormData() { 227 void ContentAutofillDriver::DidPreviewAutofillFormData() {
219 autofill_manager_->OnDidPreviewAutofillFormData(); 228 autofill_handler_->OnDidPreviewAutofillFormData();
220 } 229 }
221 230
222 void ContentAutofillDriver::DidEndTextFieldEditing() { 231 void ContentAutofillDriver::DidEndTextFieldEditing() {
223 autofill_manager_->OnDidEndTextFieldEditing(); 232 autofill_handler_->OnDidEndTextFieldEditing();
224 } 233 }
225 234
226 void ContentAutofillDriver::SetDataList( 235 void ContentAutofillDriver::SetDataList(
227 const std::vector<base::string16>& values, 236 const std::vector<base::string16>& values,
228 const std::vector<base::string16>& labels) { 237 const std::vector<base::string16>& labels) {
229 autofill_manager_->OnSetDataList(values, labels); 238 autofill_handler_->OnSetDataList(values, labels);
230 } 239 }
231 240
232 void ContentAutofillDriver::DidNavigateFrame( 241 void ContentAutofillDriver::DidNavigateFrame(
233 content::NavigationHandle* navigation_handle) { 242 content::NavigationHandle* navigation_handle) {
234 if (navigation_handle->IsInMainFrame() && 243 if (navigation_handle->IsInMainFrame() &&
235 !navigation_handle->IsSameDocument()) { 244 !navigation_handle->IsSameDocument()) {
236 autofill_manager_->Reset(); 245 autofill_handler_->Reset();
237 } 246 }
238 } 247 }
239 248
240 void ContentAutofillDriver::SetAutofillManager( 249 void ContentAutofillDriver::SetAutofillManager(
241 std::unique_ptr<AutofillManager> manager) { 250 std::unique_ptr<AutofillManager> manager) {
242 autofill_manager_ = std::move(manager); 251 CHECK(autofill_manager_);
243 autofill_manager_->SetExternalDelegate(&autofill_external_delegate_); 252 autofill_handler_ = std::move(manager);
253 autofill_manager_ = static_cast<AutofillManager*>(autofill_handler_.get());
254 autofill_manager_->SetExternalDelegate(autofill_external_delegate_.get());
244 } 255 }
245 256
246 const mojom::AutofillAgentPtr& ContentAutofillDriver::GetAutofillAgent() { 257 const mojom::AutofillAgentPtr& ContentAutofillDriver::GetAutofillAgent() {
247 // Here is a lazy binding, and will not reconnect after connection error. 258 // Here is a lazy binding, and will not reconnect after connection error.
248 if (!autofill_agent_) { 259 if (!autofill_agent_) {
249 render_frame_host_->GetRemoteInterfaces()->GetInterface( 260 render_frame_host_->GetRemoteInterfaces()->GetInterface(
250 mojo::MakeRequest(&autofill_agent_)); 261 mojo::MakeRequest(&autofill_agent_));
251 } 262 }
252 263
253 return autofill_agent_; 264 return autofill_agent_;
(...skipping 18 matching lines...) Expand all
272 283
273 void ContentAutofillDriver::RemoveHandler( 284 void ContentAutofillDriver::RemoveHandler(
274 const content::RenderWidgetHost::KeyPressEventCallback& handler) { 285 const content::RenderWidgetHost::KeyPressEventCallback& handler) {
275 content::RenderWidgetHostView* view = render_frame_host_->GetView(); 286 content::RenderWidgetHostView* view = render_frame_host_->GetView();
276 if (!view) 287 if (!view)
277 return; 288 return;
278 view->GetRenderWidgetHost()->RemoveKeyPressEventCallback(handler); 289 view->GetRenderWidgetHost()->RemoveKeyPressEventCallback(handler);
279 } 290 }
280 291
281 } // namespace autofill 292 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698