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(); |
| 33 // This constructor is used for testing only. |
| 34 explicit PasswordManagerHandler( |
| 35 scoped_ptr<PasswordManagerPresenter> presenter); |
27 ~PasswordManagerHandler() override; | 36 ~PasswordManagerHandler() override; |
28 | 37 |
29 // OptionsPageUIHandler implementation. | 38 // OptionsPageUIHandler implementation. |
30 void GetLocalizedValues(base::DictionaryValue* localized_strings) override; | 39 void GetLocalizedValues(base::DictionaryValue* localized_strings) override; |
31 void InitializeHandler() override; | 40 void InitializeHandler() override; |
| 41 void InitializePage() override; |
32 void RegisterMessages() override; | 42 void RegisterMessages() override; |
33 | 43 |
| 44 // ui::SelectFileDialog::Listener implementation |
| 45 void FileSelected(const base::FilePath& path, |
| 46 int index, |
| 47 void* params) override; |
| 48 |
34 // PasswordUIView implementation. | 49 // PasswordUIView implementation. |
35 Profile* GetProfile() override; | 50 Profile* GetProfile() override; |
36 void ShowPassword( | 51 void ShowPassword( |
37 size_t index, | 52 size_t index, |
38 const std::string& origin_url, | 53 const std::string& origin_url, |
39 const std::string& username, | 54 const std::string& username, |
40 const base::string16& password_value) override; | 55 const base::string16& password_value) override; |
41 void SetPasswordList( | 56 void SetPasswordList( |
42 const std::vector<scoped_ptr<autofill::PasswordForm>>& password_list, | 57 const std::vector<scoped_ptr<autofill::PasswordForm>>& password_list, |
43 bool show_passwords) override; | 58 bool show_passwords) override; |
44 void SetPasswordExceptionList( | 59 void SetPasswordExceptionList( |
45 const std::vector<scoped_ptr<autofill::PasswordForm>>& | 60 const std::vector<scoped_ptr<autofill::PasswordForm>>& |
46 password_exception_list) override; | 61 password_exception_list) override; |
47 #if !defined(OS_ANDROID) | 62 #if !defined(OS_ANDROID) |
48 gfx::NativeWindow GetNativeWindow() const override; | 63 gfx::NativeWindow GetNativeWindow() const override; |
49 #endif | 64 #endif |
50 private: | 65 private: |
| 66 friend class ::PasswordManagerHandlerTest; |
| 67 |
51 // Clears and then populates the list of passwords and password exceptions. | 68 // Clears and then populates the list of passwords and password exceptions. |
52 // Called when the JS PasswordManager object is initialized. | 69 // Called when the JS PasswordManager object is initialized. |
53 void HandleUpdatePasswordLists(const base::ListValue* args); | 70 void HandleUpdatePasswordLists(const base::ListValue* args); |
54 | 71 |
55 // Removes a saved password entry. | 72 // Removes a saved password entry. |
56 // |value| the entry index to be removed. | 73 // |value| the entry index to be removed. |
57 void HandleRemoveSavedPassword(const base::ListValue* args); | 74 void HandleRemoveSavedPassword(const base::ListValue* args); |
58 | 75 |
59 // Removes a saved password exception. | 76 // Removes a saved password exception. |
60 // |value| the entry index to be removed. | 77 // |value| the entry index to be removed. |
61 void HandleRemovePasswordException(const base::ListValue* args); | 78 void HandleRemovePasswordException(const base::ListValue* args); |
62 | 79 |
63 // Requests the plain text password for an entry to be revealed. | 80 // Requests the plain text password for an entry to be revealed. |
64 // |index| The index of the entry. | 81 // |index| The index of the entry. |
65 void HandleRequestShowPassword(const base::ListValue* args); | 82 void HandleRequestShowPassword(const base::ListValue* args); |
66 | 83 |
| 84 // Import from CSV/JSON file. The steps are: |
| 85 // 1. user click import button -> HandlePasswordImport() -> |
| 86 // start file selector |
| 87 // 2. user selects file -> ImportPasswordFileSeleted() -> read to memory |
| 88 // 3. read completes -> ImportPasswordFileRead() -> store to PasswordStore |
| 89 void HandlePasswordImport(const base::ListValue* args); |
| 90 void ImportPasswordFileSelected(const base::FilePath& path); |
| 91 void ImportPasswordFileRead(password_manager::PasswordImporter::Result result, |
| 92 const std::vector<autofill::PasswordForm>& forms); |
| 93 |
| 94 // Export to CSV/JSON file. The steps are: |
| 95 // 1. user click export button -> HandlePasswordExport() -> |
| 96 // check OS password if necessary -> start file selector |
| 97 // 2. user selects file -> ExportPasswordFileSeleted() -> |
| 98 // write to memory buffer -> start write operation |
| 99 void HandlePasswordExport(const base::ListValue* args); |
| 100 void ExportPasswordFileSelected(const base::FilePath& path); |
| 101 |
67 // User pref for storing accept languages. | 102 // User pref for storing accept languages. |
68 std::string languages_; | 103 std::string languages_; |
69 | 104 |
70 // The PasswordManagerPresenter object owned by the this view. | 105 // The PasswordManagerPresenter object owned by the this view. |
71 PasswordManagerPresenter password_manager_presenter_; | 106 scoped_ptr<PasswordManagerPresenter> password_manager_presenter_; |
| 107 |
| 108 // Handle for file picker |
| 109 scoped_refptr<ui::SelectFileDialog> selected_file_dialog_; |
72 | 110 |
73 DISALLOW_COPY_AND_ASSIGN(PasswordManagerHandler); | 111 DISALLOW_COPY_AND_ASSIGN(PasswordManagerHandler); |
74 }; | 112 }; |
75 | 113 |
76 } // namespace options | 114 } // namespace options |
77 | 115 |
78 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_PASSWORD_MANAGER_HANDLER_H_ | 116 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_PASSWORD_MANAGER_HANDLER_H_ |
OLD | NEW |