OLD | NEW |
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 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 bool CppBoundClass::IsMethodRegistered(std::string name) { | 233 bool CppBoundClass::IsMethodRegistered(std::string name) { |
234 // NPUTF8 is a typedef for char, so this cast is safe. | 234 // NPUTF8 is a typedef for char, so this cast is safe. |
235 NPIdentifier ident = NPN_GetStringIdentifier((const NPUTF8*)name.c_str()); | 235 NPIdentifier ident = NPN_GetStringIdentifier((const NPUTF8*)name.c_str()); |
236 MethodList::iterator callback = methods_.find(ident); | 236 MethodList::iterator callback = methods_.find(ident); |
237 return (callback != methods_.end()); | 237 return (callback != methods_.end()); |
238 } | 238 } |
239 | 239 |
240 void CppBoundClass::BindToJavascript(WebFrame* frame, | 240 void CppBoundClass::BindToJavascript(WebFrame* frame, |
241 const std::wstring& classname) { | 241 const std::wstring& classname) { |
242 #if USE(JSC) | 242 #if USE(JSC) |
243 KJS::JSLock lock(false); | 243 JSC::JSLock lock(false); |
244 #endif | 244 #endif |
245 | 245 |
246 // Create an NPObject using our static NPClass. The first argument (a | 246 // Create an NPObject using our static NPClass. The first argument (a |
247 // plugin's instance handle) is passed through to the allocate function | 247 // plugin's instance handle) is passed through to the allocate function |
248 // directly, and we don't use it, so it's ok to be 0. | 248 // directly, and we don't use it, so it's ok to be 0. |
249 NPObject* np_obj = NPN_CreateObject(0, &CppNPObject::np_class_); | 249 NPObject* np_obj = NPN_CreateObject(0, &CppNPObject::np_class_); |
250 CppNPObject* obj = reinterpret_cast<CppNPObject*>(np_obj); | 250 CppNPObject* obj = reinterpret_cast<CppNPObject*>(np_obj); |
251 obj->bound_class = this; | 251 obj->bound_class = this; |
252 | 252 |
253 // BindToWindowObject will (indirectly) retain the np_object. We save it | 253 // BindToWindowObject will (indirectly) retain the np_object. We save it |
254 // so we can release it when we're destroyed. | 254 // so we can release it when we're destroyed. |
255 frame->BindToWindowObject(classname, np_obj); | 255 frame->BindToWindowObject(classname, np_obj); |
256 bound_objects_.push_back(np_obj); | 256 bound_objects_.push_back(np_obj); |
257 } | 257 } |
258 | 258 |
OLD | NEW |