Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2008 The Native Client Authors. All rights reserved. | 2 * Copyright 2008 The Native Client Authors. All rights reserved. |
| 3 * Use of this source code is governed by a BSD-style license that can | 3 * Use of this source code is governed by a BSD-style license that can |
| 4 * be found in the LICENSE file. | 4 * be found in the LICENSE file. |
| 5 */ | 5 */ |
| 6 | 6 |
| 7 #include "native_client/src/trusted/plugin/srpc/plugin.h" | 7 #include "native_client/src/trusted/plugin/srpc/plugin.h" |
| 8 | 8 |
| 9 #include <assert.h> | 9 #include <assert.h> |
| 10 #include <fcntl.h> | 10 #include <fcntl.h> |
| 11 #include <stdarg.h> | 11 #include <stdarg.h> |
| 12 #include <stdio.h> | 12 #include <stdio.h> |
| 13 #include <stdlib.h> | 13 #include <stdlib.h> |
| 14 #include <string.h> | 14 #include <string.h> |
| 15 | 15 |
| 16 #include <sys/types.h> | 16 #include <sys/types.h> |
| 17 #include <sys/stat.h> | 17 #include <sys/stat.h> |
| 18 | 18 |
| 19 #include <list> | |
| 19 #include <string> | 20 #include <string> |
| 20 | 21 |
| 21 #include "native_client/src/include/portability_string.h" | 22 #include "native_client/src/include/portability_string.h" |
| 22 | 23 |
| 23 #include "native_client/src/trusted/desc/nacl_desc_conn_cap.h" | 24 #include "native_client/src/trusted/desc/nacl_desc_conn_cap.h" |
| 24 #include "native_client/src/trusted/nonnacl_util/sel_ldr_launcher.h" | 25 #include "native_client/src/trusted/nonnacl_util/sel_ldr_launcher.h" |
| 25 | 26 |
| 26 #include "native_client/src/trusted/plugin/srpc/browser_interface.h" | 27 #include "native_client/src/trusted/plugin/srpc/browser_interface.h" |
| 27 #include "native_client/src/trusted/plugin/srpc/srpc.h" | 28 #include "native_client/src/trusted/plugin/srpc/srpc.h" |
| 28 #include "native_client/src/trusted/plugin/srpc/scriptable_handle.h" | 29 #include "native_client/src/trusted/plugin/srpc/scriptable_handle.h" |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 51 "__defaultSocketAddress", METHOD_CALL, "", "h"); | 52 "__defaultSocketAddress", METHOD_CALL, "", "h"); |
| 52 AddMethodToMap(NullPluginMethod, "__nullPluginMethod", METHOD_CALL, "s", "i"); | 53 AddMethodToMap(NullPluginMethod, "__nullPluginMethod", METHOD_CALL, "s", "i"); |
| 53 AddMethodToMap(GetHeightProperty, "height", PROPERTY_GET, "", "i"); | 54 AddMethodToMap(GetHeightProperty, "height", PROPERTY_GET, "", "i"); |
| 54 AddMethodToMap(SetHeightProperty, "height", PROPERTY_SET, "i", ""); | 55 AddMethodToMap(SetHeightProperty, "height", PROPERTY_SET, "i", ""); |
| 55 AddMethodToMap(GetWidthProperty, "width", PROPERTY_GET, "", "i"); | 56 AddMethodToMap(GetWidthProperty, "width", PROPERTY_GET, "", "i"); |
| 56 AddMethodToMap(SetWidthProperty, "width", PROPERTY_SET, "i", ""); | 57 AddMethodToMap(SetWidthProperty, "width", PROPERTY_SET, "i", ""); |
| 57 AddMethodToMap(GetModuleReadyProperty, | 58 AddMethodToMap(GetModuleReadyProperty, |
| 58 "__moduleReady", PROPERTY_GET, "", "i"); | 59 "__moduleReady", PROPERTY_GET, "", "i"); |
| 59 AddMethodToMap(SetModuleReadyProperty, | 60 AddMethodToMap(SetModuleReadyProperty, |
| 60 "__moduleReady", PROPERTY_SET, "i", ""); | 61 "__moduleReady", PROPERTY_SET, "i", ""); |
| 61 AddMethodToMap(GetSrcProperty, | 62 AddMethodToMap(GetNexeProperty, |
| 62 "src", PROPERTY_GET, "", "s"); | 63 "nexe", PROPERTY_GET, "", "s"); |
| 63 AddMethodToMap(SetSrcProperty, | 64 AddMethodToMap(SetNexeProperty, |
| 64 "src", PROPERTY_SET, "s", ""); | 65 "nexe", PROPERTY_SET, "s", ""); |
| 65 AddMethodToMap(GetVideoUpdateModeProperty, | 66 AddMethodToMap(GetVideoUpdateModeProperty, |
| 66 "videoUpdateMode", PROPERTY_GET, "", "i"); | 67 "videoUpdateMode", PROPERTY_GET, "", "i"); |
| 67 AddMethodToMap(SetVideoUpdateModeProperty, | 68 AddMethodToMap(SetVideoUpdateModeProperty, |
| 68 "videoUpdateMode", PROPERTY_SET, "i", ""); | 69 "videoUpdateMode", PROPERTY_SET, "i", ""); |
| 69 } | 70 } |
| 70 | 71 |
| 71 bool Plugin::HasMethodEx(uintptr_t method_id, CallType call_type) { | 72 bool Plugin::HasMethodEx(uintptr_t method_id, CallType call_type) { |
| 72 // The requested method is not implemented by the Plugin, | 73 // The requested method is not implemented by the Plugin, |
| 73 // maybe it is implemented by the NaCl module | 74 // maybe it is implemented by the NaCl module |
| 74 if (socket_) { | 75 if (socket_) { |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 227 } | 228 } |
| 228 return true; | 229 return true; |
| 229 } | 230 } |
| 230 | 231 |
| 231 bool Plugin::SetModuleReadyProperty(void *obj, SrpcParams *params) { | 232 bool Plugin::SetModuleReadyProperty(void *obj, SrpcParams *params) { |
| 232 UNREFERENCED_PARAMETER(obj); | 233 UNREFERENCED_PARAMETER(obj); |
| 233 params->SetExceptionInfo("__moduleReady is a read-only property"); | 234 params->SetExceptionInfo("__moduleReady is a read-only property"); |
| 234 return false; | 235 return false; |
| 235 } | 236 } |
| 236 | 237 |
| 237 bool Plugin::GetSrcProperty(void *obj, SrpcParams *params) { | 238 bool Plugin::GetNexeProperty(void *obj, SrpcParams *params) { |
| 238 Plugin *plugin = reinterpret_cast<Plugin*>(obj); | 239 Plugin *plugin = reinterpret_cast<Plugin*>(obj); |
| 239 params->outs[0]->u.sval = | 240 params->outs[0]->u.sval = |
| 240 PortablePluginInterface::MemAllocStrdup(plugin->local_url_); | 241 PortablePluginInterface::MemAllocStrdup(plugin->local_url_); |
| 241 return true; | 242 return true; |
| 242 } | 243 } |
| 243 | 244 |
| 244 bool Plugin::SetSrcProperty(void *obj, SrpcParams *params) { | 245 // TODO(adonovan): Expose this as a user configuration option. |
| 246 static const enum { BEFORE_ARCH, AFTER_ARCH, NEVER } kTryPNaCl = BEFORE_ARCH; | |
|
bsy
2010/03/23 21:20:37
might want ALWAYS/ONLY, for those people who prefe
| |
| 247 // TODO(adonovan): Compatibility hack. Allows x86 bigots to avoid | |
| 248 // renaming their executables. Not for release. | |
| 249 static const bool kTryWithoutArchitecture = true; | |
| 250 | |
| 251 // Given a base nexe URL (architecture unspecified), computes the list | |
| 252 // of URLs to try, e.g.: | |
| 253 // | |
| 254 // <base>-armv7.nexe | |
| 255 // <base>.pnacl | |
| 256 // <base>.nexe | |
| 257 // | |
| 258 // The order and elements of the returned list depend on the options | |
| 259 // above. | |
| 260 static void GetNexeURLs(const std::string& base_url, | |
| 261 std::list<std::string> *urls) { | |
| 262 // Issue a helpful warning, since we're making an incompatible change. | |
| 263 unsigned int idx = base_url.find(".nexe"); | |
| 264 if (idx != std::string::npos && idx + 5 == base_url.size()) { | |
| 265 dprintf(("embed.nexe = %s; \".nexe\" suffix should be omitted", | |
| 266 base_url.c_str())); | |
| 267 } | |
| 268 | |
| 269 if (kTryPNaCl == BEFORE_ARCH) urls->push_back(base_url + ".pnacl"); | |
| 270 | |
| 271 // TODO(adonovan): is there a better macro for us to use? | |
| 272 urls->push_back(base_url + | |
| 273 #if NACL_TARGET_ARCH == x86 && NACL_TARGET_SUBARCH == 64 | |
| 274 "-x86-64.nexe" | |
|
bsy
2010/03/23 21:20:37
not sure i like '-' as separator, esp since tools
| |
| 275 #elif NACL_TARGET_ARCH == x86 && NACL_TARGET_SUBARCH == 32 | |
| 276 "-x86-32.nexe" | |
| 277 #elif NACL_TARGET_ARCH == arm | |
| 278 "-arm.nexe" | |
| 279 // FIXME(adonovan): Shouldn't we be more specific than just "ARM", | |
| 280 // We should probably be as specific as uname -m, e.g. "armv7l"? | |
| 281 #else | |
| 282 #error "Unknown NACL_TARGET_ARCH/SUBARCH." | |
| 283 #endif | |
| 284 ); | |
| 285 if (kTryPNaCl == AFTER_ARCH) urls->push_back(base_url + ".pnacl"); | |
| 286 if (kTryWithoutArchitecture) urls->push_back(base_url); | |
| 287 } | |
| 288 | |
| 289 bool Plugin::SetNexeProperty(void *obj, SrpcParams *params) { | |
| 245 Plugin *plugin = reinterpret_cast<Plugin*>(obj); | 290 Plugin *plugin = reinterpret_cast<Plugin*>(obj); |
| 246 if (NULL != plugin->service_runtime_interface_) { | 291 if (NULL != plugin->service_runtime_interface_) { |
| 247 dprintf(("Plugin::SetProperty: unloading previous\n")); | 292 dprintf(("Plugin::SetProperty: unloading previous\n")); |
| 248 // Plugin owns socket_address_ and socket_, so when we change to a new | 293 // Plugin owns socket_address_ and socket_, so when we change to a new |
| 249 // socket we need to give up ownership of the old one. | 294 // socket we need to give up ownership of the old one. |
| 250 plugin->socket_address_->Unref(); | 295 plugin->socket_address_->Unref(); |
| 251 plugin->socket_address_ = NULL; | 296 plugin->socket_address_ = NULL; |
| 252 plugin->socket_->Unref(); | 297 plugin->socket_->Unref(); |
| 253 plugin->socket_ = NULL; | 298 plugin->socket_ = NULL; |
| 254 plugin->service_runtime_interface_ = NULL; | 299 plugin->service_runtime_interface_ = NULL; |
| 255 } | 300 } |
| 256 // Load the new module if the origin of the page is valid. | 301 // Load the new module if the origin of the page is valid. |
| 257 const char* url = params->ins[0]->u.sval; | 302 const char* url = params->ins[0]->u.sval; |
| 258 dprintf(("Plugin::SetProperty src = '%s'\n", url)); | 303 dprintf(("Plugin::SetProperty nexe = '%s'\n", url)); |
| 259 LoadNaClAppNotify* callback = new(std::nothrow) LoadNaClAppNotify(plugin, | 304 std::list<std::string> urls; |
| 260 url); | 305 GetNexeURLs(url, &urls); |
| 306 LoadNaClAppNotify* callback = | |
| 307 new(std::nothrow) LoadNaClAppNotify(plugin, urls); | |
| 261 if ((NULL == callback) || (!callback->StartDownload())) { | 308 if ((NULL == callback) || (!callback->StartDownload())) { |
| 262 dprintf(("Failed to load URL to local file.\n")); | 309 dprintf(("Failed to load URL to local file.\n")); |
| 263 // callback is always deleted in URLNotify | 310 // callback is always deleted in URLNotify |
| 311 // FIXME(adonovan): it is? even when StartDownload failed? | |
| 312 // FIXME(adonovan): shouldn't this result in the onfail handler | |
| 313 // getting called? | |
|
bsy
2010/03/23 21:20:37
i think StartDownload always fails a download by c
adonovan
2010/03/25 00:44:05
You're right, the notification always occurs, even
| |
| 264 return false; | 314 return false; |
| 265 } | 315 } |
| 266 return true; | 316 return true; |
| 267 } | 317 } |
| 268 | 318 |
| 269 bool Plugin::GetVideoUpdateModeProperty(void *obj, SrpcParams *params) { | 319 bool Plugin::GetVideoUpdateModeProperty(void *obj, SrpcParams *params) { |
| 270 Plugin *plugin = reinterpret_cast<Plugin*>(obj); | 320 Plugin *plugin = reinterpret_cast<Plugin*>(obj); |
| 271 params->outs[0]->u.ival = plugin->video_update_mode_; | 321 params->outs[0]->u.ival = plugin->video_update_mode_; |
| 272 return true; | 322 return true; |
| 273 } | 323 } |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 481 | 531 |
| 482 Plugin* Plugin::GetPlugin() { | 532 Plugin* Plugin::GetPlugin() { |
| 483 return this; | 533 return this; |
| 484 } | 534 } |
| 485 | 535 |
| 486 | 536 |
| 487 PLUGIN_JMPBUF Plugin::loader_env; | 537 PLUGIN_JMPBUF Plugin::loader_env; |
| 488 | 538 |
| 489 | 539 |
| 490 } // namespace nacl_srpc | 540 } // namespace nacl_srpc |
| OLD | NEW |