| 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 |
| 11 #include "base/auto_reset.h" | 11 #include "base/auto_reset.h" |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/i18n/case_conversion.h" | 14 #include "base/i18n/case_conversion.h" |
| 15 #include "base/location.h" | 15 #include "base/location.h" |
| 16 #include "base/metrics/field_trial.h" | 16 #include "base/metrics/field_trial.h" |
| 17 #include "base/single_thread_task_runner.h" | 17 #include "base/single_thread_task_runner.h" |
| 18 #include "base/strings/string_piece.h" | 18 #include "base/strings/string_piece.h" |
| 19 #include "base/strings/string_split.h" | 19 #include "base/strings/string_split.h" |
| 20 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
| 21 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
| 22 #include "base/threading/thread_task_runner_handle.h" | 22 #include "base/threading/thread_task_runner_handle.h" |
| 23 #include "base/time/time.h" | 23 #include "base/time/time.h" |
| 24 #include "build/build_config.h" | 24 #include "build/build_config.h" |
| 25 #include "components/autofill/content/renderer/form_autofill_util.h" | 25 #include "components/autofill/content/renderer/form_autofill_util.h" |
| 26 #include "components/autofill/content/renderer/page_click_tracker.h" | |
| 27 #include "components/autofill/content/renderer/password_autofill_agent.h" | 26 #include "components/autofill/content/renderer/password_autofill_agent.h" |
| 28 #include "components/autofill/content/renderer/password_generation_agent.h" | 27 #include "components/autofill/content/renderer/password_generation_agent.h" |
| 29 #include "components/autofill/content/renderer/renderer_save_password_progress_l
ogger.h" | 28 #include "components/autofill/content/renderer/renderer_save_password_progress_l
ogger.h" |
| 30 #include "components/autofill/core/common/autofill_constants.h" | 29 #include "components/autofill/core/common/autofill_constants.h" |
| 31 #include "components/autofill/core/common/autofill_data_validation.h" | 30 #include "components/autofill/core/common/autofill_data_validation.h" |
| 32 #include "components/autofill/core/common/autofill_switches.h" | 31 #include "components/autofill/core/common/autofill_switches.h" |
| 33 #include "components/autofill/core/common/autofill_util.h" | 32 #include "components/autofill/core/common/autofill_util.h" |
| 34 #include "components/autofill/core/common/form_data.h" | 33 #include "components/autofill/core/common/form_data.h" |
| 35 #include "components/autofill/core/common/form_data_predictions.h" | 34 #include "components/autofill/core/common/form_data_predictions.h" |
| 36 #include "components/autofill/core/common/form_field_data.h" | 35 #include "components/autofill/core/common/form_field_data.h" |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 show_password_suggestions_only(false) { | 140 show_password_suggestions_only(false) { |
| 142 } | 141 } |
| 143 | 142 |
| 144 AutofillAgent::AutofillAgent(content::RenderFrame* render_frame, | 143 AutofillAgent::AutofillAgent(content::RenderFrame* render_frame, |
| 145 PasswordAutofillAgent* password_autofill_agent, | 144 PasswordAutofillAgent* password_autofill_agent, |
| 146 PasswordGenerationAgent* password_generation_agent) | 145 PasswordGenerationAgent* password_generation_agent) |
| 147 : content::RenderFrameObserver(render_frame), | 146 : content::RenderFrameObserver(render_frame), |
| 148 form_cache_(*render_frame->GetWebFrame()), | 147 form_cache_(*render_frame->GetWebFrame()), |
| 149 password_autofill_agent_(password_autofill_agent), | 148 password_autofill_agent_(password_autofill_agent), |
| 150 password_generation_agent_(password_generation_agent), | 149 password_generation_agent_(password_generation_agent), |
| 151 legacy_(render_frame->GetRenderView(), this), | |
| 152 autofill_query_id_(0), | 150 autofill_query_id_(0), |
| 153 was_query_node_autofilled_(false), | 151 was_query_node_autofilled_(false), |
| 154 ignore_text_changes_(false), | 152 ignore_text_changes_(false), |
| 155 is_popup_possibly_visible_(false), | 153 is_popup_possibly_visible_(false), |
| 156 is_generation_popup_possibly_visible_(false), | 154 is_generation_popup_possibly_visible_(false), |
| 155 page_click_tracker_(new PageClickTracker(render_frame, this)), |
| 157 binding_(this), | 156 binding_(this), |
| 158 weak_ptr_factory_(this) { | 157 weak_ptr_factory_(this) { |
| 159 render_frame->GetWebFrame()->SetAutofillClient(this); | 158 render_frame->GetWebFrame()->SetAutofillClient(this); |
| 160 password_autofill_agent->SetAutofillAgent(this); | 159 password_autofill_agent->SetAutofillAgent(this); |
| 161 | 160 |
| 162 // AutofillAgent is guaranteed to outlive |render_frame|. | 161 // AutofillAgent is guaranteed to outlive |render_frame|. |
| 163 render_frame->GetInterfaceRegistry()->AddInterface( | 162 render_frame->GetInterfaceRegistry()->AddInterface( |
| 164 base::Bind(&AutofillAgent::BindRequest, base::Unretained(this))); | 163 base::Bind(&AutofillAgent::BindRequest, base::Unretained(this))); |
| 165 | |
| 166 // This owns itself, and will delete itself when |render_frame| is destructed | |
| 167 // (same as AutofillAgent). This object must be constructed after | |
| 168 // AutofillAgent so that password generation UI is shown before password | |
| 169 // manager UI (see https://crbug.com/498545). | |
| 170 new PageClickTracker(render_frame, this); | |
| 171 } | 164 } |
| 172 | 165 |
| 173 AutofillAgent::~AutofillAgent() {} | 166 AutofillAgent::~AutofillAgent() {} |
| 174 | 167 |
| 175 void AutofillAgent::BindRequest(mojom::AutofillAgentRequest request) { | 168 void AutofillAgent::BindRequest(mojom::AutofillAgentRequest request) { |
| 176 binding_.Bind(std::move(request)); | 169 binding_.Bind(std::move(request)); |
| 177 } | 170 } |
| 178 | 171 |
| 179 bool AutofillAgent::FormDataCompare::operator()(const FormData& lhs, | 172 bool AutofillAgent::FormDataCompare::operator()(const FormData& lhs, |
| 180 const FormData& rhs) const { | 173 const FormData& rhs) const { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 } | 207 } |
| 215 | 208 |
| 216 void AutofillAgent::DidChangeScrollOffset() { | 209 void AutofillAgent::DidChangeScrollOffset() { |
| 217 if (IsKeyboardAccessoryEnabled()) | 210 if (IsKeyboardAccessoryEnabled()) |
| 218 return; | 211 return; |
| 219 | 212 |
| 220 HidePopup(); | 213 HidePopup(); |
| 221 } | 214 } |
| 222 | 215 |
| 223 void AutofillAgent::FocusedNodeChanged(const WebNode& node) { | 216 void AutofillAgent::FocusedNodeChanged(const WebNode& node) { |
| 217 page_click_tracker_->FocusedNodeChanged(node); |
| 218 |
| 224 HidePopup(); | 219 HidePopup(); |
| 225 | 220 |
| 226 if (node.IsNull() || !node.IsElementNode()) { | 221 if (node.IsNull() || !node.IsElementNode()) { |
| 227 if (!last_interacted_form_.IsNull()) { | 222 if (!last_interacted_form_.IsNull()) { |
| 228 // Focus moved away from the last interacted form to somewhere else on | 223 // Focus moved away from the last interacted form to somewhere else on |
| 229 // the page. | 224 // the page. |
| 230 GetAutofillDriver()->FocusNoLongerOnForm(); | 225 GetAutofillDriver()->FocusNoLongerOnForm(); |
| 231 } | 226 } |
| 232 return; | 227 return; |
| 233 } | 228 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 submitted_forms_.insert(form_data); | 269 submitted_forms_.insert(form_data); |
| 275 } | 270 } |
| 276 | 271 |
| 277 if (form_submitted) { | 272 if (form_submitted) { |
| 278 GetAutofillDriver()->FormSubmitted(form_data); | 273 GetAutofillDriver()->FormSubmitted(form_data); |
| 279 } | 274 } |
| 280 } | 275 } |
| 281 | 276 |
| 282 void AutofillAgent::Shutdown() { | 277 void AutofillAgent::Shutdown() { |
| 283 binding_.Close(); | 278 binding_.Close(); |
| 284 legacy_.Shutdown(); | |
| 285 weak_ptr_factory_.InvalidateWeakPtrs(); | 279 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 286 } | 280 } |
| 287 | 281 |
| 288 void AutofillAgent::FocusChangeComplete() { | |
| 289 WebDocument doc = render_frame()->GetWebFrame()->GetDocument(); | |
| 290 WebElement focused_element; | |
| 291 if (!doc.IsNull()) | |
| 292 focused_element = doc.FocusedElement(); | |
| 293 // PasswordGenerationAgent needs to know about focus changes, even if there is | |
| 294 // no focused element. | |
| 295 if (password_generation_agent_ && | |
| 296 password_generation_agent_->FocusedNodeHasChanged(focused_element)) { | |
| 297 is_generation_popup_possibly_visible_ = true; | |
| 298 is_popup_possibly_visible_ = true; | |
| 299 } | |
| 300 if (!focused_element.IsNull() && password_autofill_agent_) | |
| 301 password_autofill_agent_->FocusedNodeHasChanged(focused_element); | |
| 302 } | |
| 303 | 282 |
| 304 void AutofillAgent::FormControlElementClicked( | 283 void AutofillAgent::FormControlElementClicked( |
| 305 const WebFormControlElement& element, | 284 const WebFormControlElement& element, |
| 306 bool was_focused) { | 285 bool was_focused) { |
| 307 // TODO(estade): Remove this check when PageClickTracker is per-frame. | |
| 308 if (element.GetDocument().GetFrame() != render_frame()->GetWebFrame()) | |
| 309 return; | |
| 310 | |
| 311 const WebInputElement* input_element = ToWebInputElement(&element); | 286 const WebInputElement* input_element = ToWebInputElement(&element); |
| 312 if (!input_element && !form_util::IsTextAreaElement(element)) | 287 if (!input_element && !form_util::IsTextAreaElement(element)) |
| 313 return; | 288 return; |
| 314 | 289 |
| 315 ShowSuggestionsOptions options; | 290 ShowSuggestionsOptions options; |
| 316 options.autofill_on_empty_values = true; | 291 options.autofill_on_empty_values = true; |
| 317 options.show_full_suggestion_list = element.IsAutofilled(); | 292 options.show_full_suggestion_list = element.IsAutofilled(); |
| 318 | 293 |
| 319 if (!IsSingleClickEnabled()) { | 294 if (!IsSingleClickEnabled()) { |
| 320 // Show full suggestions when clicking on an already-focused form field. On | 295 // Show full suggestions when clicking on an already-focused form field. On |
| (...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 767 // Frame is only processed if it has finished loading, otherwise you can end | 742 // Frame is only processed if it has finished loading, otherwise you can end |
| 768 // up with a partially parsed form. | 743 // up with a partially parsed form. |
| 769 if (frame && !frame->IsLoading()) { | 744 if (frame && !frame->IsLoading()) { |
| 770 ProcessForms(); | 745 ProcessForms(); |
| 771 password_autofill_agent_->OnDynamicFormsSeen(); | 746 password_autofill_agent_->OnDynamicFormsSeen(); |
| 772 if (password_generation_agent_) | 747 if (password_generation_agent_) |
| 773 password_generation_agent_->OnDynamicFormsSeen(); | 748 password_generation_agent_->OnDynamicFormsSeen(); |
| 774 } | 749 } |
| 775 } | 750 } |
| 776 | 751 |
| 752 void AutofillAgent::DidCompleteFocusChangeInFrame() { |
| 753 WebDocument doc = render_frame()->GetWebFrame()->GetDocument(); |
| 754 WebElement focused_element; |
| 755 if (!doc.IsNull()) |
| 756 focused_element = doc.FocusedElement(); |
| 757 // PasswordGenerationAgent needs to know about focus changes, even if there is |
| 758 // no focused element. |
| 759 if (password_generation_agent_ && |
| 760 password_generation_agent_->FocusedNodeHasChanged(focused_element)) { |
| 761 is_generation_popup_possibly_visible_ = true; |
| 762 is_popup_possibly_visible_ = true; |
| 763 } |
| 764 if (!focused_element.IsNull() && password_autofill_agent_) |
| 765 password_autofill_agent_->FocusedNodeHasChanged(focused_element); |
| 766 |
| 767 // PageClickTracker needs to be notified after |
| 768 // |is_generation_popup_possibly_visible_| has been updated. |
| 769 page_click_tracker_->DidCompleteFocusChangeInFrame(); |
| 770 } |
| 771 |
| 772 void AutofillAgent::DidReceiveLeftMouseDownOrGestureTapInNode( |
| 773 const WebNode& node) { |
| 774 page_click_tracker_->DidReceiveLeftMouseDownOrGestureTapInNode(node); |
| 775 } |
| 776 |
| 777 void AutofillAgent::AjaxSucceeded() { | 777 void AutofillAgent::AjaxSucceeded() { |
| 778 OnSameDocumentNavigationCompleted(); | 778 OnSameDocumentNavigationCompleted(); |
| 779 password_autofill_agent_->AJAXSucceeded(); | 779 password_autofill_agent_->AJAXSucceeded(); |
| 780 } | 780 } |
| 781 | 781 |
| 782 const mojom::AutofillDriverPtr& AutofillAgent::GetAutofillDriver() { | 782 const mojom::AutofillDriverPtr& AutofillAgent::GetAutofillDriver() { |
| 783 if (!autofill_driver_) { | 783 if (!autofill_driver_) { |
| 784 render_frame()->GetRemoteInterfaces()->GetInterface( | 784 render_frame()->GetRemoteInterfaces()->GetInterface( |
| 785 mojo::MakeRequest(&autofill_driver_)); | 785 mojo::MakeRequest(&autofill_driver_)); |
| 786 } | 786 } |
| 787 | 787 |
| 788 return autofill_driver_; | 788 return autofill_driver_; |
| 789 } | 789 } |
| 790 | 790 |
| 791 const mojom::PasswordManagerDriverPtr& | 791 const mojom::PasswordManagerDriverPtr& |
| 792 AutofillAgent::GetPasswordManagerDriver() { | 792 AutofillAgent::GetPasswordManagerDriver() { |
| 793 DCHECK(password_autofill_agent_); | 793 DCHECK(password_autofill_agent_); |
| 794 return password_autofill_agent_->GetPasswordManagerDriver(); | 794 return password_autofill_agent_->GetPasswordManagerDriver(); |
| 795 } | 795 } |
| 796 | 796 |
| 797 // LegacyAutofillAgent --------------------------------------------------------- | |
| 798 | |
| 799 AutofillAgent::LegacyAutofillAgent::LegacyAutofillAgent( | |
| 800 content::RenderView* render_view, | |
| 801 AutofillAgent* agent) | |
| 802 : content::RenderViewObserver(render_view), agent_(agent) { | |
| 803 } | |
| 804 | |
| 805 AutofillAgent::LegacyAutofillAgent::~LegacyAutofillAgent() { | |
| 806 } | |
| 807 | |
| 808 void AutofillAgent::LegacyAutofillAgent::Shutdown() { | |
| 809 agent_ = nullptr; | |
| 810 } | |
| 811 | |
| 812 void AutofillAgent::LegacyAutofillAgent::OnDestruct() { | |
| 813 // No-op. Don't delete |this|. | |
| 814 } | |
| 815 | |
| 816 void AutofillAgent::LegacyAutofillAgent::FocusChangeComplete() { | |
| 817 if (agent_) | |
| 818 agent_->FocusChangeComplete(); | |
| 819 } | |
| 820 | |
| 821 } // namespace autofill | 797 } // namespace autofill |
| OLD | NEW |