Commit 4ba900a2 authored by Minoru Chikamune's avatar Minoru Chikamune Committed by Commit Bot

Migrate NativeFileSystemFileHandle and NativeFileSystemDirectoryHandle to use GC mojo wrappers.

No behavior change. This CL reduces potential risks of use-after-free bugs.

Bug: 1049056
Change-Id: I5264649499cc8e9507ca18aa2bf62ccfe0506b5e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2145527Reviewed-by: default avatarKouhei Ueno <kouhei@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Minoru Chikamune <chikamune@chromium.org>
Cr-Commit-Position: refs/heads/master@{#758503}
parent a50d0e4f
...@@ -37,10 +37,10 @@ NativeFileSystemDirectoryHandle::NativeFileSystemDirectoryHandle( ...@@ -37,10 +37,10 @@ NativeFileSystemDirectoryHandle::NativeFileSystemDirectoryHandle(
ExecutionContext* context, ExecutionContext* context,
const String& name, const String& name,
mojo::PendingRemote<mojom::blink::NativeFileSystemDirectoryHandle> mojo_ptr) mojo::PendingRemote<mojom::blink::NativeFileSystemDirectoryHandle> mojo_ptr)
: NativeFileSystemHandle(context, name), : NativeFileSystemHandle(context, name), mojo_ptr_(context) {
mojo_ptr_(std::move(mojo_ptr), mojo_ptr_.Bind(std::move(mojo_ptr),
context->GetTaskRunner(TaskType::kMiscPlatformAPI)) { context->GetTaskRunner(TaskType::kMiscPlatformAPI));
DCHECK(mojo_ptr_); DCHECK(mojo_ptr_.is_bound());
} }
ScriptPromise NativeFileSystemDirectoryHandle::getFile( ScriptPromise NativeFileSystemDirectoryHandle::getFile(
...@@ -79,7 +79,7 @@ ScriptPromise NativeFileSystemDirectoryHandle::getDirectory( ...@@ -79,7 +79,7 @@ ScriptPromise NativeFileSystemDirectoryHandle::getDirectory(
auto* resolver = MakeGarbageCollected<ScriptPromiseResolver>(script_state); auto* resolver = MakeGarbageCollected<ScriptPromiseResolver>(script_state);
ScriptPromise result = resolver->Promise(); ScriptPromise result = resolver->Promise();
if (!mojo_ptr_) { if (!mojo_ptr_.is_bound()) {
resolver->Reject(MakeGarbageCollected<DOMException>( resolver->Reject(MakeGarbageCollected<DOMException>(
DOMExceptionCode::kInvalidStateError)); DOMExceptionCode::kInvalidStateError));
return result; return result;
...@@ -141,7 +141,7 @@ ScriptPromise NativeFileSystemDirectoryHandle::removeEntry( ...@@ -141,7 +141,7 @@ ScriptPromise NativeFileSystemDirectoryHandle::removeEntry(
auto* resolver = MakeGarbageCollected<ScriptPromiseResolver>(script_state); auto* resolver = MakeGarbageCollected<ScriptPromiseResolver>(script_state);
ScriptPromise result = resolver->Promise(); ScriptPromise result = resolver->Promise();
if (!mojo_ptr_) { if (!mojo_ptr_.is_bound()) {
resolver->Reject(MakeGarbageCollected<DOMException>( resolver->Reject(MakeGarbageCollected<DOMException>(
DOMExceptionCode::kInvalidStateError)); DOMExceptionCode::kInvalidStateError));
return result; return result;
...@@ -164,7 +164,7 @@ ScriptPromise NativeFileSystemDirectoryHandle::resolve( ...@@ -164,7 +164,7 @@ ScriptPromise NativeFileSystemDirectoryHandle::resolve(
auto* resolver = MakeGarbageCollected<ScriptPromiseResolver>(script_state); auto* resolver = MakeGarbageCollected<ScriptPromiseResolver>(script_state);
ScriptPromise result = resolver->Promise(); ScriptPromise result = resolver->Promise();
if (!mojo_ptr_) { if (!mojo_ptr_.is_bound()) {
resolver->Reject(MakeGarbageCollected<DOMException>( resolver->Reject(MakeGarbageCollected<DOMException>(
DOMExceptionCode::kInvalidStateError)); DOMExceptionCode::kInvalidStateError));
return result; return result;
...@@ -245,15 +245,20 @@ ScriptPromise NativeFileSystemDirectoryHandle::getSystemDirectory( ...@@ -245,15 +245,20 @@ ScriptPromise NativeFileSystemDirectoryHandle::getSystemDirectory(
mojo::PendingRemote<mojom::blink::NativeFileSystemTransferToken> mojo::PendingRemote<mojom::blink::NativeFileSystemTransferToken>
NativeFileSystemDirectoryHandle::Transfer() { NativeFileSystemDirectoryHandle::Transfer() {
mojo::PendingRemote<mojom::blink::NativeFileSystemTransferToken> result; mojo::PendingRemote<mojom::blink::NativeFileSystemTransferToken> result;
if (mojo_ptr_) if (mojo_ptr_.is_bound())
mojo_ptr_->Transfer(result.InitWithNewPipeAndPassReceiver()); mojo_ptr_->Transfer(result.InitWithNewPipeAndPassReceiver());
return result; return result;
} }
void NativeFileSystemDirectoryHandle::Trace(Visitor* visitor) {
visitor->Trace(mojo_ptr_);
NativeFileSystemHandle::Trace(visitor);
}
void NativeFileSystemDirectoryHandle::QueryPermissionImpl( void NativeFileSystemDirectoryHandle::QueryPermissionImpl(
bool writable, bool writable,
base::OnceCallback<void(mojom::blink::PermissionStatus)> callback) { base::OnceCallback<void(mojom::blink::PermissionStatus)> callback) {
if (!mojo_ptr_) { if (!mojo_ptr_.is_bound()) {
std::move(callback).Run(mojom::blink::PermissionStatus::DENIED); std::move(callback).Run(mojom::blink::PermissionStatus::DENIED);
return; return;
} }
...@@ -264,7 +269,7 @@ void NativeFileSystemDirectoryHandle::RequestPermissionImpl( ...@@ -264,7 +269,7 @@ void NativeFileSystemDirectoryHandle::RequestPermissionImpl(
bool writable, bool writable,
base::OnceCallback<void(mojom::blink::NativeFileSystemErrorPtr, base::OnceCallback<void(mojom::blink::NativeFileSystemErrorPtr,
mojom::blink::PermissionStatus)> callback) { mojom::blink::PermissionStatus)> callback) {
if (!mojo_ptr_) { if (!mojo_ptr_.is_bound()) {
std::move(callback).Run( std::move(callback).Run(
mojom::blink::NativeFileSystemError::New( mojom::blink::NativeFileSystemError::New(
mojom::blink::NativeFileSystemStatus::kInvalidState, mojom::blink::NativeFileSystemStatus::kInvalidState,
...@@ -280,7 +285,7 @@ void NativeFileSystemDirectoryHandle::IsSameEntryImpl( ...@@ -280,7 +285,7 @@ void NativeFileSystemDirectoryHandle::IsSameEntryImpl(
mojo::PendingRemote<mojom::blink::NativeFileSystemTransferToken> other, mojo::PendingRemote<mojom::blink::NativeFileSystemTransferToken> other,
base::OnceCallback<void(mojom::blink::NativeFileSystemErrorPtr, bool)> base::OnceCallback<void(mojom::blink::NativeFileSystemErrorPtr, bool)>
callback) { callback) {
if (!mojo_ptr_) { if (!mojo_ptr_.is_bound()) {
std::move(callback).Run( std::move(callback).Run(
mojom::blink::NativeFileSystemError::New( mojom::blink::NativeFileSystemError::New(
mojom::blink::NativeFileSystemStatus::kInvalidState, mojom::blink::NativeFileSystemStatus::kInvalidState,
...@@ -302,8 +307,4 @@ void NativeFileSystemDirectoryHandle::IsSameEntryImpl( ...@@ -302,8 +307,4 @@ void NativeFileSystemDirectoryHandle::IsSameEntryImpl(
std::move(callback))); std::move(callback)));
} }
void NativeFileSystemDirectoryHandle::ContextDestroyed() {
mojo_ptr_.reset();
}
} // namespace blink } // namespace blink
...@@ -6,9 +6,9 @@ ...@@ -6,9 +6,9 @@
#define THIRD_PARTY_BLINK_RENDERER_MODULES_NATIVE_FILE_SYSTEM_NATIVE_FILE_SYSTEM_DIRECTORY_HANDLE_H_ #define THIRD_PARTY_BLINK_RENDERER_MODULES_NATIVE_FILE_SYSTEM_NATIVE_FILE_SYSTEM_DIRECTORY_HANDLE_H_
#include "mojo/public/cpp/bindings/pending_remote.h" #include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "third_party/blink/public/mojom/native_file_system/native_file_system_directory_handle.mojom-blink.h" #include "third_party/blink/public/mojom/native_file_system/native_file_system_directory_handle.mojom-blink.h"
#include "third_party/blink/renderer/modules/native_file_system/native_file_system_handle.h" #include "third_party/blink/renderer/modules/native_file_system/native_file_system_handle.h"
#include "third_party/blink/renderer/platform/mojo/heap_mojo_remote.h"
namespace blink { namespace blink {
class FileSystemGetDirectoryOptions; class FileSystemGetDirectoryOptions;
...@@ -51,7 +51,7 @@ class NativeFileSystemDirectoryHandle final : public NativeFileSystemHandle { ...@@ -51,7 +51,7 @@ class NativeFileSystemDirectoryHandle final : public NativeFileSystemHandle {
return mojo_ptr_.get(); return mojo_ptr_.get();
} }
void ContextDestroyed() override; void Trace(Visitor*) override;
private: private:
void QueryPermissionImpl( void QueryPermissionImpl(
...@@ -68,7 +68,7 @@ class NativeFileSystemDirectoryHandle final : public NativeFileSystemHandle { ...@@ -68,7 +68,7 @@ class NativeFileSystemDirectoryHandle final : public NativeFileSystemHandle {
base::OnceCallback<void(mojom::blink::NativeFileSystemErrorPtr, bool)>) base::OnceCallback<void(mojom::blink::NativeFileSystemErrorPtr, bool)>)
override; override;
mojo::Remote<mojom::blink::NativeFileSystemDirectoryHandle> mojo_ptr_; HeapMojoRemote<mojom::blink::NativeFileSystemDirectoryHandle> mojo_ptr_;
}; };
} // namespace blink } // namespace blink
......
...@@ -27,10 +27,10 @@ NativeFileSystemFileHandle::NativeFileSystemFileHandle( ...@@ -27,10 +27,10 @@ NativeFileSystemFileHandle::NativeFileSystemFileHandle(
ExecutionContext* context, ExecutionContext* context,
const String& name, const String& name,
mojo::PendingRemote<mojom::blink::NativeFileSystemFileHandle> mojo_ptr) mojo::PendingRemote<mojom::blink::NativeFileSystemFileHandle> mojo_ptr)
: NativeFileSystemHandle(context, name), : NativeFileSystemHandle(context, name), mojo_ptr_(context) {
mojo_ptr_(std::move(mojo_ptr), mojo_ptr_.Bind(std::move(mojo_ptr),
context->GetTaskRunner(TaskType::kMiscPlatformAPI)) { context->GetTaskRunner(TaskType::kMiscPlatformAPI));
DCHECK(mojo_ptr_); DCHECK(mojo_ptr_.is_bound());
} }
ScriptPromise NativeFileSystemFileHandle::createWriter( ScriptPromise NativeFileSystemFileHandle::createWriter(
...@@ -39,7 +39,7 @@ ScriptPromise NativeFileSystemFileHandle::createWriter( ...@@ -39,7 +39,7 @@ ScriptPromise NativeFileSystemFileHandle::createWriter(
auto* resolver = MakeGarbageCollected<ScriptPromiseResolver>(script_state); auto* resolver = MakeGarbageCollected<ScriptPromiseResolver>(script_state);
ScriptPromise result = resolver->Promise(); ScriptPromise result = resolver->Promise();
if (!mojo_ptr_) { if (!mojo_ptr_.is_bound()) {
resolver->Reject(MakeGarbageCollected<DOMException>( resolver->Reject(MakeGarbageCollected<DOMException>(
DOMExceptionCode::kInvalidStateError)); DOMExceptionCode::kInvalidStateError));
return result; return result;
...@@ -71,7 +71,7 @@ ScriptPromise NativeFileSystemFileHandle::createWritable( ...@@ -71,7 +71,7 @@ ScriptPromise NativeFileSystemFileHandle::createWritable(
ScriptState* script_state, ScriptState* script_state,
const FileSystemCreateWriterOptions* options, const FileSystemCreateWriterOptions* options,
ExceptionState& exception_state) { ExceptionState& exception_state) {
if (!mojo_ptr_) { if (!mojo_ptr_.is_bound()) {
exception_state.ThrowDOMException(DOMExceptionCode::kInvalidStateError, ""); exception_state.ThrowDOMException(DOMExceptionCode::kInvalidStateError, "");
return ScriptPromise(); return ScriptPromise();
} }
...@@ -105,7 +105,7 @@ ScriptPromise NativeFileSystemFileHandle::createWritable( ...@@ -105,7 +105,7 @@ ScriptPromise NativeFileSystemFileHandle::createWritable(
ScriptPromise NativeFileSystemFileHandle::getFile( ScriptPromise NativeFileSystemFileHandle::getFile(
ScriptState* script_state, ScriptState* script_state,
ExceptionState& exception_state) { ExceptionState& exception_state) {
if (!mojo_ptr_) { if (!mojo_ptr_.is_bound()) {
exception_state.ThrowDOMException(DOMExceptionCode::kInvalidStateError, ""); exception_state.ThrowDOMException(DOMExceptionCode::kInvalidStateError, "");
return ScriptPromise(); return ScriptPromise();
} }
...@@ -132,19 +132,20 @@ ScriptPromise NativeFileSystemFileHandle::getFile( ...@@ -132,19 +132,20 @@ ScriptPromise NativeFileSystemFileHandle::getFile(
mojo::PendingRemote<mojom::blink::NativeFileSystemTransferToken> mojo::PendingRemote<mojom::blink::NativeFileSystemTransferToken>
NativeFileSystemFileHandle::Transfer() { NativeFileSystemFileHandle::Transfer() {
mojo::PendingRemote<mojom::blink::NativeFileSystemTransferToken> result; mojo::PendingRemote<mojom::blink::NativeFileSystemTransferToken> result;
if (mojo_ptr_) if (mojo_ptr_.is_bound())
mojo_ptr_->Transfer(result.InitWithNewPipeAndPassReceiver()); mojo_ptr_->Transfer(result.InitWithNewPipeAndPassReceiver());
return result; return result;
} }
void NativeFileSystemFileHandle::ContextDestroyed() { void NativeFileSystemFileHandle::Trace(Visitor* visitor) {
mojo_ptr_.reset(); visitor->Trace(mojo_ptr_);
NativeFileSystemHandle::Trace(visitor);
} }
void NativeFileSystemFileHandle::QueryPermissionImpl( void NativeFileSystemFileHandle::QueryPermissionImpl(
bool writable, bool writable,
base::OnceCallback<void(mojom::blink::PermissionStatus)> callback) { base::OnceCallback<void(mojom::blink::PermissionStatus)> callback) {
if (!mojo_ptr_) { if (!mojo_ptr_.is_bound()) {
std::move(callback).Run(mojom::blink::PermissionStatus::DENIED); std::move(callback).Run(mojom::blink::PermissionStatus::DENIED);
return; return;
} }
...@@ -155,7 +156,7 @@ void NativeFileSystemFileHandle::RequestPermissionImpl( ...@@ -155,7 +156,7 @@ void NativeFileSystemFileHandle::RequestPermissionImpl(
bool writable, bool writable,
base::OnceCallback<void(mojom::blink::NativeFileSystemErrorPtr, base::OnceCallback<void(mojom::blink::NativeFileSystemErrorPtr,
mojom::blink::PermissionStatus)> callback) { mojom::blink::PermissionStatus)> callback) {
if (!mojo_ptr_) { if (!mojo_ptr_.is_bound()) {
std::move(callback).Run( std::move(callback).Run(
mojom::blink::NativeFileSystemError::New( mojom::blink::NativeFileSystemError::New(
mojom::blink::NativeFileSystemStatus::kInvalidState, mojom::blink::NativeFileSystemStatus::kInvalidState,
...@@ -171,7 +172,7 @@ void NativeFileSystemFileHandle::IsSameEntryImpl( ...@@ -171,7 +172,7 @@ void NativeFileSystemFileHandle::IsSameEntryImpl(
mojo::PendingRemote<mojom::blink::NativeFileSystemTransferToken> other, mojo::PendingRemote<mojom::blink::NativeFileSystemTransferToken> other,
base::OnceCallback<void(mojom::blink::NativeFileSystemErrorPtr, bool)> base::OnceCallback<void(mojom::blink::NativeFileSystemErrorPtr, bool)>
callback) { callback) {
if (!mojo_ptr_) { if (!mojo_ptr_.is_bound()) {
std::move(callback).Run( std::move(callback).Run(
mojom::blink::NativeFileSystemError::New( mojom::blink::NativeFileSystemError::New(
mojom::blink::NativeFileSystemStatus::kInvalidState, mojom::blink::NativeFileSystemStatus::kInvalidState,
......
...@@ -6,9 +6,9 @@ ...@@ -6,9 +6,9 @@
#define THIRD_PARTY_BLINK_RENDERER_MODULES_NATIVE_FILE_SYSTEM_NATIVE_FILE_SYSTEM_FILE_HANDLE_H_ #define THIRD_PARTY_BLINK_RENDERER_MODULES_NATIVE_FILE_SYSTEM_NATIVE_FILE_SYSTEM_FILE_HANDLE_H_
#include "mojo/public/cpp/bindings/pending_remote.h" #include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "third_party/blink/public/mojom/native_file_system/native_file_system_file_handle.mojom-blink.h" #include "third_party/blink/public/mojom/native_file_system/native_file_system_file_handle.mojom-blink.h"
#include "third_party/blink/renderer/modules/native_file_system/native_file_system_handle.h" #include "third_party/blink/renderer/modules/native_file_system/native_file_system_handle.h"
#include "third_party/blink/renderer/platform/mojo/heap_mojo_remote.h"
namespace blink { namespace blink {
class FileSystemCreateWriterOptions; class FileSystemCreateWriterOptions;
...@@ -34,12 +34,12 @@ class NativeFileSystemFileHandle final : public NativeFileSystemHandle { ...@@ -34,12 +34,12 @@ class NativeFileSystemFileHandle final : public NativeFileSystemHandle {
mojo::PendingRemote<mojom::blink::NativeFileSystemTransferToken> Transfer() mojo::PendingRemote<mojom::blink::NativeFileSystemTransferToken> Transfer()
override; override;
void ContextDestroyed() override;
mojom::blink::NativeFileSystemFileHandle* MojoHandle() { mojom::blink::NativeFileSystemFileHandle* MojoHandle() {
return mojo_ptr_.get(); return mojo_ptr_.get();
} }
void Trace(Visitor*) override;
private: private:
void QueryPermissionImpl( void QueryPermissionImpl(
bool writable, bool writable,
...@@ -53,7 +53,7 @@ class NativeFileSystemFileHandle final : public NativeFileSystemHandle { ...@@ -53,7 +53,7 @@ class NativeFileSystemFileHandle final : public NativeFileSystemHandle {
base::OnceCallback<void(mojom::blink::NativeFileSystemErrorPtr, bool)>) base::OnceCallback<void(mojom::blink::NativeFileSystemErrorPtr, bool)>)
override; override;
mojo::Remote<mojom::blink::NativeFileSystemFileHandle> mojo_ptr_; HeapMojoRemote<mojom::blink::NativeFileSystemFileHandle> mojo_ptr_;
}; };
} // namespace blink } // namespace blink
......
...@@ -22,7 +22,7 @@ using mojom::blink::NativeFileSystemErrorPtr; ...@@ -22,7 +22,7 @@ using mojom::blink::NativeFileSystemErrorPtr;
NativeFileSystemHandle::NativeFileSystemHandle( NativeFileSystemHandle::NativeFileSystemHandle(
ExecutionContext* execution_context, ExecutionContext* execution_context,
const String& name) const String& name)
: ExecutionContextLifecycleObserver(execution_context), name_(name) {} : ExecutionContextClient(execution_context), name_(name) {}
// static // static
NativeFileSystemHandle* NativeFileSystemHandle::CreateFromMojoEntry( NativeFileSystemHandle* NativeFileSystemHandle::CreateFromMojoEntry(
...@@ -114,7 +114,7 @@ ScriptPromise NativeFileSystemHandle::isSameEntry( ...@@ -114,7 +114,7 @@ ScriptPromise NativeFileSystemHandle::isSameEntry(
void NativeFileSystemHandle::Trace(Visitor* visitor) { void NativeFileSystemHandle::Trace(Visitor* visitor) {
ScriptWrappable::Trace(visitor); ScriptWrappable::Trace(visitor);
ExecutionContextLifecycleObserver::Trace(visitor); ExecutionContextClient::Trace(visitor);
} }
} // namespace blink } // namespace blink
...@@ -22,7 +22,7 @@ class ExecutionContext; ...@@ -22,7 +22,7 @@ class ExecutionContext;
class FileSystemHandlePermissionDescriptor; class FileSystemHandlePermissionDescriptor;
class NativeFileSystemHandle : public ScriptWrappable, class NativeFileSystemHandle : public ScriptWrappable,
public ExecutionContextLifecycleObserver { public ExecutionContextClient {
DEFINE_WRAPPERTYPEINFO(); DEFINE_WRAPPERTYPEINFO();
USING_GARBAGE_COLLECTED_MIXIN(NativeFileSystemHandle); USING_GARBAGE_COLLECTED_MIXIN(NativeFileSystemHandle);
......
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