Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 CHROME_RENDERER_AUTOFILL_HELPER_H_ | 5 #ifndef CHROME_RENDERER_AUTOFILL_HELPER_H_ |
| 6 #define CHROME_RENDERER_AUTOFILL_HELPER_H_ | 6 #define CHROME_RENDERER_AUTOFILL_HELPER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "chrome/renderer/form_manager.h" | 13 #include "chrome/renderer/form_manager.h" |
| 14 #include "chrome/renderer/page_click_listener.h" | 14 #include "chrome/renderer/page_click_listener.h" |
| 15 #include "chrome/renderer/render_view.h" | |
| 16 #include "third_party/WebKit/WebKit/chromium/public/WebAutoFillClient.h" | |
| 15 #include "third_party/WebKit/WebKit/chromium/public/WebNode.h" | 17 #include "third_party/WebKit/WebKit/chromium/public/WebNode.h" |
| 16 | 18 |
| 17 class RenderView; | 19 class PasswordAutocompleteManager; |
| 18 | 20 |
| 19 namespace WebKit { | 21 namespace WebKit { |
| 20 class WebInputElement; | 22 class WebInputElement; |
| 21 class WebKeyboardEvent; | 23 class WebKeyboardEvent; |
| 22 class WebString; | 24 class WebString; |
| 23 } | 25 } |
| 24 | 26 |
| 25 // AutoFillHelper deals with AutoFill related communications between WebKit and | 27 // AutoFillHelper deals with AutoFill related communications between WebKit and |
| 26 // the browser. There is one AutofillHelper per RenderView. | 28 // the browser. There is one AutofillHelper per RenderView. |
| 27 // This code was originally part of RenderView. | 29 // This code was originally part of RenderView. |
| 28 // Note that AutoFill encompasses: | 30 // Note that AutoFill encompasses: |
| 29 // - single text field suggestions, that we usually refer to as Autocomplete | 31 // - single text field suggestions, that we usually refer to as Autocomplete |
| 30 // - entire form fill based on one field entry, referred to as form AutoFill. | 32 // - entire form fill based on one field entry, referred to as form AutoFill. |
| 31 | 33 |
| 32 class AutoFillHelper : public PageClickListener { | 34 class AutoFillHelper : public RenderView::Observer, |
| 35 public PageClickListener, | |
| 36 public WebKit::WebAutoFillClient { | |
| 33 public: | 37 public: |
| 34 explicit AutoFillHelper(RenderView* render_view); | 38 // PasswordAutocompleteManager is guaranteed to outlive AutoFillHelper. |
| 35 | 39 explicit AutoFillHelper( |
| 36 // Removes the Autocomplete suggestion |value| for the field named |name|. | 40 PasswordAutocompleteManager* password_autocomplete_manager); |
| 37 void RemoveAutocompleteSuggestion(const WebKit::WebString& name, | |
| 38 const WebKit::WebString& value); | |
| 39 | |
| 40 // Called when we have received AutoFill suggestions from the browser. | |
| 41 void SuggestionsReceived(int query_id, | |
| 42 const std::vector<string16>& values, | |
| 43 const std::vector<string16>& labels, | |
| 44 const std::vector<string16>& icons, | |
| 45 const std::vector<int>& unique_ids); | |
| 46 | |
| 47 // Called when we have received suggestions for an entire form from the | |
| 48 // browser. | |
| 49 void FormDataFilled(int query_id, const webkit_glue::FormData& form); | |
| 50 | |
| 51 // Called by Webkit when the user has selected a suggestion in the popup (this | |
| 52 // happens when the user hovers over an suggestion or navigates the popup with | |
| 53 // the arrow keys). | |
| 54 void DidSelectAutoFillSuggestion(const WebKit::WebNode& node, | |
| 55 int unique_id); | |
| 56 | |
| 57 // Called by Webkit when the user has accepted a suggestion in the popup. | |
| 58 void DidAcceptAutoFillSuggestion(const WebKit::WebNode& node, | |
| 59 const WebKit::WebString& value, | |
| 60 int unique_id, | |
| 61 unsigned index); | |
| 62 | |
| 63 // Called by WebKit when the user has cleared the selection from the AutoFill | |
| 64 // suggestions popup. This happens when a user uses the arrow keys to | |
| 65 // navigate outside the range of possible selections, or when the popup | |
| 66 // closes. | |
| 67 void DidClearAutoFillSelection(const WebKit::WebNode& node); | |
| 68 | |
| 69 // Called when the frame contents are available. Extracts the forms from that | |
| 70 // frame and sends them to the browser for parsing. | |
| 71 void FrameContentsAvailable(WebKit::WebFrame* frame); | |
| 72 | |
| 73 // Called before a frame is closed. Gives us an opportunity to clean up. | |
| 74 // DEPRECATED. | |
| 75 void FrameWillClose(WebKit::WebFrame* frame); | |
| 76 | |
| 77 // Called when |frame| is detached from the view. Gives us an opportunity to | |
| 78 // clean up. | |
| 79 void FrameDetached(WebKit::WebFrame* frame); | |
| 80 | |
| 81 // WebViewClient editor call forwarded by the RenderView. | |
| 82 void TextDidChangeInTextField(const WebKit::WebInputElement& element); | |
| 83 | |
| 84 // WebViewClient editor call forwarded by the RenderView. For lower level | |
| 85 // event translation. Specifically, for down/up key presses in an input | |
| 86 // element. | |
| 87 void KeyDownInTextField(const WebKit::WebInputElement& element, | |
| 88 const WebKit::WebKeyboardEvent& event); | |
| 89 | 41 |
| 90 private: | 42 private: |
| 91 enum AutoFillAction { | 43 enum AutoFillAction { |
| 92 AUTOFILL_NONE, // No state set. | 44 AUTOFILL_NONE, // No state set. |
| 93 AUTOFILL_FILL, // Fill the AutoFill form data. | 45 AUTOFILL_FILL, // Fill the AutoFill form data. |
| 94 AUTOFILL_PREVIEW, // Preview the AutoFill form data. | 46 AUTOFILL_PREVIEW, // Preview the AutoFill form data. |
| 95 }; | 47 }; |
| 96 | 48 |
| 49 // RenderView::Observer implementation. | |
| 50 virtual bool OnMessageReceived(const IPC::Message& message); | |
| 51 virtual void DidFinishDocumentLoad(WebKit::WebFrame* frame); | |
| 52 virtual void FrameDetached(WebKit::WebFrame* frame); | |
| 53 virtual void FrameWillClose(WebKit::WebFrame* frame); | |
| 54 virtual void FrameTranslated(WebKit::WebFrame* frame); | |
| 55 | |
| 97 // PageClickListener implementation: | 56 // PageClickListener implementation: |
| 98 virtual bool InputElementClicked(const WebKit::WebInputElement& element, | 57 virtual bool InputElementClicked(const WebKit::WebInputElement& element, |
| 99 bool was_focused, | 58 bool was_focused, |
| 100 bool is_focused); | 59 bool is_focused); |
| 101 | 60 |
| 61 // WebKit::WebAutoFillClient implementation: | |
| 62 virtual void didAcceptAutoFillSuggestion(const WebKit::WebNode& node, | |
| 63 const WebKit::WebString& value, | |
| 64 const WebKit::WebString& label, | |
| 65 int unique_id, | |
| 66 unsigned index); | |
| 67 virtual void didSelectAutoFillSuggestion(const WebKit::WebNode& node, | |
| 68 const WebKit::WebString& value, | |
| 69 const WebKit::WebString& label, | |
| 70 int unique_id); | |
| 71 virtual void didClearAutoFillSelection(const WebKit::WebNode& node); | |
| 72 virtual void didAcceptAutocompleteSuggestion( | |
| 73 const WebKit::WebInputElement& element); | |
| 74 virtual void removeAutocompleteSuggestion(const WebKit::WebString& name, | |
| 75 const WebKit::WebString& value); | |
|
Ilya Sherman
2011/01/13 02:18:30
nit: indentation
jam
2011/01/13 02:53:43
Done.
| |
| 76 virtual void textFieldDidEndEditing(const WebKit::WebInputElement& element); | |
| 77 virtual void textFieldDidChange(const WebKit::WebInputElement& element); | |
| 78 virtual void textFieldDidReceiveKeyDown( | |
| 79 const WebKit::WebInputElement& element, | |
| 80 const WebKit::WebKeyboardEvent& event); | |
| 81 | |
| 82 void OnSuggestionsReturned(int query_id, | |
| 83 const std::vector<string16>& values, | |
| 84 const std::vector<string16>& labels, | |
| 85 const std::vector<string16>& icons, | |
| 86 const std::vector<int>& unique_ids); | |
| 87 void OnFormDataFilled(int query_id, const webkit_glue::FormData& form); | |
| 88 | |
| 89 // Called in a posted task by textFieldDidChange() to work-around a WebKit bug | |
| 90 // http://bugs.webkit.org/show_bug.cgi?id=16976 | |
| 91 void TextFieldDidChangeImpl(const WebKit::WebInputElement& element); | |
| 92 | |
| 102 // Shows the autocomplete suggestions for |element|. | 93 // Shows the autocomplete suggestions for |element|. |
| 103 // This call is asynchronous and may or may not lead to the showing of a | 94 // This call is asynchronous and may or may not lead to the showing of a |
| 104 // suggestion popup (no popup is shown if there are no available suggestions). | 95 // suggestion popup (no popup is shown if there are no available suggestions). |
| 105 // |autofill_on_empty_values| specifies whether suggestions should be shown | 96 // |autofill_on_empty_values| specifies whether suggestions should be shown |
| 106 // when |element| contains no text. | 97 // when |element| contains no text. |
| 107 // |requires_caret_at_end| specifies whether suggestions should be shown when | 98 // |requires_caret_at_end| specifies whether suggestions should be shown when |
| 108 // the caret is not after the last character in |element|. | 99 // the caret is not after the last character in |element|. |
| 109 // |display_warning_if_disabled| specifies whether a warning should be | 100 // |display_warning_if_disabled| specifies whether a warning should be |
| 110 // displayed to the user if AutoFill has suggestions available, but cannot | 101 // displayed to the user if AutoFill has suggestions available, but cannot |
| 111 // fill them because it is disabled (e.g. when trying to fill a credit card | 102 // fill them because it is disabled (e.g. when trying to fill a credit card |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 131 // Scans the given frame for forms and sends them up to the browser. | 122 // Scans the given frame for forms and sends them up to the browser. |
| 132 void SendForms(WebKit::WebFrame* frame); | 123 void SendForms(WebKit::WebFrame* frame); |
| 133 | 124 |
| 134 // Fills |form| and |field| with the FormData and FormField corresponding to | 125 // Fills |form| and |field| with the FormData and FormField corresponding to |
| 135 // |node|. Returns true if the data was found; and false otherwise. | 126 // |node|. Returns true if the data was found; and false otherwise. |
| 136 bool FindFormAndFieldForNode( | 127 bool FindFormAndFieldForNode( |
| 137 const WebKit::WebNode& node, | 128 const WebKit::WebNode& node, |
| 138 webkit_glue::FormData* form, | 129 webkit_glue::FormData* form, |
| 139 webkit_glue::FormField* field) WARN_UNUSED_RESULT; | 130 webkit_glue::FormField* field) WARN_UNUSED_RESULT; |
| 140 | 131 |
| 141 // Weak reference. | 132 FormManager form_manager_; |
| 142 RenderView* render_view_; | |
| 143 | 133 |
| 144 FormManager form_manager_; | 134 PasswordAutocompleteManager* password_autocomplete_manager_; |
| 145 | 135 |
| 146 // The ID of the last request sent for form field AutoFill. Used to ignore | 136 // The ID of the last request sent for form field AutoFill. Used to ignore |
| 147 // out of date responses. | 137 // out of date responses. |
| 148 int autofill_query_id_; | 138 int autofill_query_id_; |
| 149 | 139 |
| 150 // The node corresponding to the last request sent for form field AutoFill. | 140 // The node corresponding to the last request sent for form field AutoFill. |
| 151 WebKit::WebNode autofill_query_node_; | 141 WebKit::WebNode autofill_query_node_; |
| 152 | 142 |
| 153 // The action to take when receiving AutoFill data from the AutoFillManager. | 143 // The action to take when receiving AutoFill data from the AutoFillManager. |
| 154 AutoFillAction autofill_action_; | 144 AutoFillAction autofill_action_; |
| 155 | 145 |
| 156 // Should we display a warning if autofill is disabled? | 146 // Should we display a warning if autofill is disabled? |
| 157 bool display_warning_if_disabled_; | 147 bool display_warning_if_disabled_; |
| 158 | 148 |
| 159 // Was the query node autofilled prior to previewing the form? | 149 // Was the query node autofilled prior to previewing the form? |
| 160 bool was_query_node_autofilled_; | 150 bool was_query_node_autofilled_; |
| 161 | 151 |
| 162 // The menu index of the "Clear" menu item. | 152 // The menu index of the "Clear" menu item. |
| 163 int suggestions_clear_index_; | 153 int suggestions_clear_index_; |
| 164 | 154 |
| 165 // The menu index of the "AutoFill options..." menu item. | 155 // The menu index of the "AutoFill options..." menu item. |
| 166 int suggestions_options_index_; | 156 int suggestions_options_index_; |
| 167 | 157 |
| 158 ScopedRunnableMethodFactory<AutoFillHelper> method_factory_; | |
| 159 | |
| 168 DISALLOW_COPY_AND_ASSIGN(AutoFillHelper); | 160 DISALLOW_COPY_AND_ASSIGN(AutoFillHelper); |
| 169 }; | 161 }; |
| 170 | 162 |
| 171 #endif // CHROME_RENDERER_AUTOFILL_HELPER_H_ | 163 #endif // CHROME_RENDERER_AUTOFILL_HELPER_H_ |
| OLD | NEW |