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

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: Rebased 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/json_manifest.h"
18 #include "components/nacl/renderer/manifest_service_channel.h" 19 #include "components/nacl/renderer/manifest_service_channel.h"
19 #include "components/nacl/renderer/nexe_load_manager.h" 20 #include "components/nacl/renderer/nexe_load_manager.h"
20 #include "components/nacl/renderer/pnacl_translation_resource_host.h" 21 #include "components/nacl/renderer/pnacl_translation_resource_host.h"
21 #include "components/nacl/renderer/sandbox_arch.h" 22 #include "components/nacl/renderer/sandbox_arch.h"
22 #include "components/nacl/renderer/trusted_plugin_channel.h" 23 #include "components/nacl/renderer/trusted_plugin_channel.h"
23 #include "content/public/common/content_client.h" 24 #include "content/public/common/content_client.h"
24 #include "content/public/common/content_switches.h" 25 #include "content/public/common/content_switches.h"
25 #include "content/public/common/sandbox_init.h" 26 #include "content/public/common/sandbox_init.h"
26 #include "content/public/renderer/pepper_plugin_instance.h" 27 #include "content/public/renderer/pepper_plugin_instance.h"
27 #include "content/public/renderer/render_thread.h" 28 #include "content/public/renderer/render_thread.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 75
75 base::LazyInstance<InstanceInfoMap> g_instance_info = 76 base::LazyInstance<InstanceInfoMap> g_instance_info =
76 LAZY_INSTANCE_INITIALIZER; 77 LAZY_INSTANCE_INITIALIZER;
77 78
78 typedef base::ScopedPtrHashMap<PP_Instance, NexeLoadManager> 79 typedef base::ScopedPtrHashMap<PP_Instance, NexeLoadManager>
79 NexeLoadManagerMap; 80 NexeLoadManagerMap;
80 81
81 base::LazyInstance<NexeLoadManagerMap> g_load_manager_map = 82 base::LazyInstance<NexeLoadManagerMap> g_load_manager_map =
82 LAZY_INSTANCE_INITIALIZER; 83 LAZY_INSTANCE_INITIALIZER;
83 84
84 NexeLoadManager* GetNexeLoadManager(PP_Instance instance) { 85 typedef base::ScopedPtrHashMap<int32_t, nacl::JsonManifest> JsonManifestMap;
86
87 base::LazyInstance<JsonManifestMap> g_manifest_map =
88 LAZY_INSTANCE_INITIALIZER;
89
90 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.
91 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.
92
93 nacl::NexeLoadManager* GetNexeLoadManager(PP_Instance instance) {
85 NexeLoadManagerMap& map = g_load_manager_map.Get(); 94 NexeLoadManagerMap& map = g_load_manager_map.Get();
86 NexeLoadManagerMap::iterator iter = map.find(instance); 95 NexeLoadManagerMap::iterator iter = map.find(instance);
87 if (iter != map.end()) 96 if (iter != map.end())
88 return iter->second; 97 return iter->second;
89 return NULL; 98 return NULL;
90 } 99 }
91 100
92 int GetRoutingID(PP_Instance instance) { 101 int GetRoutingID(PP_Instance instance) {
93 // Check that we are on the main renderer thread. 102 // Check that we are on the main renderer thread.
94 DCHECK(content::RenderThread::Get()); 103 DCHECK(content::RenderThread::Get());
(...skipping 749 matching lines...) Expand 10 before | Expand all | Expand 10 after
844 return PP_FALSE; 853 return PP_FALSE;
845 } 854 }
846 855
847 PP_Bool DevInterfacesEnabled(PP_Instance instance) { 856 PP_Bool DevInterfacesEnabled(PP_Instance instance) {
848 nacl::NexeLoadManager* load_manager = GetNexeLoadManager(instance); 857 nacl::NexeLoadManager* load_manager = GetNexeLoadManager(instance);
849 if (load_manager) 858 if (load_manager)
850 return PP_FromBool(load_manager->DevInterfacesEnabled()); 859 return PP_FromBool(load_manager->DevInterfacesEnabled());
851 return PP_FALSE; 860 return PP_FALSE;
852 } 861 }
853 862
863 int32_t CreatePNaClManifest(PP_Instance /* instance */) {
864 return kPNaClManifestId;
865 }
866
867 int32_t CreateJsonManifest(PP_Instance instance,
868 const char* manifest_url,
869 const char* isa_type,
870 const char* manifest_data) {
871 int32_t manifest_id = g_next_manifest_id;
872 g_next_manifest_id++;
873
874 scoped_ptr<nacl::JsonManifest> j(
875 new nacl::JsonManifest(
876 manifest_url,
877 isa_type,
878 PP_ToBool(IsNonSFIModeEnabled()),
879 PP_ToBool(NaClDebugEnabledForURL(manifest_url))));
880 JsonManifest::ErrorInfo error_info;
881 if (j->Init(manifest_data, &error_info)) {
882 g_manifest_map.Get().add(manifest_id, j.Pass());
883 return manifest_id;
884 }
885 nacl::NexeLoadManager* load_manager = GetNexeLoadManager(instance);
886 if (load_manager)
887 load_manager->ReportLoadError(error_info.error, error_info.string);
888 return -1;
889 }
890
891 void DestroyManifest(PP_Instance /* instance */,
892 int32_t manifest_id) {
893 if (manifest_id == kPNaClManifestId)
894 return;
895 g_manifest_map.Get().erase(manifest_id);
896 }
897
898 PP_Bool ManifestGetProgramURL(PP_Instance instance,
899 int32_t manifest_id,
900 PP_Var* pp_full_url,
901 PP_PNaClOptions* pnacl_options,
902 PP_Bool* pp_uses_nonsfi_mode) {
903 nacl::NexeLoadManager* load_manager = GetNexeLoadManager(instance);
904 if (manifest_id == kPNaClManifestId) {
905 if (load_manager) {
906 load_manager->ReportLoadError(
907 PP_NACL_ERROR_MANIFEST_GET_NEXE_URL,
908 "pnacl manifest does not contain a program.");
909 }
910 return PP_FALSE;
911 }
912
913 JsonManifestMap::iterator it = g_manifest_map.Get().find(manifest_id);
914 if (it == g_manifest_map.Get().end())
915 return PP_FALSE;
916
917 bool uses_nonsfi_mode;
918 std::string full_url;
919 JsonManifest::ErrorInfo error_info;
920 if (it->second->GetProgramURL(&full_url, pnacl_options, &uses_nonsfi_mode,
921 &error_info)) {
922 *pp_full_url = ppapi::StringVar::StringToPPVar(full_url);
923 *pp_uses_nonsfi_mode = PP_FromBool(uses_nonsfi_mode);
924 return PP_TRUE;
925 }
926
927 if (load_manager)
928 load_manager->ReportLoadError(error_info.error, error_info.string);
929 return PP_FALSE;
930 }
931
932 PP_Bool ManifestResolveKey(PP_Instance instance,
933 int32_t manifest_id,
934 const char* key,
935 PP_Var* pp_full_url,
936 PP_PNaClOptions* pnacl_options) {
937 if (manifest_id == kPNaClManifestId) {
938 pnacl_options->translate = PP_FALSE;
939 // We can only resolve keys in the files/ namespace.
940 const std::string kFilesPrefix = "files/";
941 std::string key_string(key);
942 if (key_string.find(kFilesPrefix) == std::string::npos) {
943 nacl::NexeLoadManager* load_manager = GetNexeLoadManager(instance);
944 if (load_manager)
945 load_manager->ReportLoadError(PP_NACL_ERROR_MANIFEST_RESOLVE_URL,
946 "key did not start with files/");
947 return PP_FALSE;
948 }
949 std::string key_basename = key_string.substr(kFilesPrefix.length());
950 std::string pnacl_url =
951 std::string("chrome://pnacl-translator/") + GetSandboxArch() + "/" +
952 key_basename;
953 *pp_full_url = ppapi::StringVar::StringToPPVar(pnacl_url);
954 return PP_TRUE;
955 }
956
957 JsonManifestMap::iterator it = g_manifest_map.Get().find(manifest_id);
958 if (it == g_manifest_map.Get().end())
959 return PP_FALSE;
960
961 std::string full_url;
962 bool ok = it->second->ResolveKey(key, &full_url, pnacl_options);
963 if (ok)
964 *pp_full_url = ppapi::StringVar::StringToPPVar(full_url);
965 return PP_FromBool(ok);
966 }
967
854 const PPB_NaCl_Private nacl_interface = { 968 const PPB_NaCl_Private nacl_interface = {
855 &LaunchSelLdr, 969 &LaunchSelLdr,
856 &StartPpapiProxy, 970 &StartPpapiProxy,
857 &UrandomFD, 971 &UrandomFD,
858 &Are3DInterfacesDisabled, 972 &Are3DInterfacesDisabled,
859 &BrokerDuplicateHandle, 973 &BrokerDuplicateHandle,
860 &GetReadonlyPnaclFD, 974 &GetReadonlyPnaclFD,
861 &CreateTemporaryFile, 975 &CreateTemporaryFile,
862 &GetNumberOfProcessors, 976 &GetNumberOfProcessors,
863 &IsNonSFIModeEnabled, 977 &IsNonSFIModeEnabled,
(...skipping 18 matching lines...) Expand all
882 &Vlog, 996 &Vlog,
883 &InitializePlugin, 997 &InitializePlugin,
884 &GetNexeSize, 998 &GetNexeSize,
885 &RequestNaClManifest, 999 &RequestNaClManifest,
886 &GetManifestBaseURL, 1000 &GetManifestBaseURL,
887 &ResolvesRelativeToPluginBaseURL, 1001 &ResolvesRelativeToPluginBaseURL,
888 &ParseDataURL, 1002 &ParseDataURL,
889 &ProcessNaClManifest, 1003 &ProcessNaClManifest,
890 &GetManifestURLArgument, 1004 &GetManifestURLArgument,
891 &IsPNaCl, 1005 &IsPNaCl,
892 &DevInterfacesEnabled 1006 &DevInterfacesEnabled,
1007 &CreatePNaClManifest,
1008 &CreateJsonManifest,
1009 &DestroyManifest,
1010 &ManifestGetProgramURL,
1011 &ManifestResolveKey
893 }; 1012 };
894 1013
895 } // namespace 1014 } // namespace
896 1015
897 const PPB_NaCl_Private* GetNaClPrivateInterface() { 1016 const PPB_NaCl_Private* GetNaClPrivateInterface() {
898 return &nacl_interface; 1017 return &nacl_interface;
899 } 1018 }
900 1019
901 } // namespace nacl 1020 } // namespace nacl
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698