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 CHROME_BROWSER_UI_WEBUI_OPTIONS_PASSWORD_MANAGER_HANDLER_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_OPTIONS_PASSWORD_MANAGER_HANDLER_H_ |
6 #define CHROME_BROWSER_UI_WEBUI_OPTIONS_PASSWORD_MANAGER_HANDLER_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_OPTIONS_PASSWORD_MANAGER_HANDLER_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/gtest_prod_util.h" | |
13 #include "base/macros.h" | 14 #include "base/macros.h" |
14 #include "build/build_config.h" | 15 #include "build/build_config.h" |
15 #include "chrome/browser/ui/passwords/password_manager_presenter.h" | 16 #include "chrome/browser/ui/passwords/password_manager_presenter.h" |
16 #include "chrome/browser/ui/passwords/password_ui_view.h" | 17 #include "chrome/browser/ui/passwords/password_ui_view.h" |
17 #include "chrome/browser/ui/webui/options/options_ui.h" | 18 #include "chrome/browser/ui/webui/options/options_ui.h" |
19 #include "components/password_manager/core/browser/import/password_importer.h" | |
18 #include "components/prefs/pref_member.h" | 20 #include "components/prefs/pref_member.h" |
21 #include "ui/shell_dialogs/select_file_dialog.h" | |
22 | |
23 class PasswordManagerHandlerTest; | |
19 | 24 |
20 namespace options { | 25 namespace options { |
21 | 26 |
22 // The WebUI based PasswordUIView. Displays passwords in the web ui. | 27 // The WebUI based PasswordUIView. Displays passwords in the web ui. |
23 class PasswordManagerHandler : public OptionsPageUIHandler, | 28 class PasswordManagerHandler : public OptionsPageUIHandler, |
24 public PasswordUIView { | 29 public PasswordUIView, |
30 public ui::SelectFileDialog::Listener { | |
25 public: | 31 public: |
26 PasswordManagerHandler(); | 32 PasswordManagerHandler(); |
27 ~PasswordManagerHandler() override; | 33 ~PasswordManagerHandler() override; |
28 | 34 |
29 // OptionsPageUIHandler implementation. | 35 // OptionsPageUIHandler implementation. |
30 void GetLocalizedValues(base::DictionaryValue* localized_strings) override; | 36 void GetLocalizedValues(base::DictionaryValue* localized_strings) override; |
31 void InitializeHandler() override; | 37 void InitializeHandler() override; |
38 void InitializePage() override; | |
32 void RegisterMessages() override; | 39 void RegisterMessages() override; |
33 | 40 |
41 // ui::SelectFileDialog::Listener implementation | |
vabr (Chromium)
2016/04/12 08:55:39
Please comment on |params| being in fact of type F
xunlu
2016/04/18 02:09:13
Done.
| |
42 void FileSelected(const base::FilePath& path, | |
43 int index, | |
44 void* params) override; | |
45 | |
34 // PasswordUIView implementation. | 46 // PasswordUIView implementation. |
35 Profile* GetProfile() override; | 47 Profile* GetProfile() override; |
36 void ShowPassword( | 48 void ShowPassword( |
37 size_t index, | 49 size_t index, |
38 const std::string& origin_url, | 50 const std::string& origin_url, |
39 const std::string& username, | 51 const std::string& username, |
40 const base::string16& password_value) override; | 52 const base::string16& password_value) override; |
41 void SetPasswordList( | 53 void SetPasswordList( |
42 const std::vector<std::unique_ptr<autofill::PasswordForm>>& password_list) | 54 const std::vector<std::unique_ptr<autofill::PasswordForm>>& password_list) |
43 override; | 55 override; |
44 void SetPasswordExceptionList( | 56 void SetPasswordExceptionList( |
45 const std::vector<std::unique_ptr<autofill::PasswordForm>>& | 57 const std::vector<std::unique_ptr<autofill::PasswordForm>>& |
46 password_exception_list) override; | 58 password_exception_list) override; |
47 #if !defined(OS_ANDROID) | 59 #if !defined(OS_ANDROID) |
48 gfx::NativeWindow GetNativeWindow() const override; | 60 gfx::NativeWindow GetNativeWindow() const override; |
49 #endif | 61 #endif |
62 | |
63 protected: | |
64 // This constructor is used for testing only. | |
65 explicit PasswordManagerHandler( | |
66 scoped_ptr<PasswordManagerPresenter> presenter); | |
67 | |
50 private: | 68 private: |
51 // Clears and then populates the list of passwords and password exceptions. | 69 // Clears and then populates the list of passwords and password exceptions. |
52 // Called when the JS PasswordManager object is initialized. | 70 // Called when the JS PasswordManager object is initialized. |
53 void HandleUpdatePasswordLists(const base::ListValue* args); | 71 void HandleUpdatePasswordLists(const base::ListValue* args); |
54 | 72 |
55 // Removes a saved password entry. | 73 // Removes a saved password entry. |
56 // |value| the entry index to be removed. | 74 // |value| the entry index to be removed. |
57 void HandleRemoveSavedPassword(const base::ListValue* args); | 75 void HandleRemoveSavedPassword(const base::ListValue* args); |
58 | 76 |
59 // Removes a saved password exception. | 77 // Removes a saved password exception. |
60 // |value| the entry index to be removed. | 78 // |value| the entry index to be removed. |
61 void HandleRemovePasswordException(const base::ListValue* args); | 79 void HandleRemovePasswordException(const base::ListValue* args); |
62 | 80 |
63 // Requests the plain text password for an entry to be revealed. | 81 // Requests the plain text password for an entry to be revealed. |
64 // |index| The index of the entry. | 82 // |index| The index of the entry. |
65 void HandleRequestShowPassword(const base::ListValue* args); | 83 void HandleRequestShowPassword(const base::ListValue* args); |
66 | 84 |
67 // The PasswordManagerPresenter object owned by the this view. | 85 // Import from CSV/JSON file. The steps are: |
68 PasswordManagerPresenter password_manager_presenter_; | 86 // 1. user click import button -> HandlePasswordImport() -> |
87 // start file selector | |
88 // 2. user selects file -> ImportPasswordFileSeleted() -> read to memory | |
89 // 3. read completes -> ImportPasswordFileRead() -> store to PasswordStore | |
90 void HandlePasswordImport(const base::ListValue* args); | |
91 void ImportPasswordFileSelected(const base::FilePath& path); | |
92 void ImportPasswordFileRead(password_manager::PasswordImporter::Result result, | |
93 const std::vector<autofill::PasswordForm>& forms); | |
94 | |
95 // Export to CSV/JSON file. The steps are: | |
96 // 1. user click export button -> HandlePasswordExport() -> | |
97 // check OS password if necessary -> start file selector | |
98 // 2. user selects file -> ExportPasswordFileSeleted() -> | |
99 // write to memory buffer -> start write operation | |
100 void HandlePasswordExport(const base::ListValue* args); | |
101 void ExportPasswordFileSelected(const base::FilePath& path); | |
102 | |
103 // A short class to persist imported password forms to password store. | |
104 class ImportPasswordResultConsumer | |
105 : public base::RefCountedThreadSafe<ImportPasswordResultConsumer> { | |
106 public: | |
107 explicit ImportPasswordResultConsumer(Profile* profile); | |
108 | |
109 void ConsumePassword(password_manager::PasswordImporter::Result result, | |
110 const std::vector<autofill::PasswordForm>& forms); | |
111 | |
112 private: | |
113 friend class base::RefCountedThreadSafe<ImportPasswordResultConsumer>; | |
114 | |
115 ~ImportPasswordResultConsumer() {} | |
116 | |
117 Profile* profile_; | |
118 }; | |
119 | |
120 // User pref for storing accept languages. | |
121 std::string languages_; | |
122 | |
123 scoped_ptr<PasswordManagerPresenter> password_manager_presenter_; | |
124 | |
125 // File picker to import/export file path. | |
126 scoped_refptr<ui::SelectFileDialog> select_file_dialog_; | |
69 | 127 |
70 DISALLOW_COPY_AND_ASSIGN(PasswordManagerHandler); | 128 DISALLOW_COPY_AND_ASSIGN(PasswordManagerHandler); |
71 }; | 129 }; |
72 | 130 |
73 } // namespace options | 131 } // namespace options |
74 | 132 |
75 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_PASSWORD_MANAGER_HANDLER_H_ | 133 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_PASSWORD_MANAGER_HANDLER_H_ |
OLD | NEW |