#include "content/browser/file_system_access/file_system_access_directory_handle_impl.h"
#include <optional>
#include "base/barrier_callback.h"
#include "base/containers/contains.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/i18n/file_util_icu.h"
#include "base/memory/ref_counted_delete_on_sequence.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/thread_pool.h"
#include "base/uuid.h"
#include "build/build_config.h"
#include "content/browser/file_system_access/features.h"
#include "content/browser/file_system_access/file_system_access_error.h"
#include "content/browser/file_system_access/file_system_access_manager_impl.h"
#include "content/browser/file_system_access/file_system_access_transfer_token_impl.h"
#include "content/public/browser/file_system_access_permission_context.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "net/base/filename_util.h"
#include "storage/browser/file_system/file_system_context.h"
#include "storage/browser/file_system/file_system_operation_runner.h"
#include "storage/browser/file_system/file_system_url.h"
#include "storage/common/file_system/file_system_types.h"
#include "storage/common/file_system/file_system_util.h"
#include "third_party/blink/public/mojom/file_system_access/file_system_access_cloud_identifier.mojom.h"
#include "third_party/blink/public/mojom/file_system_access/file_system_access_error.mojom.h"
#include "third_party/blink/public/mojom/file_system_access/file_system_access_file_handle.mojom.h"
#include "third_party/blink/public/mojom/file_system_access/file_system_access_transfer_token.mojom.h"
FileSystemAccessEntry;
FileSystemAccessEntryPtr;
FileSystemAccessHandle;
FileSystemAccessStatus;
FileSystemAccessTransferToken;
FileSystemOperationRunner;
namespace content {
HandleType;
PathType;
SensitiveEntryResult;
UserAction;
namespace {
bool IsShellIntegratedExtension(const base::FilePath::StringType& extension) { … }
}
struct FileSystemAccessDirectoryHandleImpl::
FileSystemAccessDirectoryEntriesListenerHolder
: base::RefCountedDeleteOnSequence<
FileSystemAccessDirectoryEntriesListenerHolder> { … };
FileSystemAccessDirectoryHandleImpl::FileSystemAccessDirectoryHandleImpl(
FileSystemAccessManagerImpl* manager,
const BindingContext& context,
const storage::FileSystemURL& url,
const SharedHandleState& handle_state)
: … { … }
FileSystemAccessDirectoryHandleImpl::~FileSystemAccessDirectoryHandleImpl() =
default;
void FileSystemAccessDirectoryHandleImpl::GetPermissionStatus(
bool writable,
GetPermissionStatusCallback callback) { … }
void FileSystemAccessDirectoryHandleImpl::RequestPermission(
bool writable,
RequestPermissionCallback callback) { … }
void FileSystemAccessDirectoryHandleImpl::GetFile(const std::string& basename,
bool create,
GetFileCallback callback) { … }
void FileSystemAccessDirectoryHandleImpl::DoGetFile(
bool create,
storage::FileSystemURL url,
GetFileCallback callback,
SensitiveEntryResult sensitive_entry_result) { … }
void FileSystemAccessDirectoryHandleImpl::GetDirectory(
const std::string& basename,
bool create,
GetDirectoryCallback callback) { … }
void FileSystemAccessDirectoryHandleImpl::GetEntries(
mojo::PendingRemote<blink::mojom::FileSystemAccessDirectoryEntriesListener>
pending_listener) { … }
void FileSystemAccessDirectoryHandleImpl::Move(
mojo::PendingRemote<blink::mojom::FileSystemAccessTransferToken>
destination_directory,
const std::string& new_entry_name,
MoveCallback callback) { … }
void FileSystemAccessDirectoryHandleImpl::Rename(
const std::string& new_entry_name,
RenameCallback callback) { … }
void FileSystemAccessDirectoryHandleImpl::Remove(bool recurse,
RemoveCallback callback) { … }
void FileSystemAccessDirectoryHandleImpl::RemoveEntry(
const std::string& basename,
bool recurse,
RemoveEntryCallback callback) { … }
void FileSystemAccessDirectoryHandleImpl::Resolve(
mojo::PendingRemote<blink::mojom::FileSystemAccessTransferToken>
possible_child,
ResolveCallback callback) { … }
void FileSystemAccessDirectoryHandleImpl::ResolveImpl(
ResolveCallback callback,
FileSystemAccessTransferTokenImpl* possible_child) { … }
void FileSystemAccessDirectoryHandleImpl::Transfer(
mojo::PendingReceiver<FileSystemAccessTransferToken> token) { … }
void FileSystemAccessDirectoryHandleImpl::GetFileWithWritePermission(
const storage::FileSystemURL& child_url,
GetFileCallback callback) { … }
void FileSystemAccessDirectoryHandleImpl::DidGetFile(
const storage::FileSystemURL& url,
GetFileCallback callback,
base::File::Error result) { … }
void FileSystemAccessDirectoryHandleImpl::GetDirectoryWithWritePermission(
const storage::FileSystemURL& child_url,
GetDirectoryCallback callback) { … }
void FileSystemAccessDirectoryHandleImpl::DidGetDirectory(
const storage::FileSystemURL& url,
GetDirectoryCallback callback,
base::File::Error result) { … }
void FileSystemAccessDirectoryHandleImpl::DidReadDirectory(
scoped_refptr<FileSystemAccessDirectoryEntriesListenerHolder>
listener_holder,
base::File::Error result,
std::vector<filesystem::mojom::DirectoryEntry> file_list,
bool has_more_entries) { … }
void FileSystemAccessDirectoryHandleImpl::DidVerifySensitiveAccessForFileEntry(
std::string basename,
storage::FileSystemURL child_url,
base::OnceCallback<void(FileSystemAccessEntryPtr)> barrier_callback,
FileSystemAccessPermissionContext::SensitiveEntryResult
sensitive_entry_result) { … }
void FileSystemAccessDirectoryHandleImpl::MergeCurrentBatchEntries(
base::OnceCallback<void(std::vector<FileSystemAccessEntryPtr>)>
final_callback,
std::vector<FileSystemAccessEntryPtr> entries) { … }
void FileSystemAccessDirectoryHandleImpl::CurrentBatchEntriesReady(
scoped_refptr<FileSystemAccessDirectoryEntriesListenerHolder>
listener_holder,
std::vector<FileSystemAccessEntryPtr> entries) { … }
bool FileSystemAccessDirectoryHandleImpl::IsSafePathComponent(
storage::FileSystemType type,
const std::string& name) { … }
blink::mojom::FileSystemAccessErrorPtr
FileSystemAccessDirectoryHandleImpl::GetChildURL(
const std::string& basename,
storage::FileSystemURL* result) { … }
FileSystemAccessEntryPtr FileSystemAccessDirectoryHandleImpl::CreateEntry(
const std::string& basename,
const storage::FileSystemURL& url,
HandleType handle_type) { … }
void FileSystemAccessDirectoryHandleImpl::GetUniqueId(
GetUniqueIdCallback callback) { … }
void FileSystemAccessDirectoryHandleImpl::GetCloudIdentifiers(
GetCloudIdentifiersCallback callback) { … }
base::WeakPtr<FileSystemAccessHandleBase>
FileSystemAccessDirectoryHandleImpl::AsWeakPtr() { … }
}