Index: chrome/renderer/autofill_helper.h |
=================================================================== |
--- chrome/renderer/autofill_helper.h (revision 71253) |
+++ chrome/renderer/autofill_helper.h (working copy) |
@@ -10,18 +10,15 @@ |
#include "base/basictypes.h" |
#include "base/compiler_specific.h" |
+#include "base/task.h" |
#include "chrome/renderer/form_manager.h" |
#include "chrome/renderer/page_click_listener.h" |
+#include "chrome/renderer/render_view_observer.h" |
+#include "third_party/WebKit/WebKit/chromium/public/WebAutoFillClient.h" |
#include "third_party/WebKit/WebKit/chromium/public/WebNode.h" |
-class RenderView; |
+class PasswordAutocompleteManager; |
-namespace WebKit { |
-class WebInputElement; |
-class WebKeyboardEvent; |
-class WebString; |
-} |
- |
// AutoFillHelper deals with AutoFill related communications between WebKit and |
// the browser. There is one AutofillHelper per RenderView. |
// This code was originally part of RenderView. |
@@ -29,64 +26,35 @@ |
// - single text field suggestions, that we usually refer to as Autocomplete |
// - entire form fill based on one field entry, referred to as form AutoFill. |
-class AutoFillHelper : public PageClickListener { |
+class AutoFillHelper : public RenderViewObserver, |
+ public PageClickListener, |
+ public WebKit::WebAutoFillClient { |
public: |
- explicit AutoFillHelper(RenderView* render_view); |
+ // PasswordAutocompleteManager is guaranteed to outlive AutoFillHelper. |
+ AutoFillHelper(RenderView* render_view, |
+ PasswordAutocompleteManager* password_autocomplete_manager); |
- // Removes the Autocomplete suggestion |value| for the field named |name|. |
- void RemoveAutocompleteSuggestion(const WebKit::WebString& name, |
- const WebKit::WebString& value); |
+ // WebKit::WebAutoFillClient implementation. Public for tests. |
+ virtual void didAcceptAutoFillSuggestion(const WebKit::WebNode& node, |
+ const WebKit::WebString& value, |
+ const WebKit::WebString& label, |
+ int unique_id, |
+ unsigned index); |
+ virtual void didSelectAutoFillSuggestion(const WebKit::WebNode& node, |
+ const WebKit::WebString& value, |
+ const WebKit::WebString& label, |
+ int unique_id); |
+ virtual void didClearAutoFillSelection(const WebKit::WebNode& node); |
+ virtual void didAcceptAutocompleteSuggestion( |
+ const WebKit::WebInputElement& element); |
+ virtual void removeAutocompleteSuggestion(const WebKit::WebString& name, |
+ const WebKit::WebString& value); |
+ virtual void textFieldDidEndEditing(const WebKit::WebInputElement& element); |
+ virtual void textFieldDidChange(const WebKit::WebInputElement& element); |
+ virtual void textFieldDidReceiveKeyDown( |
+ const WebKit::WebInputElement& element, |
+ const WebKit::WebKeyboardEvent& event); |
- // Called when we have received AutoFill suggestions from the browser. |
- void SuggestionsReceived(int query_id, |
- const std::vector<string16>& values, |
- const std::vector<string16>& labels, |
- const std::vector<string16>& icons, |
- const std::vector<int>& unique_ids); |
- |
- // Called when we have received suggestions for an entire form from the |
- // browser. |
- void FormDataFilled(int query_id, const webkit_glue::FormData& form); |
- |
- // Called by Webkit when the user has selected a suggestion in the popup (this |
- // happens when the user hovers over an suggestion or navigates the popup with |
- // the arrow keys). |
- void DidSelectAutoFillSuggestion(const WebKit::WebNode& node, |
- int unique_id); |
- |
- // Called by Webkit when the user has accepted a suggestion in the popup. |
- void DidAcceptAutoFillSuggestion(const WebKit::WebNode& node, |
- const WebKit::WebString& value, |
- int unique_id, |
- unsigned index); |
- |
- // Called by WebKit when the user has cleared the selection from the AutoFill |
- // suggestions popup. This happens when a user uses the arrow keys to |
- // navigate outside the range of possible selections, or when the popup |
- // closes. |
- void DidClearAutoFillSelection(const WebKit::WebNode& node); |
- |
- // Called when the frame contents are available. Extracts the forms from that |
- // frame and sends them to the browser for parsing. |
- void FrameContentsAvailable(WebKit::WebFrame* frame); |
- |
- // Called before a frame is closed. Gives us an opportunity to clean up. |
- // DEPRECATED. |
- void FrameWillClose(WebKit::WebFrame* frame); |
- |
- // Called when |frame| is detached from the view. Gives us an opportunity to |
- // clean up. |
- void FrameDetached(WebKit::WebFrame* frame); |
- |
- // WebViewClient editor call forwarded by the RenderView. |
- void TextDidChangeInTextField(const WebKit::WebInputElement& element); |
- |
- // WebViewClient editor call forwarded by the RenderView. For lower level |
- // event translation. Specifically, for down/up key presses in an input |
- // element. |
- void KeyDownInTextField(const WebKit::WebInputElement& element, |
- const WebKit::WebKeyboardEvent& event); |
- |
private: |
enum AutoFillAction { |
AUTOFILL_NONE, // No state set. |
@@ -94,11 +62,29 @@ |
AUTOFILL_PREVIEW, // Preview the AutoFill form data. |
}; |
+ // RenderView::Observer implementation. |
+ virtual bool OnMessageReceived(const IPC::Message& message); |
+ virtual void DidFinishDocumentLoad(WebKit::WebFrame* frame); |
+ virtual void FrameDetached(WebKit::WebFrame* frame); |
+ virtual void FrameWillClose(WebKit::WebFrame* frame); |
+ virtual void FrameTranslated(WebKit::WebFrame* frame); |
+ |
// PageClickListener implementation: |
virtual bool InputElementClicked(const WebKit::WebInputElement& element, |
bool was_focused, |
bool is_focused); |
+ void OnSuggestionsReturned(int query_id, |
+ const std::vector<string16>& values, |
+ const std::vector<string16>& labels, |
+ const std::vector<string16>& icons, |
+ const std::vector<int>& unique_ids); |
+ void OnFormDataFilled(int query_id, const webkit_glue::FormData& form); |
+ |
+ // Called in a posted task by textFieldDidChange() to work-around a WebKit bug |
+ // http://bugs.webkit.org/show_bug.cgi?id=16976 |
+ void TextFieldDidChangeImpl(const WebKit::WebInputElement& element); |
+ |
// Shows the autocomplete suggestions for |element|. |
// This call is asynchronous and may or may not lead to the showing of a |
// suggestion popup (no popup is shown if there are no available suggestions). |
@@ -138,11 +124,10 @@ |
webkit_glue::FormData* form, |
webkit_glue::FormField* field) WARN_UNUSED_RESULT; |
- // Weak reference. |
- RenderView* render_view_; |
- |
FormManager form_manager_; |
+ PasswordAutocompleteManager* password_autocomplete_manager_; |
+ |
// The ID of the last request sent for form field AutoFill. Used to ignore |
// out of date responses. |
int autofill_query_id_; |
@@ -165,6 +150,8 @@ |
// The menu index of the "AutoFill options..." menu item. |
int suggestions_options_index_; |
+ ScopedRunnableMethodFactory<AutoFillHelper> method_factory_; |
+ |
DISALLOW_COPY_AND_ASSIGN(AutoFillHelper); |
}; |