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

Side by Side Diff: webkit/glue/cpp_bound_class.cc

Issue 3175: Pass the invoked JavaScript method name as an argument to the fallback callback (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 12 years, 2 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
« no previous file with comments | « webkit/glue/cpp_bound_class.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This file contains definitions for CppBoundClass 5 // This file contains definitions for CppBoundClass
6 6
7 // Here's the control flow of a JS method getting forwarded to a class. 7 // Here's the control flow of a JS method getting forwarded to a class.
8 // - Something calls our NPObject with a function like "Invoke". 8 // - Something calls our NPObject with a function like "Invoke".
9 // - CppNPObject's static invoke() function forwards it to its attached 9 // - CppNPObject's static invoke() function forwards it to its attached
10 // CppBoundClass's Invoke() method. 10 // CppBoundClass's Invoke() method.
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 for (BoundObjectList::iterator i = bound_objects_.begin(); 147 for (BoundObjectList::iterator i = bound_objects_.begin();
148 i != bound_objects_.end(); ++i) { 148 i != bound_objects_.end(); ++i) {
149 #if USE(V8) 149 #if USE(V8)
150 _NPN_UnregisterObject(*i); 150 _NPN_UnregisterObject(*i);
151 #endif 151 #endif
152 NPN_ReleaseObject(*i); 152 NPN_ReleaseObject(*i);
153 } 153 }
154 } 154 }
155 155
156 bool CppBoundClass::HasMethod(NPIdentifier ident) { 156 bool CppBoundClass::HasMethod(NPIdentifier ident) {
157 return (methods_.find(ident) != methods_.end()); 157 return (methods_.find(ident) != methods_.end() || fallback_callback_.get());
Evan Martin 2008/10/07 18:26:42 I spoke with Feng. This is the only line we have
158 } 158 }
159 159
160 bool CppBoundClass::HasProperty(NPIdentifier ident) { 160 bool CppBoundClass::HasProperty(NPIdentifier ident) {
161 return (properties_.find(ident) != properties_.end()); 161 return (properties_.find(ident) != properties_.end());
162 } 162 }
163 163
164 bool CppBoundClass::Invoke(NPIdentifier ident, 164 bool CppBoundClass::Invoke(NPIdentifier ident,
165 const NPVariant* args, 165 const NPVariant* args,
166 size_t arg_count, 166 size_t arg_count,
167 NPVariant* result) { 167 NPVariant* result) {
168 MethodList::const_iterator method = methods_.find(ident); 168 MethodList::const_iterator method = methods_.find(ident);
169 Callback* callback; 169 Callback* callback;
170 bool inject_method_name = false;
170 if (method == methods_.end()) { 171 if (method == methods_.end()) {
171 if (fallback_callback_.get()) { 172 if (fallback_callback_.get()) {
172 callback = fallback_callback_.get(); 173 callback = fallback_callback_.get();
174 inject_method_name = true;
173 } else { 175 } else {
174 VOID_TO_NPVARIANT(*result); 176 VOID_TO_NPVARIANT(*result);
175 return false; 177 return false;
176 } 178 }
177 } else { 179 } else {
178 callback = (*method).second; 180 callback = (*method).second;
179 } 181 }
180 182
181 // Build a CppArgumentList argument vector from the NPVariants coming in. 183 // Build a CppArgumentList argument vector from the NPVariants coming in.
182 CppArgumentList cpp_args(arg_count); 184 size_t arg_offset = (inject_method_name ? 1 : 0);
183 for (size_t i = 0; i < arg_count; i++) 185 CppArgumentList cpp_args(arg_count + arg_offset);
184 cpp_args[i].Set(args[i]); 186 for (size_t i = arg_offset; i < arg_count + arg_offset; i++)
187 cpp_args[i].Set(args[i - arg_offset]);
188
189 // If the fallback is being called pass the JavaScript method name as the
190 // first argument.
191 if (inject_method_name) {
192 NPUTF8* name = NPN_UTF8FromIdentifier(ident);
193 cpp_args[0].Set(name);
194 free(name);
195 }
185 196
186 CppVariant cpp_result; 197 CppVariant cpp_result;
187 callback->Run(cpp_args, &cpp_result); 198 callback->Run(cpp_args, &cpp_result);
188 199
189 cpp_result.CopyToNPVariant(result); 200 cpp_result.CopyToNPVariant(result);
190 return true; 201 return true;
191 } 202 }
192 203
193 bool CppBoundClass::GetProperty(NPIdentifier ident, NPVariant* result) { 204 bool CppBoundClass::GetProperty(NPIdentifier ident, NPVariant* result) {
194 PropertyList::const_iterator prop = properties_.find(ident); 205 PropertyList::const_iterator prop = properties_.find(ident);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 NPObject* np_obj = NPN_CreateObject(0, &CppNPObject::np_class_); 257 NPObject* np_obj = NPN_CreateObject(0, &CppNPObject::np_class_);
247 CppNPObject* obj = reinterpret_cast<CppNPObject*>(np_obj); 258 CppNPObject* obj = reinterpret_cast<CppNPObject*>(np_obj);
248 obj->bound_class = this; 259 obj->bound_class = this;
249 260
250 // BindToWindowObject will (indirectly) retain the np_object. We save it 261 // BindToWindowObject will (indirectly) retain the np_object. We save it
251 // so we can release it when we're destroyed. 262 // so we can release it when we're destroyed.
252 frame->BindToWindowObject(classname, np_obj); 263 frame->BindToWindowObject(classname, np_obj);
253 bound_objects_.push_back(np_obj); 264 bound_objects_.push_back(np_obj);
254 } 265 }
255 266
OLDNEW
« no previous file with comments | « webkit/glue/cpp_bound_class.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698