diff options
Diffstat (limited to 'chromium/third_party/blink/renderer/modules/indexeddb')
54 files changed, 505 insertions, 299 deletions
diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/BUILD.gn b/chromium/third_party/blink/renderer/modules/indexeddb/BUILD.gn index 1728725a3bf..593b29a7949 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/BUILD.gn +++ b/chromium/third_party/blink/renderer/modules/indexeddb/BUILD.gn @@ -88,7 +88,5 @@ blink_modules_sources("indexeddb") { "web_idb_transaction_impl.h", ] - public_deps = [ - "//third_party/blink/public/mojom:mojom_modules_blink", - ] + public_deps = [ "//third_party/blink/public/mojom:mojom_modules_blink" ] } diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/global_indexed_db.cc b/chromium/third_party/blink/renderer/modules/indexeddb/global_indexed_db.cc index 2bfd37384f0..4989637cd4c 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/global_indexed_db.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/global_indexed_db.cc @@ -41,7 +41,7 @@ class GlobalIndexedDBImpl final return idb_factory_; } - void Trace(blink::Visitor* visitor) override { + void Trace(Visitor* visitor) override { visitor->Trace(idb_factory_); Supplement<T>::Trace(visitor); } diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_any.cc b/chromium/third_party/blink/renderer/modules/indexeddb/idb_any.cc index 777f8d0a6f7..aa1a275705a 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_any.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_any.cc @@ -35,14 +35,6 @@ namespace blink { -IDBAny* IDBAny::CreateUndefined() { - return MakeGarbageCollected<IDBAny>(kUndefinedType); -} - -IDBAny* IDBAny::CreateNull() { - return MakeGarbageCollected<IDBAny>(kNullType); -} - IDBAny::IDBAny(Type type) : type_(type) { DCHECK(type == kUndefinedType || type == kNullType); } @@ -67,8 +59,8 @@ IDBCursor* IDBAny::IdbCursor() const { IDBCursorWithValue* IDBAny::IdbCursorWithValue() const { DCHECK_EQ(type_, kIDBCursorWithValueType); - SECURITY_DCHECK(idb_cursor_->IsCursorWithValue()); - return ToIDBCursorWithValue(idb_cursor_.Get()); + SECURITY_DCHECK(IsA<IDBCursorWithValue>(idb_cursor_.Get())); + return To<IDBCursorWithValue>(idb_cursor_.Get()); } IDBDatabase* IDBAny::IdbDatabase() const { @@ -101,8 +93,8 @@ IDBAny::IDBAny(DOMStringList* value) : type_(kDOMStringListType), dom_string_list_(value) {} IDBAny::IDBAny(IDBCursor* value) - : type_(value->IsCursorWithValue() ? kIDBCursorWithValueType - : kIDBCursorType), + : type_(IsA<IDBCursorWithValue>(value) ? kIDBCursorWithValueType + : kIDBCursorType), idb_cursor_(value) {} IDBAny::IDBAny(IDBDatabase* value) @@ -119,7 +111,7 @@ IDBAny::IDBAny(std::unique_ptr<IDBKey> key) IDBAny::IDBAny(int64_t value) : type_(kIntegerType), integer_(value) {} -void IDBAny::Trace(blink::Visitor* visitor) { +void IDBAny::Trace(Visitor* visitor) { visitor->Trace(dom_string_list_); visitor->Trace(idb_cursor_); visitor->Trace(idb_database_); diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_any.h b/chromium/third_party/blink/renderer/modules/indexeddb/idb_any.h index a5ca81642ff..825eeae6ffa 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_any.h +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_any.h @@ -55,9 +55,6 @@ class IDBObjectStore; class MODULES_EXPORT IDBAny final : public GarbageCollected<IDBAny> { public: - static IDBAny* CreateUndefined(); - static IDBAny* CreateNull(); - enum Type { kUndefinedType = 0, kNullType, @@ -81,7 +78,7 @@ class MODULES_EXPORT IDBAny final : public GarbageCollected<IDBAny> { explicit IDBAny(int64_t); ~IDBAny(); - void Trace(blink::Visitor*); + void Trace(Visitor*); void ContextWillBeDestroyed(); Type GetType() const { return type_; } diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_cursor.cc b/chromium/third_party/blink/renderer/modules/indexeddb/idb_cursor.cc index 782f3a05223..b0552bc3e58 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_cursor.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_cursor.cc @@ -32,6 +32,7 @@ #include "third_party/blink/renderer/bindings/modules/v8/v8_idb_request.h" #include "third_party/blink/renderer/modules/indexed_db_names.h" #include "third_party/blink/renderer/modules/indexeddb/idb_any.h" +#include "third_party/blink/renderer/modules/indexeddb/idb_cursor_with_value.h" #include "third_party/blink/renderer/modules/indexeddb/idb_database.h" #include "third_party/blink/renderer/modules/indexeddb/idb_object_store.h" #include "third_party/blink/renderer/modules/indexeddb/idb_tracing.h" @@ -41,6 +42,7 @@ #include "third_party/blink/renderer/platform/bindings/script_state.h" #include "third_party/blink/renderer/platform/bindings/v8_private_property.h" #include "third_party/blink/renderer/platform/heap/heap.h" +#include "third_party/blink/renderer/platform/wtf/casting.h" namespace blink { @@ -62,7 +64,7 @@ IDBCursor::IDBCursor(std::unique_ptr<WebIDBCursor> backend, IDBCursor::~IDBCursor() = default; -void IDBCursor::Trace(blink::Visitor* visitor) { +void IDBCursor::Trace(Visitor* visitor) { visitor->Trace(request_); visitor->Trace(source_); visitor->Trace(transaction_); @@ -392,7 +394,7 @@ ScriptValue IDBCursor::primaryKey(ScriptState* script_state) { } ScriptValue IDBCursor::value(ScriptState* script_state) { - DCHECK(IsCursorWithValue()); + DCHECK(IsA<IDBCursorWithValue>(this)); IDBAny* value; if (value_) { @@ -407,7 +409,7 @@ ScriptValue IDBCursor::value(ScriptState* script_state) { #endif // DCHECK_IS_ON() } else { - value = IDBAny::CreateUndefined(); + value = MakeGarbageCollected<IDBAny>(IDBAny::kUndefinedType); } value_dirty_ = false; @@ -430,7 +432,7 @@ void IDBCursor::SetValueReady(std::unique_ptr<IDBKey> key, got_value_ = true; - if (!IsCursorWithValue()) + if (!IsA<IDBCursorWithValue>(this)) return; value_dirty_ = true; diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_cursor.h b/chromium/third_party/blink/renderer/modules/indexeddb/idb_cursor.h index c3292558d28..86ca472dff3 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_cursor.h +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_cursor.h @@ -59,7 +59,7 @@ class IDBCursor : public ScriptWrappable { IDBTransaction*); ~IDBCursor() override; - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; void ContextWillBeDestroyed() { backend_.reset(); } WARN_UNUSED_RESULT v8::Local<v8::Object> AssociateWithWrapper( diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_cursor.idl b/chromium/third_party/blink/renderer/modules/indexeddb/idb_cursor.idl index 2ac7fa5dd93..21e8813eb40 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_cursor.idl +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_cursor.idl @@ -47,7 +47,7 @@ enum IDBCursorDirection { [RaisesException] void advance([EnforceRange] unsigned long count); [CallWith=ScriptState, ImplementedAs=Continue, RaisesException] - void continue([DefaultValue=Undefined] optional any key); + void continue(optional any key = null); [CallWith=ScriptState, RaisesException] void continuePrimaryKey(any key, any primaryKey); diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_cursor_with_value.h b/chromium/third_party/blink/renderer/modules/indexeddb/idb_cursor_with_value.h index 559640e80dc..26b35f268d7 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_cursor_with_value.h +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_cursor_with_value.h @@ -31,6 +31,7 @@ #include "third_party/blink/renderer/modules/indexeddb/idb_cursor.h" #include "third_party/blink/renderer/modules/indexeddb/indexed_db.h" #include "third_party/blink/renderer/modules/indexeddb/web_idb_cursor.h" +#include "third_party/blink/renderer/platform/wtf/casting.h" namespace blink { @@ -56,11 +57,12 @@ class IDBCursorWithValue final : public IDBCursor { bool IsCursorWithValue() const override { return true; } }; -DEFINE_TYPE_CASTS(IDBCursorWithValue, - IDBCursor, - cursor, - cursor->IsCursorWithValue(), - cursor.IsCursorWithValue()); +template <> +struct DowncastTraits<IDBCursorWithValue> { + static bool AllowFrom(const IDBCursor& cursor) { + return cursor.IsCursorWithValue(); + } +}; } // namespace blink diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_database.cc b/chromium/third_party/blink/renderer/modules/indexeddb/idb_database.cc index 97f5b505fab..3f2764199a4 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_database.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_database.cc @@ -30,6 +30,7 @@ #include "base/atomic_sequence_num.h" #include "base/optional.h" +#include "third_party/blink/public/common/browser_interface_broker_proxy.h" #include "third_party/blink/public/common/indexeddb/web_idb_types.h" #include "third_party/blink/public/mojom/indexeddb/indexeddb.mojom-blink.h" #include "third_party/blink/renderer/bindings/core/v8/serialization/serialized_script_value.h" @@ -93,12 +94,15 @@ const char IDBDatabase::kTransactionReadOnlyErrorMessage[] = const char IDBDatabase::kDatabaseClosedErrorMessage[] = "The database connection is closed."; -IDBDatabase::IDBDatabase(ExecutionContext* context, - std::unique_ptr<WebIDBDatabase> backend, - IDBDatabaseCallbacks* callbacks, - v8::Isolate* isolate) - : ContextLifecycleObserver(context), +IDBDatabase::IDBDatabase( + ExecutionContext* context, + std::unique_ptr<WebIDBDatabase> backend, + IDBDatabaseCallbacks* callbacks, + v8::Isolate* isolate, + mojo::PendingRemote<mojom::blink::ObservedFeature> connection_lifetime) + : ExecutionContextLifecycleObserver(context), backend_(std::move(backend)), + connection_lifetime_(std::move(connection_lifetime)), event_queue_( MakeGarbageCollected<EventQueue>(context, TaskType::kDatabaseAccess)), database_callbacks_(callbacks), @@ -117,14 +121,14 @@ IDBDatabase::~IDBDatabase() { backend_->Close(); } -void IDBDatabase::Trace(blink::Visitor* visitor) { +void IDBDatabase::Trace(Visitor* visitor) { visitor->Trace(version_change_transaction_); visitor->Trace(transactions_); visitor->Trace(observers_); visitor->Trace(event_queue_); visitor->Trace(database_callbacks_); EventTargetWithInlineData::Trace(visitor); - ContextLifecycleObserver::Trace(visitor); + ExecutionContextLifecycleObserver::Trace(visitor); } int64_t IDBDatabase::NextTransactionId() { @@ -463,6 +467,7 @@ void IDBDatabase::close() { if (close_pending_) return; + connection_lifetime_.reset(); close_pending_ = true; feature_handle_for_scheduler_.reset(); @@ -521,11 +526,18 @@ void IDBDatabase::EnqueueEvent(Event* event) { DispatchEventResult IDBDatabase::DispatchEventInternal(Event& event) { IDB_TRACE("IDBDatabase::dispatchEvent"); - if (!GetExecutionContext()) - return DispatchEventResult::kCanceledBeforeDispatch; + + event.SetTarget(this); + + // If this event originated from script, it should have no side effects. + if (!event.isTrusted()) + return EventTarget::DispatchEventInternal(event); DCHECK(event.type() == event_type_names::kVersionchange || event.type() == event_type_names::kClose); + if (!GetExecutionContext()) + return DispatchEventResult::kCanceledBeforeDispatch; + DispatchEventResult dispatch_result = EventTarget::DispatchEventInternal(event); if (event.type() == event_type_names::kVersionchange && !close_pending_ && @@ -593,7 +605,7 @@ bool IDBDatabase::HasPendingActivity() const { return !close_pending_ && GetExecutionContext() && HasEventListeners(); } -void IDBDatabase::ContextDestroyed(ExecutionContext*) { +void IDBDatabase::ContextDestroyed() { // Immediately close the connection to the back end. Don't attempt a // normal close() since that may wait on transactions which require a // round trip to the back-end to abort. @@ -602,6 +614,8 @@ void IDBDatabase::ContextDestroyed(ExecutionContext*) { backend_.reset(); } + connection_lifetime_.reset(); + if (database_callbacks_) database_callbacks_->DetachWebCallbacks(); } @@ -611,7 +625,7 @@ const AtomicString& IDBDatabase::InterfaceName() const { } ExecutionContext* IDBDatabase::GetExecutionContext() const { - return ContextLifecycleObserver::GetExecutionContext(); + return ExecutionContextLifecycleObserver::GetExecutionContext(); } STATIC_ASSERT_ENUM(mojom::blink::IDBException::kNoError, diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_database.h b/chromium/third_party/blink/renderer/modules/indexeddb/idb_database.h index 74452627150..6eef002a162 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_database.h +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_database.h @@ -29,18 +29,19 @@ #include <memory> #include "base/memory/scoped_refptr.h" +#include "third_party/blink/public/mojom/feature_observer/feature_observer.mojom-blink.h" #include "third_party/blink/renderer/bindings/core/v8/active_script_wrappable.h" #include "third_party/blink/renderer/bindings/core/v8/string_or_string_sequence.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_idb_object_store_parameters.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_idb_transaction_options.h" #include "third_party/blink/renderer/core/dom/dom_string_list.h" -#include "third_party/blink/renderer/core/execution_context/context_lifecycle_observer.h" +#include "third_party/blink/renderer/core/execution_context/execution_context_lifecycle_observer.h" #include "third_party/blink/renderer/modules/event_modules.h" #include "third_party/blink/renderer/modules/event_target_modules.h" #include "third_party/blink/renderer/modules/indexeddb/idb_database_callbacks.h" #include "third_party/blink/renderer/modules/indexeddb/idb_metadata.h" #include "third_party/blink/renderer/modules/indexeddb/idb_object_store.h" -#include "third_party/blink/renderer/modules/indexeddb/idb_object_store_parameters.h" #include "third_party/blink/renderer/modules/indexeddb/idb_transaction.h" -#include "third_party/blink/renderer/modules/indexeddb/idb_transaction_options.h" #include "third_party/blink/renderer/modules/indexeddb/indexed_db.h" #include "third_party/blink/renderer/modules/indexeddb/web_idb_database.h" #include "third_party/blink/renderer/modules/indexeddb/web_idb_database_callbacks.h" @@ -60,18 +61,20 @@ class IDBObserver; class MODULES_EXPORT IDBDatabase final : public EventTargetWithInlineData, public ActiveScriptWrappable<IDBDatabase>, - public ContextLifecycleObserver { + public ExecutionContextLifecycleObserver { USING_GARBAGE_COLLECTED_MIXIN(IDBDatabase); DEFINE_WRAPPERTYPEINFO(); public: - IDBDatabase(ExecutionContext*, - std::unique_ptr<WebIDBDatabase>, - IDBDatabaseCallbacks*, - v8::Isolate*); + IDBDatabase( + ExecutionContext*, + std::unique_ptr<WebIDBDatabase>, + IDBDatabaseCallbacks*, + v8::Isolate*, + mojo::PendingRemote<mojom::blink::ObservedFeature> connection_lifetime); ~IDBDatabase() override; - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; // Overwrites the database metadata, including object store and index // metadata. Used to pass metadata to the database when it is opened. @@ -130,8 +133,8 @@ class MODULES_EXPORT IDBDatabase final // ScriptWrappable bool HasPendingActivity() const final; - // ContextLifecycleObserver - void ContextDestroyed(ExecutionContext*) override; + // ExecutionContextLifecycleObserver + void ContextDestroyed() override; // EventTarget const AtomicString& InterfaceName() const override; @@ -192,6 +195,9 @@ class MODULES_EXPORT IDBDatabase final Member<IDBTransaction> version_change_transaction_; HeapHashMap<int64_t, Member<IDBTransaction>> transactions_; HeapHashMap<int32_t, Member<IDBObserver>> observers_; + // No interface here, so no need to bind it. This is only for + // lifetime observation of the use of IndexedDB from the browser. + mojo::PendingRemote<mojom::blink::ObservedFeature> connection_lifetime_; bool close_pending_ = false; diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_database.idl b/chromium/third_party/blink/renderer/modules/indexeddb/idb_database.idl index 938b6b4fae9..2b5273199f9 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_database.idl +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_database.idl @@ -24,7 +24,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -// https://w3c.github.io/IndexedDB/#idl-def-IDBDatabase +// https://w3c.github.io/IndexedDB/#database-interface [ ActiveScriptWrappable, @@ -45,7 +45,7 @@ [MeasureAs=IndexedDBWrite, NewObject, RaisesException] IDBObjectStore createObjectStore(DOMString name, - optional IDBObjectStoreParameters options); + optional IDBObjectStoreParameters options = {}); [MeasureAs=IndexedDBWrite, RaisesException] void deleteObjectStore(DOMString name); diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_database_callbacks.cc b/chromium/third_party/blink/renderer/modules/indexeddb/idb_database_callbacks.cc index cf324f4fac5..14e8037e5a2 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_database_callbacks.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_database_callbacks.cc @@ -34,7 +34,7 @@ IDBDatabaseCallbacks::IDBDatabaseCallbacks() : database_(nullptr) {} IDBDatabaseCallbacks::~IDBDatabaseCallbacks() = default; -void IDBDatabaseCallbacks::Trace(blink::Visitor* visitor) { +void IDBDatabaseCallbacks::Trace(Visitor* visitor) { visitor->Trace(database_); } diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_database_callbacks.h b/chromium/third_party/blink/renderer/modules/indexeddb/idb_database_callbacks.h index 7591e448bf9..76c09201024 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_database_callbacks.h +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_database_callbacks.h @@ -41,7 +41,7 @@ class MODULES_EXPORT IDBDatabaseCallbacks public: IDBDatabaseCallbacks(); virtual ~IDBDatabaseCallbacks(); - void Trace(blink::Visitor*); + void Trace(Visitor*); // IDBDatabaseCallbacks virtual void OnForcedClose(); diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_factory.cc b/chromium/third_party/blink/renderer/modules/indexeddb/idb_factory.cc index c7b06b4c851..46c5b343293 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_factory.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_factory.cc @@ -33,15 +33,15 @@ #include "mojo/public/cpp/bindings/pending_associated_receiver.h" #include "mojo/public/cpp/bindings/pending_associated_remote.h" -#include "services/service_manager/public/cpp/interface_provider.h" +#include "third_party/blink/public/mojom/feature_observer/feature_observer.mojom-blink.h" #include "third_party/blink/public/mojom/indexeddb/indexeddb.mojom-blink.h" -#include "third_party/blink/public/platform/interface_provider.h" #include "third_party/blink/public/platform/platform.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/modules/v8/v8_binding_for_modules.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_idb_database_info.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/execution_context/execution_context.h" @@ -51,7 +51,6 @@ #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_callbacks.h" -#include "third_party/blink/renderer/modules/indexeddb/idb_database_info.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_tracing.h" @@ -205,8 +204,8 @@ IDBFactory::IDBFactory(std::unique_ptr<WebIDBFactory> web_idb_factory) : web_idb_factory_(std::move(web_idb_factory)) {} static bool IsContextValid(ExecutionContext* context) { - DCHECK(IsA<Document>(context) || context->IsWorkerGlobalScope()); - if (auto* document = DynamicTo<Document>(context)) + DCHECK(context->IsDocument() || context->IsWorkerGlobalScope()); + if (auto* document = Document::DynamicFrom(context)) return document->GetFrame() && document->GetPage(); return true; } @@ -216,8 +215,13 @@ WebIDBFactory* IDBFactory::GetFactory(ExecutionContext* execution_context) { mojo::PendingRemote<mojom::blink::IDBFactory> web_idb_factory_host_remote; execution_context->GetBrowserInterfaceBroker().GetInterface( web_idb_factory_host_remote.InitWithNewPipeAndPassReceiver()); + + mojo::PendingRemote<mojom::blink::FeatureObserver> feature_observer; + execution_context->GetBrowserInterfaceBroker().GetInterface( + feature_observer.InitWithNewPipeAndPassReceiver()); + web_idb_factory_ = std::make_unique<WebIDBFactoryImpl>( - std::move(web_idb_factory_host_remote), + std::move(web_idb_factory_host_remote), std::move(feature_observer), execution_context->GetTaskRunner(TaskType::kDatabaseAccess)); } return web_idb_factory_.get(); @@ -340,6 +344,13 @@ IDBOpenDBRequest* IDBFactory::OpenInternal(ScriptState* script_state, auto* database_callbacks = MakeGarbageCollected<IDBDatabaseCallbacks>(); int64_t transaction_id = IDBDatabase::NextTransactionId(); + ExecutionContext* execution_context = ExecutionContext::From(script_state); + WebIDBFactory* factory = GetFactory(execution_context); + if (!factory) { + exception_state.ThrowSecurityError("An internal error occurred."); + return nullptr; + } + auto transaction_backend = std::make_unique<WebIDBTransactionImpl>( ExecutionContext::From(script_state) ->GetTaskRunner(TaskType::kDatabaseAccess), @@ -348,7 +359,8 @@ IDBOpenDBRequest* IDBFactory::OpenInternal(ScriptState* script_state, transaction_receiver = transaction_backend->CreateReceiver(); auto* request = MakeGarbageCollected<IDBOpenDBRequest>( script_state, database_callbacks, std::move(transaction_backend), - transaction_id, version, std::move(metrics)); + transaction_id, version, std::move(metrics), + factory->GetObservedFeature()); if (!CachedAllowIndexedDB(script_state)) { request->HandleResponse(MakeGarbageCollected<DOMException>( @@ -356,12 +368,6 @@ IDBOpenDBRequest* IDBFactory::OpenInternal(ScriptState* script_state, return request; } - ExecutionContext* execution_context = ExecutionContext::From(script_state); - WebIDBFactory* factory = GetFactory(execution_context); - if (!factory) { - exception_state.ThrowSecurityError("An internal error occurred."); - return nullptr; - } factory->Open(name, version, std::move(transaction_receiver), transaction_id, request->CreateWebCallbacks(), database_callbacks->CreateWebCallbacks()); @@ -413,9 +419,17 @@ IDBOpenDBRequest* IDBFactory::DeleteDatabaseInternal( WebFeature::kFileAccessedDatabase); } + ExecutionContext* execution_context = ExecutionContext::From(script_state); + WebIDBFactory* factory = GetFactory(execution_context); + if (!factory) { + exception_state.ThrowSecurityError("An internal error occurred."); + return nullptr; + } + auto* request = MakeGarbageCollected<IDBOpenDBRequest>( script_state, nullptr, /*IDBTransactionAssociatedPtr=*/nullptr, 0, - IDBDatabaseMetadata::kDefaultVersion, std::move(metrics)); + IDBDatabaseMetadata::kDefaultVersion, std::move(metrics), + factory->GetObservedFeature()); if (!CachedAllowIndexedDB(script_state)) { request->HandleResponse(MakeGarbageCollected<DOMException>( @@ -423,12 +437,6 @@ IDBOpenDBRequest* IDBFactory::DeleteDatabaseInternal( return request; } - ExecutionContext* execution_context = ExecutionContext::From(script_state); - WebIDBFactory* factory = GetFactory(execution_context); - if (!factory) { - exception_state.ThrowSecurityError("An internal error occurred."); - return nullptr; - } factory->DeleteDatabase(name, request->CreateWebCallbacks(), force_close); return request; } @@ -469,7 +477,7 @@ bool IDBFactory::AllowIndexedDB(ScriptState* script_state) { DCHECK(execution_context->IsContextThread()); SECURITY_DCHECK(execution_context->IsDocument() || execution_context->IsWorkerGlobalScope()); - if (auto* document = DynamicTo<Document>(execution_context)) { + if (auto* document = Document::DynamicFrom(execution_context)) { LocalFrame* frame = document->GetFrame(); if (!frame) return false; diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_index.cc b/chromium/third_party/blink/renderer/modules/indexeddb/idb_index.cc index dce0cab4d1e..a17ecbae88c 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_index.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_index.cc @@ -55,7 +55,7 @@ IDBIndex::IDBIndex(scoped_refptr<IDBIndexMetadata> metadata, IDBIndex::~IDBIndex() = default; -void IDBIndex::Trace(blink::Visitor* visitor) { +void IDBIndex::Trace(Visitor* visitor) { visitor->Trace(object_store_); visitor->Trace(transaction_); ScriptWrappable::Trace(visitor); diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_index.h b/chromium/third_party/blink/renderer/modules/indexeddb/idb_index.h index 0d628fc767c..8bb99e9366f 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_index.h +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_index.h @@ -51,7 +51,7 @@ class IDBIndex final : public ScriptWrappable { IDBIndex(scoped_refptr<IDBIndexMetadata>, IDBObjectStore*, IDBTransaction*); ~IDBIndex() override; - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; // Implement the IDL const String& name() const { return Metadata().name; } diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_index.idl b/chromium/third_party/blink/renderer/modules/indexeddb/idb_index.idl index ebd480e4003..e644cdb658d 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_index.idl +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_index.idl @@ -36,14 +36,14 @@ [NewObject, CallWith=ScriptState, RaisesException] IDBRequest get(any key); [NewObject, CallWith=ScriptState, RaisesException] IDBRequest getKey(any key); - [NewObject, CallWith=ScriptState, RaisesException] IDBRequest getAll([DefaultValue=Undefined] optional any query, + [NewObject, CallWith=ScriptState, RaisesException] IDBRequest getAll(optional any query = null, optional [EnforceRange] unsigned long count); - [NewObject, CallWith=ScriptState, RaisesException] IDBRequest getAllKeys([DefaultValue=Undefined] optional any query, + [NewObject, CallWith=ScriptState, RaisesException] IDBRequest getAllKeys(optional any query = null, optional [EnforceRange] unsigned long count); - [NewObject, CallWith=ScriptState, RaisesException] IDBRequest count([DefaultValue=Undefined] optional any key); + [NewObject, CallWith=ScriptState, RaisesException] IDBRequest count(optional any key = null); - [NewObject, CallWith=ScriptState, RaisesException] IDBRequest openCursor([DefaultValue=Undefined] optional any range, + [NewObject, CallWith=ScriptState, RaisesException] IDBRequest openCursor(optional any range = null, optional IDBCursorDirection direction = "next"); - [NewObject, CallWith=ScriptState, RaisesException] IDBRequest openKeyCursor([DefaultValue=Undefined] optional any range, + [NewObject, CallWith=ScriptState, RaisesException] IDBRequest openKeyCursor(optional any range = null, optional IDBCursorDirection direction = "next"); }; diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_key_range.h b/chromium/third_party/blink/renderer/modules/indexeddb/idb_key_range.h index 80fb9535737..55311ab0e86 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_key_range.h +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_key_range.h @@ -76,9 +76,7 @@ class MODULES_EXPORT IDBKeyRange final : public ScriptWrappable { const ScriptValue&, ExceptionState&); - void Trace(blink::Visitor* visitor) override { - ScriptWrappable::Trace(visitor); - } + void Trace(Visitor* visitor) override { ScriptWrappable::Trace(visitor); } // Implement the IDBKeyRange IDL IDBKey* Lower() const { return lower_.get(); } diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_object_store.cc b/chromium/third_party/blink/renderer/modules/indexeddb/idb_object_store.cc index 460ba8896ce..471ac159cef 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_object_store.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_object_store.cc @@ -28,7 +28,9 @@ #include <memory> #include "base/feature_list.h" +#include "base/memory/ptr_util.h" #include "base/memory/scoped_refptr.h" +#include "base/metrics/histogram_macros.h" #include "base/numerics/safe_conversions.h" #include "third_party/blink/public/platform/web_blob_info.h" #include "third_party/blink/renderer/bindings/core/v8/serialization/serialized_script_value_factory.h" @@ -48,7 +50,6 @@ #include "third_party/blink/renderer/modules/indexeddb/web_idb_database.h" #include "third_party/blink/renderer/platform/bindings/exception_state.h" #include "third_party/blink/renderer/platform/bindings/script_state.h" -#include "third_party/blink/renderer/platform/instrumentation/histogram.h" #include "third_party/blink/renderer/platform/wtf/shared_buffer.h" #include "v8/include/v8.h" @@ -61,7 +62,7 @@ IDBObjectStore::IDBObjectStore(scoped_refptr<IDBObjectStoreMetadata> metadata, DCHECK(metadata_.get()); } -void IDBObjectStore::Trace(blink::Visitor* visitor) { +void IDBObjectStore::Trace(Visitor* visitor) { visitor->Trace(transaction_); visitor->Trace(index_map_); ScriptWrappable::Trace(visitor); @@ -339,6 +340,14 @@ static Vector<std::unique_ptr<IDBKey>> GenerateIndexKeysForValue( IDBRequest* IDBObjectStore::add(ScriptState* script_state, const ScriptValue& value, + ExceptionState& exception_state) { + v8::Isolate* isolate = script_state->GetIsolate(); + return add(script_state, value, ScriptValue(isolate, v8::Undefined(isolate)), + exception_state); +} + +IDBRequest* IDBObjectStore::add(ScriptState* script_state, + const ScriptValue& value, const ScriptValue& key, ExceptionState& exception_state) { IDB_TRACE1("IDBObjectStore::addRequestSetup", "store_name", @@ -349,6 +358,14 @@ IDBRequest* IDBObjectStore::add(ScriptState* script_state, IDBRequest* IDBObjectStore::put(ScriptState* script_state, const ScriptValue& value, + ExceptionState& exception_state) { + v8::Isolate* isolate = script_state->GetIsolate(); + return put(script_state, value, ScriptValue(isolate, v8::Undefined(isolate)), + exception_state); +} + +IDBRequest* IDBObjectStore::put(ScriptState* script_state, + const ScriptValue& value, const ScriptValue& key, ExceptionState& exception_state) { IDB_TRACE1("IDBObjectStore::putRequestSetup", "store_name", @@ -571,8 +588,9 @@ IDBRequest* IDBObjectStore::DoPut(ScriptState* script_state, if (base::FeatureList::IsEnabled(kIndexedDBLargeValueWrapping)) value_wrapper.WrapIfBiggerThan(IDBValueWrapper::kWrapThreshold); - auto idb_value = std::make_unique<IDBValue>(value_wrapper.TakeWireBytes(), - value_wrapper.TakeBlobInfo()); + auto idb_value = std::make_unique<IDBValue>( + value_wrapper.TakeWireBytes(), value_wrapper.TakeBlobInfo(), + value_wrapper.TakeNativeFileSystemTransferTokens()); request->transit_blob_handles() = value_wrapper.TakeBlobDataHandles(); transaction_->transaction_backend()->Put( @@ -708,7 +726,7 @@ class IndexPopulator final : public NativeEventListener { DCHECK(index_metadata_.get()); } - void Trace(blink::Visitor* visitor) override { + void Trace(Visitor* visitor) override { visitor->Trace(script_state_); visitor->Trace(database_); NativeEventListener::Trace(visitor); diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_object_store.h b/chromium/third_party/blink/renderer/modules/indexeddb/idb_object_store.h index c742dbdf8be..79819338c46 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_object_store.h +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_object_store.h @@ -29,9 +29,9 @@ #include "base/memory/scoped_refptr.h" #include "third_party/blink/public/common/indexeddb/web_idb_types.h" #include "third_party/blink/renderer/bindings/core/v8/serialization/serialized_script_value.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_idb_index_parameters.h" #include "third_party/blink/renderer/modules/indexeddb/idb_cursor.h" #include "third_party/blink/renderer/modules/indexeddb/idb_index.h" -#include "third_party/blink/renderer/modules/indexeddb/idb_index_parameters.h" #include "third_party/blink/renderer/modules/indexeddb/idb_key.h" #include "third_party/blink/renderer/modules/indexeddb/idb_key_range.h" #include "third_party/blink/renderer/modules/indexeddb/idb_metadata.h" @@ -54,7 +54,7 @@ class MODULES_EXPORT IDBObjectStore final : public ScriptWrappable { IDBObjectStore(scoped_refptr<IDBObjectStoreMetadata>, IDBTransaction*); ~IDBObjectStore() override = default; - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; const IDBObjectStoreMetadata& Metadata() const { return *metadata_; } const IDBKeyPath& IdbKeyPath() const { return Metadata().key_path; } @@ -96,12 +96,14 @@ class MODULES_EXPORT IDBObjectStore final : public ScriptWrappable { IDBRequest* getAllKeys(ScriptState*, const ScriptValue& range, ExceptionState&); + IDBRequest* add(ScriptState*, const ScriptValue& value, ExceptionState&); IDBRequest* add(ScriptState*, - const ScriptValue&, + const ScriptValue& value, const ScriptValue& key, ExceptionState&); + IDBRequest* put(ScriptState*, const ScriptValue& value, ExceptionState&); IDBRequest* put(ScriptState*, - const ScriptValue&, + const ScriptValue& value, const ScriptValue& key, ExceptionState&); IDBRequest* Delete(ScriptState*, const ScriptValue& key, ExceptionState&); diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_object_store.idl b/chromium/third_party/blink/renderer/modules/indexeddb/idb_object_store.idl index 3218ac74f71..c8b9a30009c 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_object_store.idl +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_object_store.idl @@ -23,7 +23,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -// https://w3c.github.io/IndexedDB/#idl-def-IDBObjectStore +// https://w3c.github.io/IndexedDB/#object-store-interface [ Exposed=(Window,Worker) @@ -35,10 +35,10 @@ readonly attribute boolean autoIncrement; [CallWith=ScriptState, MeasureAs=IndexedDBWrite, NewObject, RaisesException] - IDBRequest put(any value, [DefaultValue=Undefined] optional any key); + IDBRequest put(any value, optional any key); [CallWith=ScriptState, MeasureAs=IndexedDBWrite, NewObject, RaisesException] - IDBRequest add(any value, [DefaultValue=Undefined] optional any key); + IDBRequest add(any value, optional any key); [ CallWith=ScriptState, @@ -58,22 +58,22 @@ IDBRequest getKey(any key); [CallWith=ScriptState, MeasureAs=IndexedDBRead, NewObject, RaisesException] - IDBRequest getAll([DefaultValue=Undefined] optional any query, + IDBRequest getAll(optional any query = null, optional [EnforceRange] unsigned long count); [CallWith=ScriptState, MeasureAs=IndexedDBRead, NewObject, RaisesException] - IDBRequest getAllKeys([DefaultValue=Undefined] optional any query, + IDBRequest getAllKeys(optional any query = null, optional [EnforceRange] unsigned long count); [CallWith=ScriptState, MeasureAs=IndexedDBRead, NewObject, RaisesException] - IDBRequest count([DefaultValue=Undefined] optional any key); + IDBRequest count(optional any key = null); [CallWith=ScriptState, MeasureAs=IndexedDBRead, NewObject, RaisesException] - IDBRequest openCursor([DefaultValue=Undefined] optional any range, + IDBRequest openCursor(optional any range = null, optional IDBCursorDirection direction = "next"); [CallWith=ScriptState, MeasureAs=IndexedDBRead, NewObject, RaisesException] - IDBRequest openKeyCursor([DefaultValue=Undefined] optional any range, + IDBRequest openKeyCursor(optional any range = null, optional IDBCursorDirection direction = "next"); [MeasureAs=IndexedDBRead, RaisesException] IDBIndex index(DOMString name); @@ -81,7 +81,7 @@ [CallWith=ScriptState, MeasureAs=IndexedDBWrite, NewObject, RaisesException] IDBIndex createIndex(DOMString name, (DOMString or sequence<DOMString>) keyPath, - optional IDBIndexParameters options); + optional IDBIndexParameters options = {}); [MeasureAs=IndexedDBWrite, RaisesException] void deleteIndex(DOMString name); diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_observation.cc b/chromium/third_party/blink/renderer/modules/indexeddb/idb_observation.cc index 4b05d8b8e3b..923dc0f01c8 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_observation.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_observation.cc @@ -81,7 +81,7 @@ void IDBObservation::SetIsolate(v8::Isolate* isolate) { value_->Value()->SetIsolate(isolate); } -void IDBObservation::Trace(blink::Visitor* visitor) { +void IDBObservation::Trace(Visitor* visitor) { visitor->Trace(key_range_); visitor->Trace(value_); ScriptWrappable::Trace(visitor); diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_observation.h b/chromium/third_party/blink/renderer/modules/indexeddb/idb_observation.h index bc668d0ea16..11d3d59a04b 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_observation.h +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_observation.h @@ -32,7 +32,7 @@ class IDBObservation final : public ScriptWrappable { ~IDBObservation() override; void SetIsolate(v8::Isolate* isolate); - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; // Implement the IDL ScriptValue key(ScriptState*); diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_observer.cc b/chromium/third_party/blink/renderer/modules/indexeddb/idb_observer.cc index fb4c0617684..b4caa0796f3 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_observer.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_observer.cc @@ -9,10 +9,10 @@ #include "third_party/blink/renderer/bindings/modules/v8/to_v8_for_modules.h" #include "third_party/blink/renderer/bindings/modules/v8/v8_binding_for_modules.h" #include "third_party/blink/renderer/bindings/modules/v8/v8_idb_observer_callback.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_idb_observer_init.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_observer_changes.h" -#include "third_party/blink/renderer/modules/indexeddb/idb_observer_init.h" #include "third_party/blink/renderer/modules/indexeddb/idb_transaction.h" #include "third_party/blink/renderer/platform/bindings/exception_state.h" @@ -98,7 +98,7 @@ void IDBObserver::unobserve(IDBDatabase* database, database->RemoveObservers(observer_ids_to_remove); } -void IDBObserver::Trace(blink::Visitor* visitor) { +void IDBObserver::Trace(Visitor* visitor) { visitor->Trace(callback_); visitor->Trace(observer_ids_); ScriptWrappable::Trace(visitor); diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_observer.h b/chromium/third_party/blink/renderer/modules/indexeddb/idb_observer.h index 84133685682..6ac5fa3d26c 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_observer.h +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_observer.h @@ -36,7 +36,7 @@ class MODULES_EXPORT IDBObserver final : public ScriptWrappable { ExceptionState&); void unobserve(IDBDatabase*, ExceptionState&); - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; private: Member<V8IDBObserverCallback> callback_; diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_observer.idl b/chromium/third_party/blink/renderer/modules/indexeddb/idb_observer.idl index 258c4904246..a56142de3f6 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_observer.idl +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_observer.idl @@ -8,9 +8,9 @@ callback IDBObserverCallback = void (IDBObserverChanges changes); [ Exposed=(Window,Worker), - Constructor(IDBObserverCallback callback), RuntimeEnabled=IDBObserver ] interface IDBObserver { + constructor(IDBObserverCallback callback); [RaisesException, Measure] void observe(IDBDatabase db, IDBTransaction tx, IDBObserverInit options); [RaisesException, Measure] void unobserve(IDBDatabase db); }; diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_observer_changes.cc b/chromium/third_party/blink/renderer/modules/indexeddb/idb_observer_changes.cc index f8b1e48c15d..28c5ffe1c79 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_observer_changes.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_observer_changes.cc @@ -49,7 +49,7 @@ void IDBObserverChanges::ExtractChanges( } } -void IDBObserverChanges::Trace(blink::Visitor* visitor) { +void IDBObserverChanges::Trace(Visitor* visitor) { visitor->Trace(database_); visitor->Trace(transaction_); visitor->Trace(records_); diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_observer_changes.h b/chromium/third_party/blink/renderer/modules/indexeddb/idb_observer_changes.h index 874589dd8ff..d4c6ecd12fb 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_observer_changes.h +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_observer_changes.h @@ -25,7 +25,7 @@ class IDBObserverChanges final : public ScriptWrappable { const Vector<Persistent<IDBObservation>>& observations, const Vector<int32_t>& observation_indices); - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; // Implement IDL IDBTransaction* transaction() const { return transaction_.Get(); } diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_open_db_request.cc b/chromium/third_party/blink/renderer/modules/indexeddb/idb_open_db_request.cc index 8c3850c312d..8bae0d1d458 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_open_db_request.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_open_db_request.cc @@ -28,6 +28,7 @@ #include <memory> #include <utility> +#include "base/metrics/histogram_macros.h" #include "base/optional.h" #include "third_party/blink/renderer/bindings/modules/v8/idb_object_store_or_idb_index_or_idb_cursor.h" #include "third_party/blink/renderer/core/dom/dom_exception.h" @@ -37,7 +38,6 @@ #include "third_party/blink/renderer/modules/indexeddb/idb_tracing.h" #include "third_party/blink/renderer/modules/indexeddb/idb_version_change_event.h" #include "third_party/blink/renderer/platform/heap/heap.h" -#include "third_party/blink/renderer/platform/instrumentation/histogram.h" namespace blink { @@ -47,7 +47,8 @@ IDBOpenDBRequest::IDBOpenDBRequest( std::unique_ptr<WebIDBTransaction> transaction_backend, int64_t transaction_id, int64_t version, - IDBRequest::AsyncTraceState metrics) + IDBRequest::AsyncTraceState metrics, + mojo::PendingRemote<mojom::blink::ObservedFeature> connection_lifetime) : IDBRequest(script_state, IDBRequest::Source(), nullptr, @@ -56,19 +57,20 @@ IDBOpenDBRequest::IDBOpenDBRequest( transaction_backend_(std::move(transaction_backend)), transaction_id_(transaction_id), version_(version), + connection_lifetime_(std::move(connection_lifetime)), start_time_(base::Time::Now()) { DCHECK(!ResultAsAny()); } IDBOpenDBRequest::~IDBOpenDBRequest() = default; -void IDBOpenDBRequest::Trace(blink::Visitor* visitor) { +void IDBOpenDBRequest::Trace(Visitor* visitor) { visitor->Trace(database_callbacks_); IDBRequest::Trace(visitor); } -void IDBOpenDBRequest::ContextDestroyed(ExecutionContext* destroyed_context) { - IDBRequest::ContextDestroyed(destroyed_context); +void IDBOpenDBRequest::ContextDestroyed() { + IDBRequest::ContextDestroyed(); if (database_callbacks_) database_callbacks_->DetachWebCallbacks(); } @@ -105,7 +107,7 @@ void IDBOpenDBRequest::EnqueueUpgradeNeeded( auto* idb_database = MakeGarbageCollected<IDBDatabase>( GetExecutionContext(), std::move(backend), database_callbacks_.Release(), - isolate_); + isolate_, std::move(connection_lifetime_)); idb_database->SetMetadata(metadata); if (old_version == IDBDatabaseMetadata::kNoVersion) { @@ -148,7 +150,8 @@ void IDBOpenDBRequest::EnqueueResponse(std::unique_ptr<WebIDBDatabase> backend, DCHECK(database_callbacks_); idb_database = MakeGarbageCollected<IDBDatabase>( GetExecutionContext(), std::move(backend), - database_callbacks_.Release(), isolate_); + database_callbacks_.Release(), isolate_, + std::move(connection_lifetime_)); SetResult(MakeGarbageCollected<IDBAny>(idb_database)); } idb_database->SetMetadata(metadata); @@ -165,7 +168,7 @@ void IDBOpenDBRequest::EnqueueResponse(int64_t old_version) { // This database hasn't had an integer version before. old_version = IDBDatabaseMetadata::kDefaultVersion; } - SetResult(IDBAny::CreateUndefined()); + SetResult(MakeGarbageCollected<IDBAny>(IDBAny::kUndefinedType)); EnqueueEvent(MakeGarbageCollected<IDBVersionChangeEvent>( event_type_names::kSuccess, old_version, base::nullopt)); } @@ -180,6 +183,15 @@ bool IDBOpenDBRequest::ShouldEnqueueEvent() const { } DispatchEventResult IDBOpenDBRequest::DispatchEventInternal(Event& event) { + // If this event originated from script, it should have no side effects. + if (!event.isTrusted()) + return IDBRequest::DispatchEventInternal(event); + DCHECK(event.type() == event_type_names::kSuccess || + event.type() == event_type_names::kError || + event.type() == event_type_names::kBlocked || + event.type() == event_type_names::kUpgradeneeded) + << "event type was " << event.type(); + // If the connection closed between onUpgradeNeeded and the delivery of the // "success" event, an "error" event should be fired instead. if (event.type() == event_type_names::kSuccess && diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_open_db_request.h b/chromium/third_party/blink/renderer/modules/indexeddb/idb_open_db_request.h index 5266f1dc833..45282c00a41 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_open_db_request.h +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_open_db_request.h @@ -28,6 +28,7 @@ #include <memory> +#include "third_party/blink/public/mojom/feature_observer/feature_observer.mojom-blink.h" #include "third_party/blink/renderer/modules/indexeddb/idb_request.h" #include "third_party/blink/renderer/modules/indexeddb/web_idb_database.h" #include "third_party/blink/renderer/modules/modules_export.h" @@ -40,15 +41,17 @@ class MODULES_EXPORT IDBOpenDBRequest final : public IDBRequest { DEFINE_WRAPPERTYPEINFO(); public: - IDBOpenDBRequest(ScriptState*, - IDBDatabaseCallbacks*, - std::unique_ptr<WebIDBTransaction> transaction_backend, - int64_t transaction_id, - int64_t version, - IDBRequest::AsyncTraceState metrics); + IDBOpenDBRequest( + ScriptState*, + IDBDatabaseCallbacks*, + std::unique_ptr<WebIDBTransaction> transaction_backend, + int64_t transaction_id, + int64_t version, + IDBRequest::AsyncTraceState metrics, + mojo::PendingRemote<mojom::blink::ObservedFeature> connection_lifetime); ~IDBOpenDBRequest() override; - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; void EnqueueBlocked(int64_t existing_version) override; void EnqueueUpgradeNeeded(int64_t old_version, @@ -59,8 +62,8 @@ class MODULES_EXPORT IDBOpenDBRequest final : public IDBRequest { void EnqueueResponse(std::unique_ptr<WebIDBDatabase>, const IDBDatabaseMetadata&) override; - // ContextLifecycleObserver - void ContextDestroyed(ExecutionContext*) final; + // ExecutionContextLifecycleObserver + void ContextDestroyed() final; // EventTarget const AtomicString& InterfaceName() const override; @@ -82,6 +85,9 @@ class MODULES_EXPORT IDBOpenDBRequest final : public IDBRequest { const int64_t transaction_id_; int64_t version_; + // Passed to the IDBDatabase when created. + mojo::PendingRemote<mojom::blink::ObservedFeature> connection_lifetime_; + base::Time start_time_; bool open_time_recorded_ = false; }; diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_request.cc b/chromium/third_party/blink/renderer/modules/indexeddb/idb_request.cc index a0f2288d1e1..96b9daef25a 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_request.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_request.cc @@ -62,21 +62,25 @@ IDBRequest::AsyncTraceState::AsyncTraceState(const char* trace_event_name) // If PopulateForNewEvent is called, it sets trace_event_name_ to // trace_event_name. Otherwise, trace_event_name_ is nullptr, so this instance // is considered empty. This roundabout initialization lets us avoid calling - // TRACE_EVENT_ASYNC_END0 with an uninitalized ID. - TRACE_EVENT_ASYNC_BEGIN0("IndexedDB", trace_event_name, - PopulateForNewEvent(trace_event_name)); + // TRACE_EVENT_NESTABLE_ASYNC_END0 with an uninitalized ID. + TRACE_EVENT_NESTABLE_ASYNC_BEGIN0( + "IndexedDB", trace_event_name, + TRACE_ID_LOCAL(PopulateForNewEvent(trace_event_name))); } void IDBRequest::AsyncTraceState::RecordAndReset() { if (trace_event_name_) { - TRACE_EVENT_ASYNC_END0("IndexedDB", trace_event_name_, id_); + TRACE_EVENT_NESTABLE_ASYNC_END0("IndexedDB", trace_event_name_, + TRACE_ID_LOCAL(id_)); trace_event_name_ = nullptr; } } IDBRequest::AsyncTraceState::~AsyncTraceState() { - if (trace_event_name_) - TRACE_EVENT_ASYNC_END0("IndexedDB", trace_event_name_, id_); + if (trace_event_name_) { + TRACE_EVENT_NESTABLE_ASYNC_END0("IndexedDB", trace_event_name_, + TRACE_ID_LOCAL(id_)); + } } size_t IDBRequest::AsyncTraceState::PopulateForNewEvent( @@ -131,7 +135,7 @@ IDBRequest::IDBRequest(ScriptState* script_state, const Source& source, IDBTransaction* transaction, AsyncTraceState metrics) - : ContextLifecycleObserver(ExecutionContext::From(script_state)), + : ExecutionContextLifecycleObserver(ExecutionContext::From(script_state)), transaction_(transaction), isolate_(script_state->GetIsolate()), metrics_(std::move(metrics)), @@ -145,7 +149,7 @@ IDBRequest::~IDBRequest() { ready_state_ == kEarlyDeath || !GetExecutionContext()); } -void IDBRequest::Trace(blink::Visitor* visitor) { +void IDBRequest::Trace(Visitor* visitor) { visitor->Trace(transaction_); visitor->Trace(source_); visitor->Trace(result_); @@ -153,7 +157,7 @@ void IDBRequest::Trace(blink::Visitor* visitor) { visitor->Trace(event_queue_); visitor->Trace(pending_cursor_); EventTargetWithInlineData::Trace(visitor); - ContextLifecycleObserver::Trace(visitor); + ExecutionContextLifecycleObserver::Trace(visitor); } ScriptValue IDBRequest::result(ScriptState* script_state, @@ -413,7 +417,7 @@ void IDBRequest::EnqueueResponse(DOMException* error) { } error_ = error; - SetResult(IDBAny::CreateUndefined()); + SetResult(MakeGarbageCollected<IDBAny>(IDBAny::kUndefinedType)); pending_cursor_.Clear(); EnqueueEvent(Event::CreateCancelableBubble(event_type_names::kError)); } @@ -482,7 +486,7 @@ void IDBRequest::EnqueueResponse(std::unique_ptr<IDBKey> idb_key) { if (idb_key && idb_key->IsValid()) EnqueueResultInternal(MakeGarbageCollected<IDBAny>(std::move(idb_key))); else - EnqueueResultInternal(IDBAny::CreateUndefined()); + EnqueueResultInternal(MakeGarbageCollected<IDBAny>(IDBAny::kUndefinedType)); } namespace { @@ -556,7 +560,7 @@ void IDBRequest::EnqueueResponse() { metrics_.RecordAndReset(); return; } - EnqueueResultInternal(IDBAny::CreateUndefined()); + EnqueueResultInternal(MakeGarbageCollected<IDBAny>(IDBAny::kUndefinedType)); } void IDBRequest::EnqueueResultInternal(IDBAny* result) { @@ -594,7 +598,7 @@ bool IDBRequest::HasPendingActivity() const { return has_pending_activity_ && GetExecutionContext(); } -void IDBRequest::ContextDestroyed(ExecutionContext*) { +void IDBRequest::ContextDestroyed() { if (ready_state_ == PENDING) { ready_state_ = kEarlyDeath; if (queue_item_) @@ -620,31 +624,43 @@ const AtomicString& IDBRequest::InterfaceName() const { } ExecutionContext* IDBRequest::GetExecutionContext() const { - return ContextLifecycleObserver::GetExecutionContext(); + return ExecutionContextLifecycleObserver::GetExecutionContext(); } DispatchEventResult IDBRequest::DispatchEventInternal(Event& event) { IDB_TRACE("IDBRequest::dispatchEvent"); - if (!GetExecutionContext()) - return DispatchEventResult::kCanceledBeforeDispatch; - DCHECK_EQ(ready_state_, PENDING); - DCHECK(has_pending_activity_); - DCHECK_EQ(event.target(), this); - if (event.type() != event_type_names::kBlocked) - ready_state_ = DONE; + event.SetTarget(this); HeapVector<Member<EventTarget>> targets; targets.push_back(this); if (transaction_ && !prevent_propagation_) { + // Per spec: "A request's get the parent algorithm returns the request’s + // transaction." targets.push_back(transaction_); - // If there ever are events that are associated with a database but - // that do not have a transaction, then this will not work and we need - // this object to actually hold a reference to the database (to ensure - // it stays alive). + // Per spec: "A transaction's get the parent algorithm returns the + // transaction’s connection." targets.push_back(transaction_->db()); } + // If this event originated from script, it should have no side effects. + if (!event.isTrusted()) + return IDBEventDispatcher::Dispatch(event, targets); + DCHECK(event.type() == event_type_names::kSuccess || + event.type() == event_type_names::kError || + event.type() == event_type_names::kBlocked || + event.type() == event_type_names::kUpgradeneeded) + << "event type was " << event.type(); + + if (!GetExecutionContext()) + return DispatchEventResult::kCanceledBeforeDispatch; + DCHECK_EQ(ready_state_, PENDING); + DCHECK(has_pending_activity_); + DCHECK_EQ(event.target(), this); + + if (event.type() != event_type_names::kBlocked) + ready_state_ = DONE; + // Cursor properties should not be updated until the success event is being // dispatched. IDBCursor* cursor_to_notify = nullptr; @@ -662,13 +678,6 @@ DispatchEventResult IDBRequest::DispatchEventInternal(Event& event) { did_fire_upgrade_needed_event_ = true; } - // FIXME: When we allow custom event dispatching, this will probably need to - // change. - DCHECK(event.type() == event_type_names::kSuccess || - event.type() == event_type_names::kError || - event.type() == event_type_names::kBlocked || - event.type() == event_type_names::kUpgradeneeded) - << "event type was " << event.type(); const bool set_transaction_active = transaction_ && (event.type() == event_type_names::kSuccess || @@ -692,7 +701,6 @@ DispatchEventResult IDBRequest::DispatchEventInternal(Event& event) { // has completed. metrics_.RecordAndReset(); - event.SetTarget(this); DispatchEventResult dispatch_result = IDBEventDispatcher::Dispatch(event, targets); diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_request.h b/chromium/third_party/blink/renderer/modules/indexeddb/idb_request.h index 48a337ead33..ed3bf8e446c 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_request.h +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_request.h @@ -44,7 +44,7 @@ #include "third_party/blink/renderer/core/dom/events/event_listener.h" #include "third_party/blink/renderer/core/dom/events/event_queue.h" #include "third_party/blink/renderer/core/dom/events/event_target.h" -#include "third_party/blink/renderer/core/execution_context/context_lifecycle_observer.h" +#include "third_party/blink/renderer/core/execution_context/execution_context_lifecycle_observer.h" #include "third_party/blink/renderer/modules/event_modules.h" #include "third_party/blink/renderer/modules/indexeddb/idb_any.h" #include "third_party/blink/renderer/modules/indexeddb/idb_transaction.h" @@ -66,7 +66,7 @@ class IDBValue; class MODULES_EXPORT IDBRequest : public EventTargetWithInlineData, public ActiveScriptWrappable<IDBRequest>, - public ContextLifecycleObserver { + public ExecutionContextLifecycleObserver { DEFINE_WRAPPERTYPEINFO(); USING_GARBAGE_COLLECTED_MIXIN(IDBRequest); @@ -74,20 +74,21 @@ class MODULES_EXPORT IDBRequest : public EventTargetWithInlineData, using Source = IDBObjectStoreOrIDBIndexOrIDBCursor; // Container for async tracing state. // - // The documentation for TRACE_EVENT_ASYNC_{BEGIN,END} suggests identifying - // trace events by using pointers or a counter that is always incremented on - // the same thread. This is not viable for IndexedDB, because the same object - // can result in multiple trace events (requests associated with cursors), and - // IndexedDB can be used from multiple threads in the same renderer (workers). - // Furthermore, we want to record the beginning event of an async trace right - // when we start serving an IDB API call, before the IDBRequest object is - // created, so we can't rely on information in an IDBRequest. + // The documentation for TRACE_EVENT_NESTABLE_ASYNC_{BEGIN,END} suggests + // identifying trace events by using pointers or a counter that is always + // incremented on the same thread. This is not viable for IndexedDB, because + // the same object can result in multiple trace events (requests associated + // with cursors), and IndexedDB can be used from multiple threads in the same + // renderer (workers). Furthermore, we want to record the beginning event of + // an async trace right when we start serving an IDB API call, before the + // IDBRequest object is created, so we can't rely on information in an + // IDBRequest. // // This class solves the ID uniqueness problem by relying on an atomic counter // to generating unique IDs in a threadsafe manner. The atomic machinery is // used when tracing is enabled. The recording problem is solved by having // instances of this class store the information needed to record async trace - // end events (via TRACE_EVENT_ASYNC_END). + // end events (via TRACE_EVENT_NESTABLE_ASYNC_END). // // From a mechanical perspective, creating an AsyncTraceState instance records // the beginning event of an async trace. The instance is then moved into an @@ -179,7 +180,7 @@ class MODULES_EXPORT IDBRequest : public EventTargetWithInlineData, IDBRequest(ScriptState*, const Source&, IDBTransaction*, AsyncTraceState); ~IDBRequest() override; - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; v8::Isolate* GetIsolate() const { return isolate_; } ScriptValue result(ScriptState*, ExceptionState&); @@ -291,8 +292,8 @@ class MODULES_EXPORT IDBRequest : public EventTargetWithInlineData, // ScriptWrappable bool HasPendingActivity() const final; - // ContextLifecycleObserver - void ContextDestroyed(ExecutionContext*) override; + // ExecutionContextLifecycleObserver + void ContextDestroyed() override; // EventTarget const AtomicString& InterfaceName() const override; diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_request_loader.cc b/chromium/third_party/blink/renderer/modules/indexeddb/idb_request_loader.cc index fced38c2ed5..1eadb10238c 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_request_loader.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_request_loader.cc @@ -4,6 +4,7 @@ #include "third_party/blink/renderer/modules/indexeddb/idb_request_loader.h" +#include "base/metrics/histogram_functions.h" #include "third_party/blink/public/platform/task_type.h" #include "third_party/blink/renderer/core/dom/dom_exception.h" #include "third_party/blink/renderer/core/execution_context/execution_context.h" @@ -13,7 +14,6 @@ #include "third_party/blink/renderer/modules/indexeddb/idb_value.h" #include "third_party/blink/renderer/modules/indexeddb/idb_value_wrapping.h" #include "third_party/blink/renderer/platform/heap/heap.h" -#include "third_party/blink/renderer/platform/instrumentation/histogram.h" #include "third_party/blink/renderer/platform/scheduler/public/thread_scheduler.h" #include "third_party/blink/renderer/platform/wtf/std_lib_extras.h" @@ -129,11 +129,8 @@ void IDBRequestLoader::DidFail(FileErrorCode) { file_reader_loading_ = false; #endif // DCHECK_IS_ON() - DEFINE_THREAD_SAFE_STATIC_LOCAL(SparseHistogram, - idb_request_loader_read_errors_histogram, - ("Storage.Blob.IDBRequestLoader.ReadError")); - idb_request_loader_read_errors_histogram.Sample( - std::max(0, -loader_->GetNetError())); + base::UmaHistogramSparse("Storage.Blob.IDBRequestLoader.ReadError", + std::max(0, -loader_->GetNetError())); ReportError(); } diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_request_test.cc b/chromium/third_party/blink/renderer/modules/indexeddb/idb_request_test.cc index f5cfb941f37..e4c632f56cc 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_request_test.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_request_test.cc @@ -192,7 +192,8 @@ class IDBRequestTest : public testing::Test { std::unique_ptr<MockWebIDBTransaction> transaction_backend) { db_ = MakeGarbageCollected<IDBDatabase>( scope.GetExecutionContext(), std::move(database_backend), - MakeGarbageCollected<IDBDatabaseCallbacks>(), scope.GetIsolate()); + MakeGarbageCollected<IDBDatabaseCallbacks>(), scope.GetIsolate(), + mojo::NullRemote()); HashSet<String> transaction_scope = {"store"}; transaction_ = IDBTransaction::CreateNonVersionChange( @@ -319,7 +320,17 @@ TEST_F(IDBRequestTest, EventsAfterEarlyDeathStopWithQueuedResult) { EnsureIDBCallbacksDontThrow(request, scope.GetExceptionState()); } -TEST_F(IDBRequestTest, EventsAfterEarlyDeathStopWithTwoQueuedResults) { +// This test is flaky on Marshmallow 64 bit Tester because the test is +// crashing. See <http://crbug.com/1068057>. +#if defined(OS_ANDROID) +#define MAYBE_EventsAfterEarlyDeathStopWithTwoQueuedResults \ + DISABLED_EventsAfterEarlyDeathStopWithTwoQueuedResults +#else +#define MAYBE_EventsAfterEarlyDeathStopWithTwoQueuedResults \ + EventsAfterEarlyDeathStopWithTwoQueuedResults +#endif + +TEST_F(IDBRequestTest, MAYBE_EventsAfterEarlyDeathStopWithTwoQueuedResults) { V8TestingScope scope; const int64_t kTransactionId = 1234; auto database_backend = std::make_unique<MockWebIDBDatabase>(); @@ -356,7 +367,17 @@ TEST_F(IDBRequestTest, EventsAfterEarlyDeathStopWithTwoQueuedResults) { EnsureIDBCallbacksDontThrow(request2, scope.GetExceptionState()); } -TEST_F(IDBRequestTest, AbortErrorAfterAbort) { +// This test is flaky on Marshmallow 64 bit Tester because the test is +// crashing. See <http://crbug.com/1068057>. +#if defined(OS_ANDROID) +#define MAYBE_AbortErrorAfterAbort \ + DISABLED_AbortErrorAfterAbort +#else +#define MAYBE_AbortErrorAfterAbort \ + AbortErrorAfterAbort +#endif + +TEST_F(IDBRequestTest, MAYBE_AbortErrorAfterAbort) { V8TestingScope scope; IDBTransaction* transaction = nullptr; IDBRequest* request = @@ -399,7 +420,8 @@ TEST_F(IDBRequestTest, ConnectionsAfterStopping) { kTransactionId); auto* request = MakeGarbageCollected<IDBOpenDBRequest>( scope.GetScriptState(), callbacks, std::move(transaction_backend), - kTransactionId, kVersion, IDBRequest::AsyncTraceState()); + kTransactionId, kVersion, IDBRequest::AsyncTraceState(), + mojo::NullRemote()); EXPECT_EQ(request->readyState(), "pending"); std::unique_ptr<WebIDBCallbacks> callbacks = request->CreateWebCallbacks(); @@ -421,7 +443,8 @@ TEST_F(IDBRequestTest, ConnectionsAfterStopping) { kTransactionId); auto* request = MakeGarbageCollected<IDBOpenDBRequest>( scope.GetScriptState(), callbacks, std::move(transaction_backend), - kTransactionId, kVersion, IDBRequest::AsyncTraceState()); + kTransactionId, kVersion, IDBRequest::AsyncTraceState(), + mojo::NullRemote()); EXPECT_EQ(request->readyState(), "pending"); std::unique_ptr<WebIDBCallbacks> callbacks = request->CreateWebCallbacks(); diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_transaction.cc b/chromium/third_party/blink/renderer/modules/indexeddb/idb_transaction.cc index 28bf2cc0c2b..8a6c2696438 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_transaction.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_transaction.cc @@ -82,7 +82,7 @@ IDBTransaction::IDBTransaction( mojom::IDBTransactionMode mode, mojom::IDBTransactionDurability durability, IDBDatabase* db) - : ContextLifecycleObserver(ExecutionContext::From(script_state)), + : ExecutionContextLifecycleObserver(ExecutionContext::From(script_state)), transaction_backend_(std::move(transaction_backend)), id_(id), database_(db), @@ -120,7 +120,7 @@ IDBTransaction::IDBTransaction( IDBDatabase* db, IDBOpenDBRequest* open_db_request, const IDBDatabaseMetadata& old_metadata) - : ContextLifecycleObserver(execution_context), + : ExecutionContextLifecycleObserver(execution_context), transaction_backend_(std::move(transaction_backend)), id_(id), database_(db), @@ -140,14 +140,14 @@ IDBTransaction::IDBTransaction( } IDBTransaction::~IDBTransaction() { - // Note: IDBTransaction is a ContextLifecycleObserver (rather than + // Note: IDBTransaction is a ExecutionContextLifecycleObserver (rather than // ContextClient) only in order to be able call upon GetExecutionContext() // during this destructor. DCHECK(state_ == kFinished || !GetExecutionContext()); DCHECK(request_list_.IsEmpty() || !GetExecutionContext()); } -void IDBTransaction::Trace(blink::Visitor* visitor) { +void IDBTransaction::Trace(Visitor* visitor) { visitor->Trace(database_); visitor->Trace(open_db_request_); visitor->Trace(error_); @@ -157,7 +157,7 @@ void IDBTransaction::Trace(blink::Visitor* visitor) { visitor->Trace(deleted_indexes_); visitor->Trace(event_queue_); EventTargetWithInlineData::Trace(visitor); - ContextLifecycleObserver::Trace(visitor); + ExecutionContextLifecycleObserver::Trace(visitor); } void IDBTransaction::SetError(DOMException* error) { @@ -543,7 +543,7 @@ const AtomicString& IDBTransaction::InterfaceName() const { } ExecutionContext* IDBTransaction::GetExecutionContext() const { - return ContextLifecycleObserver::GetExecutionContext(); + return ExecutionContextLifecycleObserver::GetExecutionContext(); } const char* IDBTransaction::InactiveErrorMessage() const { @@ -564,6 +564,21 @@ const char* IDBTransaction::InactiveErrorMessage() const { DispatchEventResult IDBTransaction::DispatchEventInternal(Event& event) { IDB_TRACE1("IDBTransaction::dispatchEvent", "txn.id", id_); + + event.SetTarget(this); + + // Per spec: "A transaction's get the parent algorithm returns the + // transaction’s connection." + HeapVector<Member<EventTarget>> targets; + targets.push_back(this); + targets.push_back(db()); + + // If this event originated from script, it should have no side effects. + if (!event.isTrusted()) + return IDBEventDispatcher::Dispatch(event, targets); + DCHECK(event.type() == event_type_names::kComplete || + event.type() == event_type_names::kAbort); + if (!GetExecutionContext()) { state_ = kFinished; return DispatchEventResult::kCanceledBeforeDispatch; @@ -574,14 +589,6 @@ DispatchEventResult IDBTransaction::DispatchEventInternal(Event& event) { DCHECK_EQ(event.target(), this); state_ = kFinished; - HeapVector<Member<EventTarget>> targets; - targets.push_back(this); - targets.push_back(db()); - - // FIXME: When we allow custom event dispatching, this will probably need to - // change. - DCHECK(event.type() == event_type_names::kComplete || - event.type() == event_type_names::kAbort); DispatchEventResult dispatch_result = IDBEventDispatcher::Dispatch(event, targets); // FIXME: Try to construct a test where |this| outlives openDBRequest and we diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_transaction.h b/chromium/third_party/blink/renderer/modules/indexeddb/idb_transaction.h index 108f9dfe58c..298c182f981 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_transaction.h +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_transaction.h @@ -33,7 +33,7 @@ #include "third_party/blink/renderer/bindings/core/v8/active_script_wrappable.h" #include "third_party/blink/renderer/core/dom/dom_string_list.h" #include "third_party/blink/renderer/core/dom/events/event_listener.h" -#include "third_party/blink/renderer/core/execution_context/context_lifecycle_observer.h" +#include "third_party/blink/renderer/core/execution_context/execution_context_lifecycle_observer.h" #include "third_party/blink/renderer/modules/event_modules.h" #include "third_party/blink/renderer/modules/event_target_modules.h" #include "third_party/blink/renderer/modules/indexeddb/idb_metadata.h" @@ -64,7 +64,7 @@ class ScriptState; class MODULES_EXPORT IDBTransaction final : public EventTargetWithInlineData, public ActiveScriptWrappable<IDBTransaction>, - public ContextLifecycleObserver { + public ExecutionContextLifecycleObserver { USING_GARBAGE_COLLECTED_MIXIN(IDBTransaction); DEFINE_WRAPPERTYPEINFO(); @@ -102,7 +102,7 @@ class MODULES_EXPORT IDBTransaction final const IDBDatabaseMetadata&); ~IDBTransaction() override; - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; static mojom::IDBTransactionMode StringToMode(const String&); @@ -195,6 +195,8 @@ class MODULES_EXPORT IDBTransaction final return transaction_backend_.get(); } + void ContextDestroyed() override {} + protected: // EventTarget DispatchEventResult DispatchEventInternal(Event&) override; diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_transaction_test.cc b/chromium/third_party/blink/renderer/modules/indexeddb/idb_transaction_test.cc index f71d72e1c45..0dfa392fae3 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_transaction_test.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_transaction_test.cc @@ -41,6 +41,7 @@ #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/events/event_queue.h" +#include "third_party/blink/renderer/core/testing/scoped_mock_overlay_scrollbars.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_key.h" @@ -73,7 +74,8 @@ class FakeIDBDatabaseCallbacks final : public IDBDatabaseCallbacks { void OnComplete(int64_t transaction_id) override {} }; -class IDBTransactionTest : public testing::Test { +class IDBTransactionTest : public testing::Test, + public ScopedMockOverlayScrollbars { protected: void SetUp() override { url_loader_mock_factory_ = platform_->GetURLLoaderMockFactory(); @@ -93,7 +95,8 @@ class IDBTransactionTest : public testing::Test { std::unique_ptr<MockWebIDBTransaction> transaction_backend) { db_ = MakeGarbageCollected<IDBDatabase>( scope.GetExecutionContext(), std::move(database_backend), - MakeGarbageCollected<FakeIDBDatabaseCallbacks>(), scope.GetIsolate()); + MakeGarbageCollected<FakeIDBDatabaseCallbacks>(), scope.GetIsolate(), + mojo::NullRemote()); HashSet<String> transaction_scope = {"store"}; transaction_ = IDBTransaction::CreateNonVersionChange( diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_value.cc b/chromium/third_party/blink/renderer/modules/indexeddb/idb_value.cc index 026313c9c66..0e98861bc23 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_value.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_value.cc @@ -17,9 +17,14 @@ namespace blink { -IDBValue::IDBValue(scoped_refptr<SharedBuffer> data, - Vector<WebBlobInfo> blob_info) - : data_(std::move(data)), blob_info_(std::move(blob_info)) {} +IDBValue::IDBValue( + scoped_refptr<SharedBuffer> data, + Vector<WebBlobInfo> blob_info, + Vector<mojo::PendingRemote<mojom::blink::NativeFileSystemTransferToken>> + native_file_system_tokens) + : data_(std::move(data)), + blob_info_(std::move(blob_info)), + native_file_system_tokens_(std::move(native_file_system_tokens)) {} IDBValue::~IDBValue() { if (isolate_ && external_allocated_size_) diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_value.h b/chromium/third_party/blink/renderer/modules/indexeddb/idb_value.h index 8bf8eac62bf..e5c6842de82 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_value.h +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_value.h @@ -9,6 +9,7 @@ #include "base/macros.h" #include "base/memory/scoped_refptr.h" +#include "third_party/blink/public/mojom/native_file_system/native_file_system_transfer_token.mojom-blink-forward.h" #include "third_party/blink/renderer/modules/indexeddb/idb_key.h" #include "third_party/blink/renderer/modules/indexeddb/idb_key_path.h" #include "third_party/blink/renderer/modules/modules_export.h" @@ -36,7 +37,11 @@ class WebBlobInfo; // the values before returning them to the user. class MODULES_EXPORT IDBValue final { public: - IDBValue(scoped_refptr<SharedBuffer>, Vector<WebBlobInfo>); + IDBValue( + scoped_refptr<SharedBuffer>, + Vector<WebBlobInfo>, + Vector<mojo::PendingRemote<mojom::blink::NativeFileSystemTransferToken>> = + {}); ~IDBValue(); size_t DataSize() const { return data_ ? data_->size() : 0; } @@ -48,6 +53,11 @@ class MODULES_EXPORT IDBValue final { const IDBKey* PrimaryKey() const { return primary_key_.get(); } const IDBKeyPath& KeyPath() const { return key_path_; } + Vector<mojo::PendingRemote<mojom::blink::NativeFileSystemTransferToken>>& + NativeFileSystemTokens() { + return native_file_system_tokens_; + } + // Injects a primary key into a value coming from the backend. void SetInjectedPrimaryKey(std::unique_ptr<IDBKey> primary_key, IDBKeyPath primary_key_path) { @@ -89,6 +99,9 @@ class MODULES_EXPORT IDBValue final { Vector<WebBlobInfo> blob_info_; + Vector<mojo::PendingRemote<mojom::blink::NativeFileSystemTransferToken>> + native_file_system_tokens_; + std::unique_ptr<IDBKey> primary_key_; IDBKeyPath key_path_; diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_value_wrapping.cc b/chromium/third_party/blink/renderer/modules/indexeddb/idb_value_wrapping.cc index 74b7c5a1763..bd07795b99a 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_value_wrapping.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_value_wrapping.cc @@ -87,12 +87,8 @@ void IDBValueWrapper::Clone(ScriptState* script_state, ScriptValue* clone) { DCHECK(!done_cloning_) << __func__ << " called after DoneCloning()"; #endif // DCHECK_IS_ON() - bool read_wasm_from_stream = true; - // It is safe to unconditionally enable WASM module decoding because the - // relevant checks were already performed in SerializedScriptValue::Serialize, - // called by the IDBValueWrapper constructor. *clone = DeserializeScriptValue(script_state, serialized_value_.get(), - &blob_info_, read_wasm_from_stream); + &blob_info_); } // static diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_value_wrapping.h b/chromium/third_party/blink/renderer/modules/indexeddb/idb_value_wrapping.h index 28a88bcdb3a..d8cca97c034 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_value_wrapping.h +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_value_wrapping.h @@ -157,6 +157,16 @@ class MODULES_EXPORT IDBValueWrapper { return std::move(blob_info_); } + Vector<mojo::PendingRemote<mojom::blink::NativeFileSystemTransferToken>> + TakeNativeFileSystemTransferTokens() { +#if DCHECK_IS_ON() + DCHECK(done_cloning_) << __func__ << " called before DoneCloning()"; + DCHECK(owns_file_system_handles_) << __func__ << " called twice"; + owns_file_system_handles_ = false; +#endif // DCHECK_IS_ON() + return std::move(serialized_value_->NativeFileSystemTokens()); + } + size_t DataLengthBeforeWrapInBytes() { return original_data_length_; } // Default threshold for WrapIfBiggerThan(). @@ -199,6 +209,7 @@ class MODULES_EXPORT IDBValueWrapper { bool owns_blob_handles_ = true; bool owns_blob_info_ = true; bool owns_wire_bytes_ = true; + bool owns_file_system_handles_ = true; #endif // DCHECK_IS_ON() }; diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_version_change_event.cc b/chromium/third_party/blink/renderer/modules/indexeddb/idb_version_change_event.cc index 4eeaa231768..a83ad44913a 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_version_change_event.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_version_change_event.cc @@ -71,7 +71,7 @@ const AtomicString& IDBVersionChangeEvent::InterfaceName() const { return event_interface_names::kIDBVersionChangeEvent; } -void IDBVersionChangeEvent::Trace(blink::Visitor* visitor) { +void IDBVersionChangeEvent::Trace(Visitor* visitor) { Event::Trace(visitor); } diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_version_change_event.h b/chromium/third_party/blink/renderer/modules/indexeddb/idb_version_change_event.h index 3d404a5aaf8..60bc00915ec 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_version_change_event.h +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_version_change_event.h @@ -30,10 +30,10 @@ #include "third_party/blink/public/common/indexeddb/web_idb_types.h" #include "third_party/blink/public/mojom/indexeddb/indexeddb.mojom-blink-forward.h" #include "third_party/blink/renderer/bindings/core/v8/serialization/serialized_script_value.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_idb_version_change_event_init.h" #include "third_party/blink/renderer/modules/event_modules.h" #include "third_party/blink/renderer/modules/indexeddb/idb_any.h" #include "third_party/blink/renderer/modules/indexeddb/idb_request.h" -#include "third_party/blink/renderer/modules/indexeddb/idb_version_change_event_init.h" #include "third_party/blink/renderer/platform/wtf/text/wtf_string.h" namespace blink { @@ -61,14 +61,16 @@ class IDBVersionChangeEvent final : public Event { const IDBVersionChangeEventInit*); uint64_t oldVersion() const { return old_version_; } - uint64_t newVersion(bool& is_null) const; + base::Optional<uint64_t> newVersion() const { return new_version_; } + // TODO(crbug.com/1060971): Remove |is_null| version. + uint64_t newVersion(bool& is_null) const; // DEPRECATED const AtomicString& dataLoss() const; const String& dataLossMessage() const { return data_loss_message_; } const AtomicString& InterfaceName() const override; - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; private: uint64_t old_version_; diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_version_change_event.idl b/chromium/third_party/blink/renderer/modules/indexeddb/idb_version_change_event.idl index b3bdfbb41d9..47a8172f4a6 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_version_change_event.idl +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_version_change_event.idl @@ -29,9 +29,9 @@ enum IDBDataLossAmount { "none", "total" }; [ - Exposed=(Window,Worker), - Constructor(DOMString type, optional IDBVersionChangeEventInit eventInitDict) + Exposed=(Window,Worker) ] interface IDBVersionChangeEvent : Event { + constructor(DOMString type, optional IDBVersionChangeEventInit eventInitDict = {}); readonly attribute unsigned long long oldVersion; readonly attribute unsigned long long? newVersion; diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idls.gni b/chromium/third_party/blink/renderer/modules/indexeddb/idls.gni new file mode 100644 index 00000000000..9c8b7d8bbef --- /dev/null +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idls.gni @@ -0,0 +1,34 @@ +# Copyright 2020 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. + +modules_idl_files = [ + "idb_cursor.idl", + "idb_cursor_with_value.idl", + "idb_database.idl", + "idb_factory.idl", + "idb_index.idl", + "idb_key_range.idl", + "idb_object_store.idl", + "idb_observation.idl", + "idb_observer.idl", + "idb_observer_changes.idl", + "idb_open_db_request.idl", + "idb_request.idl", + "idb_transaction.idl", + "idb_version_change_event.idl", +] + +modules_dictionary_idl_files = [ + "idb_database_info.idl", + "idb_index_parameters.idl", + "idb_object_store_parameters.idl", + "idb_observer_init.idl", + "idb_transaction_options.idl", + "idb_version_change_event_init.idl", +] + +modules_dependency_idl_files = [ + "window_indexed_database.idl", + "worker_global_scope_indexed_database.idl", +] diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/indexed_db_blink_mojom_traits.cc b/chromium/third_party/blink/renderer/modules/indexeddb/indexed_db_blink_mojom_traits.cc index 340121d34fe..5c0ec1f2105 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/indexed_db_blink_mojom_traits.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/indexed_db_blink_mojom_traits.cc @@ -7,7 +7,6 @@ #include "base/stl_util.h" #include "mojo/public/cpp/bindings/array_traits_wtf_vector.h" #include "mojo/public/cpp/bindings/pending_remote.h" -#include "third_party/blink/public/platform/file_path_conversion.h" #include "third_party/blink/public/platform/web_blob_info.h" #include "third_party/blink/renderer/modules/indexeddb/idb_key_range.h" #include "third_party/blink/renderer/platform/file_metadata.h" @@ -185,16 +184,16 @@ StructTraits<blink::mojom::IDBValueDataView, std::unique_ptr<blink::IDBValue>>:: } // static -Vector<blink::mojom::blink::IDBBlobInfoPtr> +Vector<blink::mojom::blink::IDBExternalObjectPtr> StructTraits<blink::mojom::IDBValueDataView, std::unique_ptr<blink::IDBValue>>:: - blob_or_file_info(const std::unique_ptr<blink::IDBValue>& input) { - Vector<blink::mojom::blink::IDBBlobInfoPtr> blob_or_file_info; - blob_or_file_info.ReserveInitialCapacity(input->BlobInfo().size()); + external_objects(const std::unique_ptr<blink::IDBValue>& input) { + Vector<blink::mojom::blink::IDBExternalObjectPtr> external_objects; + external_objects.ReserveInitialCapacity( + input->BlobInfo().size() + input->NativeFileSystemTokens().size()); for (const blink::WebBlobInfo& info : input->BlobInfo()) { auto blob_info = blink::mojom::blink::IDBBlobInfo::New(); if (info.IsFile()) { blob_info->file = blink::mojom::blink::IDBFileInfo::New(); - blob_info->file->path = blink::WebStringToFilePath(info.FilePath()); String name = info.FileName(); if (name.IsNull()) name = g_empty_string; @@ -211,9 +210,16 @@ StructTraits<blink::mojom::IDBValueDataView, std::unique_ptr<blink::IDBValue>>:: blob_info->mime_type = mime_type; blob_info->blob = mojo::PendingRemote<blink::mojom::blink::Blob>( info.CloneBlobHandle(), blink::mojom::blink::Blob::Version_); - blob_or_file_info.push_back(std::move(blob_info)); + external_objects.push_back( + blink::mojom::blink::IDBExternalObject::NewBlobOrFile( + std::move(blob_info))); } - return blob_or_file_info; + for (auto& token : input->NativeFileSystemTokens()) { + external_objects.push_back( + blink::mojom::blink::IDBExternalObject::NewNativeFileSystemToken( + std::move(token))); + } + return external_objects; } // static @@ -226,35 +232,49 @@ bool StructTraits<blink::mojom::IDBValueDataView, return false; if (value_bits.IsEmpty()) { - *out = std::make_unique<blink::IDBValue>( - scoped_refptr<SharedBuffer>(), Vector<blink::WebBlobInfo>()); + *out = std::make_unique<blink::IDBValue>(scoped_refptr<SharedBuffer>(), + Vector<blink::WebBlobInfo>()); return true; } scoped_refptr<SharedBuffer> value_buffer = SharedBuffer::Create( reinterpret_cast<const char*>(value_bits.data()), value_bits.size()); - Vector<blink::mojom::blink::IDBBlobInfoPtr> blob_or_file_info; - if (!data.ReadBlobOrFileInfo(&blob_or_file_info)) + Vector<blink::mojom::blink::IDBExternalObjectPtr> external_objects; + if (!data.ReadExternalObjects(&external_objects)) return false; Vector<blink::WebBlobInfo> value_blob_info; - value_blob_info.ReserveInitialCapacity(blob_or_file_info.size()); - for (const auto& info : blob_or_file_info) { - if (info->file) { - value_blob_info.emplace_back( - info->uuid, blink::FilePathToWebString(info->file->path), - info->file->name, info->mime_type, - blink::NullableTimeToOptionalTime(info->file->last_modified), - info->size, info->blob.PassPipe()); - } else { - value_blob_info.emplace_back(info->uuid, info->mime_type, info->size, - info->blob.PassPipe()); + Vector< + mojo::PendingRemote<blink::mojom::blink::NativeFileSystemTransferToken>> + native_file_system_tokens; + + for (const auto& object : external_objects) { + switch (object->which()) { + case blink::mojom::blink::IDBExternalObject::Tag::BLOB_OR_FILE: { + auto& info = object->get_blob_or_file(); + if (info->file) { + value_blob_info.emplace_back( + info->uuid, info->file->name, info->mime_type, + blink::NullableTimeToOptionalTime(info->file->last_modified), + info->size, info->blob.PassPipe()); + } else { + value_blob_info.emplace_back(info->uuid, info->mime_type, info->size, + info->blob.PassPipe()); + } + break; + } + case blink::mojom::blink::IDBExternalObject::Tag:: + NATIVE_FILE_SYSTEM_TOKEN: + native_file_system_tokens.push_back( + std::move(object->get_native_file_system_token())); + break; } } - *out = std::make_unique<blink::IDBValue>(std::move(value_buffer), - std::move(value_blob_info)); + *out = std::make_unique<blink::IDBValue>( + std::move(value_buffer), std::move(value_blob_info), + std::move(native_file_system_tokens)); return true; } diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/indexed_db_blink_mojom_traits.h b/chromium/third_party/blink/renderer/modules/indexeddb/indexed_db_blink_mojom_traits.h index 5a94ff7159d..4019374a826 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/indexed_db_blink_mojom_traits.h +++ b/chromium/third_party/blink/renderer/modules/indexeddb/indexed_db_blink_mojom_traits.h @@ -128,7 +128,7 @@ template <> struct MODULES_EXPORT StructTraits<blink::mojom::IDBValueDataView, std::unique_ptr<blink::IDBValue>> { static Vector<uint8_t> bits(const std::unique_ptr<blink::IDBValue>& input); - static Vector<blink::mojom::blink::IDBBlobInfoPtr> blob_or_file_info( + static Vector<blink::mojom::blink::IDBExternalObjectPtr> external_objects( const std::unique_ptr<blink::IDBValue>& input); static bool Read(blink::mojom::IDBValueDataView data, std::unique_ptr<blink::IDBValue>* out); diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/inspector_indexed_db_agent.cc b/chromium/third_party/blink/renderer/modules/indexeddb/inspector_indexed_db_agent.cc index e278a24906d..6c8b3f073f0 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/inspector_indexed_db_agent.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/inspector_indexed_db_agent.cc @@ -36,6 +36,7 @@ #include "third_party/blink/public/common/indexeddb/web_idb_types.h" #include "third_party/blink/renderer/bindings/core/v8/script_controller.h" #include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_idb_transaction_options.h" #include "third_party/blink/renderer/core/dom/document.h" #include "third_party/blink/renderer/core/dom/dom_string_list.h" #include "third_party/blink/renderer/core/dom/events/native_event_listener.h" @@ -58,7 +59,6 @@ #include "third_party/blink/renderer/modules/indexeddb/idb_open_db_request.h" #include "third_party/blink/renderer/modules/indexeddb/idb_request.h" #include "third_party/blink/renderer/modules/indexeddb/idb_transaction.h" -#include "third_party/blink/renderer/modules/indexeddb/idb_transaction_options.h" #include "third_party/blink/renderer/modules/indexeddb/web_idb_cursor.h" #include "third_party/blink/renderer/platform/bindings/exception_state.h" #include "third_party/blink/renderer/platform/bindings/script_state.h" @@ -101,13 +101,13 @@ const char kNoDocumentError[] = "No document for given frame found"; Response AssertIDBFactory(Document* document, IDBFactory*& result) { LocalDOMWindow* dom_window = document->domWindow(); if (!dom_window) - return Response::Error("No IndexedDB factory for given frame found"); + return Response::ServerError("No IndexedDB factory for given frame found"); IDBFactory* idb_factory = GlobalIndexedDB::indexedDB(*dom_window); if (!idb_factory) - return Response::Error("No IndexedDB factory for given frame found"); + return Response::ServerError("No IndexedDB factory for given frame found"); result = idb_factory; - return Response::OK(); + return Response::Success(); } class GetDatabaseNamesCallback final : public NativeEventListener { @@ -121,7 +121,8 @@ class GetDatabaseNamesCallback final : public NativeEventListener { void Invoke(ExecutionContext*, Event* event) override { if (event->type() != event_type_names::kSuccess) { - request_callback_->sendFailure(Response::Error("Unexpected event type.")); + request_callback_->sendFailure( + Response::ServerError("Unexpected event type.")); return; } @@ -129,7 +130,7 @@ class GetDatabaseNamesCallback final : public NativeEventListener { IDBAny* request_result = idb_request->ResultAsAny(); if (request_result->GetType() != IDBAny::kDOMStringListType) { request_callback_->sendFailure( - Response::Error("Unexpected result type.")); + Response::ServerError("Unexpected result type.")); return; } @@ -156,7 +157,7 @@ class DeleteCallback final : public NativeEventListener { void Invoke(ExecutionContext*, Event* event) override { if (event->type() != event_type_names::kSuccess) { request_callback_->sendFailure( - Response::Error("Failed to delete database.")); + Response::ServerError("Failed to delete database.")); return; } request_callback_->sendSuccess(); @@ -182,12 +183,12 @@ class ExecutableWithDatabase void Start(LocalFrame* frame, const String& database_name) { Document* document = frame ? frame->GetDocument() : nullptr; if (!document) { - SendFailure(Response::Error(kNoDocumentError)); + SendFailure(Response::ServerError(kNoDocumentError)); return; } IDBFactory* idb_factory = nullptr; Response response = AssertIDBFactory(document, idb_factory); - if (!response.isSuccess()) { + if (!response.IsSuccess()) { SendFailure(response); return; } @@ -216,7 +217,7 @@ class ExecutableWithDatabase IDBOpenDBRequest* idb_open_db_request = idb_factory->open(script_state, database_name, exception_state); if (exception_state.HadException()) { - SendFailure(Response::Error("Could not open database.")); + SendFailure(Response::ServerError("Could not open database.")); return; } idb_open_db_request->addEventListener(event_type_names::kUpgradeneeded, @@ -250,7 +251,7 @@ class OpenDatabaseCallback final : public NativeEventListener { void Invoke(ExecutionContext* context, Event* event) override { if (event->type() != event_type_names::kSuccess) { executable_with_database_->GetRequestCallback()->sendFailure( - Response::Error("Unexpected event type.")); + Response::ServerError("Unexpected event type.")); return; } @@ -259,7 +260,7 @@ class OpenDatabaseCallback final : public NativeEventListener { IDBAny* request_result = idb_open_db_request->ResultAsAny(); if (request_result->GetType() != IDBAny::kIDBDatabaseType) { executable_with_database_->GetRequestCallback()->sendFailure( - Response::Error("Unexpected result type.")); + Response::ServerError("Unexpected result type.")); return; } @@ -269,7 +270,7 @@ class OpenDatabaseCallback final : public NativeEventListener { idb_database->close(); } - void Trace(blink::Visitor* visitor) override { + void Trace(Visitor* visitor) override { visitor->Trace(script_state_); NativeEventListener::Trace(visitor); } @@ -297,7 +298,7 @@ class UpgradeDatabaseCallback final : public NativeEventListener { void Invoke(ExecutionContext* context, Event* event) override { if (event->type() != event_type_names::kUpgradeneeded) { executable_with_database_->GetRequestCallback()->sendFailure( - Response::Error("Unexpected event type.")); + Response::ServerError("Unexpected event type.")); return; } @@ -309,7 +310,7 @@ class UpgradeDatabaseCallback final : public NativeEventListener { NonThrowableExceptionState exception_state; idb_open_db_request->transaction()->abort(exception_state); executable_with_database_->GetRequestCallback()->sendFailure( - Response::Error("Aborted upgrade.")); + Response::ServerError("Aborted upgrade.")); } private: @@ -537,7 +538,8 @@ class OpenCursorCallback final : public NativeEventListener { void Invoke(ExecutionContext*, Event* event) override { if (event->type() != event_type_names::kSuccess) { - request_callback_->sendFailure(Response::Error("Unexpected event type.")); + request_callback_->sendFailure( + Response::ServerError("Unexpected event type.")); return; } @@ -549,7 +551,7 @@ class OpenCursorCallback final : public NativeEventListener { } if (request_result->GetType() != IDBAny::kIDBCursorWithValueType) { request_callback_->sendFailure( - Response::Error("Unexpected result type.")); + Response::ServerError("Unexpected result type.")); return; } @@ -560,7 +562,7 @@ class OpenCursorCallback final : public NativeEventListener { idb_cursor->advance(skip_count_, exception_state); if (exception_state.HadException()) { request_callback_->sendFailure( - Response::Error("Could not advance cursor.")); + Response::ServerError("Could not advance cursor.")); } skip_count_ = 0; return; @@ -578,11 +580,11 @@ class OpenCursorCallback final : public NativeEventListener { exception_state); if (exception_state.HadException()) { request_callback_->sendFailure( - Response::Error("Could not continue cursor.")); + Response::ServerError("Could not continue cursor.")); return; } - Document* document = To<Document>(ExecutionContext::From(script_state_)); + Document* document = Document::From(ExecutionContext::From(script_state_)); if (!document) return; ScriptState::Scope scope(script_state_); @@ -608,7 +610,7 @@ class OpenCursorCallback final : public NativeEventListener { request_callback_->sendSuccess(std::move(result_), has_more); } - void Trace(blink::Visitor* visitor) override { + void Trace(Visitor* visitor) override { visitor->Trace(script_state_); NativeEventListener::Trace(visitor); } @@ -644,14 +646,14 @@ class DataLoader final : public ExecutableWithDatabase<RequestDataCallback> { TransactionForDatabase(script_state, idb_database, object_store_name_); if (!idb_transaction) { request_callback_->sendFailure( - Response::Error("Could not get transaction")); + Response::ServerError("Could not get transaction")); return; } IDBObjectStore* idb_object_store = ObjectStoreForTransaction(idb_transaction, object_store_name_); if (!idb_object_store) { request_callback_->sendFailure( - Response::Error("Could not get object store")); + Response::ServerError("Could not get object store")); return; } @@ -659,7 +661,8 @@ class DataLoader final : public ExecutableWithDatabase<RequestDataCallback> { if (!index_name_.IsEmpty()) { IDBIndex* idb_index = IndexForObjectStore(idb_object_store, index_name_); if (!idb_index) { - request_callback_->sendFailure(Response::Error("Could not get index")); + request_callback_->sendFailure( + Response::ServerError("Could not get index")); return; } @@ -729,14 +732,14 @@ void InspectorIndexedDBAgent::DidCommitLoadForLocalFrame(LocalFrame* frame) { Response InspectorIndexedDBAgent::enable() { enabled_.Set(true); - return Response::OK(); + return Response::Success(); } Response InspectorIndexedDBAgent::disable() { enabled_.Clear(); v8_session_->releaseObjectGroup( ToV8InspectorStringView(kIndexedDBObjectGroup)); - return Response::OK(); + return Response::Success(); } void InspectorIndexedDBAgent::requestDatabaseNames( @@ -746,12 +749,12 @@ void InspectorIndexedDBAgent::requestDatabaseNames( inspected_frames_->FrameWithSecurityOrigin(security_origin); Document* document = frame ? frame->GetDocument() : nullptr; if (!document) { - request_callback->sendFailure(Response::Error(kNoDocumentError)); + request_callback->sendFailure(Response::ServerError(kNoDocumentError)); return; } IDBFactory* idb_factory = nullptr; Response response = AssertIDBFactory(document, idb_factory); - if (!response.isSuccess()) { + if (!response.IsSuccess()) { request_callback->sendFailure(response); return; } @@ -767,7 +770,7 @@ void InspectorIndexedDBAgent::requestDatabaseNames( idb_factory->GetDatabaseNames(script_state, exception_state); if (exception_state.HadException()) { request_callback->sendFailure( - Response::Error("Could not obtain database names.")); + Response::ServerError("Could not obtain database names.")); return; } idb_request->addEventListener( @@ -802,7 +805,8 @@ void InspectorIndexedDBAgent::requestData( key_range.isJust() ? IdbKeyRangeFromKeyRange(key_range.fromJust()) : nullptr; if (key_range.isJust() && !idb_key_range) { - request_callback->sendFailure(Response::Error("Can not parse key range.")); + request_callback->sendFailure( + Response::ServerError("Can not parse key range.")); return; } @@ -857,7 +861,7 @@ class GetMetadata final : public ExecutableWithDatabase<GetMetadataCallback> { void NotifySubtaskDone(const String& error) { if (!error.IsNull()) { - request_callback_->sendFailure(Response::Error(error)); + request_callback_->sendFailure(Response::ServerError(error.Utf8())); return; } if (--subtask_pending_ == 0) { @@ -881,14 +885,14 @@ class GetMetadata final : public ExecutableWithDatabase<GetMetadataCallback> { indexed_db_names::kReadonly); if (!idb_transaction) { request_callback_->sendFailure( - Response::Error("Could not get transaction")); + Response::ServerError("Could not get transaction")); return; } IDBObjectStore* idb_object_store = ObjectStoreForTransaction(idb_transaction, object_store_name_); if (!idb_object_store) { request_callback_->sendFailure( - Response::Error("Could not get object store")); + Response::ServerError("Could not get object store")); return; } @@ -901,9 +905,10 @@ class GetMetadata final : public ExecutableWithDatabase<GetMetadataCallback> { DCHECK(!exception_state.HadException()); if (exception_state.HadException()) { ExceptionCode ec = exception_state.Code(); - request_callback_->sendFailure(Response::Error( + request_callback_->sendFailure(Response::ServerError( String::Format("Could not count entries in object store '%s': %d", - object_store_name_.Utf8().c_str(), ec))); + object_store_name_.Latin1().c_str(), ec) + .Utf8())); return; } GetMetadataListener* listener_get_entries_count = @@ -964,7 +969,7 @@ class DeleteObjectStoreEntriesListener final : public NativeEventListener { void Invoke(ExecutionContext*, Event* event) override { if (event->type() != event_type_names::kSuccess) { request_callback_->sendFailure( - Response::Error("Failed to delete specified entries")); + Response::ServerError("Failed to delete specified entries")); return; } @@ -1000,14 +1005,14 @@ class DeleteObjectStoreEntries final indexed_db_names::kReadwrite); if (!idb_transaction) { request_callback_->sendFailure( - Response::Error("Could not get transaction")); + Response::ServerError("Could not get transaction")); return; } IDBObjectStore* idb_object_store = ObjectStoreForTransaction(idb_transaction, object_store_name_); if (!idb_object_store) { request_callback_->sendFailure( - Response::Error("Could not get object store")); + Response::ServerError("Could not get object store")); return; } @@ -1038,7 +1043,8 @@ void InspectorIndexedDBAgent::deleteObjectStoreEntries( std::unique_ptr<DeleteObjectStoreEntriesCallback> request_callback) { IDBKeyRange* idb_key_range = IdbKeyRangeFromKeyRange(key_range.get()); if (!idb_key_range) { - request_callback->sendFailure(Response::Error("Can not parse key range")); + request_callback->sendFailure( + Response::ServerError("Can not parse key range")); return; } scoped_refptr<DeleteObjectStoreEntries> delete_object_store_entries = @@ -1058,7 +1064,8 @@ class ClearObjectStoreListener final : public NativeEventListener { void Invoke(ExecutionContext*, Event* event) override { if (event->type() != event_type_names::kComplete) { - request_callback_->sendFailure(Response::Error("Unexpected event type.")); + request_callback_->sendFailure( + Response::ServerError("Unexpected event type.")); return; } @@ -1090,14 +1097,14 @@ class ClearObjectStore final indexed_db_names::kReadwrite); if (!idb_transaction) { request_callback_->sendFailure( - Response::Error("Could not get transaction")); + Response::ServerError("Could not get transaction")); return; } IDBObjectStore* idb_object_store = ObjectStoreForTransaction(idb_transaction, object_store_name_); if (!idb_object_store) { request_callback_->sendFailure( - Response::Error("Could not get object store")); + Response::ServerError("Could not get object store")); return; } @@ -1106,9 +1113,10 @@ class ClearObjectStore final DCHECK(!exception_state.HadException()); if (exception_state.HadException()) { ExceptionCode ec = exception_state.Code(); - request_callback_->sendFailure(Response::Error( + request_callback_->sendFailure(Response::ServerError( String::Format("Could not clear object store '%s': %d", - object_store_name_.Utf8().c_str(), ec))); + object_store_name_.Latin1().c_str(), ec) + .Utf8())); return; } idb_transaction->addEventListener( @@ -1147,12 +1155,12 @@ void InspectorIndexedDBAgent::deleteDatabase( inspected_frames_->FrameWithSecurityOrigin(security_origin); Document* document = frame ? frame->GetDocument() : nullptr; if (!document) { - request_callback->sendFailure(Response::Error(kNoDocumentError)); + request_callback->sendFailure(Response::ServerError(kNoDocumentError)); return; } IDBFactory* idb_factory = nullptr; Response response = AssertIDBFactory(document, idb_factory); - if (!response.isSuccess()) { + if (!response.IsSuccess()) { request_callback->sendFailure(response); return; } @@ -1168,7 +1176,7 @@ void InspectorIndexedDBAgent::deleteDatabase( script_state, database_name, exception_state); if (exception_state.HadException()) { request_callback->sendFailure( - Response::Error("Could not delete database.")); + Response::ServerError("Could not delete database.")); return; } idb_request->addEventListener( @@ -1179,7 +1187,7 @@ void InspectorIndexedDBAgent::deleteDatabase( false); } -void InspectorIndexedDBAgent::Trace(blink::Visitor* visitor) { +void InspectorIndexedDBAgent::Trace(Visitor* visitor) { visitor->Trace(inspected_frames_); InspectorBaseAgent::Trace(visitor); } diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/inspector_indexed_db_agent.h b/chromium/third_party/blink/renderer/modules/indexeddb/inspector_indexed_db_agent.h index c4fa599841b..f584276e2f8 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/inspector_indexed_db_agent.h +++ b/chromium/third_party/blink/renderer/modules/indexeddb/inspector_indexed_db_agent.h @@ -47,7 +47,7 @@ class MODULES_EXPORT InspectorIndexedDBAgent final public: InspectorIndexedDBAgent(InspectedFrames*, v8_inspector::V8InspectorSession*); ~InspectorIndexedDBAgent() override; - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; void Restore() override; void DidCommitLoadForLocalFrame(LocalFrame*) override; diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/mock_web_idb_factory.h b/chromium/third_party/blink/renderer/modules/indexeddb/mock_web_idb_factory.h index e2bd1dfba07..1d52aab774b 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/mock_web_idb_factory.h +++ b/chromium/third_party/blink/renderer/modules/indexeddb/mock_web_idb_factory.h @@ -40,6 +40,8 @@ class MockWebIDBFactory : public testing::StrictMock<blink::WebIDBFactory> { void(const WTF::String& name, std::unique_ptr<WebIDBCallbacks>, bool force_close)); + MOCK_METHOD0(GetObservedFeature, + mojo::PendingRemote<mojom::blink::ObservedFeature>()); void SetCallbacksPointer(std::unique_ptr<WebIDBCallbacks>* callbacks); diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_database_impl.cc b/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_database_impl.cc index b99decb0155..0ac1b13d05f 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_database_impl.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_database_impl.cc @@ -5,6 +5,7 @@ #include "third_party/blink/renderer/modules/indexeddb/web_idb_database_impl.h" #include "base/format_macros.h" +#include "base/memory/ptr_util.h" #include "mojo/public/cpp/bindings/self_owned_associated_receiver.h" #include "third_party/blink/public/mojom/indexeddb/indexeddb.mojom-blink.h" #include "third_party/blink/renderer/modules/indexeddb/idb_database_error.h" diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_factory.h b/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_factory.h index 07fc9bffed8..42ef51b2612 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_factory.h +++ b/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_factory.h @@ -30,6 +30,7 @@ #define THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_WEB_IDB_FACTORY_H_ #include "mojo/public/cpp/bindings/pending_associated_receiver.h" +#include "third_party/blink/public/mojom/feature_observer/feature_observer.mojom-blink.h" #include "third_party/blink/renderer/modules/modules_export.h" namespace WTF { @@ -58,6 +59,8 @@ class MODULES_EXPORT WebIDBFactory { virtual void DeleteDatabase(const WTF::String& name, std::unique_ptr<WebIDBCallbacks>, bool force_close) = 0; + virtual mojo::PendingRemote<mojom::blink::ObservedFeature> + GetObservedFeature() = 0; }; } // namespace blink diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_factory_impl.cc b/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_factory_impl.cc index 875fb3037f2..ebd78224b09 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_factory_impl.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_factory_impl.cc @@ -15,13 +15,24 @@ namespace blink { WebIDBFactoryImpl::WebIDBFactoryImpl( mojo::PendingRemote<mojom::blink::IDBFactory> pending_factory, + mojo::PendingRemote<mojom::blink::FeatureObserver> feature_observer, scoped_refptr<base::SingleThreadTaskRunner> task_runner) : task_runner_(std::move(task_runner)) { factory_.Bind(std::move(pending_factory), task_runner_); + feature_observer_.Bind(std::move(feature_observer), task_runner_); } WebIDBFactoryImpl::~WebIDBFactoryImpl() = default; +mojo::PendingRemote<mojom::blink::ObservedFeature> +WebIDBFactoryImpl::GetObservedFeature() { + mojo::PendingRemote<mojom::blink::ObservedFeature> feature; + feature_observer_->Register( + feature.InitWithNewPipeAndPassReceiver(), + mojom::blink::ObservedFeatureType::kIndexedDBConnection); + return feature; +} + void WebIDBFactoryImpl::GetDatabaseInfo( std::unique_ptr<WebIDBCallbacks> callbacks) { callbacks->SetState(nullptr, WebIDBCallbacksImpl::kNoTransaction); diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_factory_impl.h b/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_factory_impl.h index aaec596aa00..4a761c34404 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_factory_impl.h +++ b/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_factory_impl.h @@ -26,6 +26,7 @@ class WebIDBFactoryImpl : public WebIDBFactory { public: explicit WebIDBFactoryImpl( mojo::PendingRemote<mojom::blink::IDBFactory> pending_factory, + mojo::PendingRemote<mojom::blink::FeatureObserver> feature_observer, scoped_refptr<base::SingleThreadTaskRunner> task_runner); ~WebIDBFactoryImpl() override; @@ -43,6 +44,8 @@ class WebIDBFactoryImpl : public WebIDBFactory { void DeleteDatabase(const WTF::String& name, std::unique_ptr<WebIDBCallbacks> callbacks, bool force_close) override; + mojo::PendingRemote<mojom::blink::ObservedFeature> GetObservedFeature() + override; private: mojo::PendingAssociatedRemote<mojom::blink::IDBCallbacks> GetCallbacksProxy( @@ -52,6 +55,7 @@ class WebIDBFactoryImpl : public WebIDBFactory { std::unique_ptr<IndexedDBDatabaseCallbacksImpl> callbacks); mojo::Remote<mojom::blink::IDBFactory> factory_; + mojo::Remote<mojom::blink::FeatureObserver> feature_observer_; scoped_refptr<base::SingleThreadTaskRunner> task_runner_; }; |