| Index: Source/bindings/dart/DartNativeExtensions.cpp
|
| diff --git a/Source/bindings/dart/DartCallback.cpp b/Source/bindings/dart/DartNativeExtensions.cpp
|
| similarity index 55%
|
| copy from Source/bindings/dart/DartCallback.cpp
|
| copy to Source/bindings/dart/DartNativeExtensions.cpp
|
| index 7ad4cb2d957098fd994ceeb62c8745eed47fbe40..a3216f6d804610d15ccec6c6b5393ed4d1bbe694 100644
|
| --- a/Source/bindings/dart/DartCallback.cpp
|
| +++ b/Source/bindings/dart/DartNativeExtensions.cpp
|
| @@ -1,5 +1,5 @@
|
| /*
|
| - * Copyright (C) 2006-2011 Google Inc. All rights reserved.
|
| + * Copyright (C) 2014 Google Inc. All rights reserved.
|
| *
|
| * Redistribution and use in source and binary forms, with or without
|
| * modification, are permitted provided that the following conditions are
|
| @@ -29,48 +29,55 @@
|
| */
|
|
|
| #include "config.h"
|
| -#include "bindings/dart/DartCallback.h"
|
|
|
| -#include "bindings/dart/DartController.h"
|
| -#include "bindings/dart/DartDOMData.h"
|
| +#include "bindings/dart/DartNativeExtensions.h"
|
| +
|
| #include "bindings/dart/DartUtilities.h"
|
|
|
| namespace WebCore {
|
|
|
| -DartCallback::DartCallback(Dart_Handle object, Dart_Handle& exception)
|
| +#if defined(ENABLE_DART_NATIVE_EXTENSIONS)
|
| +Dart_Handle DartNativeExtensions::loadExtension(const String& url, Dart_Handle parentLibrary)
|
| {
|
| - if (!Dart_IsClosure(object)) {
|
| - exception = Dart_NewStringFromCString("Callback must be a function");
|
| - m_callback = 0;
|
| - return;
|
| - }
|
| - m_callback = Dart_NewPersistentHandle(object);
|
| -}
|
| + String userUri = url.substring(String("dart-ext:").length());
|
|
|
| -DartCallback::~DartCallback()
|
| -{
|
| - if (!m_callback || !isIsolateAlive())
|
| - return;
|
| -
|
| - DartIsolateScope scope(isolate());
|
| - Dart_DeletePersistentHandle(m_callback);
|
| -}
|
| + String name;
|
| + String path;
|
| + size_t index = userUri.reverseFind('/');
|
| + if (index == kNotFound) {
|
| + name = userUri;
|
| + path = "./";
|
| + } else if (index == userUri.length() - 1) {
|
| + return Dart_NewApiError("Extension name missing.");
|
| + } else {
|
| + name = userUri.substring(index + 1);
|
| + path = userUri.substring(0, index + 1);
|
| + }
|
|
|
| -bool DartCallback::handleEvent(int argc, Dart_Handle* argv)
|
| -{
|
| - ASSERT(isolate() == Dart_CurrentIsolate());
|
| - ASSERT(m_callback);
|
| + void* libraryHandle = 0;
|
| + Dart_Handle result = loadExtensionLibrary(path, name, &libraryHandle);
|
| + if (Dart_IsError(result)) {
|
| + return result;
|
| + }
|
|
|
| - ExecutionContext* context = DartDOMData::current()->scriptExecutionContext();
|
| - DartController* dartController = DartController::retrieve(context);
|
| + String initFunctionName = name + "_Init";
|
|
|
| - Dart_Handle result = dartController->callFunction(Dart_HandleFromPersistent(m_callback), argc, argv);
|
| + typedef Dart_Handle (*InitFunctionType)(Dart_Handle library);
|
| + InitFunctionType fn;
|
| + result = resolveSymbol(libraryHandle, initFunctionName, reinterpret_cast<void**>(&fn));
|
| if (Dart_IsError(result)) {
|
| - DartUtilities::reportProblem(context, result);
|
| - return false;
|
| + return result;
|
| }
|
|
|
| - return true;
|
| + return (*fn)(parentLibrary);
|
| }
|
| +#else
|
| +Dart_Handle DartNativeExtensions::loadExtension(const String& url, Dart_Handle parentLibrary)
|
| +{
|
| + return Dart_NewApiError("Native extensions are not enabled.");
|
| +}
|
| +#endif // defined(ENABLE_DART_NATIVE_EXTENSIONS)
|
|
|
| }
|
| +
|
| +
|
|
|