| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/dispatcher.h" | 5 #include "ppapi/proxy/dispatcher.h" |
| 6 | 6 |
| 7 #include <string.h> // For memset. | 7 #include <string.h> // For memset. |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 | 10 |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "ipc/ipc_message.h" | 13 #include "ipc/ipc_message.h" |
| 14 #include "ipc/ipc_sync_channel.h" | 14 #include "ipc/ipc_sync_channel.h" |
| 15 #include "ipc/ipc_test_sink.h" |
| 15 #include "ppapi/c/dev/ppb_buffer_dev.h" | 16 #include "ppapi/c/dev/ppb_buffer_dev.h" |
| 16 #include "ppapi/c/dev/ppb_char_set_dev.h" | 17 #include "ppapi/c/dev/ppb_char_set_dev.h" |
| 17 #include "ppapi/c/dev/ppb_cursor_control_dev.h" | 18 #include "ppapi/c/dev/ppb_cursor_control_dev.h" |
| 18 #include "ppapi/c/dev/ppb_cursor_control_dev.h" | 19 #include "ppapi/c/dev/ppb_cursor_control_dev.h" |
| 19 #include "ppapi/c/dev/ppb_font_dev.h" | 20 #include "ppapi/c/dev/ppb_font_dev.h" |
| 20 #include "ppapi/c/dev/ppb_fullscreen_dev.h" | 21 #include "ppapi/c/dev/ppb_fullscreen_dev.h" |
| 21 #include "ppapi/c/dev/ppb_fullscreen_dev.h" | 22 #include "ppapi/c/dev/ppb_fullscreen_dev.h" |
| 22 #include "ppapi/c/dev/ppb_testing_dev.h" | 23 #include "ppapi/c/dev/ppb_testing_dev.h" |
| 23 #include "ppapi/c/dev/ppb_var_deprecated.h" | 24 #include "ppapi/c/dev/ppb_var_deprecated.h" |
| 24 #include "ppapi/c/pp_errors.h" | 25 #include "ppapi/c/pp_errors.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 #include "ppapi/proxy/ppp_instance_proxy.h" | 59 #include "ppapi/proxy/ppp_instance_proxy.h" |
| 59 #include "ppapi/proxy/var_serialization_rules.h" | 60 #include "ppapi/proxy/var_serialization_rules.h" |
| 60 | 61 |
| 61 namespace pp { | 62 namespace pp { |
| 62 namespace proxy { | 63 namespace proxy { |
| 63 | 64 |
| 64 Dispatcher::Dispatcher(base::ProcessHandle remote_process_handle, | 65 Dispatcher::Dispatcher(base::ProcessHandle remote_process_handle, |
| 65 GetInterfaceFunc local_get_interface) | 66 GetInterfaceFunc local_get_interface) |
| 66 : pp_module_(0), | 67 : pp_module_(0), |
| 67 remote_process_handle_(remote_process_handle), | 68 remote_process_handle_(remote_process_handle), |
| 69 test_sink_(NULL), |
| 68 disallow_trusted_interfaces_(false), // TODO(brettw) make this settable. | 70 disallow_trusted_interfaces_(false), // TODO(brettw) make this settable. |
| 69 local_get_interface_(local_get_interface), | 71 local_get_interface_(local_get_interface), |
| 70 declared_supported_remote_interfaces_(false), | 72 declared_supported_remote_interfaces_(false), |
| 71 callback_tracker_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 73 callback_tracker_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 72 memset(id_to_proxy_, 0, | 74 memset(id_to_proxy_, 0, |
| 73 static_cast<int>(INTERFACE_ID_COUNT) * sizeof(InterfaceProxy*)); | 75 static_cast<int>(INTERFACE_ID_COUNT) * sizeof(InterfaceProxy*)); |
| 74 } | 76 } |
| 75 | 77 |
| 76 Dispatcher::~Dispatcher() { | 78 Dispatcher::~Dispatcher() { |
| 77 } | 79 } |
| 78 | 80 |
| 79 bool Dispatcher::InitWithChannel(MessageLoop* ipc_message_loop, | 81 bool Dispatcher::InitWithChannel(MessageLoop* ipc_message_loop, |
| 80 const IPC::ChannelHandle& channel_handle, | 82 const IPC::ChannelHandle& channel_handle, |
| 81 bool is_client, | 83 bool is_client, |
| 82 base::WaitableEvent* shutdown_event) { | 84 base::WaitableEvent* shutdown_event) { |
| 83 IPC::Channel::Mode mode = is_client ? IPC::Channel::MODE_CLIENT | 85 IPC::Channel::Mode mode = is_client ? IPC::Channel::MODE_CLIENT |
| 84 : IPC::Channel::MODE_SERVER; | 86 : IPC::Channel::MODE_SERVER; |
| 85 channel_.reset(new IPC::SyncChannel(channel_handle, mode, this, | 87 channel_.reset(new IPC::SyncChannel(channel_handle, mode, this, |
| 86 ipc_message_loop, false, shutdown_event)); | 88 ipc_message_loop, false, shutdown_event)); |
| 87 return true; | 89 return true; |
| 88 } | 90 } |
| 89 | 91 |
| 92 void Dispatcher::InitWithTestSink(IPC::TestSink* test_sink) { |
| 93 DCHECK(!test_sink_); |
| 94 test_sink_ = test_sink; |
| 95 } |
| 96 |
| 90 bool Dispatcher::OnMessageReceived(const IPC::Message& msg) { | 97 bool Dispatcher::OnMessageReceived(const IPC::Message& msg) { |
| 91 // Control messages. | 98 // Control messages. |
| 92 if (msg.routing_id() == MSG_ROUTING_CONTROL) { | 99 if (msg.routing_id() == MSG_ROUTING_CONTROL) { |
| 93 bool handled = true; | 100 bool handled = true; |
| 94 IPC_BEGIN_MESSAGE_MAP(Dispatcher, msg) | 101 IPC_BEGIN_MESSAGE_MAP(Dispatcher, msg) |
| 95 IPC_MESSAGE_HANDLER(PpapiMsg_DeclareInterfaces, | 102 IPC_MESSAGE_HANDLER(PpapiMsg_DeclareInterfaces, |
| 96 OnMsgDeclareInterfaces) | 103 OnMsgDeclareInterfaces) |
| 97 IPC_MESSAGE_HANDLER(PpapiMsg_SupportsInterface, OnMsgSupportsInterface) | 104 IPC_MESSAGE_HANDLER(PpapiMsg_SupportsInterface, OnMsgSupportsInterface) |
| 98 IPC_MESSAGE_FORWARD(PpapiMsg_ExecuteCallback, &callback_tracker_, | 105 IPC_MESSAGE_FORWARD(PpapiMsg_ExecuteCallback, &callback_tracker_, |
| 99 CallbackTracker::ReceiveExecuteSerializedCallback) | 106 CallbackTracker::ReceiveExecuteSerializedCallback) |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 if (!proxy.get()) | 157 if (!proxy.get()) |
| 151 return NULL; // Don't know how to proxy this interface. | 158 return NULL; // Don't know how to proxy this interface. |
| 152 | 159 |
| 153 // Save our proxy. | 160 // Save our proxy. |
| 154 proxies_[interface] = proxy; | 161 proxies_[interface] = proxy; |
| 155 id_to_proxy_[proxy->GetInterfaceId()] = proxy.get(); | 162 id_to_proxy_[proxy->GetInterfaceId()] = proxy.get(); |
| 156 return proxy->GetSourceInterface(); | 163 return proxy->GetSourceInterface(); |
| 157 } | 164 } |
| 158 | 165 |
| 159 bool Dispatcher::Send(IPC::Message* msg) { | 166 bool Dispatcher::Send(IPC::Message* msg) { |
| 167 if (test_sink_) |
| 168 return test_sink_->Send(msg); |
| 160 return channel_->Send(msg); | 169 return channel_->Send(msg); |
| 161 } | 170 } |
| 162 | 171 |
| 163 bool Dispatcher::RemoteSupportsTargetInterface(const std::string& interface) { | 172 bool Dispatcher::RemoteSupportsTargetInterface(const std::string& interface) { |
| 164 bool result = false; | 173 bool result = false; |
| 165 Send(new PpapiMsg_SupportsInterface(interface, &result)); | 174 Send(new PpapiMsg_SupportsInterface(interface, &result)); |
| 166 return result; | 175 return result; |
| 167 } | 176 } |
| 168 | 177 |
| 169 bool Dispatcher::IsInterfaceTrusted(const std::string& interface) { | 178 bool Dispatcher::IsInterfaceTrusted(const std::string& interface) { |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 if (interface_name == PPB_URLLOADERTRUSTED_INTERFACE) | 282 if (interface_name == PPB_URLLOADERTRUSTED_INTERFACE) |
| 274 return new PPB_URLLoaderTrusted_Proxy(this, interface_functions); | 283 return new PPB_URLLoaderTrusted_Proxy(this, interface_functions); |
| 275 } | 284 } |
| 276 | 285 |
| 277 return NULL; | 286 return NULL; |
| 278 } | 287 } |
| 279 | 288 |
| 280 } // namespace proxy | 289 } // namespace proxy |
| 281 } // namespace pp | 290 } // namespace pp |
| 282 | 291 |
| OLD | NEW |