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 "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" |
(...skipping 22 matching lines...) Expand all Loading... |
33 #include "net/base/net_errors.h" | 33 #include "net/base/net_errors.h" |
34 #include "net/http/http_util.h" | 34 #include "net/http/http_util.h" |
35 #include "ppapi/c/pp_bool.h" | 35 #include "ppapi/c/pp_bool.h" |
36 #include "ppapi/c/private/pp_file_handle.h" | 36 #include "ppapi/c/private/pp_file_handle.h" |
37 #include "ppapi/native_client/src/trusted/plugin/nacl_entry_points.h" | 37 #include "ppapi/native_client/src/trusted/plugin/nacl_entry_points.h" |
38 #include "ppapi/shared_impl/ppapi_globals.h" | 38 #include "ppapi/shared_impl/ppapi_globals.h" |
39 #include "ppapi/shared_impl/ppapi_permissions.h" | 39 #include "ppapi/shared_impl/ppapi_permissions.h" |
40 #include "ppapi/shared_impl/ppapi_preferences.h" | 40 #include "ppapi/shared_impl/ppapi_preferences.h" |
41 #include "ppapi/shared_impl/var.h" | 41 #include "ppapi/shared_impl/var.h" |
42 #include "ppapi/thunk/enter.h" | 42 #include "ppapi/thunk/enter.h" |
| 43 #include "third_party/jsoncpp/source/include/json/reader.h" |
| 44 #include "third_party/jsoncpp/source/include/json/value.h" |
43 #include "third_party/WebKit/public/platform/WebURLLoader.h" | 45 #include "third_party/WebKit/public/platform/WebURLLoader.h" |
44 #include "third_party/WebKit/public/web/WebDocument.h" | 46 #include "third_party/WebKit/public/web/WebDocument.h" |
45 #include "third_party/WebKit/public/web/WebElement.h" | 47 #include "third_party/WebKit/public/web/WebElement.h" |
46 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 48 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
47 #include "third_party/WebKit/public/web/WebPluginContainer.h" | 49 #include "third_party/WebKit/public/web/WebPluginContainer.h" |
48 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" | 50 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" |
49 #include "third_party/WebKit/public/web/WebURLLoaderOptions.h" | 51 #include "third_party/WebKit/public/web/WebURLLoaderOptions.h" |
50 | 52 |
51 namespace nacl { | 53 namespace nacl { |
52 namespace { | 54 namespace { |
(...skipping 901 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
954 "could not load manifest url."); | 956 "could not load manifest url."); |
955 } | 957 } |
956 | 958 |
957 if (pp_error == PP_OK) { | 959 if (pp_error == PP_OK) { |
958 std::string contents; | 960 std::string contents; |
959 *out_data = ppapi::StringVar::StringToPPVar(data); | 961 *out_data = ppapi::StringVar::StringToPPVar(data); |
960 } | 962 } |
961 callback.func(callback.user_data, pp_error); | 963 callback.func(callback.user_data, pp_error); |
962 } | 964 } |
963 | 965 |
| 966 PP_Bool GetPNaClResourceInfo(PP_Instance instance, |
| 967 const char* filename, |
| 968 PP_Var* llc_tool_name, |
| 969 PP_Var* ld_tool_name) { |
| 970 NexeLoadManager* load_manager = GetNexeLoadManager(instance); |
| 971 DCHECK(load_manager); |
| 972 if (!load_manager) |
| 973 return PP_FALSE; |
| 974 |
| 975 base::PlatformFile file = GetReadonlyPnaclFD(filename); |
| 976 if (file == base::kInvalidPlatformFileValue) { |
| 977 load_manager->ReportLoadError( |
| 978 PP_NACL_ERROR_PNACL_RESOURCE_FETCH, |
| 979 "The Portable Native Client (pnacl) component is not " |
| 980 "installed. Please consult chrome://components for more " |
| 981 "information."); |
| 982 return PP_FALSE; |
| 983 } |
| 984 |
| 985 const int kBufferSize = 1 << 20; |
| 986 scoped_ptr<char> buffer(new char[kBufferSize]); |
| 987 if (base::ReadPlatformFile(file, 0, buffer.get(), kBufferSize) < 0) { |
| 988 load_manager->ReportLoadError( |
| 989 PP_NACL_ERROR_PNACL_RESOURCE_FETCH, |
| 990 std::string("PnaclResources::ReadResourceInfo reading failed for: ") + |
| 991 filename); |
| 992 return PP_FALSE; |
| 993 } |
| 994 |
| 995 // Expect the JSON file to contain a top-level object (dictionary). |
| 996 Json::Reader json_reader; |
| 997 Json::Value json_data; |
| 998 if (!json_reader.parse(buffer.get(), json_data)) { |
| 999 load_manager->ReportLoadError( |
| 1000 PP_NACL_ERROR_PNACL_RESOURCE_FETCH, |
| 1001 std::string("Parsing resource info failed: JSON parse error: ") + |
| 1002 json_reader.getFormattedErrorMessages()); |
| 1003 return PP_FALSE; |
| 1004 } |
| 1005 |
| 1006 if (!json_data.isObject()) { |
| 1007 load_manager->ReportLoadError( |
| 1008 PP_NACL_ERROR_PNACL_RESOURCE_FETCH, |
| 1009 "Parsing resource info failed: Malformed JSON dictionary"); |
| 1010 return PP_FALSE; |
| 1011 } |
| 1012 |
| 1013 if (json_data.isMember("pnacl-llc-name")) { |
| 1014 Json::Value json_name = json_data["pnacl-llc-name"]; |
| 1015 if (json_name.isString()) { |
| 1016 std::string llc_tool_name_str = json_name.asString(); |
| 1017 *llc_tool_name = ppapi::StringVar::StringToPPVar(llc_tool_name_str); |
| 1018 } |
| 1019 } |
| 1020 |
| 1021 if (json_data.isMember("pnacl-ld-name")) { |
| 1022 Json::Value json_name = json_data["pnacl-ld-name"]; |
| 1023 if (json_name.isString()) { |
| 1024 std::string ld_tool_name_str = json_name.asString(); |
| 1025 *ld_tool_name = ppapi::StringVar::StringToPPVar(ld_tool_name_str); |
| 1026 } |
| 1027 } |
| 1028 return PP_TRUE; |
| 1029 } |
| 1030 |
964 const PPB_NaCl_Private nacl_interface = { | 1031 const PPB_NaCl_Private nacl_interface = { |
965 &LaunchSelLdr, | 1032 &LaunchSelLdr, |
966 &StartPpapiProxy, | 1033 &StartPpapiProxy, |
967 &UrandomFD, | 1034 &UrandomFD, |
968 &Are3DInterfacesDisabled, | 1035 &Are3DInterfacesDisabled, |
969 &BrokerDuplicateHandle, | 1036 &BrokerDuplicateHandle, |
970 &GetReadonlyPnaclFD, | 1037 &GetReadonlyPnaclFD, |
971 &CreateTemporaryFile, | 1038 &CreateTemporaryFile, |
972 &GetNumberOfProcessors, | 1039 &GetNumberOfProcessors, |
973 &IsNonSFIModeEnabled, | 1040 &IsNonSFIModeEnabled, |
(...skipping 19 matching lines...) Expand all Loading... |
993 &InitializePlugin, | 1060 &InitializePlugin, |
994 &GetNexeSize, | 1061 &GetNexeSize, |
995 &RequestNaClManifest, | 1062 &RequestNaClManifest, |
996 &GetManifestBaseURL, | 1063 &GetManifestBaseURL, |
997 &ResolvesRelativeToPluginBaseURL, | 1064 &ResolvesRelativeToPluginBaseURL, |
998 &ParseDataURL, | 1065 &ParseDataURL, |
999 &ProcessNaClManifest, | 1066 &ProcessNaClManifest, |
1000 &GetManifestURLArgument, | 1067 &GetManifestURLArgument, |
1001 &IsPNaCl, | 1068 &IsPNaCl, |
1002 &DevInterfacesEnabled, | 1069 &DevInterfacesEnabled, |
1003 &DownloadManifestToBuffer | 1070 &DownloadManifestToBuffer, |
| 1071 &GetPNaClResourceInfo |
1004 }; | 1072 }; |
1005 | 1073 |
1006 } // namespace | 1074 } // namespace |
1007 | 1075 |
1008 const PPB_NaCl_Private* GetNaClPrivateInterface() { | 1076 const PPB_NaCl_Private* GetNaClPrivateInterface() { |
1009 return &nacl_interface; | 1077 return &nacl_interface; |
1010 } | 1078 } |
1011 | 1079 |
1012 } // namespace nacl | 1080 } // namespace nacl |
OLD | NEW |