OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 * Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
5 */ | 5 */ |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "native_client/src/trusted/plugin/json_manifest.h" | 9 #include "native_client/src/trusted/plugin/json_manifest.h" |
10 | 10 |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 return true; | 189 return true; |
190 } | 190 } |
191 | 191 |
192 // this will probably be replaced by jvoung's version that exposes | 192 // this will probably be replaced by jvoung's version that exposes |
193 // is_portable checks | 193 // is_portable checks |
194 bool GetKeyUrl(const Json::Value& dictionary, | 194 bool GetKeyUrl(const Json::Value& dictionary, |
195 const nacl::string& key, | 195 const nacl::string& key, |
196 const nacl::string& sandbox_isa, | 196 const nacl::string& sandbox_isa, |
197 const Manifest* manifest, | 197 const Manifest* manifest, |
198 nacl::string* full_url, | 198 nacl::string* full_url, |
199 bool* permit_extension_url, | |
200 ErrorInfo* error_info, | 199 ErrorInfo* error_info, |
201 bool* is_portable) { | 200 bool* is_portable) { |
202 CHECK(full_url != NULL && error_info != NULL); | 201 CHECK(full_url != NULL && error_info != NULL); |
203 *full_url = ""; | 202 *full_url = ""; |
204 if (!dictionary.isMember(key)) { | 203 if (!dictionary.isMember(key)) { |
205 error_info->SetReport(ERROR_MANIFEST_RESOLVE_URL, | 204 error_info->SetReport(ERROR_MANIFEST_RESOLVE_URL, |
206 "file key not found in manifest"); | 205 "file key not found in manifest"); |
207 return false; | 206 return false; |
208 } | 207 } |
209 const Json::Value& isa_dict = dictionary[key]; | 208 const Json::Value& isa_dict = dictionary[key]; |
210 if (isa_dict.isMember(sandbox_isa)) { | 209 if (isa_dict.isMember(sandbox_isa)) { |
211 nacl::string relative_url = isa_dict[sandbox_isa][kUrlKey].asString(); | 210 nacl::string relative_url = isa_dict[sandbox_isa][kUrlKey].asString(); |
212 *is_portable = false; | 211 *is_portable = false; |
213 return manifest->ResolveURL(relative_url, full_url, permit_extension_url, | 212 return manifest->ResolveURL(relative_url, full_url, error_info); |
214 error_info); | |
215 } | 213 } |
216 if (isa_dict.isMember(kPortableKey)) { | 214 if (isa_dict.isMember(kPortableKey)) { |
217 nacl::string relative_url = isa_dict[kPortableKey][kUrlKey].asString(); | 215 nacl::string relative_url = isa_dict[kPortableKey][kUrlKey].asString(); |
218 *is_portable = true; | 216 *is_portable = true; |
219 return manifest->ResolveURL(relative_url, full_url, permit_extension_url, | 217 return manifest->ResolveURL(relative_url, full_url, error_info); |
220 error_info); | |
221 } | 218 } |
222 error_info->SetReport(ERROR_MANIFEST_RESOLVE_URL, | 219 error_info->SetReport(ERROR_MANIFEST_RESOLVE_URL, |
223 "neither ISA-specific nor portable representations" | 220 "neither ISA-specific nor portable representations" |
224 " exist"); | 221 " exist"); |
225 return false; | 222 return false; |
226 } | 223 } |
227 | 224 |
228 } // namespace | 225 } // namespace |
229 | 226 |
230 bool JsonManifest::Init(const nacl::string& manifest_json, | 227 bool JsonManifest::Init(const nacl::string& manifest_json, |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 return false; | 320 return false; |
324 } | 321 } |
325 } | 322 } |
326 } | 323 } |
327 | 324 |
328 return true; | 325 return true; |
329 } | 326 } |
330 | 327 |
331 bool JsonManifest::ResolveURL(const nacl::string& relative_url, | 328 bool JsonManifest::ResolveURL(const nacl::string& relative_url, |
332 nacl::string* full_url, | 329 nacl::string* full_url, |
333 bool* permit_extension_url, | |
334 ErrorInfo* error_info) const { | 330 ErrorInfo* error_info) const { |
335 // JSON manifests cannot confer extension access rights. | |
336 *permit_extension_url = false; | |
337 // The contents of the manifest are resolved relative to the manifest URL. | 331 // The contents of the manifest are resolved relative to the manifest URL. |
338 CHECK(url_util_ != NULL); | 332 CHECK(url_util_ != NULL); |
339 pp::Var resolved_url = | 333 pp::Var resolved_url = |
340 url_util_->ResolveRelativeToURL(pp::Var(manifest_base_url_), | 334 url_util_->ResolveRelativeToURL(pp::Var(manifest_base_url_), |
341 relative_url); | 335 relative_url); |
342 if (!resolved_url.is_string()) { | 336 if (!resolved_url.is_string()) { |
343 error_info->SetReport( | 337 error_info->SetReport( |
344 ERROR_MANIFEST_RESOLVE_URL, | 338 ERROR_MANIFEST_RESOLVE_URL, |
345 "could not resolve url '" + relative_url + | 339 "could not resolve url '" + relative_url + |
346 "' relative to manifest base url '" + manifest_base_url_.c_str() + | 340 "' relative to manifest base url '" + manifest_base_url_.c_str() + |
(...skipping 20 matching lines...) Expand all Loading... |
367 &nexe_url, | 361 &nexe_url, |
368 &error_string, | 362 &error_string, |
369 prefer_portable_, | 363 prefer_portable_, |
370 is_portable)) { | 364 is_portable)) { |
371 error_info->SetReport(ERROR_MANIFEST_GET_NEXE_URL, | 365 error_info->SetReport(ERROR_MANIFEST_GET_NEXE_URL, |
372 nacl::string("program:") + sandbox_isa_ + | 366 nacl::string("program:") + sandbox_isa_ + |
373 error_string); | 367 error_string); |
374 return false; | 368 return false; |
375 } | 369 } |
376 | 370 |
377 // The program URL must be in the current origin. | 371 return ResolveURL(nexe_url, full_url, error_info); |
378 bool dummy_permit_extension_url; | |
379 return ResolveURL(nexe_url, full_url, &dummy_permit_extension_url, | |
380 error_info); | |
381 } | 372 } |
382 | 373 |
383 bool JsonManifest::GetFileKeys(std::set<nacl::string>* keys) const { | 374 bool JsonManifest::GetFileKeys(std::set<nacl::string>* keys) const { |
384 if (!dictionary_.isMember(kFilesKey)) { | 375 if (!dictionary_.isMember(kFilesKey)) { |
385 // trivial success: no keys when there is no "files" section. | 376 // trivial success: no keys when there is no "files" section. |
386 return true; | 377 return true; |
387 } | 378 } |
388 const Json::Value& files = dictionary_[kFilesKey]; | 379 const Json::Value& files = dictionary_[kFilesKey]; |
389 CHECK(files.isObject()); | 380 CHECK(files.isObject()); |
390 Json::Value::Members members = files.getMemberNames(); | 381 Json::Value::Members members = files.getMemberNames(); |
391 for (size_t i = 0; i < members.size(); ++i) { | 382 for (size_t i = 0; i < members.size(); ++i) { |
392 keys->insert(members[i]); | 383 keys->insert(members[i]); |
393 } | 384 } |
394 return true; | 385 return true; |
395 } | 386 } |
396 | 387 |
397 bool JsonManifest::ResolveKey(const nacl::string& key, | 388 bool JsonManifest::ResolveKey(const nacl::string& key, |
398 nacl::string* full_url, | 389 nacl::string* full_url, |
399 bool* permit_extension_url, | |
400 ErrorInfo* error_info, | 390 ErrorInfo* error_info, |
401 bool* is_portable) const { | 391 bool* is_portable) const { |
402 NaClLog(3, "JsonManifest::ResolveKey(%s)\n", key.c_str()); | 392 NaClLog(3, "JsonManifest::ResolveKey(%s)\n", key.c_str()); |
403 // key must be one of kProgramKey or kFileKey '/' file-section-key | 393 // key must be one of kProgramKey or kFileKey '/' file-section-key |
404 | 394 |
405 *full_url = ""; | 395 *full_url = ""; |
406 if (key == kProgramKey) { | 396 if (key == kProgramKey) { |
407 return GetKeyUrl(dictionary_, key, sandbox_isa_, this, full_url, | 397 return GetKeyUrl(dictionary_, key, sandbox_isa_, this, full_url, |
408 permit_extension_url, error_info, is_portable); | 398 error_info, is_portable); |
409 } | 399 } |
410 nacl::string::const_iterator p = find(key.begin(), key.end(), '/'); | 400 nacl::string::const_iterator p = find(key.begin(), key.end(), '/'); |
411 if (p == key.end()) { | 401 if (p == key.end()) { |
412 error_info->SetReport(ERROR_MANIFEST_RESOLVE_URL, | 402 error_info->SetReport(ERROR_MANIFEST_RESOLVE_URL, |
413 nacl::string("ResolveKey: invalid key, no slash: ") | 403 nacl::string("ResolveKey: invalid key, no slash: ") |
414 + key); | 404 + key); |
415 return false; | 405 return false; |
416 } | 406 } |
417 | 407 |
418 // generalize to permit other sections? | 408 // generalize to permit other sections? |
(...skipping 16 matching lines...) Expand all Loading... |
435 return false; | 425 return false; |
436 } | 426 } |
437 if (!files.isMember(rest)) { | 427 if (!files.isMember(rest)) { |
438 error_info->SetReport( | 428 error_info->SetReport( |
439 ERROR_MANIFEST_RESOLVE_URL, | 429 ERROR_MANIFEST_RESOLVE_URL, |
440 nacl::string("ResolveKey: no such \"files\" entry: ") + key); | 430 nacl::string("ResolveKey: no such \"files\" entry: ") + key); |
441 *is_portable = false; | 431 *is_portable = false; |
442 return false; | 432 return false; |
443 } | 433 } |
444 return GetKeyUrl(files, rest, sandbox_isa_, this, full_url, | 434 return GetKeyUrl(files, rest, sandbox_isa_, this, full_url, |
445 permit_extension_url, error_info, is_portable); | 435 error_info, is_portable); |
446 } | 436 } |
447 | 437 |
448 } // namespace plugin | 438 } // namespace plugin |
OLD | NEW |