| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_PASSWORD_AUTOCOMPLETE_MANAGER_H_ | 5 #ifndef CHROME_RENDERER_AUTOFILL_PASSWORD_AUTOFILL_MANAGER_H_ |
| 6 #define CHROME_RENDERER_PASSWORD_AUTOCOMPLETE_MANAGER_H_ | 6 #define CHROME_RENDERER_AUTOFILL_PASSWORD_AUTOFILL_MANAGER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/task.h" | 12 #include "base/task.h" |
| 13 #include "chrome/renderer/page_click_listener.h" | 13 #include "chrome/renderer/page_click_listener.h" |
| 14 #include "chrome/renderer/render_view_observer.h" | 14 #include "chrome/renderer/render_view_observer.h" |
| 15 #include "webkit/glue/password_form_dom_manager.h" | 15 #include "webkit/glue/password_form_dom_manager.h" |
| 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h" |
| 17 | 17 |
| 18 namespace WebKit { | 18 namespace WebKit { |
| 19 class WebInputElement; | 19 class WebInputElement; |
| 20 class WebKeyboardEvent; | 20 class WebKeyboardEvent; |
| 21 } | 21 } |
| 22 | 22 |
| 23 namespace autofill { |
| 24 |
| 23 // This class is responsible for filling password forms. | 25 // This class is responsible for filling password forms. |
| 24 // There is one PasswordAutocompleteManager per RenderView. | 26 // There is one PasswordAutoFillManager per RenderView. |
| 25 class PasswordAutocompleteManager : public RenderViewObserver, | 27 class PasswordAutoFillManager : public RenderViewObserver, |
| 26 public PageClickListener { | 28 public PageClickListener { |
| 27 public: | 29 public: |
| 28 explicit PasswordAutocompleteManager(RenderView* render_view); | 30 explicit PasswordAutoFillManager(RenderView* render_view); |
| 29 virtual ~PasswordAutocompleteManager(); | 31 virtual ~PasswordAutoFillManager(); |
| 30 | 32 |
| 31 // WebViewClient editor related calls forwarded by the RenderView. | 33 // WebViewClient editor related calls forwarded by the RenderView. |
| 32 // If they return true, it indicates the event was consumed and should not | 34 // If they return true, it indicates the event was consumed and should not |
| 33 // be used for any other autofill activity. | 35 // be used for any other autofill activity. |
| 34 bool TextFieldDidEndEditing(const WebKit::WebInputElement& element); | 36 bool TextFieldDidEndEditing(const WebKit::WebInputElement& element); |
| 35 bool TextDidChangeInTextField(const WebKit::WebInputElement& element); | 37 bool TextDidChangeInTextField(const WebKit::WebInputElement& element); |
| 36 bool TextFieldHandlingKeyDown(const WebKit::WebInputElement& element, | 38 bool TextFieldHandlingKeyDown(const WebKit::WebInputElement& element, |
| 37 const WebKit::WebKeyboardEvent& event); | 39 const WebKit::WebKeyboardEvent& event); |
| 38 // Fills the password associated with user name |value|. Returns true if the | 40 // Fills the password associated with user name |value|. Returns true if the |
| 39 // username and password fields were filled, false otherwise. | 41 // username and password fields were filled, false otherwise. |
| 40 bool DidSelectAutoFillSuggestion(const WebKit::WebNode& node, | 42 bool DidSelectAutoFillSuggestion(const WebKit::WebNode& node, |
| 41 const WebKit::WebString& value); | 43 const WebKit::WebString& value); |
| 42 | 44 |
| 43 private: | 45 private: |
| 44 friend class PasswordAutocompleteManagerTest; | 46 friend class PasswordAutoFillManagerTest; |
| 45 | 47 |
| 46 struct PasswordInfo { | 48 struct PasswordInfo { |
| 47 WebKit::WebInputElement password_field; | 49 WebKit::WebInputElement password_field; |
| 48 webkit_glue::PasswordFormFillData fill_data; | 50 webkit_glue::PasswordFormFillData fill_data; |
| 49 bool backspace_pressed_last; | 51 bool backspace_pressed_last; |
| 50 PasswordInfo() : backspace_pressed_last(false) {} | 52 PasswordInfo() : backspace_pressed_last(false) {} |
| 51 }; | 53 }; |
| 52 typedef std::map<WebKit::WebElement, PasswordInfo> LoginToPasswordInfoMap; | 54 typedef std::map<WebKit::WebElement, PasswordInfo> LoginToPasswordInfoMap; |
| 53 | 55 |
| 54 // RenderViewObserver: | 56 // RenderViewObserver: |
| 55 virtual bool OnMessageReceived(const IPC::Message& message); | 57 virtual bool OnMessageReceived(const IPC::Message& message); |
| 56 virtual void DidFinishDocumentLoad(WebKit::WebFrame* frame); | 58 virtual void DidFinishDocumentLoad(WebKit::WebFrame* frame); |
| 57 virtual void DidFinishLoad(WebKit::WebFrame* frame); | 59 virtual void DidFinishLoad(WebKit::WebFrame* frame); |
| 58 virtual void FrameDetached(WebKit::WebFrame* frame); | 60 virtual void FrameDetached(WebKit::WebFrame* frame); |
| 59 virtual void FrameWillClose(WebKit::WebFrame* frame); | 61 virtual void FrameWillClose(WebKit::WebFrame* frame); |
| 60 | 62 |
| 61 // PageClickListener: | 63 // PageClickListener: |
| 62 virtual bool InputElementClicked(const WebKit::WebInputElement& element, | 64 virtual bool InputElementClicked(const WebKit::WebInputElement& element, |
| 63 bool was_focused, | 65 bool was_focused, |
| 64 bool is_focused); | 66 bool is_focused); |
| 65 | 67 |
| 66 // RenderView IPC handlers: | 68 // RenderView IPC handlers: |
| 67 void OnFillPasswordForm( | 69 void OnFillPasswordForm(const webkit_glue::PasswordFormFillData& form_data); |
| 68 const webkit_glue::PasswordFormFillData& form_data); | |
| 69 | 70 |
| 70 // Scans the given frame for password forms and sends them up to the browser. | 71 // Scans the given frame for password forms and sends them up to the browser. |
| 71 // If |only_visible| is true, only forms visible in the layout are sent. | 72 // If |only_visible| is true, only forms visible in the layout are sent. |
| 72 void SendPasswordForms(WebKit::WebFrame* frame, bool only_visible); | 73 void SendPasswordForms(WebKit::WebFrame* frame, bool only_visible); |
| 73 | 74 |
| 74 void GetSuggestions( | 75 void GetSuggestions(const webkit_glue::PasswordFormFillData& fill_data, |
| 75 const webkit_glue::PasswordFormFillData& fill_data, | 76 const string16& input, |
| 76 const string16& input, | 77 std::vector<string16>* suggestions); |
| 77 std::vector<string16>* suggestions); | |
| 78 | 78 |
| 79 bool ShowSuggestionPopup( | 79 bool ShowSuggestionPopup(const webkit_glue::PasswordFormFillData& fill_data, |
| 80 const webkit_glue::PasswordFormFillData& fill_data, | 80 const WebKit::WebInputElement& user_input); |
| 81 const WebKit::WebInputElement& user_input); | |
| 82 | 81 |
| 83 bool FillUserNameAndPassword( | 82 bool FillUserNameAndPassword( |
| 84 WebKit::WebInputElement* username_element, | 83 WebKit::WebInputElement* username_element, |
| 85 WebKit::WebInputElement* password_element, | 84 WebKit::WebInputElement* password_element, |
| 86 const webkit_glue::PasswordFormFillData& fill_data, | 85 const webkit_glue::PasswordFormFillData& fill_data, |
| 87 bool exact_username_match, | 86 bool exact_username_match, |
| 88 bool set_selection); | 87 bool set_selection); |
| 89 | 88 |
| 90 // Fills |login_input| and |password| with the most relevant suggestion from | 89 // Fills |login_input| and |password| with the most relevant suggestion from |
| 91 // |fill_data| and shows a popup with other suggestions. | 90 // |fill_data| and shows a popup with other suggestions. |
| 92 void PerformInlineAutocomplete( | 91 void PerformInlineAutocomplete( |
| 93 const WebKit::WebInputElement& username, | 92 const WebKit::WebInputElement& username, |
| 94 const WebKit::WebInputElement& password, | 93 const WebKit::WebInputElement& password, |
| 95 const webkit_glue::PasswordFormFillData& fill_data); | 94 const webkit_glue::PasswordFormFillData& fill_data); |
| 96 | 95 |
| 97 // Invoked when the passed frame is closing. Gives us a chance to clear any | 96 // Invoked when the passed frame is closing. Gives us a chance to clear any |
| 98 // reference we may have to elements in that frame. | 97 // reference we may have to elements in that frame. |
| 99 void FrameClosing(const WebKit::WebFrame* frame); | 98 void FrameClosing(const WebKit::WebFrame* frame); |
| 100 | 99 |
| 101 // The logins we have filled so far with their associated info. | 100 // The logins we have filled so far with their associated info. |
| 102 LoginToPasswordInfoMap login_to_password_info_; | 101 LoginToPasswordInfoMap login_to_password_info_; |
| 103 | 102 |
| 104 ScopedRunnableMethodFactory<PasswordAutocompleteManager> method_factory_; | 103 ScopedRunnableMethodFactory<PasswordAutoFillManager> method_factory_; |
| 105 | 104 |
| 106 DISALLOW_COPY_AND_ASSIGN(PasswordAutocompleteManager); | 105 DISALLOW_COPY_AND_ASSIGN(PasswordAutoFillManager); |
| 107 }; | 106 }; |
| 108 | 107 |
| 109 #endif // CHROME_RENDERER_PASSWORD_AUTOCOMPLETE_MANAGER_H_ | 108 } // namespace autofill |
| 109 |
| 110 #endif // CHROME_RENDERER_AUTOFILL_PASSWORD_AUTOFILL_MANAGER_H_ |
| OLD | NEW |