Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Side by Side Diff: components/autofill/content/renderer/password_autofill_agent.h

Issue 163843002: Fix check for user gesture on password autofill (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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);
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();
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);
104
105 bool was_gesture_seen_;
jww 2014/02/13 21:34:00 nit: I'd suggest renaming this to something like w
vabr (Chromium) 2014/02/14 08:13:12 Done.
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 DidHandleKeyEvent() OVERRIDE;
124 virtual void DidHandleMouseEvent(const blink::WebMouseEvent& event) OVERRIDE;
125 virtual void DidHandleTouchEvent(const blink::WebTouchEvent& event) OVERRIDE;
116 126
117 // RenderView IPC handlers: 127 // RenderView IPC handlers:
118 void OnFillPasswordForm(const PasswordFormFillData& form_data); 128 void OnFillPasswordForm(const PasswordFormFillData& form_data);
119 129
120 // Scans the given frame for password forms and sends them up to the browser. 130 // 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. 131 // If |only_visible| is true, only forms visible in the layout are sent.
122 void SendPasswordForms(blink::WebFrame* frame, bool only_visible); 132 void SendPasswordForms(blink::WebFrame* frame, bool only_visible);
123 133
124 void GetSuggestions(const PasswordFormFillData& fill_data, 134 void GetSuggestions(const PasswordFormFillData& fill_data,
125 const base::string16& input, 135 const base::string16& input,
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 // Used for UMA stats. 186 // Used for UMA stats.
177 OtherPossibleUsernamesUsage usernames_usage_; 187 OtherPossibleUsernamesUsage usernames_usage_;
178 188
179 // Pointer to the WebView. Used to access page scale factor. 189 // Pointer to the WebView. Used to access page scale factor.
180 blink::WebView* web_view_; 190 blink::WebView* web_view_;
181 191
182 // Set if the user might be submitting a password form on the current page, 192 // 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). 193 // but the submit may still fail (i.e. doesn't pass JavaScript validation).
184 FrameToPasswordFormMap provisionally_saved_forms_; 194 FrameToPasswordFormMap provisionally_saved_forms_;
185 195
186 scoped_ptr<AutofillWebUserGestureHandler> gesture_handler_; 196 PasswordValueGatekeeper gatekeeper_;
187 197
188 bool user_gesture_occurred_; 198 bool user_gesture_occurred_;
189 199
190 base::WeakPtrFactory<PasswordAutofillAgent> weak_ptr_factory_; 200 base::WeakPtrFactory<PasswordAutofillAgent> weak_ptr_factory_;
191 201
192 DISALLOW_COPY_AND_ASSIGN(PasswordAutofillAgent); 202 DISALLOW_COPY_AND_ASSIGN(PasswordAutofillAgent);
193 }; 203 };
194 204
195 } // namespace autofill 205 } // namespace autofill
196 206
197 #endif // COMPONENTS_AUTOFILL_CONTENT_RENDERER_PASSWORD_AUTOFILL_AGENT_H_ 207 #endif // COMPONENTS_AUTOFILL_CONTENT_RENDERER_PASSWORD_AUTOFILL_AGENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698