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