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

Side by Side Diff: Source/WebCore/bindings/dart/DartClassInfo.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 unified diff | Download patch
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 "DartClassInfo.h"
32
33 #include "DartDOMWindow.h"
34 #include "DartDOMWrapper.h"
35 #include "DartIsolateState.h"
36 #include "DartUtilities.h"
37 #include "PlatformString.h"
38 #include "npruntime_impl.h"
39 #include <bindings/npruntime.h>
40 #include <dart_api.h>
41 #include <wtf/HashMap.h>
42 #include <wtf/OwnArrayPtr.h>
43 #include <wtf/StdLibExtras.h>
44 #include <wtf/text/CString.h>
45 #include <wtf/text/StringHash.h>
46
47 namespace WebCore {
48
49 struct ClassInfo {
50 const char* className;
51 const char* classScript;
52 const Dart_NativeEntryResolver resolver;
53
54 ClassInfo(const char* className, const char* classScript, const Dart_NativeE ntryResolver resolver)
55 : className(className)
56 , classScript(classScript)
57 , resolver(resolver) { }
58 };
59
60 typedef Vector<ClassInfo> ClassInfos;
61 static ClassInfos& getClassInfos()
62 {
63 DEFINE_STATIC_LOCAL(ClassInfos, classInfos, ());
64 return classInfos;
65 }
66
67 void DartClassInfo::registerClass(const char* className, const char* classScript , const Dart_NativeEntryResolver resolver)
68 {
69 getClassInfos().append(ClassInfo(className, classScript, resolver));
70 }
71
72 static void topLevelWindow(Dart_NativeArguments args)
73 {
74 DartApiScope dartApiScope;
75 if (!DartUtilities::isFullDomIsolate(Dart_CurrentIsolate()))
76 Dart_ThrowException(DartUtilities::domDisabledException());
77
78 // Return full DOMWindow implementation (toDartValue(DOMWindow*) always retu rns secure wrapper).
79 Dart_Handle result = DartDOMWrapper::toDart<DartDOMWindow>(DartUtilities::do mWindowForCurrentIsolate());
80 if (result)
81 Dart_SetReturnValue(args, result);
82 }
83
84 static void npObjectGet(Dart_NativeArguments args)
85 {
86 DART_UNIMPLEMENTED();
87 }
88
89 static NPIdentifier getStringIdentifier(Dart_Handle id)
90 {
91 intptr_t length = 0;
92 // FIXME: add return value check.
93 Dart_StringLength(id, &length);
94 char* buffer = new char[length + 1];
95 Dart_StringGet8(id, reinterpret_cast<uint8_t*>(buffer), &length);
96 buffer[length] = '\0';
97 NPIdentifier result = _NPN_GetStringIdentifier(buffer);
98 delete [] buffer;
99 return result;
100 }
101
102 static void npObjectInvoke(Dart_NativeArguments args)
103 {
104 DartApiScope dartApiScope;
105 Dart_Handle exception;
106 {
107 NPObject* npObject = DartDOMWrapper::receiver< NPObject >(args);
108
109 if (!Dart_IsNull(Dart_GetNativeArgument(args, 2))) {
110 exception = DartUtilities::notImplementedException();
111 goto fail;
112 }
113
114 // FIXME: proper support for HTMLAppletElement and HTMLEmbedElement, see v8.
115
116 // FIXME: support argument conversion.
117 int numArgs = 0;
118 OwnArrayPtr<NPVariant> npArgs = adoptArrayPtr(new NPVariant[numArgs]);
119
120 NPVariant result;
121 VOID_TO_NPVARIANT(result);
122
123 bool retval = true;
124 if (npObject->_class->invoke) {
125 NPIdentifier identifier = getStringIdentifier(Dart_GetNativeArgument (args, 1));
126 retval = npObject->_class->invoke(npObject, identifier, npArgs.get() , numArgs, &result);
127 }
128
129 if (!retval) {
130 exception = Dart_NewString("Error calling method on NPObject.");
131 goto fail;
132 }
133
134 // FIXME: support return value conversion.
135
136 return;
137 }
138
139 fail:
140 Dart_ThrowException(exception);
141 ASSERT_NOT_REACHED();
142 }
143
144 namespace DartDOMWindowInternal {
145
146 void historyCrossFrameGetter(Dart_NativeArguments);
147
148 void locationCrossFrameGetter(Dart_NativeArguments);
149
150 }
151
152 static Dart_NativeFunction domResolver(Dart_Handle name, int argumentCount)
153 {
154 // FIXME: native for DOM helpers require a class on its own.
155 // FIXME: Hash for efficient lookup.
156 Dart_NativeFunction result = 0;
157 const ClassInfos& classInfos = getClassInfos();
158 for (size_t i = 0; i < classInfos.size(); i++) {
159 const ClassInfo& classInfo = classInfos[i];
160 if (classInfo.resolver) {
161 result = classInfo.resolver(name, argumentCount);
162 if (result)
163 return result;
164 }
165 }
166 // Some utility functions.
167 String str = DartUtilities::dartStringToString(name);
168 if (argumentCount == 0 && str == "TopLevel_Window")
169 return topLevelWindow;
170 if (argumentCount == 2 && str == "NPObject_get")
171 return npObjectGet;
172 if (argumentCount == 3 && str == "NPObject_invoke")
173 return npObjectInvoke;
174 if (argumentCount == 1 && str == "DOMWindow_history_cross_frame_Getter")
175 return DartDOMWindowInternal::historyCrossFrameGetter;
176 if (argumentCount == 1 && str == "DOMWindow_location_cross_frame_Getter")
177 return DartDOMWindowInternal::locationCrossFrameGetter;
178 return 0;
179 }
180
181 void DartClassInfo::registerClasses(Dart_Handle library)
182 {
183 const ClassInfos& classInfos = getClassInfos();
184 for (size_t i = 0; i < classInfos.size(); i++)
185 // FIXME: proper management of DOM library.
186 Dart_LoadSource(library, Dart_NewString(classInfos[i].className), Dart_N ewString(classInfos[i].classScript));
187 Dart_SetNativeResolver(library, domResolver);
188 }
189
190 }
OLDNEW
« no previous file with comments | « Source/WebCore/bindings/dart/DartClassInfo.h ('k') | Source/WebCore/bindings/dart/DartController.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698