Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(108)

Unified Diff: Source/WebCore/bindings/dart/DartDOMWrapper.cpp

Issue 8802010: Dart bindings for WebKit (Closed) Base URL: http://svn.webkit.org/repository/webkit/trunk
Patch Set: Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/WebCore/bindings/dart/DartDOMWrapper.h ('k') | Source/WebCore/bindings/dart/DartEventListener.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/WebCore/bindings/dart/DartDOMWrapper.cpp
diff --git a/Source/WebCore/bindings/dart/DartDOMWrapper.cpp b/Source/WebCore/bindings/dart/DartDOMWrapper.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..e71fbe94e1781d5a7ac520845ad057e6aab3fbd9
--- /dev/null
+++ b/Source/WebCore/bindings/dart/DartDOMWrapper.cpp
@@ -0,0 +1,174 @@
+// 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 "DartDOMWrapper.h"
+
+#include "CSSMutableStyleDeclaration.h"
+#include "DartCSSStyleDeclaration.h"
+#include "DartDOMCoreException.h"
+#include "DartEventException.h"
+#include "DartHTMLElement.h"
+#include "DartNode.h"
+#include "DartRangeException.h"
+#include "DartUtilities.h"
+#include "DartXMLHttpRequestException.h"
+#include "DartXPathException.h"
+#include "HTMLFormControlElement.h"
+#include <stdio.h>
+#include <wtf/text/WTFString.h>
+
+#if ENABLE(SVG)
+#include "DartSVGException.h"
+#endif
+#if ENABLE(XPATH)
+#include "DartXPathException.h"
+#endif
+#if ENABLE(SQL_DATABASE)
+#include "DartSQLException.h"
+#endif
+#if ENABLE(BLOB) || ENABLE(FILE_SYSTEM)
+#include "DartFileException.h"
+#include "DartOperationNotAllowedException.h"
+#endif
+#if ENABLE(INDEXED_DATABASE)
+#include "DartIDBDatabaseException.h"
+#endif
+
+namespace WebCore {
+
+void DartDOMWrapper::derefDOMObject(Dart_Handle wrapper, void* domObject)
+{
+ ASSERT(domObject == readNativePointer(wrapper, kNativeImplementationIndex));
+ DerefObjectFunction derefObjectFunction = reinterpret_cast<DerefObjectFunction>(readNativePointer(wrapper, kDerefObjectFunctionIndex));
+ (*derefObjectFunction)(domObject);
+}
+
+Dart_Handle DartDOMWrapper::instantiateWrapper(const char* className)
+{
+ // FIXME: this all is very ugly, but we're blocked by API here.
+ // In this case we need an API to invoke ctor, or even better,
+ // create an instance without exposing constructor at all.
+ String factoryMethodName = String("_create") + className;
+ Dart_Handle dom = Dart_LookupLibrary(Dart_NewString(DartUtilities::domLibraryName));
+ ASSERT(!Dart_IsError(dom));
+
+ Dart_Handle instance = Dart_InvokeStatic(dom, Dart_NewString(className), DartUtilities::stringToDartString(factoryMethodName), 0, 0);
+ ASSERT(!Dart_IsError(instance));
+ return instance;
+}
+
+bool DartDOMWrapper::instanceOf(const char* dartImplementationClassName, Dart_Handle wrapper, Dart_Handle& exception)
+{
+ // FIXME: Cache classes in the corresponding bindings class. Requires persistent handles.
+ Dart_Handle dom = DartUtilities::domLibraryForCurrentIsolate();
+ Dart_Handle cls = Dart_GetClass(dom, Dart_NewString(dartImplementationClassName));
+ if (Dart_IsError(cls)) {
+ exception = Dart_NewString(Dart_GetError(cls));
+ return false;
+ }
+
+ bool isInstanceOf = false;
+ Dart_Handle result = Dart_ObjectIsType(wrapper, cls, &isInstanceOf);
+ if (Dart_IsError(result)) {
+ exception = Dart_NewString(Dart_GetError(result));
+ return false;
+ }
+ if (!isInstanceOf) {
+ String message = String("Invalid class: expected ") + dartImplementationClassName;
+ exception = DartUtilities::stringToDartString(message);
+ return false;
+ }
+
+ return true;
+}
+
+Dart_Handle DartDOMWrapper::exceptionCodeToDartException(ExceptionCode exceptionCode)
+{
+ ASSERT(exceptionCode > 0);
+
+ ExceptionCodeDescription description(exceptionCode);
+
+ switch (description.type) {
+ case DOMCoreExceptionType:
+ return toDartValue(DOMCoreException::create(description));
+ case RangeExceptionType:
+ return toDartValue(RangeException::create(description));
+ case EventExceptionType:
+ return toDartValue(EventException::create(description));
+ case XMLHttpRequestExceptionType:
+ return toDartValue(XMLHttpRequestException::create(description));
+#if ENABLE(SVG)
+ case SVGExceptionType:
+ return toDartValue(SVGException::create(description));
+#endif
+ case XPathExceptionType:
+ return toDartValue(XPathException::create(description));
+#if ENABLE(SQL_DATABASE)
+ case SQLExceptionType:
+ return toDartValue(SQLException::create(description));
+#endif
+#if ENABLE(BLOB) || ENABLE(FILE_SYSTEM)
+ case FileExceptionType:
+ return toDartValue(FileException::create(description));
+ case OperationNotAllowedExceptionType:
+ return toDartValue(OperationNotAllowedException::create(description));
+#endif
+#if ENABLE(INDEXED_DATABASE)
+ case IDBDatabaseExceptionType:
+ return toDartValue(IDBDatabaseException::create(description));
+#endif
+ }
+
+ ASSERT_NOT_REACHED();
+ return Dart_NewString("Unknown WebCore exception");
+}
+
+Dart_Handle toDartValue(ContainerNode* value)
+{
+ return toDartValue(static_cast<Node*>(value));
+}
+
+Dart_Handle toDartValue(CSSMutableStyleDeclaration* value)
+{
+ return toDartValue(static_cast<CSSStyleDeclaration*>(value));
+}
+
+Dart_Handle toDartValue(HTMLFormControlElement* value)
+{
+ return toDartValue(static_cast<HTMLElement*>(value));
+}
+
+Dart_Handle toDartValue(NPObject* object)
+{
+ // FIXME: put NPObjects into a map as well.
+ return DartDOMWrapper::newWrapper("NPObject", object);
+}
+
+}
« no previous file with comments | « Source/WebCore/bindings/dart/DartDOMWrapper.h ('k') | Source/WebCore/bindings/dart/DartEventListener.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698