1 // Copyright (c) 2011 The Native Client Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef EXAMPLES_TUMBLER_SCRIPTING_BRIDGE_H_
6 #define EXAMPLES_TUMBLER_SCRIPTING_BRIDGE_H_
14 #include "ppapi/cpp/var.h"
18 class MethodCallbackExecutor;
20 // This class handles the interface between the browser and the NaCl module.
21 // There is a single point of entry from the browser: postMessage(). The
22 // string passed to postMessage() has this format:
23 // 'function_name arg_name0:arg_0 arg_name1:arg1 ...'
24 // The arguments have undetermined type; they are placed in a map of argument
25 // names and values. Values are all strings, it is up to the target code to
26 // do any type coercion.
27 // Methods called by the scripting bridge must have a signature like this:
28 // void Method(const ScriptingBridge& bridge,
29 // const ParameterDictionary&);
30 class ScriptingBridge {
32 // Shared pointer type used in the method map.
33 typedef std::tr1::shared_ptr<MethodCallbackExecutor>
34 SharedMethodCallbackExecutor;
36 virtual ~ScriptingBridge() {}
38 // Causes |method_name| to be published as a method that can be called via
39 // postMessage() from the browser. Associates this method with |method|.
40 bool AddMethodNamed(const std::string& method_name,
41 SharedMethodCallbackExecutor method);
43 bool InvokeMethod(const std::string& method);
46 typedef std::map<std::string, SharedMethodCallbackExecutor> MethodDictionary;
48 MethodDictionary method_dictionary_;
51 } // namespace tumbler
52 #endif // EXAMPLES_TUMBLER_SCRIPTING_BRIDGE_H_