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_GENERATION_MANAGER_H_ | 5 #ifndef COMPONENTS_AUTOFILL_CONTENT_RENDERER_PASSWORD_GENERATION_MANAGER_H_ |
6 #define COMPONENTS_AUTOFILL_CONTENT_RENDERER_PASSWORD_GENERATION_MANAGER_H_ | 6 #define COMPONENTS_AUTOFILL_CONTENT_RENDERER_PASSWORD_GENERATION_MANAGER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "content/public/renderer/render_view_observer.h" | 13 #include "content/public/renderer/render_view_observer.h" |
14 #include "third_party/WebKit/public/web/WebInputElement.h" | 14 #include "third_party/WebKit/public/web/WebInputElement.h" |
15 #include "third_party/WebKit/public/web/WebPasswordGeneratorClient.h" | 15 #include "third_party/WebKit/public/web/WebPasswordGeneratorClient.h" |
16 #include "url/gurl.h" | 16 #include "url/gurl.h" |
17 | 17 |
18 namespace WebKit { | 18 namespace WebKit { |
19 class WebCString; | 19 class WebCString; |
20 class WebDocument; | 20 class WebDocument; |
21 } | 21 } |
22 | 22 |
23 namespace autofill { | 23 namespace autofill { |
24 struct FormData; | |
25 } | |
26 | |
27 namespace content { | |
28 struct PasswordForm; | |
29 } | |
30 | |
31 namespace autofill { | |
32 | 24 |
| 25 struct FormData; |
| 26 struct PasswordForm; |
| 27 |
33 // This class is responsible for controlling communication for password | 28 // This class is responsible for controlling communication for password |
34 // generation between the browser (which shows the popup and generates | 29 // generation between the browser (which shows the popup and generates |
35 // passwords) and WebKit (shows the generation icon in the password field). | 30 // passwords) and WebKit (shows the generation icon in the password field). |
36 class PasswordGenerationManager : public content::RenderViewObserver, | 31 class PasswordGenerationManager : public content::RenderViewObserver, |
37 public WebKit::WebPasswordGeneratorClient { | 32 public WebKit::WebPasswordGeneratorClient { |
38 public: | 33 public: |
39 explicit PasswordGenerationManager(content::RenderView* render_view); | 34 explicit PasswordGenerationManager(content::RenderView* render_view); |
40 virtual ~PasswordGenerationManager(); | 35 virtual ~PasswordGenerationManager(); |
41 | 36 |
42 protected: | 37 protected: |
43 // Returns true if this document is one that we should consider analyzing. | 38 // Returns true if this document is one that we should consider analyzing. |
44 // Virtual so that it can be overriden during testing. | 39 // Virtual so that it can be overriden during testing. |
45 virtual bool ShouldAnalyzeDocument(const WebKit::WebDocument& document) const; | 40 virtual bool ShouldAnalyzeDocument(const WebKit::WebDocument& document) const; |
46 | 41 |
47 // RenderViewObserver: | 42 // RenderViewObserver: |
48 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 43 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
49 | 44 |
50 private: | 45 private: |
51 // RenderViewObserver: | 46 // RenderViewObserver: |
52 virtual void DidFinishDocumentLoad(WebKit::WebFrame* frame) OVERRIDE; | 47 virtual void DidFinishDocumentLoad(WebKit::WebFrame* frame) OVERRIDE; |
53 virtual void DidFinishLoad(WebKit::WebFrame* frame) OVERRIDE; | 48 virtual void DidFinishLoad(WebKit::WebFrame* frame) OVERRIDE; |
54 | 49 |
55 // WebPasswordGeneratorClient: | 50 // WebPasswordGeneratorClient: |
56 virtual void openPasswordGenerator(WebKit::WebInputElement& element) OVERRIDE; | 51 virtual void openPasswordGenerator(WebKit::WebInputElement& element) OVERRIDE; |
57 | 52 |
58 // Message handlers. | 53 // Message handlers. |
59 void OnFormNotBlacklisted(const content::PasswordForm& form); | 54 void OnFormNotBlacklisted(const PasswordForm& form); |
60 void OnPasswordAccepted(const base::string16& password); | 55 void OnPasswordAccepted(const base::string16& password); |
61 void OnPasswordGenerationEnabled(bool enabled); | 56 void OnPasswordGenerationEnabled(bool enabled); |
62 void OnAccountCreationFormsDetected( | 57 void OnAccountCreationFormsDetected( |
63 const std::vector<autofill::FormData>& forms); | 58 const std::vector<autofill::FormData>& forms); |
64 | 59 |
65 // Helper function to decide whether we should show password generation icon. | 60 // Helper function to decide whether we should show password generation icon. |
66 void MaybeShowIcon(); | 61 void MaybeShowIcon(); |
67 | 62 |
68 content::RenderView* render_view_; | 63 content::RenderView* render_view_; |
69 | 64 |
70 // True if password generation is enabled for the profile associated | 65 // True if password generation is enabled for the profile associated |
71 // with this renderer. | 66 // with this renderer. |
72 bool enabled_; | 67 bool enabled_; |
73 | 68 |
74 // Stores the origin of the account creation form we detected. | 69 // Stores the origin of the account creation form we detected. |
75 scoped_ptr<content::PasswordForm> possible_account_creation_form_; | 70 scoped_ptr<PasswordForm> possible_account_creation_form_; |
76 | 71 |
77 // Stores the origins of the password forms confirmed not to be blacklisted | 72 // Stores the origins of the password forms confirmed not to be blacklisted |
78 // by the browser. A form can be blacklisted if a user chooses "never save | 73 // by the browser. A form can be blacklisted if a user chooses "never save |
79 // passwords for this site". | 74 // passwords for this site". |
80 std::vector<GURL> not_blacklisted_password_form_origins_; | 75 std::vector<GURL> not_blacklisted_password_form_origins_; |
81 | 76 |
82 // Stores each password form for which the Autofill server classifies one of | 77 // Stores each password form for which the Autofill server classifies one of |
83 // the form's fields as an ACCOUNT_CREATION_PASSWORD. | 78 // the form's fields as an ACCOUNT_CREATION_PASSWORD. |
84 std::vector<autofill::FormData> account_creation_forms_; | 79 std::vector<autofill::FormData> account_creation_forms_; |
85 | 80 |
86 std::vector<WebKit::WebInputElement> passwords_; | 81 std::vector<WebKit::WebInputElement> passwords_; |
87 | 82 |
88 DISALLOW_COPY_AND_ASSIGN(PasswordGenerationManager); | 83 DISALLOW_COPY_AND_ASSIGN(PasswordGenerationManager); |
89 }; | 84 }; |
90 | 85 |
91 } // namespace autofill | 86 } // namespace autofill |
92 | 87 |
93 #endif // COMPONENTS_AUTOFILL_CONTENT_RENDERER_PASSWORD_GENERATION_MANAGER_H_ | 88 #endif // COMPONENTS_AUTOFILL_CONTENT_RENDERER_PASSWORD_GENERATION_MANAGER_H_ |
OLD | NEW |