| Index: Source/bindings/dart/DartNativeUtilities.cpp
|
| diff --git a/Source/bindings/dart/DartNativeUtilities.cpp b/Source/bindings/dart/DartNativeUtilities.cpp
|
| index 9831cb7e39c92c099c78aca4bde905644b0262b6..d7a19e1ad006dfdd007bebaf9cee14bc87d98caa 100644
|
| --- a/Source/bindings/dart/DartNativeUtilities.cpp
|
| +++ b/Source/bindings/dart/DartNativeUtilities.cpp
|
| @@ -33,14 +33,19 @@
|
| #include "DartDOMData.h"
|
| #include "DartDOMStringMap.h"
|
| #include "DartDocument.h"
|
| +#include "DartElement.h"
|
| #include "DartWindow.h"
|
| #include "RuntimeEnabledFeatures.h"
|
| #include "bindings/dart/DartController.h"
|
| +#include "bindings/dart/DartCustomElementConstructorBuilder.h"
|
| +#include "bindings/dart/DartCustomElementLifecycleCallbacks.h"
|
| #include "bindings/dart/DartDOMWrapper.h"
|
| #include "bindings/dart/DartUtilities.h"
|
| #include "bindings/dart/V8Converter.h"
|
| #include "bindings/v8/ScriptController.h"
|
| #include "bindings/v8/npruntime_impl.h"
|
| +#include "core/dom/CustomElementCallbackDispatcher.h"
|
| +#include "core/dom/Document.h"
|
| #include "core/page/Frame.h"
|
|
|
| #include <bindings/npruntime.h>
|
| @@ -53,6 +58,8 @@
|
|
|
| namespace WebCore {
|
|
|
| +namespace DartNativeUtilitiesInternal {
|
| +
|
| static void topLevelWindow(Dart_NativeArguments args)
|
| {
|
| // Return full DOMWindow implementation (DartDOMWrapper::createWrapper always returns a secure wrapper).
|
| @@ -99,26 +106,76 @@ static void registerElement(Dart_NativeArguments args)
|
| DartApiScope dartApiScope;
|
| Dart_Handle exception = 0;
|
| {
|
| - DartStringAdapter tag = DartUtilities::dartToString(Dart_GetNativeArgument(args, 0), exception);
|
| + ScriptExecutionContext* scriptExecutionContext = DartUtilities::scriptExecutionContext();
|
| + ASSERT(scriptExecutionContext);
|
| +
|
| + Document* document = DartDocument::toNative(args, 0, exception);
|
| + if (exception)
|
| + goto fail;
|
| +
|
| + DartStringAdapter name = DartUtilities::dartToString(Dart_GetNativeArgument(args, 1), exception);
|
| if (exception)
|
| goto fail;
|
|
|
| - Dart_Handle customType = Dart_GetNativeArgument(args, 1);
|
| + Dart_Handle customType = Dart_GetNativeArgument(args, 2);
|
| ASSERT(Dart_IsType(customType));
|
|
|
| - Dart_Handle nativeType = Dart_GetNativeArgument(args, 2);
|
| - ASSERT(Dart_IsType(nativeType));
|
| + AtomicString extendsTagName;
|
| + Dart_Handle extendsArg = Dart_GetNativeArgument(args, 3);
|
| + if (!Dart_IsNull(extendsArg)) {
|
| + extendsTagName = DartUtilities::dartToString(extendsArg, exception);
|
| + if (exception) {
|
| + goto fail;
|
| + }
|
| + }
|
|
|
| - DartCustomElementMap* map = DartDOMData::current()->customElementMap();
|
| - if (map->contains(tag)) {
|
| - // FIXME: Wrap in a proper exception.
|
| - exception = Dart_NewStringFromCString("Element tag already registered");
|
| + CustomElementRegistrationContext* registrationContext = document->registrationContext();
|
| + if (!registrationContext) {
|
| + exception = DartDOMWrapper::exceptionCodeToDartException(NotSupportedError);
|
| goto fail;
|
| }
|
| - map->set(tag, Dart_NewPersistentHandle(customType));
|
|
|
| - DartCustomElementMap* baseMap = DartDOMData::current()->customBaseElementMap();
|
| - baseMap->set(tag, Dart_NewPersistentHandle(nativeType));
|
| + ScriptState* scriptState = ScriptState::forContext(DartUtilities::currentV8Context());
|
| +
|
| + const Dictionary dictionary;
|
| + DartCustomElementConstructorBuilder constructorBuilder(customType, extendsTagName, scriptState, &dictionary);
|
| + DartExceptionState es;
|
| + registrationContext->registerElement(document, &constructorBuilder, name, CustomElement::AllNames, es);
|
| + if (es.hadException()) {
|
| + exception = DartDOMWrapper::exceptionCodeToDartException(es);
|
| + goto fail;
|
| + }
|
| + return;
|
| + }
|
| +
|
| +fail:
|
| + Dart_ThrowException(exception);
|
| + ASSERT_NOT_REACHED();
|
| +}
|
| +
|
| +// Fast-path for Document.createElement, when typeExtension is not needed.
|
| +void createElement(Dart_NativeArguments args)
|
| +{
|
| + Dart_Handle exception = 0;
|
| + {
|
| + Document* receiver = DartDOMWrapper::receiver< Document >(args);
|
| +
|
| + DartStringAdapter localName = DartUtilities::dartToString(args, 1, exception);
|
| + if (exception)
|
| + goto fail;
|
| +
|
| + DartExceptionState es;
|
| + RefPtr<Element> result;
|
| + {
|
| + CustomElementCallbackDispatcher::CallbackDeliveryScope deliveryScope;
|
| +
|
| + result = receiver->createElement(localName, es);
|
| + }
|
| + DartElement::returnToDart(args, result);
|
| + if (es.hadException()) {
|
| + exception = DartDOMWrapper::exceptionCodeToDartException(es);
|
| + goto fail;
|
| + }
|
| return;
|
| }
|
|
|
| @@ -357,6 +414,8 @@ fail:
|
| ASSERT_NOT_REACHED();
|
| }
|
|
|
| +} // namespace DartNativeUtilitiesInternal
|
| +
|
| namespace DartWindowInternal {
|
|
|
| void historyCrossFrameGetter(Dart_NativeArguments);
|
| @@ -371,9 +430,9 @@ Dart_NativeFunction commonHtmlResolver(Dart_Handle name, int argumentCount)
|
| {
|
| String str = DartUtilities::toString(name);
|
| if (argumentCount == 2 && str == "Utils_spawnDomFunction")
|
| - return spawnDomFunction;
|
| + return DartNativeUtilitiesInternal::spawnDomFunction;
|
| if (argumentCount == 2 && str == "Utils_spawnDomUri")
|
| - return spawnDomUri;
|
| + return DartNativeUtilitiesInternal::spawnDomUri;
|
| return 0;
|
| }
|
|
|
| @@ -389,19 +448,21 @@ Dart_NativeFunction domIsolateHtmlResolver(Dart_Handle name, int argumentCount)
|
|
|
| String str = DartUtilities::toString(name);
|
| if (argumentCount == 0 && str == "Utils_window")
|
| - return topLevelWindow;
|
| + return DartNativeUtilitiesInternal::topLevelWindow;
|
| if (argumentCount == 1 && str == "Utils_forwardingPrint")
|
| - return forwardingPrint;
|
| + return DartNativeUtilitiesInternal::forwardingPrint;
|
| if (argumentCount == 0 && str == "Utils_getNewIsolateId")
|
| - return getNewIsolateId;
|
| - if (argumentCount == 3 && str == "Utils_register")
|
| - return registerElement;
|
| + return DartNativeUtilitiesInternal::getNewIsolateId;
|
| + if (argumentCount == 4 && str == "Utils_register")
|
| + return DartNativeUtilitiesInternal::registerElement;
|
| + if (argumentCount == 2 && str == "Utils_createElement")
|
| + return DartNativeUtilitiesInternal::createElement;
|
| if (argumentCount == 1 && str == "NPObject_retrieve")
|
| - return npObjectRetrieve;
|
| + return DartNativeUtilitiesInternal::npObjectRetrieve;
|
| if (argumentCount == 2 && str == "NPObject_property")
|
| - return npObjectProperty;
|
| + return DartNativeUtilitiesInternal::npObjectProperty;
|
| if (argumentCount == 3 && str == "NPObject_invoke")
|
| - return npObjectInvoke;
|
| + return DartNativeUtilitiesInternal::npObjectInvoke;
|
| if (argumentCount == 1 && str == "Window_history_cross_frame_Getter")
|
| return DartWindowInternal::historyCrossFrameGetter;
|
| if (argumentCount == 1 && str == "Window_location_cross_frame_Getter")
|
|
|