1 // Copyright 2019 The Chromium Embedded Framework Authors. Portions copyright 2 // 2013 The Chromium Authors. All rights reserved. Use of this source code is 3 // governed by a BSD-style license that can be found in the LICENSE file. 4 5 #ifndef CEF_LIBCEF_BROWSER_DEVTOOLS_DEVTOOLS_FILE_MANAGER_H_ 6 #define CEF_LIBCEF_BROWSER_DEVTOOLS_DEVTOOLS_FILE_MANAGER_H_ 7 8 #include "base/callback_forward.h" 9 #include "base/macros.h" 10 #include "base/memory/weak_ptr.h" 11 12 #include <map> 13 #include <string> 14 15 namespace base { 16 class FilePath; 17 class SequencedTaskRunner; 18 class Value; 19 } // namespace base 20 21 class AlloyBrowserHostImpl; 22 class PrefService; 23 24 // File management helper for DevTools. 25 // Based on chrome/browser/devtools/devtools_ui_bindings.cc and 26 // chrome/browser/devtools/devtools_file_helper.cc. 27 class CefDevToolsFileManager { 28 public: 29 CefDevToolsFileManager(AlloyBrowserHostImpl* browser_impl, 30 PrefService* prefs); 31 32 void SaveToFile(const std::string& url, 33 const std::string& content, 34 bool save_as); 35 void AppendToFile(const std::string& url, const std::string& content); 36 37 private: 38 // SaveToFile implementation: 39 typedef base::Callback<void(const std::string&)> SaveCallback; 40 typedef base::Callback<void()> CancelCallback; 41 void Save(const std::string& url, 42 const std::string& content, 43 bool save_as, 44 const SaveCallback& saveCallback, 45 const CancelCallback& cancelCallback); 46 void SaveAsDialogDismissed(const std::string& url, 47 const std::string& content, 48 const SaveCallback& saveCallback, 49 const CancelCallback& cancelCallback, 50 int selected_accept_filter, 51 const std::vector<base::FilePath>& file_paths); 52 void SaveAsFileSelected(const std::string& url, 53 const std::string& content, 54 const SaveCallback& callback, 55 const base::FilePath& path); 56 void FileSavedAs(const std::string& url, const std::string& file_system_path); 57 void CanceledFileSaveAs(const std::string& url); 58 59 // AppendToFile implementation: 60 typedef base::Callback<void(void)> AppendCallback; 61 void Append(const std::string& url, 62 const std::string& content, 63 const AppendCallback& callback); 64 void AppendedTo(const std::string& url); 65 66 void CallClientFunction(const std::string& function_name, 67 const base::Value* arg1, 68 const base::Value* arg2, 69 const base::Value* arg3); 70 71 // Guaranteed to outlive this object. 72 AlloyBrowserHostImpl* browser_impl_; 73 PrefService* prefs_; 74 75 typedef std::map<std::string, base::FilePath> PathsMap; 76 PathsMap saved_files_; 77 scoped_refptr<base::SequencedTaskRunner> file_task_runner_; 78 base::WeakPtrFactory<CefDevToolsFileManager> weak_factory_; 79 80 DISALLOW_COPY_AND_ASSIGN(CefDevToolsFileManager); 81 }; 82 83 #endif // CEF_LIBCEF_BROWSER_DEVTOOLS_DEVTOOLS_FILE_MANAGER_H_ 84