| OLD | NEW |
| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <tuple> | 9 #include <tuple> |
| 10 | 10 |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 IPC_MESSAGE_HANDLER(AutofillMsg_ClearPreviewedForm, OnClearPreviewedForm) | 213 IPC_MESSAGE_HANDLER(AutofillMsg_ClearPreviewedForm, OnClearPreviewedForm) |
| 214 IPC_MESSAGE_HANDLER(AutofillMsg_FillFieldWithValue, OnFillFieldWithValue) | 214 IPC_MESSAGE_HANDLER(AutofillMsg_FillFieldWithValue, OnFillFieldWithValue) |
| 215 IPC_MESSAGE_HANDLER(AutofillMsg_PreviewFieldWithValue, | 215 IPC_MESSAGE_HANDLER(AutofillMsg_PreviewFieldWithValue, |
| 216 OnPreviewFieldWithValue) | 216 OnPreviewFieldWithValue) |
| 217 IPC_MESSAGE_HANDLER(AutofillMsg_AcceptDataListSuggestion, | 217 IPC_MESSAGE_HANDLER(AutofillMsg_AcceptDataListSuggestion, |
| 218 OnAcceptDataListSuggestion) | 218 OnAcceptDataListSuggestion) |
| 219 IPC_MESSAGE_HANDLER(AutofillMsg_FillPasswordSuggestion, | 219 IPC_MESSAGE_HANDLER(AutofillMsg_FillPasswordSuggestion, |
| 220 OnFillPasswordSuggestion) | 220 OnFillPasswordSuggestion) |
| 221 IPC_MESSAGE_HANDLER(AutofillMsg_PreviewPasswordSuggestion, | 221 IPC_MESSAGE_HANDLER(AutofillMsg_PreviewPasswordSuggestion, |
| 222 OnPreviewPasswordSuggestion) | 222 OnPreviewPasswordSuggestion) |
| 223 IPC_MESSAGE_HANDLER(AutofillMsg_RequestAutocompleteResult, | |
| 224 OnRequestAutocompleteResult) | |
| 225 IPC_MESSAGE_UNHANDLED(handled = false) | 223 IPC_MESSAGE_UNHANDLED(handled = false) |
| 226 IPC_END_MESSAGE_MAP() | 224 IPC_END_MESSAGE_MAP() |
| 227 return handled; | 225 return handled; |
| 228 } | 226 } |
| 229 | 227 |
| 230 void AutofillAgent::DidCommitProvisionalLoad(bool is_new_navigation, | 228 void AutofillAgent::DidCommitProvisionalLoad(bool is_new_navigation, |
| 231 bool is_same_page_navigation) { | 229 bool is_same_page_navigation) { |
| 232 blink::WebFrame* frame = render_frame()->GetWebFrame(); | 230 blink::WebFrame* frame = render_frame()->GetWebFrame(); |
| 233 // TODO(dvadym): check if we need to check if it is main frame navigation | 231 // TODO(dvadym): check if we need to check if it is main frame navigation |
| 234 // http://crbug.com/443155 | 232 // http://crbug.com/443155 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 if (!doc.isNull()) | 333 if (!doc.isNull()) |
| 336 focused_element = doc.focusedElement(); | 334 focused_element = doc.focusedElement(); |
| 337 | 335 |
| 338 if (!focused_element.isNull() && password_generation_agent_ && | 336 if (!focused_element.isNull() && password_generation_agent_ && |
| 339 password_generation_agent_->FocusedNodeHasChanged(focused_element)) { | 337 password_generation_agent_->FocusedNodeHasChanged(focused_element)) { |
| 340 is_generation_popup_possibly_visible_ = true; | 338 is_generation_popup_possibly_visible_ = true; |
| 341 is_popup_possibly_visible_ = true; | 339 is_popup_possibly_visible_ = true; |
| 342 } | 340 } |
| 343 } | 341 } |
| 344 | 342 |
| 345 void AutofillAgent::didRequestAutocomplete( | |
| 346 const WebFormElement& form) { | |
| 347 DCHECK_EQ(form.document().frame(), render_frame()->GetWebFrame()); | |
| 348 | |
| 349 // Disallow the dialog over non-https or broken https, except when the | |
| 350 // ignore SSL flag is passed. See http://crbug.com/272512. | |
| 351 // TODO(palmer): this should be moved to the browser process after frames | |
| 352 // get their own processes. | |
| 353 GURL url(form.document().url()); | |
| 354 content::SSLStatus ssl_status = | |
| 355 render_frame()->GetRenderView()->GetSSLStatusOfFrame( | |
| 356 form.document().frame()); | |
| 357 bool is_safe = url.SchemeIsCryptographic() && | |
| 358 !net::IsCertStatusError(ssl_status.cert_status); | |
| 359 bool allow_unsafe = base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 360 ::switches::kReduceSecurityForTesting); | |
| 361 FormData form_data; | |
| 362 std::string error_message; | |
| 363 if (!in_flight_request_form_.isNull()) { | |
| 364 error_message = "already active."; | |
| 365 } else if (!is_safe && !allow_unsafe) { | |
| 366 error_message = | |
| 367 "must use a secure connection or --reduce-security-for-testing."; | |
| 368 } else if (!WebFormElementToFormData( | |
| 369 form, WebFormControlElement(), | |
| 370 static_cast<form_util::ExtractMask>( | |
| 371 form_util::EXTRACT_VALUE | form_util::EXTRACT_OPTION_TEXT | | |
| 372 form_util::EXTRACT_OPTIONS), | |
| 373 &form_data, NULL)) { | |
| 374 error_message = "failed to parse form."; | |
| 375 } | |
| 376 | |
| 377 if (!error_message.empty()) { | |
| 378 WebConsoleMessage console_message = WebConsoleMessage( | |
| 379 WebConsoleMessage::LevelLog, | |
| 380 WebString(base::ASCIIToUTF16("requestAutocomplete: ") + | |
| 381 base::ASCIIToUTF16(error_message))); | |
| 382 form.document().frame()->addMessageToConsole(console_message); | |
| 383 WebFormElement(form).finishRequestAutocomplete( | |
| 384 WebFormElement::AutocompleteResultErrorDisabled); | |
| 385 return; | |
| 386 } | |
| 387 | |
| 388 // Cancel any pending Autofill requests and hide any currently showing popups. | |
| 389 ++autofill_query_id_; | |
| 390 HidePopup(); | |
| 391 | |
| 392 in_flight_request_form_ = form; | |
| 393 Send(new AutofillHostMsg_RequestAutocomplete(routing_id(), form_data)); | |
| 394 } | |
| 395 | |
| 396 void AutofillAgent::setIgnoreTextChanges(bool ignore) { | 343 void AutofillAgent::setIgnoreTextChanges(bool ignore) { |
| 397 ignore_text_changes_ = ignore; | 344 ignore_text_changes_ = ignore; |
| 398 } | 345 } |
| 399 | 346 |
| 400 void AutofillAgent::FormControlElementClicked( | 347 void AutofillAgent::FormControlElementClicked( |
| 401 const WebFormControlElement& element, | 348 const WebFormControlElement& element, |
| 402 bool was_focused) { | 349 bool was_focused) { |
| 403 // TODO(estade): Remove this check when PageClickTracker is per-frame. | 350 // TODO(estade): Remove this check when PageClickTracker is per-frame. |
| 404 if (element.document().frame() != render_frame()->GetWebFrame()) | 351 if (element.document().frame() != render_frame()->GetWebFrame()) |
| 405 return; | 352 return; |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 657 // removed from the DOM. | 604 // removed from the DOM. |
| 658 if (form_util::AreFormContentsVisible(last_interacted_form_)) | 605 if (form_util::AreFormContentsVisible(last_interacted_form_)) |
| 659 return; | 606 return; |
| 660 | 607 |
| 661 // Could not find a visible form equal to our saved form, assume submission. | 608 // Could not find a visible form equal to our saved form, assume submission. |
| 662 WillSendSubmitEvent(last_interacted_form_); | 609 WillSendSubmitEvent(last_interacted_form_); |
| 663 WillSubmitForm(last_interacted_form_); | 610 WillSubmitForm(last_interacted_form_); |
| 664 last_interacted_form_.reset(); | 611 last_interacted_form_.reset(); |
| 665 } | 612 } |
| 666 | 613 |
| 667 void AutofillAgent::OnRequestAutocompleteResult( | |
| 668 WebFormElement::AutocompleteResult result, | |
| 669 const base::string16& message, | |
| 670 const FormData& form_data) { | |
| 671 if (in_flight_request_form_.isNull()) | |
| 672 return; | |
| 673 | |
| 674 if (result == WebFormElement::AutocompleteResultSuccess) { | |
| 675 form_util::FillFormIncludingNonFocusableElements(form_data, | |
| 676 in_flight_request_form_); | |
| 677 if (!in_flight_request_form_.checkValidity()) | |
| 678 result = WebFormElement::AutocompleteResultErrorInvalid; | |
| 679 } | |
| 680 | |
| 681 in_flight_request_form_.finishRequestAutocomplete(result); | |
| 682 | |
| 683 if (!message.empty()) { | |
| 684 const base::string16 prefix(base::ASCIIToUTF16("requestAutocomplete: ")); | |
| 685 WebConsoleMessage console_message = WebConsoleMessage( | |
| 686 WebConsoleMessage::LevelLog, WebString(prefix + message)); | |
| 687 in_flight_request_form_.document().frame()->addMessageToConsole( | |
| 688 console_message); | |
| 689 } | |
| 690 | |
| 691 in_flight_request_form_.reset(); | |
| 692 } | |
| 693 | |
| 694 void AutofillAgent::ShowSuggestions(const WebFormControlElement& element, | 614 void AutofillAgent::ShowSuggestions(const WebFormControlElement& element, |
| 695 const ShowSuggestionsOptions& options) { | 615 const ShowSuggestionsOptions& options) { |
| 696 if (!element.isEnabled() || element.isReadOnly()) | 616 if (!element.isEnabled() || element.isReadOnly()) |
| 697 return; | 617 return; |
| 698 if (!element.suggestedValue().isEmpty()) | 618 if (!element.suggestedValue().isEmpty()) |
| 699 return; | 619 return; |
| 700 | 620 |
| 701 const WebInputElement* input_element = toWebInputElement(&element); | 621 const WebInputElement* input_element = toWebInputElement(&element); |
| 702 if (input_element) { | 622 if (input_element) { |
| 703 if (!input_element->isTextField()) | 623 if (!input_element->isTextField()) |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 879 void AutofillAgent::LegacyAutofillAgent::OnDestruct() { | 799 void AutofillAgent::LegacyAutofillAgent::OnDestruct() { |
| 880 // No-op. Don't delete |this|. | 800 // No-op. Don't delete |this|. |
| 881 } | 801 } |
| 882 | 802 |
| 883 void AutofillAgent::LegacyAutofillAgent::FocusChangeComplete() { | 803 void AutofillAgent::LegacyAutofillAgent::FocusChangeComplete() { |
| 884 if (agent_) | 804 if (agent_) |
| 885 agent_->FocusChangeComplete(); | 805 agent_->FocusChangeComplete(); |
| 886 } | 806 } |
| 887 | 807 |
| 888 } // namespace autofill | 808 } // namespace autofill |
| OLD | NEW |