OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ppapi/native_client/src/trusted/plugin/pnacl_resources.h" | 5 #include "ppapi/native_client/src/trusted/plugin/pnacl_resources.h" |
6 | 6 |
7 #include "native_client/src/include/portability_io.h" | 7 #include "native_client/src/include/portability_io.h" |
8 #include "native_client/src/shared/platform/nacl_check.h" | 8 #include "native_client/src/shared/platform/nacl_check.h" |
9 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h" | 9 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h" |
10 #include "ppapi/c/pp_errors.h" | 10 #include "ppapi/c/pp_errors.h" |
11 #include "ppapi/native_client/src/trusted/plugin/file_utils.h" | |
12 #include "ppapi/native_client/src/trusted/plugin/manifest.h" | 11 #include "ppapi/native_client/src/trusted/plugin/manifest.h" |
13 #include "ppapi/native_client/src/trusted/plugin/plugin.h" | 12 #include "ppapi/native_client/src/trusted/plugin/plugin.h" |
14 #include "ppapi/native_client/src/trusted/plugin/pnacl_coordinator.h" | 13 #include "ppapi/native_client/src/trusted/plugin/pnacl_coordinator.h" |
15 #include "ppapi/native_client/src/trusted/plugin/utility.h" | 14 #include "ppapi/native_client/src/trusted/plugin/utility.h" |
16 #include "third_party/jsoncpp/source/include/json/reader.h" | 15 #include "third_party/jsoncpp/source/include/json/reader.h" |
17 #include "third_party/jsoncpp/source/include/json/value.h" | 16 #include "third_party/jsoncpp/source/include/json/value.h" |
18 | 17 |
19 namespace plugin { | 18 namespace plugin { |
20 | 19 |
21 static const char kPnaclBaseUrl[] = "chrome://pnacl-translator/"; | 20 static const char kPnaclBaseUrl[] = "chrome://pnacl-translator/"; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 PLUGIN_PRINTF(("PnaclResources::ReadResourceInfo\n")); | 99 PLUGIN_PRINTF(("PnaclResources::ReadResourceInfo\n")); |
101 | 100 |
102 nacl::string full_url = PnaclUrls::GetBaseUrl() + resource_info_url; | 101 nacl::string full_url = PnaclUrls::GetBaseUrl() + resource_info_url; |
103 PLUGIN_PRINTF(("Resolved resources info url: %s\n", full_url.c_str())); | 102 PLUGIN_PRINTF(("Resolved resources info url: %s\n", full_url.c_str())); |
104 nacl::string resource_info_filename = | 103 nacl::string resource_info_filename = |
105 PnaclUrls::PnaclComponentURLToFilename(full_url); | 104 PnaclUrls::PnaclComponentURLToFilename(full_url); |
106 | 105 |
107 PLUGIN_PRINTF(("Pnacl-converted resources info url: %s\n", | 106 PLUGIN_PRINTF(("Pnacl-converted resources info url: %s\n", |
108 resource_info_filename.c_str())); | 107 resource_info_filename.c_str())); |
109 | 108 |
110 int32_t fd = GetPnaclFD(plugin_, resource_info_filename.c_str()); | 109 PP_Var pp_llc_tool_name_var; |
111 if (fd < 0) { | 110 PP_Var pp_ld_tool_name_var; |
112 // File-open failed. Assume this means that the file is | 111 if (!plugin_->nacl_interface()->GetPnaclResourceInfo( |
113 // not actually installed. | 112 plugin_->pp_instance(), |
114 coordinator_->ReportNonPpapiError(PP_NACL_ERROR_PNACL_RESOURCE_FETCH, | 113 resource_info_filename.c_str(), |
115 nacl::string("The Portable Native Client (pnacl) component is not " | 114 &pp_llc_tool_name_var, |
116 "installed. Please consult chrome://components for more " | 115 &pp_ld_tool_name_var)) { |
117 "information.")); | 116 coordinator_->ExitWithError(); |
118 return; | |
119 } | 117 } |
120 | 118 |
121 nacl::string json_buffer; | 119 pp::Var llc_tool_name(pp::PASS_REF, pp_llc_tool_name_var); |
122 file_utils::StatusCode status = file_utils::SlurpFile(fd, json_buffer); | 120 pp::Var ld_tool_name(pp::PASS_REF, pp_ld_tool_name_var); |
123 if (status != file_utils::PLUGIN_FILE_SUCCESS) { | 121 llc_tool_name_ = llc_tool_name.AsString(); |
124 coordinator_->ReportNonPpapiError(PP_NACL_ERROR_PNACL_RESOURCE_FETCH, | 122 llc_tool_name_ = ld_tool_name.AsString(); |
125 nacl::string("PnaclResources::ReadResourceInfo reading " | |
126 "failed for: ") + resource_info_filename); | |
127 return; | |
128 } | |
129 | |
130 // Finally, we have the resource info JSON data in json_buffer. | |
131 PLUGIN_PRINTF(("Resource info JSON data:\n%s\n", json_buffer.c_str())); | |
132 if (!ParseResourceInfo(json_buffer)) | |
133 return; | |
134 | |
135 // Done. Queue the completion callback. | |
136 pp::Core* core = pp::Module::Get()->core(); | 123 pp::Core* core = pp::Module::Get()->core(); |
137 core->CallOnMainThread(0, resource_info_read_cb, PP_OK); | 124 core->CallOnMainThread(0, resource_info_read_cb, PP_OK); |
138 } | 125 } |
139 | 126 |
140 bool PnaclResources::ParseResourceInfo(const nacl::string& buf) { | |
141 // Expect the JSON file to contain a top-level object (dictionary). | |
142 Json::Reader json_reader; | |
143 Json::Value json_data; | |
144 if (!json_reader.parse(buf, json_data)) { | |
145 std::string errmsg = nacl::string("JSON parse error: ") + | |
146 json_reader.getFormatedErrorMessages(); | |
147 coordinator_->ReportNonPpapiError(PP_NACL_ERROR_PNACL_RESOURCE_FETCH, | |
148 nacl::string("Parsing resource info failed: ") + errmsg + "\n"); | |
149 return false; | |
150 } | |
151 | |
152 if (!json_data.isObject()) { | |
153 coordinator_->ReportNonPpapiError(PP_NACL_ERROR_PNACL_RESOURCE_FETCH, | |
154 nacl::string("Parsing resource info failed: " | |
155 "Malformed JSON dictionary\n")); | |
156 return false; | |
157 } | |
158 | |
159 if (json_data.isMember("pnacl-llc-name")) { | |
160 Json::Value json_name = json_data["pnacl-llc-name"]; | |
161 if (json_name.isString()) { | |
162 llc_tool_name_ = json_name.asString(); | |
163 PLUGIN_PRINTF(("Set llc_tool_name=%s\n", llc_tool_name_.c_str())); | |
164 } | |
165 } | |
166 | |
167 if (json_data.isMember("pnacl-ld-name")) { | |
168 Json::Value json_name = json_data["pnacl-ld-name"]; | |
169 if (json_name.isString()) { | |
170 ld_tool_name_ = json_name.asString(); | |
171 PLUGIN_PRINTF(("Set ld_tool_name=%s\n", ld_tool_name_.c_str())); | |
172 } | |
173 } | |
174 return true; | |
175 } | |
176 | |
177 nacl::string PnaclResources::GetFullUrl( | 127 nacl::string PnaclResources::GetFullUrl( |
178 const nacl::string& partial_url, const nacl::string& sandbox_arch) const { | 128 const nacl::string& partial_url, const nacl::string& sandbox_arch) const { |
179 return PnaclUrls::GetBaseUrl() + sandbox_arch + "/" + partial_url; | 129 return PnaclUrls::GetBaseUrl() + sandbox_arch + "/" + partial_url; |
180 } | 130 } |
181 | 131 |
182 void PnaclResources::StartLoad( | 132 void PnaclResources::StartLoad( |
183 const pp::CompletionCallback& all_loaded_callback) { | 133 const pp::CompletionCallback& all_loaded_callback) { |
184 PLUGIN_PRINTF(("PnaclResources::StartLoad\n")); | 134 PLUGIN_PRINTF(("PnaclResources::StartLoad\n")); |
185 | 135 |
186 std::vector<nacl::string> resource_urls; | 136 std::vector<nacl::string> resource_urls; |
(...skipping 24 matching lines...) Expand all Loading... |
211 resource_wrappers_[resource_urls[i]] = | 161 resource_wrappers_[resource_urls[i]] = |
212 plugin_->wrapper_factory()->MakeFileDesc(fd, O_RDONLY); | 162 plugin_->wrapper_factory()->MakeFileDesc(fd, O_RDONLY); |
213 } | 163 } |
214 } | 164 } |
215 // We're done! Queue the callback. | 165 // We're done! Queue the callback. |
216 pp::Core* core = pp::Module::Get()->core(); | 166 pp::Core* core = pp::Module::Get()->core(); |
217 core->CallOnMainThread(0, all_loaded_callback, result); | 167 core->CallOnMainThread(0, all_loaded_callback, result); |
218 } | 168 } |
219 | 169 |
220 } // namespace plugin | 170 } // namespace plugin |
OLD | NEW |