1 // Copyright (c) 2012 The Chromium 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. 4 5 #ifndef PPAPI_PROXY_DISPATCHER_H_ 6 #define PPAPI_PROXY_DISPATCHER_H_ 7 8 #include <set> 9 #include <string> 10 #include <vector> 11 12 #include "base/callback_forward.h" 13 #include "base/compiler_specific.h" 14 #include "base/memory/ref_counted.h" 15 #include "base/tracked_objects.h" 16 #include "ppapi/c/pp_instance.h" 17 #include "ppapi/c/pp_module.h" 18 #include "ppapi/c/ppp.h" 19 #include "ppapi/proxy/proxy_channel.h" 20 #include "ppapi/proxy/interface_list.h" 21 #include "ppapi/proxy/interface_proxy.h" 22 #include "ppapi/proxy/plugin_var_tracker.h" 23 #include "ppapi/shared_impl/api_id.h" 24 25 namespace IPC { 26 class MessageFilter; 27 } 28 29 namespace ppapi { 30 namespace proxy { 31 32 class VarSerializationRules; 33 34 // An interface proxy can represent either end of a cross-process interface 35 // call. The "source" side is where the call is invoked, and the "target" side 36 // is where the call ends up being executed. 37 // 38 // Plugin side | Browser side 39 // -------------------------------------|-------------------------------------- 40 // | 41 // "Source" | "Target" 42 // InterfaceProxy ----------------------> InterfaceProxy 43 // | 44 // | 45 // "Target" | "Source" 46 // InterfaceProxy <---------------------- InterfaceProxy 47 // | 48 class PPAPI_PROXY_EXPORT Dispatcher : public ProxyChannel { 49 public: 50 virtual ~Dispatcher(); 51 52 // Returns true if the dispatcher is on the plugin side, or false if it's the 53 // browser side. 54 virtual bool IsPlugin() const = 0; 55 56 VarSerializationRules* serialization_rules() const { 57 return serialization_rules_.get(); 58 } 59 60 // Returns a non-owning pointer to the interface proxy for the given ID, or 61 // NULL if the ID isn't found. This will create the proxy if it hasn't been 62 // created so far. 63 InterfaceProxy* GetInterfaceProxy(ApiID id); 64 65 // Adds the given filter to the IO thread. Takes ownership of the pointer. 66 void AddIOThreadMessageFilter(IPC::MessageFilter* filter); 67 68 // IPC::Listener implementation. 69 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; 70 71 PP_GetInterface_Func local_get_interface() const { 72 return local_get_interface_; 73 } 74 75 const PpapiPermissions& permissions() const { return permissions_; } 76 77 protected: 78 explicit Dispatcher(PP_GetInterface_Func local_get_interface, 79 const PpapiPermissions& permissions); 80 81 // Setter for the derived classes to set the appropriate var serialization. 82 // Takes one reference of the given pointer, which must be on the heap. 83 void SetSerializationRules(VarSerializationRules* var_serialization_rules); 84 85 // Called when an invalid message is received from the remote site. The 86 // default implementation does nothing, derived classes can override. 87 virtual void OnInvalidMessageReceived(); 88 89 private: 90 friend class PluginDispatcherTest; 91 92 // Lists all lazily-created interface proxies. 93 scoped_ptr<InterfaceProxy> proxies_[API_ID_COUNT]; 94 95 PP_GetInterface_Func local_get_interface_; 96 97 scoped_refptr<VarSerializationRules> serialization_rules_; 98 99 PpapiPermissions permissions_; 100 101 DISALLOW_COPY_AND_ASSIGN(Dispatcher); 102 }; 103 104 } // namespace proxy 105 } // namespace ppapi 106 107 #endif // PPAPI_PROXY_DISPATCHER_H_ 108