summaryrefslogtreecommitdiffstats
path: root/webkit/glue/cpp_binding_example.cc
diff options
context:
space:
mode:
Diffstat (limited to 'webkit/glue/cpp_binding_example.cc')
-rw-r--r--webkit/glue/cpp_binding_example.cc33
1 files changed, 31 insertions, 2 deletions
diff --git a/webkit/glue/cpp_binding_example.cc b/webkit/glue/cpp_binding_example.cc
index b71ffd3..79e96e4 100644
--- a/webkit/glue/cpp_binding_example.cc
+++ b/webkit/glue/cpp_binding_example.cc
@@ -2,11 +2,31 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// This file contains the definition for CppBindingExample, a usage example
-// that is not actually used anywhere. See cpp_binding_example.h.
+// This file contains the definition for CppBindingExample, which is used in
+// cpp_bound_class_unittest.
#include "cpp_binding_example.h"
+namespace {
+
+class PropertyCallbackExample : public CppBoundClass::PropertyCallback {
+ public:
+ virtual bool GetValue(CppVariant* value) {
+ value->Set(value_);
+ return true;
+ }
+
+ virtual bool SetValue(const CppVariant& value) {
+ value_.Set(value);
+ return true;
+ }
+
+ private:
+ CppVariant value_;
+};
+
+}
+
CppBindingExample::CppBindingExample() {
// Map properties. It's recommended, but not required, that the JavaScript
// names (used as the keys in this map) match the names of the member
@@ -14,6 +34,11 @@ CppBindingExample::CppBindingExample() {
BindProperty("my_value", &my_value);
BindProperty("my_other_value", &my_other_value);
+ // Bind property with a callback.
+ BindProperty("my_value_with_callback", new PropertyCallbackExample());
+ // Bind property with a getter callback.
+ BindProperty("same", &CppBindingExample::same);
+
// Map methods. See comment above about names.
BindMethod("echoValue", &CppBindingExample::echoValue);
BindMethod("echoType", &CppBindingExample::echoType);
@@ -88,6 +113,10 @@ void CppBindingExample::plus(const CppArgumentList& args,
result->Set(sum);
}
+void CppBindingExample::same(CppVariant* result) {
+ result->Set(42);
+}
+
void CppBindingExample::fallbackMethod(const CppArgumentList& args,
CppVariant* result) {
printf("Error: unknown JavaScript method invoked.\n");