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; |
(...skipping 13 matching lines...) Expand all Loading... |
57 void HandleRemoveSavedPassword(const base::ListValue* args); | 72 void HandleRemoveSavedPassword(const base::ListValue* args); |
58 | 73 |
59 // Removes a saved password exception. | 74 // Removes a saved password exception. |
60 // |value| the entry index to be removed. | 75 // |value| the entry index to be removed. |
61 void HandleRemovePasswordException(const base::ListValue* args); | 76 void HandleRemovePasswordException(const base::ListValue* args); |
62 | 77 |
63 // Requests the plain text password for an entry to be revealed. | 78 // Requests the plain text password for an entry to be revealed. |
64 // |index| The index of the entry. | 79 // |index| The index of the entry. |
65 void HandleRequestShowPassword(const base::ListValue* args); | 80 void HandleRequestShowPassword(const base::ListValue* args); |
66 | 81 |
| 82 // Import from CSV/JSON file. The steps are: |
| 83 // 1. user click import button -> HandlePasswordImport() -> |
| 84 // start file selector |
| 85 // 2. user selects file -> ImportPasswordFileSeleted() -> read to memory |
| 86 // 3. read completes -> ImportPasswordFileRead() -> store to PasswordStore |
| 87 void HandlePasswordImport(const base::ListValue* args); |
| 88 void ImportPasswordFileSelected(const base::FilePath& path); |
| 89 void ImportPasswordFileRead(password_manager::PasswordImporter::Result result, |
| 90 const std::vector<autofill::PasswordForm>& forms); |
| 91 |
| 92 // Export to CSV/JSON file. The steps are: |
| 93 // 1. user click export button -> HandlePasswordExport() -> |
| 94 // check OS password if necessary -> start file selector |
| 95 // 2. user selects file -> ExportPasswordFileSeleted() -> |
| 96 // write to memory buffer -> start write operation |
| 97 void HandlePasswordExport(const base::ListValue* args); |
| 98 void ExportPasswordFileSelected(const base::FilePath& path); |
| 99 |
| 100 // A short class to persist imported password forms to password store. |
| 101 class ImportPasswordResultConsumer |
| 102 : public base::RefCountedThreadSafe<ImportPasswordResultConsumer> { |
| 103 public: |
| 104 explicit ImportPasswordResultConsumer(Profile* profile); |
| 105 |
| 106 void ConsumePassword(password_manager::PasswordImporter::Result result, |
| 107 const std::vector<autofill::PasswordForm>& forms); |
| 108 |
| 109 private: |
| 110 friend class base::RefCountedThreadSafe<ImportPasswordResultConsumer>; |
| 111 |
| 112 ~ImportPasswordResultConsumer() {} |
| 113 |
| 114 Profile* profile_; |
| 115 }; |
| 116 |
67 // User pref for storing accept languages. | 117 // User pref for storing accept languages. |
68 std::string languages_; | 118 std::string languages_; |
69 | 119 |
70 // The PasswordManagerPresenter object owned by the this view. | 120 // The PasswordManagerPresenter object owned by the this view. |
71 PasswordManagerPresenter password_manager_presenter_; | 121 scoped_ptr<PasswordManagerPresenter> password_manager_presenter_; |
| 122 |
| 123 // Handle for file picker |
| 124 scoped_refptr<ui::SelectFileDialog> selected_file_dialog_; |
72 | 125 |
73 DISALLOW_COPY_AND_ASSIGN(PasswordManagerHandler); | 126 DISALLOW_COPY_AND_ASSIGN(PasswordManagerHandler); |
74 }; | 127 }; |
75 | 128 |
76 } // namespace options | 129 } // namespace options |
77 | 130 |
78 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_PASSWORD_MANAGER_HANDLER_H_ | 131 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_PASSWORD_MANAGER_HANDLER_H_ |
OLD | NEW |