| 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 #include "ppapi/proxy/host_dispatcher.h" | 5 #include "ppapi/proxy/host_dispatcher.h" |
| 6 | 6 |
| 7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "ppapi/c/private/ppb_proxy_private.h" | 9 #include "ppapi/c/private/ppb_proxy_private.h" |
| 10 #include "ppapi/c/ppb_var.h" | 10 #include "ppapi/c/ppb_var.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 } | 54 } |
| 55 private: | 55 private: |
| 56 bool* var_; | 56 bool* var_; |
| 57 bool old_value_; | 57 bool old_value_; |
| 58 }; | 58 }; |
| 59 | 59 |
| 60 } // namespace | 60 } // namespace |
| 61 | 61 |
| 62 HostDispatcher::HostDispatcher(PP_Module module, | 62 HostDispatcher::HostDispatcher(PP_Module module, |
| 63 PP_GetInterface_Func local_get_interface, | 63 PP_GetInterface_Func local_get_interface, |
| 64 SyncMessageStatusReceiver* sync_status, | |
| 65 const PpapiPermissions& permissions) | 64 const PpapiPermissions& permissions) |
| 66 : Dispatcher(local_get_interface, permissions), | 65 : Dispatcher(local_get_interface, permissions), |
| 67 sync_status_(sync_status), | |
| 68 pp_module_(module), | 66 pp_module_(module), |
| 69 ppb_proxy_(NULL), | 67 ppb_proxy_(NULL), |
| 70 allow_plugin_reentrancy_(false) { | 68 allow_plugin_reentrancy_(false), |
| 69 weak_ptr_factory_(this) { |
| 71 if (!g_module_to_dispatcher) | 70 if (!g_module_to_dispatcher) |
| 72 g_module_to_dispatcher = new ModuleToDispatcherMap; | 71 g_module_to_dispatcher = new ModuleToDispatcherMap; |
| 73 (*g_module_to_dispatcher)[pp_module_] = this; | 72 (*g_module_to_dispatcher)[pp_module_] = this; |
| 74 | 73 |
| 75 SetSerializationRules(new HostVarSerializationRules); | 74 SetSerializationRules(new HostVarSerializationRules); |
| 76 | 75 |
| 77 ppb_proxy_ = reinterpret_cast<const PPB_Proxy_Private*>( | 76 ppb_proxy_ = reinterpret_cast<const PPB_Proxy_Private*>( |
| 78 local_get_interface(PPB_PROXY_PRIVATE_INTERFACE)); | 77 local_get_interface(PPB_PROXY_PRIVATE_INTERFACE)); |
| 79 DCHECK(ppb_proxy_) << "The proxy interface should always be supported."; | 78 DCHECK(ppb_proxy_) << "The proxy interface should always be supported."; |
| 80 | 79 |
| 81 ppb_proxy_->SetReserveInstanceIDCallback(pp_module_, &ReserveInstanceID); | 80 ppb_proxy_->SetReserveInstanceIDCallback(pp_module_, &ReserveInstanceID); |
| 82 } | 81 } |
| 83 | 82 |
| 84 HostDispatcher::~HostDispatcher() { | 83 HostDispatcher::~HostDispatcher() { |
| 85 g_module_to_dispatcher->erase(pp_module_); | 84 g_module_to_dispatcher->erase(pp_module_); |
| 86 } | 85 } |
| 87 | 86 |
| 88 bool HostDispatcher::InitHostWithChannel( | 87 bool HostDispatcher::InitHostWithChannel( |
| 89 Delegate* delegate, | 88 Delegate* delegate, |
| 90 base::ProcessId peer_pid, | 89 base::ProcessId peer_pid, |
| 91 const IPC::ChannelHandle& channel_handle, | 90 const IPC::ChannelHandle& channel_handle, |
| 92 bool is_client, | 91 bool is_client, |
| 93 const ppapi::Preferences& preferences) { | 92 const ppapi::Preferences& preferences) { |
| 94 if (!Dispatcher::InitWithChannel(delegate, peer_pid, channel_handle, | 93 if (!Dispatcher::InitWithChannel(delegate, peer_pid, channel_handle, |
| 95 is_client)) | 94 is_client)) |
| 96 return false; | 95 return false; |
| 97 AddIOThreadMessageFilter(sync_status_.get()); | |
| 98 | |
| 99 Send(new PpapiMsg_SetPreferences(preferences)); | 96 Send(new PpapiMsg_SetPreferences(preferences)); |
| 100 return true; | 97 return true; |
| 101 } | 98 } |
| 102 | 99 |
| 103 // static | 100 // static |
| 104 HostDispatcher* HostDispatcher::GetForInstance(PP_Instance instance) { | 101 HostDispatcher* HostDispatcher::GetForInstance(PP_Instance instance) { |
| 105 if (!g_instance_to_dispatcher) | 102 if (!g_instance_to_dispatcher) |
| 106 return NULL; | 103 return NULL; |
| 107 InstanceToDispatcherMap::iterator found = g_instance_to_dispatcher->find( | 104 InstanceToDispatcherMap::iterator found = g_instance_to_dispatcher->find( |
| 108 instance); | 105 instance); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 // Don't allow sending sync messages during module shutdown. Seee the "else" | 147 // Don't allow sending sync messages during module shutdown. Seee the "else" |
| 151 // block below for why. | 148 // block below for why. |
| 152 CHECK(!PP_ToBool(ppb_proxy()->IsInModuleDestructor(pp_module()))); | 149 CHECK(!PP_ToBool(ppb_proxy()->IsInModuleDestructor(pp_module()))); |
| 153 | 150 |
| 154 // Prevent the dispatcher from going away during sync calls. Scenarios | 151 // Prevent the dispatcher from going away during sync calls. Scenarios |
| 155 // where this could happen include a Send for a sync message which while | 152 // where this could happen include a Send for a sync message which while |
| 156 // waiting for the reply, dispatches an incoming ExecuteScript call which | 153 // waiting for the reply, dispatches an incoming ExecuteScript call which |
| 157 // destroys the plugin module and in turn the dispatcher. | 154 // destroys the plugin module and in turn the dispatcher. |
| 158 ScopedModuleReference scoped_ref(this); | 155 ScopedModuleReference scoped_ref(this); |
| 159 | 156 |
| 160 sync_status_->BeginBlockOnSyncMessage(); | 157 FOR_EACH_OBSERVER(SyncMessageStatusObserver, sync_status_observer_list_, |
| 158 BeginBlockOnSyncMessage()); |
| 161 bool result = Dispatcher::Send(msg); | 159 bool result = Dispatcher::Send(msg); |
| 162 sync_status_->EndBlockOnSyncMessage(); | 160 FOR_EACH_OBSERVER(SyncMessageStatusObserver, sync_status_observer_list_, |
| 161 EndBlockOnSyncMessage()); |
| 163 | 162 |
| 164 return result; | 163 return result; |
| 165 } else { | 164 } else { |
| 166 // We don't want to have a scoped ref for async message cases since since | 165 // We don't want to have a scoped ref for async message cases since since |
| 167 // async messages are sent during module desruction. In this case, the | 166 // async messages are sent during module desruction. In this case, the |
| 168 // module will have a 0 refcount and addrefing and releasing it will | 167 // module will have a 0 refcount and addrefing and releasing it will |
| 169 // reenter the destructor and it will crash. | 168 // reenter the destructor and it will crash. |
| 170 return Dispatcher::Send(msg); | 169 return Dispatcher::Send(msg); |
| 171 } | 170 } |
| 172 } | 171 } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 std::pair<PluginSupportedMap::iterator, bool> iter_success_pair; | 232 std::pair<PluginSupportedMap::iterator, bool> iter_success_pair; |
| 234 iter_success_pair = plugin_supported_.insert( | 233 iter_success_pair = plugin_supported_.insert( |
| 235 PluginSupportedMap::value_type(iface_name, supported)); | 234 PluginSupportedMap::value_type(iface_name, supported)); |
| 236 iter = iter_success_pair.first; | 235 iter = iter_success_pair.first; |
| 237 } | 236 } |
| 238 if (iter->second) | 237 if (iter->second) |
| 239 return proxied_interface; | 238 return proxied_interface; |
| 240 return NULL; | 239 return NULL; |
| 241 } | 240 } |
| 242 | 241 |
| 242 base::Closure HostDispatcher::AddSyncMessageStatusObserver( |
| 243 SyncMessageStatusObserver* obs) { |
| 244 sync_status_observer_list_.AddObserver(obs); |
| 245 return base::Bind(&HostDispatcher::RemoveSyncMessageStatusObserver, |
| 246 weak_ptr_factory_.GetWeakPtr(), |
| 247 obs); |
| 248 } |
| 249 |
| 250 void HostDispatcher::RemoveSyncMessageStatusObserver( |
| 251 SyncMessageStatusObserver* obs) { |
| 252 sync_status_observer_list_.RemoveObserver(obs); |
| 253 } |
| 254 |
| 243 void HostDispatcher::AddFilter(IPC::Listener* listener) { | 255 void HostDispatcher::AddFilter(IPC::Listener* listener) { |
| 244 filters_.push_back(listener); | 256 filters_.push_back(listener); |
| 245 } | 257 } |
| 246 | 258 |
| 247 void HostDispatcher::OnInvalidMessageReceived() { | 259 void HostDispatcher::OnInvalidMessageReceived() { |
| 248 // TODO(brettw) bug 95345 kill the plugin when an invalid message is | 260 // TODO(brettw) bug 95345 kill the plugin when an invalid message is |
| 249 // received. | 261 // received. |
| 250 } | 262 } |
| 251 | 263 |
| 252 void HostDispatcher::OnHostMsgLogWithSource(PP_Instance instance, | 264 void HostDispatcher::OnHostMsgLogWithSource(PP_Instance instance, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 272 } | 284 } |
| 273 } | 285 } |
| 274 | 286 |
| 275 ScopedModuleReference::~ScopedModuleReference() { | 287 ScopedModuleReference::~ScopedModuleReference() { |
| 276 if (dispatcher_) | 288 if (dispatcher_) |
| 277 dispatcher_->ppb_proxy()->ReleaseModule(dispatcher_->pp_module()); | 289 dispatcher_->ppb_proxy()->ReleaseModule(dispatcher_->pp_module()); |
| 278 } | 290 } |
| 279 | 291 |
| 280 } // namespace proxy | 292 } // namespace proxy |
| 281 } // namespace ppapi | 293 } // namespace ppapi |
| OLD | NEW |