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

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

Issue 3119028: Use console.log to report NaCl errors in Chrome instead of alerts (Closed) Base URL: http://nativeclient.googlecode.com/svn/trunk/src/native_client/
Patch Set: '' Created 10 years, 4 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
OLDNEW
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/plugin.h" 7 #include "native_client/src/trusted/plugin/plugin.h"
8 8
9 #include <assert.h> 9 #include <assert.h>
10 #include <fcntl.h> 10 #include <fcntl.h>
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 } 321 }
322 return socket_->handle()->InitParams(method_id, call_type, params); 322 return socket_->handle()->InitParams(method_id, call_type, params);
323 } 323 }
324 324
325 325
326 bool Plugin::SetNexesPropertyImpl(const char* nexes_attr) { 326 bool Plugin::SetNexesPropertyImpl(const char* nexes_attr) {
327 PLUGIN_PRINTF(("Plugin::SetNexesPropertyImpl (nexes_attr='%s')\n", 327 PLUGIN_PRINTF(("Plugin::SetNexesPropertyImpl (nexes_attr='%s')\n",
328 nexes_attr)); 328 nexes_attr));
329 nacl::string result; 329 nacl::string result;
330 if (!GetNexeURL(nexes_attr, &result)) { 330 if (!GetNexeURL(nexes_attr, &result)) {
331 // TODO(adonovan): Ideally we would print to the browser's
332 // JavaScript console: alert popups are annoying, and no-one can
333 // be expected to read stderr.
334 PLUGIN_PRINTF(("Plugin::SetNexesPropertyImpl (result='%s')\n", 331 PLUGIN_PRINTF(("Plugin::SetNexesPropertyImpl (result='%s')\n",
335 result.c_str())); 332 result.c_str()));
336 browser_interface()->Alert(instance_id(), result); 333 browser_interface()->AddToConsole(instance_id(), result);
337 return false; 334 return false;
338 } else { 335 } else {
339 return SetSrcPropertyImpl(result); 336 return SetSrcPropertyImpl(result);
340 } 337 }
341 } 338 }
342 339
343 bool Plugin::SetSrcPropertyImpl(const nacl::string& url) { 340 bool Plugin::SetSrcPropertyImpl(const nacl::string& url) {
344 PLUGIN_PRINTF(("Plugin::SetSrcPropertyImpl (unloading previous)\n")); 341 PLUGIN_PRINTF(("Plugin::SetSrcPropertyImpl (unloading previous)\n"));
345 // We do not actually need to shut down the process here when 342 // We do not actually need to shut down the process here when
346 // initiating the (asynchronous) download. It is more important to 343 // initiating the (asynchronous) download. It is more important to
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 nacl_module_origin_.c_str(), nacl_module_origin_valid)); 531 nacl_module_origin_.c_str(), nacl_module_origin_valid));
535 // If the page origin where the EMBED/OBJECT tag occurs is not in 532 // If the page origin where the EMBED/OBJECT tag occurs is not in
536 // the whitelist, refuse to load. If the NaCl module's origin is 533 // the whitelist, refuse to load. If the NaCl module's origin is
537 // not in the whitelist, also refuse to load. 534 // not in the whitelist, also refuse to load.
538 // TODO(adonovan): JavaScript permits cross-origin loading, and so 535 // TODO(adonovan): JavaScript permits cross-origin loading, and so
539 // does Chrome ; why don't we? 536 // does Chrome ; why don't we?
540 if (!origin_valid_ || !nacl_module_origin_valid) { 537 if (!origin_valid_ || !nacl_module_origin_valid) {
541 nacl::string message = nacl::string("Load failed: NaCl module ") + 538 nacl::string message = nacl::string("Load failed: NaCl module ") +
542 logical_url + " does not come ""from a whitelisted source. " 539 logical_url + " does not come ""from a whitelisted source. "
543 "See native_client/src/trusted/plugin/origin.cc for the list."; 540 "See native_client/src/trusted/plugin/origin.cc for the list.";
544 browser_interface->Alert(instance_id(), message.c_str()); 541 browser_interface->AddToConsole(instance_id(), message.c_str());
545 PLUGIN_PRINTF(("Plugin::Load (return 0)")); 542 PLUGIN_PRINTF(("Plugin::Load (return 0)"));
546 return false; 543 return false;
547 } 544 }
548 // Catch any bad accesses, etc., while loading. 545 // Catch any bad accesses, etc., while loading.
549 ScopedCatchSignals sigcatcher( 546 ScopedCatchSignals sigcatcher(
550 (ScopedCatchSignals::SigHandlerType) SignalHandler); 547 (ScopedCatchSignals::SigHandlerType) SignalHandler);
551 if (PLUGIN_SETJMP(g_LoaderEnv, 1)) { 548 if (PLUGIN_SETJMP(g_LoaderEnv, 1)) {
552 return false; 549 return false;
553 } 550 }
554 551
(...skipping 10 matching lines...) Expand all
565 ssize_t result; 562 ssize_t result;
566 result = shmbufp->read(0, sizeof elf_hdr_buf, elf_hdr_buf); 563 result = shmbufp->read(0, sizeof elf_hdr_buf, elf_hdr_buf);
567 if (sizeof elf_hdr_buf == result) { // (const char*)(elf_hdr_buf) 564 if (sizeof elf_hdr_buf == result) { // (const char*)(elf_hdr_buf)
568 success = browser_interface->MightBeElfExecutable(elf_hdr_buf, 565 success = browser_interface->MightBeElfExecutable(elf_hdr_buf,
569 sizeof elf_hdr_buf, 566 sizeof elf_hdr_buf,
570 &error_string); 567 &error_string);
571 } 568 }
572 } 569 }
573 if (!success) { 570 if (!success) {
574 PLUGIN_PRINTF(("Plugin::Load (error_string='%s')\n", error_string.c_str())); 571 PLUGIN_PRINTF(("Plugin::Load (error_string='%s')\n", error_string.c_str()));
575 browser_interface->Alert(instance_id(), error_string); 572 browser_interface->AddToConsole(instance_id(), error_string);
576 return false; 573 return false;
577 } 574 }
578 575
579 // Ensure that we do not leak the ServiceRuntime object for an 576 // Ensure that we do not leak the ServiceRuntime object for an
580 // existing subprocess. Ensure that any associated listener threads 577 // existing subprocess. Ensure that any associated listener threads
581 // do not go unjoined, because if they outlive the Plugin object, 578 // do not go unjoined, because if they outlive the Plugin object,
582 // they will not be memory safe. 579 // they will not be memory safe.
583 ShutDownSubprocess(); 580 ShutDownSubprocess();
584 581
585 // Load a file via a forked sel_ldr process. 582 // Load a file via a forked sel_ldr process.
586 service_runtime_ = new(std::nothrow) ServiceRuntime(browser_interface, this); 583 service_runtime_ = new(std::nothrow) ServiceRuntime(browser_interface, this);
587 if (NULL == service_runtime_) { 584 if (NULL == service_runtime_) {
588 PLUGIN_PRINTF(("Plugin::Load (ServiceRuntime Ctor failed)\n")); 585 PLUGIN_PRINTF(("Plugin::Load (ServiceRuntime Ctor failed)\n"));
589 browser_interface->Alert(instance_id(), "ServiceRuntime Ctor failed"); 586 browser_interface->AddToConsole(instance_id(),
587 "ServiceRuntime Ctor failed");
590 return false; 588 return false;
591 } 589 }
592 bool service_runtime_started = false; 590 bool service_runtime_started = false;
593 if (NULL == shmbufp) { 591 if (NULL == shmbufp) {
594 service_runtime_started = service_runtime_->Start(local_url_); 592 service_runtime_started = service_runtime_->Start(local_url_);
595 } else { 593 } else {
596 int32_t size; 594 int32_t size;
597 NaClDesc* raw_desc = shmbufp->shm(&size); 595 NaClDesc* raw_desc = shmbufp->shm(&size);
598 if (NULL == raw_desc) { 596 if (NULL == raw_desc) {
599 PLUGIN_PRINTF(("Plugin::Load (extracting shm failed)\n")); 597 PLUGIN_PRINTF(("Plugin::Load (extracting shm failed)\n"));
600 return false; 598 return false;
601 } 599 }
602 nacl::DescWrapper* wrapped_shm = 600 nacl::DescWrapper* wrapped_shm =
603 wrapper_factory_->MakeGeneric(NaClDescRef(raw_desc)); 601 wrapper_factory_->MakeGeneric(NaClDescRef(raw_desc));
604 service_runtime_started = 602 service_runtime_started =
605 service_runtime_->StartUnderChromium(local_url_, wrapped_shm); 603 service_runtime_->StartUnderChromium(local_url_, wrapped_shm);
606 // Start consumes the wrapped_shm. 604 // Start consumes the wrapped_shm.
607 } 605 }
608 if (!service_runtime_started) { 606 if (!service_runtime_started) {
609 PLUGIN_PRINTF(("Plugin::Load (failed to start service runtime)\n")); 607 PLUGIN_PRINTF(("Plugin::Load (failed to start service runtime)\n"));
610 browser_interface->Alert(instance_id(), 608 browser_interface->AddToConsole(instance_id(),
611 "Load: FAILED to start service runtime"); 609 "Load: FAILED to start service runtime");
612 return false; 610 return false;
613 } 611 }
614 612
615 PLUGIN_PRINTF(("Plugin::Load (started sel_ldr)\n")); 613 PLUGIN_PRINTF(("Plugin::Load (started sel_ldr)\n"));
616 // Plugin takes ownership of socket_address_ from service_runtime_, 614 // Plugin takes ownership of socket_address_ from service_runtime_,
617 // so we do not need to call AddRef(). 615 // so we do not need to call AddRef().
618 socket_address_ = service_runtime_->default_socket_address(); 616 socket_address_ = service_runtime_->default_socket_address();
619 PLUGIN_PRINTF(("Plugin::Load (established socket address %p)\n", 617 PLUGIN_PRINTF(("Plugin::Load (established socket address %p)\n",
620 static_cast<void*>(socket_address_))); 618 static_cast<void*>(socket_address_)));
621 if (!StartSrpcServices(&error_string)) { 619 if (!StartSrpcServices(&error_string)) {
622 browser_interface_->Alert(instance_id(), error_string); 620 browser_interface_->Alert(instance_id(), error_string);
polina 2010/08/26 02:45:15 This is still an Alert. Is that on purpose?
623 return false; 621 return false;
624 } 622 }
625 return true; 623 return true;
626 } 624 }
627 625
628 bool Plugin::StartSrpcServices(nacl::string* error) { 626 bool Plugin::StartSrpcServices(nacl::string* error) {
629 if (socket_ != NULL) { 627 if (socket_ != NULL) {
630 socket_->Unref(); 628 socket_->Unref();
631 socket_ = NULL; 629 socket_ = NULL;
632 } 630 }
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
699 697
700 void VideoGlobalLock() { 698 void VideoGlobalLock() {
701 g_VideoMutex.Lock(); 699 g_VideoMutex.Lock();
702 } 700 }
703 701
704 void VideoGlobalUnlock() { 702 void VideoGlobalUnlock() {
705 g_VideoMutex.Unlock(); 703 g_VideoMutex.Unlock();
706 } 704 }
707 705
708 } // namespace plugin 706 } // namespace plugin
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698