• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/memory/weak_ptr.h"
10 
11 #include <map>
12 #include <string>
13 
14 namespace base {
15 class FilePath;
16 class SequencedTaskRunner;
17 class Value;
18 }  // namespace base
19 
20 class AlloyBrowserHostImpl;
21 class PrefService;
22 
23 // File management helper for DevTools.
24 // Based on chrome/browser/devtools/devtools_ui_bindings.cc and
25 // chrome/browser/devtools/devtools_file_helper.cc.
26 class CefDevToolsFileManager {
27  public:
28   CefDevToolsFileManager(AlloyBrowserHostImpl* browser_impl,
29                          PrefService* prefs);
30 
31   CefDevToolsFileManager(const CefDevToolsFileManager&) = delete;
32   CefDevToolsFileManager& operator=(const CefDevToolsFileManager&) = delete;
33 
34   void SaveToFile(const std::string& url,
35                   const std::string& content,
36                   bool save_as);
37   void AppendToFile(const std::string& url, const std::string& content);
38 
39  private:
40   // SaveToFile implementation:
41   using SaveCallback = base::OnceCallback<void(const std::string&)>;
42   using CancelCallback = base::OnceCallback<void()>;
43   void Save(const std::string& url,
44             const std::string& content,
45             bool save_as,
46             SaveCallback saveCallback,
47             CancelCallback cancelCallback);
48   void SaveAsDialogDismissed(const std::string& url,
49                              const std::string& content,
50                              SaveCallback saveCallback,
51                              CancelCallback cancelCallback,
52                              int selected_accept_filter,
53                              const std::vector<base::FilePath>& file_paths);
54   void SaveAsFileSelected(const std::string& url,
55                           const std::string& content,
56                           SaveCallback callback,
57                           const base::FilePath& path);
58   void FileSavedAs(const std::string& url, const std::string& file_system_path);
59   void CanceledFileSaveAs(const std::string& url);
60 
61   // AppendToFile implementation:
62   using AppendCallback = base::OnceCallback<void(void)>;
63   void Append(const std::string& url,
64               const std::string& content,
65               AppendCallback callback);
66   void AppendedTo(const std::string& url);
67 
68   void CallClientFunction(const std::string& function_name,
69                           const base::Value* arg1,
70                           const base::Value* arg2,
71                           const base::Value* arg3);
72 
73   // Guaranteed to outlive this object.
74   AlloyBrowserHostImpl* browser_impl_;
75   PrefService* prefs_;
76 
77   using PathsMap = std::map<std::string, base::FilePath>;
78   PathsMap saved_files_;
79   scoped_refptr<base::SequencedTaskRunner> file_task_runner_;
80   base::WeakPtrFactory<CefDevToolsFileManager> weak_factory_;
81 };
82 
83 #endif  // CEF_LIBCEF_BROWSER_DEVTOOLS_DEVTOOLS_FILE_MANAGER_H_
84