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

Side by Side Diff: components/nacl/renderer/ppb_nacl_private_impl.cc

Issue 264943003: Pepper: Move manifest logic to components/nacl. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix typo Created 6 years, 7 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 | « components/nacl/renderer/json_manifest.cc ('k') | ppapi/api/private/ppb_nacl_private.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/containers/scoped_ptr_hash_map.h" 10 #include "base/containers/scoped_ptr_hash_map.h"
11 #include "base/lazy_instance.h" 11 #include "base/lazy_instance.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/rand_util.h" 13 #include "base/rand_util.h"
14 #include "components/nacl/common/nacl_host_messages.h" 14 #include "components/nacl/common/nacl_host_messages.h"
15 #include "components/nacl/common/nacl_messages.h" 15 #include "components/nacl/common/nacl_messages.h"
16 #include "components/nacl/common/nacl_switches.h" 16 #include "components/nacl/common/nacl_switches.h"
17 #include "components/nacl/common/nacl_types.h" 17 #include "components/nacl/common/nacl_types.h"
18 #include "components/nacl/renderer/histogram.h" 18 #include "components/nacl/renderer/histogram.h"
19 #include "components/nacl/renderer/json_manifest.h"
19 #include "components/nacl/renderer/manifest_downloader.h" 20 #include "components/nacl/renderer/manifest_downloader.h"
20 #include "components/nacl/renderer/manifest_service_channel.h" 21 #include "components/nacl/renderer/manifest_service_channel.h"
21 #include "components/nacl/renderer/nexe_load_manager.h" 22 #include "components/nacl/renderer/nexe_load_manager.h"
22 #include "components/nacl/renderer/pnacl_translation_resource_host.h" 23 #include "components/nacl/renderer/pnacl_translation_resource_host.h"
23 #include "components/nacl/renderer/sandbox_arch.h" 24 #include "components/nacl/renderer/sandbox_arch.h"
24 #include "components/nacl/renderer/trusted_plugin_channel.h" 25 #include "components/nacl/renderer/trusted_plugin_channel.h"
25 #include "content/public/common/content_client.h" 26 #include "content/public/common/content_client.h"
26 #include "content/public/common/content_switches.h" 27 #include "content/public/common/content_switches.h"
27 #include "content/public/common/sandbox_init.h" 28 #include "content/public/common/sandbox_init.h"
28 #include "content/public/renderer/pepper_plugin_instance.h" 29 #include "content/public/renderer/pepper_plugin_instance.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 81
81 base::LazyInstance<InstanceInfoMap> g_instance_info = 82 base::LazyInstance<InstanceInfoMap> g_instance_info =
82 LAZY_INSTANCE_INITIALIZER; 83 LAZY_INSTANCE_INITIALIZER;
83 84
84 typedef base::ScopedPtrHashMap<PP_Instance, NexeLoadManager> 85 typedef base::ScopedPtrHashMap<PP_Instance, NexeLoadManager>
85 NexeLoadManagerMap; 86 NexeLoadManagerMap;
86 87
87 base::LazyInstance<NexeLoadManagerMap> g_load_manager_map = 88 base::LazyInstance<NexeLoadManagerMap> g_load_manager_map =
88 LAZY_INSTANCE_INITIALIZER; 89 LAZY_INSTANCE_INITIALIZER;
89 90
90 NexeLoadManager* GetNexeLoadManager(PP_Instance instance) { 91 typedef base::ScopedPtrHashMap<int32_t, nacl::JsonManifest> JsonManifestMap;
92
93 base::LazyInstance<JsonManifestMap> g_manifest_map =
94 LAZY_INSTANCE_INITIALIZER;
95
96 base::LazyInstance<int32_t> g_next_manifest_id =
97 LAZY_INSTANCE_INITIALIZER;
98
99 // We have to define a method here since we can't use a static initializer.
100 int32_t GetPNaClManifestId() {
101 return std::numeric_limits<int32_t>::max();
102 }
103
104 nacl::NexeLoadManager* GetNexeLoadManager(PP_Instance instance) {
91 NexeLoadManagerMap& map = g_load_manager_map.Get(); 105 NexeLoadManagerMap& map = g_load_manager_map.Get();
92 NexeLoadManagerMap::iterator iter = map.find(instance); 106 NexeLoadManagerMap::iterator iter = map.find(instance);
93 if (iter != map.end()) 107 if (iter != map.end())
94 return iter->second; 108 return iter->second;
95 return NULL; 109 return NULL;
96 } 110 }
97 111
98 int GetRoutingID(PP_Instance instance) { 112 int GetRoutingID(PP_Instance instance) {
99 // Check that we are on the main renderer thread. 113 // Check that we are on the main renderer thread.
100 DCHECK(content::RenderThread::Get()); 114 DCHECK(content::RenderThread::Get());
(...skipping 883 matching lines...) Expand 10 before | Expand all | Expand 10 after
984 "could not load manifest url."); 998 "could not load manifest url.");
985 } 999 }
986 1000
987 if (pp_error == PP_OK) { 1001 if (pp_error == PP_OK) {
988 std::string contents; 1002 std::string contents;
989 *out_data = ppapi::StringVar::StringToPPVar(data); 1003 *out_data = ppapi::StringVar::StringToPPVar(data);
990 } 1004 }
991 callback.func(callback.user_data, pp_error); 1005 callback.func(callback.user_data, pp_error);
992 } 1006 }
993 1007
1008 int32_t CreatePNaClManifest(PP_Instance /* instance */) {
1009 return GetPNaClManifestId();
1010 }
1011
1012 int32_t CreateJsonManifest(PP_Instance instance,
1013 const char* manifest_url,
1014 const char* isa_type,
1015 const char* manifest_data) {
1016 int32_t manifest_id = g_next_manifest_id.Get();
1017 g_next_manifest_id.Get()++;
1018
1019 scoped_ptr<nacl::JsonManifest> j(
1020 new nacl::JsonManifest(
1021 manifest_url,
1022 isa_type,
1023 PP_ToBool(IsNonSFIModeEnabled()),
1024 PP_ToBool(NaClDebugEnabledForURL(manifest_url))));
1025 JsonManifest::ErrorInfo error_info;
1026 if (j->Init(manifest_data, &error_info)) {
1027 g_manifest_map.Get().add(manifest_id, j.Pass());
1028 return manifest_id;
1029 }
1030 nacl::NexeLoadManager* load_manager = GetNexeLoadManager(instance);
1031 if (load_manager)
1032 load_manager->ReportLoadError(error_info.error, error_info.string);
1033 return -1;
1034 }
1035
1036 void DestroyManifest(PP_Instance /* instance */,
1037 int32_t manifest_id) {
1038 if (manifest_id == GetPNaClManifestId())
1039 return;
1040 g_manifest_map.Get().erase(manifest_id);
1041 }
1042
1043 PP_Bool ManifestGetProgramURL(PP_Instance instance,
1044 int32_t manifest_id,
1045 PP_Var* pp_full_url,
1046 PP_PNaClOptions* pnacl_options,
1047 PP_Bool* pp_uses_nonsfi_mode) {
1048 nacl::NexeLoadManager* load_manager = GetNexeLoadManager(instance);
1049 if (manifest_id == GetPNaClManifestId()) {
1050 if (load_manager) {
1051 load_manager->ReportLoadError(
1052 PP_NACL_ERROR_MANIFEST_GET_NEXE_URL,
1053 "pnacl manifest does not contain a program.");
1054 }
1055 return PP_FALSE;
1056 }
1057
1058 JsonManifestMap::iterator it = g_manifest_map.Get().find(manifest_id);
1059 if (it == g_manifest_map.Get().end())
1060 return PP_FALSE;
1061
1062 bool uses_nonsfi_mode;
1063 std::string full_url;
1064 JsonManifest::ErrorInfo error_info;
1065 if (it->second->GetProgramURL(&full_url, pnacl_options, &uses_nonsfi_mode,
1066 &error_info)) {
1067 *pp_full_url = ppapi::StringVar::StringToPPVar(full_url);
1068 *pp_uses_nonsfi_mode = PP_FromBool(uses_nonsfi_mode);
1069 return PP_TRUE;
1070 }
1071
1072 if (load_manager)
1073 load_manager->ReportLoadError(error_info.error, error_info.string);
1074 return PP_FALSE;
1075 }
1076
1077 PP_Bool ManifestResolveKey(PP_Instance instance,
1078 int32_t manifest_id,
1079 const char* key,
1080 PP_Var* pp_full_url,
1081 PP_PNaClOptions* pnacl_options) {
1082 if (manifest_id == GetPNaClManifestId()) {
1083 pnacl_options->translate = PP_FALSE;
1084 // We can only resolve keys in the files/ namespace.
1085 const std::string kFilesPrefix = "files/";
1086 std::string key_string(key);
1087 if (key_string.find(kFilesPrefix) == std::string::npos) {
1088 nacl::NexeLoadManager* load_manager = GetNexeLoadManager(instance);
1089 if (load_manager)
1090 load_manager->ReportLoadError(PP_NACL_ERROR_MANIFEST_RESOLVE_URL,
1091 "key did not start with files/");
1092 return PP_FALSE;
1093 }
1094 std::string key_basename = key_string.substr(kFilesPrefix.length());
1095 std::string pnacl_url =
1096 std::string("chrome://pnacl-translator/") + GetSandboxArch() + "/" +
1097 key_basename;
1098 *pp_full_url = ppapi::StringVar::StringToPPVar(pnacl_url);
1099 return PP_TRUE;
1100 }
1101
1102 JsonManifestMap::iterator it = g_manifest_map.Get().find(manifest_id);
1103 if (it == g_manifest_map.Get().end())
1104 return PP_FALSE;
1105
1106 std::string full_url;
1107 bool ok = it->second->ResolveKey(key, &full_url, pnacl_options);
1108 if (ok)
1109 *pp_full_url = ppapi::StringVar::StringToPPVar(full_url);
1110 return PP_FromBool(ok);
1111 }
1112
994 const PPB_NaCl_Private nacl_interface = { 1113 const PPB_NaCl_Private nacl_interface = {
995 &LaunchSelLdr, 1114 &LaunchSelLdr,
996 &StartPpapiProxy, 1115 &StartPpapiProxy,
997 &UrandomFD, 1116 &UrandomFD,
998 &Are3DInterfacesDisabled, 1117 &Are3DInterfacesDisabled,
999 &BrokerDuplicateHandle, 1118 &BrokerDuplicateHandle,
1000 &GetReadonlyPnaclFD, 1119 &GetReadonlyPnaclFD,
1001 &CreateTemporaryFile, 1120 &CreateTemporaryFile,
1002 &GetNumberOfProcessors, 1121 &GetNumberOfProcessors,
1003 &IsNonSFIModeEnabled, 1122 &IsNonSFIModeEnabled,
(...skipping 19 matching lines...) Expand all
1023 &InitializePlugin, 1142 &InitializePlugin,
1024 &GetNexeSize, 1143 &GetNexeSize,
1025 &RequestNaClManifest, 1144 &RequestNaClManifest,
1026 &GetManifestBaseURL, 1145 &GetManifestBaseURL,
1027 &ResolvesRelativeToPluginBaseURL, 1146 &ResolvesRelativeToPluginBaseURL,
1028 &ParseDataURL, 1147 &ParseDataURL,
1029 &ProcessNaClManifest, 1148 &ProcessNaClManifest,
1030 &GetManifestURLArgument, 1149 &GetManifestURLArgument,
1031 &IsPNaCl, 1150 &IsPNaCl,
1032 &DevInterfacesEnabled, 1151 &DevInterfacesEnabled,
1033 &DownloadManifestToBuffer 1152 &DownloadManifestToBuffer,
1153 &CreatePNaClManifest,
1154 &CreateJsonManifest,
1155 &DestroyManifest,
1156 &ManifestGetProgramURL,
1157 &ManifestResolveKey
1034 }; 1158 };
1035 1159
1036 } // namespace 1160 } // namespace
1037 1161
1038 const PPB_NaCl_Private* GetNaClPrivateInterface() { 1162 const PPB_NaCl_Private* GetNaClPrivateInterface() {
1039 return &nacl_interface; 1163 return &nacl_interface;
1040 } 1164 }
1041 1165
1042 } // namespace nacl 1166 } // namespace nacl
OLDNEW
« no previous file with comments | « components/nacl/renderer/json_manifest.cc ('k') | ppapi/api/private/ppb_nacl_private.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698