| 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 <numeric> | 7 #include <numeric> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 | 98 |
| 99 base::LazyInstance<InstanceInfoMap> g_instance_info = | 99 base::LazyInstance<InstanceInfoMap> g_instance_info = |
| 100 LAZY_INSTANCE_INITIALIZER; | 100 LAZY_INSTANCE_INITIALIZER; |
| 101 | 101 |
| 102 typedef base::ScopedPtrHashMap<PP_Instance, NexeLoadManager> | 102 typedef base::ScopedPtrHashMap<PP_Instance, NexeLoadManager> |
| 103 NexeLoadManagerMap; | 103 NexeLoadManagerMap; |
| 104 | 104 |
| 105 base::LazyInstance<NexeLoadManagerMap> g_load_manager_map = | 105 base::LazyInstance<NexeLoadManagerMap> g_load_manager_map = |
| 106 LAZY_INSTANCE_INITIALIZER; | 106 LAZY_INSTANCE_INITIALIZER; |
| 107 | 107 |
| 108 typedef base::ScopedPtrHashMap<PP_Instance, nacl::JsonManifest> JsonManifestMap; | |
| 109 | |
| 110 base::LazyInstance<JsonManifestMap> g_manifest_map = | |
| 111 LAZY_INSTANCE_INITIALIZER; | |
| 112 | |
| 113 nacl::NexeLoadManager* GetNexeLoadManager(PP_Instance instance) { | 108 nacl::NexeLoadManager* GetNexeLoadManager(PP_Instance instance) { |
| 114 NexeLoadManagerMap& map = g_load_manager_map.Get(); | 109 NexeLoadManagerMap& map = g_load_manager_map.Get(); |
| 115 NexeLoadManagerMap::iterator iter = map.find(instance); | 110 NexeLoadManagerMap::iterator iter = map.find(instance); |
| 116 if (iter != map.end()) | 111 if (iter != map.end()) |
| 117 return iter->second; | 112 return iter->second; |
| 118 return NULL; | 113 return NULL; |
| 119 } | 114 } |
| 120 | 115 |
| 121 int GetRoutingID(PP_Instance instance) { | 116 int GetRoutingID(PP_Instance instance) { |
| 122 // Check that we are on the main renderer thread. | 117 // Check that we are on the main renderer thread. |
| (...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 757 } | 752 } |
| 758 | 753 |
| 759 void InstanceCreated(PP_Instance instance) { | 754 void InstanceCreated(PP_Instance instance) { |
| 760 scoped_ptr<NexeLoadManager> new_load_manager(new NexeLoadManager(instance)); | 755 scoped_ptr<NexeLoadManager> new_load_manager(new NexeLoadManager(instance)); |
| 761 NexeLoadManagerMap& map = g_load_manager_map.Get(); | 756 NexeLoadManagerMap& map = g_load_manager_map.Get(); |
| 762 DLOG_IF(ERROR, map.count(instance) != 0) << "Instance count should be 0"; | 757 DLOG_IF(ERROR, map.count(instance) != 0) << "Instance count should be 0"; |
| 763 map.add(instance, new_load_manager.Pass()); | 758 map.add(instance, new_load_manager.Pass()); |
| 764 } | 759 } |
| 765 | 760 |
| 766 void InstanceDestroyed(PP_Instance instance) { | 761 void InstanceDestroyed(PP_Instance instance) { |
| 767 g_manifest_map.Get().erase(instance); | 762 DeleteJsonManifest(instance); |
| 768 | 763 |
| 769 NexeLoadManagerMap& map = g_load_manager_map.Get(); | 764 NexeLoadManagerMap& map = g_load_manager_map.Get(); |
| 770 DLOG_IF(ERROR, map.count(instance) == 0) << "Could not find instance ID"; | 765 DLOG_IF(ERROR, map.count(instance) == 0) << "Could not find instance ID"; |
| 771 // The erase may call NexeLoadManager's destructor prior to removing it from | 766 // The erase may call NexeLoadManager's destructor prior to removing it from |
| 772 // the map. In that case, it is possible for the trusted Plugin to re-enter | 767 // the map. In that case, it is possible for the trusted Plugin to re-enter |
| 773 // the NexeLoadManager (e.g., by calling ReportLoadError). Passing out the | 768 // the NexeLoadManager (e.g., by calling ReportLoadError). Passing out the |
| 774 // NexeLoadManager to a local scoped_ptr just ensures that its entry is gone | 769 // NexeLoadManager to a local scoped_ptr just ensures that its entry is gone |
| 775 // from the map prior to the destructor being invoked. | 770 // from the map prior to the destructor being invoked. |
| 776 scoped_ptr<NexeLoadManager> temp(map.take(instance)); | 771 scoped_ptr<NexeLoadManager> temp(map.take(instance)); |
| 777 map.erase(instance); | 772 map.erase(instance); |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1041 isa_type = GetSandboxArch(); | 1036 isa_type = GetSandboxArch(); |
| 1042 | 1037 |
| 1043 scoped_ptr<nacl::JsonManifest> j( | 1038 scoped_ptr<nacl::JsonManifest> j( |
| 1044 new nacl::JsonManifest( | 1039 new nacl::JsonManifest( |
| 1045 manifest_url.c_str(), | 1040 manifest_url.c_str(), |
| 1046 isa_type, | 1041 isa_type, |
| 1047 IsNonSFIModeEnabled(), | 1042 IsNonSFIModeEnabled(), |
| 1048 PP_ToBool(NaClDebugEnabledForURL(manifest_url.c_str())))); | 1043 PP_ToBool(NaClDebugEnabledForURL(manifest_url.c_str())))); |
| 1049 JsonManifest::ErrorInfo error_info; | 1044 JsonManifest::ErrorInfo error_info; |
| 1050 if (j->Init(manifest_data.c_str(), &error_info)) { | 1045 if (j->Init(manifest_data.c_str(), &error_info)) { |
| 1051 g_manifest_map.Get().add(instance, j.Pass()); | 1046 AddJsonManifest(instance, j.Pass()); |
| 1052 return true; | 1047 return true; |
| 1053 } | 1048 } |
| 1054 load_manager->ReportLoadError(error_info.error, error_info.string); | 1049 load_manager->ReportLoadError(error_info.error, error_info.string); |
| 1055 return false; | 1050 return false; |
| 1056 } | 1051 } |
| 1057 | 1052 |
| 1058 PP_Bool ManifestGetProgramURL(PP_Instance instance, | 1053 PP_Bool ManifestGetProgramURL(PP_Instance instance, |
| 1059 PP_Var* pp_full_url, | 1054 PP_Var* pp_full_url, |
| 1060 PP_PNaClOptions* pnacl_options, | 1055 PP_PNaClOptions* pnacl_options, |
| 1061 PP_Bool* pp_uses_nonsfi_mode) { | 1056 PP_Bool* pp_uses_nonsfi_mode) { |
| 1062 nacl::NexeLoadManager* load_manager = GetNexeLoadManager(instance); | 1057 nacl::NexeLoadManager* load_manager = GetNexeLoadManager(instance); |
| 1063 | 1058 |
| 1064 JsonManifestMap::iterator it = g_manifest_map.Get().find(instance); | 1059 JsonManifest* manifest = GetJsonManifest(instance); |
| 1065 if (it == g_manifest_map.Get().end()) | 1060 if (manifest == NULL) |
| 1066 return PP_FALSE; | 1061 return PP_FALSE; |
| 1067 | 1062 |
| 1068 bool uses_nonsfi_mode; | 1063 bool uses_nonsfi_mode; |
| 1069 std::string full_url; | 1064 std::string full_url; |
| 1070 JsonManifest::ErrorInfo error_info; | 1065 JsonManifest::ErrorInfo error_info; |
| 1071 if (it->second->GetProgramURL(&full_url, pnacl_options, &uses_nonsfi_mode, | 1066 if (manifest->GetProgramURL(&full_url, pnacl_options, &uses_nonsfi_mode, |
| 1072 &error_info)) { | 1067 &error_info)) { |
| 1073 *pp_full_url = ppapi::StringVar::StringToPPVar(full_url); | 1068 *pp_full_url = ppapi::StringVar::StringToPPVar(full_url); |
| 1074 *pp_uses_nonsfi_mode = PP_FromBool(uses_nonsfi_mode); | 1069 *pp_uses_nonsfi_mode = PP_FromBool(uses_nonsfi_mode); |
| 1075 return PP_TRUE; | 1070 return PP_TRUE; |
| 1076 } | 1071 } |
| 1077 | 1072 |
| 1078 if (load_manager) | 1073 if (load_manager) |
| 1079 load_manager->ReportLoadError(error_info.error, error_info.string); | 1074 load_manager->ReportLoadError(error_info.error, error_info.string); |
| 1080 return PP_FALSE; | 1075 return PP_FALSE; |
| 1081 } | 1076 } |
| 1082 | 1077 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1109 FROM_HERE, | 1104 FROM_HERE, |
| 1110 base::Bind(callback.func, callback.user_data, | 1105 base::Bind(callback.func, callback.user_data, |
| 1111 static_cast<int32_t>(PP_ERROR_FAILED))); | 1106 static_cast<int32_t>(PP_ERROR_FAILED))); |
| 1112 return; | 1107 return; |
| 1113 } | 1108 } |
| 1114 std::string key_basename = key_string.substr(kFilesPrefix.length()); | 1109 std::string key_basename = key_string.substr(kFilesPrefix.length()); |
| 1115 resolved_url = | 1110 resolved_url = |
| 1116 std::string(kPNaClTranslatorBaseUrl) + GetSandboxArch() + "/" + | 1111 std::string(kPNaClTranslatorBaseUrl) + GetSandboxArch() + "/" + |
| 1117 key_basename; | 1112 key_basename; |
| 1118 } else { | 1113 } else { |
| 1119 JsonManifestMap::iterator it = g_manifest_map.Get().find(instance); | 1114 JsonManifest* manifest = GetJsonManifest(instance); |
| 1120 if (it == g_manifest_map.Get().end()) { | 1115 if (manifest == NULL) { |
| 1121 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( | 1116 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( |
| 1122 FROM_HERE, | 1117 FROM_HERE, |
| 1123 base::Bind(callback.func, callback.user_data, | 1118 base::Bind(callback.func, callback.user_data, |
| 1124 static_cast<int32_t>(PP_ERROR_FAILED))); | 1119 static_cast<int32_t>(PP_ERROR_FAILED))); |
| 1125 return; | 1120 return; |
| 1126 } | 1121 } |
| 1127 | 1122 |
| 1128 PP_PNaClOptions pnacl_options; | 1123 PP_PNaClOptions pnacl_options; |
| 1129 bool ok = it->second->ResolveKey(key, &resolved_url, &pnacl_options); | 1124 bool ok = manifest->ResolveKey(key, &resolved_url, &pnacl_options); |
| 1130 // We don't support OpenManifestEntry for files that require PNaCl | 1125 // We don't support OpenManifestEntry for files that require PNaCl |
| 1131 // translation. | 1126 // translation. |
| 1132 if (!ok || pnacl_options.translate) { | 1127 if (!ok || pnacl_options.translate) { |
| 1133 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( | 1128 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( |
| 1134 FROM_HERE, | 1129 FROM_HERE, |
| 1135 base::Bind(callback.func, callback.user_data, | 1130 base::Bind(callback.func, callback.user_data, |
| 1136 static_cast<int32_t>(PP_ERROR_FAILED))); | 1131 static_cast<int32_t>(PP_ERROR_FAILED))); |
| 1137 return; | 1132 return; |
| 1138 } | 1133 } |
| 1139 } | 1134 } |
| (...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1592 &DownloadNexe, | 1587 &DownloadNexe, |
| 1593 }; | 1588 }; |
| 1594 | 1589 |
| 1595 } // namespace | 1590 } // namespace |
| 1596 | 1591 |
| 1597 const PPB_NaCl_Private* GetNaClPrivateInterface() { | 1592 const PPB_NaCl_Private* GetNaClPrivateInterface() { |
| 1598 return &nacl_interface; | 1593 return &nacl_interface; |
| 1599 } | 1594 } |
| 1600 | 1595 |
| 1601 } // namespace nacl | 1596 } // namespace nacl |
| OLD | NEW |