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

Side by Side Diff: Source/WebCore/bindings/dart/DartDOMWrapper.cpp

Issue 9188009: Things to unfork. (Closed) Base URL: svn://svn.chromium.org/multivm/trunk/webkit
Patch Set: Created 8 years, 11 months 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2011, Google Inc.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above
11 // copyright notice, this list of conditions and the following disclaimer
12 // in the documentation and/or other materials provided with the
13 // distribution.
14 // * Neither the name of Google Inc. nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30 #include "config.h"
31 #include "DartDOMWrapper.h"
32
33 #include "CSSMutableStyleDeclaration.h"
34 #include "DartCSSStyleDeclaration.h"
35 #include "DartDOMCoreException.h"
36 #include "DartEventException.h"
37 #include "DartHTMLElement.h"
38 #include "DartNode.h"
39 #include "DartRangeException.h"
40 #include "DartUtilities.h"
41 #include "DartXMLHttpRequestException.h"
42 #include "DartXPathException.h"
43 #include "HTMLFormControlElement.h"
44
45 #include <stdio.h>
46 #include <wtf/text/WTFString.h>
47
48 #if ENABLE(SVG)
49 #include "DartSVGException.h"
50 #endif
51 #if ENABLE(XPATH)
52 #include "DartXPathException.h"
53 #endif
54 #if ENABLE(SQL_DATABASE)
55 #include "DartSQLException.h"
56 #endif
57 #if ENABLE(BLOB) || ENABLE(FILE_SYSTEM)
58 #include "DartFileException.h"
59 #include "DartOperationNotAllowedException.h"
60 #endif
61 #if ENABLE(INDEXED_DATABASE)
62 #include "DartIDBDatabaseException.h"
63 #endif
64
65 namespace WebCore {
66
67 void DartDOMWrapper::derefDOMObject(Dart_Handle wrapper, void* domObject)
68 {
69 ASSERT(domObject == readNativePointer(wrapper, kNativeImplementationIndex));
70 DerefObjectFunction derefObjectFunction = reinterpret_cast<DerefObjectFuncti on>(readNativePointer(wrapper, kDerefObjectFunctionIndex));
71 (*derefObjectFunction)(domObject);
72 }
73
74 Dart_Handle DartDOMWrapper::instantiateWrapper(const char* className)
75 {
76 // FIXME: this all is very ugly, but we're blocked by API here.
77 // In this case we need an API to invoke ctor, or even better,
78 // create an instance without exposing constructor at all.
79 String factoryMethodName = String("_create") + className;
80 Dart_Handle dom = Dart_LookupLibrary(Dart_NewString(DartUtilities::domLibrar yName));
81 ASSERT(!Dart_IsError(dom));
82
83 Dart_Handle instance = Dart_InvokeStatic(dom, Dart_NewString(className), Dar tUtilities::stringToDartString(factoryMethodName), 0, 0);
84 ASSERT(!Dart_IsError(instance));
85 return instance;
86 }
87
88 bool DartDOMWrapper::instanceOf(const char* dartImplementationClassName, Dart_Ha ndle wrapper, Dart_Handle& exception)
89 {
90 // FIXME: Cache classes in the corresponding bindings class. Requires persis tent handles.
91 Dart_Handle dom = DartUtilities::domLibraryForCurrentIsolate();
92 Dart_Handle cls = Dart_GetClass(dom, Dart_NewString(dartImplementationClassN ame));
93 if (Dart_IsError(cls)) {
94 exception = Dart_NewString(Dart_GetError(cls));
95 return false;
96 }
97
98 bool isInstanceOf = false;
99 Dart_Handle result = Dart_ObjectIsType(wrapper, cls, &isInstanceOf);
100 if (Dart_IsError(result)) {
101 exception = Dart_NewString(Dart_GetError(result));
102 return false;
103 }
104 if (!isInstanceOf) {
105 String message = String("Invalid class: expected ") + dartImplementation ClassName;
106 exception = DartUtilities::stringToDartString(message);
107 return false;
108 }
109
110 return true;
111 }
112
113 Dart_Handle DartDOMWrapper::exceptionCodeToDartException(ExceptionCode exception Code)
114 {
115 ASSERT(exceptionCode > 0);
116
117 ExceptionCodeDescription description(exceptionCode);
118
119 switch (description.type) {
120 case DOMCoreExceptionType:
121 return toDartValue(DOMCoreException::create(description));
122 case RangeExceptionType:
123 return toDartValue(RangeException::create(description));
124 case EventExceptionType:
125 return toDartValue(EventException::create(description));
126 case XMLHttpRequestExceptionType:
127 return toDartValue(XMLHttpRequestException::create(description));
128 #if ENABLE(SVG)
129 case SVGExceptionType:
130 return toDartValue(SVGException::create(description));
131 #endif
132 case XPathExceptionType:
133 return toDartValue(XPathException::create(description));
134 #if ENABLE(SQL_DATABASE)
135 case SQLExceptionType:
136 return toDartValue(SQLException::create(description));
137 #endif
138 #if ENABLE(BLOB) || ENABLE(FILE_SYSTEM)
139 case FileExceptionType:
140 return toDartValue(FileException::create(description));
141 case OperationNotAllowedExceptionType:
142 return toDartValue(OperationNotAllowedException::create(description));
143 #endif
144 #if ENABLE(INDEXED_DATABASE)
145 case IDBDatabaseExceptionType:
146 return toDartValue(IDBDatabaseException::create(description));
147 #endif
148 }
149
150 ASSERT_NOT_REACHED();
151 return Dart_NewString("Unknown WebCore exception");
152 }
153
154 Dart_Handle toDartValue(ContainerNode* value)
155 {
156 return toDartValue(static_cast<Node*>(value));
157 }
158
159 Dart_Handle toDartValue(CSSMutableStyleDeclaration* value)
160 {
161 return toDartValue(static_cast<CSSStyleDeclaration*>(value));
162 }
163
164 Dart_Handle toDartValue(HTMLFormControlElement* value)
165 {
166 return toDartValue(static_cast<HTMLElement*>(value));
167 }
168
169 Dart_Handle toDartValue(NPObject* object)
170 {
171 // FIXME: put NPObjects into a map as well.
172 return DartDOMWrapper::newWrapper("NPObject", object);
173 }
174
175 }
OLDNEW
« 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