| 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/DartWindow.h" | |
| 32 | |
| 33 #include "bindings/core/dart/DartDOMWrapper.h" | |
| 34 #include "bindings/core/dart/DartEventListener.h" | |
| 35 #include "bindings/core/dart/DartFileReader.h" | |
| 36 #include "bindings/core/dart/DartHistory.h" | |
| 37 #include "bindings/core/dart/DartLocation.h" | |
| 38 #include "bindings/core/dart/DartScheduledAction.h" | |
| 39 #include "bindings/core/dart/DartUtilities.h" | |
| 40 #include "bindings/core/dart/DartWebKitCSSMatrix.h" | |
| 41 #include "bindings/core/dart/DartWebKitPoint.h" | |
| 42 #include "bindings/core/dart/DartXMLHttpRequest.h" | |
| 43 #include "core/css/CSSMatrix.h" | |
| 44 #include "core/dom/Document.h" | |
| 45 #include "core/dom/ExecutionContext.h" | |
| 46 #include "core/dom/MessagePort.h" | |
| 47 #include "core/fileapi/FileReader.h" | |
| 48 #include "core/frame/DOMTimer.h" | |
| 49 #include "core/frame/History.h" | |
| 50 #include "core/frame/LocalDOMWindow.h" | |
| 51 #include "core/frame/Location.h" | |
| 52 #include "core/xml/XMLHttpRequest.h" | |
| 53 | |
| 54 #include "wtf/OwnPtr.h" | |
| 55 | |
| 56 namespace blink { | |
| 57 | |
| 58 namespace DartWindowInternal { | |
| 59 | |
| 60 void eventGetter(Dart_NativeArguments) | |
| 61 { | |
| 62 // FIXME: proper implementation. | |
| 63 DART_UNIMPLEMENTED(); | |
| 64 } | |
| 65 | |
| 66 void eventSetter(Dart_NativeArguments) | |
| 67 { | |
| 68 // FIXME: proper implementation. | |
| 69 DART_UNIMPLEMENTED(); | |
| 70 } | |
| 71 | |
| 72 void historyCrossFrameGetter(Dart_NativeArguments args) | |
| 73 { | |
| 74 { | |
| 75 LocalDOMWindow* receiver = DartDOMWrapper::receiver<LocalDOMWindow>(args
); | |
| 76 DartDOMData* domData = static_cast<DartDOMData*>(Dart_GetNativeIsolateDa
ta(args)); | |
| 77 | |
| 78 Dart_WeakPersistentHandle existingWrapper = DartDOMWrapper::lookupWrappe
r<DartHistory>(domData, &receiver->history()); | |
| 79 if (existingWrapper) { | |
| 80 Dart_SetWeakHandleReturnValue(args, existingWrapper); | |
| 81 return; | |
| 82 } | |
| 83 | |
| 84 Dart_Handle result = DartDOMWrapper::createWrapper<DartHistory>( | |
| 85 domData, &receiver->history(), _HistoryCrossFrameClassId); | |
| 86 if (result) | |
| 87 Dart_SetReturnValue(args, result); | |
| 88 } | |
| 89 } | |
| 90 | |
| 91 void locationCrossFrameGetter(Dart_NativeArguments args) | |
| 92 { | |
| 93 { | |
| 94 LocalDOMWindow* receiver = DartDOMWrapper::receiver<LocalDOMWindow>(args
); | |
| 95 DartDOMData* domData = static_cast<DartDOMData*>(Dart_GetNativeIsolateDa
ta(args)); | |
| 96 | |
| 97 Dart_WeakPersistentHandle existingWrapper = DartDOMWrapper::lookupWrappe
r<DartLocation>(domData, &receiver->location()); | |
| 98 if (existingWrapper) { | |
| 99 Dart_SetWeakHandleReturnValue(args, existingWrapper); | |
| 100 return; | |
| 101 } | |
| 102 | |
| 103 Dart_Handle result = DartDOMWrapper::createWrapper<DartLocation>( | |
| 104 domData, &receiver->location(), _LocationCrossFrameClassId); | |
| 105 if (result) | |
| 106 Dart_SetReturnValue(args, result); | |
| 107 } | |
| 108 } | |
| 109 | |
| 110 void locationSetter(Dart_NativeArguments args) | |
| 111 { | |
| 112 Dart_Handle exception = 0; | |
| 113 { | |
| 114 LocalDOMWindow* receiver = DartDOMWrapper::receiver<LocalDOMWindow>(args
); | |
| 115 ASSERT(receiver == DartUtilities::domWindowForCurrentIsolate()); | |
| 116 | |
| 117 DartStringAdapter location = | |
| 118 DartUtilities::dartToString(args, 1, exception); | |
| 119 if (exception) | |
| 120 goto fail; | |
| 121 | |
| 122 receiver->setLocation(location, receiver, receiver); | |
| 123 return; | |
| 124 } | |
| 125 | |
| 126 fail: | |
| 127 Dart_ThrowException(exception); | |
| 128 ASSERT_NOT_REACHED(); | |
| 129 } | |
| 130 | |
| 131 void openCallback(Dart_NativeArguments args) | |
| 132 { | |
| 133 Dart_Handle exception = 0; | |
| 134 { | |
| 135 LocalDOMWindow* receiver = DartDOMWrapper::receiver<LocalDOMWindow>(args
); | |
| 136 ASSERT(receiver == DartUtilities::domWindowForCurrentIsolate()); | |
| 137 | |
| 138 DartStringAdapter url = DartUtilities::dartToString(args, 1, exception); | |
| 139 if (exception) | |
| 140 goto fail; | |
| 141 DartStringAdapter name = DartUtilities::dartToString(args, 2, exception)
; | |
| 142 if (exception) | |
| 143 goto fail; | |
| 144 DartStringAdapter options = DartUtilities::dartToStringWithNullCheck(arg
s, 3, exception); | |
| 145 if (exception) | |
| 146 goto fail; | |
| 147 | |
| 148 RefPtr<LocalDOMWindow> openedWindow = receiver->open(url, name, options,
receiver, receiver); | |
| 149 if (openedWindow) | |
| 150 DartWindow::returnToDart(args, openedWindow.release(), true); | |
| 151 return; | |
| 152 } | |
| 153 | |
| 154 fail: | |
| 155 Dart_ThrowException(exception); | |
| 156 ASSERT_NOT_REACHED(); | |
| 157 } | |
| 158 | |
| 159 void frameElementGetter(Dart_NativeArguments) | |
| 160 { | |
| 161 // FIXME: proper implementation. | |
| 162 DART_UNIMPLEMENTED(); | |
| 163 } | |
| 164 | |
| 165 void openerSetter(Dart_NativeArguments) | |
| 166 { | |
| 167 // FIXME: proper implementation. | |
| 168 DART_UNIMPLEMENTED(); | |
| 169 } | |
| 170 | |
| 171 void showModalDialogCallback(Dart_NativeArguments) | |
| 172 { | |
| 173 // FIXME: proper implementation. | |
| 174 DART_UNIMPLEMENTED(); | |
| 175 } | |
| 176 | |
| 177 void handlePostMessageCallback(Dart_NativeArguments args, bool extendedTransfer) | |
| 178 { | |
| 179 Dart_Handle exception = 0; | |
| 180 { | |
| 181 LocalDOMWindow* receiver = DartDOMWrapper::receiver<LocalDOMWindow>(args
); | |
| 182 | |
| 183 LocalDOMWindow* source = DartUtilities::domWindowForCurrentIsolate(); | |
| 184 ASSERT(source); | |
| 185 ASSERT(source->frame()); | |
| 186 | |
| 187 MessagePortArray portArray; | |
| 188 ArrayBufferArray bufferArray; | |
| 189 if (!Dart_IsNull(Dart_GetNativeArgument(args, 3))) { | |
| 190 DartUtilities::toMessagePortArray(Dart_GetNativeArgument(args, 3), p
ortArray, bufferArray, exception); | |
| 191 if (exception) | |
| 192 goto fail; | |
| 193 } | |
| 194 | |
| 195 RefPtr<SerializedScriptValue> message = DartUtilities::toSerializedScrip
tValue( | |
| 196 Dart_GetNativeArgument(args, 1), | |
| 197 &portArray, | |
| 198 extendedTransfer ? &bufferArray : 0, | |
| 199 exception); | |
| 200 if (exception) | |
| 201 goto fail; | |
| 202 | |
| 203 DartStringAdapter targetOrigin = DartUtilities::dartToString(args, 2, ex
ception); | |
| 204 if (exception) | |
| 205 goto fail; | |
| 206 | |
| 207 DartExceptionState es; | |
| 208 receiver->postMessage(message.release(), &portArray, targetOrigin, sourc
e, es); | |
| 209 if (es.hadException()) { | |
| 210 exception = es.toDart(args); | |
| 211 goto fail; | |
| 212 } | |
| 213 | |
| 214 return; | |
| 215 } | |
| 216 | |
| 217 fail: | |
| 218 Dart_ThrowException(exception); | |
| 219 ASSERT_NOT_REACHED(); | |
| 220 } | |
| 221 | |
| 222 void postMessageCallback(Dart_NativeArguments args) | |
| 223 { | |
| 224 handlePostMessageCallback(args, false); | |
| 225 } | |
| 226 | |
| 227 void webkitPostMessageCallback(Dart_NativeArguments args) | |
| 228 { | |
| 229 handlePostMessageCallback(args, true); | |
| 230 } | |
| 231 | |
| 232 // NOTE: if throws exception, doesn't unwind the stack, should be called with ca
ution! | |
| 233 static void windowSetTimeoutImpl(Dart_NativeArguments args, bool singleShot) | |
| 234 { | |
| 235 Dart_Handle exception = 0; | |
| 236 { | |
| 237 LocalDOMWindow* receiver = DartDOMWrapper::receiver<LocalDOMWindow>(args
); | |
| 238 ASSERT(receiver == DartUtilities::domWindowForCurrentIsolate()); | |
| 239 | |
| 240 Dart_Handle callback = Dart_GetNativeArgument(args, 1); | |
| 241 if (!Dart_IsClosure(callback)) { | |
| 242 exception = Dart_NewStringFromCString("Not a Dart closure passed"); | |
| 243 goto fail; | |
| 244 } | |
| 245 | |
| 246 int timeout = DartUtilities::dartToInt(Dart_GetNativeArgument(args, 2),
exception); | |
| 247 if (exception) | |
| 248 goto fail; | |
| 249 | |
| 250 ExecutionContext* context = receiver->document(); | |
| 251 ASSERT(context); | |
| 252 OwnPtr<DartScheduledAction> action = adoptPtr(new DartScheduledAction(Da
rt_CurrentIsolate(), callback)); | |
| 253 int id = DOMTimer::install(context, action.release(), timeout, singleSho
t); | |
| 254 Dart_SetReturnValue(args, DartUtilities::intToDart(id)); | |
| 255 return; | |
| 256 } | |
| 257 | |
| 258 fail: | |
| 259 Dart_ThrowException(exception); | |
| 260 ASSERT_NOT_REACHED(); | |
| 261 } | |
| 262 | |
| 263 void setTimeoutCallback(Dart_NativeArguments args) | |
| 264 { | |
| 265 windowSetTimeoutImpl(args, true /* singleShot */); | |
| 266 } | |
| 267 | |
| 268 void setIntervalCallback(Dart_NativeArguments args) | |
| 269 { | |
| 270 windowSetTimeoutImpl(args, false /* singleShot */); | |
| 271 } | |
| 272 | |
| 273 void addEventListenerCallback(Dart_NativeArguments args) | |
| 274 { | |
| 275 Dart_Handle exception = 0; | |
| 276 { | |
| 277 LocalDOMWindow* receiver = DartDOMWrapper::receiver<LocalDOMWindow>(args
); | |
| 278 ASSERT(receiver == DartUtilities::domWindowForCurrentIsolate()); | |
| 279 | |
| 280 DartStringAdapter type = DartUtilities::dartToString(args, 1, exception)
; | |
| 281 if (exception) | |
| 282 goto fail; | |
| 283 EventListener* listener = DartEventListener::toNative(Dart_GetNativeArgu
ment(args, 2), exception); | |
| 284 if (exception) | |
| 285 goto fail; | |
| 286 bool useCapture = DartUtilities::dartToBool(Dart_GetNativeArgument(args,
3), exception); | |
| 287 if (exception) | |
| 288 goto fail; | |
| 289 | |
| 290 receiver->addEventListener(type, listener, useCapture); | |
| 291 return; | |
| 292 } | |
| 293 | |
| 294 fail: | |
| 295 Dart_ThrowException(exception); | |
| 296 ASSERT_NOT_REACHED(); | |
| 297 } | |
| 298 | |
| 299 void removeEventListenerCallback(Dart_NativeArguments args) | |
| 300 { | |
| 301 Dart_Handle exception = 0; | |
| 302 { | |
| 303 LocalDOMWindow* receiver = DartDOMWrapper::receiver<LocalDOMWindow>(args
); | |
| 304 ASSERT(receiver == DartUtilities::domWindowForCurrentIsolate()); | |
| 305 | |
| 306 DartStringAdapter type = DartUtilities::dartToString(args, 1, exception)
; | |
| 307 if (exception) | |
| 308 goto fail; | |
| 309 EventListener* listener = DartEventListener::toNative(Dart_GetNativeArgu
ment(args, 2), exception); | |
| 310 if (exception) | |
| 311 goto fail; | |
| 312 bool useCapture = DartUtilities::dartToBool(Dart_GetNativeArgument(args,
3), exception); | |
| 313 if (exception) | |
| 314 goto fail; | |
| 315 | |
| 316 receiver->removeEventListener(type, listener, useCapture); | |
| 317 return; | |
| 318 } | |
| 319 | |
| 320 fail: | |
| 321 Dart_ThrowException(exception); | |
| 322 ASSERT_NOT_REACHED(); | |
| 323 } | |
| 324 | |
| 325 void toStringCallback(Dart_NativeArguments args) | |
| 326 { | |
| 327 // FIXME: proper implementation. | |
| 328 Dart_SetReturnValue(args, Dart_NewStringFromCString("<window>")); | |
| 329 } | |
| 330 | |
| 331 void ___getter___2Callback(Dart_NativeArguments) | |
| 332 { | |
| 333 // FIXME: proper implementation. | |
| 334 DART_UNIMPLEMENTED(); | |
| 335 } | |
| 336 | |
| 337 } | |
| 338 | |
| 339 Dart_Handle DartWindow::createWrapper(DartDOMData* domData, LocalDOMWindow* wind
ow) | |
| 340 { | |
| 341 LocalDOMWindow* primaryWindow = DartUtilities::domWindowForCurrentIsolate(); | |
| 342 if (window == primaryWindow) { | |
| 343 return DartDOMWrapper::createWrapper<DartWindow>( | |
| 344 domData, window, WindowClassId); | |
| 345 } else { | |
| 346 return DartDOMWrapper::createWrapper<DartWindow>( | |
| 347 domData, window, _DOMWindowCrossFrameClassId); | |
| 348 } | |
| 349 } | |
| 350 | |
| 351 } | |
| OLD | NEW |