Commit a7fbcf2d authored by Kenichi Ishibashi's avatar Kenichi Ishibashi Committed by Commit Bot

Remove IndexedDBClient

IndexedDBClient was a WorkerClient and it provided AllowIndexedDB().
IDBFactory extracted an IndexedDBClient from execution context to
call AllowIndexedDB(). However this was an unnecessary abstraction
and we can directly implement AllowIndexedDB() in IDBFactory.
This CL removes IndexedDBClient to remove the abstraction.
This eliminates creating a GarbageCollection object.

This CL doesn't have behavioral changes.

Bug: 988335
Change-Id: Ia6948cf195abf53335609d2ddb2a02bd7c7faa84
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1722276Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarHiroki Nakagawa <nhiroki@chromium.org>
Reviewed-by: default avatarJoshua Bell <jsbell@chromium.org>
Commit-Queue: Kenichi Ishibashi <bashi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#682146}
parent 82f758de
...@@ -85,7 +85,6 @@ class CORE_EXPORT CoreInitializer { ...@@ -85,7 +85,6 @@ class CORE_EXPORT CoreInitializer {
// Supplements installed on a frame using ChromeClient // Supplements installed on a frame using ChromeClient
virtual void InstallSupplements(LocalFrame&) const = 0; virtual void InstallSupplements(LocalFrame&) const = 0;
virtual void ProvideLocalFileSystemToWorker(WorkerClients&) const = 0; virtual void ProvideLocalFileSystemToWorker(WorkerClients&) const = 0;
virtual void ProvideIndexedDBClientToWorker(WorkerClients&) const = 0;
virtual MediaControls* CreateMediaControls(HTMLMediaElement&, virtual MediaControls* CreateMediaControls(HTMLMediaElement&,
ShadowRoot&) const = 0; ShadowRoot&) const = 0;
virtual PictureInPictureController* CreatePictureInPictureController( virtual PictureInPictureController* CreatePictureInPictureController(
......
...@@ -338,8 +338,6 @@ WorkerClients* WebSharedWorkerImpl::CreateWorkerClients() { ...@@ -338,8 +338,6 @@ WorkerClients* WebSharedWorkerImpl::CreateWorkerClients() {
auto* worker_clients = MakeGarbageCollected<WorkerClients>(); auto* worker_clients = MakeGarbageCollected<WorkerClients>();
CoreInitializer::GetInstance().ProvideLocalFileSystemToWorker( CoreInitializer::GetInstance().ProvideLocalFileSystemToWorker(
*worker_clients); *worker_clients);
CoreInitializer::GetInstance().ProvideIndexedDBClientToWorker(
*worker_clients);
return worker_clients; return worker_clients;
} }
......
...@@ -361,8 +361,6 @@ WorkerClients* DedicatedWorker::CreateWorkerClients() { ...@@ -361,8 +361,6 @@ WorkerClients* DedicatedWorker::CreateWorkerClients() {
auto* worker_clients = MakeGarbageCollected<WorkerClients>(); auto* worker_clients = MakeGarbageCollected<WorkerClients>();
CoreInitializer::GetInstance().ProvideLocalFileSystemToWorker( CoreInitializer::GetInstance().ProvideLocalFileSystemToWorker(
*worker_clients); *worker_clients);
CoreInitializer::GetInstance().ProvideIndexedDBClientToWorker(
*worker_clients);
return worker_clients; return worker_clients;
} }
......
...@@ -59,7 +59,6 @@ ...@@ -59,7 +59,6 @@
#include "third_party/blink/renderer/core/workers/worker_backing_thread_startup_data.h" #include "third_party/blink/renderer/core/workers/worker_backing_thread_startup_data.h"
#include "third_party/blink/renderer/core/workers/worker_classic_script_loader.h" #include "third_party/blink/renderer/core/workers/worker_classic_script_loader.h"
#include "third_party/blink/renderer/core/workers/worker_global_scope.h" #include "third_party/blink/renderer/core/workers/worker_global_scope.h"
#include "third_party/blink/renderer/modules/indexeddb/indexed_db_client.h"
#include "third_party/blink/renderer/modules/service_worker/service_worker_global_scope_proxy.h" #include "third_party/blink/renderer/modules/service_worker/service_worker_global_scope_proxy.h"
#include "third_party/blink/renderer/modules/service_worker/service_worker_installed_scripts_manager.h" #include "third_party/blink/renderer/modules/service_worker/service_worker_installed_scripts_manager.h"
#include "third_party/blink/renderer/modules/service_worker/service_worker_thread.h" #include "third_party/blink/renderer/modules/service_worker/service_worker_thread.h"
...@@ -383,9 +382,8 @@ void WebEmbeddedWorkerImpl::StartWorkerThread() { ...@@ -383,9 +382,8 @@ void WebEmbeddedWorkerImpl::StartWorkerThread() {
const HttpsState starter_https_state = const HttpsState starter_https_state =
CalculateHttpsState(starter_origin.get()); CalculateHttpsState(starter_origin.get());
// TODO(bashi): Pass nullptr instead of an empty WorkerClients.
auto* worker_clients = MakeGarbageCollected<WorkerClients>(); auto* worker_clients = MakeGarbageCollected<WorkerClients>();
ProvideIndexedDBClientToWorker(
worker_clients, MakeGarbageCollected<IndexedDBClient>(*worker_clients));
scoped_refptr<WebWorkerFetchContext> web_worker_fetch_context; scoped_refptr<WebWorkerFetchContext> web_worker_fetch_context;
if (base::FeatureList::IsEnabled( if (base::FeatureList::IsEnabled(
......
...@@ -62,8 +62,6 @@ blink_modules_sources("indexeddb") { ...@@ -62,8 +62,6 @@ blink_modules_sources("indexeddb") {
"indexed_db.h", "indexed_db.h",
"indexed_db_blink_mojom_traits.cc", "indexed_db_blink_mojom_traits.cc",
"indexed_db_blink_mojom_traits.h", "indexed_db_blink_mojom_traits.h",
"indexed_db_client.cc",
"indexed_db_client.h",
"indexed_db_database_callbacks_impl.cc", "indexed_db_database_callbacks_impl.cc",
"indexed_db_database_callbacks_impl.h", "indexed_db_database_callbacks_impl.h",
"indexed_db_dispatcher.cc", "indexed_db_dispatcher.cc",
......
...@@ -36,12 +36,15 @@ ...@@ -36,12 +36,15 @@
#include "third_party/blink/public/platform/interface_provider.h" #include "third_party/blink/public/platform/interface_provider.h"
#include "third_party/blink/public/platform/platform.h" #include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/public/platform/task_type.h" #include "third_party/blink/public/platform/task_type.h"
#include "third_party/blink/public/platform/web_content_settings_client.h"
#include "third_party/blink/public/platform/web_security_origin.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h" #include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_binding_for_modules.h" #include "third_party/blink/renderer/bindings/modules/v8/v8_binding_for_modules.h"
#include "third_party/blink/renderer/core/dom/document.h" #include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/dom_exception.h" #include "third_party/blink/renderer/core/dom/dom_exception.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h" #include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/probe/core_probes.h" #include "third_party/blink/renderer/core/probe/core_probes.h"
#include "third_party/blink/renderer/core/workers/worker_global_scope.h"
#include "third_party/blink/renderer/modules/indexed_db_names.h" #include "third_party/blink/renderer/modules/indexed_db_names.h"
#include "third_party/blink/renderer/modules/indexeddb/idb_database.h" #include "third_party/blink/renderer/modules/indexeddb/idb_database.h"
#include "third_party/blink/renderer/modules/indexeddb/idb_database_callbacks.h" #include "third_party/blink/renderer/modules/indexeddb/idb_database_callbacks.h"
...@@ -49,7 +52,6 @@ ...@@ -49,7 +52,6 @@
#include "third_party/blink/renderer/modules/indexeddb/idb_key.h" #include "third_party/blink/renderer/modules/indexeddb/idb_key.h"
#include "third_party/blink/renderer/modules/indexeddb/idb_name_and_version.h" #include "third_party/blink/renderer/modules/indexeddb/idb_name_and_version.h"
#include "third_party/blink/renderer/modules/indexeddb/idb_tracing.h" #include "third_party/blink/renderer/modules/indexeddb/idb_tracing.h"
#include "third_party/blink/renderer/modules/indexeddb/indexed_db_client.h"
#include "third_party/blink/renderer/modules/indexeddb/web_idb_callbacks.h" #include "third_party/blink/renderer/modules/indexeddb/web_idb_callbacks.h"
#include "third_party/blink/renderer/modules/indexeddb/web_idb_database_callbacks.h" #include "third_party/blink/renderer/modules/indexeddb/web_idb_database_callbacks.h"
#include "third_party/blink/renderer/modules/indexeddb/web_idb_factory.h" #include "third_party/blink/renderer/modules/indexeddb/web_idb_factory.h"
...@@ -267,8 +269,7 @@ IDBRequest* IDBFactory::GetDatabaseNames(ScriptState* script_state, ...@@ -267,8 +269,7 @@ IDBRequest* IDBFactory::GetDatabaseNames(ScriptState* script_state,
WebFeature::kFileAccessedDatabase); WebFeature::kFileAccessedDatabase);
} }
if (!IndexedDBClient::From(ExecutionContext::From(script_state)) if (!AllowIndexedDB(ExecutionContext::From(script_state))) {
->AllowIndexedDB(ExecutionContext::From(script_state))) {
request->HandleResponse(MakeGarbageCollected<DOMException>( request->HandleResponse(MakeGarbageCollected<DOMException>(
DOMExceptionCode::kUnknownError, kPermissionDeniedErrorMessage)); DOMExceptionCode::kUnknownError, kPermissionDeniedErrorMessage));
return request; return request;
...@@ -330,8 +331,7 @@ IDBOpenDBRequest* IDBFactory::OpenInternal(ScriptState* script_state, ...@@ -330,8 +331,7 @@ IDBOpenDBRequest* IDBFactory::OpenInternal(ScriptState* script_state,
script_state, database_callbacks, std::move(transaction_backend), script_state, database_callbacks, std::move(transaction_backend),
transaction_id, version, std::move(metrics)); transaction_id, version, std::move(metrics));
if (!IndexedDBClient::From(ExecutionContext::From(script_state)) if (!AllowIndexedDB(ExecutionContext::From(script_state))) {
->AllowIndexedDB(ExecutionContext::From(script_state))) {
request->HandleResponse(MakeGarbageCollected<DOMException>( request->HandleResponse(MakeGarbageCollected<DOMException>(
DOMExceptionCode::kUnknownError, kPermissionDeniedErrorMessage)); DOMExceptionCode::kUnknownError, kPermissionDeniedErrorMessage));
return request; return request;
...@@ -398,8 +398,7 @@ IDBOpenDBRequest* IDBFactory::DeleteDatabaseInternal( ...@@ -398,8 +398,7 @@ IDBOpenDBRequest* IDBFactory::DeleteDatabaseInternal(
script_state, nullptr, /*IDBTransactionAssociatedPtr=*/nullptr, 0, script_state, nullptr, /*IDBTransactionAssociatedPtr=*/nullptr, 0,
IDBDatabaseMetadata::kDefaultVersion, std::move(metrics)); IDBDatabaseMetadata::kDefaultVersion, std::move(metrics));
if (!IndexedDBClient::From(ExecutionContext::From(script_state)) if (!AllowIndexedDB(ExecutionContext::From(script_state))) {
->AllowIndexedDB(ExecutionContext::From(script_state))) {
request->HandleResponse(MakeGarbageCollected<DOMException>( request->HandleResponse(MakeGarbageCollected<DOMException>(
DOMExceptionCode::kUnknownError, kPermissionDeniedErrorMessage)); DOMExceptionCode::kUnknownError, kPermissionDeniedErrorMessage));
return request; return request;
...@@ -446,4 +445,27 @@ int16_t IDBFactory::cmp(ScriptState* script_state, ...@@ -446,4 +445,27 @@ int16_t IDBFactory::cmp(ScriptState* script_state,
return static_cast<int16_t>(first->Compare(second.get())); return static_cast<int16_t>(first->Compare(second.get()));
} }
bool IDBFactory::AllowIndexedDB(ExecutionContext* execution_context) {
DCHECK(execution_context->IsContextThread());
SECURITY_DCHECK(execution_context->IsDocument() ||
execution_context->IsWorkerGlobalScope());
if (auto* document = DynamicTo<Document>(execution_context)) {
LocalFrame* frame = document->GetFrame();
if (!frame)
return false;
if (auto* settings_client = frame->GetContentSettingsClient()) {
return settings_client->AllowIndexedDB(
WebSecurityOrigin(execution_context->GetSecurityOrigin()));
}
return true;
}
WebContentSettingsClient* content_settings_client =
To<WorkerGlobalScope>(execution_context)->ContentSettingsClient();
if (!content_settings_client)
return true;
return content_settings_client->AllowIndexedDB(
WebSecurityOrigin(execution_context->GetSecurityOrigin()));
}
} // namespace blink } // namespace blink
...@@ -84,6 +84,8 @@ class MODULES_EXPORT IDBFactory final : public ScriptWrappable { ...@@ -84,6 +84,8 @@ class MODULES_EXPORT IDBFactory final : public ScriptWrappable {
ExceptionState&, ExceptionState&,
bool); bool);
bool AllowIndexedDB(ExecutionContext* execution_context);
std::unique_ptr<WebIDBFactory> web_idb_factory_; std::unique_ptr<WebIDBFactory> web_idb_factory_;
}; };
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/modules/indexeddb/indexed_db_client.h"
#include "third_party/blink/public/platform/web_content_settings_client.h"
#include "third_party/blink/public/platform/web_security_origin.h"
#include "third_party/blink/renderer/bindings/core/v8/worker_or_worklet_script_controller.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/workers/worker_clients.h"
#include "third_party/blink/renderer/core/workers/worker_global_scope.h"
#include "third_party/blink/renderer/platform/weborigin/security_origin.h"
namespace blink {
IndexedDBClient::IndexedDBClient(LocalFrame& frame)
: Supplement<LocalFrame>(frame) {}
IndexedDBClient::IndexedDBClient(WorkerClients& clients)
: Supplement<WorkerClients>(clients) {}
IndexedDBClient* IndexedDBClient::From(ExecutionContext* context) {
if (auto* document = DynamicTo<Document>(context)) {
return Supplement<LocalFrame>::From<IndexedDBClient>(document->GetFrame());
}
WorkerClients* clients = To<WorkerGlobalScope>(*context).Clients();
DCHECK(clients);
return Supplement<WorkerClients>::From<IndexedDBClient>(clients);
}
bool IndexedDBClient::AllowIndexedDB(ExecutionContext* context) {
DCHECK(context->IsContextThread());
SECURITY_DCHECK(context->IsDocument() || context->IsWorkerGlobalScope());
if (auto* document = DynamicTo<Document>(context)) {
LocalFrame* frame = document->GetFrame();
if (!frame)
return false;
if (auto* settings_client = frame->GetContentSettingsClient()) {
return settings_client->AllowIndexedDB(
WebSecurityOrigin(context->GetSecurityOrigin()));
}
return true;
}
WebContentSettingsClient* content_settings_client =
To<WorkerGlobalScope>(context)->ContentSettingsClient();
if (!content_settings_client)
return true;
return content_settings_client->AllowIndexedDB(WebSecurityOrigin());
}
// static
const char IndexedDBClient::kSupplementName[] = "IndexedDBClient";
void IndexedDBClient::Trace(blink::Visitor* visitor) {
Supplement<LocalFrame>::Trace(visitor);
Supplement<WorkerClients>::Trace(visitor);
}
void ProvideIndexedDBClientTo(LocalFrame& frame, IndexedDBClient* client) {
Supplement<LocalFrame>::ProvideTo(frame, client);
}
void ProvideIndexedDBClientToWorker(WorkerClients* clients,
IndexedDBClient* client) {
Supplement<WorkerClients>::ProvideTo(*clients, client);
}
} // namespace blink
/*
* Copyright (C) 2010 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:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. 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.
* 3. Neither the name of Apple Computer, Inc. ("Apple") 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 APPLE AND ITS 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 APPLE OR ITS 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_INDEXEDDB_INDEXED_DB_CLIENT_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_INDEXED_DB_CLIENT_H_
#include "base/macros.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/workers/worker_clients.h"
#include "third_party/blink/renderer/modules/modules_export.h"
#include "third_party/blink/renderer/platform/bindings/name_client.h"
#include "third_party/blink/renderer/platform/heap/handle.h"
#include "third_party/blink/renderer/platform/supplementable.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
namespace blink {
class ExecutionContext;
class LocalFrame;
class WorkerClients;
class IndexedDBClient : public GarbageCollected<IndexedDBClient>,
public Supplement<LocalFrame>,
public Supplement<WorkerClients>,
public NameClient {
USING_GARBAGE_COLLECTED_MIXIN(IndexedDBClient);
public:
static const char kSupplementName[];
explicit IndexedDBClient(LocalFrame&);
explicit IndexedDBClient(WorkerClients&);
void Trace(blink::Visitor*) override;
const char* NameInHeapSnapshot() const override { return "IndexedDBClient"; }
bool AllowIndexedDB(ExecutionContext*);
static IndexedDBClient* From(ExecutionContext*);
private:
DISALLOW_COPY_AND_ASSIGN(IndexedDBClient);
};
void ProvideIndexedDBClientTo(LocalFrame&, IndexedDBClient*);
void ProvideIndexedDBClientToWorker(WorkerClients*, IndexedDBClient*);
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_INDEXED_DB_CLIENT_H_
...@@ -53,7 +53,6 @@ ...@@ -53,7 +53,6 @@
#include "third_party/blink/renderer/modules/gamepad/navigator_gamepad.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/image_downloader/image_downloader_impl.h"
#include "third_party/blink/renderer/modules/indexed_db_names.h" #include "third_party/blink/renderer/modules/indexed_db_names.h"
#include "third_party/blink/renderer/modules/indexeddb/indexed_db_client.h"
#include "third_party/blink/renderer/modules/indexeddb/inspector_indexed_db_agent.h" #include "third_party/blink/renderer/modules/indexeddb/inspector_indexed_db_agent.h"
#include "third_party/blink/renderer/modules/installation/installation_service_impl.h" #include "third_party/blink/renderer/modules/installation/installation_service_impl.h"
#include "third_party/blink/renderer/modules/installedapp/installed_app_controller.h" #include "third_party/blink/renderer/modules/installedapp/installed_app_controller.h"
...@@ -183,7 +182,6 @@ void ModulesInitializer::InstallSupplements(LocalFrame& frame) const { ...@@ -183,7 +182,6 @@ void ModulesInitializer::InstallSupplements(LocalFrame& frame) const {
frame, MakeGarbageCollected<PushMessagingClient>(frame)); frame, MakeGarbageCollected<PushMessagingClient>(frame));
ProvideUserMediaTo( ProvideUserMediaTo(
frame, std::make_unique<UserMediaClient>(client->UserMediaClient())); frame, std::make_unique<UserMediaClient>(client->UserMediaClient()));
ProvideIndexedDBClientTo(frame, MakeGarbageCollected<IndexedDBClient>(frame));
ProvideLocalFileSystemTo(frame, std::make_unique<LocalFileSystemClient>()); ProvideLocalFileSystemTo(frame, std::make_unique<LocalFileSystemClient>());
ScreenOrientationControllerImpl::ProvideTo(frame); ScreenOrientationControllerImpl::ProvideTo(frame);
...@@ -205,12 +203,6 @@ void ModulesInitializer::ProvideLocalFileSystemToWorker( ...@@ -205,12 +203,6 @@ void ModulesInitializer::ProvideLocalFileSystemToWorker(
&worker_clients, std::make_unique<LocalFileSystemClient>()); &worker_clients, std::make_unique<LocalFileSystemClient>());
} }
void ModulesInitializer::ProvideIndexedDBClientToWorker(
WorkerClients& worker_clients) const {
::blink::ProvideIndexedDBClientToWorker(
&worker_clients, MakeGarbageCollected<IndexedDBClient>(worker_clients));
}
MediaControls* ModulesInitializer::CreateMediaControls( MediaControls* ModulesInitializer::CreateMediaControls(
HTMLMediaElement& media_element, HTMLMediaElement& media_element,
ShadowRoot& shadow_root) const { ShadowRoot& shadow_root) const {
......
...@@ -23,7 +23,6 @@ class MODULES_EXPORT ModulesInitializer : public CoreInitializer { ...@@ -23,7 +23,6 @@ class MODULES_EXPORT ModulesInitializer : public CoreInitializer {
private: private:
void InstallSupplements(LocalFrame&) const override; void InstallSupplements(LocalFrame&) const override;
void ProvideLocalFileSystemToWorker(WorkerClients&) const override; void ProvideLocalFileSystemToWorker(WorkerClients&) const override;
void ProvideIndexedDBClientToWorker(WorkerClients&) const override;
MediaControls* CreateMediaControls(HTMLMediaElement&, MediaControls* CreateMediaControls(HTMLMediaElement&,
ShadowRoot&) const override; ShadowRoot&) const override;
PictureInPictureController* CreatePictureInPictureController( PictureInPictureController* CreatePictureInPictureController(
......
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