| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2011, Google Inc. |
| 2 // 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 #include "config.h" |
| 31 #include "bindings/core/dart/DartMessageEvent.h" |
| 32 |
| 33 #include "bindings/core/dart/DartBlob.h" |
| 34 #include "bindings/core/dart/DartWindow.h" |
| 35 #include "bindings/core/dart/V8Converter.h" |
| 36 #include "bindings/core/v8/ScriptController.h" |
| 37 #include "bindings/dart/DartWebkitClassIds.h" |
| 38 |
| 39 namespace blink { |
| 40 |
| 41 Dart_Handle DartMessageEvent::createWrapper(DartDOMData* domData, MessageEvent*
event) |
| 42 { |
| 43 // The V8 custom method also appears to do some memory usage tracking. |
| 44 // FIXMEDART: implement the same sort of tracking for Dart. |
| 45 return DartDOMWrapper::createWrapper<DartMessageEvent>( |
| 46 domData, event, MessageEventClassId); |
| 47 } |
| 48 |
| 49 namespace DartMessageEventInternal { |
| 50 |
| 51 void dataGetter(Dart_NativeArguments args) |
| 52 { |
| 53 Dart_Handle exception = 0; |
| 54 { |
| 55 MessageEvent* receiver = DartDOMWrapper::receiver<MessageEvent>(args); |
| 56 |
| 57 Dart_Handle result = Dart_Null(); |
| 58 switch (receiver->dataType()) { |
| 59 case MessageEvent::DataTypeScriptValue: |
| 60 case MessageEvent::DataTypeSerializedScriptValue: { |
| 61 v8::Isolate* v8Isolate = v8::Isolate::GetCurrent(); |
| 62 v8::HandleScope handleScope(v8Isolate); |
| 63 v8::Context::Scope scope(toV8Context(DartUtilities::domWindowForCurr
entIsolate()->frame(), DOMWrapperWorld::mainWorld())); |
| 64 RefPtr<SerializedScriptValue> serializedValue = receiver->dataAsSeri
alizedScriptValue(); |
| 65 if (!serializedValue) |
| 66 break; |
| 67 MessagePortArray ports = receiver->ports(); |
| 68 result = V8Converter::toDart(serializedValue->deserialize(&ports), e
xception); |
| 69 if (exception) |
| 70 goto fail; |
| 71 break; |
| 72 } |
| 73 |
| 74 case MessageEvent::DataTypeString: |
| 75 DartUtilities::setDartStringReturnValue(args, receiver->dataAsString
()); |
| 76 return; |
| 77 |
| 78 case MessageEvent::DataTypeBlob: |
| 79 result = DartBlob::toDart(receiver->dataAsBlob()); |
| 80 break; |
| 81 |
| 82 case MessageEvent::DataTypeArrayBuffer: |
| 83 result = DartUtilities::arrayBufferToDart(receiver->dataAsArrayBuffe
r()); |
| 84 break; |
| 85 } |
| 86 // FIXME: cache the result. |
| 87 Dart_SetReturnValue(args, result); |
| 88 return; |
| 89 } |
| 90 |
| 91 fail: |
| 92 Dart_ThrowException(exception); |
| 93 ASSERT_NOT_REACHED(); |
| 94 } |
| 95 |
| 96 void initMessageEventCallback(Dart_NativeArguments args) |
| 97 { |
| 98 Dart_Handle exception = 0; |
| 99 { |
| 100 MessageEvent* receiver = DartDOMWrapper::receiver<MessageEvent>(args); |
| 101 |
| 102 DartStringAdapter typeArg = DartUtilities::dartToString(args, 1, excepti
on); |
| 103 if (exception) |
| 104 goto fail; |
| 105 |
| 106 bool canBubbleArg = DartUtilities::dartToBool(args, 2, exception); |
| 107 if (exception) |
| 108 goto fail; |
| 109 |
| 110 bool cancelableArg = DartUtilities::dartToBool(args, 3, exception); |
| 111 if (exception) |
| 112 goto fail; |
| 113 |
| 114 RefPtr<SerializedScriptValue> dataArg = DartUtilities::dartToSerializedS
criptValue(Dart_GetNativeArgument(args, 4), exception); |
| 115 if (exception) |
| 116 goto fail; |
| 117 |
| 118 DartStringAdapter originArg = DartUtilities::dartToString(args, 5, excep
tion); |
| 119 if (exception) |
| 120 goto fail; |
| 121 |
| 122 DartStringAdapter lastEventIdArg = DartUtilities::dartToString(args, 6,
exception); |
| 123 if (exception) |
| 124 goto fail; |
| 125 |
| 126 LocalDOMWindow* sourceArg = DartWindow::toNativeWithNullCheck(Dart_GetNa
tiveArgument(args, 7), exception); |
| 127 if (exception) |
| 128 goto fail; |
| 129 |
| 130 OwnPtr<MessagePortArray> portArray; |
| 131 if (!Dart_IsNull(Dart_GetNativeArgument(args, 8))) { |
| 132 portArray = adoptPtr(new MessagePortArray); |
| 133 ArrayBufferArray bufferArray; |
| 134 DartUtilities::toMessagePortArray(Dart_GetNativeArgument(args, 8), *
portArray, bufferArray, exception); |
| 135 if (exception) |
| 136 goto fail; |
| 137 if (bufferArray.size() > 0) { |
| 138 exception = Dart_NewStringFromCString("MessagePortArray argument
must contain only MessagePorts"); |
| 139 goto fail; |
| 140 } |
| 141 } |
| 142 |
| 143 receiver->initMessageEvent(typeArg, canBubbleArg, cancelableArg, dataArg
, originArg, lastEventIdArg, sourceArg, portArray.release()); |
| 144 return; |
| 145 } |
| 146 |
| 147 fail: |
| 148 Dart_ThrowException(exception); |
| 149 ASSERT_NOT_REACHED(); |
| 150 } |
| 151 |
| 152 } |
| 153 |
| 154 } |
| OLD | NEW |