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_PASSWORD_AUTOFILL_AGENT_H_ | 5 #ifndef COMPONENTS_AUTOFILL_CONTENT_RENDERER_PASSWORD_AUTOFILL_AGENT_H_ |
6 #define COMPONENTS_AUTOFILL_CONTENT_RENDERER_PASSWORD_AUTOFILL_AGENT_H_ | 6 #define COMPONENTS_AUTOFILL_CONTENT_RENDERER_PASSWORD_AUTOFILL_AGENT_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/memory/linked_ptr.h" | 11 #include "base/memory/linked_ptr.h" |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
14 #include "components/autofill/core/common/password_form_fill_data.h" | 13 #include "components/autofill/core/common/password_form_fill_data.h" |
15 #include "content/public/renderer/render_view_observer.h" | 14 #include "content/public/renderer/render_view_observer.h" |
16 #include "third_party/WebKit/public/web/WebInputElement.h" | 15 #include "third_party/WebKit/public/web/WebInputElement.h" |
17 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" | |
18 | 16 |
19 namespace blink { | 17 namespace blink { |
20 class WebInputElement; | 18 class WebInputElement; |
21 class WebKeyboardEvent; | 19 class WebKeyboardEvent; |
22 class WebSecurityOrigin; | 20 class WebSecurityOrigin; |
23 class WebView; | 21 class WebView; |
24 } | 22 } |
25 | 23 |
26 namespace autofill { | 24 namespace autofill { |
27 | 25 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
74 struct PasswordInfo { | 72 struct PasswordInfo { |
75 blink::WebInputElement password_field; | 73 blink::WebInputElement password_field; |
76 PasswordFormFillData fill_data; | 74 PasswordFormFillData fill_data; |
77 bool backspace_pressed_last; | 75 bool backspace_pressed_last; |
78 PasswordInfo() : backspace_pressed_last(false) {} | 76 PasswordInfo() : backspace_pressed_last(false) {} |
79 }; | 77 }; |
80 typedef std::map<blink::WebElement, PasswordInfo> LoginToPasswordInfoMap; | 78 typedef std::map<blink::WebElement, PasswordInfo> LoginToPasswordInfoMap; |
81 typedef std::map<blink::WebFrame*, | 79 typedef std::map<blink::WebFrame*, |
82 linked_ptr<PasswordForm> > FrameToPasswordFormMap; | 80 linked_ptr<PasswordForm> > FrameToPasswordFormMap; |
83 | 81 |
84 class AutofillWebUserGestureHandler : public blink::WebUserGestureHandler { | 82 // This class holds a vector of autofilled password input elements and makes |
83 // sure the autofilled password value is not accessible to JavaScript code | |
84 // until the user interacts with the page. | |
85 class PasswordValueGatekeeper { | |
85 public: | 86 public: |
86 AutofillWebUserGestureHandler(PasswordAutofillAgent* agent); | 87 PasswordValueGatekeeper(); |
87 virtual ~AutofillWebUserGestureHandler(); | 88 ~PasswordValueGatekeeper(); |
88 | 89 |
89 void addElement(const blink::WebInputElement& element) { | 90 // Call this for every autofilled password field, so that the gatekeeper |
90 elements_.push_back(element); | 91 // protects the value accordingly. |
91 } | 92 void RegisterElement(blink::WebInputElement& element); |
Ilya Sherman
2014/02/14 23:07:33
nit: Please pass by const-reference, pointer, or c
vabr (Chromium)
2014/02/17 14:24:56
Thanks for catching this! I went with the pointer,
| |
92 | 93 |
93 void clearElements() { | 94 // Call this to notify the gatekeeper that the user interacted with the |
94 elements_.clear(); | 95 // page. |
95 } | 96 void OnGesture(); |
Ilya Sherman
2014/02/14 23:07:33
nit: Perhaps "OnUserInteraction()" or "OnUserGestu
vabr (Chromium)
2014/02/17 14:24:56
Done. I chose OnUserGesture to match the naming fr
| |
96 | 97 |
97 virtual void onGesture(); | 98 // Call this to reset the gatekeeper on a new page navigation. |
99 void Reset(); | |
98 | 100 |
99 private: | 101 private: |
100 PasswordAutofillAgent* agent_; | 102 // Make the value of |element| accessible to JavaScript code. |
103 void ShowValue(blink::WebInputElement& element); | |
Ilya Sherman
2014/02/14 23:07:33
nit: Please pass by const-reference, pointer, or c
vabr (Chromium)
2014/02/17 14:24:56
Thanks! Done, the same as RegisterElement.
| |
104 | |
105 bool was_user_gesture_seen_; | |
101 std::vector<blink::WebInputElement> elements_; | 106 std::vector<blink::WebInputElement> elements_; |
107 | |
108 DISALLOW_COPY_AND_ASSIGN(PasswordValueGatekeeper); | |
102 }; | 109 }; |
103 | 110 |
104 // RenderViewObserver: | 111 // RenderViewObserver: |
105 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 112 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
106 virtual void DidStartProvisionalLoad(blink::WebFrame* frame) OVERRIDE; | 113 virtual void DidStartProvisionalLoad(blink::WebFrame* frame) OVERRIDE; |
107 virtual void DidStartLoading() OVERRIDE; | 114 virtual void DidStartLoading() OVERRIDE; |
108 virtual void DidFinishDocumentLoad(blink::WebFrame* frame) OVERRIDE; | 115 virtual void DidFinishDocumentLoad(blink::WebFrame* frame) OVERRIDE; |
109 virtual void DidFinishLoad(blink::WebFrame* frame) OVERRIDE; | 116 virtual void DidFinishLoad(blink::WebFrame* frame) OVERRIDE; |
110 virtual void FrameDetached(blink::WebFrame* frame) OVERRIDE; | 117 virtual void FrameDetached(blink::WebFrame* frame) OVERRIDE; |
111 virtual void FrameWillClose(blink::WebFrame* frame) OVERRIDE; | 118 virtual void FrameWillClose(blink::WebFrame* frame) OVERRIDE; |
112 virtual void WillSendSubmitEvent(blink::WebFrame* frame, | 119 virtual void WillSendSubmitEvent(blink::WebFrame* frame, |
113 const blink::WebFormElement& form) OVERRIDE; | 120 const blink::WebFormElement& form) OVERRIDE; |
114 virtual void WillSubmitForm(blink::WebFrame* frame, | 121 virtual void WillSubmitForm(blink::WebFrame* frame, |
115 const blink::WebFormElement& form) OVERRIDE; | 122 const blink::WebFormElement& form) OVERRIDE; |
123 virtual void ProcessingUserGestureEvent() OVERRIDE; | |
116 | 124 |
117 // RenderView IPC handlers: | 125 // RenderView IPC handlers: |
118 void OnFillPasswordForm(const PasswordFormFillData& form_data); | 126 void OnFillPasswordForm(const PasswordFormFillData& form_data); |
119 | 127 |
120 // Scans the given frame for password forms and sends them up to the browser. | 128 // Scans the given frame for password forms and sends them up to the browser. |
121 // If |only_visible| is true, only forms visible in the layout are sent. | 129 // If |only_visible| is true, only forms visible in the layout are sent. |
122 void SendPasswordForms(blink::WebFrame* frame, bool only_visible); | 130 void SendPasswordForms(blink::WebFrame* frame, bool only_visible); |
123 | 131 |
124 void GetSuggestions(const PasswordFormFillData& fill_data, | 132 void GetSuggestions(const PasswordFormFillData& fill_data, |
125 const base::string16& input, | 133 const base::string16& input, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
176 // Used for UMA stats. | 184 // Used for UMA stats. |
177 OtherPossibleUsernamesUsage usernames_usage_; | 185 OtherPossibleUsernamesUsage usernames_usage_; |
178 | 186 |
179 // Pointer to the WebView. Used to access page scale factor. | 187 // Pointer to the WebView. Used to access page scale factor. |
180 blink::WebView* web_view_; | 188 blink::WebView* web_view_; |
181 | 189 |
182 // Set if the user might be submitting a password form on the current page, | 190 // Set if the user might be submitting a password form on the current page, |
183 // but the submit may still fail (i.e. doesn't pass JavaScript validation). | 191 // but the submit may still fail (i.e. doesn't pass JavaScript validation). |
184 FrameToPasswordFormMap provisionally_saved_forms_; | 192 FrameToPasswordFormMap provisionally_saved_forms_; |
185 | 193 |
186 scoped_ptr<AutofillWebUserGestureHandler> gesture_handler_; | 194 PasswordValueGatekeeper gatekeeper_; |
187 | 195 |
188 bool user_gesture_occurred_; | 196 bool user_gesture_occurred_; |
189 | 197 |
190 base::WeakPtrFactory<PasswordAutofillAgent> weak_ptr_factory_; | 198 base::WeakPtrFactory<PasswordAutofillAgent> weak_ptr_factory_; |
191 | 199 |
192 DISALLOW_COPY_AND_ASSIGN(PasswordAutofillAgent); | 200 DISALLOW_COPY_AND_ASSIGN(PasswordAutofillAgent); |
193 }; | 201 }; |
194 | 202 |
195 } // namespace autofill | 203 } // namespace autofill |
196 | 204 |
197 #endif // COMPONENTS_AUTOFILL_CONTENT_RENDERER_PASSWORD_AUTOFILL_AGENT_H_ | 205 #endif // COMPONENTS_AUTOFILL_CONTENT_RENDERER_PASSWORD_AUTOFILL_AGENT_H_ |
OLD | NEW |