Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(188)

Side by Side Diff: ppapi/proxy/host_dispatcher.h

Issue 589213003: PPAPI: Never re-enter JavaScript for PostMessage. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make MessageChannel observer clean up more reliably, guarantee HungPluginFilter stays alive long en… Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ppapi/proxy/dispatcher.cc ('k') | ppapi/proxy/host_dispatcher.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/weak_ptr.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,
54 const PpapiPermissions& permissions); 56 const PpapiPermissions& permissions);
55 ~HostDispatcher(); 57 ~HostDispatcher();
56 58
57 // You must call this function before anything else. Returns true on success. 59 // You must call this function before anything else. Returns true on success.
58 // The delegate pointer must outlive this class, ownership is not 60 // The delegate pointer must outlive this class, ownership is not
59 // transferred. 61 // transferred.
60 virtual bool InitHostWithChannel(Delegate* delegate, 62 virtual bool InitHostWithChannel(Delegate* delegate,
61 base::ProcessId peer_pid, 63 base::ProcessId peer_pid,
62 const IPC::ChannelHandle& channel_handle, 64 const IPC::ChannelHandle& channel_handle,
63 bool is_client, 65 bool is_client,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 // See the value below. Call this when processing a scripting message from 97 // 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 98 // the plugin that can be reentered. This is set to false at the beginning
97 // of processing of each message from the plugin. 99 // of processing of each message from the plugin.
98 void set_allow_plugin_reentrancy() { 100 void set_allow_plugin_reentrancy() {
99 allow_plugin_reentrancy_ = true; 101 allow_plugin_reentrancy_ = true;
100 } 102 }
101 103
102 // Returns the proxy interface for talking to the implementation. 104 // Returns the proxy interface for talking to the implementation.
103 const PPB_Proxy_Private* ppb_proxy() const { return ppb_proxy_; } 105 const PPB_Proxy_Private* ppb_proxy() const { return ppb_proxy_; }
104 106
107 // Register an observer that will be invoked when the dispatcher begins
108 // sending a sync message and finishes sending a sync message.
109 // Returns a Closure that can be used to unregister the observer (the Closure
110 // is bound to a weak pointer, so is safe to call even after the
111 // HostDispatcher is gone.)
112 base::Closure AddSyncMessageStatusObserver(SyncMessageStatusObserver* obs);
113
105 void AddFilter(IPC::Listener* listener); 114 void AddFilter(IPC::Listener* listener);
106 115
107 protected: 116 protected:
108 // Overridden from Dispatcher. 117 // Overridden from Dispatcher.
109 virtual void OnInvalidMessageReceived(); 118 virtual void OnInvalidMessageReceived();
110 119
111 private: 120 private:
112 void OnHostMsgLogWithSource(PP_Instance instance, 121 void OnHostMsgLogWithSource(PP_Instance instance,
113 int int_log_level, 122 int int_log_level,
114 const std::string& source, 123 const std::string& source,
115 const std::string& value); 124 const std::string& value);
116 125
117 scoped_refptr<SyncMessageStatusReceiver> sync_status_; 126 void RemoveSyncMessageStatusObserver(SyncMessageStatusObserver* obs);
118 127
119 PP_Module pp_module_; 128 PP_Module pp_module_;
120 129
121 // Maps interface name to whether that interface is supported. If an interface 130 // 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. 131 // 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; 132 typedef base::hash_map<std::string, bool> PluginSupportedMap;
124 PluginSupportedMap plugin_supported_; 133 PluginSupportedMap plugin_supported_;
125 134
126 // Guaranteed non-NULL. 135 // Guaranteed non-NULL.
127 const PPB_Proxy_Private* ppb_proxy_; 136 const PPB_Proxy_Private* ppb_proxy_;
128 137
129 // Set to true when the plugin is in a state that it can be reentered by a 138 // 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 139 // 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 140 // 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 141 // plugin is in this state, it needs to accept reentrancy since scripting may
133 // ultimately call back into the plugin. 142 // ultimately call back into the plugin.
134 bool allow_plugin_reentrancy_; 143 bool allow_plugin_reentrancy_;
135 144
145 ObserverList<SyncMessageStatusObserver> sync_status_observer_list_;
146
136 std::vector<IPC::Listener*> filters_; 147 std::vector<IPC::Listener*> filters_;
137 148
149 base::WeakPtrFactory<HostDispatcher> weak_ptr_factory_;
150
138 DISALLOW_COPY_AND_ASSIGN(HostDispatcher); 151 DISALLOW_COPY_AND_ASSIGN(HostDispatcher);
139 }; 152 };
140 153
141 // Create this object on the stack to prevent the module (and hence the 154 // 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 155 // dispatcher) from being deleted out from under you. This is necessary when
143 // calling some scripting functions that may delete the plugin. 156 // calling some scripting functions that may delete the plugin.
144 // 157 //
145 // This class does nothing if used on the plugin side. 158 // This class does nothing if used on the plugin side.
146 class ScopedModuleReference { 159 class ScopedModuleReference {
147 public: 160 public:
148 explicit ScopedModuleReference(Dispatcher* dispatcher); 161 explicit ScopedModuleReference(Dispatcher* dispatcher);
149 ~ScopedModuleReference(); 162 ~ScopedModuleReference();
150 163
151 private: 164 private:
152 HostDispatcher* dispatcher_; 165 HostDispatcher* dispatcher_;
153 166
154 DISALLOW_COPY_AND_ASSIGN(ScopedModuleReference); 167 DISALLOW_COPY_AND_ASSIGN(ScopedModuleReference);
155 }; 168 };
156 169
157 } // namespace proxy 170 } // namespace proxy
158 } // namespace ppapi 171 } // namespace ppapi
159 172
160 #endif // PPAPI_PROXY_HOST_DISPATCHER_H_ 173 #endif // PPAPI_PROXY_HOST_DISPATCHER_H_
OLDNEW
« no previous file with comments | « ppapi/proxy/dispatcher.cc ('k') | ppapi/proxy/host_dispatcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698