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 #ifdef _MSC_VER | 5 #ifdef _MSC_VER |
6 // Do not warn about use of std::copy with raw pointers. | 6 // Do not warn about use of std::copy with raw pointers. |
7 #pragma warning(disable : 4996) | 7 #pragma warning(disable : 4996) |
8 #endif | 8 #endif |
9 | 9 |
10 #include "ppapi/native_client/src/trusted/plugin/plugin.h" | 10 #include "ppapi/native_client/src/trusted/plugin/plugin.h" |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 #ifdef NACL_OSX | 111 #ifdef NACL_OSX |
112 // TODO(kochi): For crbug.com/102808, this is a stopgap solution for Lion | 112 // TODO(kochi): For crbug.com/102808, this is a stopgap solution for Lion |
113 // until we expose IME API to .nexe. This disables any IME interference | 113 // until we expose IME API to .nexe. This disables any IME interference |
114 // against key inputs, so you cannot use off-the-spot IME input for NaCl apps. | 114 // against key inputs, so you cannot use off-the-spot IME input for NaCl apps. |
115 // This makes discrepancy among platforms and therefore we should remove | 115 // This makes discrepancy among platforms and therefore we should remove |
116 // this hack when IME API is made available. | 116 // this hack when IME API is made available. |
117 // The default for non-Mac platforms is still off-the-spot IME mode. | 117 // The default for non-Mac platforms is still off-the-spot IME mode. |
118 pp::TextInputController(this).SetTextInputType(PP_TEXTINPUT_TYPE_NONE); | 118 pp::TextInputController(this).SetTextInputType(PP_TEXTINPUT_TYPE_NONE); |
119 #endif | 119 #endif |
120 | 120 |
121 // Remember the embed/object argn/argv pairs. | |
122 argn_ = new char*[argc]; | |
123 argv_ = new char*[argc]; | |
124 argc_ = 0; | |
125 for (int i = 0; i < argc; ++i) { | 121 for (int i = 0; i < argc; ++i) { |
126 if (NULL != argn_ && NULL != argv_) { | 122 std::string name(argn[i]); |
127 argn_[argc_] = strdup(argn[i]); | 123 std::string value(argv[i]); |
128 argv_[argc_] = strdup(argv[i]); | 124 args_[name] = value; |
129 if (NULL == argn_[argc_] || NULL == argv_[argc_]) { | |
130 // Give up on passing arguments. | |
131 free(argn_[argc_]); | |
132 free(argv_[argc_]); | |
133 continue; | |
134 } | |
135 ++argc_; | |
136 } | |
137 } | 125 } |
138 // TODO(sehr): this leaks strings if there is a subsequent failure. | |
139 | 126 |
140 // Set up the factory used to produce DescWrappers. | 127 // Set up the factory used to produce DescWrappers. |
141 wrapper_factory_ = new nacl::DescWrapperFactory(); | 128 wrapper_factory_ = new nacl::DescWrapperFactory(); |
142 if (NULL == wrapper_factory_) { | 129 if (NULL == wrapper_factory_) { |
143 return false; | 130 return false; |
144 } | 131 } |
145 PLUGIN_PRINTF(("Plugin::Init (wrapper_factory=%p)\n", | 132 PLUGIN_PRINTF(("Plugin::Init (wrapper_factory=%p)\n", |
146 static_cast<void*>(wrapper_factory_))); | 133 static_cast<void*>(wrapper_factory_))); |
147 | 134 |
148 PLUGIN_PRINTF(("Plugin::Init (return 1)\n")); | 135 PLUGIN_PRINTF(("Plugin::Init (return 1)\n")); |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 nacl_subprocess->description()); | 477 nacl_subprocess->description()); |
491 return NULL; | 478 return NULL; |
492 } | 479 } |
493 | 480 |
494 PLUGIN_PRINTF(("Plugin::LoadHelperNaClModule (%s)\n", | 481 PLUGIN_PRINTF(("Plugin::LoadHelperNaClModule (%s)\n", |
495 nacl_subprocess.get()->detailed_description().c_str())); | 482 nacl_subprocess.get()->detailed_description().c_str())); |
496 | 483 |
497 return nacl_subprocess.release(); | 484 return nacl_subprocess.release(); |
498 } | 485 } |
499 | 486 |
500 char* Plugin::LookupArgument(const char* key) { | 487 std::string Plugin::LookupArgument(const std::string& key) const { |
501 char** keys = argn_; | 488 std::map<std::string, std::string>::const_iterator it = args_.find(key); |
502 for (int ii = 0, len = argc_; ii < len; ++ii) { | 489 if (it != args_.end()) |
503 if (!strcmp(keys[ii], key)) { | 490 return it->second; |
504 return argv_[ii]; | 491 return std::string(); |
505 } | |
506 } | |
507 return NULL; | |
508 } | 492 } |
509 | 493 |
510 const char* const Plugin::kNaClMIMEType = "application/x-nacl"; | 494 const char* const Plugin::kNaClMIMEType = "application/x-nacl"; |
511 const char* const Plugin::kPnaclMIMEType = "application/x-pnacl"; | 495 const char* const Plugin::kPnaclMIMEType = "application/x-pnacl"; |
512 | 496 |
513 bool Plugin::NexeIsContentHandler() const { | 497 bool Plugin::NexeIsContentHandler() const { |
514 // Tests if the MIME type is not a NaCl MIME type. | 498 // Tests if the MIME type is not a NaCl MIME type. |
515 // If the MIME type is foreign, then this NEXE is being used as a content | 499 // If the MIME type is foreign, then this NEXE is being used as a content |
516 // type handler rather than directly by an HTML document. | 500 // type handler rather than directly by an HTML document. |
517 return | 501 return |
(...skipping 22 matching lines...) Expand all Loading... |
540 if (url_util_ == NULL) | 524 if (url_util_ == NULL) |
541 return false; | 525 return false; |
542 | 526 |
543 PLUGIN_PRINTF(("Plugin::Init (url_util_=%p)\n", | 527 PLUGIN_PRINTF(("Plugin::Init (url_util_=%p)\n", |
544 static_cast<const void*>(url_util_))); | 528 static_cast<const void*>(url_util_))); |
545 | 529 |
546 bool status = EarlyInit(static_cast<int>(argc), argn, argv); | 530 bool status = EarlyInit(static_cast<int>(argc), argn, argv); |
547 if (status) { | 531 if (status) { |
548 // Look for the developer attribute; if it's present, enable 'dev' | 532 // Look for the developer attribute; if it's present, enable 'dev' |
549 // interfaces. | 533 // interfaces. |
550 const char* dev_settings = LookupArgument(kDevAttribute); | 534 enable_dev_interfaces_ = args_.find(kDevAttribute) != args_.end(); |
551 enable_dev_interfaces_ = (dev_settings != NULL); | |
552 | 535 |
553 const char* type_attr = LookupArgument(kTypeAttribute); | 536 mime_type_ = LookupArgument(kTypeAttribute); |
554 if (type_attr != NULL) { | 537 std::transform(mime_type_.begin(), mime_type_.end(), mime_type_.begin(), |
555 mime_type_ = nacl::string(type_attr); | 538 tolower); |
556 std::transform(mime_type_.begin(), mime_type_.end(), mime_type_.begin(), | |
557 tolower); | |
558 } | |
559 | 539 |
560 const char* manifest_url = LookupArgument(kSrcManifestAttribute); | 540 std::string manifest_url; |
561 if (NexeIsContentHandler()) { | 541 if (NexeIsContentHandler()) { |
562 // For content handlers 'src' will be the URL for the content | 542 // For content handlers 'src' will be the URL for the content |
563 // and 'nacl' will be the URL for the manifest. | 543 // and 'nacl' will be the URL for the manifest. |
564 manifest_url = LookupArgument(kNaClManifestAttribute); | 544 manifest_url = LookupArgument(kNaClManifestAttribute); |
565 // For content handlers the NEXE runs in the security context of the | 545 // For content handlers the NEXE runs in the security context of the |
566 // content it is rendering and the NEXE itself appears to be a | 546 // content it is rendering and the NEXE itself appears to be a |
567 // cross-origin resource stored in a Chrome extension. | 547 // cross-origin resource stored in a Chrome extension. |
| 548 } else { |
| 549 manifest_url = LookupArgument(kSrcManifestAttribute); |
568 } | 550 } |
569 // Use the document URL as the base for resolving relative URLs to find the | 551 // Use the document URL as the base for resolving relative URLs to find the |
570 // manifest. This takes into account the setting of <base> tags that | 552 // manifest. This takes into account the setting of <base> tags that |
571 // precede the embed/object. | 553 // precede the embed/object. |
572 CHECK(url_util_ != NULL); | 554 CHECK(url_util_ != NULL); |
573 pp::Var base_var = url_util_->GetDocumentURL(this); | 555 pp::Var base_var = url_util_->GetDocumentURL(this); |
574 if (!base_var.is_string()) { | 556 if (!base_var.is_string()) { |
575 PLUGIN_PRINTF(("Plugin::Init (unable to find document url)\n")); | 557 PLUGIN_PRINTF(("Plugin::Init (unable to find document url)\n")); |
576 return false; | 558 return false; |
577 } | 559 } |
578 set_plugin_base_url(base_var.AsString()); | 560 set_plugin_base_url(base_var.AsString()); |
579 if (manifest_url == NULL) { | 561 if (manifest_url.empty()) { |
580 // TODO(sehr,polina): this should be a hard error when scripting | 562 // TODO(sehr,polina): this should be a hard error when scripting |
581 // the src property is no longer allowed. | 563 // the src property is no longer allowed. |
582 PLUGIN_PRINTF(("Plugin::Init:" | 564 PLUGIN_PRINTF(("Plugin::Init:" |
583 " WARNING: no 'src' property, so no manifest loaded.\n")); | 565 " WARNING: no 'src' property, so no manifest loaded.\n")); |
584 if (NULL != LookupArgument(kNaClManifestAttribute)) { | 566 if (args_.find(kNaClManifestAttribute) != args_.end()) { |
585 PLUGIN_PRINTF(("Plugin::Init:" | 567 PLUGIN_PRINTF(("Plugin::Init:" |
586 " WARNING: 'nacl' property is incorrect. Use 'src'.\n")); | 568 " WARNING: 'nacl' property is incorrect. Use 'src'.\n")); |
587 } | 569 } |
588 } else { | 570 } else { |
589 // Issue a GET for the manifest_url. The manifest file will be parsed to | 571 // Issue a GET for the manifest_url. The manifest file will be parsed to |
590 // determine the nexe URL. | 572 // determine the nexe URL. |
591 // Sets src property to full manifest URL. | 573 // Sets src property to full manifest URL. |
592 RequestNaClManifest(manifest_url); | 574 RequestNaClManifest(manifest_url.c_str()); |
593 } | 575 } |
594 } | 576 } |
595 | 577 |
596 PLUGIN_PRINTF(("Plugin::Init (status=%d)\n", status)); | 578 PLUGIN_PRINTF(("Plugin::Init (status=%d)\n", status)); |
597 return status; | 579 return status; |
598 } | 580 } |
599 | 581 |
600 Plugin::Plugin(PP_Instance pp_instance) | 582 Plugin::Plugin(PP_Instance pp_instance) |
601 : pp::Instance(pp_instance), | 583 : pp::Instance(pp_instance), |
602 argc_(-1), | |
603 argn_(NULL), | |
604 argv_(NULL), | |
605 main_subprocess_("main subprocess", NULL, NULL), | 584 main_subprocess_("main subprocess", NULL, NULL), |
606 nexe_error_reported_(false), | 585 nexe_error_reported_(false), |
607 wrapper_factory_(NULL), | 586 wrapper_factory_(NULL), |
608 enable_dev_interfaces_(false), | 587 enable_dev_interfaces_(false), |
609 is_installed_(false), | 588 is_installed_(false), |
610 init_time_(0), | 589 init_time_(0), |
611 ready_time_(0), | 590 ready_time_(0), |
612 nexe_size_(0), | 591 nexe_size_(0), |
613 time_of_last_progress_event_(0), | 592 time_of_last_progress_event_(0), |
614 exit_status_(-1), | 593 exit_status_(-1), |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
670 // threads. | 649 // threads. |
671 // | 650 // |
672 // The main_subprocess object, which wraps the main service_runtime | 651 // The main_subprocess object, which wraps the main service_runtime |
673 // object, is dtor'd implicitly after the explicit code below runs, | 652 // object, is dtor'd implicitly after the explicit code below runs, |
674 // so the main service runtime object will not have been dtor'd, | 653 // so the main service runtime object will not have been dtor'd, |
675 // though the Shutdown method may have been called, during the | 654 // though the Shutdown method may have been called, during the |
676 // lifetime of the service threads. | 655 // lifetime of the service threads. |
677 ShutDownSubprocesses(); | 656 ShutDownSubprocesses(); |
678 | 657 |
679 delete wrapper_factory_; | 658 delete wrapper_factory_; |
680 delete[] argv_; | |
681 delete[] argn_; | |
682 | 659 |
683 HistogramTimeSmall( | 660 HistogramTimeSmall( |
684 "NaCl.Perf.ShutdownTime.Total", | 661 "NaCl.Perf.ShutdownTime.Total", |
685 (NaClGetTimeOfDayMicroseconds() - shutdown_start) | 662 (NaClGetTimeOfDayMicroseconds() - shutdown_start) |
686 / NACL_MICROS_PER_MILLI); | 663 / NACL_MICROS_PER_MILLI); |
687 | 664 |
688 PLUGIN_PRINTF(("Plugin::~Plugin (this=%p, return)\n", | 665 PLUGIN_PRINTF(("Plugin::~Plugin (this=%p, return)\n", |
689 static_cast<void*>(this))); | 666 static_cast<void*>(this))); |
690 } | 667 } |
691 | 668 |
(...skipping 811 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1503 DCHECK(pp::Module::Get()->core()->IsMainThread()); | 1480 DCHECK(pp::Module::Get()->core()->IsMainThread()); |
1504 DCHECK(nacl_interface_); | 1481 DCHECK(nacl_interface_); |
1505 exit_status_ = exit_status; | 1482 exit_status_ = exit_status; |
1506 nacl_interface_->SetReadOnlyProperty(pp_instance(), | 1483 nacl_interface_->SetReadOnlyProperty(pp_instance(), |
1507 pp::Var("exitStatus").pp_var(), | 1484 pp::Var("exitStatus").pp_var(), |
1508 pp::Var(exit_status_).pp_var()); | 1485 pp::Var(exit_status_).pp_var()); |
1509 } | 1486 } |
1510 | 1487 |
1511 | 1488 |
1512 } // namespace plugin | 1489 } // namespace plugin |
OLD | NEW |