Advertisement
Guest User

Untitled

a guest
Aug 13th, 2012
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.66 KB | None | 0 0
  1. #ifndef __METHOD_DISPATCHER_H__
  2. #define __METHOD_DISPATCHER_H__
  3.  
  4. #include <Awesomium/WebCore.h>
  5. #include <functional>
  6. #include <map>
  7.  
  8. using namespace Awesomium;
  9.  
  10. class Application;
  11.  
  12. typedef std::pair<int, WebString> ObjectMethodKey;
  13. typedef std::function<void(Application*, WebView*, const Awesomium::JSArray&)>
  14.   ObjectMethodDelegate;
  15. typedef std::function<JSValue(Application*, WebView*, const Awesomium::JSArray&)>
  16.   ObjectMethodWithRetvalDelegate;
  17. typedef std::map<ObjectMethodKey, ObjectMethodDelegate> BoundMethodMap;
  18. typedef std::map<ObjectMethodKey, ObjectMethodWithRetvalDelegate> BoundMethodWithRetvalMap;
  19.  
  20. class MethodDispatcher : public JSMethodHandler {
  21.  public:
  22.   MethodDispatcher(Application* app);
  23.  
  24.   void Bind(JSObject& object,
  25.     const WebString& name,
  26.     ObjectMethodDelegate callback);
  27.  
  28.   void BindWithRetval(JSObject& object,
  29.     const WebString& name,
  30.     ObjectMethodWithRetvalDelegate callback);
  31.  
  32.   // Inherited from JSMethodHandler
  33.   void OnMethodCall(Awesomium::WebView* caller,
  34.                     unsigned int remote_object_id,
  35.                     const Awesomium::WebString& method_name,
  36.                     const Awesomium::JSArray& args);
  37.  
  38.   // Inherited from JSMethodHandler
  39.   JSValue OnMethodCallWithReturnValue(Awesomium::WebView* caller,
  40.                                       unsigned int remote_object_id,
  41.                                       const Awesomium::WebString& method_name,
  42.                                       const Awesomium::JSArray& args);
  43.  
  44. protected:
  45.   Application* app_;
  46.   BoundMethodMap bound_methods_;
  47.   BoundMethodWithRetvalMap bound_methods_with_retval_;
  48. };
  49.  
  50. #endif  // __METHOD_DISPATCHER_H__
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement