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 <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.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 "base/timer/timer.h" | 15 #include "base/timer/timer.h" |
16 #include "components/autofill/content/renderer/form_cache.h" | 16 #include "components/autofill/content/renderer/form_cache.h" |
17 #include "components/autofill/content/renderer/page_click_listener.h" | 17 #include "components/autofill/content/renderer/page_click_listener.h" |
18 #include "components/autofill/core/common/forms_seen_state.h" | 18 #include "components/autofill/core/common/forms_seen_state.h" |
19 #include "content/public/renderer/render_view_observer.h" | 19 #include "content/public/renderer/render_view_observer.h" |
20 #include "third_party/WebKit/public/web/WebAutofillClient.h" | 20 #include "third_party/WebKit/public/web/WebAutofillClient.h" |
21 #include "third_party/WebKit/public/web/WebFormElement.h" | 21 #include "third_party/WebKit/public/web/WebFormElement.h" |
22 #include "third_party/WebKit/public/web/WebInputElement.h" | 22 #include "third_party/WebKit/public/web/WebInputElement.h" |
23 | 23 |
24 namespace WebKit { | 24 namespace blink { |
25 class WebNode; | 25 class WebNode; |
26 class WebView; | 26 class WebView; |
27 } | 27 } |
28 | 28 |
29 namespace autofill { | 29 namespace autofill { |
30 | 30 |
31 struct FormData; | 31 struct FormData; |
32 struct FormFieldData; | 32 struct FormFieldData; |
33 struct WebElementDescriptor; | 33 struct WebElementDescriptor; |
34 class PasswordAutofillAgent; | 34 class PasswordAutofillAgent; |
35 | 35 |
36 // AutofillAgent deals with Autofill related communications between WebKit and | 36 // AutofillAgent deals with Autofill related communications between WebKit and |
37 // the browser. There is one AutofillAgent per RenderView. | 37 // the browser. There is one AutofillAgent per RenderView. |
38 // This code was originally part of RenderView. | 38 // This code was originally part of RenderView. |
39 // Note that Autofill encompasses: | 39 // Note that Autofill encompasses: |
40 // - single text field suggestions, that we usually refer to as Autocomplete, | 40 // - single text field suggestions, that we usually refer to as Autocomplete, |
41 // - password form fill, refered to as Password Autofill, and | 41 // - password form fill, refered to as Password Autofill, and |
42 // - entire form fill based on one field entry, referred to as Form Autofill. | 42 // - entire form fill based on one field entry, referred to as Form Autofill. |
43 | 43 |
44 class AutofillAgent : public content::RenderViewObserver, | 44 class AutofillAgent : public content::RenderViewObserver, |
45 public PageClickListener, | 45 public PageClickListener, |
46 public WebKit::WebAutofillClient { | 46 public blink::WebAutofillClient { |
47 public: | 47 public: |
48 // PasswordAutofillAgent is guaranteed to outlive AutofillAgent. | 48 // PasswordAutofillAgent is guaranteed to outlive AutofillAgent. |
49 AutofillAgent(content::RenderView* render_view, | 49 AutofillAgent(content::RenderView* render_view, |
50 PasswordAutofillAgent* password_autofill_manager); | 50 PasswordAutofillAgent* password_autofill_manager); |
51 virtual ~AutofillAgent(); | 51 virtual ~AutofillAgent(); |
52 | 52 |
53 private: | 53 private: |
54 enum AutofillAction { | 54 enum AutofillAction { |
55 AUTOFILL_NONE, // No state set. | 55 AUTOFILL_NONE, // No state set. |
56 AUTOFILL_FILL, // Fill the Autofill form data. | 56 AUTOFILL_FILL, // Fill the Autofill form data. |
57 AUTOFILL_PREVIEW, // Preview the Autofill form data. | 57 AUTOFILL_PREVIEW, // Preview the Autofill form data. |
58 }; | 58 }; |
59 | 59 |
60 // RenderView::Observer: | 60 // RenderView::Observer: |
61 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 61 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
62 virtual void DidFinishDocumentLoad(WebKit::WebFrame* frame) OVERRIDE; | 62 virtual void DidFinishDocumentLoad(blink::WebFrame* frame) OVERRIDE; |
63 virtual void DidCommitProvisionalLoad(WebKit::WebFrame* frame, | 63 virtual void DidCommitProvisionalLoad(blink::WebFrame* frame, |
64 bool is_new_navigation) OVERRIDE; | 64 bool is_new_navigation) OVERRIDE; |
65 virtual void FrameDetached(WebKit::WebFrame* frame) OVERRIDE; | 65 virtual void FrameDetached(blink::WebFrame* frame) OVERRIDE; |
66 virtual void WillSubmitForm(WebKit::WebFrame* frame, | 66 virtual void WillSubmitForm(blink::WebFrame* frame, |
67 const WebKit::WebFormElement& form) OVERRIDE; | 67 const blink::WebFormElement& form) OVERRIDE; |
68 virtual void ZoomLevelChanged() OVERRIDE; | 68 virtual void ZoomLevelChanged() OVERRIDE; |
69 virtual void DidChangeScrollOffset(WebKit::WebFrame* frame) OVERRIDE; | 69 virtual void DidChangeScrollOffset(blink::WebFrame* frame) OVERRIDE; |
70 virtual void FocusedNodeChanged(const WebKit::WebNode& node) OVERRIDE; | 70 virtual void FocusedNodeChanged(const blink::WebNode& node) OVERRIDE; |
71 virtual void OrientationChangeEvent(int orientation) OVERRIDE; | 71 virtual void OrientationChangeEvent(int orientation) OVERRIDE; |
72 | 72 |
73 // PageClickListener: | 73 // PageClickListener: |
74 virtual void InputElementClicked(const WebKit::WebInputElement& element, | 74 virtual void InputElementClicked(const blink::WebInputElement& element, |
75 bool was_focused, | 75 bool was_focused, |
76 bool is_focused) OVERRIDE; | 76 bool is_focused) OVERRIDE; |
77 virtual void InputElementLostFocus() OVERRIDE; | 77 virtual void InputElementLostFocus() OVERRIDE; |
78 | 78 |
79 // WebKit::WebAutofillClient: | 79 // blink::WebAutofillClient: |
80 virtual void didClearAutofillSelection(const WebKit::WebNode& node) OVERRIDE; | 80 virtual void didClearAutofillSelection(const blink::WebNode& node) OVERRIDE; |
81 virtual void textFieldDidEndEditing( | 81 virtual void textFieldDidEndEditing( |
82 const WebKit::WebInputElement& element) OVERRIDE; | 82 const blink::WebInputElement& element) OVERRIDE; |
83 virtual void textFieldDidChange( | 83 virtual void textFieldDidChange( |
84 const WebKit::WebInputElement& element) OVERRIDE; | 84 const blink::WebInputElement& element) OVERRIDE; |
85 virtual void textFieldDidReceiveKeyDown( | 85 virtual void textFieldDidReceiveKeyDown( |
86 const WebKit::WebInputElement& element, | 86 const blink::WebInputElement& element, |
87 const WebKit::WebKeyboardEvent& event) OVERRIDE; | 87 const blink::WebKeyboardEvent& event) OVERRIDE; |
88 virtual void didRequestAutocomplete( | 88 virtual void didRequestAutocomplete( |
89 WebKit::WebFrame* frame, | 89 blink::WebFrame* frame, |
90 const WebKit::WebFormElement& form) OVERRIDE; | 90 const blink::WebFormElement& form) OVERRIDE; |
91 virtual void setIgnoreTextChanges(bool ignore) OVERRIDE; | 91 virtual void setIgnoreTextChanges(bool ignore) OVERRIDE; |
92 virtual void didAssociateFormControls( | 92 virtual void didAssociateFormControls( |
93 const WebKit::WebVector<WebKit::WebNode>& nodes) OVERRIDE; | 93 const blink::WebVector<blink::WebNode>& nodes) OVERRIDE; |
94 | 94 |
95 void OnFormDataFilled(int query_id, const FormData& form); | 95 void OnFormDataFilled(int query_id, const FormData& form); |
96 void OnFieldTypePredictionsAvailable( | 96 void OnFieldTypePredictionsAvailable( |
97 const std::vector<FormDataPredictions>& forms); | 97 const std::vector<FormDataPredictions>& forms); |
98 | 98 |
99 // For external Autofill selection. | 99 // For external Autofill selection. |
100 void OnSetAutofillActionFill(); | 100 void OnSetAutofillActionFill(); |
101 void OnClearForm(); | 101 void OnClearForm(); |
102 void OnSetAutofillActionPreview(); | 102 void OnSetAutofillActionPreview(); |
103 void OnClearPreviewedForm(); | 103 void OnClearPreviewedForm(); |
104 void OnSetNodeText(const base::string16& value); | 104 void OnSetNodeText(const base::string16& value); |
105 void OnAcceptDataListSuggestion(const base::string16& value); | 105 void OnAcceptDataListSuggestion(const base::string16& value); |
106 void OnAcceptPasswordAutofillSuggestion(const base::string16& value); | 106 void OnAcceptPasswordAutofillSuggestion(const base::string16& value); |
107 | 107 |
108 // Called when interactive autocomplete finishes. | 108 // Called when interactive autocomplete finishes. |
109 void OnRequestAutocompleteResult( | 109 void OnRequestAutocompleteResult( |
110 WebKit::WebFormElement::AutocompleteResult result, | 110 blink::WebFormElement::AutocompleteResult result, |
111 const FormData& form_data); | 111 const FormData& form_data); |
112 | 112 |
113 // Called when an autocomplete request succeeds or fails with the |result|. | 113 // Called when an autocomplete request succeeds or fails with the |result|. |
114 void FinishAutocompleteRequest( | 114 void FinishAutocompleteRequest( |
115 WebKit::WebFormElement::AutocompleteResult result); | 115 blink::WebFormElement::AutocompleteResult result); |
116 | 116 |
117 // Called when the page is actually shown in the browser, as opposed to simply | 117 // Called when the page is actually shown in the browser, as opposed to simply |
118 // being preloaded. | 118 // being preloaded. |
119 void OnPageShown(); | 119 void OnPageShown(); |
120 | 120 |
121 // Called in a posted task by textFieldDidChange() to work-around a WebKit bug | 121 // Called in a posted task by textFieldDidChange() to work-around a WebKit bug |
122 // http://bugs.webkit.org/show_bug.cgi?id=16976 | 122 // http://bugs.webkit.org/show_bug.cgi?id=16976 |
123 void TextFieldDidChangeImpl(const WebKit::WebInputElement& element); | 123 void TextFieldDidChangeImpl(const blink::WebInputElement& element); |
124 | 124 |
125 // Shows the autofill suggestions for |element|. | 125 // Shows the autofill suggestions for |element|. |
126 // This call is asynchronous and may or may not lead to the showing of a | 126 // This call is asynchronous and may or may not lead to the showing of a |
127 // suggestion popup (no popup is shown if there are no available suggestions). | 127 // suggestion popup (no popup is shown if there are no available suggestions). |
128 // |autofill_on_empty_values| specifies whether suggestions should be shown | 128 // |autofill_on_empty_values| specifies whether suggestions should be shown |
129 // when |element| contains no text. | 129 // when |element| contains no text. |
130 // |requires_caret_at_end| specifies whether suggestions should be shown when | 130 // |requires_caret_at_end| specifies whether suggestions should be shown when |
131 // the caret is not after the last character in |element|. | 131 // the caret is not after the last character in |element|. |
132 // |display_warning_if_disabled| specifies whether a warning should be | 132 // |display_warning_if_disabled| specifies whether a warning should be |
133 // displayed to the user if Autofill has suggestions available, but cannot | 133 // displayed to the user if Autofill has suggestions available, but cannot |
134 // fill them because it is disabled (e.g. when trying to fill a credit card | 134 // fill them because it is disabled (e.g. when trying to fill a credit card |
135 // form on a non-secure website). | 135 // form on a non-secure website). |
136 void ShowSuggestions(const WebKit::WebInputElement& element, | 136 void ShowSuggestions(const blink::WebInputElement& element, |
137 bool autofill_on_empty_values, | 137 bool autofill_on_empty_values, |
138 bool requires_caret_at_end, | 138 bool requires_caret_at_end, |
139 bool display_warning_if_disabled); | 139 bool display_warning_if_disabled); |
140 | 140 |
141 // Queries the browser for Autocomplete and Autofill suggestions for the given | 141 // Queries the browser for Autocomplete and Autofill suggestions for the given |
142 // |element|. | 142 // |element|. |
143 void QueryAutofillSuggestions(const WebKit::WebInputElement& element, | 143 void QueryAutofillSuggestions(const blink::WebInputElement& element, |
144 bool display_warning_if_disabled); | 144 bool display_warning_if_disabled); |
145 | 145 |
146 // Sets the element value to reflect the selected |suggested_value|. | 146 // Sets the element value to reflect the selected |suggested_value|. |
147 void AcceptDataListSuggestion(const base::string16& suggested_value); | 147 void AcceptDataListSuggestion(const base::string16& suggested_value); |
148 | 148 |
149 // Queries the AutofillManager for form data for the form containing |node|. | 149 // Queries the AutofillManager for form data for the form containing |node|. |
150 // |value| is the current text in the field, and |unique_id| is the selected | 150 // |value| is the current text in the field, and |unique_id| is the selected |
151 // profile's unique ID. |action| specifies whether to Fill or Preview the | 151 // profile's unique ID. |action| specifies whether to Fill or Preview the |
152 // values returned from the AutofillManager. | 152 // values returned from the AutofillManager. |
153 void FillAutofillFormData(const WebKit::WebNode& node, | 153 void FillAutofillFormData(const blink::WebNode& node, |
154 int unique_id, | 154 int unique_id, |
155 AutofillAction action); | 155 AutofillAction action); |
156 | 156 |
157 // Fills |form| and |field| with the FormData and FormField corresponding to | 157 // Fills |form| and |field| with the FormData and FormField corresponding to |
158 // |node|. Returns true if the data was found; and false otherwise. | 158 // |node|. Returns true if the data was found; and false otherwise. |
159 bool FindFormAndFieldForNode( | 159 bool FindFormAndFieldForNode( |
160 const WebKit::WebNode& node, | 160 const blink::WebNode& node, |
161 FormData* form, | 161 FormData* form, |
162 FormFieldData* field) WARN_UNUSED_RESULT; | 162 FormFieldData* field) WARN_UNUSED_RESULT; |
163 | 163 |
164 // Set |node| to display the given |value|. | 164 // Set |node| to display the given |value|. |
165 void SetNodeText(const base::string16& value, WebKit::WebInputElement* node); | 165 void SetNodeText(const base::string16& value, blink::WebInputElement* node); |
166 | 166 |
167 // Hides any currently showing Autofill UI. | 167 // Hides any currently showing Autofill UI. |
168 void HideAutofillUI(); | 168 void HideAutofillUI(); |
169 | 169 |
170 FormCache form_cache_; | 170 FormCache form_cache_; |
171 | 171 |
172 PasswordAutofillAgent* password_autofill_agent_; // WEAK reference. | 172 PasswordAutofillAgent* password_autofill_agent_; // WEAK reference. |
173 | 173 |
174 // The ID of the last request sent for form field Autofill. Used to ignore | 174 // The ID of the last request sent for form field Autofill. Used to ignore |
175 // out of date responses. | 175 // out of date responses. |
176 int autofill_query_id_; | 176 int autofill_query_id_; |
177 | 177 |
178 // The element corresponding to the last request sent for form field Autofill. | 178 // The element corresponding to the last request sent for form field Autofill. |
179 WebKit::WebInputElement element_; | 179 blink::WebInputElement element_; |
180 | 180 |
181 // The form element currently requesting an interactive autocomplete. | 181 // The form element currently requesting an interactive autocomplete. |
182 WebKit::WebFormElement in_flight_request_form_; | 182 blink::WebFormElement in_flight_request_form_; |
183 | 183 |
184 // All the form elements seen in the top frame. | 184 // All the form elements seen in the top frame. |
185 std::vector<WebKit::WebFormElement> form_elements_; | 185 std::vector<blink::WebFormElement> form_elements_; |
186 | 186 |
187 // The action to take when receiving Autofill data from the AutofillManager. | 187 // The action to take when receiving Autofill data from the AutofillManager. |
188 AutofillAction autofill_action_; | 188 AutofillAction autofill_action_; |
189 | 189 |
190 // Pointer to the WebView. Used to access page scale factor. | 190 // Pointer to the WebView. Used to access page scale factor. |
191 WebKit::WebView* web_view_; | 191 blink::WebView* web_view_; |
192 | 192 |
193 // Should we display a warning if autofill is disabled? | 193 // Should we display a warning if autofill is disabled? |
194 bool display_warning_if_disabled_; | 194 bool display_warning_if_disabled_; |
195 | 195 |
196 // Was the query node autofilled prior to previewing the form? | 196 // Was the query node autofilled prior to previewing the form? |
197 bool was_query_node_autofilled_; | 197 bool was_query_node_autofilled_; |
198 | 198 |
199 // Have we already shown Autofill suggestions for the field the user is | 199 // Have we already shown Autofill suggestions for the field the user is |
200 // currently editing? Used to keep track of state for metrics logging. | 200 // currently editing? Used to keep track of state for metrics logging. |
201 bool has_shown_autofill_popup_for_current_edit_; | 201 bool has_shown_autofill_popup_for_current_edit_; |
(...skipping 23 matching lines...) Expand all Loading... |
225 FRIEND_TEST_ALL_PREFIXES(PasswordAutofillAgentTest, WaitUsername); | 225 FRIEND_TEST_ALL_PREFIXES(PasswordAutofillAgentTest, WaitUsername); |
226 FRIEND_TEST_ALL_PREFIXES(PasswordAutofillAgentTest, SuggestionAccept); | 226 FRIEND_TEST_ALL_PREFIXES(PasswordAutofillAgentTest, SuggestionAccept); |
227 FRIEND_TEST_ALL_PREFIXES(PasswordAutofillAgentTest, SuggestionSelect); | 227 FRIEND_TEST_ALL_PREFIXES(PasswordAutofillAgentTest, SuggestionSelect); |
228 | 228 |
229 DISALLOW_COPY_AND_ASSIGN(AutofillAgent); | 229 DISALLOW_COPY_AND_ASSIGN(AutofillAgent); |
230 }; | 230 }; |
231 | 231 |
232 } // namespace autofill | 232 } // namespace autofill |
233 | 233 |
234 #endif // COMPONENTS_AUTOFILL_CONTENT_RENDERER_AUTOFILL_AGENT_H_ | 234 #endif // COMPONENTS_AUTOFILL_CONTENT_RENDERER_AUTOFILL_AGENT_H_ |
OLD | NEW |