Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(414)

Unified Diff: Source/bindings/modules/v8/custom/V8ServiceWorkerMessageEventCustom.cpp

Issue 1139873002: [PROTOTYPE] ServiceWorker: Add ServiceWorkerMessageEvent impl. Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/bindings/modules/v8/custom/V8ServiceWorkerMessageEventCustom.cpp
diff --git a/Source/bindings/modules/v8/custom/V8ServiceWorkerMessageEventCustom.cpp b/Source/bindings/modules/v8/custom/V8ServiceWorkerMessageEventCustom.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..3db1e7514d69d6d0051a198a5005c99837e8dc40
--- /dev/null
+++ b/Source/bindings/modules/v8/custom/V8ServiceWorkerMessageEventCustom.cpp
@@ -0,0 +1,87 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "config.h"
+#include "bindings/modules/v8/V8ServiceWorkerMessageEvent.h"
+
+#include "bindings/core/v8/Dictionary.h"
+#include "bindings/core/v8/SerializedScriptValue.h"
+#include "bindings/core/v8/SerializedScriptValueFactory.h"
+#include "bindings/core/v8/V8Binding.h"
+#include "bindings/core/v8/V8DOMWrapper.h"
+#include "bindings/core/v8/V8Event.h"
+#include "bindings/core/v8/V8HiddenValue.h"
+#include "bindings/core/v8/V8MessagePort.h"
+
+namespace blink {
+
+static v8::Local<v8::Value> cacheState(v8::Isolate* isolate, v8::Local<v8::Object> event, v8::Local<v8::Value> data)
+{
+ V8HiddenValue::setHiddenValue(isolate, event, V8HiddenValue::data(isolate), data);
+ return data;
+}
+
+void V8ServiceWorkerMessageEvent::dataAttributeGetterCustom(const v8::PropertyCallbackInfo<v8::Value>& info)
+{
+ ServiceWorkerMessageEvent* event = V8ServiceWorkerMessageEvent::toImpl(info.Holder());
+
+ v8::Local<v8::Value> result = V8HiddenValue::getHiddenValue(info.GetIsolate(), info.Holder(), V8HiddenValue::detail(info.GetIsolate()));
+
+ if (!result.IsEmpty()) {
+ v8SetReturnValue(info, result);
+ return;
+ }
+
+ if (!event->serializedData()) {
+ // If we're in an isolated world and the event was created in the main world,
+ // we need to find the 'detail' property on the main world wrapper and clone it.
+ v8::Local<v8::Value> mainWorldData = V8HiddenValue::getHiddenValueFromMainWorldWrapper(info.GetIsolate(), event, V8HiddenValue::data(info.GetIsolate()));
+ if (!mainWorldData.IsEmpty())
+ event->setSerializedData(SerializedScriptValueFactory::instance().createAndSwallowExceptions(info.GetIsolate(), mainWorldData));
+ }
+
+ if (event->serializedData()) {
+ result = event->serializedData()->deserialize();
+ v8SetReturnValue(info, cacheState(info.GetIsolate(), info.Holder(), result));
+ return;
+ }
+
+ v8SetReturnValue(info, cacheState(info.GetIsolate(), info.Holder(), v8::Null(info.GetIsolate())));
+}
+
+void V8ServiceWorkerMessageEvent::initServiceWorkerMessageEventMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info)
+{
+ ExceptionState exceptionState(ExceptionState::ExecutionContext, "initServiceWorkerMessageEvent", "ServiceWorkerMessageEvent", info.Holder(), info.GetIsolate());
+ ServiceWorkerMessageEvent* event = V8ServiceWorkerMessageEvent::toImpl(info.Holder());
+ TOSTRING_VOID(V8StringResource<>, typeArg, info[0]);
+ bool canBubbleArg;
+ bool cancelableArg;
+ if (!v8Call(info[1]->BooleanValue(info.GetIsolate()->GetCurrentContext()), canBubbleArg)
+ || !v8Call(info[2]->BooleanValue(info.GetIsolate()->GetCurrentContext()), cancelableArg))
+ return;
+ v8::Local<v8::Value> dataArg = info[3];
+ TOSTRING_VOID(V8StringResource<>, originArg, info[4]);
+ TOSTRING_VOID(V8StringResource<>, lastEventIdArg, info[5]);
+ ServiceWorkerOrMessagePort sourceArg;
+ V8ServiceWorkerOrMessagePort::toImpl(info.GetIsolate(), info[6], sourceArg, exceptionState);
+ if (exceptionState.throwIfNeeded())
+ return;
+ OwnPtrWillBeRawPtr<MessagePortArray> portArray = nullptr;
+ const int portArrayIndex = 7;
+ if (!isUndefinedOrNull(info[portArrayIndex])) {
+ portArray = adoptPtrWillBeNoop(new MessagePortArray);
+ *portArray = toRefPtrWillBeMemberNativeArray<MessagePort, V8MessagePort>(info[portArrayIndex], portArrayIndex + 1, info.GetIsolate(), exceptionState);
+ if (exceptionState.throwIfNeeded())
+ return;
+ }
+ event->initServiceWorkerMessageEvent(typeArg, canBubbleArg, cancelableArg, originArg, lastEventIdArg, sourceArg, portArray.release());
+
+ if (!dataArg.IsEmpty()) {
+ V8HiddenValue::setHiddenValue(info.GetIsolate(), info.Holder(), V8HiddenValue::data(info.GetIsolate()), dataArg);
+ if (DOMWrapperWorld::current(info.GetIsolate()).isIsolatedWorld())
+ event->setSerializedData(SerializedScriptValueFactory::instance().createAndSwallowExceptions(info.GetIsolate(), dataArg));
+ }
+}
+
+} // namespace blink
« no previous file with comments | « Source/bindings/modules/v8/DictionaryHelperForModules.cpp ('k') | Source/bindings/modules/v8/custom/custom.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698