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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "config.h"
6 #include "bindings/modules/v8/V8ServiceWorkerMessageEvent.h"
7
8 #include "bindings/core/v8/Dictionary.h"
9 #include "bindings/core/v8/SerializedScriptValue.h"
10 #include "bindings/core/v8/SerializedScriptValueFactory.h"
11 #include "bindings/core/v8/V8Binding.h"
12 #include "bindings/core/v8/V8DOMWrapper.h"
13 #include "bindings/core/v8/V8Event.h"
14 #include "bindings/core/v8/V8HiddenValue.h"
15 #include "bindings/core/v8/V8MessagePort.h"
16
17 namespace blink {
18
19 static v8::Local<v8::Value> cacheState(v8::Isolate* isolate, v8::Local<v8::Objec t> event, v8::Local<v8::Value> data)
20 {
21 V8HiddenValue::setHiddenValue(isolate, event, V8HiddenValue::data(isolate), data);
22 return data;
23 }
24
25 void V8ServiceWorkerMessageEvent::dataAttributeGetterCustom(const v8::PropertyCa llbackInfo<v8::Value>& info)
26 {
27 ServiceWorkerMessageEvent* event = V8ServiceWorkerMessageEvent::toImpl(info. Holder());
28
29 v8::Local<v8::Value> result = V8HiddenValue::getHiddenValue(info.GetIsolate( ), info.Holder(), V8HiddenValue::detail(info.GetIsolate()));
30
31 if (!result.IsEmpty()) {
32 v8SetReturnValue(info, result);
33 return;
34 }
35
36 if (!event->serializedData()) {
37 // If we're in an isolated world and the event was created in the main w orld,
38 // we need to find the 'detail' property on the main world wrapper and c lone it.
39 v8::Local<v8::Value> mainWorldData = V8HiddenValue::getHiddenValueFromMa inWorldWrapper(info.GetIsolate(), event, V8HiddenValue::data(info.GetIsolate())) ;
40 if (!mainWorldData.IsEmpty())
41 event->setSerializedData(SerializedScriptValueFactory::instance().cr eateAndSwallowExceptions(info.GetIsolate(), mainWorldData));
42 }
43
44 if (event->serializedData()) {
45 result = event->serializedData()->deserialize();
46 v8SetReturnValue(info, cacheState(info.GetIsolate(), info.Holder(), resu lt));
47 return;
48 }
49
50 v8SetReturnValue(info, cacheState(info.GetIsolate(), info.Holder(), v8::Null (info.GetIsolate())));
51 }
52
53 void V8ServiceWorkerMessageEvent::initServiceWorkerMessageEventMethodCustom(cons t v8::FunctionCallbackInfo<v8::Value>& info)
54 {
55 ExceptionState exceptionState(ExceptionState::ExecutionContext, "initService WorkerMessageEvent", "ServiceWorkerMessageEvent", info.Holder(), info.GetIsolate ());
56 ServiceWorkerMessageEvent* event = V8ServiceWorkerMessageEvent::toImpl(info. Holder());
57 TOSTRING_VOID(V8StringResource<>, typeArg, info[0]);
58 bool canBubbleArg;
59 bool cancelableArg;
60 if (!v8Call(info[1]->BooleanValue(info.GetIsolate()->GetCurrentContext()), c anBubbleArg)
61 || !v8Call(info[2]->BooleanValue(info.GetIsolate()->GetCurrentContext()) , cancelableArg))
62 return;
63 v8::Local<v8::Value> dataArg = info[3];
64 TOSTRING_VOID(V8StringResource<>, originArg, info[4]);
65 TOSTRING_VOID(V8StringResource<>, lastEventIdArg, info[5]);
66 ServiceWorkerOrMessagePort sourceArg;
67 V8ServiceWorkerOrMessagePort::toImpl(info.GetIsolate(), info[6], sourceArg, exceptionState);
68 if (exceptionState.throwIfNeeded())
69 return;
70 OwnPtrWillBeRawPtr<MessagePortArray> portArray = nullptr;
71 const int portArrayIndex = 7;
72 if (!isUndefinedOrNull(info[portArrayIndex])) {
73 portArray = adoptPtrWillBeNoop(new MessagePortArray);
74 *portArray = toRefPtrWillBeMemberNativeArray<MessagePort, V8MessagePort> (info[portArrayIndex], portArrayIndex + 1, info.GetIsolate(), exceptionState);
75 if (exceptionState.throwIfNeeded())
76 return;
77 }
78 event->initServiceWorkerMessageEvent(typeArg, canBubbleArg, cancelableArg, o riginArg, lastEventIdArg, sourceArg, portArray.release());
79
80 if (!dataArg.IsEmpty()) {
81 V8HiddenValue::setHiddenValue(info.GetIsolate(), info.Holder(), V8Hidden Value::data(info.GetIsolate()), dataArg);
82 if (DOMWrapperWorld::current(info.GetIsolate()).isIsolatedWorld())
83 event->setSerializedData(SerializedScriptValueFactory::instance().cr eateAndSwallowExceptions(info.GetIsolate(), dataArg));
84 }
85 }
86
87 } // namespace blink
OLDNEW
« 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