OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/nacl/renderer/ppb_nacl_private_impl.h" | 5 #include "components/nacl/renderer/ppb_nacl_private_impl.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/containers/scoped_ptr_hash_map.h" | 8 #include "base/containers/scoped_ptr_hash_map.h" |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 #include "ppapi/c/private/pp_file_handle.h" | 28 #include "ppapi/c/private/pp_file_handle.h" |
29 #include "ppapi/native_client/src/trusted/plugin/nacl_entry_points.h" | 29 #include "ppapi/native_client/src/trusted/plugin/nacl_entry_points.h" |
30 #include "ppapi/shared_impl/ppapi_globals.h" | 30 #include "ppapi/shared_impl/ppapi_globals.h" |
31 #include "ppapi/shared_impl/ppapi_permissions.h" | 31 #include "ppapi/shared_impl/ppapi_permissions.h" |
32 #include "ppapi/shared_impl/ppapi_preferences.h" | 32 #include "ppapi/shared_impl/ppapi_preferences.h" |
33 #include "ppapi/shared_impl/var.h" | 33 #include "ppapi/shared_impl/var.h" |
34 #include "ppapi/thunk/enter.h" | 34 #include "ppapi/thunk/enter.h" |
35 | 35 |
36 namespace { | 36 namespace { |
37 | 37 |
38 // Forward declare LogToConsole() we can use it in other functions here. | |
39 void LogToConsole(PP_Instance instance, const char* message); | |
40 | |
41 base::LazyInstance<scoped_refptr<PnaclTranslationResourceHost> > | 38 base::LazyInstance<scoped_refptr<PnaclTranslationResourceHost> > |
42 g_pnacl_resource_host = LAZY_INSTANCE_INITIALIZER; | 39 g_pnacl_resource_host = LAZY_INSTANCE_INITIALIZER; |
43 | 40 |
44 static bool InitializePnaclResourceHost() { | 41 static bool InitializePnaclResourceHost() { |
45 // Must run on the main thread. | 42 // Must run on the main thread. |
46 content::RenderThread* render_thread = content::RenderThread::Get(); | 43 content::RenderThread* render_thread = content::RenderThread::Get(); |
47 if (!render_thread) | 44 if (!render_thread) |
48 return false; | 45 return false; |
49 if (!g_pnacl_resource_host.Get()) { | 46 if (!g_pnacl_resource_host.Get()) { |
50 g_pnacl_resource_host.Get() = new PnaclTranslationResourceHost( | 47 g_pnacl_resource_host.Get() = new PnaclTranslationResourceHost( |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 if (load_manager) | 439 if (load_manager) |
443 load_manager->SetReadOnlyProperty(key, value); | 440 load_manager->SetReadOnlyProperty(key, value); |
444 } | 441 } |
445 | 442 |
446 void ReportLoadError(PP_Instance instance, | 443 void ReportLoadError(PP_Instance instance, |
447 PP_NaClError error, | 444 PP_NaClError error, |
448 const char* error_message, | 445 const char* error_message, |
449 const char* console_message) { | 446 const char* console_message) { |
450 nacl::NexeLoadManager* load_manager = GetNexeLoadManager(instance); | 447 nacl::NexeLoadManager* load_manager = GetNexeLoadManager(instance); |
451 if (load_manager) | 448 if (load_manager) |
452 load_manager->ReportLoadError(error, error_message); | 449 load_manager->ReportLoadError(error, error_message, console_message); |
453 LogToConsole(instance, console_message); | |
454 } | 450 } |
455 | 451 |
456 void InstanceCreated(PP_Instance instance) { | 452 void InstanceCreated(PP_Instance instance) { |
457 scoped_ptr<nacl::NexeLoadManager> new_load_manager( | 453 scoped_ptr<nacl::NexeLoadManager> new_load_manager( |
458 new nacl::NexeLoadManager(instance)); | 454 new nacl::NexeLoadManager(instance)); |
459 NexeLoadManagerMap& map = g_load_manager_map.Get(); | 455 NexeLoadManagerMap& map = g_load_manager_map.Get(); |
460 DLOG_IF(ERROR, map.count(instance) != 0) << "Instance count should be 0"; | 456 DLOG_IF(ERROR, map.count(instance) != 0) << "Instance count should be 0"; |
461 map.add(instance, new_load_manager.Pass()); | 457 map.add(instance, new_load_manager.Pass()); |
462 } | 458 } |
463 | 459 |
(...skipping 19 matching lines...) Expand all Loading... |
483 | 479 |
484 GURL gurl(url_string->value()); | 480 GURL gurl(url_string->value()); |
485 if (gurl.SchemeIs("chrome-extension")) | 481 if (gurl.SchemeIs("chrome-extension")) |
486 return PP_SCHEME_CHROME_EXTENSION; | 482 return PP_SCHEME_CHROME_EXTENSION; |
487 if (gurl.SchemeIs("data")) | 483 if (gurl.SchemeIs("data")) |
488 return PP_SCHEME_DATA; | 484 return PP_SCHEME_DATA; |
489 return PP_SCHEME_OTHER; | 485 return PP_SCHEME_OTHER; |
490 } | 486 } |
491 | 487 |
492 void LogToConsole(PP_Instance instance, const char* message) { | 488 void LogToConsole(PP_Instance instance, const char* message) { |
493 std::string source("NativeClient"); | 489 nacl::NexeLoadManager* load_manager = GetNexeLoadManager(instance); |
494 ppapi::PpapiGlobals::Get()->LogWithSource(instance, | 490 DCHECK(load_manager); |
495 PP_LOGLEVEL_LOG, | 491 if (load_manager) |
496 source, | 492 load_manager->LogToConsole(std::string(message)); |
497 std::string(message)); | |
498 } | 493 } |
499 | 494 |
500 PP_Bool GetNexeErrorReported(PP_Instance instance) { | 495 PP_Bool GetNexeErrorReported(PP_Instance instance) { |
501 nacl::NexeLoadManager* load_manager = GetNexeLoadManager(instance); | 496 nacl::NexeLoadManager* load_manager = GetNexeLoadManager(instance); |
502 DCHECK(load_manager); | 497 DCHECK(load_manager); |
503 if (load_manager) | 498 if (load_manager) |
504 return PP_FromBool(load_manager->nexe_error_reported()); | 499 return PP_FromBool(load_manager->nexe_error_reported()); |
505 return PP_FALSE; | 500 return PP_FALSE; |
506 } | 501 } |
507 | 502 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 | 569 |
575 } // namespace | 570 } // namespace |
576 | 571 |
577 namespace nacl { | 572 namespace nacl { |
578 | 573 |
579 const PPB_NaCl_Private* GetNaClPrivateInterface() { | 574 const PPB_NaCl_Private* GetNaClPrivateInterface() { |
580 return &nacl_interface; | 575 return &nacl_interface; |
581 } | 576 } |
582 | 577 |
583 } // namespace nacl | 578 } // namespace nacl |
OLD | NEW |