OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 // A concrete definition of the DOM autocomplete framework defined by | 5 // A concrete definition of the DOM autocomplete framework defined by |
6 // autocomplete_input_listener.h, for the password manager. | 6 // autocomplete_input_listener.h, for the password manager. |
7 | 7 |
8 #ifndef WEBKIT_GLUE_PASSWORD_AUTOCOMPLETE_LISTENER_H_ | 8 #ifndef WEBKIT_GLUE_PASSWORD_AUTOCOMPLETE_LISTENER_H_ |
9 #define WEBKIT_GLUE_PASSWORD_AUTOCOMPLETE_LISTENER_H_ | 9 #define WEBKIT_GLUE_PASSWORD_AUTOCOMPLETE_LISTENER_H_ |
10 | 10 |
| 11 #include "config.h" |
| 12 |
| 13 #include "base/compiler_specific.h" |
| 14 |
| 15 MSVC_PUSH_WARNING_LEVEL(0); |
| 16 #include "HTMLInputElement.h" |
| 17 MSVC_POP_WARNING(); |
| 18 |
11 #include "base/basictypes.h" | 19 #include "base/basictypes.h" |
12 #include "webkit/glue/autocomplete_input_listener.h" | 20 #include "base/scoped_ptr.h" |
13 #include "webkit/glue/password_form_dom_manager.h" | 21 #include "webkit/glue/password_form_dom_manager.h" |
14 | 22 |
15 namespace webkit_glue { | 23 namespace webkit_glue { |
16 | 24 |
17 class PasswordAutocompleteListener : public AutocompleteInputListener { | 25 // A proxy interface to a WebCore::HTMLInputElement for inline autocomplete. |
| 26 // The delegate does not own the WebCore element; it only interfaces it. |
| 27 class HTMLInputDelegate { |
| 28 public: |
| 29 explicit HTMLInputDelegate(WebCore::HTMLInputElement* element); |
| 30 virtual ~HTMLInputDelegate(); |
| 31 |
| 32 virtual void SetValue(const std::wstring& value); |
| 33 virtual void SetSelectionRange(size_t start, size_t end); |
| 34 virtual void OnFinishedAutocompleting(); |
| 35 |
| 36 private: |
| 37 // The underlying DOM element we're wrapping. We reference the underlying |
| 38 // HTMLInputElement for its lifetime to ensure it does not get freed by |
| 39 // WebCore while in use by the delegate instance. |
| 40 WebCore::HTMLInputElement* element_; |
| 41 |
| 42 DISALLOW_COPY_AND_ASSIGN(HTMLInputDelegate); |
| 43 }; |
| 44 |
| 45 |
| 46 class PasswordAutocompleteListener { |
18 public: | 47 public: |
19 PasswordAutocompleteListener(HTMLInputDelegate* username_delegate, | 48 PasswordAutocompleteListener(HTMLInputDelegate* username_delegate, |
20 HTMLInputDelegate* password_delegate, | 49 HTMLInputDelegate* password_delegate, |
21 const PasswordFormDomManager::FillData& data); | 50 const PasswordFormDomManager::FillData& data); |
22 virtual ~PasswordAutocompleteListener() { | 51 virtual ~PasswordAutocompleteListener() { |
23 } | 52 } |
24 | 53 |
25 // AutocompleteInputListener implementation. | |
26 virtual void OnBlur(WebCore::HTMLInputElement* element, | 54 virtual void OnBlur(WebCore::HTMLInputElement* element, |
27 const std::wstring& user_input); | 55 const std::wstring& user_input); |
28 virtual void OnInlineAutocompleteNeeded(WebCore::HTMLInputElement* element, | 56 virtual void OnInlineAutocompleteNeeded(WebCore::HTMLInputElement* element, |
29 const std::wstring& user_input); | 57 const std::wstring& user_input); |
30 | 58 |
31 private: | 59 private: |
32 // Check if the input string resembles a potential matching login | 60 // Check if the input string resembles a potential matching login |
33 // (username/password) and if so, match them up by autocompleting | 61 // (username/password) and if so, match them up by autocompleting the edit |
34 // the edit delegates. | 62 // delegates. |
35 bool TryToMatch(const std::wstring& input, | 63 bool TryToMatch(const std::wstring& input, |
36 const std::wstring& username, | 64 const std::wstring& username, |
37 const std::wstring& password); | 65 const std::wstring& password); |
38 | 66 |
39 // Access to password field to autocomplete on blur/username updates. | 67 // Access to password field to autocomplete on blur/username updates. |
40 scoped_ptr<HTMLInputDelegate> password_delegate_; | 68 scoped_ptr<HTMLInputDelegate> password_delegate_; |
41 scoped_ptr<HTMLInputDelegate> username_delegate_; | 69 scoped_ptr<HTMLInputDelegate> username_delegate_; |
42 | 70 |
43 // Contains the extra logins for matching on delta/blur. | 71 // Contains the extra logins for matching on delta/blur. |
44 PasswordFormDomManager::FillData data_; | 72 PasswordFormDomManager::FillData data_; |
45 | 73 |
46 DISALLOW_COPY_AND_ASSIGN(PasswordAutocompleteListener); | 74 DISALLOW_COPY_AND_ASSIGN(PasswordAutocompleteListener); |
47 }; | 75 }; |
48 | 76 |
49 } // webkit_glue | 77 } // webkit_glue |
50 | 78 |
51 #endif // WEBKIT_GLUE_PASSWORD_AUTOCOMPLETE_LISTENER_H_ | 79 #endif // WEBKIT_GLUE_PASSWORD_AUTOCOMPLETE_LISTENER_H_ |
52 | 80 |
OLD | NEW |