CppBindingExample class:
This provides an example of how to use the CppBoundClass to create methods
and properties that can be exposed to JavaScript by an appropriately built
embedding client. It is also used by the CppBoundClass unit test.
Typically, a class intended to be bound to JavaScript will define a
constructor, any methods and properties to be exposed, and optionally a
destructor. An embedding client can then bind the class to a JavaScript
object in a frame's window using the CppBoundClass::BindToJavascript() method,
generally called from the WebFrameClient's DidClearWindowObject().
Once this class has been bound, say to the name "example", it might be called
from JavaScript in the following way:
<script>
if (window.example) {
document.writeln(example.echoValue(false));
document.writeln(example.echoType("Hello world!"));
document.writeln(example.plus(2, 3.1));
example.my_value = 15;
example.my_other_value = 2.1;
document.writeln(example.plus(example.my_value, example.my_other_value));
}
</script>
*/
#ifndef CPP_BINDING_EXAMPLE_H__
#define CPP_BINDING_EXAMPLE_H__
#include "webkit/glue/cpp_bound_class.h"
#include "webkit/glue/webkit_glue_export.h"
namespace webkit_glue {
class CppBindingExample : public CppBoundClass {
public:
WEBKIT_GLUE_EXPORT CppBindingExample();
void echoValue(const CppArgumentList& args, CppVariant* result);
void echoType(const CppArgumentList& args, CppVariant* result);
void plus(const CppArgumentList& args, CppVariant* result);
void same(CppVariant* result);
void fallbackMethod(const CppArgumentList& args, CppVariant* result);
CppVariant my_value;
CppVariant my_other_value;
};
}
#endif