[email protected] | 4c41d3f | 2012-02-15 01:44:47 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "ppapi/proxy/plugin_dispatcher.h" |
| 6 | |
| 7 | #include <map> |
| 8 | |
[email protected] | 709a847e | 2010-11-10 01:16:11 | [diff] [blame] | 9 | #include "base/compiler_specific.h" |
[email protected] | 83ad1c4 | 2013-05-01 16:56:27 | [diff] [blame] | 10 | #include "base/debug/trace_event.h" |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 11 | #include "base/logging.h" |
[email protected] | aabfa65 | 2011-07-13 23:28:44 | [diff] [blame] | 12 | #include "base/message_loop.h" |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 13 | #include "ipc/ipc_message.h" |
| 14 | #include "ipc/ipc_sync_channel.h" |
[email protected] | 83ad1c4 | 2013-05-01 16:56:27 | [diff] [blame] | 15 | #include "ipc/ipc_sync_message_filter.h" |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 16 | #include "ppapi/c/pp_errors.h" |
[email protected] | e8f07ac | 2012-01-03 17:43:36 | [diff] [blame] | 17 | #include "ppapi/c/ppp_instance.h" |
[email protected] | 11d0c36 | 2012-10-11 02:02:11 | [diff] [blame] | 18 | #include "ppapi/proxy/flash_resource.h" |
[email protected] | a1686e27 | 2012-11-01 23:39:34 | [diff] [blame] | 19 | #include "ppapi/proxy/flash_clipboard_resource.h" |
[email protected] | 0c92b0d | 2012-12-08 00:46:23 | [diff] [blame] | 20 | #include "ppapi/proxy/flash_file_resource.h" |
[email protected] | f511881 | 2012-08-24 19:54:30 | [diff] [blame] | 21 | #include "ppapi/proxy/gamepad_resource.h" |
[email protected] | 5c96602 | 2011-09-13 18:09:37 | [diff] [blame] | 22 | #include "ppapi/proxy/interface_list.h" |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 23 | #include "ppapi/proxy/interface_proxy.h" |
[email protected] | 6018116 | 2013-04-26 22:02:53 | [diff] [blame] | 24 | #include "ppapi/proxy/plugin_globals.h" |
[email protected] | 2cc06224 | 2011-03-10 21:16:34 | [diff] [blame] | 25 | #include "ppapi/proxy/plugin_message_filter.h" |
[email protected] | 6239d34 | 2011-05-06 22:55:47 | [diff] [blame] | 26 | #include "ppapi/proxy/plugin_resource_tracker.h" |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 27 | #include "ppapi/proxy/plugin_var_serialization_rules.h" |
| 28 | #include "ppapi/proxy/ppapi_messages.h" |
[email protected] | ceadc39 | 2011-06-15 23:04:24 | [diff] [blame] | 29 | #include "ppapi/proxy/ppb_instance_proxy.h" |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 30 | #include "ppapi/proxy/ppp_class_proxy.h" |
[email protected] | 6239d34 | 2011-05-06 22:55:47 | [diff] [blame] | 31 | #include "ppapi/proxy/resource_creation_proxy.h" |
[email protected] | eccf8031 | 2012-07-14 15:43:42 | [diff] [blame] | 32 | #include "ppapi/proxy/resource_message_params.h" |
| 33 | #include "ppapi/shared_impl/ppapi_globals.h" |
[email protected] | 4c41d3f | 2012-02-15 01:44:47 | [diff] [blame] | 34 | #include "ppapi/shared_impl/proxy_lock.h" |
[email protected] | 7f8b26b | 2011-08-18 15:41:01 | [diff] [blame] | 35 | #include "ppapi/shared_impl/resource.h" |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 36 | |
[email protected] | 339fbcff | 2012-02-29 16:10:32 | [diff] [blame] | 37 | #if defined(OS_POSIX) && !defined(OS_NACL) |
[email protected] | 2025d00 | 2012-11-14 20:54:35 | [diff] [blame] | 38 | #include "base/posix/eintr_wrapper.h" |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 39 | #include "ipc/ipc_channel_posix.h" |
| 40 | #endif |
| 41 | |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 42 | namespace ppapi { |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 43 | namespace proxy { |
| 44 | |
| 45 | namespace { |
| 46 | |
[email protected] | 465faa2 | 2011-02-08 16:31:46 | [diff] [blame] | 47 | typedef std::map<PP_Instance, PluginDispatcher*> InstanceToDispatcherMap; |
| 48 | InstanceToDispatcherMap* g_instance_to_dispatcher = NULL; |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 49 | |
[email protected] | a9b16dd | 2012-01-31 05:00:26 | [diff] [blame] | 50 | typedef std::set<PluginDispatcher*> DispatcherSet; |
| 51 | DispatcherSet* g_live_dispatchers = NULL; |
| 52 | |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 53 | } // namespace |
| 54 | |
[email protected] | 06e0a34 | 2011-09-27 04:24:30 | [diff] [blame] | 55 | InstanceData::InstanceData() |
[email protected] | 22fdaa6 | 2012-11-30 01:55:44 | [diff] [blame] | 56 | : is_request_surrounding_text_pending(false), |
[email protected] | a8e7214 | 2012-08-21 17:24:20 | [diff] [blame] | 57 | should_do_request_surrounding_text(false) { |
[email protected] | c7bf745 | 2011-09-12 21:31:50 | [diff] [blame] | 58 | } |
| 59 | |
[email protected] | 0f41c01 | 2011-10-21 19:49:20 | [diff] [blame] | 60 | InstanceData::~InstanceData() { |
| 61 | // Run any pending mouse lock callback to prevent leaks. |
[email protected] | f0c8624 | 2013-06-02 21:25:43 | [diff] [blame] | 62 | if (mouse_lock_callback.get()) |
[email protected] | aed9653 | 2012-06-23 14:27:42 | [diff] [blame] | 63 | mouse_lock_callback->Abort(); |
[email protected] | 0f41c01 | 2011-10-21 19:49:20 | [diff] [blame] | 64 | } |
| 65 | |
[email protected] | f0ecb55 | 2012-05-11 22:09:11 | [diff] [blame] | 66 | PluginDispatcher::PluginDispatcher(PP_GetInterface_Func get_interface, |
[email protected] | 195d4cde | 2012-10-02 18:12:41 | [diff] [blame] | 67 | const PpapiPermissions& permissions, |
[email protected] | bc2eeb4 | 2012-05-02 22:35:53 | [diff] [blame] | 68 | bool incognito) |
[email protected] | 195d4cde | 2012-10-02 18:12:41 | [diff] [blame] | 69 | : Dispatcher(get_interface, permissions), |
[email protected] | 208aad79 | 2011-05-26 19:05:28 | [diff] [blame] | 70 | plugin_delegate_(NULL), |
[email protected] | 373a95a | 2011-07-01 16:58:14 | [diff] [blame] | 71 | received_preferences_(false), |
[email protected] | bc2eeb4 | 2012-05-02 22:35:53 | [diff] [blame] | 72 | plugin_dispatcher_id_(0), |
| 73 | incognito_(incognito) { |
[email protected] | 67600b9 | 2012-03-10 06:51:48 | [diff] [blame] | 74 | SetSerializationRules(new PluginVarSerializationRules(AsWeakPtr())); |
[email protected] | a9b16dd | 2012-01-31 05:00:26 | [diff] [blame] | 75 | |
| 76 | if (!g_live_dispatchers) |
| 77 | g_live_dispatchers = new DispatcherSet; |
| 78 | g_live_dispatchers->insert(this); |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | PluginDispatcher::~PluginDispatcher() { |
[email protected] | 6018116 | 2013-04-26 22:02:53 | [diff] [blame] | 82 | PluginGlobals::Get()->plugin_var_tracker()->DidDeleteDispatcher(this); |
| 83 | |
[email protected] | 373a95a | 2011-07-01 16:58:14 | [diff] [blame] | 84 | if (plugin_delegate_) |
| 85 | plugin_delegate_->Unregister(plugin_dispatcher_id_); |
[email protected] | a9b16dd | 2012-01-31 05:00:26 | [diff] [blame] | 86 | |
| 87 | g_live_dispatchers->erase(this); |
| 88 | if (g_live_dispatchers->empty()) { |
| 89 | delete g_live_dispatchers; |
| 90 | g_live_dispatchers = NULL; |
| 91 | } |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | // static |
[email protected] | 4614f19 | 2011-01-21 00:26:43 | [diff] [blame] | 95 | PluginDispatcher* PluginDispatcher::GetForInstance(PP_Instance instance) { |
[email protected] | 465faa2 | 2011-02-08 16:31:46 | [diff] [blame] | 96 | if (!g_instance_to_dispatcher) |
| 97 | return NULL; |
| 98 | InstanceToDispatcherMap::iterator found = g_instance_to_dispatcher->find( |
| 99 | instance); |
| 100 | if (found == g_instance_to_dispatcher->end()) |
| 101 | return NULL; |
| 102 | return found->second; |
[email protected] | 4614f19 | 2011-01-21 00:26:43 | [diff] [blame] | 103 | } |
| 104 | |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 105 | // static |
[email protected] | 7f8b26b | 2011-08-18 15:41:01 | [diff] [blame] | 106 | PluginDispatcher* PluginDispatcher::GetForResource(const Resource* resource) { |
| 107 | return GetForInstance(resource->pp_instance()); |
| 108 | } |
| 109 | |
| 110 | // static |
[email protected] | 5c96602 | 2011-09-13 18:09:37 | [diff] [blame] | 111 | const void* PluginDispatcher::GetBrowserInterface(const char* interface_name) { |
[email protected] | c0514ee | 2012-11-02 21:41:20 | [diff] [blame] | 112 | if (!interface_name) { |
| 113 | DLOG(WARNING) << "|interface_name| is null. Did you forget to add " |
| 114 | "the |interface_name()| template function to the interface's C++ " |
| 115 | "wrapper?"; |
| 116 | return NULL; |
| 117 | } |
[email protected] | 234c139 | 2012-09-27 23:30:41 | [diff] [blame] | 118 | |
[email protected] | 5c96602 | 2011-09-13 18:09:37 | [diff] [blame] | 119 | return InterfaceList::GetInstance()->GetInterfaceForPPB(interface_name); |
| 120 | } |
| 121 | |
[email protected] | a9b16dd | 2012-01-31 05:00:26 | [diff] [blame] | 122 | // static |
| 123 | void PluginDispatcher::LogWithSource(PP_Instance instance, |
[email protected] | 598816ad | 2012-12-13 01:34:32 | [diff] [blame] | 124 | PP_LogLevel level, |
[email protected] | a9b16dd | 2012-01-31 05:00:26 | [diff] [blame] | 125 | const std::string& source, |
| 126 | const std::string& value) { |
| 127 | if (!g_live_dispatchers || !g_instance_to_dispatcher) |
| 128 | return; |
| 129 | |
| 130 | if (instance) { |
| 131 | InstanceToDispatcherMap::iterator found = |
| 132 | g_instance_to_dispatcher->find(instance); |
| 133 | if (found != g_instance_to_dispatcher->end()) { |
| 134 | // Send just to this specific dispatcher. |
| 135 | found->second->Send(new PpapiHostMsg_LogWithSource( |
| 136 | instance, static_cast<int>(level), source, value)); |
| 137 | return; |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | // Instance 0 or invalid, send to all dispatchers. |
| 142 | for (DispatcherSet::iterator i = g_live_dispatchers->begin(); |
| 143 | i != g_live_dispatchers->end(); ++i) { |
| 144 | (*i)->Send(new PpapiHostMsg_LogWithSource( |
| 145 | instance, static_cast<int>(level), source, value)); |
| 146 | } |
| 147 | } |
| 148 | |
[email protected] | 5c96602 | 2011-09-13 18:09:37 | [diff] [blame] | 149 | const void* PluginDispatcher::GetPluginInterface( |
| 150 | const std::string& interface_name) { |
| 151 | InterfaceMap::iterator found = plugin_interfaces_.find(interface_name); |
| 152 | if (found == plugin_interfaces_.end()) { |
| 153 | const void* ret = local_get_interface()(interface_name.c_str()); |
| 154 | plugin_interfaces_.insert(std::make_pair(interface_name, ret)); |
| 155 | return ret; |
| 156 | } |
| 157 | return found->second; |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 158 | } |
| 159 | |
[email protected] | e2614c6 | 2011-04-16 22:12:45 | [diff] [blame] | 160 | bool PluginDispatcher::InitPluginWithChannel( |
[email protected] | d259a8e | 2011-05-18 22:31:09 | [diff] [blame] | 161 | PluginDelegate* delegate, |
[email protected] | 108fd34 | 2013-01-04 20:46:54 | [diff] [blame] | 162 | base::ProcessId peer_pid, |
[email protected] | 2cc06224 | 2011-03-10 21:16:34 | [diff] [blame] | 163 | const IPC::ChannelHandle& channel_handle, |
| 164 | bool is_client) { |
[email protected] | 108fd34 | 2013-01-04 20:46:54 | [diff] [blame] | 165 | if (!Dispatcher::InitWithChannel(delegate, peer_pid, channel_handle, |
| 166 | is_client)) |
[email protected] | 2cc06224 | 2011-03-10 21:16:34 | [diff] [blame] | 167 | return false; |
[email protected] | d259a8e | 2011-05-18 22:31:09 | [diff] [blame] | 168 | plugin_delegate_ = delegate; |
[email protected] | 373a95a | 2011-07-01 16:58:14 | [diff] [blame] | 169 | plugin_dispatcher_id_ = plugin_delegate_->Register(this); |
[email protected] | 2cc06224 | 2011-03-10 21:16:34 | [diff] [blame] | 170 | |
[email protected] | 83ad1c4 | 2013-05-01 16:56:27 | [diff] [blame] | 171 | sync_filter_ = new IPC::SyncMessageFilter(delegate->GetShutdownEvent()); |
| 172 | channel()->AddFilter(sync_filter_.get()); |
| 173 | |
[email protected] | 2cc06224 | 2011-03-10 21:16:34 | [diff] [blame] | 174 | // The message filter will intercept and process certain messages directly |
| 175 | // on the I/O thread. |
| 176 | channel()->AddFilter( |
| 177 | new PluginMessageFilter(delegate->GetGloballySeenInstanceIDSet())); |
| 178 | return true; |
| 179 | } |
| 180 | |
[email protected] | 7cf4091 | 2010-12-09 18:25:03 | [diff] [blame] | 181 | bool PluginDispatcher::IsPlugin() const { |
| 182 | return true; |
| 183 | } |
| 184 | |
[email protected] | 83ad1c4 | 2013-05-01 16:56:27 | [diff] [blame] | 185 | bool PluginDispatcher::SendMessage(IPC::Message* msg) { |
| 186 | // Currently we need to choose between two different mechanisms for sending. |
| 187 | // On the main thread we use the regular dispatch Send() method, on another |
| 188 | // thread we use SyncMessageFilter. |
| 189 | if (PpapiGlobals::Get()->GetMainThreadMessageLoop()->BelongsToCurrentThread()) |
| 190 | return Dispatcher::Send(msg); |
| 191 | return sync_filter_->Send(msg); |
| 192 | } |
| 193 | |
[email protected] | b00bbb3 | 2011-03-30 19:02:14 | [diff] [blame] | 194 | bool PluginDispatcher::Send(IPC::Message* msg) { |
[email protected] | 366ae24 | 2011-05-10 02:23:58 | [diff] [blame] | 195 | TRACE_EVENT2("ppapi proxy", "PluginDispatcher::Send", |
| 196 | "Class", IPC_MESSAGE_ID_CLASS(msg->type()), |
| 197 | "Line", IPC_MESSAGE_ID_LINE(msg->type())); |
[email protected] | b00bbb3 | 2011-03-30 19:02:14 | [diff] [blame] | 198 | // We always want plugin->renderer messages to arrive in-order. If some sync |
[email protected] | 4c41d3f | 2012-02-15 01:44:47 | [diff] [blame] | 199 | // and some async messages are sent in response to a synchronous |
[email protected] | b00bbb3 | 2011-03-30 19:02:14 | [diff] [blame] | 200 | // renderer->plugin call, the sync reply will be processed before the async |
| 201 | // reply, and everything will be confused. |
| 202 | // |
| 203 | // Allowing all async messages to unblock the renderer means more reentrancy |
| 204 | // there but gives correct ordering. |
[email protected] | 80f86a9 | 2012-04-09 23:58:14 | [diff] [blame] | 205 | // |
| 206 | // We don't want reply messages to unblock however, as they will potentially |
| 207 | // end up on the wrong queue - see crbug.com/122443 |
| 208 | if (!msg->is_reply()) |
| 209 | msg->set_unblock(true); |
[email protected] | 4c41d3f | 2012-02-15 01:44:47 | [diff] [blame] | 210 | if (msg->is_sync()) { |
| 211 | // Synchronous messages might be re-entrant, so we need to drop the lock. |
| 212 | ProxyAutoUnlock unlock; |
[email protected] | 83ad1c4 | 2013-05-01 16:56:27 | [diff] [blame] | 213 | return SendMessage(msg); |
[email protected] | 4c41d3f | 2012-02-15 01:44:47 | [diff] [blame] | 214 | } |
[email protected] | 83ad1c4 | 2013-05-01 16:56:27 | [diff] [blame] | 215 | return SendMessage(msg); |
[email protected] | b00bbb3 | 2011-03-30 19:02:14 | [diff] [blame] | 216 | } |
| 217 | |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 218 | bool PluginDispatcher::OnMessageReceived(const IPC::Message& msg) { |
[email protected] | 4c41d3f | 2012-02-15 01:44:47 | [diff] [blame] | 219 | // We need to grab the proxy lock to ensure that we don't collide with the |
| 220 | // plugin making pepper calls on a different thread. |
| 221 | ProxyAutoLock lock; |
[email protected] | 366ae24 | 2011-05-10 02:23:58 | [diff] [blame] | 222 | TRACE_EVENT2("ppapi proxy", "PluginDispatcher::OnMessageReceived", |
| 223 | "Class", IPC_MESSAGE_ID_CLASS(msg.type()), |
| 224 | "Line", IPC_MESSAGE_ID_LINE(msg.type())); |
[email protected] | eccf8031 | 2012-07-14 15:43:42 | [diff] [blame] | 225 | |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 226 | if (msg.routing_id() == MSG_ROUTING_CONTROL) { |
| 227 | // Handle some plugin-specific control messages. |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 228 | bool handled = true; |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 229 | IPC_BEGIN_MESSAGE_MAP(PluginDispatcher, msg) |
[email protected] | eccf8031 | 2012-07-14 15:43:42 | [diff] [blame] | 230 | IPC_MESSAGE_HANDLER(PpapiPluginMsg_ResourceReply, OnMsgResourceReply) |
[email protected] | 465faa2 | 2011-02-08 16:31:46 | [diff] [blame] | 231 | IPC_MESSAGE_HANDLER(PpapiMsg_SupportsInterface, OnMsgSupportsInterface) |
[email protected] | 208aad79 | 2011-05-26 19:05:28 | [diff] [blame] | 232 | IPC_MESSAGE_HANDLER(PpapiMsg_SetPreferences, OnMsgSetPreferences) |
[email protected] | 5c96602 | 2011-09-13 18:09:37 | [diff] [blame] | 233 | IPC_MESSAGE_UNHANDLED(handled = false); |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 234 | IPC_END_MESSAGE_MAP() |
[email protected] | 5c96602 | 2011-09-13 18:09:37 | [diff] [blame] | 235 | if (handled) |
[email protected] | 37fe036 | 2011-09-13 04:00:33 | [diff] [blame] | 236 | return true; |
[email protected] | 37fe036 | 2011-09-13 04:00:33 | [diff] [blame] | 237 | } |
[email protected] | 5c96602 | 2011-09-13 18:09:37 | [diff] [blame] | 238 | return Dispatcher::OnMessageReceived(msg); |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 239 | } |
| 240 | |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 241 | void PluginDispatcher::OnChannelError() { |
[email protected] | 4f15d284 | 2011-02-15 17:36:33 | [diff] [blame] | 242 | Dispatcher::OnChannelError(); |
| 243 | |
[email protected] | 4b417e5 | 2011-04-18 22:51:08 | [diff] [blame] | 244 | // The renderer has crashed or exited. This channel and all instances |
| 245 | // associated with it are no longer valid. |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 246 | ForceFreeAllInstances(); |
| 247 | // TODO(brettw) free resources too! |
| 248 | delete this; |
| 249 | } |
| 250 | |
[email protected] | f56279c | 2011-02-02 18:12:31 | [diff] [blame] | 251 | void PluginDispatcher::DidCreateInstance(PP_Instance instance) { |
[email protected] | 465faa2 | 2011-02-08 16:31:46 | [diff] [blame] | 252 | if (!g_instance_to_dispatcher) |
| 253 | g_instance_to_dispatcher = new InstanceToDispatcherMap; |
| 254 | (*g_instance_to_dispatcher)[instance] = this; |
| 255 | |
[email protected] | f56279c | 2011-02-02 18:12:31 | [diff] [blame] | 256 | instance_map_[instance] = InstanceData(); |
| 257 | } |
| 258 | |
| 259 | void PluginDispatcher::DidDestroyInstance(PP_Instance instance) { |
| 260 | InstanceDataMap::iterator it = instance_map_.find(instance); |
| 261 | if (it != instance_map_.end()) |
| 262 | instance_map_.erase(it); |
[email protected] | 465faa2 | 2011-02-08 16:31:46 | [diff] [blame] | 263 | |
| 264 | if (g_instance_to_dispatcher) { |
| 265 | InstanceToDispatcherMap::iterator found = g_instance_to_dispatcher->find( |
| 266 | instance); |
| 267 | if (found != g_instance_to_dispatcher->end()) { |
| 268 | DCHECK(found->second == this); |
| 269 | g_instance_to_dispatcher->erase(found); |
| 270 | } else { |
| 271 | NOTREACHED(); |
| 272 | } |
| 273 | } |
[email protected] | f56279c | 2011-02-02 18:12:31 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | InstanceData* PluginDispatcher::GetInstanceData(PP_Instance instance) { |
| 277 | InstanceDataMap::iterator it = instance_map_.find(instance); |
| 278 | return (it == instance_map_.end()) ? NULL : &it->second; |
| 279 | } |
| 280 | |
[email protected] | 4f200612 | 2012-04-30 05:13:17 | [diff] [blame] | 281 | thunk::PPB_Instance_API* PluginDispatcher::GetInstanceAPI() { |
| 282 | return static_cast<PPB_Instance_Proxy*>( |
| 283 | GetInterfaceProxy(API_ID_PPB_INSTANCE)); |
| 284 | } |
| 285 | |
| 286 | thunk::ResourceCreationAPI* PluginDispatcher::GetResourceCreationAPI() { |
| 287 | return static_cast<ResourceCreationProxy*>( |
| 288 | GetInterfaceProxy(API_ID_RESOURCE_CREATION)); |
[email protected] | 6239d34 | 2011-05-06 22:55:47 | [diff] [blame] | 289 | } |
| 290 | |
[email protected] | 00c0d04 | 2012-09-10 07:06:39 | [diff] [blame] | 291 | // static |
| 292 | void PluginDispatcher::DispatchResourceReply( |
| 293 | const ppapi::proxy::ResourceMessageReplyParams& reply_params, |
| 294 | const IPC::Message& nested_msg) { |
[email protected] | 719b781 | 2012-11-08 00:33:21 | [diff] [blame] | 295 | // We need to grab the proxy lock to ensure that we don't collide with the |
| 296 | // plugin making pepper calls on a different thread. |
| 297 | ProxyAutoLock lock; |
| 298 | LockedDispatchResourceReply(reply_params, nested_msg); |
[email protected] | 00c0d04 | 2012-09-10 07:06:39 | [diff] [blame] | 299 | } |
| 300 | |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 301 | void PluginDispatcher::ForceFreeAllInstances() { |
[email protected] | 4f15d284 | 2011-02-15 17:36:33 | [diff] [blame] | 302 | if (!g_instance_to_dispatcher) |
| 303 | return; |
| 304 | |
| 305 | // Iterating will remove each item from the map, so we need to make a copy |
| 306 | // to avoid things changing out from under is. |
| 307 | InstanceToDispatcherMap temp_map = *g_instance_to_dispatcher; |
| 308 | for (InstanceToDispatcherMap::iterator i = temp_map.begin(); |
| 309 | i != temp_map.end(); ++i) { |
| 310 | if (i->second == this) { |
| 311 | // Synthesize an "instance destroyed" message, this will notify the |
| 312 | // plugin and also remove it from our list of tracked plugins. |
[email protected] | ac4b54d | 2011-10-20 23:09:28 | [diff] [blame] | 313 | PpapiMsg_PPPInstance_DidDestroy msg(API_ID_PPP_INSTANCE, i->first); |
[email protected] | 4585fbc | 2011-06-13 17:17:56 | [diff] [blame] | 314 | OnMessageReceived(msg); |
[email protected] | 4f15d284 | 2011-02-15 17:36:33 | [diff] [blame] | 315 | } |
| 316 | } |
[email protected] | 176c7392 | 2010-12-03 17:32:19 | [diff] [blame] | 317 | } |
| 318 | |
[email protected] | eccf8031 | 2012-07-14 15:43:42 | [diff] [blame] | 319 | void PluginDispatcher::OnMsgResourceReply( |
| 320 | const ppapi::proxy::ResourceMessageReplyParams& reply_params, |
| 321 | const IPC::Message& nested_msg) { |
[email protected] | 719b781 | 2012-11-08 00:33:21 | [diff] [blame] | 322 | LockedDispatchResourceReply(reply_params, nested_msg); |
[email protected] | eccf8031 | 2012-07-14 15:43:42 | [diff] [blame] | 323 | } |
| 324 | |
[email protected] | 465faa2 | 2011-02-08 16:31:46 | [diff] [blame] | 325 | void PluginDispatcher::OnMsgSupportsInterface( |
| 326 | const std::string& interface_name, |
| 327 | bool* result) { |
[email protected] | 5c96602 | 2011-09-13 18:09:37 | [diff] [blame] | 328 | *result = !!GetPluginInterface(interface_name); |
[email protected] | e8f07ac | 2012-01-03 17:43:36 | [diff] [blame] | 329 | |
| 330 | // Do fallback for PPP_Instance. This is a hack here and if we have more |
| 331 | // cases like this it should be generalized. The PPP_Instance proxy always |
| 332 | // proxies the 1.1 interface, and then does fallback to 1.0 inside the |
| 333 | // plugin process (see PPP_Instance_Proxy). So here we return true for |
| 334 | // supporting the 1.1 interface if either 1.1 or 1.0 is supported. |
| 335 | if (!*result && interface_name == PPP_INSTANCE_INTERFACE) |
| 336 | *result = !!GetPluginInterface(PPP_INSTANCE_INTERFACE_1_0); |
[email protected] | 465faa2 | 2011-02-08 16:31:46 | [diff] [blame] | 337 | } |
| 338 | |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 339 | void PluginDispatcher::OnMsgSetPreferences(const Preferences& prefs) { |
[email protected] | 208aad79 | 2011-05-26 19:05:28 | [diff] [blame] | 340 | // The renderer may send us preferences more than once (currently this |
| 341 | // happens every time a new plugin instance is created). Since we don't have |
| 342 | // a way to signal to the plugin that the preferences have changed, changing |
| 343 | // the default fonts and such in the middle of a running plugin could be |
| 344 | // confusing to it. As a result, we never allow the preferences to be changed |
| 345 | // once they're set. The user will have to restart to get new font prefs |
| 346 | // propogated to plugins. |
| 347 | if (!received_preferences_) { |
| 348 | received_preferences_ = true; |
| 349 | preferences_ = prefs; |
| 350 | } |
| 351 | } |
| 352 | |
[email protected] | 719b781 | 2012-11-08 00:33:21 | [diff] [blame] | 353 | // static |
| 354 | void PluginDispatcher::LockedDispatchResourceReply( |
| 355 | const ppapi::proxy::ResourceMessageReplyParams& reply_params, |
| 356 | const IPC::Message& nested_msg) { |
| 357 | Resource* resource = PpapiGlobals::Get()->GetResourceTracker()->GetResource( |
| 358 | reply_params.pp_resource()); |
| 359 | if (!resource) { |
[email protected] | 4f01c76 | 2012-12-05 02:44:18 | [diff] [blame] | 360 | DLOG_IF(INFO, reply_params.sequence() != 0) |
| 361 | << "Pepper resource reply message received but the resource doesn't " |
| 362 | "exist (probably has been destroyed)."; |
[email protected] | 719b781 | 2012-11-08 00:33:21 | [diff] [blame] | 363 | return; |
| 364 | } |
| 365 | resource->OnReplyReceived(reply_params, nested_msg); |
| 366 | } |
| 367 | |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 368 | } // namespace proxy |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 369 | } // namespace ppapi |