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

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

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

Powered by Google App Engine
This is Rietveld 408576698