Only grant permissions to new extensions from sync if they have the expected version
[chromium-blink-merge.git] / chrome / browser / devtools / devtools_file_helper.h
blob101f0d73dc014e72e4ba080bdbac8147cab121cf
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_DEVTOOLS_DEVTOOLS_FILE_HELPER_H_
6 #define CHROME_BROWSER_DEVTOOLS_DEVTOOLS_FILE_HELPER_H_
8 #include <map>
9 #include <string>
10 #include <vector>
12 #include "base/basictypes.h"
13 #include "base/callback.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/memory/weak_ptr.h"
16 #include "base/strings/string16.h"
18 class Profile;
20 namespace base {
21 class FilePath;
24 namespace content {
25 class WebContents;
28 class DevToolsFileHelper {
29 public:
30 struct FileSystem {
31 FileSystem();
32 FileSystem(const std::string& file_system_name,
33 const std::string& root_url,
34 const std::string& file_system_path);
36 std::string file_system_name;
37 std::string root_url;
38 std::string file_system_path;
41 DevToolsFileHelper(content::WebContents* web_contents, Profile* profile);
42 ~DevToolsFileHelper();
44 typedef base::Callback<void(void)> SaveCallback;
45 typedef base::Callback<void(void)> AppendCallback;
46 typedef base::Callback<
47 void(const std::vector<DevToolsFileHelper::FileSystem>&)>
48 RequestFileSystemsCallback;
49 typedef base::Callback<void(const DevToolsFileHelper::FileSystem&)>
50 AddFileSystemCallback;
51 typedef base::Callback<void(const base::string16&,
52 const base::Callback<void(bool)>&)>
53 ShowInfoBarCallback;
55 // Saves |content| to the file and associates its path with given |url|.
56 // If client is calling this method with given |url| for the first time
57 // or |save_as| is true, confirmation dialog is shown to the user.
58 void Save(const std::string& url,
59 const std::string& content,
60 bool save_as,
61 const SaveCallback& saveCallback,
62 const SaveCallback& cancelCallback);
64 // Append |content| to the file that has been associated with given |url|.
65 // The |url| can be associated with a file via calling Save method.
66 // If the Save method has not been called for this |url|, then
67 // Append method does nothing.
68 void Append(const std::string& url,
69 const std::string& content,
70 const AppendCallback& callback);
72 // Shows select folder dialog.
73 // If user cancels folder selection, passes empty FileSystem struct to
74 // |callback|.
75 // Shows infobar by means of |show_info_bar_callback| to let the user decide
76 // whether to grant security permissions or not.
77 // If user allows adding file system in infobar, grants renderer read/write
78 // permissions, registers isolated file system for it and passes FileSystem
79 // struct to |callback|. Saves file system path to prefs.
80 // If user denies adding file system in infobar, passes error string to
81 // |callback|.
82 void AddFileSystem(const AddFileSystemCallback& callback,
83 const ShowInfoBarCallback& show_info_bar_callback);
85 // Upgrades dragged file system permissions to a read-write access.
86 // Shows infobar by means of |show_info_bar_callback| to let the user decide
87 // whether to grant security permissions or not.
88 // If user allows adding file system in infobar, grants renderer read/write
89 // permissions, registers isolated file system for it and passes FileSystem
90 // struct to |callback|. Saves file system path to prefs.
91 // If user denies adding file system in infobar, passes error string to
92 // |callback|.
93 void UpgradeDraggedFileSystemPermissions(
94 const std::string& file_system_url,
95 const AddFileSystemCallback& callback,
96 const ShowInfoBarCallback& show_info_bar_callback);
98 // Loads file system paths from prefs, grants permissions and registers
99 // isolated file system for those of them that contain magic file and passes
100 // FileSystem structs for registered file systems to |callback|.
101 void RequestFileSystems(const RequestFileSystemsCallback& callback);
103 // Removes isolated file system for given |file_system_path|.
104 void RemoveFileSystem(const std::string& file_system_path);
106 // Returns whether access to the folder on given |file_system_path| was
107 // granted.
108 bool IsFileSystemAdded(const std::string& file_system_path);
110 private:
111 void SaveAsFileSelected(const std::string& url,
112 const std::string& content,
113 const SaveCallback& callback,
114 const base::FilePath& path);
115 void SaveAsFileSelectionCanceled(const SaveCallback& callback);
116 void InnerAddFileSystem(
117 const AddFileSystemCallback& callback,
118 const ShowInfoBarCallback& show_info_bar_callback,
119 const base::FilePath& path);
120 void AddUserConfirmedFileSystem(
121 const AddFileSystemCallback& callback,
122 const base::FilePath& path,
123 bool allowed);
124 void RestoreValidatedFileSystems(
125 const RequestFileSystemsCallback& callback,
126 const std::vector<base::FilePath>& file_paths);
128 content::WebContents* web_contents_;
129 Profile* profile_;
130 typedef std::map<std::string, base::FilePath> PathsMap;
131 PathsMap saved_files_;
132 base::WeakPtrFactory<DevToolsFileHelper> weak_factory_;
133 DISALLOW_COPY_AND_ASSIGN(DevToolsFileHelper);
136 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_FILE_HELPER_H_