#include "chrome/browser/devtools/devtools_file_helper.h"
#include <set>
#include <vector>
#include "base/base64.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/hash/md5.h"
#include "base/json/values_util.h"
#include "base/lazy_instance.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/bind_post_task.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/thread_pool.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/devtools/devtools_file_watcher.h"
#include "chrome/browser/download/download_prefs.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/chrome_select_file_policy.h"
#include "chrome/common/pref_names.h"
#include "chrome/grit/generated_resources.h"
#include "components/prefs/pref_service.h"
#include "components/prefs/scoped_user_pref_update.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/child_process_security_policy.h"
#include "content/public/browser/download_manager.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_client.h"
#include "content/public/common/url_constants.h"
#include "storage/browser/file_system/file_system_url.h"
#include "storage/browser/file_system/isolated_context.h"
#include "storage/common/file_system/file_system_util.h"
#include "third_party/blink/public/common/storage_key/storage_key.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/shell_dialogs/select_file_dialog.h"
#include "ui/shell_dialogs/selected_file_info.h"
#include "url/gurl.h"
#include "url/origin.h"
BrowserContext;
BrowserThread;
DownloadManager;
RenderViewHost;
WebContents;
set;
namespace {
static const char kRootName[] = …;
static const char kPermissionDenied[] = …;
static const char kSelectionCancelled[] = …;
base::LazyInstance<base::FilePath>::Leaky
g_last_save_path = …;
SelectedCallback;
CanceledCallback;
class SelectFileDialog : public ui::SelectFileDialog::Listener { … };
void WriteToFile(const base::FilePath& path,
const std::string& content,
bool is_base64) { … }
void AppendToFile(const base::FilePath& path, const std::string& content) { … }
storage::IsolatedContext* isolated_context() { … }
std::string RegisterFileSystem(WebContents* web_contents,
const base::FilePath& path) { … }
DevToolsFileHelper::FileSystem CreateFileSystemStruct(
WebContents* web_contents,
const std::string& type,
const std::string& file_system_id,
const std::string& file_system_path) { … }
PathToType;
PathToType GetAddedFileSystemPaths(Profile* profile) { … }
}
DevToolsFileHelper::FileSystem::FileSystem() = default;
DevToolsFileHelper::FileSystem::~FileSystem() = default;
DevToolsFileHelper::FileSystem::FileSystem(const FileSystem& other) = default;
DevToolsFileHelper::FileSystem::FileSystem(const std::string& type,
const std::string& file_system_name,
const std::string& root_url,
const std::string& file_system_path)
: … { … }
DevToolsFileHelper::DevToolsFileHelper(WebContents* web_contents,
Profile* profile,
Delegate* delegate)
: … { … }
DevToolsFileHelper::~DevToolsFileHelper() = default;
void DevToolsFileHelper::Save(const std::string& url,
const std::string& content,
bool save_as,
bool is_base64,
SaveCallback saveCallback,
base::OnceClosure cancelCallback) { … }
void DevToolsFileHelper::Append(const std::string& url,
const std::string& content,
base::OnceClosure callback) { … }
void DevToolsFileHelper::SaveAsFileSelected(const std::string& url,
const std::string& content,
bool is_base64,
SaveCallback callback,
const base::FilePath& path) { … }
void DevToolsFileHelper::AddFileSystem(
const std::string& type,
const ShowInfoBarCallback& show_info_bar_callback) { … }
void DevToolsFileHelper::UpgradeDraggedFileSystemPermissions(
const std::string& file_system_url,
const ShowInfoBarCallback& show_info_bar_callback) { … }
void DevToolsFileHelper::InnerAddFileSystem(
const ShowInfoBarCallback& show_info_bar_callback,
const std::string& type,
const base::FilePath& path) { … }
void DevToolsFileHelper::AddUserConfirmedFileSystem(const std::string& type,
const base::FilePath& path,
bool allowed) { … }
void DevToolsFileHelper::FailedToAddFileSystem(const std::string& error) { … }
namespace {
void RunOnUIThread(base::OnceClosure callback) { … }
}
std::vector<DevToolsFileHelper::FileSystem>
DevToolsFileHelper::GetFileSystems() { … }
void DevToolsFileHelper::RemoveFileSystem(const std::string& file_system_path) { … }
bool DevToolsFileHelper::IsFileSystemAdded(
const std::string& file_system_path) { … }
void DevToolsFileHelper::OnOpenItemComplete(
const base::FilePath& path,
platform_util::OpenOperationResult result) { … }
void DevToolsFileHelper::ShowItemInFolder(const std::string& file_system_path) { … }
void DevToolsFileHelper::FileSystemPathsSettingChangedOnUI() { … }
void DevToolsFileHelper::FilePathsChanged(
const std::vector<std::string>& changed_paths,
const std::vector<std::string>& added_paths,
const std::vector<std::string>& removed_paths) { … }