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