blob: 861fa0adefe30c6531b7f14d2ab1d03e0c5f6c7a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_WEBUI_POLICY_TOOL_UI_HANDLER_H_
#define CHROME_BROWSER_UI_WEBUI_POLICY_TOOL_UI_HANDLER_H_
#include "base/files/file_path.h"
#include "chrome/browser/ui/webui/policy_ui_handler.h"
class PolicyToolUIHandler : public PolicyUIHandler {
public:
PolicyToolUIHandler();
~PolicyToolUIHandler() override;
// content::WebUIMessageHandler implementation.
void RegisterMessages() override;
void OnJavascriptDisallowed() override;
private:
friend class PolicyToolUITest;
enum class SessionErrors {
kNone = 0,
kInvalidSessionName,
kSessionNameExist,
kSessionNameNotExist,
kRenamedSessionError,
};
// Reads the current session file (based on the session_name_) and sends the
// contents to the UI.
void ImportFile();
void HandleInitializedAdmin(const base::ListValue* args);
void HandleLoadSession(const base::ListValue* args);
// Rename a session if the new session name doesn't exist.
void HandleRenameSession(const base::ListValue* args);
void HandleUpdateSession(const base::ListValue* args);
void HandleResetSession(const base::ListValue* args);
void HandleDeleteSession(const base::ListValue* args);
void HandleExportLinux(const base::ListValue* args);
void OnSessionDeleted(bool is_successful);
std::string ReadOrCreateFileCallback();
void OnFileRead(const std::string& contents);
static SessionErrors DoRenameSession(const base::FilePath& old_session_path,
const base::FilePath& new_session_path);
void OnSessionRenamed(SessionErrors result);
bool DoUpdateSession(const std::string& contents);
void OnSessionUpdated(bool is_successful);
bool IsValidSessionName(const base::FilePath::StringType& name) const;
base::FilePath GetSessionPath(const base::FilePath::StringType& name) const;
void OnSessionsListReceived(base::ListValue list);
void SetDefaultSessionName();
// ui::SelectFileDialog::Listener implementation.
void FileSelected(const base::FilePath& path,
int index,
void* params) override;
void FileSelectionCanceled(void* params) override;
void WriteSessionPolicyToFile(const base::FilePath& path) const;
void ExportSessionToFile(const base::FilePath::StringType& file_extension);
bool is_saving_enabled_ = true;
// This string is filled when an export action occurs, it contains the current
// session dictionary in a specific format. This format will be JSON, PLIST,
// or REG; depending on the kind of export.
std::string session_dict_for_exporting_;
base::FilePath sessions_dir_;
base::FilePath::StringType session_name_;
scoped_refptr<ui::SelectFileDialog> export_policies_select_file_dialog_;
base::WeakPtrFactory<PolicyToolUIHandler> callback_weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(PolicyToolUIHandler);
};
#endif // CHROME_BROWSER_UI_WEBUI_POLICY_TOOL_UI_HANDLER_H_
|