| 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 #ifndef COMPONENTS_AUTOFILL_CONTENT_RENDERER_AUTOFILL_AGENT_H_ | 5 #ifndef COMPONENTS_AUTOFILL_CONTENT_RENDERER_AUTOFILL_AGENT_H_ |
| 6 #define COMPONENTS_AUTOFILL_CONTENT_RENDERER_AUTOFILL_AGENT_H_ | 6 #define COMPONENTS_AUTOFILL_CONTENT_RENDERER_AUTOFILL_AGENT_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 15 #include "components/autofill/content/public/interfaces/autofill_agent.mojom.h" | 15 #include "components/autofill/content/public/interfaces/autofill_agent.mojom.h" |
| 16 #include "components/autofill/content/public/interfaces/autofill_driver.mojom.h" | 16 #include "components/autofill/content/public/interfaces/autofill_driver.mojom.h" |
| 17 #include "components/autofill/content/renderer/form_cache.h" | 17 #include "components/autofill/content/renderer/form_cache.h" |
| 18 #include "components/autofill/content/renderer/page_click_listener.h" | 18 #include "components/autofill/content/renderer/page_click_listener.h" |
| 19 #include "content/public/renderer/render_frame_observer.h" | 19 #include "content/public/renderer/render_frame_observer.h" |
| 20 #include "content/public/renderer/render_view_observer.h" | 20 #include "content/public/renderer/render_view_observer.h" |
| 21 #include "mojo/public/cpp/bindings/binding_set.h" | 21 #include "mojo/public/cpp/bindings/binding.h" |
| 22 #include "third_party/WebKit/public/web/WebAutofillClient.h" | 22 #include "third_party/WebKit/public/web/WebAutofillClient.h" |
| 23 #include "third_party/WebKit/public/web/WebFormControlElement.h" | 23 #include "third_party/WebKit/public/web/WebFormControlElement.h" |
| 24 #include "third_party/WebKit/public/web/WebFormElement.h" | 24 #include "third_party/WebKit/public/web/WebFormElement.h" |
| 25 #include "third_party/WebKit/public/web/WebInputElement.h" | 25 #include "third_party/WebKit/public/web/WebInputElement.h" |
| 26 | 26 |
| 27 namespace blink { | 27 namespace blink { |
| 28 class WebNode; | 28 class WebNode; |
| 29 class WebView; | 29 class WebView; |
| 30 } | 30 } |
| 31 | 31 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 52 // PasswordAutofillAgent is guaranteed to outlive AutofillAgent. | 52 // PasswordAutofillAgent is guaranteed to outlive AutofillAgent. |
| 53 // PasswordGenerationAgent may be NULL. If it is not, then it is also | 53 // PasswordGenerationAgent may be NULL. If it is not, then it is also |
| 54 // guaranteed to outlive AutofillAgent. | 54 // guaranteed to outlive AutofillAgent. |
| 55 AutofillAgent(content::RenderFrame* render_frame, | 55 AutofillAgent(content::RenderFrame* render_frame, |
| 56 PasswordAutofillAgent* password_autofill_manager, | 56 PasswordAutofillAgent* password_autofill_manager, |
| 57 PasswordGenerationAgent* password_generation_agent); | 57 PasswordGenerationAgent* password_generation_agent); |
| 58 ~AutofillAgent() override; | 58 ~AutofillAgent() override; |
| 59 | 59 |
| 60 void BindRequest(mojom::AutofillAgentRequest request); | 60 void BindRequest(mojom::AutofillAgentRequest request); |
| 61 | 61 |
| 62 const mojom::AutofillDriverPtr& GetMojoAutofillDriver(); |
| 63 |
| 64 // mojom::AutofillAgent: |
| 65 void FirstUserGestureObservedInTab() override; |
| 66 void FillForm(int32_t id, const FormData& form) override; |
| 67 void PreviewForm(int32_t id, const FormData& form) override; |
| 68 void FieldTypePredictionsAvailable( |
| 69 mojo::Array<FormDataPredictions> forms) override; |
| 70 void ClearForm() override; |
| 71 void ClearPreviewedForm() override; |
| 72 void FillFieldWithValue(const mojo::String& value) override; |
| 73 void PreviewFieldWithValue(const mojo::String& value) override; |
| 74 void AcceptDataListSuggestion(const mojo::String& value) override; |
| 75 void FillPasswordSuggestion(const mojo::String& username, |
| 76 const mojo::String& password) override; |
| 77 void PreviewPasswordSuggestion(const mojo::String& username, |
| 78 const mojo::String& password) override; |
| 79 void ShowInitialPasswordAccountSuggestions( |
| 80 int32_t key, |
| 81 const PasswordFormFillData& form_data) override; |
| 82 |
| 62 private: | 83 private: |
| 63 // Functor used as a simplified comparison function for FormData. Only | 84 // Functor used as a simplified comparison function for FormData. Only |
| 64 // compares forms at a high level (notably name, origin, action). | 85 // compares forms at a high level (notably name, origin, action). |
| 65 struct FormDataCompare { | 86 struct FormDataCompare { |
| 66 bool operator()(const FormData& lhs, const FormData& rhs) const; | 87 bool operator()(const FormData& lhs, const FormData& rhs) const; |
| 67 }; | 88 }; |
| 68 | 89 |
| 69 // Thunk class for RenderViewObserver methods that haven't yet been migrated | 90 // Thunk class for RenderViewObserver methods that haven't yet been migrated |
| 70 // to RenderFrameObserver. Should eventually be removed. | 91 // to RenderFrameObserver. Should eventually be removed. |
| 71 // http://crbug.com/433486 | 92 // http://crbug.com/433486 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 // be elided because of the current value of |element| (relevant for inline | 132 // be elided because of the current value of |element| (relevant for inline |
| 112 // autocomplete). | 133 // autocomplete). |
| 113 bool show_full_suggestion_list; | 134 bool show_full_suggestion_list; |
| 114 | 135 |
| 115 // Specifies that only show a suggestions box if |element| is part of a | 136 // Specifies that only show a suggestions box if |element| is part of a |
| 116 // password form, otherwise show no suggestions. | 137 // password form, otherwise show no suggestions. |
| 117 bool show_password_suggestions_only; | 138 bool show_password_suggestions_only; |
| 118 }; | 139 }; |
| 119 | 140 |
| 120 // content::RenderFrameObserver: | 141 // content::RenderFrameObserver: |
| 121 bool OnMessageReceived(const IPC::Message& message) override; | |
| 122 void DidCommitProvisionalLoad(bool is_new_navigation, | 142 void DidCommitProvisionalLoad(bool is_new_navigation, |
| 123 bool is_same_page_navigation) override; | 143 bool is_same_page_navigation) override; |
| 124 void DidFinishDocumentLoad() override; | 144 void DidFinishDocumentLoad() override; |
| 125 void WillSendSubmitEvent(const blink::WebFormElement& form) override; | 145 void WillSendSubmitEvent(const blink::WebFormElement& form) override; |
| 126 void WillSubmitForm(const blink::WebFormElement& form) override; | 146 void WillSubmitForm(const blink::WebFormElement& form) override; |
| 127 void DidChangeScrollOffset() override; | 147 void DidChangeScrollOffset() override; |
| 128 void FocusedNodeChanged(const blink::WebNode& node) override; | 148 void FocusedNodeChanged(const blink::WebNode& node) override; |
| 129 void OnDestruct() override; | 149 void OnDestruct() override; |
| 130 | 150 |
| 131 // Fires IPC messages for a given form submission. Will always fire | 151 // Fires IPC messages for a given form submission. Will always fire |
| (...skipping 24 matching lines...) Expand all Loading... |
| 156 const blink::WebInputElement& element, | 176 const blink::WebInputElement& element, |
| 157 const blink::WebKeyboardEvent& event) override; | 177 const blink::WebKeyboardEvent& event) override; |
| 158 void setIgnoreTextChanges(bool ignore) override; | 178 void setIgnoreTextChanges(bool ignore) override; |
| 159 void didAssociateFormControls( | 179 void didAssociateFormControls( |
| 160 const blink::WebVector<blink::WebNode>& nodes) override; | 180 const blink::WebVector<blink::WebNode>& nodes) override; |
| 161 void openTextDataListChooser(const blink::WebInputElement& element) override; | 181 void openTextDataListChooser(const blink::WebInputElement& element) override; |
| 162 void dataListOptionsChanged(const blink::WebInputElement& element) override; | 182 void dataListOptionsChanged(const blink::WebInputElement& element) override; |
| 163 void firstUserGestureObserved() override; | 183 void firstUserGestureObserved() override; |
| 164 void ajaxSucceeded() override; | 184 void ajaxSucceeded() override; |
| 165 | 185 |
| 166 void OnFieldTypePredictionsAvailable( | |
| 167 const std::vector<FormDataPredictions>& forms); | |
| 168 void OnFillForm(int query_id, const FormData& form); | |
| 169 void OnPing(); | 186 void OnPing(); |
| 170 void OnPreviewForm(int query_id, const FormData& form); | |
| 171 | |
| 172 // mojom::AutofillAgent: | |
| 173 void FirstUserGestureObservedInTab() override; | |
| 174 | |
| 175 // For external Autofill selection. | |
| 176 void OnClearForm(); | |
| 177 void OnClearPreviewedForm(); | |
| 178 void OnFillFieldWithValue(const base::string16& value); | |
| 179 void OnPreviewFieldWithValue(const base::string16& value); | |
| 180 void OnAcceptDataListSuggestion(const base::string16& value); | |
| 181 void OnFillPasswordSuggestion(const base::string16& username, | |
| 182 const base::string16& password); | |
| 183 void OnPreviewPasswordSuggestion(const base::string16& username, | |
| 184 const base::string16& password); | |
| 185 void OnShowInitialPasswordAccountSuggestions( | |
| 186 int key, | |
| 187 const PasswordFormFillData& form_data); | |
| 188 | 187 |
| 189 // Called when a same-page navigation is detected. | 188 // Called when a same-page navigation is detected. |
| 190 void OnSamePageNavigationCompleted(); | 189 void OnSamePageNavigationCompleted(); |
| 191 | 190 |
| 192 // Called in a posted task by textFieldDidChange() to work-around a WebKit bug | 191 // Called in a posted task by textFieldDidChange() to work-around a WebKit bug |
| 193 // http://bugs.webkit.org/show_bug.cgi?id=16976 | 192 // http://bugs.webkit.org/show_bug.cgi?id=16976 |
| 194 void TextFieldDidChangeImpl(const blink::WebFormControlElement& element); | 193 void TextFieldDidChangeImpl(const blink::WebFormControlElement& element); |
| 195 | 194 |
| 196 // Shows the autofill suggestions for |element|. This call is asynchronous | 195 // Shows the autofill suggestions for |element|. This call is asynchronous |
| 197 // and may or may not lead to the showing of a suggestion popup (no popup is | 196 // and may or may not lead to the showing of a suggestion popup (no popup is |
| 198 // shown if there are no available suggestions). | 197 // shown if there are no available suggestions). |
| 199 void ShowSuggestions(const blink::WebFormControlElement& element, | 198 void ShowSuggestions(const blink::WebFormControlElement& element, |
| 200 const ShowSuggestionsOptions& options); | 199 const ShowSuggestionsOptions& options); |
| 201 | 200 |
| 202 // Queries the browser for Autocomplete and Autofill suggestions for the given | 201 // Queries the browser for Autocomplete and Autofill suggestions for the given |
| 203 // |element|. | 202 // |element|. |
| 204 void QueryAutofillSuggestions(const blink::WebFormControlElement& element); | 203 void QueryAutofillSuggestions(const blink::WebFormControlElement& element); |
| 205 | 204 |
| 206 // Sets the element value to reflect the selected |suggested_value|. | 205 // Sets the element value to reflect the selected |suggested_value|. |
| 207 void AcceptDataListSuggestion(const base::string16& suggested_value); | 206 void DoAcceptDataListSuggestion(const base::string16& suggested_value); |
| 208 | 207 |
| 209 // Fills |form| and |field| with the FormData and FormField corresponding to | 208 // Fills |form| and |field| with the FormData and FormField corresponding to |
| 210 // |node|. Returns true if the data was found; and false otherwise. | 209 // |node|. Returns true if the data was found; and false otherwise. |
| 211 bool FindFormAndFieldForNode( | 210 bool FindFormAndFieldForNode( |
| 212 const blink::WebNode& node, | 211 const blink::WebNode& node, |
| 213 FormData* form, | 212 FormData* form, |
| 214 FormFieldData* field) WARN_UNUSED_RESULT; | 213 FormFieldData* field) WARN_UNUSED_RESULT; |
| 215 | 214 |
| 216 // Set |node| to display the given |value|. | 215 // Set |node| to display the given |value|. |
| 217 void FillFieldWithValue(const base::string16& value, | 216 void DoFillFieldWithValue(const base::string16& value, |
| 218 blink::WebInputElement* node); | 217 blink::WebInputElement* node); |
| 219 | 218 |
| 220 // Set |node| to display the given |value| as a preview. The preview is | 219 // Set |node| to display the given |value| as a preview. The preview is |
| 221 // visible on screen to the user, but not visible to the page via the DOM or | 220 // visible on screen to the user, but not visible to the page via the DOM or |
| 222 // JavaScript. | 221 // JavaScript. |
| 223 void PreviewFieldWithValue(const base::string16& value, | 222 void DoPreviewFieldWithValue(const base::string16& value, |
| 224 blink::WebInputElement* node); | 223 blink::WebInputElement* node); |
| 225 | 224 |
| 226 // Notifies browser of new fillable forms in |render_frame|. | 225 // Notifies browser of new fillable forms in |render_frame|. |
| 227 void ProcessForms(); | 226 void ProcessForms(); |
| 228 | 227 |
| 229 // Sends a message to the browser that the form is about to be submitted, | 228 // Sends a message to the browser that the form is about to be submitted, |
| 230 // only if the particular message has not been previously submitted for the | 229 // only if the particular message has not been previously submitted for the |
| 231 // form in the current frame. | 230 // form in the current frame. |
| 232 // Additionally, depending on |send_submitted_event| a message is sent to the | 231 // Additionally, depending on |send_submitted_event| a message is sent to the |
| 233 // browser that the form was submitted. | 232 // browser that the form was submitted. |
| 234 void SendFormEvents(const blink::WebFormElement& form, | 233 void SendFormEvents(const blink::WebFormElement& form, |
| 235 bool send_submitted_event); | 234 bool send_submitted_event); |
| 236 | 235 |
| 237 // Hides any currently showing Autofill popup. | 236 // Hides any currently showing Autofill popup. |
| 238 void HidePopup(); | 237 void HidePopup(); |
| 239 | 238 |
| 240 // Returns true if the text field change is due to a user gesture. Can be | 239 // Returns true if the text field change is due to a user gesture. Can be |
| 241 // overriden in tests. | 240 // overriden in tests. |
| 242 virtual bool IsUserGesture() const; | 241 virtual bool IsUserGesture() const; |
| 243 | 242 |
| 244 void ConnectToMojoAutofillDriverIfNeeded(); | |
| 245 | |
| 246 // Formerly cached forms for all frames, now only caches forms for the current | 243 // Formerly cached forms for all frames, now only caches forms for the current |
| 247 // frame. | 244 // frame. |
| 248 FormCache form_cache_; | 245 FormCache form_cache_; |
| 249 | 246 |
| 250 // Keeps track of the forms for which a "will submit" message has been sent in | 247 // Keeps track of the forms for which a "will submit" message has been sent in |
| 251 // this frame's current load. We use a simplified comparison function. | 248 // this frame's current load. We use a simplified comparison function. |
| 252 std::set<FormData, FormDataCompare> submitted_forms_; | 249 std::set<FormData, FormDataCompare> submitted_forms_; |
| 253 | 250 |
| 254 PasswordAutofillAgent* password_autofill_agent_; // Weak reference. | 251 PasswordAutofillAgent* password_autofill_agent_; // Weak reference. |
| 255 PasswordGenerationAgent* password_generation_agent_; // Weak reference. | 252 PasswordGenerationAgent* password_generation_agent_; // Weak reference. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 282 // performance improvement, so that the IPC channel isn't flooded with | 279 // performance improvement, so that the IPC channel isn't flooded with |
| 283 // messages to close the Autofill popup when it can't possibly be showing. | 280 // messages to close the Autofill popup when it can't possibly be showing. |
| 284 bool is_popup_possibly_visible_; | 281 bool is_popup_possibly_visible_; |
| 285 | 282 |
| 286 // If the generation popup is possibly visible. This is tracked to prevent | 283 // If the generation popup is possibly visible. This is tracked to prevent |
| 287 // generation UI from displaying at the same time as password manager UI. | 284 // generation UI from displaying at the same time as password manager UI. |
| 288 // This is needed because generation is shown on field focus vs. field click | 285 // This is needed because generation is shown on field focus vs. field click |
| 289 // for the password manager. TODO(gcasto): Have both UIs show on focus. | 286 // for the password manager. TODO(gcasto): Have both UIs show on focus. |
| 290 bool is_generation_popup_possibly_visible_; | 287 bool is_generation_popup_possibly_visible_; |
| 291 | 288 |
| 292 mojo::BindingSet<mojom::AutofillAgent> bindings_; | 289 mojo::Binding<mojom::AutofillAgent> binding_; |
| 293 | 290 |
| 294 mojom::AutofillDriverPtr mojo_autofill_driver_; | 291 mojom::AutofillDriverPtr mojo_autofill_driver_; |
| 295 | 292 |
| 296 base::WeakPtrFactory<AutofillAgent> weak_ptr_factory_; | 293 base::WeakPtrFactory<AutofillAgent> weak_ptr_factory_; |
| 297 | 294 |
| 298 DISALLOW_COPY_AND_ASSIGN(AutofillAgent); | 295 DISALLOW_COPY_AND_ASSIGN(AutofillAgent); |
| 299 }; | 296 }; |
| 300 | 297 |
| 301 } // namespace autofill | 298 } // namespace autofill |
| 302 | 299 |
| 303 #endif // COMPONENTS_AUTOFILL_CONTENT_RENDERER_AUTOFILL_AGENT_H_ | 300 #endif // COMPONENTS_AUTOFILL_CONTENT_RENDERER_AUTOFILL_AGENT_H_ |
| OLD | NEW |