Commit 7b5b6d55 authored by Hiroki Nakagawa's avatar Hiroki Nakagawa Committed by Commit Bot

Filesystem: Inline FileSystemClient in LocalFileSystem for cleanup

FileSystemClient is used for checking permissions to access Filesystem APIs.
The client is now used only from LocalFileSystem, and no longer has to be a
separate class.

Bug: 1009854
Change-Id: I8aa25d1e6c41d1114f7bd9904d53ae20dc089e4f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1833002
Commit-Queue: Victor Costan <pwnall@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarVictor Costan <pwnall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#701431}
parent 37e2d2f6
......@@ -45,7 +45,6 @@ blink_modules_sources("filesystem") {
"file_entry_sync.h",
"file_system_callbacks.cc",
"file_system_callbacks.h",
"file_system_client.h",
"file_system_dispatcher.cc",
"file_system_dispatcher.h",
"file_writer.cc",
......@@ -58,8 +57,6 @@ blink_modules_sources("filesystem") {
"html_input_element_file_system.h",
"local_file_system.cc",
"local_file_system.h",
"local_file_system_client.cc",
"local_file_system_client.h",
"metadata.h",
"sync_callback_helper.h",
"worker_global_scope_file_system.cc",
......
/*
* Copyright (C) 2013 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_FILESYSTEM_FILE_SYSTEM_CLIENT_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_FILESYSTEM_FILE_SYSTEM_CLIENT_H_
#include <memory>
#include "base/callback.h"
#include "base/macros.h"
#include "third_party/blink/public/mojom/filesystem/file_system.mojom-blink.h"
#include "third_party/blink/renderer/modules/modules_export.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
#include "third_party/blink/renderer/platform/wtf/forward.h"
namespace blink {
class ExecutionContext;
class LocalFrame;
class WorkerClients;
class FileSystemClient {
USING_FAST_MALLOC(FileSystemClient);
public:
FileSystemClient() = default;
virtual ~FileSystemClient() = default;
virtual bool RequestFileSystemAccessSync(ExecutionContext*) = 0;
virtual void RequestFileSystemAccessAsync(ExecutionContext*,
base::OnceCallback<void(bool)>) = 0;
private:
DISALLOW_COPY_AND_ASSIGN(FileSystemClient);
};
MODULES_EXPORT void ProvideLocalFileSystemTo(LocalFrame&,
std::unique_ptr<FileSystemClient>);
MODULES_EXPORT void ProvideLocalFileSystemToWorker(
WorkerClients*,
std::unique_ptr<FileSystemClient>);
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_FILESYSTEM_FILE_SYSTEM_CLIENT_H_
......@@ -47,7 +47,6 @@
#include "third_party/blink/renderer/core/workers/worker_global_scope.h"
#include "third_party/blink/renderer/modules/filesystem/dom_file_system.h"
#include "third_party/blink/renderer/modules/filesystem/file_system_callbacks.h"
#include "third_party/blink/renderer/modules/filesystem/file_system_client.h"
#include "third_party/blink/renderer/modules/filesystem/file_system_dispatcher.h"
#include "third_party/blink/renderer/platform/wtf/functional.h"
#include "third_party/blink/renderer/platform/wtf/std_lib_extras.h"
......@@ -110,15 +109,26 @@ void LocalFileSystem::RequestFileSystemCallback(
void LocalFileSystem::RequestFileSystemAccessInternal(
ExecutionContext* context,
base::OnceCallback<void(bool)> callback) {
if (!context->IsDocument()) {
if (!Client().RequestFileSystemAccessSync(context)) {
std::move(callback).Run(false);
return;
if (context->IsDocument()) {
auto* client =
To<Document>(context)->GetFrame()->GetContentSettingsClient();
if (!client) {
std::move(callback).Run(true);
} else {
client->RequestFileSystemAccessAsync(std::move(callback));
}
std::move(callback).Run(true);
return;
}
Client().RequestFileSystemAccessAsync(context, std::move(callback));
if (context->IsWorkerGlobalScope()) {
auto* client = To<WorkerGlobalScope>(context)->ContentSettingsClient();
if (!client) {
std::move(callback).Run(true);
} else {
std::move(callback).Run(client->RequestFileSystemAccessSync());
}
return;
}
NOTREACHED();
}
void LocalFileSystem::FileSystemNotAllowedInternal(
......@@ -167,17 +177,11 @@ void LocalFileSystem::ResolveURLInternal(
}
}
LocalFileSystem::LocalFileSystem(LocalFrame& frame,
std::unique_ptr<FileSystemClient> client)
: Supplement<LocalFrame>(frame), client_(std::move(client)) {
DCHECK(client_);
}
LocalFileSystem::LocalFileSystem(LocalFrame& frame)
: Supplement<LocalFrame>(frame) {}
LocalFileSystem::LocalFileSystem(WorkerClients& worker_clients,
std::unique_ptr<FileSystemClient> client)
: Supplement<WorkerClients>(worker_clients), client_(std::move(client)) {
DCHECK(client_);
}
LocalFileSystem::LocalFileSystem(WorkerClients& worker_clients)
: Supplement<WorkerClients>(worker_clients) {}
void LocalFileSystem::Trace(blink::Visitor* visitor) {
Supplement<LocalFrame>::Trace(visitor);
......@@ -202,17 +206,13 @@ LocalFileSystem* LocalFileSystem::From(ExecutionContext& context) {
return file_system;
}
void ProvideLocalFileSystemTo(LocalFrame& frame,
std::unique_ptr<FileSystemClient> client) {
frame.ProvideSupplement(
MakeGarbageCollected<LocalFileSystem>(frame, std::move(client)));
void ProvideLocalFileSystemTo(LocalFrame& frame) {
frame.ProvideSupplement(MakeGarbageCollected<LocalFileSystem>(frame));
}
void ProvideLocalFileSystemToWorker(WorkerClients* worker_clients,
std::unique_ptr<FileSystemClient> client) {
Supplement<WorkerClients>::ProvideTo(*worker_clients,
MakeGarbageCollected<LocalFileSystem>(
*worker_clients, std::move(client)));
void ProvideLocalFileSystemToWorker(WorkerClients& worker_clients) {
worker_clients.ProvideSupplement(
MakeGarbageCollected<LocalFileSystem>(worker_clients));
}
} // namespace blink
......@@ -46,7 +46,6 @@
namespace blink {
class FileSystemClient;
class ExecutionContext;
class FileSystemCallbacks;
class KURL;
......@@ -63,8 +62,8 @@ class LocalFileSystem final : public GarbageCollected<LocalFileSystem>,
static const char kSupplementName[];
LocalFileSystem(LocalFrame&, std::unique_ptr<FileSystemClient>);
LocalFileSystem(WorkerClients&, std::unique_ptr<FileSystemClient>);
explicit LocalFileSystem(LocalFrame&);
explicit LocalFileSystem(WorkerClients&);
~LocalFileSystem();
void ResolveURL(ExecutionContext*,
......@@ -77,8 +76,6 @@ class LocalFileSystem final : public GarbageCollected<LocalFileSystem>,
std::unique_ptr<FileSystemCallbacks>,
SynchronousType sync_type);
FileSystemClient& Client() const { return *client_; }
static LocalFileSystem* From(ExecutionContext&);
void Trace(blink::Visitor*) override;
......@@ -110,11 +107,12 @@ class LocalFileSystem final : public GarbageCollected<LocalFileSystem>,
std::unique_ptr<ResolveURICallbacks>,
SynchronousType sync_type);
const std::unique_ptr<FileSystemClient> client_;
DISALLOW_COPY_AND_ASSIGN(LocalFileSystem);
};
void ProvideLocalFileSystemTo(LocalFrame&);
void ProvideLocalFileSystemToWorker(WorkerClients&);
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_FILESYSTEM_LOCAL_FILE_SYSTEM_H_
/*
* Copyright (C) 2013 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "third_party/blink/renderer/modules/filesystem/local_file_system_client.h"
#include <memory>
#include <utility>
#include "base/memory/ptr_util.h"
#include "third_party/blink/public/platform/web_content_settings_client.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/workers/worker_global_scope.h"
#include "third_party/blink/renderer/platform/weborigin/security_origin.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
namespace blink {
LocalFileSystemClient::~LocalFileSystemClient() = default;
bool LocalFileSystemClient::RequestFileSystemAccessSync(
ExecutionContext* context) {
DCHECK(context);
if (IsA<Document>(context)) {
// TODO(dcheng): Why is this NOTREACHED and handled?
NOTREACHED();
return false;
}
WebContentSettingsClient* content_settings_client =
To<WorkerGlobalScope>(context)->ContentSettingsClient();
if (!content_settings_client)
return true;
return content_settings_client->RequestFileSystemAccessSync();
}
void LocalFileSystemClient::RequestFileSystemAccessAsync(
ExecutionContext* context,
base::OnceCallback<void(bool)> callback) {
DCHECK(context);
auto* document = DynamicTo<Document>(context);
if (!document) {
// TODO(dcheng): Why is this NOTREACHED and handled?
NOTREACHED();
return;
}
if (auto* client = document->GetFrame()->GetContentSettingsClient()) {
client->RequestFileSystemAccessAsync(std::move(callback));
} else {
std::move(callback).Run(true);
}
}
LocalFileSystemClient::LocalFileSystemClient() = default;
} // namespace blink
/*
* Copyright (C) 2013 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_FILESYSTEM_LOCAL_FILE_SYSTEM_CLIENT_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_FILESYSTEM_LOCAL_FILE_SYSTEM_CLIENT_H_
#include <memory>
#include "base/callback.h"
#include "third_party/blink/renderer/modules/filesystem/file_system_client.h"
#include "third_party/blink/renderer/modules/modules_export.h"
#include "third_party/blink/renderer/platform/wtf/forward.h"
namespace blink {
class LocalFileSystemClient final : public FileSystemClient {
public:
LocalFileSystemClient();
~LocalFileSystemClient() override;
bool RequestFileSystemAccessSync(ExecutionContext*) override;
void RequestFileSystemAccessAsync(ExecutionContext*,
base::OnceCallback<void(bool)>) override;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_FILESYSTEM_LOCAL_FILE_SYSTEM_CLIENT_H_
......@@ -50,7 +50,7 @@
#include "third_party/blink/renderer/modules/event_target_modules_names.h"
#include "third_party/blink/renderer/modules/exported/web_embedded_worker_impl.h"
#include "third_party/blink/renderer/modules/filesystem/dragged_isolated_file_system_impl.h"
#include "third_party/blink/renderer/modules/filesystem/local_file_system_client.h"
#include "third_party/blink/renderer/modules/filesystem/local_file_system.h"
#include "third_party/blink/renderer/modules/gamepad/navigator_gamepad.h"
#include "third_party/blink/renderer/modules/image_downloader/image_downloader_impl.h"
#include "third_party/blink/renderer/modules/indexed_db_names.h"
......@@ -182,7 +182,7 @@ void ModulesInitializer::InstallSupplements(LocalFrame& frame) const {
ProvidePushMessagingClientTo(
frame, MakeGarbageCollected<PushMessagingClient>(frame));
ProvideUserMediaTo(frame);
ProvideLocalFileSystemTo(frame, std::make_unique<LocalFileSystemClient>());
ProvideLocalFileSystemTo(frame);
ScreenOrientationControllerImpl::ProvideTo(frame);
if (RuntimeEnabledFeatures::PresentationEnabled())
......@@ -200,8 +200,7 @@ void ModulesInitializer::InstallSupplements(LocalFrame& frame) const {
void ModulesInitializer::ProvideLocalFileSystemToWorker(
WorkerClients& worker_clients) const {
::blink::ProvideLocalFileSystemToWorker(
&worker_clients, std::make_unique<LocalFileSystemClient>());
::blink::ProvideLocalFileSystemToWorker(worker_clients);
}
MediaControls* ModulesInitializer::CreateMediaControls(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment