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