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

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

Issue 2180093002: [Autofill] Switch on use_new_wrapper_types mode. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add gyp Created 4 years, 4 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 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 24 matching lines...) Expand all
35 #include "components/autofill/core/common/form_data_predictions.h" 35 #include "components/autofill/core/common/form_data_predictions.h"
36 #include "components/autofill/core/common/form_field_data.h" 36 #include "components/autofill/core/common/form_field_data.h"
37 #include "components/autofill/core/common/password_form.h" 37 #include "components/autofill/core/common/password_form.h"
38 #include "components/autofill/core/common/password_form_fill_data.h" 38 #include "components/autofill/core/common/password_form_fill_data.h"
39 #include "components/autofill/core/common/save_password_progress_logger.h" 39 #include "components/autofill/core/common/save_password_progress_logger.h"
40 #include "content/public/common/content_switches.h" 40 #include "content/public/common/content_switches.h"
41 #include "content/public/common/ssl_status.h" 41 #include "content/public/common/ssl_status.h"
42 #include "content/public/common/url_constants.h" 42 #include "content/public/common/url_constants.h"
43 #include "content/public/renderer/render_frame.h" 43 #include "content/public/renderer/render_frame.h"
44 #include "content/public/renderer/render_view.h" 44 #include "content/public/renderer/render_view.h"
45 #include "mojo/common/common_type_converters.h"
46 #include "net/cert/cert_status_flags.h" 45 #include "net/cert/cert_status_flags.h"
47 #include "services/shell/public/cpp/interface_provider.h" 46 #include "services/shell/public/cpp/interface_provider.h"
48 #include "services/shell/public/cpp/interface_registry.h" 47 #include "services/shell/public/cpp/interface_registry.h"
49 #include "third_party/WebKit/public/platform/WebURLRequest.h" 48 #include "third_party/WebKit/public/platform/WebURLRequest.h"
50 #include "third_party/WebKit/public/web/WebConsoleMessage.h" 49 #include "third_party/WebKit/public/web/WebConsoleMessage.h"
51 #include "third_party/WebKit/public/web/WebDataSource.h" 50 #include "third_party/WebKit/public/web/WebDataSource.h"
52 #include "third_party/WebKit/public/web/WebDocument.h" 51 #include "third_party/WebKit/public/web/WebDocument.h"
53 #include "third_party/WebKit/public/web/WebElementCollection.h" 52 #include "third_party/WebKit/public/web/WebElementCollection.h"
54 #include "third_party/WebKit/public/web/WebFormControlElement.h" 53 #include "third_party/WebKit/public/web/WebFormControlElement.h"
55 #include "third_party/WebKit/public/web/WebFormElement.h" 54 #include "third_party/WebKit/public/web/WebFormElement.h"
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 form_util::PreviewForm(form, element_); 506 form_util::PreviewForm(form, element_);
508 507
509 GetAutofillDriver()->DidPreviewAutofillFormData(); 508 GetAutofillDriver()->DidPreviewAutofillFormData();
510 } 509 }
511 510
512 void AutofillAgent::OnPing() { 511 void AutofillAgent::OnPing() {
513 GetAutofillDriver()->PingAck(); 512 GetAutofillDriver()->PingAck();
514 } 513 }
515 514
516 void AutofillAgent::FieldTypePredictionsAvailable( 515 void AutofillAgent::FieldTypePredictionsAvailable(
517 mojo::Array<FormDataPredictions> forms) { 516 const std::vector<FormDataPredictions>& forms) {
518 for (const auto& form : forms) { 517 for (const auto& form : forms) {
519 form_cache_.ShowPredictions(form); 518 form_cache_.ShowPredictions(form);
520 } 519 }
521 } 520 }
522 521
523 void AutofillAgent::ClearForm() { 522 void AutofillAgent::ClearForm() {
524 form_cache_.ClearFormWithElement(element_); 523 form_cache_.ClearFormWithElement(element_);
525 } 524 }
526 525
527 void AutofillAgent::ClearPreviewedForm() { 526 void AutofillAgent::ClearPreviewedForm() {
528 if (!element_.isNull()) { 527 if (!element_.isNull()) {
529 if (password_autofill_agent_->DidClearAutofillSelection(element_)) 528 if (password_autofill_agent_->DidClearAutofillSelection(element_))
530 return; 529 return;
531 530
532 form_util::ClearPreviewedFormWithElement(element_, 531 form_util::ClearPreviewedFormWithElement(element_,
533 was_query_node_autofilled_); 532 was_query_node_autofilled_);
534 } else { 533 } else {
535 // TODO(isherman): There seem to be rare cases where this code *is* 534 // TODO(isherman): There seem to be rare cases where this code *is*
536 // reachable: see [ http://crbug.com/96321#c6 ]. Ideally we would 535 // reachable: see [ http://crbug.com/96321#c6 ]. Ideally we would
537 // understand those cases and fix the code to avoid them. However, so far I 536 // understand those cases and fix the code to avoid them. However, so far I
538 // have been unable to reproduce such a case locally. If you hit this 537 // have been unable to reproduce such a case locally. If you hit this
539 // NOTREACHED(), please file a bug against me. 538 // NOTREACHED(), please file a bug against me.
540 NOTREACHED(); 539 NOTREACHED();
541 } 540 }
542 } 541 }
543 542
544 void AutofillAgent::FillFieldWithValue(const mojo::String& value) { 543 void AutofillAgent::FillFieldWithValue(const std::string& value) {
545 WebInputElement* input_element = toWebInputElement(&element_); 544 WebInputElement* input_element = toWebInputElement(&element_);
546 if (input_element) { 545 if (input_element) {
547 DoFillFieldWithValue(value.To<base::string16>(), input_element); 546 DoFillFieldWithValue(base::UTF8ToUTF16(value), input_element);
548 input_element->setAutofilled(true); 547 input_element->setAutofilled(true);
549 } 548 }
550 } 549 }
551 550
552 void AutofillAgent::PreviewFieldWithValue(const mojo::String& value) { 551 void AutofillAgent::PreviewFieldWithValue(const std::string& value) {
553 WebInputElement* input_element = toWebInputElement(&element_); 552 WebInputElement* input_element = toWebInputElement(&element_);
554 if (input_element) 553 if (input_element)
555 DoPreviewFieldWithValue(value.To<base::string16>(), input_element); 554 DoPreviewFieldWithValue(base::UTF8ToUTF16(value), input_element);
556 } 555 }
557 556
558 void AutofillAgent::AcceptDataListSuggestion(const mojo::String& value) { 557 void AutofillAgent::AcceptDataListSuggestion(const std::string& value) {
559 DoAcceptDataListSuggestion(value.To<base::string16>()); 558 DoAcceptDataListSuggestion(base::UTF8ToUTF16(value));
560 } 559 }
561 560
562 void AutofillAgent::FillPasswordSuggestion(const mojo::String& username, 561 void AutofillAgent::FillPasswordSuggestion(const std::string& username,
563 const mojo::String& password) { 562 const std::string& password) {
564 bool handled = password_autofill_agent_->FillSuggestion( 563 bool handled = password_autofill_agent_->FillSuggestion(
565 element_, username.To<base::string16>(), password.To<base::string16>()); 564 element_, base::UTF8ToUTF16(username), base::UTF8ToUTF16(password));
566 DCHECK(handled); 565 DCHECK(handled);
567 } 566 }
568 567
569 void AutofillAgent::PreviewPasswordSuggestion(const mojo::String& username, 568 void AutofillAgent::PreviewPasswordSuggestion(const std::string& username,
570 const mojo::String& password) { 569 const std::string& password) {
571 bool handled = password_autofill_agent_->PreviewSuggestion( 570 bool handled = password_autofill_agent_->PreviewSuggestion(
572 element_, username.To<base::string16>(), password.To<base::string16>()); 571 element_, base::UTF8ToUTF16(username), base::UTF8ToUTF16(password));
573 DCHECK(handled); 572 DCHECK(handled);
574 } 573 }
575 574
576 void AutofillAgent::ShowInitialPasswordAccountSuggestions( 575 void AutofillAgent::ShowInitialPasswordAccountSuggestions(
577 int32_t key, 576 int32_t key,
578 const PasswordFormFillData& form_data) { 577 const PasswordFormFillData& form_data) {
579 std::vector<blink::WebInputElement> elements; 578 std::vector<blink::WebInputElement> elements;
580 std::unique_ptr<RendererSavePasswordProgressLogger> logger; 579 std::unique_ptr<RendererSavePasswordProgressLogger> logger;
581 if (password_autofill_agent_->logging_state_active()) { 580 if (password_autofill_agent_->logging_state_active()) {
582 logger.reset(new RendererSavePasswordProgressLogger(this, routing_id())); 581 logger.reset(new RendererSavePasswordProgressLogger(this, routing_id()));
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 // Find the datalist values and send them to the browser process. 727 // Find the datalist values and send them to the browser process.
729 GetDataListSuggestions(*input_element, 728 GetDataListSuggestions(*input_element,
730 &data_list_values, 729 &data_list_values,
731 &data_list_labels); 730 &data_list_labels);
732 TrimStringVectorForIPC(&data_list_values); 731 TrimStringVectorForIPC(&data_list_values);
733 TrimStringVectorForIPC(&data_list_labels); 732 TrimStringVectorForIPC(&data_list_labels);
734 } 733 }
735 734
736 is_popup_possibly_visible_ = true; 735 is_popup_possibly_visible_ = true;
737 736
738 GetAutofillDriver()->SetDataList( 737 std::vector<std::string> values;
yzshen1 2016/07/26 16:45:36 Please reserve space.
leonhsl(Using Gerrit) 2016/07/27 02:50:26 Acknowledged.
leonhsl(Using Gerrit) 2016/07/27 09:25:32 Done. Use base::string16 typemap now, removed thes
739 mojo::Array<mojo::String>::From(data_list_values), 738 for (auto& i : data_list_values)
740 mojo::Array<mojo::String>::From(data_list_labels)); 739 values.emplace_back(base::UTF16ToUTF8(i));
740 std::vector<std::string> labels;
741 for (auto& i : data_list_labels)
742 labels.emplace_back(base::UTF16ToUTF8(i));
743 GetAutofillDriver()->SetDataList(values, labels);
741 GetAutofillDriver()->QueryFormFieldAutofill( 744 GetAutofillDriver()->QueryFormFieldAutofill(
742 autofill_query_id_, form, field, 745 autofill_query_id_, form, field,
743 render_frame()->GetRenderView()->ElementBoundsInWindow(element_)); 746 render_frame()->GetRenderView()->ElementBoundsInWindow(element_));
744 } 747 }
745 748
746 void AutofillAgent::DoFillFieldWithValue(const base::string16& value, 749 void AutofillAgent::DoFillFieldWithValue(const base::string16& value,
747 WebInputElement* node) { 750 WebInputElement* node) {
748 base::AutoReset<bool> auto_reset(&ignore_text_changes_, true); 751 base::AutoReset<bool> auto_reset(&ignore_text_changes_, true);
749 node->setEditingValue(value.substr(0, node->maxLength())); 752 node->setEditingValue(value.substr(0, node->maxLength()));
750 } 753 }
751 754
752 void AutofillAgent::DoPreviewFieldWithValue(const base::string16& value, 755 void AutofillAgent::DoPreviewFieldWithValue(const base::string16& value,
753 WebInputElement* node) { 756 WebInputElement* node) {
754 was_query_node_autofilled_ = element_.isAutofilled(); 757 was_query_node_autofilled_ = element_.isAutofilled();
755 node->setSuggestedValue(value.substr(0, node->maxLength())); 758 node->setSuggestedValue(value.substr(0, node->maxLength()));
756 node->setAutofilled(true); 759 node->setAutofilled(true);
757 form_util::PreviewSuggestion(node->suggestedValue(), node->value(), node); 760 form_util::PreviewSuggestion(node->suggestedValue(), node->value(), node);
758 } 761 }
759 762
760 void AutofillAgent::ProcessForms() { 763 void AutofillAgent::ProcessForms() {
761 // Record timestamp of when the forms are first seen. This is used to 764 // Record timestamp of when the forms are first seen. This is used to
762 // measure the overhead of the Autofill feature. 765 // measure the overhead of the Autofill feature.
763 base::TimeTicks forms_seen_timestamp = base::TimeTicks::Now(); 766 base::TimeTicks forms_seen_timestamp = base::TimeTicks::Now();
764 767
765 WebLocalFrame* frame = render_frame()->GetWebFrame(); 768 WebLocalFrame* frame = render_frame()->GetWebFrame();
766 std::vector<FormData> forms = form_cache_.ExtractNewForms(); 769 std::vector<FormData> forms = form_cache_.ExtractNewForms();
767 770
768 // Always communicate to browser process for topmost frame. 771 // Always communicate to browser process for topmost frame.
769 if (!forms.empty() || !frame->parent()) { 772 if (!forms.empty() || !frame->parent()) {
770 GetAutofillDriver()->FormsSeen(std::move(forms), forms_seen_timestamp); 773 GetAutofillDriver()->FormsSeen(forms, forms_seen_timestamp);
771 } 774 }
772 } 775 }
773 776
774 void AutofillAgent::HidePopup() { 777 void AutofillAgent::HidePopup() {
775 if (!is_popup_possibly_visible_) 778 if (!is_popup_possibly_visible_)
776 return; 779 return;
777 is_popup_possibly_visible_ = false; 780 is_popup_possibly_visible_ = false;
778 is_generation_popup_possibly_visible_ = false; 781 is_generation_popup_possibly_visible_ = false;
779 782
780 GetAutofillDriver()->HidePopup(); 783 GetAutofillDriver()->HidePopup();
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
833 void AutofillAgent::LegacyAutofillAgent::OnDestruct() { 836 void AutofillAgent::LegacyAutofillAgent::OnDestruct() {
834 // No-op. Don't delete |this|. 837 // No-op. Don't delete |this|.
835 } 838 }
836 839
837 void AutofillAgent::LegacyAutofillAgent::FocusChangeComplete() { 840 void AutofillAgent::LegacyAutofillAgent::FocusChangeComplete() {
838 if (agent_) 841 if (agent_)
839 agent_->FocusChangeComplete(); 842 agent_->FocusChangeComplete();
840 } 843 }
841 844
842 } // namespace autofill 845 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698