| 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 /* | 5 /* |
| 6 CppBoundClass class: | 6 CppBoundClass class: |
| 7 This base class serves as a parent for C++ classes designed to be bound to | 7 This base class serves as a parent for C++ classes designed to be bound to |
| 8 JavaScript objects. | 8 JavaScript objects. |
| 9 | 9 |
| 10 Subclasses should define the constructor to build the property and method | 10 Subclasses should define the constructor to build the property and method |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 void (T::*method)(const CppArgumentList&, CppVariant*)) { | 67 void (T::*method)(const CppArgumentList&, CppVariant*)) { |
| 68 Callback* callback = | 68 Callback* callback = |
| 69 NewCallback<T, const CppArgumentList&, CppVariant*>( | 69 NewCallback<T, const CppArgumentList&, CppVariant*>( |
| 70 static_cast<T*>(this), method); | 70 static_cast<T*>(this), method); |
| 71 BindCallback(name, callback); | 71 BindCallback(name, callback); |
| 72 } | 72 } |
| 73 | 73 |
| 74 // Bind the Javascript property called |name| to a CppVariant |prop|. | 74 // Bind the Javascript property called |name| to a CppVariant |prop|. |
| 75 void BindProperty(std::string name, CppVariant* prop); | 75 void BindProperty(std::string name, CppVariant* prop); |
| 76 | 76 |
| 77 // Set the fallback callback, which is called when when a callback is | 77 // Set the fallback callback, which is called when a callback is invoked |
| 78 // invoked that isn't bound. | 78 // that isn't bound. |
| 79 // If it is NULL (its default value), a JavaScript exception is thrown in | 79 // If it is NULL (its default value), a JavaScript exception is thrown in |
| 80 // that case (as normally expected). If non NULL, the fallback method is | 80 // that case (as normally expected). If non NULL, the fallback method is |
| 81 // invoked and the script continues its execution. | 81 // invoked and the script continues its execution. |
| 82 // Passing NULL for |callback| clears out any existing binding. | 82 // Passing NULL for |callback| clears out any existing binding. |
| 83 // It is used for tests and should probably only be used in such cases | 83 // It is used for tests and should probably only be used in such cases |
| 84 // as it may cause unexpected behaviors (a JavaScript object with a | 84 // as it may cause unexpected behaviors (a JavaScript object with a |
| 85 // fallback always returns true when checked for a method's | 85 // fallback always returns true when checked for a method's |
| 86 // existence). | 86 // existence). |
| 87 // The name of the nonexistent JavaScript method will be passed as the |
| 88 // first argument to the fallback method. |
| 87 void BindFallbackCallback(Callback* fallback_callback) { | 89 void BindFallbackCallback(Callback* fallback_callback) { |
| 88 fallback_callback_.reset(fallback_callback); | 90 fallback_callback_.reset(fallback_callback); |
| 89 } | 91 } |
| 90 | 92 |
| 91 // A wrapper for BindFallbackCallback, to simplify the common case of | 93 // A wrapper for BindFallbackCallback, to simplify the common case of |
| 92 // binding a method on the current object. Though not verified here, | 94 // binding a method on the current object. Though not verified here, |
| 93 // |method| must be a method of this CppBoundClass subclass. | 95 // |method| must be a method of this CppBoundClass subclass. |
| 94 // Passing NULL for |method| clears out any existing binding. | 96 // Passing NULL for |method| clears out any existing binding. |
| 95 template<typename T> | 97 template<typename T> |
| 96 void BindFallbackMethod( | 98 void BindFallbackMethod( |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 // A list of all NPObjects we created and bound in BindToJavascript(), so we | 133 // A list of all NPObjects we created and bound in BindToJavascript(), so we |
| 132 // can clean them up when we're destroyed. | 134 // can clean them up when we're destroyed. |
| 133 typedef std::vector<NPObject*> BoundObjectList; | 135 typedef std::vector<NPObject*> BoundObjectList; |
| 134 BoundObjectList bound_objects_; | 136 BoundObjectList bound_objects_; |
| 135 | 137 |
| 136 DISALLOW_EVIL_CONSTRUCTORS(CppBoundClass); | 138 DISALLOW_EVIL_CONSTRUCTORS(CppBoundClass); |
| 137 }; | 139 }; |
| 138 | 140 |
| 139 #endif // CPP_BOUNDCLASS_H__ | 141 #endif // CPP_BOUNDCLASS_H__ |
| 140 | 142 |
| OLD | NEW |