| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef PPAPI_PROXY_DISPATCHER_H_ | 5 #ifndef PPAPI_PROXY_DISPATCHER_H_ |
| 6 #define PPAPI_PROXY_DISPATCHER_H_ | 6 #define PPAPI_PROXY_DISPATCHER_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/tracked_objects.h" | 13 #include "base/tracked_objects.h" |
| 14 #include "ipc/ipc_channel_proxy.h" | 14 #include "ipc/ipc_channel_proxy.h" |
| 15 #include "ppapi/c/pp_instance.h" | 15 #include "ppapi/c/pp_instance.h" |
| 16 #include "ppapi/c/pp_module.h" | 16 #include "ppapi/c/pp_module.h" |
| 17 #include "ppapi/proxy/callback_tracker.h" | 17 #include "ppapi/proxy/callback_tracker.h" |
| 18 #include "ppapi/proxy/proxy_channel.h" | 18 #include "ppapi/proxy/proxy_channel.h" |
| 19 #include "ppapi/proxy/interface_id.h" | 19 #include "ppapi/proxy/interface_id.h" |
| 20 #include "ppapi/proxy/interface_list.h" |
| 20 #include "ppapi/proxy/interface_proxy.h" | 21 #include "ppapi/proxy/interface_proxy.h" |
| 21 #include "ppapi/proxy/plugin_var_tracker.h" | 22 #include "ppapi/proxy/plugin_var_tracker.h" |
| 22 | 23 |
| 23 namespace ppapi { | 24 namespace ppapi { |
| 24 | 25 |
| 25 class WebKitForwarding; | 26 class WebKitForwarding; |
| 26 | 27 |
| 27 namespace proxy { | 28 namespace proxy { |
| 28 | 29 |
| 29 class VarSerializationRules; | 30 class VarSerializationRules; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 50 virtual ~Dispatcher(); | 51 virtual ~Dispatcher(); |
| 51 | 52 |
| 52 // Returns true if the dispatcher is on the plugin side, or false if it's the | 53 // Returns true if the dispatcher is on the plugin side, or false if it's the |
| 53 // browser side. | 54 // browser side. |
| 54 virtual bool IsPlugin() const = 0; | 55 virtual bool IsPlugin() const = 0; |
| 55 | 56 |
| 56 VarSerializationRules* serialization_rules() const { | 57 VarSerializationRules* serialization_rules() const { |
| 57 return serialization_rules_.get(); | 58 return serialization_rules_.get(); |
| 58 } | 59 } |
| 59 | 60 |
| 60 // Wrapper for calling the local GetInterface function. | 61 // Returns a non-owning pointer to the interface proxy for the given ID, or |
| 61 const void* GetLocalInterface(const char* interface_name); | 62 // NULL if the ID isn't found. This will create the proxy if it hasn't been |
| 63 // created so far. |
| 64 InterfaceProxy* GetInterfaceProxy(InterfaceID id); |
| 62 | 65 |
| 63 // Returns the pointer to the IO thread for processing IPC messages. | 66 // Returns the pointer to the IO thread for processing IPC messages. |
| 64 // TODO(brettw) remove this. It's a hack to support the Flash | 67 // TODO(brettw) remove this. It's a hack to support the Flash |
| 65 // ModuleLocalThreadAdapter. When the thread stuff is sorted out, this | 68 // ModuleLocalThreadAdapter. When the thread stuff is sorted out, this |
| 66 // implementation detail should be hidden. | 69 // implementation detail should be hidden. |
| 67 base::MessageLoopProxy* GetIPCMessageLoop(); | 70 base::MessageLoopProxy* GetIPCMessageLoop(); |
| 68 | 71 |
| 69 // Adds the given filter to the IO thread. Takes ownership of the pointer. | 72 // Adds the given filter to the IO thread. Takes ownership of the pointer. |
| 70 // TODO(brettw) remove this. It's a hack to support the Flash | 73 // TODO(brettw) remove this. It's a hack to support the Flash |
| 71 // ModuleLocalThreadAdapter. When the thread stuff is sorted out, this | 74 // ModuleLocalThreadAdapter. When the thread stuff is sorted out, this |
| 72 // implementation detail should be hidden. | 75 // implementation detail should be hidden. |
| 73 void AddIOThreadMessageFilter(IPC::ChannelProxy::MessageFilter* filter); | 76 void AddIOThreadMessageFilter(IPC::ChannelProxy::MessageFilter* filter); |
| 74 | 77 |
| 75 // TODO(brettw): What is this comment referring to? | 78 // TODO(brettw): What is this comment referring to? |
| 76 // Called if the remote side is declaring to us which interfaces it supports | 79 // Called if the remote side is declaring to us which interfaces it supports |
| 77 // so we don't have to query for each one. We'll pre-create proxies for | 80 // so we don't have to query for each one. We'll pre-create proxies for |
| 78 // each of the given interfaces. | 81 // each of the given interfaces. |
| 79 | 82 |
| 80 // IPC::Channel::Listener implementation. | 83 // IPC::Channel::Listener implementation. |
| 81 virtual bool OnMessageReceived(const IPC::Message& msg); | 84 virtual bool OnMessageReceived(const IPC::Message& msg); |
| 82 | 85 |
| 83 CallbackTracker& callback_tracker() { | 86 CallbackTracker& callback_tracker() { |
| 84 return callback_tracker_; | 87 return callback_tracker_; |
| 85 } | 88 } |
| 86 | 89 |
| 87 // Retrieves the information associated with the given interface, identified | 90 GetInterfaceFunc local_get_interface() const { return local_get_interface_; } |
| 88 // either by name or ID. Each function searches either PPP or PPB interfaces. | |
| 89 static const InterfaceProxy::Info* GetPPBInterfaceInfo( | |
| 90 const std::string& name); | |
| 91 static const InterfaceProxy::Info* GetPPBInterfaceInfo( | |
| 92 InterfaceID id); | |
| 93 static const InterfaceProxy::Info* GetPPPInterfaceInfo( | |
| 94 const std::string& name); | |
| 95 | 91 |
| 96 protected: | 92 protected: |
| 97 Dispatcher(base::ProcessHandle remote_process_handle, | 93 Dispatcher(base::ProcessHandle remote_process_handle, |
| 98 GetInterfaceFunc local_get_interface); | 94 GetInterfaceFunc local_get_interface); |
| 99 | 95 |
| 100 // Setter for the derived classes to set the appropriate var serialization. | 96 // Setter for the derived classes to set the appropriate var serialization. |
| 101 // Takes ownership of the given pointer, which must be on the heap. | 97 // Takes ownership of the given pointer, which must be on the heap. |
| 102 void SetSerializationRules(VarSerializationRules* var_serialization_rules); | 98 void SetSerializationRules(VarSerializationRules* var_serialization_rules); |
| 103 | 99 |
| 100 // Called when an invalid message is received from the remote site. The |
| 101 // default implementation does nothing, derived classes can override. |
| 102 virtual void OnInvalidMessageReceived(); |
| 103 |
| 104 bool disallow_trusted_interfaces() const { | 104 bool disallow_trusted_interfaces() const { |
| 105 return disallow_trusted_interfaces_; | 105 return disallow_trusted_interfaces_; |
| 106 } | 106 } |
| 107 | 107 |
| 108 private: | 108 private: |
| 109 friend class HostDispatcherTest; |
| 110 friend class PluginDispatcherTest; |
| 111 |
| 112 // Lists all lazily-created interface proxies. |
| 113 scoped_ptr<InterfaceProxy> proxies_[INTERFACE_ID_COUNT]; |
| 114 |
| 109 bool disallow_trusted_interfaces_; | 115 bool disallow_trusted_interfaces_; |
| 110 | 116 |
| 111 GetInterfaceFunc local_get_interface_; | 117 GetInterfaceFunc local_get_interface_; |
| 112 | 118 |
| 113 CallbackTracker callback_tracker_; | 119 CallbackTracker callback_tracker_; |
| 114 | 120 |
| 115 scoped_ptr<VarSerializationRules> serialization_rules_; | 121 scoped_ptr<VarSerializationRules> serialization_rules_; |
| 116 | 122 |
| 117 DISALLOW_COPY_AND_ASSIGN(Dispatcher); | 123 DISALLOW_COPY_AND_ASSIGN(Dispatcher); |
| 118 }; | 124 }; |
| 119 | 125 |
| 120 } // namespace proxy | 126 } // namespace proxy |
| 121 } // namespace ppapi | 127 } // namespace ppapi |
| 122 | 128 |
| 123 #endif // PPAPI_PROXY_DISPATCHER_H_ | 129 #endif // PPAPI_PROXY_DISPATCHER_H_ |
| OLD | NEW |