diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index a08dcb52d7..42e65947b4 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -2065,7 +2065,7 @@ void WebContents::AddWorkSpace(mate::Arguments* args, args->ThrowError("path cannot be empty"); return; } - DevToolsAddFileSystem(path); + DevToolsAddFileSystem(path, std::string()); } void WebContents::RemoveWorkSpace(mate::Arguments* args, diff --git a/atom/browser/common_web_contents_delegate.cc b/atom/browser/common_web_contents_delegate.cc index 4563df8b90..dbace4819f 100644 --- a/atom/browser/common_web_contents_delegate.cc +++ b/atom/browser/common_web_contents_delegate.cc @@ -67,14 +67,17 @@ const char kRootName[] = ""; struct FileSystem { FileSystem() { } - FileSystem(const std::string& file_system_name, + FileSystem(const std::string& type, + const std::string& file_system_name, const std::string& root_url, const std::string& file_system_path) - : file_system_name(file_system_name), + : type(type), + file_system_name(file_system_name), root_url(root_url), file_system_path(file_system_path) { } + std::string type; std::string file_system_name; std::string root_url; std::string file_system_path; @@ -107,6 +110,7 @@ std::string RegisterFileSystem(content::WebContents* web_contents, FileSystem CreateFileSystemStruct( content::WebContents* web_contents, + const std::string& type, const std::string& file_system_id, const std::string& file_system_path) { const GURL origin = web_contents->GetURL().GetOrigin(); @@ -114,11 +118,12 @@ FileSystem CreateFileSystemStruct( storage::GetIsolatedFileSystemName(origin, file_system_id); std::string root_url = storage::GetIsolatedFileSystemRootURIString( origin, file_system_id, kRootName); - return FileSystem(file_system_name, root_url, file_system_path); + return FileSystem(type, file_system_name, root_url, file_system_path); } base::DictionaryValue* CreateFileSystemValue(const FileSystem& file_system) { auto* file_system_value = new base::DictionaryValue(); + file_system_value->SetString("type", file_system.type); file_system_value->SetString("fileSystemName", file_system.file_system_name); file_system_value->SetString("rootURL", file_system.root_url); file_system_value->SetString("fileSystemPath", file_system.file_system_path); @@ -146,16 +151,18 @@ PrefService* GetPrefService(content::WebContents* web_contents) { return static_cast(context)->prefs(); } -std::set GetAddedFileSystemPaths( +std::map GetAddedFileSystemPaths( content::WebContents* web_contents) { auto pref_service = GetPrefService(web_contents); const base::DictionaryValue* file_system_paths_value = pref_service->GetDictionary(prefs::kDevToolsFileSystemPaths); - std::set result; + std::map result; if (file_system_paths_value) { base::DictionaryValue::Iterator it(*file_system_paths_value); for (; !it.IsAtEnd(); it.Advance()) { - result.insert(it.key()); + std::string type = + it.value().is_string() ? it.value().GetString() : std::string(); + result[it.key()] = type; } } return result; @@ -164,8 +171,10 @@ std::set GetAddedFileSystemPaths( bool IsDevToolsFileSystemAdded( content::WebContents* web_contents, const std::string& file_system_path) { - auto file_system_paths = GetAddedFileSystemPaths(web_contents); - return file_system_paths.find(file_system_path) != file_system_paths.end(); + auto pref_service = GetPrefService(web_contents); + const base::DictionaryValue* file_systems_paths_value = + pref_service->GetDictionary(prefs::kDevToolsFileSystemPaths); + return file_systems_paths_value->HasKey(file_system_path); } } // namespace @@ -378,12 +387,14 @@ void CommonWebContentsDelegate::DevToolsRequestFileSystems() { std::vector file_systems; for (auto file_system_path : file_system_paths) { - base::FilePath path = base::FilePath::FromUTF8Unsafe(file_system_path); + base::FilePath path = + base::FilePath::FromUTF8Unsafe(file_system_path.first); std::string file_system_id = RegisterFileSystem(GetDevToolsWebContents(), path); FileSystem file_system = CreateFileSystemStruct(GetDevToolsWebContents(), + file_system_path.second, file_system_id, - file_system_path); + file_system_path.first); file_systems.push_back(file_system); } @@ -396,18 +407,18 @@ void CommonWebContentsDelegate::DevToolsRequestFileSystems() { } void CommonWebContentsDelegate::DevToolsAddFileSystem( - const base::FilePath& file_system_path) { + const base::FilePath& file_system_path, const std::string& type) { if (file_system_path.empty()) { new extensions::FileEntryPicker( GetWebContents(), file_system_path, ui::SelectFileDialog::FileTypeInfo(), - ui::SelectFileDialog::SELECT_UPLOAD_FOLDER, + ui::SelectFileDialog::SELECT_FOLDER, base::Bind(&CommonWebContentsDelegate::OnAddFileSelected, - weak_ptr_factory_.GetWeakPtr()), + weak_ptr_factory_.GetWeakPtr(), type), base::Bind(&CommonWebContentsDelegate::OnAddFileSelectionCancelled, weak_ptr_factory_.GetWeakPtr())); } else { - DevToolsAddFileSystemInteral(file_system_path); + DevToolsAddFileSystemInteral(file_system_path, type); } } @@ -505,34 +516,35 @@ void CommonWebContentsDelegate::OnSaveFileSelectionCancelled( } void CommonWebContentsDelegate::OnAddFileSelected( - const std::vector& paths) { + const std::string& type, const std::vector& paths) { DCHECK(!paths.empty()); - DevToolsAddFileSystemInteral(paths[0]); + DevToolsAddFileSystemInteral(paths[0], type); } void CommonWebContentsDelegate::OnAddFileSelectionCancelled() {} void CommonWebContentsDelegate::DevToolsAddFileSystemInteral( - const base::FilePath& path) { + const base::FilePath& path, const std::string& type) { std::string file_system_id = RegisterFileSystem(GetDevToolsWebContents(), path); if (IsDevToolsFileSystemAdded(GetDevToolsWebContents(), path.AsUTF8Unsafe())) return; FileSystem file_system = CreateFileSystemStruct(GetDevToolsWebContents(), - file_system_id, - path.AsUTF8Unsafe()); + type, + file_system_id, + path.AsUTF8Unsafe()); std::unique_ptr file_system_value( CreateFileSystemValue(file_system)); auto pref_service = GetPrefService(GetDevToolsWebContents()); DictionaryPrefUpdate update(pref_service, prefs::kDevToolsFileSystemPaths); update.Get()->SetWithoutPathExpansion( - path.AsUTF8Unsafe(), base::MakeUnique()); + path.AsUTF8Unsafe(), base::MakeUnique(type)); web_contents_->CallClientFunction("DevToolsAPI.fileSystemAdded", file_system_value.get(), - nullptr, nullptr); + nullptr); } void CommonWebContentsDelegate::OnDevToolsSaveToFile( diff --git a/atom/browser/common_web_contents_delegate.h b/atom/browser/common_web_contents_delegate.h index ce50c505b4..8f2c6b0e4d 100644 --- a/atom/browser/common_web_contents_delegate.h +++ b/atom/browser/common_web_contents_delegate.h @@ -93,7 +93,8 @@ class CommonWebContentsDelegate void DevToolsAppendToFile(const std::string& url, const std::string& content) override; void DevToolsRequestFileSystems() override; - void DevToolsAddFileSystem(const base::FilePath& path) override; + void DevToolsAddFileSystem(const base::FilePath& path, + const std::string& type) override; void DevToolsRemoveFileSystem( const base::FilePath& file_system_path) override; void DevToolsIndexPath(int request_id, @@ -118,10 +119,12 @@ class CommonWebContentsDelegate const std::vector& paths); void OnSaveFileSelectionCancelled(const std::string url); - void OnAddFileSelected(const std::vector& paths); + void OnAddFileSelected(const std::string& path, + const std::vector& paths); void OnAddFileSelectionCancelled(); - void DevToolsAddFileSystemInteral(const base::FilePath& path); + void DevToolsAddFileSystemInteral(const base::FilePath& path, + const std::string& type); // Callback for when DevToolsSaveToFile has completed. void OnDevToolsSaveToFile(const std::string& url); diff --git a/vendor/brightray/browser/inspectable_web_contents_delegate.h b/vendor/brightray/browser/inspectable_web_contents_delegate.h index 32bf5e0acb..f4ce36b422 100644 --- a/vendor/brightray/browser/inspectable_web_contents_delegate.h +++ b/vendor/brightray/browser/inspectable_web_contents_delegate.h @@ -18,7 +18,7 @@ class InspectableWebContentsDelegate { const std::string& url, const std::string& content) {} virtual void DevToolsRequestFileSystems() {} virtual void DevToolsAddFileSystem( - const base::FilePath& file_system_path) {} + const base::FilePath& file_system_path, const std::string& type) {} virtual void DevToolsRemoveFileSystem( const base::FilePath& file_system_path) {} virtual void DevToolsIndexPath( diff --git a/vendor/brightray/browser/inspectable_web_contents_impl.cc b/vendor/brightray/browser/inspectable_web_contents_impl.cc index 3c3bc5ef2c..cef05360d4 100644 --- a/vendor/brightray/browser/inspectable_web_contents_impl.cc +++ b/vendor/brightray/browser/inspectable_web_contents_impl.cc @@ -695,7 +695,7 @@ void InspectableWebContentsImpl::RequestFileSystems() { void InspectableWebContentsImpl::AddFileSystem( const std::string& type) { if (delegate_) - delegate_->DevToolsAddFileSystem(base::FilePath()); + delegate_->DevToolsAddFileSystem(base::FilePath(), type); } void InspectableWebContentsImpl::RemoveFileSystem( diff --git a/vendor/brightray/browser/inspectable_web_contents_impl.h b/vendor/brightray/browser/inspectable_web_contents_impl.h index 9fb79af35a..f2edb91e19 100644 --- a/vendor/brightray/browser/inspectable_web_contents_impl.h +++ b/vendor/brightray/browser/inspectable_web_contents_impl.h @@ -115,7 +115,7 @@ class InspectableWebContentsImpl : void AppendToFile(const std::string& url, const std::string& content) override; void RequestFileSystems() override; - void AddFileSystem(const std::string& file_system_path) override; + void AddFileSystem(const std::string& type) override; void RemoveFileSystem(const std::string& file_system_path) override; void UpgradeDraggedFileSystemPermissions( const std::string& file_system_url) override;