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

Side by Side Diff: sky/engine/bindings/core/v8/custom/V8MessageEventCustom.cpp

Issue 676723003: Remove postMessage, MessageChannel and MessagePort. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 6 years, 2 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 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #include "config.h"
32 #include "bindings/core/v8/V8MessageEvent.h"
33
34 #include "bindings/core/v8/SerializedScriptValue.h"
35 #include "bindings/core/v8/V8Binding.h"
36 #include "bindings/core/v8/V8HiddenValue.h"
37 #include "bindings/core/v8/V8MessagePort.h"
38 #include "bindings/core/v8/V8Window.h"
39 #include "bindings/core/v8/custom/V8ArrayBufferCustom.h"
40 #include "core/events/MessageEvent.h"
41
42 namespace blink {
43
44 // Ensures a wrapper is created for the data to return now so that V8 knows how
45 // much memory is used via the wrapper. To keep the wrapper alive, it's set to
46 // the wrapper of the MessageEvent as a hidden value.
47 static void ensureWrapperCreatedAndAssociated(MessageEvent* eventImpl, v8::Handl e<v8::Object> eventWrapper, v8::Isolate* isolate)
48 {
49 switch (eventImpl->dataType()) {
50 case MessageEvent::DataTypeScriptValue:
51 case MessageEvent::DataTypeSerializedScriptValue:
52 break;
53 case MessageEvent::DataTypeString: {
54 String stringValue = eventImpl->dataAsString();
55 V8HiddenValue::setHiddenValue(isolate, eventWrapper, V8HiddenValue::stri ngData(isolate), v8String(isolate, stringValue));
56 break;
57 }
58 case MessageEvent::DataTypeArrayBuffer:
59 V8HiddenValue::setHiddenValue(isolate, eventWrapper, V8HiddenValue::arra yBufferData(isolate), toV8(eventImpl->dataAsArrayBuffer(), eventWrapper, isolate ));
60 break;
61 }
62 }
63
64 v8::Handle<v8::Object> wrap(MessageEvent* impl, v8::Handle<v8::Object> creationC ontext, v8::Isolate* isolate)
65 {
66 ASSERT(impl);
67 ASSERT(!DOMDataStore::containsWrapper<V8MessageEvent>(impl, isolate));
68 v8::Handle<v8::Object> wrapper = V8MessageEvent::createWrapper(impl, creatio nContext, isolate);
69 ensureWrapperCreatedAndAssociated(impl, wrapper, isolate);
70 return wrapper;
71 }
72
73 void V8MessageEvent::dataAttributeGetterCustom(const v8::PropertyCallbackInfo<v8 ::Value>& info)
74 {
75 MessageEvent* event = V8MessageEvent::toNative(info.Holder());
76
77 v8::Handle<v8::Value> result;
78 switch (event->dataType()) {
79 case MessageEvent::DataTypeScriptValue: {
80 result = V8HiddenValue::getHiddenValue(info.GetIsolate(), info.Holder(), V8HiddenValue::data(info.GetIsolate()));
81 if (result.IsEmpty()) {
82 if (!event->dataAsSerializedScriptValue()) {
83 // If we're in an isolated world and the event was created in th e main world,
84 // we need to find the 'data' property on the main world wrapper and clone it.
85 v8::Local<v8::Value> mainWorldData = V8HiddenValue::getHiddenVal ueFromMainWorldWrapper(info.GetIsolate(), event, V8HiddenValue::data(info.GetIso late()));
86 if (!mainWorldData.IsEmpty())
87 event->setSerializedData(SerializedScriptValue::createAndSwa llowExceptions(mainWorldData, info.GetIsolate()));
88 }
89 if (event->dataAsSerializedScriptValue())
90 result = event->dataAsSerializedScriptValue()->deserialize(info. GetIsolate());
91 else
92 result = v8::Null(info.GetIsolate());
93 }
94 break;
95 }
96
97 case MessageEvent::DataTypeSerializedScriptValue:
98 if (SerializedScriptValue* serializedValue = event->dataAsSerializedScri ptValue()) {
99 MessagePortArray ports = event->ports();
100 result = serializedValue->deserialize(info.GetIsolate(), &ports);
101 } else {
102 result = v8::Null(info.GetIsolate());
103 }
104 break;
105
106 case MessageEvent::DataTypeString: {
107 result = V8HiddenValue::getHiddenValue(info.GetIsolate(), info.Holder(), V8HiddenValue::stringData(info.GetIsolate()));
108 if (result.IsEmpty()) {
109 String stringValue = event->dataAsString();
110 result = v8String(info.GetIsolate(), stringValue);
111 }
112 break;
113 }
114
115 case MessageEvent::DataTypeArrayBuffer:
116 result = V8HiddenValue::getHiddenValue(info.GetIsolate(), info.Holder(), V8HiddenValue::arrayBufferData(info.GetIsolate()));
117 if (result.IsEmpty())
118 result = toV8(event->dataAsArrayBuffer(), info.Holder(), info.GetIso late());
119 break;
120 }
121
122 // Overwrite the data attribute so it returns the cached result in future in vocations.
123 // This custom getter handler will not be called again.
124 v8::PropertyAttribute dataAttr = static_cast<v8::PropertyAttribute>(v8::Dont Delete | v8::ReadOnly);
125 info.Holder()->ForceSet(v8AtomicString(info.GetIsolate(), "data"), result, d ataAttr);
126 v8SetReturnValue(info, result);
127 }
128
129 void V8MessageEvent::initMessageEventMethodCustom(const v8::FunctionCallbackInfo <v8::Value>& info)
130 {
131 MessageEvent* event = V8MessageEvent::toNative(info.Holder());
132 TOSTRING_VOID(V8StringResource<>, typeArg, info[0]);
133 TONATIVE_VOID(bool, canBubbleArg, info[1]->BooleanValue());
134 TONATIVE_VOID(bool, cancelableArg, info[2]->BooleanValue());
135 v8::Handle<v8::Value> dataArg = info[3];
136 TOSTRING_VOID(V8StringResource<>, originArg, info[4]);
137 TOSTRING_VOID(V8StringResource<>, lastEventIdArg, info[5]);
138 LocalDOMWindow* sourceArg = toDOMWindow(info[6], info.GetIsolate());
139 OwnPtrWillBeRawPtr<MessagePortArray> portArray = nullptr;
140 const int portArrayIndex = 7;
141 if (!isUndefinedOrNull(info[portArrayIndex])) {
142 portArray = adoptPtrWillBeNoop(new MessagePortArray);
143 bool success = false;
144 *portArray = toRefPtrWillBeMemberNativeArray<MessagePort, V8MessagePort> (info[portArrayIndex], portArrayIndex + 1, info.GetIsolate(), &success);
145 if (!success)
146 return;
147 }
148 event->initMessageEvent(typeArg, canBubbleArg, cancelableArg, originArg, las tEventIdArg, sourceArg, portArray.release());
149
150 if (!dataArg.IsEmpty()) {
151 V8HiddenValue::setHiddenValue(info.GetIsolate(), info.Holder(), V8Hidden Value::data(info.GetIsolate()), dataArg);
152 if (DOMWrapperWorld::current(info.GetIsolate()).isIsolatedWorld())
153 event->setSerializedData(SerializedScriptValue::createAndSwallowExce ptions(dataArg, info.GetIsolate()));
154 }
155 }
156
157 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698