| 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 18 matching lines...) Expand all Loading... |
| 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 "DartWindow.h" | 36 #include "DartWindow.h" |
| 37 #include "RuntimeEnabledFeatures.h" | 37 #include "RuntimeEnabledFeatures.h" |
| 38 #include "bindings/dart/DartController.h" | 38 #include "bindings/dart/DartController.h" |
| 39 #include "bindings/dart/DartCustomElementConstructorBuilder.h" |
| 40 #include "bindings/dart/DartCustomElementLifecycleCallbacks.h" |
| 39 #include "bindings/dart/DartDOMWrapper.h" | 41 #include "bindings/dart/DartDOMWrapper.h" |
| 40 #include "bindings/dart/DartUtilities.h" | 42 #include "bindings/dart/DartUtilities.h" |
| 41 #include "bindings/dart/V8Converter.h" | 43 #include "bindings/dart/V8Converter.h" |
| 42 #include "bindings/v8/ScriptController.h" | 44 #include "bindings/v8/ScriptController.h" |
| 43 #include "bindings/v8/npruntime_impl.h" | 45 #include "bindings/v8/npruntime_impl.h" |
| 44 #include "core/page/Frame.h" | 46 #include "core/page/Frame.h" |
| 45 | 47 |
| 46 #include <bindings/npruntime.h> | 48 #include <bindings/npruntime.h> |
| 47 #include <dart_api.h> | 49 #include <dart_api.h> |
| 48 #include <wtf/HashMap.h> | 50 #include <wtf/HashMap.h> |
| 49 #include <wtf/OwnArrayPtr.h> | 51 #include <wtf/OwnArrayPtr.h> |
| 50 #include <wtf/StdLibExtras.h> | 52 #include <wtf/StdLibExtras.h> |
| 51 #include <wtf/text/CString.h> | 53 #include <wtf/text/CString.h> |
| 52 #include <wtf/text/StringHash.h> | 54 #include <wtf/text/StringHash.h> |
| 53 | 55 |
| 54 namespace WebCore { | 56 namespace WebCore { |
| 55 | 57 |
| 58 namespace DartNativeUtilitiesInternal { |
| 59 |
| 56 static void topLevelWindow(Dart_NativeArguments args) | 60 static void topLevelWindow(Dart_NativeArguments args) |
| 57 { | 61 { |
| 58 // Return full DOMWindow implementation (DartDOMWrapper::createWrapper alway
s returns a secure wrapper). | 62 // Return full DOMWindow implementation (DartDOMWrapper::createWrapper alway
s returns a secure wrapper). |
| 59 DOMWindow* window = DartUtilities::domWindowForCurrentIsolate(); | 63 DOMWindow* window = DartUtilities::domWindowForCurrentIsolate(); |
| 60 DartDOMWrapper::returnToDart<DartWindow>(args, window); | 64 DartDOMWrapper::returnToDart<DartWindow>(args, window); |
| 61 } | 65 } |
| 62 | 66 |
| 63 /** | 67 /** |
| 64 * Gadget for testing. | 68 * Gadget for testing. |
| 65 * | 69 * |
| (...skipping 26 matching lines...) Expand all Loading... |
| 92 { | 96 { |
| 93 static int isolateId = 0; | 97 static int isolateId = 0; |
| 94 Dart_SetReturnValue(args, DartUtilities::intToDart(isolateId++)); | 98 Dart_SetReturnValue(args, DartUtilities::intToDart(isolateId++)); |
| 95 } | 99 } |
| 96 | 100 |
| 97 static void registerElement(Dart_NativeArguments args) | 101 static void registerElement(Dart_NativeArguments args) |
| 98 { | 102 { |
| 99 DartApiScope dartApiScope; | 103 DartApiScope dartApiScope; |
| 100 Dart_Handle exception = 0; | 104 Dart_Handle exception = 0; |
| 101 { | 105 { |
| 102 DartStringAdapter tag = DartUtilities::dartToString(Dart_GetNativeArgume
nt(args, 0), exception); | 106 ScriptExecutionContext* scriptExecutionContext = DartUtilities::scriptEx
ecutionContext(); |
| 107 ASSERT(scriptExecutionContext); |
| 108 |
| 109 Document* document = DartDocument::toNative(args, 0, exception); |
| 103 if (exception) | 110 if (exception) |
| 104 goto fail; | 111 goto fail; |
| 105 | 112 |
| 106 Dart_Handle customType = Dart_GetNativeArgument(args, 1); | 113 DartStringAdapter name = DartUtilities::dartToString(Dart_GetNativeArgum
ent(args, 1), exception); |
| 114 if (exception) |
| 115 goto fail; |
| 116 |
| 117 Dart_Handle customType = Dart_GetNativeArgument(args, 2); |
| 107 ASSERT(Dart_IsType(customType)); | 118 ASSERT(Dart_IsType(customType)); |
| 108 | 119 |
| 109 Dart_Handle nativeType = Dart_GetNativeArgument(args, 2); | 120 AtomicString extendsTagName; |
| 110 ASSERT(Dart_IsType(nativeType)); | 121 Dart_Handle extendsArg = Dart_GetNativeArgument(args, 3); |
| 122 if (!Dart_IsNull(extendsArg)) { |
| 123 extendsTagName = DartUtilities::dartToString(extendsArg, exception); |
| 124 if (exception) { |
| 125 goto fail; |
| 126 } |
| 127 } |
| 111 | 128 |
| 112 DartCustomElementMap* map = DartDOMData::current()->customElementMap(); | 129 CustomElementRegistrationContext* registrationContext = document->regist
rationContext(); |
| 113 if (map->contains(tag)) { | 130 if (!registrationContext) { |
| 114 // FIXME: Wrap in a proper exception. | 131 exception = DartDOMWrapper::exceptionCodeToDartException(NotSupporte
dError); |
| 115 exception = Dart_NewStringFromCString("Element tag already registere
d"); | |
| 116 goto fail; | 132 goto fail; |
| 117 } | 133 } |
| 118 map->set(tag, Dart_NewPersistentHandle(customType)); | |
| 119 | 134 |
| 120 DartCustomElementMap* baseMap = DartDOMData::current()->customBaseElemen
tMap(); | 135 ScriptState* scriptState = ScriptState::forContext(DartUtilities::curren
tV8Context()); |
| 121 baseMap->set(tag, Dart_NewPersistentHandle(nativeType)); | 136 |
| 137 const Dictionary dictionary; |
| 138 DartCustomElementConstructorBuilder constructorBuilder(customType, exten
dsTagName, scriptState, &dictionary); |
| 139 DartExceptionState es; |
| 140 registrationContext->registerElement(document, &constructorBuilder, name
, CustomElement::AllNames, es); |
| 141 if (es.hadException()) { |
| 142 exception = DartDOMWrapper::exceptionCodeToDartException(es); |
| 143 goto fail; |
| 144 } |
| 122 return; | 145 return; |
| 123 } | 146 } |
| 124 | 147 |
| 125 fail: | 148 fail: |
| 126 Dart_ThrowException(exception); | 149 Dart_ThrowException(exception); |
| 127 ASSERT_NOT_REACHED(); | 150 ASSERT_NOT_REACHED(); |
| 128 } | 151 } |
| 129 | 152 |
| 130 static void npObjectRetrieve(Dart_NativeArguments args) | 153 static void npObjectRetrieve(Dart_NativeArguments args) |
| 131 { | 154 { |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 | 373 |
| 351 context->postTask(adoptPtr(new SpawnDomUriTask(targetUrl.string().ascii(
).data(), portId))); | 374 context->postTask(adoptPtr(new SpawnDomUriTask(targetUrl.string().ascii(
).data(), portId))); |
| 352 return; | 375 return; |
| 353 } | 376 } |
| 354 | 377 |
| 355 fail: | 378 fail: |
| 356 Dart_ThrowException(exception); | 379 Dart_ThrowException(exception); |
| 357 ASSERT_NOT_REACHED(); | 380 ASSERT_NOT_REACHED(); |
| 358 } | 381 } |
| 359 | 382 |
| 383 } // namespace DartNativeUtilitiesInternal |
| 384 |
| 360 namespace DartWindowInternal { | 385 namespace DartWindowInternal { |
| 361 | 386 |
| 362 void historyCrossFrameGetter(Dart_NativeArguments); | 387 void historyCrossFrameGetter(Dart_NativeArguments); |
| 363 | 388 |
| 364 void locationCrossFrameGetter(Dart_NativeArguments); | 389 void locationCrossFrameGetter(Dart_NativeArguments); |
| 365 | 390 |
| 366 } | 391 } |
| 367 | 392 |
| 368 extern Dart_NativeFunction htmlSnapshotResolver(Dart_Handle name, int argumentCo
unt); | 393 extern Dart_NativeFunction htmlSnapshotResolver(Dart_Handle name, int argumentCo
unt); |
| 369 | 394 |
| 370 Dart_NativeFunction commonHtmlResolver(Dart_Handle name, int argumentCount) | 395 Dart_NativeFunction commonHtmlResolver(Dart_Handle name, int argumentCount) |
| 371 { | 396 { |
| 372 String str = DartUtilities::toString(name); | 397 String str = DartUtilities::toString(name); |
| 373 if (argumentCount == 2 && str == "Utils_spawnDomFunction") | 398 if (argumentCount == 2 && str == "Utils_spawnDomFunction") |
| 374 return spawnDomFunction; | 399 return DartNativeUtilitiesInternal::spawnDomFunction; |
| 375 if (argumentCount == 2 && str == "Utils_spawnDomUri") | 400 if (argumentCount == 2 && str == "Utils_spawnDomUri") |
| 376 return spawnDomUri; | 401 return DartNativeUtilitiesInternal::spawnDomUri; |
| 377 return 0; | 402 return 0; |
| 378 } | 403 } |
| 379 | 404 |
| 380 Dart_NativeFunction domIsolateHtmlResolver(Dart_Handle name, int argumentCount) | 405 Dart_NativeFunction domIsolateHtmlResolver(Dart_Handle name, int argumentCount) |
| 381 { | 406 { |
| 382 // Some utility functions. | 407 // Some utility functions. |
| 383 if (Dart_NativeFunction func = commonHtmlResolver(name, argumentCount)) | 408 if (Dart_NativeFunction func = commonHtmlResolver(name, argumentCount)) |
| 384 return func; | 409 return func; |
| 385 if (Dart_NativeFunction func = htmlSnapshotResolver(name, argumentCount)) | 410 if (Dart_NativeFunction func = htmlSnapshotResolver(name, argumentCount)) |
| 386 return func; | 411 return func; |
| 387 if (Dart_NativeFunction func = DartDOMStringMap::resolver(name, argumentCoun
t)) | 412 if (Dart_NativeFunction func = DartDOMStringMap::resolver(name, argumentCoun
t)) |
| 388 return func; | 413 return func; |
| 389 | 414 |
| 390 String str = DartUtilities::toString(name); | 415 String str = DartUtilities::toString(name); |
| 391 if (argumentCount == 0 && str == "Utils_window") | 416 if (argumentCount == 0 && str == "Utils_window") |
| 392 return topLevelWindow; | 417 return DartNativeUtilitiesInternal::topLevelWindow; |
| 393 if (argumentCount == 1 && str == "Utils_forwardingPrint") | 418 if (argumentCount == 1 && str == "Utils_forwardingPrint") |
| 394 return forwardingPrint; | 419 return DartNativeUtilitiesInternal::forwardingPrint; |
| 395 if (argumentCount == 0 && str == "Utils_getNewIsolateId") | 420 if (argumentCount == 0 && str == "Utils_getNewIsolateId") |
| 396 return getNewIsolateId; | 421 return DartNativeUtilitiesInternal::getNewIsolateId; |
| 397 if (argumentCount == 3 && str == "Utils_register") | 422 if (argumentCount == 4 && str == "Utils_register") |
| 398 return registerElement; | 423 return DartNativeUtilitiesInternal::registerElement; |
| 399 if (argumentCount == 1 && str == "NPObject_retrieve") | 424 if (argumentCount == 1 && str == "NPObject_retrieve") |
| 400 return npObjectRetrieve; | 425 return DartNativeUtilitiesInternal::npObjectRetrieve; |
| 401 if (argumentCount == 2 && str == "NPObject_property") | 426 if (argumentCount == 2 && str == "NPObject_property") |
| 402 return npObjectProperty; | 427 return DartNativeUtilitiesInternal::npObjectProperty; |
| 403 if (argumentCount == 3 && str == "NPObject_invoke") | 428 if (argumentCount == 3 && str == "NPObject_invoke") |
| 404 return npObjectInvoke; | 429 return DartNativeUtilitiesInternal::npObjectInvoke; |
| 405 if (argumentCount == 1 && str == "Window_history_cross_frame_Getter") | 430 if (argumentCount == 1 && str == "Window_history_cross_frame_Getter") |
| 406 return DartWindowInternal::historyCrossFrameGetter; | 431 return DartWindowInternal::historyCrossFrameGetter; |
| 407 if (argumentCount == 1 && str == "Window_location_cross_frame_Getter") | 432 if (argumentCount == 1 && str == "Window_location_cross_frame_Getter") |
| 408 return DartWindowInternal::locationCrossFrameGetter; | 433 return DartWindowInternal::locationCrossFrameGetter; |
| 409 return 0; | 434 return 0; |
| 410 } | 435 } |
| 411 | 436 |
| 412 } | 437 } |
| OLD | NEW |