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 "DartDOMWindow.h" |
| 32 |
| 33 #include "DOMTimer.h" |
| 34 #include "DOMWindow.h" |
| 35 #include "DartDOMWindow.h" |
| 36 #include "DartDOMWrapper.h" |
| 37 #include "DartFileReader.h" |
| 38 #include "DartScheduledAction.h" |
| 39 #include "DartUtilities.h" |
| 40 #include "DartWebKitCSSMatrix.h" |
| 41 #include "DartWebKitPoint.h" |
| 42 #include "DartXMLHttpRequest.h" |
| 43 #include "Document.h" |
| 44 #include "FileReader.h" |
| 45 #include "History.h" |
| 46 #include "Location.h" |
| 47 #include "MessagePort.h" |
| 48 #include "OwnPtr.h" |
| 49 #include "ScriptExecutionContext.h" |
| 50 #include "SecurityOrigin.h" |
| 51 #include "WebKitCSSMatrix.h" |
| 52 #include "WebKitPoint.h" |
| 53 #include "XMLHttpRequest.h" |
| 54 |
| 55 namespace WebCore { |
| 56 |
| 57 namespace DartDOMWindowInternal { |
| 58 |
| 59 void eventGetter(Dart_NativeArguments) |
| 60 { |
| 61 // FIXME: proper implementation. |
| 62 DART_UNIMPLEMENTED(); |
| 63 } |
| 64 |
| 65 void historyCrossFrameGetter(Dart_NativeArguments args) |
| 66 { |
| 67 DartApiScope dartApiScope; |
| 68 { |
| 69 DOMWindow* receiver = DartDOMWrapper::receiver< DOMWindow >(args); |
| 70 |
| 71 Dart_Handle result = DartDOMWrapper::toDart(receiver->history(), "Histor
yCrossFrameImplementation"); |
| 72 if (result) |
| 73 Dart_SetReturnValue(args, result); |
| 74 } |
| 75 } |
| 76 |
| 77 void locationCrossFrameGetter(Dart_NativeArguments args) |
| 78 { |
| 79 DartApiScope dartApiScope; |
| 80 { |
| 81 DOMWindow* receiver = DartDOMWrapper::receiver< DOMWindow >(args); |
| 82 |
| 83 Dart_Handle result = DartDOMWrapper::toDart(receiver->location(), "Locat
ionCrossFrameImplementation"); |
| 84 if (result) |
| 85 Dart_SetReturnValue(args, result); |
| 86 } |
| 87 } |
| 88 |
| 89 void locationSetter(Dart_NativeArguments args) |
| 90 { |
| 91 DartApiScope dartApiScope; |
| 92 Dart_Handle exception; |
| 93 { |
| 94 DOMWindow* receiver = DartDOMWrapper::receiver< DOMWindow >(args); |
| 95 ASSERT(receiver == DartUtilities::domWindowForCurrentIsolate()); |
| 96 |
| 97 const ParameterAdapter< String > location(Dart_GetNativeArgument(args, 1
)); |
| 98 if (!location.conversionSuccessful()) { |
| 99 exception = location.exception(); |
| 100 goto fail; |
| 101 } |
| 102 |
| 103 receiver->setLocation(location, receiver, receiver); |
| 104 return; |
| 105 } |
| 106 |
| 107 fail: |
| 108 Dart_ThrowException(exception); |
| 109 ASSERT_NOT_REACHED(); |
| 110 } |
| 111 |
| 112 void openCallback(Dart_NativeArguments args) |
| 113 { |
| 114 DartApiScope dartApiScope; |
| 115 Dart_Handle exception; |
| 116 { |
| 117 DOMWindow* receiver = DartDOMWrapper::receiver< DOMWindow >(args); |
| 118 ASSERT(receiver == DartUtilities::domWindowForCurrentIsolate()); |
| 119 |
| 120 const ParameterAdapter< String > url(Dart_GetNativeArgument(args, 1)); |
| 121 if (!url.conversionSuccessful()) { |
| 122 exception = url.exception(); |
| 123 goto fail; |
| 124 } |
| 125 const ParameterAdapter< String > name(Dart_GetNativeArgument(args, 2)); |
| 126 if (!name.conversionSuccessful()) { |
| 127 exception = name.exception(); |
| 128 goto fail; |
| 129 } |
| 130 const ParameterAdapter< String > options(Dart_GetNativeArgument(args, 3)
, DartUtilities::ConvertNullToEmptyString); |
| 131 if (!options.conversionSuccessful()) { |
| 132 exception = options.exception(); |
| 133 goto fail; |
| 134 } |
| 135 |
| 136 RefPtr<DOMWindow> openedWindow = receiver->open(url, name, options, rece
iver, receiver); |
| 137 if (openedWindow) |
| 138 DartDOMWrapper::returnValue(args, openedWindow.release()); |
| 139 return; |
| 140 } |
| 141 |
| 142 fail: |
| 143 Dart_ThrowException(exception); |
| 144 ASSERT_NOT_REACHED(); |
| 145 } |
| 146 |
| 147 void showModalDialogCallback(Dart_NativeArguments) |
| 148 { |
| 149 // FIXME: proper implementation. |
| 150 DART_UNIMPLEMENTED(); |
| 151 } |
| 152 |
| 153 void postMessageCallback(Dart_NativeArguments args) |
| 154 { |
| 155 DartApiScope dartApiScope; |
| 156 Dart_Handle exception; |
| 157 { |
| 158 DOMWindow* receiver = DartDOMWrapper::receiver< DOMWindow >(args); |
| 159 |
| 160 DOMWindow* source = DartUtilities::domWindowForCurrentIsolate(); |
| 161 ASSERT(source); |
| 162 ASSERT(source->frame()); |
| 163 |
| 164 ParameterAdapter< RefPtr<SerializedScriptValue> > message(Dart_GetNative
Argument(args, 1)); |
| 165 if (!message.conversionSuccessful()) { |
| 166 exception = message.exception(); |
| 167 goto fail; |
| 168 } |
| 169 |
| 170 // This function has variable arguments and can either be: |
| 171 // postMessage(message, ports, targetOrigin); |
| 172 // or |
| 173 // postMessage(message, targetOrigin); |
| 174 int targetOriginParameterNumber = 2; |
| 175 MessagePortArray portArray; |
| 176 if (!Dart_IsNull(Dart_GetNativeArgument(args, 3))) { |
| 177 exception = 0; |
| 178 DartUtilities::toMessagePortArray(Dart_GetNativeArgument(args, 2), p
ortArray, exception); |
| 179 if (exception) |
| 180 goto fail; |
| 181 targetOriginParameterNumber = 3; |
| 182 } |
| 183 |
| 184 const ParameterAdapter< String > targetOrigin(Dart_GetNativeArgument(arg
s, targetOriginParameterNumber)); |
| 185 if (!targetOrigin.conversionSuccessful()) { |
| 186 exception = targetOrigin.exception(); |
| 187 goto fail; |
| 188 } |
| 189 |
| 190 ExceptionCode ec = 0; |
| 191 receiver->postMessage(message.release(), &portArray, targetOrigin, sourc
e, ec); |
| 192 if (UNLIKELY(ec)) { |
| 193 exception = DartDOMWrapper::exceptionCodeToDartException(ec); |
| 194 goto fail; |
| 195 } |
| 196 |
| 197 return; |
| 198 } |
| 199 |
| 200 fail: |
| 201 Dart_ThrowException(exception); |
| 202 ASSERT_NOT_REACHED(); |
| 203 } |
| 204 |
| 205 void webkitPostMessageCallback(Dart_NativeArguments) |
| 206 { |
| 207 // FIXME: proper implementation. |
| 208 DART_UNIMPLEMENTED(); |
| 209 } |
| 210 |
| 211 // NOTE: if throws exception, doesn't unwind the stack, should be called with ca
ution! |
| 212 static void windowSetTimeoutImpl(Dart_NativeArguments args, bool singleShot) |
| 213 { |
| 214 DartApiScope dartApiScope; |
| 215 Dart_Handle exception; |
| 216 { |
| 217 DOMWindow* receiver = DartDOMWrapper::receiver< DOMWindow >(args); |
| 218 ASSERT(receiver == DartUtilities::domWindowForCurrentIsolate()); |
| 219 |
| 220 Dart_Handle callback = Dart_GetNativeArgument(args, 1); |
| 221 if (!Dart_IsClosure(callback)) { |
| 222 exception = Dart_NewString("Not a Dart closure passed"); |
| 223 goto fail; |
| 224 } |
| 225 |
| 226 const ParameterAdapter< int > timeout(Dart_GetNativeArgument(args, 2)); |
| 227 if (!timeout.conversionSuccessful()) { |
| 228 exception = timeout.exception(); |
| 229 goto fail; |
| 230 } |
| 231 |
| 232 ScriptExecutionContext* context = receiver->document(); |
| 233 ASSERT(context); |
| 234 OwnPtr<DartScheduledAction> action = adoptPtr(new DartScheduledAction(Da
rt_CurrentIsolate(), callback)); |
| 235 intptr_t id = DOMTimer::install(context, action.release(), timeout, sing
leShot); |
| 236 DartDOMWrapper::returnValue(args, id); |
| 237 return; |
| 238 } |
| 239 |
| 240 fail: |
| 241 Dart_ThrowException(exception); |
| 242 ASSERT_NOT_REACHED(); |
| 243 } |
| 244 |
| 245 void setTimeoutCallback(Dart_NativeArguments args) |
| 246 { |
| 247 windowSetTimeoutImpl(args, true /* singleShot */); |
| 248 } |
| 249 |
| 250 void setIntervalCallback(Dart_NativeArguments args) |
| 251 { |
| 252 windowSetTimeoutImpl(args, false /* singleShot */); |
| 253 } |
| 254 |
| 255 void addEventListenerCallback(Dart_NativeArguments args) |
| 256 { |
| 257 DartApiScope dartApiScope; |
| 258 Dart_Handle exception; |
| 259 { |
| 260 DOMWindow* receiver = DartDOMWrapper::receiver< DOMWindow >(args); |
| 261 ASSERT(receiver == DartUtilities::domWindowForCurrentIsolate()); |
| 262 |
| 263 const ParameterAdapter< String > type(Dart_GetNativeArgument(args, 1)); |
| 264 if (!type.conversionSuccessful()) { |
| 265 exception = type.exception(); |
| 266 goto fail; |
| 267 } |
| 268 const ParameterAdapter< RefPtr<EventListener> > listener(Dart_GetNativeA
rgument(args, 2)); |
| 269 if (!listener.conversionSuccessful()) { |
| 270 exception = listener.exception(); |
| 271 goto fail; |
| 272 } |
| 273 const ParameterAdapter< bool > useCapture(Dart_GetNativeArgument(args, 3
)); |
| 274 if (!useCapture.conversionSuccessful()) { |
| 275 exception = useCapture.exception(); |
| 276 goto fail; |
| 277 } |
| 278 |
| 279 receiver->addEventListener(type, listener, useCapture); |
| 280 return; |
| 281 } |
| 282 |
| 283 fail: |
| 284 Dart_ThrowException(exception); |
| 285 ASSERT_NOT_REACHED(); |
| 286 } |
| 287 |
| 288 void removeEventListenerCallback(Dart_NativeArguments args) |
| 289 { |
| 290 DartApiScope dartApiScope; |
| 291 Dart_Handle exception; |
| 292 { |
| 293 DOMWindow* receiver = DartDOMWrapper::receiver< DOMWindow >(args); |
| 294 ASSERT(receiver == DartUtilities::domWindowForCurrentIsolate()); |
| 295 |
| 296 const ParameterAdapter< String > type(Dart_GetNativeArgument(args, 1)); |
| 297 if (!type.conversionSuccessful()) { |
| 298 exception = type.exception(); |
| 299 goto fail; |
| 300 } |
| 301 const ParameterAdapter< RefPtr<EventListener> > listener(Dart_GetNativeA
rgument(args, 2)); |
| 302 if (!listener.conversionSuccessful()) { |
| 303 exception = listener.exception(); |
| 304 goto fail; |
| 305 } |
| 306 const ParameterAdapter< bool > useCapture(Dart_GetNativeArgument(args, 3
)); |
| 307 if (!useCapture.conversionSuccessful()) { |
| 308 exception = useCapture.exception(); |
| 309 goto fail; |
| 310 } |
| 311 |
| 312 receiver->removeEventListener(type, listener, useCapture); |
| 313 return; |
| 314 } |
| 315 |
| 316 fail: |
| 317 Dart_ThrowException(exception); |
| 318 ASSERT_NOT_REACHED(); |
| 319 } |
| 320 |
| 321 void toStringCallback(Dart_NativeArguments) |
| 322 { |
| 323 // FIXME: proper implementation. |
| 324 DART_UNIMPLEMENTED(); |
| 325 } |
| 326 |
| 327 } |
| 328 |
| 329 Dart_Handle toDartValue(DOMWindow* window) |
| 330 { |
| 331 return DartDOMWrapper::toDart(window, "DOMWindowCrossFrameImplementation"); |
| 332 } |
| 333 |
| 334 } |
OLD | NEW |