| 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 "components/autofill/content/renderer/form_cache.h" |   15 #include "components/autofill/content/renderer/form_cache.h" | 
|   16 #include "components/autofill/content/renderer/page_click_listener.h" |   16 #include "components/autofill/content/renderer/page_click_listener.h" | 
 |   17 #include "components/autofill/content/renderer/page_click_tracker.h" | 
 |   18 #include "content/public/renderer/render_frame_observer.h" | 
|   17 #include "content/public/renderer/render_view_observer.h" |   19 #include "content/public/renderer/render_view_observer.h" | 
|   18 #include "third_party/WebKit/public/web/WebAutofillClient.h" |   20 #include "third_party/WebKit/public/web/WebAutofillClient.h" | 
|   19 #include "third_party/WebKit/public/web/WebFormControlElement.h" |   21 #include "third_party/WebKit/public/web/WebFormControlElement.h" | 
|   20 #include "third_party/WebKit/public/web/WebFormElement.h" |   22 #include "third_party/WebKit/public/web/WebFormElement.h" | 
|   21 #include "third_party/WebKit/public/web/WebInputElement.h" |   23 #include "third_party/WebKit/public/web/WebInputElement.h" | 
|   22  |   24  | 
|   23 namespace blink { |   25 namespace blink { | 
|   24 class WebNode; |   26 class WebNode; | 
|   25 class WebView; |   27 class WebView; | 
|   26 } |   28 } | 
|   27  |   29  | 
|   28 namespace autofill { |   30 namespace autofill { | 
|   29  |   31  | 
|   30 struct FormData; |   32 struct FormData; | 
|   31 struct FormFieldData; |   33 struct FormFieldData; | 
|   32 struct WebElementDescriptor; |   34 struct WebElementDescriptor; | 
|   33 class PasswordAutofillAgent; |   35 class PasswordAutofillAgent; | 
|   34 class PasswordGenerationAgent; |   36 class PasswordGenerationAgent; | 
|   35  |   37  | 
|   36 // AutofillAgent deals with Autofill related communications between WebKit and |   38 // AutofillAgent deals with Autofill related communications between WebKit and | 
|   37 // the browser.  There is one AutofillAgent per RenderView. |   39 // the browser.  There is one AutofillAgent per RenderFrame. | 
|   38 // This code was originally part of RenderView. |  | 
|   39 // Note that Autofill encompasses: |   40 // Note that Autofill encompasses: | 
|   40 // - single text field suggestions, that we usually refer to as Autocomplete, |   41 // - single text field suggestions, that we usually refer to as Autocomplete, | 
|   41 // - password form fill, refered to as Password Autofill, and |   42 // - password form fill, refered to as Password Autofill, and | 
|   42 // - entire form fill based on one field entry, referred to as Form Autofill. |   43 // - entire form fill based on one field entry, referred to as Form Autofill. | 
|   43  |   44  | 
|   44 class AutofillAgent : public content::RenderViewObserver, |   45 class AutofillAgent : public content::RenderFrameObserver, | 
|   45                       public PageClickListener, |   46                       public PageClickListener, | 
|   46                       public blink::WebAutofillClient { |   47                       public blink::WebAutofillClient { | 
|   47  public: |   48  public: | 
|   48   // PasswordAutofillAgent is guaranteed to outlive AutofillAgent. |   49   // PasswordAutofillAgent is guaranteed to outlive AutofillAgent. | 
|   49   // PasswordGenerationAgent may be NULL. If it is not, then it is also |   50   // PasswordGenerationAgent may be NULL. If it is not, then it is also | 
|   50   // guaranteed to outlive AutofillAgent. |   51   // guaranteed to outlive AutofillAgent. | 
|   51   AutofillAgent(content::RenderView* render_view, |   52   AutofillAgent(content::RenderFrame* render_frame, | 
|   52                 PasswordAutofillAgent* password_autofill_manager, |   53                 PasswordAutofillAgent* password_autofill_manager, | 
|   53                 PasswordGenerationAgent* password_generation_agent); |   54                 PasswordGenerationAgent* password_generation_agent); | 
|   54   virtual ~AutofillAgent(); |   55   virtual ~AutofillAgent(); | 
|   55  |   56  | 
|   56  private: |   57  private: | 
 |   58   // Thunk class for RenderViewObserver methods that haven't yet been migrated | 
 |   59   // to RenderFrameObserver. Should eventually be removed. | 
 |   60   // http://crbug.com/433486 | 
 |   61   class LegacyAutofillAgent : public content::RenderViewObserver { | 
 |   62    public: | 
 |   63     LegacyAutofillAgent(content::RenderView* render_view, AutofillAgent* agent); | 
 |   64     ~LegacyAutofillAgent() override; | 
 |   65  | 
 |   66    private: | 
 |   67     // content::RenderViewObserver: | 
 |   68     void OnDestruct() override; | 
 |   69     void FrameDetached(blink::WebFrame* frame) override; | 
 |   70     void WillSubmitForm(blink::WebLocalFrame* frame, | 
 |   71                         const blink::WebFormElement& form) override; | 
 |   72     void DidChangeScrollOffset(blink::WebLocalFrame* frame) override; | 
 |   73     void FocusedNodeChanged(const blink::WebNode& node) override; | 
 |   74     void OrientationChangeEvent() override; | 
 |   75     void Resized() override; | 
 |   76     void FrameWillClose(blink::WebFrame* frame) override; | 
 |   77  | 
 |   78     AutofillAgent* agent_; | 
 |   79  | 
 |   80     DISALLOW_COPY_AND_ASSIGN(LegacyAutofillAgent); | 
 |   81   }; | 
 |   82   friend class LegacyAutofillAgent; | 
 |   83  | 
|   57   // Flags passed to ShowSuggestions. |   84   // Flags passed to ShowSuggestions. | 
|   58   struct ShowSuggestionsOptions { |   85   struct ShowSuggestionsOptions { | 
|   59     // All fields are default initialized to false. |   86     // All fields are default initialized to false. | 
|   60     ShowSuggestionsOptions(); |   87     ShowSuggestionsOptions(); | 
|   61  |   88  | 
|   62     // Specifies that suggestions should be shown when |element| contains no |   89     // Specifies that suggestions should be shown when |element| contains no | 
|   63     // text. |   90     // text. | 
|   64     bool autofill_on_empty_values; |   91     bool autofill_on_empty_values; | 
|   65  |   92  | 
|   66     // Specifies that suggestions should be shown when the caret is not |   93     // Specifies that suggestions should be shown when the caret is not | 
| (...skipping 13 matching lines...) Expand all  Loading... | 
|   80     // Specifies that all autofill suggestions should be shown and none should |  107     // Specifies that all autofill suggestions should be shown and none should | 
|   81     // be elided because of the current value of |element| (relevant for inline |  108     // be elided because of the current value of |element| (relevant for inline | 
|   82     // autocomplete). |  109     // autocomplete). | 
|   83     bool show_full_suggestion_list; |  110     bool show_full_suggestion_list; | 
|   84  |  111  | 
|   85     // Specifies that only show a suggestions box if |element| is part of a |  112     // Specifies that only show a suggestions box if |element| is part of a | 
|   86     // password form, otherwise show no suggestions. |  113     // password form, otherwise show no suggestions. | 
|   87     bool show_password_suggestions_only; |  114     bool show_password_suggestions_only; | 
|   88   }; |  115   }; | 
|   89  |  116  | 
|   90   // content::RenderViewObserver: |  117   // content::RenderFrameObserver: | 
|   91   bool OnMessageReceived(const IPC::Message& message) override; |  118   bool OnMessageReceived(const IPC::Message& message) override; | 
|   92   void DidFinishDocumentLoad(blink::WebLocalFrame* frame) override; |  119   void DidCommitProvisionalLoad(bool is_new_navigation) override; | 
|   93   void DidCommitProvisionalLoad(blink::WebLocalFrame* frame, |  120   void DidFinishDocumentLoad() override; | 
|   94                                 bool is_new_navigation) override; |  121  | 
|   95   void FrameDetached(blink::WebFrame* frame) override; |  122   // Pass-throughs from LegacyAutofillAgent. These correlate with | 
|   96   void FrameWillClose(blink::WebFrame* frame) override; |  123   // RenderViewObserver methods. | 
 |  124   void FrameDetached(blink::WebFrame* frame); | 
|   97   void WillSubmitForm(blink::WebLocalFrame* frame, |  125   void WillSubmitForm(blink::WebLocalFrame* frame, | 
|   98                       const blink::WebFormElement& form) override; |  126                       const blink::WebFormElement& form); | 
|   99   void DidChangeScrollOffset(blink::WebLocalFrame* frame) override; |  127   void DidChangeScrollOffset(blink::WebLocalFrame* frame); | 
|  100   void FocusedNodeChanged(const blink::WebNode& node) override; |  128   void FocusedNodeChanged(const blink::WebNode& node); | 
|  101   void OrientationChangeEvent() override; |  129   void OrientationChangeEvent(); | 
|  102   void Resized() override; |  130   void Resized(); | 
 |  131   void LegacyFrameWillClose(blink::WebFrame* frame); | 
|  103  |  132  | 
|  104   // PageClickListener: |  133   // PageClickListener: | 
|  105   void FormControlElementClicked(const blink::WebFormControlElement& element, |  134   void FormControlElementClicked(const blink::WebFormControlElement& element, | 
|  106                                  bool was_focused) override; |  135                                  bool was_focused) override; | 
|  107  |  136  | 
|  108   // blink::WebAutofillClient: |  137   // blink::WebAutofillClient: | 
|  109   virtual void textFieldDidEndEditing( |  138   virtual void textFieldDidEndEditing( | 
|  110       const blink::WebInputElement& element); |  139       const blink::WebInputElement& element); | 
|  111   virtual void textFieldDidChange( |  140   virtual void textFieldDidChange( | 
|  112       const blink::WebFormControlElement& element); |  141       const blink::WebFormControlElement& element); | 
|  113   virtual void textFieldDidReceiveKeyDown( |  142   virtual void textFieldDidReceiveKeyDown( | 
|  114       const blink::WebInputElement& element, |  143       const blink::WebInputElement& element, | 
|  115       const blink::WebKeyboardEvent& event); |  144       const blink::WebKeyboardEvent& event); | 
|  116   virtual void didRequestAutocomplete( |  145   virtual void didRequestAutocomplete( | 
|  117       const blink::WebFormElement& form); |  146       const blink::WebFormElement& form); | 
|  118   virtual void setIgnoreTextChanges(bool ignore); |  147   virtual void setIgnoreTextChanges(bool ignore); | 
|  119   virtual void didAssociateFormControls( |  148   virtual void didAssociateFormControls( | 
|  120       const blink::WebVector<blink::WebNode>& nodes); |  149       const blink::WebVector<blink::WebNode>& nodes); | 
|  121   virtual void openTextDataListChooser(const blink::WebInputElement& element); |  150   virtual void openTextDataListChooser(const blink::WebInputElement& element); | 
|  122   virtual void firstUserGestureObserved(); |  151   virtual void firstUserGestureObserved(); | 
|  123  |  152  | 
|  124   void OnFieldTypePredictionsAvailable( |  153   void OnFieldTypePredictionsAvailable( | 
|  125       const std::vector<FormDataPredictions>& forms); |  154       const std::vector<FormDataPredictions>& forms); | 
|  126   void OnFillForm(int query_id, const FormData& form); |  155   void OnFillForm(int query_id, const FormData& form); | 
 |  156   void OnFirstUserGestureObservedInTab(); | 
|  127   void OnPing(); |  157   void OnPing(); | 
|  128   void OnPreviewForm(int query_id, const FormData& form); |  158   void OnPreviewForm(int query_id, const FormData& form); | 
|  129  |  159  | 
|  130   // For external Autofill selection. |  160   // For external Autofill selection. | 
|  131   void OnClearForm(); |  161   void OnClearForm(); | 
|  132   void OnClearPreviewedForm(); |  162   void OnClearPreviewedForm(); | 
|  133   void OnFillFieldWithValue(const base::string16& value); |  163   void OnFillFieldWithValue(const base::string16& value); | 
|  134   void OnPreviewFieldWithValue(const base::string16& value); |  164   void OnPreviewFieldWithValue(const base::string16& value); | 
|  135   void OnAcceptDataListSuggestion(const base::string16& value); |  165   void OnAcceptDataListSuggestion(const base::string16& value); | 
|  136   void OnFillPasswordSuggestion(const base::string16& username, |  166   void OnFillPasswordSuggestion(const base::string16& username, | 
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  178   // Set |node| to display the given |value|. |  208   // Set |node| to display the given |value|. | 
|  179   void FillFieldWithValue(const base::string16& value, |  209   void FillFieldWithValue(const base::string16& value, | 
|  180                           blink::WebInputElement* node); |  210                           blink::WebInputElement* node); | 
|  181  |  211  | 
|  182   // Set |node| to display the given |value| as a preview.  The preview is |  212   // Set |node| to display the given |value| as a preview.  The preview is | 
|  183   // visible on screen to the user, but not visible to the page via the DOM or |  213   // visible on screen to the user, but not visible to the page via the DOM or | 
|  184   // JavaScript. |  214   // JavaScript. | 
|  185   void PreviewFieldWithValue(const base::string16& value, |  215   void PreviewFieldWithValue(const base::string16& value, | 
|  186                              blink::WebInputElement* node); |  216                              blink::WebInputElement* node); | 
|  187  |  217  | 
|  188   // Notifies browser of new fillable forms in |frame|. |  218   // Notifies browser of new fillable forms in |render_frame|. | 
|  189   void ProcessForms(const blink::WebLocalFrame& frame); |  219   void ProcessForms(); | 
|  190  |  220  | 
|  191   // Hides any currently showing Autofill popup. |  221   // Hides any currently showing Autofill popup. | 
|  192   void HidePopup(); |  222   void HidePopup(); | 
|  193  |  223  | 
 |  224   // Formerly cached forms for all frames, now only caches forms for the current | 
 |  225   // frame. TODO(estade): simplify |FormCache| to only work with a single frame. | 
|  194   FormCache form_cache_; |  226   FormCache form_cache_; | 
|  195  |  227  | 
|  196   PasswordAutofillAgent* password_autofill_agent_;  // Weak reference. |  228   PasswordAutofillAgent* password_autofill_agent_;  // Weak reference. | 
|  197   PasswordGenerationAgent* password_generation_agent_;  // Weak reference. |  229   PasswordGenerationAgent* password_generation_agent_;  // Weak reference. | 
|  198  |  230  | 
 |  231   // Passes through RenderViewObserver methods to |this|. | 
 |  232   LegacyAutofillAgent legacy_; | 
 |  233  | 
 |  234   // Tracks clicks on the RenderViewHost, informs |this|. | 
 |  235   PageClickTracker page_click_tracker_; | 
 |  236  | 
|  199   // The ID of the last request sent for form field Autofill.  Used to ignore |  237   // The ID of the last request sent for form field Autofill.  Used to ignore | 
|  200   // out of date responses. |  238   // out of date responses. | 
|  201   int autofill_query_id_; |  239   int autofill_query_id_; | 
|  202  |  240  | 
|  203   // The element corresponding to the last request sent for form field Autofill. |  241   // The element corresponding to the last request sent for form field Autofill. | 
|  204   blink::WebFormControlElement element_; |  242   blink::WebFormControlElement element_; | 
|  205  |  243  | 
|  206   // The form element currently requesting an interactive autocomplete. |  244   // The form element currently requesting an interactive autocomplete. | 
|  207   blink::WebFormElement in_flight_request_form_; |  245   blink::WebFormElement in_flight_request_form_; | 
|  208  |  246  | 
|  209   // Pointer to the WebView. Used to access page scale factor. |  | 
|  210   blink::WebView* web_view_; |  | 
|  211  |  | 
|  212   // Should we display a warning if autofill is disabled? |  247   // Should we display a warning if autofill is disabled? | 
|  213   bool display_warning_if_disabled_; |  248   bool display_warning_if_disabled_; | 
|  214  |  249  | 
|  215   // Was the query node autofilled prior to previewing the form? |  250   // Was the query node autofilled prior to previewing the form? | 
|  216   bool was_query_node_autofilled_; |  251   bool was_query_node_autofilled_; | 
|  217  |  252  | 
|  218   // Have we already shown Autofill suggestions for the field the user is |  253   // Have we already shown Autofill suggestions for the field the user is | 
|  219   // currently editing?  Used to keep track of state for metrics logging. |  254   // currently editing?  Used to keep track of state for metrics logging. | 
|  220   bool has_shown_autofill_popup_for_current_edit_; |  255   bool has_shown_autofill_popup_for_current_edit_; | 
|  221  |  256  | 
|  222   // If true we just set the node text so we shouldn't show the popup. |  257   // If true we just set the node text so we shouldn't show the popup. | 
|  223   bool did_set_node_text_; |  258   bool did_set_node_text_; | 
|  224  |  259  | 
|  225   // Whether or not to ignore text changes.  Useful for when we're committing |  260   // Whether or not to ignore text changes.  Useful for when we're committing | 
|  226   // a composition when we are defocusing the WebView and we don't want to |  261   // a composition when we are defocusing the WebView and we don't want to | 
|  227   // trigger an autofill popup to show. |  262   // trigger an autofill popup to show. | 
|  228   bool ignore_text_changes_; |  263   bool ignore_text_changes_; | 
|  229  |  264  | 
|  230   // Whether the Autofill popup is possibly visible.  This is tracked as a |  265   // Whether the Autofill popup is possibly visible.  This is tracked as a | 
|  231   // performance improvement, so that the IPC channel isn't flooded with |  266   // performance improvement, so that the IPC channel isn't flooded with | 
|  232   // messages to close the Autofill popup when it can't possibly be showing. |  267   // messages to close the Autofill popup when it can't possibly be showing. | 
|  233   bool is_popup_possibly_visible_; |  268   bool is_popup_possibly_visible_; | 
|  234  |  269  | 
|  235   // True if a message has already been sent about forms for the main frame. |  | 
|  236   // When the main frame is first loaded, a message is sent even if no forms |  | 
|  237   // exist in the frame. Otherwise, such messages are supressed. |  | 
|  238   bool main_frame_processed_; |  | 
|  239  |  | 
|  240   base::WeakPtrFactory<AutofillAgent> weak_ptr_factory_; |  270   base::WeakPtrFactory<AutofillAgent> weak_ptr_factory_; | 
|  241  |  271  | 
|  242   DISALLOW_COPY_AND_ASSIGN(AutofillAgent); |  272   DISALLOW_COPY_AND_ASSIGN(AutofillAgent); | 
|  243 }; |  273 }; | 
|  244  |  274  | 
|  245 }  // namespace autofill |  275 }  // namespace autofill | 
|  246  |  276  | 
|  247 #endif  // COMPONENTS_AUTOFILL_CONTENT_RENDERER_AUTOFILL_AGENT_H_ |  277 #endif  // COMPONENTS_AUTOFILL_CONTENT_RENDERER_AUTOFILL_AGENT_H_ | 
| OLD | NEW |