Index: components/nacl/renderer/ppb_nacl_private_impl.cc |
diff --git a/components/nacl/renderer/ppb_nacl_private_impl.cc b/components/nacl/renderer/ppb_nacl_private_impl.cc |
index 85ff3227ed91ade21a0a43591d5d99c1e8ed79a1..028a391589b45d8e5711f4d2ad0eac61ce4ab59c 100644 |
--- a/components/nacl/renderer/ppb_nacl_private_impl.cc |
+++ b/components/nacl/renderer/ppb_nacl_private_impl.cc |
@@ -15,6 +15,7 @@ |
#include "components/nacl/common/nacl_messages.h" |
#include "components/nacl/common/nacl_switches.h" |
#include "components/nacl/common/nacl_types.h" |
+#include "components/nacl/renderer/json_manifest.h" |
#include "components/nacl/renderer/manifest_service_channel.h" |
#include "components/nacl/renderer/nexe_load_manager.h" |
#include "components/nacl/renderer/pnacl_translation_resource_host.h" |
@@ -81,7 +82,15 @@ typedef base::ScopedPtrHashMap<PP_Instance, NexeLoadManager> |
base::LazyInstance<NexeLoadManagerMap> g_load_manager_map = |
LAZY_INSTANCE_INITIALIZER; |
-NexeLoadManager* GetNexeLoadManager(PP_Instance instance) { |
+typedef base::ScopedPtrHashMap<int32_t, nacl::JsonManifest> JsonManifestMap; |
+ |
+base::LazyInstance<JsonManifestMap> g_manifest_map = |
+ LAZY_INSTANCE_INITIALIZER; |
+ |
+const int kPNaClManifestId = 0; |
bbudge
2014/05/01 23:32:33
Could you make this the largest int32?
teravest
2014/05/02 14:23:15
Done.
|
+int g_next_manifest_id = 1; // Hmm. |
bbudge
2014/05/01 23:32:33
Then this could start at 0.
teravest
2014/05/02 14:23:15
Done. That's better, thanks.
|
+ |
+nacl::NexeLoadManager* GetNexeLoadManager(PP_Instance instance) { |
NexeLoadManagerMap& map = g_load_manager_map.Get(); |
NexeLoadManagerMap::iterator iter = map.find(instance); |
if (iter != map.end()) |
@@ -851,6 +860,111 @@ PP_Bool DevInterfacesEnabled(PP_Instance instance) { |
return PP_FALSE; |
} |
+int32_t CreatePNaClManifest(PP_Instance /* instance */) { |
+ return kPNaClManifestId; |
+} |
+ |
+int32_t CreateJsonManifest(PP_Instance instance, |
+ const char* manifest_url, |
+ const char* isa_type, |
+ const char* manifest_data) { |
+ int32_t manifest_id = g_next_manifest_id; |
+ g_next_manifest_id++; |
+ |
+ scoped_ptr<nacl::JsonManifest> j( |
+ new nacl::JsonManifest( |
+ manifest_url, |
+ isa_type, |
+ PP_ToBool(IsNonSFIModeEnabled()), |
+ PP_ToBool(NaClDebugEnabledForURL(manifest_url)))); |
+ JsonManifest::ErrorInfo error_info; |
+ if (j->Init(manifest_data, &error_info)) { |
+ g_manifest_map.Get().add(manifest_id, j.Pass()); |
+ return manifest_id; |
+ } |
+ nacl::NexeLoadManager* load_manager = GetNexeLoadManager(instance); |
+ if (load_manager) |
+ load_manager->ReportLoadError(error_info.error, error_info.string); |
+ return -1; |
+} |
+ |
+void DestroyManifest(PP_Instance /* instance */, |
+ int32_t manifest_id) { |
+ if (manifest_id == kPNaClManifestId) |
+ return; |
+ g_manifest_map.Get().erase(manifest_id); |
+} |
+ |
+PP_Bool ManifestGetProgramURL(PP_Instance instance, |
+ int32_t manifest_id, |
+ PP_Var* pp_full_url, |
+ PP_PNaClOptions* pnacl_options, |
+ PP_Bool* pp_uses_nonsfi_mode) { |
+ nacl::NexeLoadManager* load_manager = GetNexeLoadManager(instance); |
+ if (manifest_id == kPNaClManifestId) { |
+ if (load_manager) { |
+ load_manager->ReportLoadError( |
+ PP_NACL_ERROR_MANIFEST_GET_NEXE_URL, |
+ "pnacl manifest does not contain a program."); |
+ } |
+ return PP_FALSE; |
+ } |
+ |
+ JsonManifestMap::iterator it = g_manifest_map.Get().find(manifest_id); |
+ if (it == g_manifest_map.Get().end()) |
+ return PP_FALSE; |
+ |
+ bool uses_nonsfi_mode; |
+ std::string full_url; |
+ JsonManifest::ErrorInfo error_info; |
+ if (it->second->GetProgramURL(&full_url, pnacl_options, &uses_nonsfi_mode, |
+ &error_info)) { |
+ *pp_full_url = ppapi::StringVar::StringToPPVar(full_url); |
+ *pp_uses_nonsfi_mode = PP_FromBool(uses_nonsfi_mode); |
+ return PP_TRUE; |
+ } |
+ |
+ if (load_manager) |
+ load_manager->ReportLoadError(error_info.error, error_info.string); |
+ return PP_FALSE; |
+} |
+ |
+PP_Bool ManifestResolveKey(PP_Instance instance, |
+ int32_t manifest_id, |
+ const char* key, |
+ PP_Var* pp_full_url, |
+ PP_PNaClOptions* pnacl_options) { |
+ if (manifest_id == kPNaClManifestId) { |
+ pnacl_options->translate = PP_FALSE; |
+ // We can only resolve keys in the files/ namespace. |
+ const std::string kFilesPrefix = "files/"; |
+ std::string key_string(key); |
+ if (key_string.find(kFilesPrefix) == std::string::npos) { |
+ nacl::NexeLoadManager* load_manager = GetNexeLoadManager(instance); |
+ if (load_manager) |
+ load_manager->ReportLoadError(PP_NACL_ERROR_MANIFEST_RESOLVE_URL, |
+ "key did not start with files/"); |
+ return PP_FALSE; |
+ } |
+ std::string key_basename = key_string.substr(kFilesPrefix.length()); |
+ std::string pnacl_url = |
+ std::string("chrome://pnacl-translator/") + GetSandboxArch() + "/" + |
+ key_basename; |
+ *pp_full_url = ppapi::StringVar::StringToPPVar(pnacl_url); |
+ return PP_TRUE; |
+ } |
+ |
+ JsonManifestMap::iterator it = g_manifest_map.Get().find(manifest_id); |
+ if (it == g_manifest_map.Get().end()) |
+ return PP_FALSE; |
+ |
+ std::string full_url; |
+ bool ok = it->second->ResolveKey(key, &full_url, pnacl_options); |
+ if (ok) |
+ *pp_full_url = ppapi::StringVar::StringToPPVar(full_url); |
+ return PP_FromBool(ok); |
+} |
+ |
const PPB_NaCl_Private nacl_interface = { |
&LaunchSelLdr, |
&StartPpapiProxy, |
@@ -889,7 +1003,12 @@ const PPB_NaCl_Private nacl_interface = { |
&ProcessNaClManifest, |
&GetManifestURLArgument, |
&IsPNaCl, |
- &DevInterfacesEnabled |
+ &DevInterfacesEnabled, |
+ &CreatePNaClManifest, |
+ &CreateJsonManifest, |
+ &DestroyManifest, |
+ &ManifestGetProgramURL, |
+ &ManifestResolveKey |
}; |
} // namespace |