| OLD | NEW |
| 1 // Copyright 2012, Google Inc. | 1 // Copyright 2012, Google Inc. |
| 2 // All rights reserved. | 2 // All rights reserved. |
| 3 // | 3 // |
| 4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
| 5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
| 6 // met: | 6 // met: |
| 7 // | 7 // |
| 8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
| 9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
| 10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | 29 |
| 30 #include "config.h" | 30 #include "config.h" |
| 31 #include "bindings/dart/DartNativeUtilities.h" | 31 #include "bindings/dart/DartNativeUtilities.h" |
| 32 | 32 |
| 33 #include "DartDOMData.h" | 33 #include "DartDOMData.h" |
| 34 #include "DartDOMStringMap.h" | 34 #include "DartDOMStringMap.h" |
| 35 #include "DartDocument.h" | 35 #include "DartDocument.h" |
| 36 #include "DartElement.h" |
| 36 #include "DartWindow.h" | 37 #include "DartWindow.h" |
| 37 #include "RuntimeEnabledFeatures.h" | 38 #include "RuntimeEnabledFeatures.h" |
| 38 #include "bindings/dart/DartController.h" | 39 #include "bindings/dart/DartController.h" |
| 40 #include "bindings/dart/DartCustomElementConstructorBuilder.h" |
| 41 #include "bindings/dart/DartCustomElementLifecycleCallbacks.h" |
| 39 #include "bindings/dart/DartDOMWrapper.h" | 42 #include "bindings/dart/DartDOMWrapper.h" |
| 40 #include "bindings/dart/DartUtilities.h" | 43 #include "bindings/dart/DartUtilities.h" |
| 41 #include "bindings/dart/V8Converter.h" | 44 #include "bindings/dart/V8Converter.h" |
| 42 #include "bindings/v8/ScriptController.h" | 45 #include "bindings/v8/ScriptController.h" |
| 43 #include "bindings/v8/npruntime_impl.h" | 46 #include "bindings/v8/npruntime_impl.h" |
| 47 #include "core/dom/CustomElementCallbackDispatcher.h" |
| 48 #include "core/dom/Document.h" |
| 44 #include "core/page/Frame.h" | 49 #include "core/page/Frame.h" |
| 45 | 50 |
| 46 #include <bindings/npruntime.h> | 51 #include <bindings/npruntime.h> |
| 47 #include <dart_api.h> | 52 #include <dart_api.h> |
| 48 #include <wtf/HashMap.h> | 53 #include <wtf/HashMap.h> |
| 49 #include <wtf/OwnArrayPtr.h> | 54 #include <wtf/OwnArrayPtr.h> |
| 50 #include <wtf/StdLibExtras.h> | 55 #include <wtf/StdLibExtras.h> |
| 51 #include <wtf/text/CString.h> | 56 #include <wtf/text/CString.h> |
| 52 #include <wtf/text/StringHash.h> | 57 #include <wtf/text/StringHash.h> |
| 53 | 58 |
| 54 namespace WebCore { | 59 namespace WebCore { |
| 55 | 60 |
| 61 namespace DartNativeUtilitiesInternal { |
| 62 |
| 56 static void topLevelWindow(Dart_NativeArguments args) | 63 static void topLevelWindow(Dart_NativeArguments args) |
| 57 { | 64 { |
| 58 // Return full DOMWindow implementation (DartDOMWrapper::createWrapper alway
s returns a secure wrapper). | 65 // Return full DOMWindow implementation (DartDOMWrapper::createWrapper alway
s returns a secure wrapper). |
| 59 DOMWindow* window = DartUtilities::domWindowForCurrentIsolate(); | 66 DOMWindow* window = DartUtilities::domWindowForCurrentIsolate(); |
| 60 DartDOMWrapper::returnToDart<DartWindow>(args, window); | 67 DartDOMWrapper::returnToDart<DartWindow>(args, window); |
| 61 } | 68 } |
| 62 | 69 |
| 63 /** | 70 /** |
| 64 * Gadget for testing. | 71 * Gadget for testing. |
| 65 * | 72 * |
| (...skipping 26 matching lines...) Expand all Loading... |
| 92 { | 99 { |
| 93 static int isolateId = 0; | 100 static int isolateId = 0; |
| 94 Dart_SetReturnValue(args, DartUtilities::intToDart(isolateId++)); | 101 Dart_SetReturnValue(args, DartUtilities::intToDart(isolateId++)); |
| 95 } | 102 } |
| 96 | 103 |
| 97 static void registerElement(Dart_NativeArguments args) | 104 static void registerElement(Dart_NativeArguments args) |
| 98 { | 105 { |
| 99 DartApiScope dartApiScope; | 106 DartApiScope dartApiScope; |
| 100 Dart_Handle exception = 0; | 107 Dart_Handle exception = 0; |
| 101 { | 108 { |
| 102 DartStringAdapter tag = DartUtilities::dartToString(Dart_GetNativeArgume
nt(args, 0), exception); | 109 ScriptExecutionContext* scriptExecutionContext = DartUtilities::scriptEx
ecutionContext(); |
| 110 ASSERT(scriptExecutionContext); |
| 111 |
| 112 Document* document = DartDocument::toNative(args, 0, exception); |
| 103 if (exception) | 113 if (exception) |
| 104 goto fail; | 114 goto fail; |
| 105 | 115 |
| 106 Dart_Handle customType = Dart_GetNativeArgument(args, 1); | 116 DartStringAdapter name = DartUtilities::dartToString(Dart_GetNativeArgum
ent(args, 1), exception); |
| 117 if (exception) |
| 118 goto fail; |
| 119 |
| 120 Dart_Handle customType = Dart_GetNativeArgument(args, 2); |
| 107 ASSERT(Dart_IsType(customType)); | 121 ASSERT(Dart_IsType(customType)); |
| 108 | 122 |
| 109 Dart_Handle nativeType = Dart_GetNativeArgument(args, 2); | 123 AtomicString extendsTagName; |
| 110 ASSERT(Dart_IsType(nativeType)); | 124 Dart_Handle extendsArg = Dart_GetNativeArgument(args, 3); |
| 125 if (!Dart_IsNull(extendsArg)) { |
| 126 extendsTagName = DartUtilities::dartToString(extendsArg, exception); |
| 127 if (exception) { |
| 128 goto fail; |
| 129 } |
| 130 } |
| 111 | 131 |
| 112 DartCustomElementMap* map = DartDOMData::current()->customElementMap(); | 132 CustomElementRegistrationContext* registrationContext = document->regist
rationContext(); |
| 113 if (map->contains(tag)) { | 133 if (!registrationContext) { |
| 114 // FIXME: Wrap in a proper exception. | 134 exception = DartDOMWrapper::exceptionCodeToDartException(NotSupporte
dError); |
| 115 exception = Dart_NewStringFromCString("Element tag already registere
d"); | |
| 116 goto fail; | 135 goto fail; |
| 117 } | 136 } |
| 118 map->set(tag, Dart_NewPersistentHandle(customType)); | |
| 119 | 137 |
| 120 DartCustomElementMap* baseMap = DartDOMData::current()->customBaseElemen
tMap(); | 138 ScriptState* scriptState = ScriptState::forContext(DartUtilities::curren
tV8Context()); |
| 121 baseMap->set(tag, Dart_NewPersistentHandle(nativeType)); | 139 |
| 140 const Dictionary dictionary; |
| 141 DartCustomElementConstructorBuilder constructorBuilder(customType, exten
dsTagName, scriptState, &dictionary); |
| 142 DartExceptionState es; |
| 143 registrationContext->registerElement(document, &constructorBuilder, name
, CustomElement::AllNames, es); |
| 144 if (es.hadException()) { |
| 145 exception = DartDOMWrapper::exceptionCodeToDartException(es); |
| 146 goto fail; |
| 147 } |
| 122 return; | 148 return; |
| 123 } | 149 } |
| 124 | 150 |
| 151 fail: |
| 152 Dart_ThrowException(exception); |
| 153 ASSERT_NOT_REACHED(); |
| 154 } |
| 155 |
| 156 // Fast-path for Document.createElement, when typeExtension is not needed. |
| 157 void createElement(Dart_NativeArguments args) |
| 158 { |
| 159 Dart_Handle exception = 0; |
| 160 { |
| 161 Document* receiver = DartDOMWrapper::receiver< Document >(args); |
| 162 |
| 163 DartStringAdapter localName = DartUtilities::dartToString(args, 1, excep
tion); |
| 164 if (exception) |
| 165 goto fail; |
| 166 |
| 167 DartExceptionState es; |
| 168 RefPtr<Element> result; |
| 169 { |
| 170 CustomElementCallbackDispatcher::CallbackDeliveryScope deliveryScope
; |
| 171 |
| 172 result = receiver->createElement(localName, es); |
| 173 } |
| 174 DartElement::returnToDart(args, result); |
| 175 if (es.hadException()) { |
| 176 exception = DartDOMWrapper::exceptionCodeToDartException(es); |
| 177 goto fail; |
| 178 } |
| 179 return; |
| 180 } |
| 181 |
| 125 fail: | 182 fail: |
| 126 Dart_ThrowException(exception); | 183 Dart_ThrowException(exception); |
| 127 ASSERT_NOT_REACHED(); | 184 ASSERT_NOT_REACHED(); |
| 128 } | 185 } |
| 129 | 186 |
| 130 static void npObjectRetrieve(Dart_NativeArguments args) | 187 static void npObjectRetrieve(Dart_NativeArguments args) |
| 131 { | 188 { |
| 132 Dart_Handle exception = 0; | 189 Dart_Handle exception = 0; |
| 133 { | 190 { |
| 134 DartStringAdapter key = DartUtilities::dartToString(Dart_GetNativeArgume
nt(args, 0), exception); | 191 DartStringAdapter key = DartUtilities::dartToString(Dart_GetNativeArgume
nt(args, 0), exception); |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 | 407 |
| 351 context->postTask(adoptPtr(new SpawnDomUriTask(targetUrl.string().ascii(
).data(), portId))); | 408 context->postTask(adoptPtr(new SpawnDomUriTask(targetUrl.string().ascii(
).data(), portId))); |
| 352 return; | 409 return; |
| 353 } | 410 } |
| 354 | 411 |
| 355 fail: | 412 fail: |
| 356 Dart_ThrowException(exception); | 413 Dart_ThrowException(exception); |
| 357 ASSERT_NOT_REACHED(); | 414 ASSERT_NOT_REACHED(); |
| 358 } | 415 } |
| 359 | 416 |
| 417 } // namespace DartNativeUtilitiesInternal |
| 418 |
| 360 namespace DartWindowInternal { | 419 namespace DartWindowInternal { |
| 361 | 420 |
| 362 void historyCrossFrameGetter(Dart_NativeArguments); | 421 void historyCrossFrameGetter(Dart_NativeArguments); |
| 363 | 422 |
| 364 void locationCrossFrameGetter(Dart_NativeArguments); | 423 void locationCrossFrameGetter(Dart_NativeArguments); |
| 365 | 424 |
| 366 } | 425 } |
| 367 | 426 |
| 368 extern Dart_NativeFunction htmlSnapshotResolver(Dart_Handle name, int argumentCo
unt); | 427 extern Dart_NativeFunction htmlSnapshotResolver(Dart_Handle name, int argumentCo
unt); |
| 369 | 428 |
| 370 Dart_NativeFunction commonHtmlResolver(Dart_Handle name, int argumentCount) | 429 Dart_NativeFunction commonHtmlResolver(Dart_Handle name, int argumentCount) |
| 371 { | 430 { |
| 372 String str = DartUtilities::toString(name); | 431 String str = DartUtilities::toString(name); |
| 373 if (argumentCount == 2 && str == "Utils_spawnDomFunction") | 432 if (argumentCount == 2 && str == "Utils_spawnDomFunction") |
| 374 return spawnDomFunction; | 433 return DartNativeUtilitiesInternal::spawnDomFunction; |
| 375 if (argumentCount == 2 && str == "Utils_spawnDomUri") | 434 if (argumentCount == 2 && str == "Utils_spawnDomUri") |
| 376 return spawnDomUri; | 435 return DartNativeUtilitiesInternal::spawnDomUri; |
| 377 return 0; | 436 return 0; |
| 378 } | 437 } |
| 379 | 438 |
| 380 Dart_NativeFunction domIsolateHtmlResolver(Dart_Handle name, int argumentCount) | 439 Dart_NativeFunction domIsolateHtmlResolver(Dart_Handle name, int argumentCount) |
| 381 { | 440 { |
| 382 // Some utility functions. | 441 // Some utility functions. |
| 383 if (Dart_NativeFunction func = commonHtmlResolver(name, argumentCount)) | 442 if (Dart_NativeFunction func = commonHtmlResolver(name, argumentCount)) |
| 384 return func; | 443 return func; |
| 385 if (Dart_NativeFunction func = htmlSnapshotResolver(name, argumentCount)) | 444 if (Dart_NativeFunction func = htmlSnapshotResolver(name, argumentCount)) |
| 386 return func; | 445 return func; |
| 387 if (Dart_NativeFunction func = DartDOMStringMap::resolver(name, argumentCoun
t)) | 446 if (Dart_NativeFunction func = DartDOMStringMap::resolver(name, argumentCoun
t)) |
| 388 return func; | 447 return func; |
| 389 | 448 |
| 390 String str = DartUtilities::toString(name); | 449 String str = DartUtilities::toString(name); |
| 391 if (argumentCount == 0 && str == "Utils_window") | 450 if (argumentCount == 0 && str == "Utils_window") |
| 392 return topLevelWindow; | 451 return DartNativeUtilitiesInternal::topLevelWindow; |
| 393 if (argumentCount == 1 && str == "Utils_forwardingPrint") | 452 if (argumentCount == 1 && str == "Utils_forwardingPrint") |
| 394 return forwardingPrint; | 453 return DartNativeUtilitiesInternal::forwardingPrint; |
| 395 if (argumentCount == 0 && str == "Utils_getNewIsolateId") | 454 if (argumentCount == 0 && str == "Utils_getNewIsolateId") |
| 396 return getNewIsolateId; | 455 return DartNativeUtilitiesInternal::getNewIsolateId; |
| 397 if (argumentCount == 3 && str == "Utils_register") | 456 if (argumentCount == 4 && str == "Utils_register") |
| 398 return registerElement; | 457 return DartNativeUtilitiesInternal::registerElement; |
| 458 if (argumentCount == 2 && str == "Utils_createElement") |
| 459 return DartNativeUtilitiesInternal::createElement; |
| 399 if (argumentCount == 1 && str == "NPObject_retrieve") | 460 if (argumentCount == 1 && str == "NPObject_retrieve") |
| 400 return npObjectRetrieve; | 461 return DartNativeUtilitiesInternal::npObjectRetrieve; |
| 401 if (argumentCount == 2 && str == "NPObject_property") | 462 if (argumentCount == 2 && str == "NPObject_property") |
| 402 return npObjectProperty; | 463 return DartNativeUtilitiesInternal::npObjectProperty; |
| 403 if (argumentCount == 3 && str == "NPObject_invoke") | 464 if (argumentCount == 3 && str == "NPObject_invoke") |
| 404 return npObjectInvoke; | 465 return DartNativeUtilitiesInternal::npObjectInvoke; |
| 405 if (argumentCount == 1 && str == "Window_history_cross_frame_Getter") | 466 if (argumentCount == 1 && str == "Window_history_cross_frame_Getter") |
| 406 return DartWindowInternal::historyCrossFrameGetter; | 467 return DartWindowInternal::historyCrossFrameGetter; |
| 407 if (argumentCount == 1 && str == "Window_location_cross_frame_Getter") | 468 if (argumentCount == 1 && str == "Window_location_cross_frame_Getter") |
| 408 return DartWindowInternal::locationCrossFrameGetter; | 469 return DartWindowInternal::locationCrossFrameGetter; |
| 409 return 0; | 470 return 0; |
| 410 } | 471 } |
| 411 | 472 |
| 412 } | 473 } |
| OLD | NEW |