| 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. |
| 11 // - CppBoundClass has then overridden Invoke() to look up the function | 11 // - CppBoundClass has then overridden Invoke() to look up the function |
| 12 // name in its internal map of methods, and then calls the appropriate | 12 // name in its internal map of methods, and then calls the appropriate |
| 13 // method. | 13 // method. |
| 14 | 14 |
| 15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/string_util.h" |
| 17 #include "webkit/api/public/WebBindings.h" | 18 #include "webkit/api/public/WebBindings.h" |
| 19 #include "webkit/api/public/WebFrame.h" |
| 20 #include "webkit/api/public/WebString.h" |
| 18 #include "webkit/glue/cpp_bound_class.h" | 21 #include "webkit/glue/cpp_bound_class.h" |
| 19 #include "webkit/glue/webframe.h" | |
| 20 | 22 |
| 21 using WebKit::WebBindings; | 23 using WebKit::WebBindings; |
| 24 using WebKit::WebFrame; |
| 22 | 25 |
| 23 // Our special NPObject type. We extend an NPObject with a pointer to a | 26 // Our special NPObject type. We extend an NPObject with a pointer to a |
| 24 // CppBoundClass, which is just a C++ interface that we forward all NPObject | 27 // CppBoundClass, which is just a C++ interface that we forward all NPObject |
| 25 // callbacks to. | 28 // callbacks to. |
| 26 struct CppNPObject { | 29 struct CppNPObject { |
| 27 NPObject parent; // This must be the first field in the struct. | 30 NPObject parent; // This must be the first field in the struct. |
| 28 CppBoundClass* bound_class; | 31 CppBoundClass* bound_class; |
| 29 | 32 |
| 30 // | 33 // |
| 31 // All following objects and functions are static, and just used to interface | 34 // All following objects and functions are static, and just used to interface |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 void CppBoundClass::BindToJavascript(WebFrame* frame, | 242 void CppBoundClass::BindToJavascript(WebFrame* frame, |
| 240 const std::wstring& classname) { | 243 const std::wstring& classname) { |
| 241 #if WEBKIT_USING_JSC | 244 #if WEBKIT_USING_JSC |
| 242 #error "This is not going to work anymore...but it's not clear what the solution
is...or if it's still necessary." | 245 #error "This is not going to work anymore...but it's not clear what the solution
is...or if it's still necessary." |
| 243 JSC::JSLock lock(false); | 246 JSC::JSLock lock(false); |
| 244 #endif | 247 #endif |
| 245 | 248 |
| 246 // BindToWindowObject will take its own reference to the NPObject, and clean | 249 // BindToWindowObject will take its own reference to the NPObject, and clean |
| 247 // up after itself. It will also (indirectly) register the object with V8, | 250 // up after itself. It will also (indirectly) register the object with V8, |
| 248 // so we must remember this so we can unregister it when we're destroyed. | 251 // so we must remember this so we can unregister it when we're destroyed. |
| 249 frame->BindToWindowObject(classname, NPVARIANT_TO_OBJECT(*GetAsCppVariant())); | 252 frame->bindToWindowObject(WideToUTF16Hack(classname), |
| 253 NPVARIANT_TO_OBJECT(*GetAsCppVariant())); |
| 250 bound_to_frame_ = true; | 254 bound_to_frame_ = true; |
| 251 } | 255 } |
| OLD | NEW |