| 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" | |
| 21 #include "ppapi/proxy/interface_proxy.h" | 20 #include "ppapi/proxy/interface_proxy.h" |
| 22 #include "ppapi/proxy/plugin_var_tracker.h" | 21 #include "ppapi/proxy/plugin_var_tracker.h" |
| 23 | 22 |
| 24 namespace ppapi { | 23 namespace ppapi { |
| 25 | 24 |
| 26 class WebKitForwarding; | 25 class WebKitForwarding; |
| 27 | 26 |
| 28 namespace proxy { | 27 namespace proxy { |
| 29 | 28 |
| 30 class VarSerializationRules; | 29 class VarSerializationRules; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 51 virtual ~Dispatcher(); | 50 virtual ~Dispatcher(); |
| 52 | 51 |
| 53 // Returns true if the dispatcher is on the plugin side, or false if it's the | 52 // Returns true if the dispatcher is on the plugin side, or false if it's the |
| 54 // browser side. | 53 // browser side. |
| 55 virtual bool IsPlugin() const = 0; | 54 virtual bool IsPlugin() const = 0; |
| 56 | 55 |
| 57 VarSerializationRules* serialization_rules() const { | 56 VarSerializationRules* serialization_rules() const { |
| 58 return serialization_rules_.get(); | 57 return serialization_rules_.get(); |
| 59 } | 58 } |
| 60 | 59 |
| 61 // Returns a non-owning pointer to the interface proxy for the given ID, or | 60 // Wrapper for calling the local GetInterface function. |
| 62 // NULL if the ID isn't found. This will create the proxy if it hasn't been | 61 const void* GetLocalInterface(const char* interface_name); |
| 63 // created so far. | |
| 64 InterfaceProxy* GetInterfaceProxy(InterfaceID id); | |
| 65 | 62 |
| 66 // Returns the pointer to the IO thread for processing IPC messages. | 63 // Returns the pointer to the IO thread for processing IPC messages. |
| 67 // TODO(brettw) remove this. It's a hack to support the Flash | 64 // TODO(brettw) remove this. It's a hack to support the Flash |
| 68 // ModuleLocalThreadAdapter. When the thread stuff is sorted out, this | 65 // ModuleLocalThreadAdapter. When the thread stuff is sorted out, this |
| 69 // implementation detail should be hidden. | 66 // implementation detail should be hidden. |
| 70 base::MessageLoopProxy* GetIPCMessageLoop(); | 67 base::MessageLoopProxy* GetIPCMessageLoop(); |
| 71 | 68 |
| 72 // Adds the given filter to the IO thread. Takes ownership of the pointer. | 69 // Adds the given filter to the IO thread. Takes ownership of the pointer. |
| 73 // TODO(brettw) remove this. It's a hack to support the Flash | 70 // TODO(brettw) remove this. It's a hack to support the Flash |
| 74 // ModuleLocalThreadAdapter. When the thread stuff is sorted out, this | 71 // ModuleLocalThreadAdapter. When the thread stuff is sorted out, this |
| 75 // implementation detail should be hidden. | 72 // implementation detail should be hidden. |
| 76 void AddIOThreadMessageFilter(IPC::ChannelProxy::MessageFilter* filter); | 73 void AddIOThreadMessageFilter(IPC::ChannelProxy::MessageFilter* filter); |
| 77 | 74 |
| 78 // TODO(brettw): What is this comment referring to? | 75 // TODO(brettw): What is this comment referring to? |
| 79 // Called if the remote side is declaring to us which interfaces it supports | 76 // Called if the remote side is declaring to us which interfaces it supports |
| 80 // so we don't have to query for each one. We'll pre-create proxies for | 77 // so we don't have to query for each one. We'll pre-create proxies for |
| 81 // each of the given interfaces. | 78 // each of the given interfaces. |
| 82 | 79 |
| 83 // IPC::Channel::Listener implementation. | 80 // IPC::Channel::Listener implementation. |
| 84 virtual bool OnMessageReceived(const IPC::Message& msg); | 81 virtual bool OnMessageReceived(const IPC::Message& msg); |
| 85 | 82 |
| 86 CallbackTracker& callback_tracker() { | 83 CallbackTracker& callback_tracker() { |
| 87 return callback_tracker_; | 84 return callback_tracker_; |
| 88 } | 85 } |
| 89 | 86 |
| 90 GetInterfaceFunc local_get_interface() const { return local_get_interface_; } | 87 // Retrieves the information associated with the given interface, identified |
| 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); |
| 91 | 95 |
| 92 protected: | 96 protected: |
| 93 Dispatcher(base::ProcessHandle remote_process_handle, | 97 Dispatcher(base::ProcessHandle remote_process_handle, |
| 94 GetInterfaceFunc local_get_interface); | 98 GetInterfaceFunc local_get_interface); |
| 95 | 99 |
| 96 // Setter for the derived classes to set the appropriate var serialization. | 100 // Setter for the derived classes to set the appropriate var serialization. |
| 97 // Takes ownership of the given pointer, which must be on the heap. | 101 // Takes ownership of the given pointer, which must be on the heap. |
| 98 void SetSerializationRules(VarSerializationRules* var_serialization_rules); | 102 void SetSerializationRules(VarSerializationRules* var_serialization_rules); |
| 99 | 103 |
| 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 | |
| 115 bool disallow_trusted_interfaces_; | 109 bool disallow_trusted_interfaces_; |
| 116 | 110 |
| 117 GetInterfaceFunc local_get_interface_; | 111 GetInterfaceFunc local_get_interface_; |
| 118 | 112 |
| 119 CallbackTracker callback_tracker_; | 113 CallbackTracker callback_tracker_; |
| 120 | 114 |
| 121 scoped_ptr<VarSerializationRules> serialization_rules_; | 115 scoped_ptr<VarSerializationRules> serialization_rules_; |
| 122 | 116 |
| 123 DISALLOW_COPY_AND_ASSIGN(Dispatcher); | 117 DISALLOW_COPY_AND_ASSIGN(Dispatcher); |
| 124 }; | 118 }; |
| 125 | 119 |
| 126 } // namespace proxy | 120 } // namespace proxy |
| 127 } // namespace ppapi | 121 } // namespace ppapi |
| 128 | 122 |
| 129 #endif // PPAPI_PROXY_DISPATCHER_H_ | 123 #endif // PPAPI_PROXY_DISPATCHER_H_ |
| OLD | NEW |