Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(585)

Side by Side Diff: chrome/browser/ui/webui/options/password_manager_handler.h

Issue 1193143003: Enable import/export of passwords into/from Password Manager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comment Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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:
32 // Enumeration of different callers of SelectFile.
33 enum FileSelectorCaller {
34 IMPORT_FILE_SELECTED,
35 EXPORT_FILE_SELECTED,
36 };
37
26 PasswordManagerHandler(); 38 PasswordManagerHandler();
27 ~PasswordManagerHandler() override; 39 ~PasswordManagerHandler() override;
28 40
29 // OptionsPageUIHandler implementation. 41 // OptionsPageUIHandler implementation.
30 void GetLocalizedValues(base::DictionaryValue* localized_strings) override; 42 void GetLocalizedValues(base::DictionaryValue* localized_strings) override;
31 void InitializeHandler() override; 43 void InitializeHandler() override;
44 void InitializePage() override;
32 void RegisterMessages() override; 45 void RegisterMessages() override;
33 46
47 // ui::SelectFileDialog::Listener implementation.
48 // |params| is of type FileSelectorCaller which indicates direction of IO.
49 void FileSelected(const base::FilePath& path,
50 int index,
51 void* params) override;
52
34 // PasswordUIView implementation. 53 // PasswordUIView implementation.
35 Profile* GetProfile() override; 54 Profile* GetProfile() override;
36 void ShowPassword( 55 void ShowPassword(
37 size_t index, 56 size_t index,
38 const std::string& origin_url, 57 const std::string& origin_url,
39 const std::string& username, 58 const std::string& username,
40 const base::string16& password_value) override; 59 const base::string16& password_value) override;
41 void SetPasswordList( 60 void SetPasswordList(
42 const std::vector<std::unique_ptr<autofill::PasswordForm>>& password_list) 61 const std::vector<std::unique_ptr<autofill::PasswordForm>>& password_list)
43 override; 62 override;
44 void SetPasswordExceptionList( 63 void SetPasswordExceptionList(
45 const std::vector<std::unique_ptr<autofill::PasswordForm>>& 64 const std::vector<std::unique_ptr<autofill::PasswordForm>>&
46 password_exception_list) override; 65 password_exception_list) override;
47 #if !defined(OS_ANDROID) 66 #if !defined(OS_ANDROID)
48 gfx::NativeWindow GetNativeWindow() const override; 67 gfx::NativeWindow GetNativeWindow() const override;
49 #endif 68 #endif
69
70 protected:
71 // This constructor is used for testing only.
72 explicit PasswordManagerHandler(
73 scoped_ptr<PasswordManagerPresenter> presenter);
74
50 private: 75 private:
51 // Clears and then populates the list of passwords and password exceptions. 76 // Clears and then populates the list of passwords and password exceptions.
52 // Called when the JS PasswordManager object is initialized. 77 // Called when the JS PasswordManager object is initialized.
53 void HandleUpdatePasswordLists(const base::ListValue* args); 78 void HandleUpdatePasswordLists(const base::ListValue* args);
54 79
55 // Removes a saved password entry. 80 // Removes a saved password entry.
56 // |value| the entry index to be removed. 81 // |value| the entry index to be removed.
57 void HandleRemoveSavedPassword(const base::ListValue* args); 82 void HandleRemoveSavedPassword(const base::ListValue* args);
58 83
59 // Removes a saved password exception. 84 // Removes a saved password exception.
60 // |value| the entry index to be removed. 85 // |value| the entry index to be removed.
61 void HandleRemovePasswordException(const base::ListValue* args); 86 void HandleRemovePasswordException(const base::ListValue* args);
62 87
63 // Requests the plain text password for an entry to be revealed. 88 // Requests the plain text password for an entry to be revealed.
64 // |index| The index of the entry. 89 // |index| The index of the entry.
65 void HandleRequestShowPassword(const base::ListValue* args); 90 void HandleRequestShowPassword(const base::ListValue* args);
66 91
67 // The PasswordManagerPresenter object owned by the this view. 92 // Import from CSV/JSON file. The steps are:
68 PasswordManagerPresenter password_manager_presenter_; 93 // 1. user click import button -> HandlePasswordImport() ->
94 // start file selector
95 // 2. user selects file -> ImportPasswordFileSeleted() -> read to memory
96 // 3. read completes -> ImportPasswordFileRead() -> store to PasswordStore
97 void HandlePasswordImport(const base::ListValue* args);
98 void ImportPasswordFileSelected(const base::FilePath& path);
99 void ImportPasswordFileRead(password_manager::PasswordImporter::Result result,
100 const std::vector<autofill::PasswordForm>& forms);
101
102 // Export to CSV/JSON file. The steps are:
103 // 1. user click export button -> HandlePasswordExport() ->
104 // check OS password if necessary -> start file selector
105 // 2. user selects file -> ExportPasswordFileSeleted() ->
106 // write to memory buffer -> start write operation
107 void HandlePasswordExport(const base::ListValue* args);
108 void ExportPasswordFileSelected(const base::FilePath& path);
109
110 // A short class to persist imported password forms to password store.
111 class ImportPasswordResultConsumer
112 : public base::RefCountedThreadSafe<ImportPasswordResultConsumer> {
113 public:
114 explicit ImportPasswordResultConsumer(Profile* profile);
115
116 void ConsumePassword(password_manager::PasswordImporter::Result result,
117 const std::vector<autofill::PasswordForm>& forms);
118
119 private:
120 friend class base::RefCountedThreadSafe<ImportPasswordResultConsumer>;
121
122 ~ImportPasswordResultConsumer() {}
123
124 Profile* profile_;
125 };
126
127 // User pref for storing accept languages.
128 std::string languages_;
129
130 scoped_ptr<PasswordManagerPresenter> password_manager_presenter_;
131
132 // File picker to import/export file path.
133 scoped_refptr<ui::SelectFileDialog> select_file_dialog_;
69 134
70 DISALLOW_COPY_AND_ASSIGN(PasswordManagerHandler); 135 DISALLOW_COPY_AND_ASSIGN(PasswordManagerHandler);
71 }; 136 };
72 137
73 } // namespace options 138 } // namespace options
74 139
75 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_PASSWORD_MANAGER_HANDLER_H_ 140 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_PASSWORD_MANAGER_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698