| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_HOST_DISPATCHER_H_ | 5 #ifndef PPAPI_PROXY_HOST_DISPATCHER_H_ |
| 6 #define PPAPI_PROXY_HOST_DISPATCHER_H_ | 6 #define PPAPI_PROXY_HOST_DISPATCHER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/observer_list.h" | |
| 15 #include "base/process/process.h" | 14 #include "base/process/process.h" |
| 16 #include "ipc/message_filter.h" | 15 #include "ipc/message_filter.h" |
| 17 #include "ppapi/c/pp_instance.h" | 16 #include "ppapi/c/pp_instance.h" |
| 18 #include "ppapi/proxy/dispatcher.h" | 17 #include "ppapi/proxy/dispatcher.h" |
| 19 | 18 |
| 20 struct PPB_Proxy_Private; | 19 struct PPB_Proxy_Private; |
| 21 | 20 |
| 22 namespace ppapi { | 21 namespace ppapi { |
| 23 | 22 |
| 24 struct Preferences; | 23 struct Preferences; |
| 25 | 24 |
| 26 namespace proxy { | 25 namespace proxy { |
| 27 | 26 |
| 28 class PPAPI_PROXY_EXPORT HostDispatcher : public Dispatcher { | 27 class PPAPI_PROXY_EXPORT HostDispatcher : public Dispatcher { |
| 29 public: | 28 public: |
| 30 // This interface receives notifications about sync messages being sent by | 29 // This interface receives notifications about sync messages being sent by |
| 31 // the dispatcher to the plugin process. Some parts of Chrome may need to | 30 // the dispatcher to the plugin process. It is used to detect a hung plugin. |
| 32 // know whether we are sending a synchronous message to the plugin; e.g. to | |
| 33 // detect a hung plugin or to avoid re-entering JavaScript. | |
| 34 // | 31 // |
| 35 // Note that there can be nested sync messages, so the begin/end status | 32 // Note that there can be nested sync messages, so the begin/end status |
| 36 // actually represents a stack of blocking messages. | 33 // actually represents a stack of blocking messages. |
| 37 class SyncMessageStatusObserver { | 34 class SyncMessageStatusReceiver : public IPC::MessageFilter { |
| 38 public: | 35 public: |
| 39 // Notification that a sync message is about to be sent out. | 36 // Notification that a sync message is about to be sent out. |
| 40 virtual void BeginBlockOnSyncMessage() = 0; | 37 virtual void BeginBlockOnSyncMessage() = 0; |
| 41 | 38 |
| 42 // Notification that a sync message reply was received and the dispatcher | 39 // Notification that a sync message reply was received and the dispatcher |
| 43 // is no longer blocked on a sync message. | 40 // is no longer blocked on a sync message. |
| 44 virtual void EndBlockOnSyncMessage() = 0; | 41 virtual void EndBlockOnSyncMessage() = 0; |
| 45 | 42 |
| 46 protected: | 43 protected: |
| 47 virtual ~SyncMessageStatusObserver() {} | 44 virtual ~SyncMessageStatusReceiver() {} |
| 48 }; | 45 }; |
| 49 | 46 |
| 50 // Constructor for the renderer side. This will take a reference to the | 47 // Constructor for the renderer side. This will take a reference to the |
| 51 // SyncMessageStatusReceiver. | 48 // SyncMessageStatusReceiver. |
| 52 // | 49 // |
| 53 // You must call InitHostWithChannel after the constructor. | 50 // You must call InitHostWithChannel after the constructor. |
| 54 HostDispatcher(PP_Module module, | 51 HostDispatcher(PP_Module module, |
| 55 PP_GetInterface_Func local_get_interface, | 52 PP_GetInterface_Func local_get_interface, |
| 53 SyncMessageStatusReceiver* sync_status, |
| 56 const PpapiPermissions& permissions); | 54 const PpapiPermissions& permissions); |
| 57 ~HostDispatcher(); | 55 ~HostDispatcher(); |
| 58 | 56 |
| 59 // You must call this function before anything else. Returns true on success. | 57 // You must call this function before anything else. Returns true on success. |
| 60 // The delegate pointer must outlive this class, ownership is not | 58 // The delegate pointer must outlive this class, ownership is not |
| 61 // transferred. | 59 // transferred. |
| 62 virtual bool InitHostWithChannel(Delegate* delegate, | 60 virtual bool InitHostWithChannel(Delegate* delegate, |
| 63 base::ProcessId peer_pid, | 61 base::ProcessId peer_pid, |
| 64 const IPC::ChannelHandle& channel_handle, | 62 const IPC::ChannelHandle& channel_handle, |
| 65 bool is_client, | 63 bool is_client, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 // See the value below. Call this when processing a scripting message from | 95 // See the value below. Call this when processing a scripting message from |
| 98 // the plugin that can be reentered. This is set to false at the beginning | 96 // the plugin that can be reentered. This is set to false at the beginning |
| 99 // of processing of each message from the plugin. | 97 // of processing of each message from the plugin. |
| 100 void set_allow_plugin_reentrancy() { | 98 void set_allow_plugin_reentrancy() { |
| 101 allow_plugin_reentrancy_ = true; | 99 allow_plugin_reentrancy_ = true; |
| 102 } | 100 } |
| 103 | 101 |
| 104 // Returns the proxy interface for talking to the implementation. | 102 // Returns the proxy interface for talking to the implementation. |
| 105 const PPB_Proxy_Private* ppb_proxy() const { return ppb_proxy_; } | 103 const PPB_Proxy_Private* ppb_proxy() const { return ppb_proxy_; } |
| 106 | 104 |
| 107 void AddSyncMessageStatusObserver(SyncMessageStatusObserver* obs); | |
| 108 void RemoveSyncMessageStatusObserver(SyncMessageStatusObserver* obs); | |
| 109 | |
| 110 void AddFilter(IPC::Listener* listener); | 105 void AddFilter(IPC::Listener* listener); |
| 111 | 106 |
| 112 protected: | 107 protected: |
| 113 // Overridden from Dispatcher. | 108 // Overridden from Dispatcher. |
| 114 virtual void OnInvalidMessageReceived(); | 109 virtual void OnInvalidMessageReceived(); |
| 115 | 110 |
| 116 private: | 111 private: |
| 117 void OnHostMsgLogWithSource(PP_Instance instance, | 112 void OnHostMsgLogWithSource(PP_Instance instance, |
| 118 int int_log_level, | 113 int int_log_level, |
| 119 const std::string& source, | 114 const std::string& source, |
| 120 const std::string& value); | 115 const std::string& value); |
| 121 | 116 |
| 117 scoped_refptr<SyncMessageStatusReceiver> sync_status_; |
| 118 |
| 122 PP_Module pp_module_; | 119 PP_Module pp_module_; |
| 123 | 120 |
| 124 // Maps interface name to whether that interface is supported. If an interface | 121 // Maps interface name to whether that interface is supported. If an interface |
| 125 // name is not in the map, that implies that we haven't queried for it yet. | 122 // name is not in the map, that implies that we haven't queried for it yet. |
| 126 typedef base::hash_map<std::string, bool> PluginSupportedMap; | 123 typedef base::hash_map<std::string, bool> PluginSupportedMap; |
| 127 PluginSupportedMap plugin_supported_; | 124 PluginSupportedMap plugin_supported_; |
| 128 | 125 |
| 129 // Guaranteed non-NULL. | 126 // Guaranteed non-NULL. |
| 130 const PPB_Proxy_Private* ppb_proxy_; | 127 const PPB_Proxy_Private* ppb_proxy_; |
| 131 | 128 |
| 132 // Set to true when the plugin is in a state that it can be reentered by a | 129 // Set to true when the plugin is in a state that it can be reentered by a |
| 133 // sync message from the host. We allow reentrancy only when we're processing | 130 // sync message from the host. We allow reentrancy only when we're processing |
| 134 // a sync message from the renderer that is a scripting command. When the | 131 // a sync message from the renderer that is a scripting command. When the |
| 135 // plugin is in this state, it needs to accept reentrancy since scripting may | 132 // plugin is in this state, it needs to accept reentrancy since scripting may |
| 136 // ultimately call back into the plugin. | 133 // ultimately call back into the plugin. |
| 137 bool allow_plugin_reentrancy_; | 134 bool allow_plugin_reentrancy_; |
| 138 | 135 |
| 139 ObserverList<SyncMessageStatusObserver> sync_status_observer_list_; | |
| 140 | |
| 141 std::vector<IPC::Listener*> filters_; | 136 std::vector<IPC::Listener*> filters_; |
| 142 | 137 |
| 143 DISALLOW_COPY_AND_ASSIGN(HostDispatcher); | 138 DISALLOW_COPY_AND_ASSIGN(HostDispatcher); |
| 144 }; | 139 }; |
| 145 | 140 |
| 146 // Create this object on the stack to prevent the module (and hence the | 141 // Create this object on the stack to prevent the module (and hence the |
| 147 // dispatcher) from being deleted out from under you. This is necessary when | 142 // dispatcher) from being deleted out from under you. This is necessary when |
| 148 // calling some scripting functions that may delete the plugin. | 143 // calling some scripting functions that may delete the plugin. |
| 149 // | 144 // |
| 150 // This class does nothing if used on the plugin side. | 145 // This class does nothing if used on the plugin side. |
| 151 class ScopedModuleReference { | 146 class ScopedModuleReference { |
| 152 public: | 147 public: |
| 153 explicit ScopedModuleReference(Dispatcher* dispatcher); | 148 explicit ScopedModuleReference(Dispatcher* dispatcher); |
| 154 ~ScopedModuleReference(); | 149 ~ScopedModuleReference(); |
| 155 | 150 |
| 156 private: | 151 private: |
| 157 HostDispatcher* dispatcher_; | 152 HostDispatcher* dispatcher_; |
| 158 | 153 |
| 159 DISALLOW_COPY_AND_ASSIGN(ScopedModuleReference); | 154 DISALLOW_COPY_AND_ASSIGN(ScopedModuleReference); |
| 160 }; | 155 }; |
| 161 | 156 |
| 162 } // namespace proxy | 157 } // namespace proxy |
| 163 } // namespace ppapi | 158 } // namespace ppapi |
| 164 | 159 |
| 165 #endif // PPAPI_PROXY_HOST_DISPATCHER_H_ | 160 #endif // PPAPI_PROXY_HOST_DISPATCHER_H_ |
| OLD | NEW |