| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/nacl_irt/manifest_service.h" | 5 #include "ppapi/nacl_irt/manifest_service.h" |
| 6 | 6 |
| 7 #include "base/message_loop/message_loop_proxy.h" | 7 #include "base/message_loop/message_loop_proxy.h" |
| 8 #include "ipc/ipc_channel_handle.h" | 8 #include "ipc/ipc_channel_handle.h" |
| 9 #include "ipc/ipc_channel_proxy.h" | 9 #include "ipc/ipc_channel_proxy.h" |
| 10 #include "ipc/ipc_sync_message_filter.h" | 10 #include "ipc/ipc_sync_message_filter.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 } | 73 } |
| 74 | 74 |
| 75 ManifestService::~ManifestService() { | 75 ManifestService::~ManifestService() { |
| 76 } | 76 } |
| 77 | 77 |
| 78 void ManifestService::StartupInitializationComplete() { | 78 void ManifestService::StartupInitializationComplete() { |
| 79 filter_->Send(new PpapiHostMsg_StartupInitializationComplete); | 79 filter_->Send(new PpapiHostMsg_StartupInitializationComplete); |
| 80 } | 80 } |
| 81 | 81 |
| 82 bool ManifestService::OpenResource(const char* file, int* fd) { | 82 bool ManifestService::OpenResource(const char* file, int* fd) { |
| 83 // We currently restrict to only allow one concurrent open_resource() call |
| 84 // per plugin. This could be fixed by doing a token lookup with |
| 85 // NaClProcessMsg_ResolveFileTokenAsyncReply instead of using a |
| 86 // global inside components/nacl/loader/nacl_listener.cc |
| 87 base::AutoLock lock(open_resource_lock_); |
| 88 |
| 83 // OpenResource will return INVALID SerializedHandle, if it is not supported. | 89 // OpenResource will return INVALID SerializedHandle, if it is not supported. |
| 84 // Specifically, PNaCl doesn't support open resource. | 90 // Specifically, PNaCl doesn't support open resource. |
| 85 ppapi::proxy::SerializedHandle ipc_fd; | 91 ppapi::proxy::SerializedHandle ipc_fd; |
| 92 |
| 93 // File tokens are ignored here, but needed when the message is processed |
| 94 // inside NaClIPCAdapter. |
| 95 uint64_t file_token_lo; |
| 96 uint64_t file_token_hi; |
| 86 if (!filter_->Send(new PpapiHostMsg_OpenResource( | 97 if (!filter_->Send(new PpapiHostMsg_OpenResource( |
| 87 std::string(kFilePrefix) + file, &ipc_fd)) || | 98 std::string(kFilePrefix) + file, |
| 88 !ipc_fd.is_file()) { | 99 &ipc_fd, |
| 100 &file_token_lo, |
| 101 &file_token_hi))) { |
| 89 LOG(ERROR) << "ManifestService::OpenResource failed:" << file; | 102 LOG(ERROR) << "ManifestService::OpenResource failed:" << file; |
| 90 *fd = -1; | 103 *fd = -1; |
| 91 return false; | 104 return false; |
| 92 } | 105 } |
| 93 | 106 |
| 94 *fd = ipc_fd.descriptor().fd; | 107 // File tokens are used internally by NaClIPCAdapter and should have |
| 108 // been cleared from the message when it is received here. |
| 109 CHECK(file_token_lo == 0); |
| 110 CHECK(file_token_hi == 0); |
| 111 |
| 112 // Copy the file if we received a valid file descriptor. Otherwise, if we got |
| 113 // a reply, the file doesn't exist, so provide an fd of -1. |
| 114 // See IrtOpenResource() for how this function's result is interpreted. |
| 115 if (ipc_fd.is_file()) |
| 116 *fd = ipc_fd.descriptor().fd; |
| 117 else |
| 118 *fd = -1; |
| 95 return true; | 119 return true; |
| 96 } | 120 } |
| 97 | 121 |
| 98 int IrtOpenResource(const char* file, int* fd) { | 122 int IrtOpenResource(const char* file, int* fd) { |
| 99 // Remove leading '/' character. | 123 // Remove leading '/' character. |
| 100 if (file[0] == '/') | 124 if (file[0] == '/') |
| 101 ++file; | 125 ++file; |
| 102 | 126 |
| 103 ManifestService* manifest_service = GetManifestService(); | 127 ManifestService* manifest_service = GetManifestService(); |
| 104 if (manifest_service == NULL || | 128 if (manifest_service == NULL || |
| 105 !manifest_service->OpenResource(file, fd)) { | 129 !manifest_service->OpenResource(file, fd)) { |
| 106 return NACL_ABI_EIO; | 130 return NACL_ABI_EIO; |
| 107 } | 131 } |
| 108 | |
| 109 return (*fd == -1) ? NACL_ABI_ENOENT : 0; | 132 return (*fd == -1) ? NACL_ABI_ENOENT : 0; |
| 110 } | 133 } |
| 111 | 134 |
| 112 } // namespace ppapi | 135 } // namespace ppapi |
| OLD | NEW |