Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(467)

Side by Side Diff: ppapi/native_client/src/trusted/plugin/plugin.cc

Issue 161403002: Pepper: Clean up trusted plugin arguments. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/native_client/src/trusted/plugin/plugin.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 #ifdef NACL_OSX 112 #ifdef NACL_OSX
113 // TODO(kochi): For crbug.com/102808, this is a stopgap solution for Lion 113 // TODO(kochi): For crbug.com/102808, this is a stopgap solution for Lion
114 // until we expose IME API to .nexe. This disables any IME interference 114 // until we expose IME API to .nexe. This disables any IME interference
115 // against key inputs, so you cannot use off-the-spot IME input for NaCl apps. 115 // against key inputs, so you cannot use off-the-spot IME input for NaCl apps.
116 // This makes discrepancy among platforms and therefore we should remove 116 // This makes discrepancy among platforms and therefore we should remove
117 // this hack when IME API is made available. 117 // this hack when IME API is made available.
118 // The default for non-Mac platforms is still off-the-spot IME mode. 118 // The default for non-Mac platforms is still off-the-spot IME mode.
119 pp::TextInputController(this).SetTextInputType(PP_TEXTINPUT_TYPE_NONE); 119 pp::TextInputController(this).SetTextInputType(PP_TEXTINPUT_TYPE_NONE);
120 #endif 120 #endif
121 121
122 // Remember the embed/object argn/argv pairs.
123 argn_ = new char*[argc];
124 argv_ = new char*[argc];
125 argc_ = 0;
126 for (int i = 0; i < argc; ++i) { 122 for (int i = 0; i < argc; ++i) {
127 if (NULL != argn_ && NULL != argv_) { 123 std::string name(argn[i]);
128 argn_[argc_] = strdup(argn[i]); 124 std::string value(argv[i]);
dmichael (off chromium) 2014/02/12 22:06:46 nit: arguably, you could not have these temp varia
129 argv_[argc_] = strdup(argv[i]); 125 args_[name] = value;
130 if (NULL == argn_[argc_] || NULL == argv_[argc_]) {
131 // Give up on passing arguments.
132 free(argn_[argc_]);
133 free(argv_[argc_]);
134 continue;
135 }
136 ++argc_;
137 }
138 } 126 }
139 // TODO(sehr): this leaks strings if there is a subsequent failure.
140 127
141 // Set up the factory used to produce DescWrappers. 128 // Set up the factory used to produce DescWrappers.
142 wrapper_factory_ = new nacl::DescWrapperFactory(); 129 wrapper_factory_ = new nacl::DescWrapperFactory();
143 if (NULL == wrapper_factory_) { 130 if (NULL == wrapper_factory_) {
144 return false; 131 return false;
145 } 132 }
146 PLUGIN_PRINTF(("Plugin::Init (wrapper_factory=%p)\n", 133 PLUGIN_PRINTF(("Plugin::Init (wrapper_factory=%p)\n",
147 static_cast<void*>(wrapper_factory_))); 134 static_cast<void*>(wrapper_factory_)));
148 135
149 PLUGIN_PRINTF(("Plugin::Init (return 1)\n")); 136 PLUGIN_PRINTF(("Plugin::Init (return 1)\n"));
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 nacl_subprocess->description()); 478 nacl_subprocess->description());
492 return NULL; 479 return NULL;
493 } 480 }
494 481
495 PLUGIN_PRINTF(("Plugin::LoadHelperNaClModule (%s)\n", 482 PLUGIN_PRINTF(("Plugin::LoadHelperNaClModule (%s)\n",
496 nacl_subprocess.get()->detailed_description().c_str())); 483 nacl_subprocess.get()->detailed_description().c_str()));
497 484
498 return nacl_subprocess.release(); 485 return nacl_subprocess.release();
499 } 486 }
500 487
501 char* Plugin::LookupArgument(const char* key) { 488 std::string Plugin::LookupArgument(const std::string& key) const {
502 char** keys = argn_; 489 std::map<std::string, std::string>::const_iterator it = args_.find(key);
503 for (int ii = 0, len = argc_; ii < len; ++ii) { 490 if (it != args_.end())
504 if (!strcmp(keys[ii], key)) { 491 return it->second;
505 return argv_[ii];
506 }
507 }
508 return NULL; 492 return NULL;
dmichael (off chromium) 2014/02/12 22:06:46 I think it would be clearer to return std::string(
509 } 493 }
510 494
511 const char* const Plugin::kNaClMIMEType = "application/x-nacl"; 495 const char* const Plugin::kNaClMIMEType = "application/x-nacl";
512 const char* const Plugin::kPnaclMIMEType = "application/x-pnacl"; 496 const char* const Plugin::kPnaclMIMEType = "application/x-pnacl";
513 497
514 bool Plugin::NexeIsContentHandler() const { 498 bool Plugin::NexeIsContentHandler() const {
515 // Tests if the MIME type is not a NaCl MIME type. 499 // Tests if the MIME type is not a NaCl MIME type.
516 // If the MIME type is foreign, then this NEXE is being used as a content 500 // If the MIME type is foreign, then this NEXE is being used as a content
517 // type handler rather than directly by an HTML document. 501 // type handler rather than directly by an HTML document.
518 return 502 return
(...skipping 30 matching lines...) Expand all
549 if (url_util_ == NULL) 533 if (url_util_ == NULL)
550 return false; 534 return false;
551 535
552 PLUGIN_PRINTF(("Plugin::Init (url_util_=%p)\n", 536 PLUGIN_PRINTF(("Plugin::Init (url_util_=%p)\n",
553 static_cast<const void*>(url_util_))); 537 static_cast<const void*>(url_util_)));
554 538
555 bool status = EarlyInit(static_cast<int>(argc), argn, argv); 539 bool status = EarlyInit(static_cast<int>(argc), argn, argv);
556 if (status) { 540 if (status) {
557 // Look for the developer attribute; if it's present, enable 'dev' 541 // Look for the developer attribute; if it's present, enable 'dev'
558 // interfaces. 542 // interfaces.
559 const char* dev_settings = LookupArgument(kDevAttribute); 543 enable_dev_interfaces_ = args_.find(kDevAttribute) != args_.end();
560 enable_dev_interfaces_ = (dev_settings != NULL);
561 544
562 const char* type_attr = LookupArgument(kTypeAttribute); 545 mime_type_ = LookupArgument(kTypeAttribute);
563 if (type_attr != NULL) { 546 std::transform(mime_type_.begin(), mime_type_.end(), mime_type_.begin(),
564 mime_type_ = nacl::string(type_attr); 547 tolower);
565 std::transform(mime_type_.begin(), mime_type_.end(), mime_type_.begin(),
566 tolower);
567 }
568 548
569 const char* manifest_url = LookupArgument(kSrcManifestAttribute); 549 std::string manifest_url;
570 if (NexeIsContentHandler()) { 550 if (NexeIsContentHandler()) {
571 // For content handlers 'src' will be the URL for the content 551 // For content handlers 'src' will be the URL for the content
572 // and 'nacl' will be the URL for the manifest. 552 // and 'nacl' will be the URL for the manifest.
573 manifest_url = LookupArgument(kNaClManifestAttribute); 553 manifest_url = LookupArgument(kNaClManifestAttribute);
574 // For content handlers the NEXE runs in the security context of the 554 // For content handlers the NEXE runs in the security context of the
575 // content it is rendering and the NEXE itself appears to be a 555 // content it is rendering and the NEXE itself appears to be a
576 // cross-origin resource stored in a Chrome extension. 556 // cross-origin resource stored in a Chrome extension.
557 } else {
558 manifest_url = LookupArgument(kSrcManifestAttribute);
577 } 559 }
578 // Use the document URL as the base for resolving relative URLs to find the 560 // Use the document URL as the base for resolving relative URLs to find the
579 // manifest. This takes into account the setting of <base> tags that 561 // manifest. This takes into account the setting of <base> tags that
580 // precede the embed/object. 562 // precede the embed/object.
581 CHECK(url_util_ != NULL); 563 CHECK(url_util_ != NULL);
582 pp::Var base_var = url_util_->GetDocumentURL(this); 564 pp::Var base_var = url_util_->GetDocumentURL(this);
583 if (!base_var.is_string()) { 565 if (!base_var.is_string()) {
584 PLUGIN_PRINTF(("Plugin::Init (unable to find document url)\n")); 566 PLUGIN_PRINTF(("Plugin::Init (unable to find document url)\n"));
585 return false; 567 return false;
586 } 568 }
587 set_plugin_base_url(base_var.AsString()); 569 set_plugin_base_url(base_var.AsString());
588 if (manifest_url == NULL) { 570 if (manifest_url.empty()) {
589 // TODO(sehr,polina): this should be a hard error when scripting 571 // TODO(sehr,polina): this should be a hard error when scripting
590 // the src property is no longer allowed. 572 // the src property is no longer allowed.
591 PLUGIN_PRINTF(("Plugin::Init:" 573 PLUGIN_PRINTF(("Plugin::Init:"
592 " WARNING: no 'src' property, so no manifest loaded.\n")); 574 " WARNING: no 'src' property, so no manifest loaded.\n"));
593 if (NULL != LookupArgument(kNaClManifestAttribute)) { 575 if (args_.find(kNaClManifestAttribute) != args_.end()) {
594 PLUGIN_PRINTF(("Plugin::Init:" 576 PLUGIN_PRINTF(("Plugin::Init:"
595 " WARNING: 'nacl' property is incorrect. Use 'src'.\n")); 577 " WARNING: 'nacl' property is incorrect. Use 'src'.\n"));
596 } 578 }
597 } else { 579 } else {
598 // Issue a GET for the manifest_url. The manifest file will be parsed to 580 // Issue a GET for the manifest_url. The manifest file will be parsed to
599 // determine the nexe URL. 581 // determine the nexe URL.
600 // Sets src property to full manifest URL. 582 // Sets src property to full manifest URL.
601 RequestNaClManifest(manifest_url); 583 RequestNaClManifest(manifest_url.c_str());
602 } 584 }
603 } 585 }
604 586
605 PLUGIN_PRINTF(("Plugin::Init (status=%d)\n", status)); 587 PLUGIN_PRINTF(("Plugin::Init (status=%d)\n", status));
606 return status; 588 return status;
607 } 589 }
608 590
609 Plugin::Plugin(PP_Instance pp_instance) 591 Plugin::Plugin(PP_Instance pp_instance)
610 : pp::InstancePrivate(pp_instance), 592 : pp::InstancePrivate(pp_instance),
611 scriptable_plugin_(NULL), 593 scriptable_plugin_(NULL),
612 argc_(-1),
613 argn_(NULL),
614 argv_(NULL),
615 main_subprocess_("main subprocess", NULL, NULL), 594 main_subprocess_("main subprocess", NULL, NULL),
616 nexe_error_reported_(false), 595 nexe_error_reported_(false),
617 wrapper_factory_(NULL), 596 wrapper_factory_(NULL),
618 enable_dev_interfaces_(false), 597 enable_dev_interfaces_(false),
619 is_installed_(false), 598 is_installed_(false),
620 init_time_(0), 599 init_time_(0),
621 ready_time_(0), 600 ready_time_(0),
622 nexe_size_(0), 601 nexe_size_(0),
623 time_of_last_progress_event_(0), 602 time_of_last_progress_event_(0),
624 exit_status_(-1), 603 exit_status_(-1),
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 // threads. 663 // threads.
685 // 664 //
686 // The main_subprocess object, which wraps the main service_runtime 665 // The main_subprocess object, which wraps the main service_runtime
687 // object, is dtor'd implicitly after the explicit code below runs, 666 // object, is dtor'd implicitly after the explicit code below runs,
688 // so the main service runtime object will not have been dtor'd, 667 // so the main service runtime object will not have been dtor'd,
689 // though the Shutdown method may have been called, during the 668 // though the Shutdown method may have been called, during the
690 // lifetime of the service threads. 669 // lifetime of the service threads.
691 ShutDownSubprocesses(); 670 ShutDownSubprocesses();
692 671
693 delete wrapper_factory_; 672 delete wrapper_factory_;
694 delete[] argv_;
695 delete[] argn_;
696 673
697 HistogramTimeSmall( 674 HistogramTimeSmall(
698 "NaCl.Perf.ShutdownTime.Total", 675 "NaCl.Perf.ShutdownTime.Total",
699 (NaClGetTimeOfDayMicroseconds() - shutdown_start) 676 (NaClGetTimeOfDayMicroseconds() - shutdown_start)
700 / NACL_MICROS_PER_MILLI); 677 / NACL_MICROS_PER_MILLI);
701 678
702 PLUGIN_PRINTF(("Plugin::~Plugin (this=%p, return)\n", 679 PLUGIN_PRINTF(("Plugin::~Plugin (this=%p, return)\n",
703 static_cast<void*>(this))); 680 static_cast<void*>(this)));
704 } 681 }
705 682
(...skipping 823 matching lines...) Expand 10 before | Expand all | Expand 10 after
1529 DCHECK(pp::Module::Get()->core()->IsMainThread()); 1506 DCHECK(pp::Module::Get()->core()->IsMainThread());
1530 DCHECK(nacl_interface_); 1507 DCHECK(nacl_interface_);
1531 exit_status_ = exit_status; 1508 exit_status_ = exit_status;
1532 nacl_interface_->SetReadOnlyProperty(pp_instance(), 1509 nacl_interface_->SetReadOnlyProperty(pp_instance(),
1533 pp::Var("exitStatus").pp_var(), 1510 pp::Var("exitStatus").pp_var(),
1534 pp::Var(exit_status_).pp_var()); 1511 pp::Var(exit_status_).pp_var());
1535 } 1512 }
1536 1513
1537 1514
1538 } // namespace plugin 1515 } // namespace plugin
OLDNEW
« no previous file with comments | « ppapi/native_client/src/trusted/plugin/plugin.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698