Index: components/nacl/renderer/manifest_service_channel.cc |
diff --git a/components/nacl/renderer/manifest_service_channel.cc b/components/nacl/renderer/manifest_service_channel.cc |
index f0f4adb8f940a261a4116c1f6fe9b1f292e0e4e2..a524070ffecd0ad0d046379d83350f3391feea55 100644 |
--- a/components/nacl/renderer/manifest_service_channel.cc |
+++ b/components/nacl/renderer/manifest_service_channel.cc |
@@ -4,6 +4,7 @@ |
#include "components/nacl/renderer/manifest_service_channel.h" |
+#include "base/bind.h" |
#include "base/callback.h" |
#include "base/callback_helpers.h" |
#include "content/public/renderer/render_thread.h" |
@@ -15,16 +16,19 @@ |
namespace nacl { |
ManifestServiceChannel::ManifestServiceChannel( |
+ bool pnacl_mode, |
const IPC::ChannelHandle& handle, |
const base::Callback<void(int32_t)>& connected_callback, |
scoped_ptr<Delegate> delegate, |
base::WaitableEvent* waitable_event) |
- : connected_callback_(connected_callback), |
+ : pnacl_mode_(pnacl_mode), |
+ connected_callback_(connected_callback), |
delegate_(delegate.Pass()), |
channel_(new IPC::SyncChannel( |
handle, IPC::Channel::MODE_CLIENT, this, |
content::RenderThread::Get()->GetIOMessageLoopProxy(), |
- true, waitable_event)) { |
+ true, waitable_event)), |
+ weak_ptr_factory_(this) { |
} |
ManifestServiceChannel::~ManifestServiceChannel() { |
@@ -32,12 +36,17 @@ ManifestServiceChannel::~ManifestServiceChannel() { |
base::ResetAndReturn(&connected_callback_).Run(PP_ERROR_FAILED); |
} |
+void ManifestServiceChannel::Send(IPC::Message* message) { |
+ channel_->Send(message); |
+} |
+ |
bool ManifestServiceChannel::OnMessageReceived(const IPC::Message& message) { |
- // TODO(hidehiko): Implement OpenResource. |
bool handled = true; |
IPC_BEGIN_MESSAGE_MAP(ManifestServiceChannel, message) |
IPC_MESSAGE_HANDLER(PpapiHostMsg_StartupInitializationComplete, |
OnStartupInitializationComplete) |
+ IPC_MESSAGE_HANDLER_DELAY_REPLY(PpapiHostMsg_OpenResource, |
+ OnOpenResource) |
IPC_MESSAGE_UNHANDLED(handled = false) |
IPC_END_MESSAGE_MAP() |
return handled; |
@@ -57,4 +66,42 @@ void ManifestServiceChannel::OnStartupInitializationComplete() { |
delegate_->StartupInitializationComplete(); |
} |
+void ManifestServiceChannel::OnOpenResource( |
+ const std::string& key, IPC::Message* reply) { |
+ if (pnacl_mode_) { |
+ // OpenResource() is disabled on PNaCl. |
+ PpapiHostMsg_OpenResource::WriteReplyParams( |
+ reply, ppapi::proxy::SerializedHandle()); |
+ Send(reply); |
+ return; |
+ } |
+ |
+#if defined(OS_WIN) |
+ // Currently this is used only for non-SFI mode, which is not supported on |
+ // windows. |
+ NOTREACHED(); |
+ // Returns an error for Release build. |
+ PpapiHostMsg_OpenResource::WriteReplyParams( |
Mark Seaborn
2014/05/01 06:32:35
Could you reduce the duplication by doing:
#if !d
hidehiko
2014/05/01 13:05:40
Done.
|
+ reply, ppapi::proxy::SerializedHandle()); |
+ Send(reply); |
+#else |
+ delegate_->OpenResource(key, |
+ base::Bind(&ManifestServiceChannel::DidOpenResource, |
+ weak_ptr_factory_.GetWeakPtr(), reply)); |
+#endif |
+} |
+ |
+#if !defined(OS_WIN) |
+void ManifestServiceChannel::DidOpenResource( |
+ IPC::Message* reply, const base::PlatformFile& platform_file) { |
+ // Here, PlatformFileForTransit is alias of base::FileDescriptor. |
+ PpapiHostMsg_OpenResource::WriteReplyParams( |
+ reply, |
+ ppapi::proxy::SerializedHandle( |
+ ppapi::proxy::SerializedHandle::FILE, |
+ base::FileDescriptor(platform_file, true))); |
+ Send(reply); |
+} |
+#endif |
+ |
} // namespace nacl |