| Index: Source/WebCore/bindings/dart/DartClassInfo.cpp
|
| diff --git a/Source/WebCore/bindings/dart/DartClassInfo.cpp b/Source/WebCore/bindings/dart/DartClassInfo.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..73d6e6b4d59e58ee6ac5eae87c90c7414981a27d
|
| --- /dev/null
|
| +++ b/Source/WebCore/bindings/dart/DartClassInfo.cpp
|
| @@ -0,0 +1,190 @@
|
| +// Copyright 2011, 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
|
| +// met:
|
| +//
|
| +// * Redistributions of source code must retain the above copyright
|
| +// notice, this list of conditions and the following disclaimer.
|
| +// * Redistributions in binary form must reproduce the above
|
| +// copyright notice, this list of conditions and the following disclaimer
|
| +// in the documentation and/or other materials provided with the
|
| +// distribution.
|
| +// * Neither the name of Google Inc. nor the names of its
|
| +// contributors may be used to endorse or promote products derived from
|
| +// this software without specific prior written permission.
|
| +//
|
| +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
| +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
| +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
| +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
| +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| +
|
| +#include "config.h"
|
| +#include "DartClassInfo.h"
|
| +
|
| +#include "DartDOMWindow.h"
|
| +#include "DartDOMWrapper.h"
|
| +#include "DartIsolateState.h"
|
| +#include "DartUtilities.h"
|
| +#include "PlatformString.h"
|
| +#include "npruntime_impl.h"
|
| +#include <bindings/npruntime.h>
|
| +#include <dart_api.h>
|
| +#include <wtf/HashMap.h>
|
| +#include <wtf/OwnArrayPtr.h>
|
| +#include <wtf/StdLibExtras.h>
|
| +#include <wtf/text/CString.h>
|
| +#include <wtf/text/StringHash.h>
|
| +
|
| +namespace WebCore {
|
| +
|
| +struct ClassInfo {
|
| + const char* className;
|
| + const char* classScript;
|
| + const Dart_NativeEntryResolver resolver;
|
| +
|
| + ClassInfo(const char* className, const char* classScript, const Dart_NativeEntryResolver resolver)
|
| + : className(className)
|
| + , classScript(classScript)
|
| + , resolver(resolver) { }
|
| +};
|
| +
|
| +typedef Vector<ClassInfo> ClassInfos;
|
| +static ClassInfos& getClassInfos()
|
| +{
|
| + DEFINE_STATIC_LOCAL(ClassInfos, classInfos, ());
|
| + return classInfos;
|
| +}
|
| +
|
| +void DartClassInfo::registerClass(const char* className, const char* classScript, const Dart_NativeEntryResolver resolver)
|
| +{
|
| + getClassInfos().append(ClassInfo(className, classScript, resolver));
|
| +}
|
| +
|
| +static void topLevelWindow(Dart_NativeArguments args)
|
| +{
|
| + DartApiScope dartApiScope;
|
| + if (!DartUtilities::isFullDomIsolate(Dart_CurrentIsolate()))
|
| + Dart_ThrowException(DartUtilities::domDisabledException());
|
| +
|
| + // Return full DOMWindow implementation (toDartValue(DOMWindow*) always returns secure wrapper).
|
| + Dart_Handle result = DartDOMWrapper::toDart<DartDOMWindow>(DartUtilities::domWindowForCurrentIsolate());
|
| + if (result)
|
| + Dart_SetReturnValue(args, result);
|
| +}
|
| +
|
| +static void npObjectGet(Dart_NativeArguments args)
|
| +{
|
| + DART_UNIMPLEMENTED();
|
| +}
|
| +
|
| +static NPIdentifier getStringIdentifier(Dart_Handle id)
|
| +{
|
| + intptr_t length = 0;
|
| + // FIXME: add return value check.
|
| + Dart_StringLength(id, &length);
|
| + char* buffer = new char[length + 1];
|
| + Dart_StringGet8(id, reinterpret_cast<uint8_t*>(buffer), &length);
|
| + buffer[length] = '\0';
|
| + NPIdentifier result = _NPN_GetStringIdentifier(buffer);
|
| + delete [] buffer;
|
| + return result;
|
| +}
|
| +
|
| +static void npObjectInvoke(Dart_NativeArguments args)
|
| +{
|
| + DartApiScope dartApiScope;
|
| + Dart_Handle exception;
|
| + {
|
| + NPObject* npObject = DartDOMWrapper::receiver< NPObject >(args);
|
| +
|
| + if (!Dart_IsNull(Dart_GetNativeArgument(args, 2))) {
|
| + exception = DartUtilities::notImplementedException();
|
| + goto fail;
|
| + }
|
| +
|
| + // FIXME: proper support for HTMLAppletElement and HTMLEmbedElement, see v8.
|
| +
|
| + // FIXME: support argument conversion.
|
| + int numArgs = 0;
|
| + OwnArrayPtr<NPVariant> npArgs = adoptArrayPtr(new NPVariant[numArgs]);
|
| +
|
| + NPVariant result;
|
| + VOID_TO_NPVARIANT(result);
|
| +
|
| + bool retval = true;
|
| + if (npObject->_class->invoke) {
|
| + NPIdentifier identifier = getStringIdentifier(Dart_GetNativeArgument(args, 1));
|
| + retval = npObject->_class->invoke(npObject, identifier, npArgs.get(), numArgs, &result);
|
| + }
|
| +
|
| + if (!retval) {
|
| + exception = Dart_NewString("Error calling method on NPObject.");
|
| + goto fail;
|
| + }
|
| +
|
| + // FIXME: support return value conversion.
|
| +
|
| + return;
|
| + }
|
| +
|
| +fail:
|
| + Dart_ThrowException(exception);
|
| + ASSERT_NOT_REACHED();
|
| +}
|
| +
|
| +namespace DartDOMWindowInternal {
|
| +
|
| +void historyCrossFrameGetter(Dart_NativeArguments);
|
| +
|
| +void locationCrossFrameGetter(Dart_NativeArguments);
|
| +
|
| +}
|
| +
|
| +static Dart_NativeFunction domResolver(Dart_Handle name, int argumentCount)
|
| +{
|
| + // FIXME: native for DOM helpers require a class on its own.
|
| + // FIXME: Hash for efficient lookup.
|
| + Dart_NativeFunction result = 0;
|
| + const ClassInfos& classInfos = getClassInfos();
|
| + for (size_t i = 0; i < classInfos.size(); i++) {
|
| + const ClassInfo& classInfo = classInfos[i];
|
| + if (classInfo.resolver) {
|
| + result = classInfo.resolver(name, argumentCount);
|
| + if (result)
|
| + return result;
|
| + }
|
| + }
|
| + // Some utility functions.
|
| + String str = DartUtilities::dartStringToString(name);
|
| + if (argumentCount == 0 && str == "TopLevel_Window")
|
| + return topLevelWindow;
|
| + if (argumentCount == 2 && str == "NPObject_get")
|
| + return npObjectGet;
|
| + if (argumentCount == 3 && str == "NPObject_invoke")
|
| + return npObjectInvoke;
|
| + if (argumentCount == 1 && str == "DOMWindow_history_cross_frame_Getter")
|
| + return DartDOMWindowInternal::historyCrossFrameGetter;
|
| + if (argumentCount == 1 && str == "DOMWindow_location_cross_frame_Getter")
|
| + return DartDOMWindowInternal::locationCrossFrameGetter;
|
| + return 0;
|
| +}
|
| +
|
| +void DartClassInfo::registerClasses(Dart_Handle library)
|
| +{
|
| + const ClassInfos& classInfos = getClassInfos();
|
| + for (size_t i = 0; i < classInfos.size(); i++)
|
| + // FIXME: proper management of DOM library.
|
| + Dart_LoadSource(library, Dart_NewString(classInfos[i].className), Dart_NewString(classInfos[i].classScript));
|
| + Dart_SetNativeResolver(library, domResolver);
|
| +}
|
| +
|
| +}
|
|
|