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

Side by Side Diff: components/autofill/content/renderer/autofill_agent.cc

Issue 707173004: Refactor Autofill for out of process iframes (OOPIF). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: mem leak Created 6 years 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/renderer/autofill_agent.h" 5 #include "components/autofill/content/renderer/autofill_agent.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/strings/string_split.h" 10 #include "base/strings/string_split.h"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "base/time/time.h" 13 #include "base/time/time.h"
14 #include "components/autofill/content/common/autofill_messages.h" 14 #include "components/autofill/content/common/autofill_messages.h"
15 #include "components/autofill/content/renderer/form_autofill_util.h" 15 #include "components/autofill/content/renderer/form_autofill_util.h"
16 #include "components/autofill/content/renderer/page_click_tracker.h" 16 #include "components/autofill/content/renderer/page_click_tracker.h"
17 #include "components/autofill/content/renderer/password_autofill_agent.h" 17 #include "components/autofill/content/renderer/password_autofill_agent.h"
18 #include "components/autofill/content/renderer/password_generation_agent.h" 18 #include "components/autofill/content/renderer/password_generation_agent.h"
19 #include "components/autofill/core/common/autofill_constants.h" 19 #include "components/autofill/core/common/autofill_constants.h"
20 #include "components/autofill/core/common/autofill_data_validation.h" 20 #include "components/autofill/core/common/autofill_data_validation.h"
21 #include "components/autofill/core/common/autofill_switches.h" 21 #include "components/autofill/core/common/autofill_switches.h"
22 #include "components/autofill/core/common/form_data.h" 22 #include "components/autofill/core/common/form_data.h"
23 #include "components/autofill/core/common/form_data_predictions.h" 23 #include "components/autofill/core/common/form_data_predictions.h"
24 #include "components/autofill/core/common/form_field_data.h" 24 #include "components/autofill/core/common/form_field_data.h"
25 #include "components/autofill/core/common/password_form.h" 25 #include "components/autofill/core/common/password_form.h"
26 #include "components/autofill/core/common/web_element_descriptor.h" 26 #include "components/autofill/core/common/web_element_descriptor.h"
27 #include "content/public/common/content_switches.h" 27 #include "content/public/common/content_switches.h"
28 #include "content/public/common/ssl_status.h" 28 #include "content/public/common/ssl_status.h"
29 #include "content/public/common/url_constants.h" 29 #include "content/public/common/url_constants.h"
30 #include "content/public/renderer/render_frame.h"
30 #include "content/public/renderer/render_view.h" 31 #include "content/public/renderer/render_view.h"
31 #include "net/cert/cert_status_flags.h" 32 #include "net/cert/cert_status_flags.h"
32 #include "third_party/WebKit/public/platform/WebRect.h" 33 #include "third_party/WebKit/public/platform/WebRect.h"
33 #include "third_party/WebKit/public/platform/WebURLRequest.h" 34 #include "third_party/WebKit/public/platform/WebURLRequest.h"
34 #include "third_party/WebKit/public/web/WebConsoleMessage.h" 35 #include "third_party/WebKit/public/web/WebConsoleMessage.h"
35 #include "third_party/WebKit/public/web/WebDataSource.h" 36 #include "third_party/WebKit/public/web/WebDataSource.h"
36 #include "third_party/WebKit/public/web/WebDocument.h" 37 #include "third_party/WebKit/public/web/WebDocument.h"
37 #include "third_party/WebKit/public/web/WebElementCollection.h" 38 #include "third_party/WebKit/public/web/WebElementCollection.h"
38 #include "third_party/WebKit/public/web/WebFormControlElement.h" 39 #include "third_party/WebKit/public/web/WebFormControlElement.h"
39 #include "third_party/WebKit/public/web/WebFormElement.h" 40 #include "third_party/WebKit/public/web/WebFormElement.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 122
122 AutofillAgent::ShowSuggestionsOptions::ShowSuggestionsOptions() 123 AutofillAgent::ShowSuggestionsOptions::ShowSuggestionsOptions()
123 : autofill_on_empty_values(false), 124 : autofill_on_empty_values(false),
124 requires_caret_at_end(false), 125 requires_caret_at_end(false),
125 display_warning_if_disabled(false), 126 display_warning_if_disabled(false),
126 datalist_only(false), 127 datalist_only(false),
127 show_full_suggestion_list(false), 128 show_full_suggestion_list(false),
128 show_password_suggestions_only(false) { 129 show_password_suggestions_only(false) {
129 } 130 }
130 131
131 AutofillAgent::AutofillAgent(content::RenderView* render_view, 132 AutofillAgent::AutofillAgent(content::RenderFrame* render_frame,
132 PasswordAutofillAgent* password_autofill_agent, 133 PasswordAutofillAgent* password_autofill_agent,
133 PasswordGenerationAgent* password_generation_agent) 134 PasswordGenerationAgent* password_generation_agent)
134 : content::RenderViewObserver(render_view), 135 : content::RenderFrameObserver(render_frame),
135 password_autofill_agent_(password_autofill_agent), 136 password_autofill_agent_(password_autofill_agent),
136 password_generation_agent_(password_generation_agent), 137 password_generation_agent_(password_generation_agent),
138 legacy_(render_frame->GetRenderView(), this),
139 page_click_tracker_(render_frame->GetRenderView(), this),
137 autofill_query_id_(0), 140 autofill_query_id_(0),
138 web_view_(render_view->GetWebView()),
139 display_warning_if_disabled_(false), 141 display_warning_if_disabled_(false),
140 was_query_node_autofilled_(false), 142 was_query_node_autofilled_(false),
141 has_shown_autofill_popup_for_current_edit_(false), 143 has_shown_autofill_popup_for_current_edit_(false),
142 did_set_node_text_(false), 144 did_set_node_text_(false),
143 ignore_text_changes_(false), 145 ignore_text_changes_(false),
144 is_popup_possibly_visible_(false), 146 is_popup_possibly_visible_(false),
145 main_frame_processed_(false),
146 weak_ptr_factory_(this) { 147 weak_ptr_factory_(this) {
147 render_view->GetWebView()->setAutofillClient(this); 148 render_frame->GetWebFrame()->setAutofillClient(this);
148
149 // The PageClickTracker is a RenderViewObserver, and hence will be freed when
150 // the RenderView is destroyed.
151 new PageClickTracker(render_view, this);
152 } 149 }
153 150
154 AutofillAgent::~AutofillAgent() {} 151 AutofillAgent::~AutofillAgent() {}
155 152
156 bool AutofillAgent::OnMessageReceived(const IPC::Message& message) { 153 bool AutofillAgent::OnMessageReceived(const IPC::Message& message) {
157 bool handled = true; 154 bool handled = true;
158 IPC_BEGIN_MESSAGE_MAP(AutofillAgent, message) 155 IPC_BEGIN_MESSAGE_MAP(AutofillAgent, message)
156 IPC_MESSAGE_HANDLER(AutofillMsg_FirstUserGestureObservedInTab,
157 OnFirstUserGestureObservedInTab)
159 IPC_MESSAGE_HANDLER(AutofillMsg_Ping, OnPing) 158 IPC_MESSAGE_HANDLER(AutofillMsg_Ping, OnPing)
160 IPC_MESSAGE_HANDLER(AutofillMsg_FillForm, OnFillForm) 159 IPC_MESSAGE_HANDLER(AutofillMsg_FillForm, OnFillForm)
161 IPC_MESSAGE_HANDLER(AutofillMsg_PreviewForm, OnPreviewForm) 160 IPC_MESSAGE_HANDLER(AutofillMsg_PreviewForm, OnPreviewForm)
162 IPC_MESSAGE_HANDLER(AutofillMsg_FieldTypePredictionsAvailable, 161 IPC_MESSAGE_HANDLER(AutofillMsg_FieldTypePredictionsAvailable,
163 OnFieldTypePredictionsAvailable) 162 OnFieldTypePredictionsAvailable)
164 IPC_MESSAGE_HANDLER(AutofillMsg_ClearForm, OnClearForm) 163 IPC_MESSAGE_HANDLER(AutofillMsg_ClearForm, OnClearForm)
165 IPC_MESSAGE_HANDLER(AutofillMsg_ClearPreviewedForm, OnClearPreviewedForm) 164 IPC_MESSAGE_HANDLER(AutofillMsg_ClearPreviewedForm, OnClearPreviewedForm)
166 IPC_MESSAGE_HANDLER(AutofillMsg_FillFieldWithValue, OnFillFieldWithValue) 165 IPC_MESSAGE_HANDLER(AutofillMsg_FillFieldWithValue, OnFillFieldWithValue)
167 IPC_MESSAGE_HANDLER(AutofillMsg_PreviewFieldWithValue, 166 IPC_MESSAGE_HANDLER(AutofillMsg_PreviewFieldWithValue,
168 OnPreviewFieldWithValue) 167 OnPreviewFieldWithValue)
169 IPC_MESSAGE_HANDLER(AutofillMsg_AcceptDataListSuggestion, 168 IPC_MESSAGE_HANDLER(AutofillMsg_AcceptDataListSuggestion,
170 OnAcceptDataListSuggestion) 169 OnAcceptDataListSuggestion)
171 IPC_MESSAGE_HANDLER(AutofillMsg_FillPasswordSuggestion, 170 IPC_MESSAGE_HANDLER(AutofillMsg_FillPasswordSuggestion,
172 OnFillPasswordSuggestion) 171 OnFillPasswordSuggestion)
173 IPC_MESSAGE_HANDLER(AutofillMsg_PreviewPasswordSuggestion, 172 IPC_MESSAGE_HANDLER(AutofillMsg_PreviewPasswordSuggestion,
174 OnPreviewPasswordSuggestion) 173 OnPreviewPasswordSuggestion)
175 IPC_MESSAGE_HANDLER(AutofillMsg_RequestAutocompleteResult, 174 IPC_MESSAGE_HANDLER(AutofillMsg_RequestAutocompleteResult,
176 OnRequestAutocompleteResult) 175 OnRequestAutocompleteResult)
177 IPC_MESSAGE_UNHANDLED(handled = false) 176 IPC_MESSAGE_UNHANDLED(handled = false)
178 IPC_END_MESSAGE_MAP() 177 IPC_END_MESSAGE_MAP()
179 return handled; 178 return handled;
180 } 179 }
181 180
182 void AutofillAgent::DidFinishDocumentLoad(WebLocalFrame* frame) { 181 void AutofillAgent::DidCommitProvisionalLoad(bool is_new_navigation) {
183 // If the main frame just finished loading, we should process it. 182 // TODO(estade): |form_cache_| shouldn't track multiple frames.
184 if (!frame->parent()) 183 form_cache_.ResetFrame(*render_frame()->GetWebFrame());
185 main_frame_processed_ = false;
186
187 ProcessForms(*frame);
188 } 184 }
189 185
190 void AutofillAgent::DidCommitProvisionalLoad(WebLocalFrame* frame, 186 void AutofillAgent::DidFinishDocumentLoad() {
191 bool is_new_navigation) { 187 ProcessForms();
192 form_cache_.ResetFrame(*frame);
193 } 188 }
194 189
195 void AutofillAgent::FrameDetached(WebFrame* frame) { 190 void AutofillAgent::FrameDetached(WebFrame* frame) {
196 form_cache_.ResetFrame(*frame); 191 if (frame != render_frame()->GetWebFrame())
197 }
198
199 void AutofillAgent::FrameWillClose(WebFrame* frame) {
200 if (in_flight_request_form_.isNull())
201 return; 192 return;
202 193
203 for (WebFrame* temp = in_flight_request_form_.document().frame(); 194 form_cache_.ResetFrame(*frame);
204 temp; temp = temp->parent()) {
205 if (temp == frame) {
206 Send(new AutofillHostMsg_CancelRequestAutocomplete(routing_id()));
207 break;
208 }
209 }
210 } 195 }
211 196
212 void AutofillAgent::WillSubmitForm(WebLocalFrame* frame, 197 void AutofillAgent::WillSubmitForm(WebLocalFrame* frame,
213 const WebFormElement& form) { 198 const WebFormElement& form) {
199 if (frame != render_frame()->GetWebFrame())
200 return;
201
214 FormData form_data; 202 FormData form_data;
215 if (WebFormElementToFormData(form, 203 if (WebFormElementToFormData(form,
216 WebFormControlElement(), 204 WebFormControlElement(),
217 REQUIRE_NONE, 205 REQUIRE_NONE,
218 static_cast<ExtractMask>( 206 static_cast<ExtractMask>(
219 EXTRACT_VALUE | EXTRACT_OPTION_TEXT), 207 EXTRACT_VALUE | EXTRACT_OPTION_TEXT),
220 &form_data, 208 &form_data,
221 NULL)) { 209 NULL)) {
222 Send(new AutofillHostMsg_FormSubmitted(routing_id(), form_data, 210 Send(new AutofillHostMsg_FormSubmitted(routing_id(), form_data,
223 base::TimeTicks::Now())); 211 base::TimeTicks::Now()));
224 } 212 }
225 } 213 }
226 214
215 void AutofillAgent::DidChangeScrollOffset(WebLocalFrame* frame) {
216 if (frame != render_frame()->GetWebFrame())
217 return;
218
219 HidePopup();
220 }
221
227 void AutofillAgent::FocusedNodeChanged(const WebNode& node) { 222 void AutofillAgent::FocusedNodeChanged(const WebNode& node) {
228 HidePopup(); 223 HidePopup();
229 224
225 if (node.isNull() || !node.isElementNode())
226 return;
227
228 if (node.document().frame() != render_frame()->GetWebFrame())
229 return;
230
230 if (password_generation_agent_ && 231 if (password_generation_agent_ &&
231 password_generation_agent_->FocusedNodeHasChanged(node)) { 232 password_generation_agent_->FocusedNodeHasChanged(node)) {
232 is_popup_possibly_visible_ = true; 233 is_popup_possibly_visible_ = true;
233 return; 234 return;
234 } 235 }
235 236
236 if (node.isNull() || !node.isElementNode())
237 return;
238
239 WebElement web_element = node.toConst<WebElement>(); 237 WebElement web_element = node.toConst<WebElement>();
240 238
241 if (!web_element.document().frame()) 239 if (!web_element.document().frame())
242 return; 240 return;
243 241
244 const WebInputElement* element = toWebInputElement(&web_element); 242 const WebInputElement* element = toWebInputElement(&web_element);
245 243
246 if (!element || !element->isEnabled() || element->isReadOnly() || 244 if (!element || !element->isEnabled() || element->isReadOnly() ||
247 !element->isTextField() || element->isPasswordField()) 245 !element->isTextField() || element->isPasswordField())
248 return; 246 return;
249 247
250 element_ = *element; 248 element_ = *element;
251 } 249 }
252 250
253 void AutofillAgent::OrientationChangeEvent() { 251 void AutofillAgent::OrientationChangeEvent() {
254 HidePopup(); 252 HidePopup();
255 } 253 }
256 254
257 void AutofillAgent::Resized() { 255 void AutofillAgent::Resized() {
258 HidePopup(); 256 HidePopup();
259 } 257 }
260 258
261 void AutofillAgent::DidChangeScrollOffset(WebLocalFrame*) { 259 void AutofillAgent::LegacyFrameWillClose(blink::WebFrame* frame) {
262 HidePopup(); 260 if (in_flight_request_form_.isNull())
261 return;
262
263 for (blink::WebFrame* temp = render_frame()->GetWebFrame(); temp;
264 temp = temp->parent()) {
265 if (temp == frame) {
266 Send(new AutofillHostMsg_CancelRequestAutocomplete(routing_id()));
267 break;
268 }
269 }
263 } 270 }
264 271
265 void AutofillAgent::didRequestAutocomplete( 272 void AutofillAgent::didRequestAutocomplete(
266 const WebFormElement& form) { 273 const WebFormElement& form) {
274 DCHECK_EQ(form.document().frame(), render_frame()->GetWebFrame());
275
267 // Disallow the dialog over non-https or broken https, except when the 276 // Disallow the dialog over non-https or broken https, except when the
268 // ignore SSL flag is passed. See http://crbug.com/272512. 277 // ignore SSL flag is passed. See http://crbug.com/272512.
269 // TODO(palmer): this should be moved to the browser process after frames 278 // TODO(palmer): this should be moved to the browser process after frames
270 // get their own processes. 279 // get their own processes.
271 GURL url(form.document().url()); 280 GURL url(form.document().url());
272 content::SSLStatus ssl_status = 281 content::SSLStatus ssl_status =
273 render_view()->GetSSLStatusOfFrame(form.document().frame()); 282 render_frame()->GetRenderView()->GetSSLStatusOfFrame(
283 form.document().frame());
274 bool is_safe = url.SchemeIs(url::kHttpsScheme) && 284 bool is_safe = url.SchemeIs(url::kHttpsScheme) &&
275 !net::IsCertStatusError(ssl_status.cert_status); 285 !net::IsCertStatusError(ssl_status.cert_status);
276 bool allow_unsafe = base::CommandLine::ForCurrentProcess()->HasSwitch( 286 bool allow_unsafe = base::CommandLine::ForCurrentProcess()->HasSwitch(
277 ::switches::kReduceSecurityForTesting); 287 ::switches::kReduceSecurityForTesting);
278 288
279 FormData form_data; 289 FormData form_data;
280 std::string error_message; 290 std::string error_message;
281 if (!in_flight_request_form_.isNull()) { 291 if (!in_flight_request_form_.isNull()) {
282 error_message = "already active."; 292 error_message = "already active.";
283 } else if (!is_safe && !allow_unsafe) { 293 } else if (!is_safe && !allow_unsafe) {
(...skipping 30 matching lines...) Expand all
314 Send(new AutofillHostMsg_RequestAutocomplete(routing_id(), form_data, url)); 324 Send(new AutofillHostMsg_RequestAutocomplete(routing_id(), form_data, url));
315 } 325 }
316 326
317 void AutofillAgent::setIgnoreTextChanges(bool ignore) { 327 void AutofillAgent::setIgnoreTextChanges(bool ignore) {
318 ignore_text_changes_ = ignore; 328 ignore_text_changes_ = ignore;
319 } 329 }
320 330
321 void AutofillAgent::FormControlElementClicked( 331 void AutofillAgent::FormControlElementClicked(
322 const WebFormControlElement& element, 332 const WebFormControlElement& element,
323 bool was_focused) { 333 bool was_focused) {
334 // TODO(estade): Remove this check when PageClickTracker is per-frame.
335 if (element.document().frame() != render_frame()->GetWebFrame())
336 return;
337
324 const WebInputElement* input_element = toWebInputElement(&element); 338 const WebInputElement* input_element = toWebInputElement(&element);
325 if (!input_element && !IsTextAreaElement(element)) 339 if (!input_element && !IsTextAreaElement(element))
326 return; 340 return;
327 341
328 ShowSuggestionsOptions options; 342 ShowSuggestionsOptions options;
329 options.autofill_on_empty_values = true; 343 options.autofill_on_empty_values = true;
330 options.display_warning_if_disabled = true; 344 options.display_warning_if_disabled = true;
331 options.show_full_suggestion_list = element.isAutofilled(); 345 options.show_full_suggestion_list = element.isAutofilled();
332 346
333 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( 347 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 444
431 void AutofillAgent::openTextDataListChooser(const WebInputElement& element) { 445 void AutofillAgent::openTextDataListChooser(const WebInputElement& element) {
432 ShowSuggestionsOptions options; 446 ShowSuggestionsOptions options;
433 options.autofill_on_empty_values = true; 447 options.autofill_on_empty_values = true;
434 options.datalist_only = true; 448 options.datalist_only = true;
435 ShowSuggestions(element, options); 449 ShowSuggestions(element, options);
436 } 450 }
437 451
438 void AutofillAgent::firstUserGestureObserved() { 452 void AutofillAgent::firstUserGestureObserved() {
439 password_autofill_agent_->FirstUserGestureObserved(); 453 password_autofill_agent_->FirstUserGestureObserved();
454 Send(new AutofillHostMsg_FirstUserGestureObserved(routing_id()));
440 } 455 }
441 456
442 void AutofillAgent::AcceptDataListSuggestion( 457 void AutofillAgent::AcceptDataListSuggestion(
443 const base::string16& suggested_value) { 458 const base::string16& suggested_value) {
444 WebInputElement* input_element = toWebInputElement(&element_); 459 WebInputElement* input_element = toWebInputElement(&element_);
445 DCHECK(input_element); 460 DCHECK(input_element);
446 base::string16 new_value = suggested_value; 461 base::string16 new_value = suggested_value;
447 // If this element takes multiple values then replace the last part with 462 // If this element takes multiple values then replace the last part with
448 // the suggestion. 463 // the suggestion.
449 if (input_element->isMultiple() && input_element->isEmailField()) { 464 if (input_element->isMultiple() && input_element->isEmailField()) {
(...skipping 20 matching lines...) Expand all
470 } 485 }
471 486
472 void AutofillAgent::OnFieldTypePredictionsAvailable( 487 void AutofillAgent::OnFieldTypePredictionsAvailable(
473 const std::vector<FormDataPredictions>& forms) { 488 const std::vector<FormDataPredictions>& forms) {
474 for (size_t i = 0; i < forms.size(); ++i) { 489 for (size_t i = 0; i < forms.size(); ++i) {
475 form_cache_.ShowPredictions(forms[i]); 490 form_cache_.ShowPredictions(forms[i]);
476 } 491 }
477 } 492 }
478 493
479 void AutofillAgent::OnFillForm(int query_id, const FormData& form) { 494 void AutofillAgent::OnFillForm(int query_id, const FormData& form) {
480 if (!render_view()->GetWebView() || query_id != autofill_query_id_) 495 if (query_id != autofill_query_id_)
481 return; 496 return;
482 497
483 was_query_node_autofilled_ = element_.isAutofilled(); 498 was_query_node_autofilled_ = element_.isAutofilled();
484 FillForm(form, element_); 499 FillForm(form, element_);
485 Send(new AutofillHostMsg_DidFillAutofillFormData(routing_id(), 500 Send(new AutofillHostMsg_DidFillAutofillFormData(routing_id(),
486 base::TimeTicks::Now())); 501 base::TimeTicks::Now()));
487 } 502 }
488 503
504 void AutofillAgent::OnFirstUserGestureObservedInTab() {
505 password_autofill_agent_->FirstUserGestureObserved();
506 }
507
489 void AutofillAgent::OnPing() { 508 void AutofillAgent::OnPing() {
490 Send(new AutofillHostMsg_PingAck(routing_id())); 509 Send(new AutofillHostMsg_PingAck(routing_id()));
491 } 510 }
492 511
493 void AutofillAgent::OnPreviewForm(int query_id, const FormData& form) { 512 void AutofillAgent::OnPreviewForm(int query_id, const FormData& form) {
494 if (!render_view()->GetWebView() || query_id != autofill_query_id_) 513 if (query_id != autofill_query_id_)
495 return; 514 return;
496 515
497 was_query_node_autofilled_ = element_.isAutofilled(); 516 was_query_node_autofilled_ = element_.isAutofilled();
498 PreviewForm(form, element_); 517 PreviewForm(form, element_);
499 Send(new AutofillHostMsg_DidPreviewAutofillFormData(routing_id())); 518 Send(new AutofillHostMsg_DidPreviewAutofillFormData(routing_id()));
500 } 519 }
501 520
502 void AutofillAgent::OnClearForm() { 521 void AutofillAgent::OnClearForm() {
503 form_cache_.ClearFormWithElement(element_); 522 form_cache_.ClearFormWithElement(element_);
504 } 523 }
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 FormFieldData field; 690 FormFieldData field;
672 if (!FindFormAndFieldForFormControlElement(element, &form, &field, 691 if (!FindFormAndFieldForFormControlElement(element, &form, &field,
673 requirements)) { 692 requirements)) {
674 // If we didn't find the cached form, at least let autocomplete have a shot 693 // If we didn't find the cached form, at least let autocomplete have a shot
675 // at providing suggestions. 694 // at providing suggestions.
676 WebFormControlElementToFormField(element, EXTRACT_VALUE, &field); 695 WebFormControlElementToFormField(element, EXTRACT_VALUE, &field);
677 } 696 }
678 if (datalist_only) 697 if (datalist_only)
679 field.should_autocomplete = false; 698 field.should_autocomplete = false;
680 699
681 gfx::RectF bounding_box_scaled = 700 gfx::RectF bounding_box_scaled = GetScaledBoundingBox(
682 GetScaledBoundingBox(web_view_->pageScaleFactor(), &element_); 701 render_frame()->GetRenderView()->GetWebView()->pageScaleFactor(),
702 &element_);
683 703
684 std::vector<base::string16> data_list_values; 704 std::vector<base::string16> data_list_values;
685 std::vector<base::string16> data_list_labels; 705 std::vector<base::string16> data_list_labels;
686 const WebInputElement* input_element = toWebInputElement(&element); 706 const WebInputElement* input_element = toWebInputElement(&element);
687 if (input_element) { 707 if (input_element) {
688 // Find the datalist values and send them to the browser process. 708 // Find the datalist values and send them to the browser process.
689 GetDataListSuggestions(*input_element, 709 GetDataListSuggestions(*input_element,
690 datalist_only, 710 datalist_only,
691 &data_list_values, 711 &data_list_values,
692 &data_list_labels); 712 &data_list_labels);
(...skipping 22 matching lines...) Expand all
715 735
716 void AutofillAgent::PreviewFieldWithValue(const base::string16& value, 736 void AutofillAgent::PreviewFieldWithValue(const base::string16& value,
717 WebInputElement* node) { 737 WebInputElement* node) {
718 was_query_node_autofilled_ = element_.isAutofilled(); 738 was_query_node_autofilled_ = element_.isAutofilled();
719 node->setSuggestedValue(value.substr(0, node->maxLength())); 739 node->setSuggestedValue(value.substr(0, node->maxLength()));
720 node->setAutofilled(true); 740 node->setAutofilled(true);
721 node->setSelectionRange(node->value().length(), 741 node->setSelectionRange(node->value().length(),
722 node->suggestedValue().length()); 742 node->suggestedValue().length());
723 } 743 }
724 744
725 void AutofillAgent::ProcessForms(const WebLocalFrame& frame) { 745 void AutofillAgent::ProcessForms() {
726 // Record timestamp of when the forms are first seen. This is used to 746 // Record timestamp of when the forms are first seen. This is used to
727 // measure the overhead of the Autofill feature. 747 // measure the overhead of the Autofill feature.
728 base::TimeTicks forms_seen_timestamp = base::TimeTicks::Now(); 748 base::TimeTicks forms_seen_timestamp = base::TimeTicks::Now();
729 749
730 std::vector<FormData> forms = form_cache_.ExtractNewForms(frame); 750 WebLocalFrame* frame = render_frame()->GetWebFrame();
751 std::vector<FormData> forms = form_cache_.ExtractNewForms(*frame);
731 752
732 // Always communicate to browser process for topmost frame. 753 // Always communicate to browser process for topmost frame.
733 if (!forms.empty() || 754 if (!forms.empty() || !frame->parent()) {
734 (!frame.parent() && !main_frame_processed_)) {
735 Send(new AutofillHostMsg_FormsSeen(routing_id(), forms, 755 Send(new AutofillHostMsg_FormsSeen(routing_id(), forms,
736 forms_seen_timestamp)); 756 forms_seen_timestamp));
737 } 757 }
738
739 if (!frame.parent())
740 main_frame_processed_ = true;
741 } 758 }
742 759
743 void AutofillAgent::HidePopup() { 760 void AutofillAgent::HidePopup() {
744 if (!is_popup_possibly_visible_) 761 if (!is_popup_possibly_visible_)
745 return; 762 return;
746 763
747 if (!element_.isNull()) 764 if (!element_.isNull())
748 OnClearPreviewedForm(); 765 OnClearPreviewedForm();
749 766
750 is_popup_possibly_visible_ = false; 767 is_popup_possibly_visible_ = false;
751 Send(new AutofillHostMsg_HidePopup(routing_id())); 768 Send(new AutofillHostMsg_HidePopup(routing_id()));
752 } 769 }
753 770
754 void AutofillAgent::didAssociateFormControls(const WebVector<WebNode>& nodes) { 771 void AutofillAgent::didAssociateFormControls(const WebVector<WebNode>& nodes) {
755 for (size_t i = 0; i < nodes.size(); ++i) { 772 for (size_t i = 0; i < nodes.size(); ++i) {
756 WebLocalFrame* frame = nodes[i].document().frame(); 773 WebLocalFrame* frame = nodes[i].document().frame();
757 // Only monitors dynamic forms created in the top frame. Dynamic forms 774 // Only monitors dynamic forms created in the top frame. Dynamic forms
758 // inserted in iframes are not captured yet. Frame is only processed 775 // inserted in iframes are not captured yet. Frame is only processed
759 // if it has finished loading, otherwise you can end up with a partially 776 // if it has finished loading, otherwise you can end up with a partially
760 // parsed form. 777 // parsed form.
761 if (frame && !frame->parent() && !frame->isLoading()) { 778 if (frame && !frame->isLoading()) {
762 ProcessForms(*frame); 779 ProcessForms();
763 password_autofill_agent_->OnDynamicFormsSeen(frame); 780 password_autofill_agent_->OnDynamicFormsSeen();
764 if (password_generation_agent_) 781 if (password_generation_agent_)
765 password_generation_agent_->OnDynamicFormsSeen(frame); 782 password_generation_agent_->OnDynamicFormsSeen();
766 return; 783 return;
767 } 784 }
768 } 785 }
769 } 786 }
770 787
788 // LegacyAutofillAgent ---------------------------------------------------------
789
790 AutofillAgent::LegacyAutofillAgent::LegacyAutofillAgent(
791 content::RenderView* render_view,
792 AutofillAgent* agent)
793 : content::RenderViewObserver(render_view), agent_(agent) {
794 }
795
796 AutofillAgent::LegacyAutofillAgent::~LegacyAutofillAgent() {
797 }
798
799 void AutofillAgent::LegacyAutofillAgent::OnDestruct() {
800 // No-op. Don't delete |this|.
801 }
802
803 void AutofillAgent::LegacyAutofillAgent::FrameDetached(WebFrame* frame) {
804 agent_->FrameDetached(frame);
805 }
806
807 void AutofillAgent::LegacyAutofillAgent::WillSubmitForm(
808 WebLocalFrame* frame,
809 const WebFormElement& form) {
810 agent_->WillSubmitForm(frame, form);
811 }
812
813 void AutofillAgent::LegacyAutofillAgent::DidChangeScrollOffset(
814 WebLocalFrame* frame) {
815 agent_->DidChangeScrollOffset(frame);
816 }
817
818 void AutofillAgent::LegacyAutofillAgent::FocusedNodeChanged(
819 const WebNode& node) {
820 agent_->FocusedNodeChanged(node);
821 }
822
823 void AutofillAgent::LegacyAutofillAgent::OrientationChangeEvent() {
824 agent_->OrientationChangeEvent();
825 }
826
827 void AutofillAgent::LegacyAutofillAgent::Resized() {
828 agent_->Resized();
829 }
830
831 void AutofillAgent::LegacyAutofillAgent::FrameWillClose(
832 blink::WebFrame* frame) {
833 agent_->LegacyFrameWillClose(frame);
834 }
835
771 } // namespace autofill 836 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/content/renderer/autofill_agent.h ('k') | components/autofill/content/renderer/page_click_tracker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698