| 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 // Manifest processing for JSON manifests. | 7 // Manifest processing for JSON manifests. |
| 8 | 8 |
| 9 #ifndef NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_JSON_MANIFEST_H_ | 9 #ifndef NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_JSON_MANIFEST_H_ |
| 10 #define NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_JSON_MANIFEST_H_ | 10 #define NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_JSON_MANIFEST_H_ |
| 11 | 11 |
| 12 #include <map> | 12 #include <map> |
| 13 #include <set> | 13 #include <set> |
| 14 #include <string> | 14 #include <string> |
| 15 | 15 |
| 16 #include "native_client/src/include/nacl_macros.h" | 16 #include "native_client/src/include/nacl_macros.h" |
| 17 #include "native_client/src/include/nacl_string.h" | 17 #include "native_client/src/include/nacl_string.h" |
| 18 #include "native_client/src/trusted/plugin/manifest.h" | 18 #include "native_client/src/trusted/plugin/manifest.h" |
| 19 #include "third_party/jsoncpp/source/include/json/value.h" | 19 #include "third_party/jsoncpp/source/include/json/value.h" |
| 20 | 20 |
| 21 namespace pp { | 21 namespace pp { |
| 22 class URLUtil_Dev; | 22 class URLUtil_Dev; |
| 23 } // namespace pp | 23 } // namespace pp |
| 24 | 24 |
| 25 namespace plugin { | 25 namespace plugin { |
| 26 | 26 |
| 27 class ErrorInfo; | 27 class ErrorInfo; |
| 28 class PnaclOptions; |
| 28 | 29 |
| 29 class JsonManifest : public Manifest { | 30 class JsonManifest : public Manifest { |
| 30 public: | 31 public: |
| 31 JsonManifest(const pp::URLUtil_Dev* url_util, | 32 JsonManifest(const pp::URLUtil_Dev* url_util, |
| 32 const nacl::string& manifest_base_url, | 33 const nacl::string& manifest_base_url, |
| 33 const nacl::string& sandbox_isa, | 34 const nacl::string& sandbox_isa, |
| 34 bool prefer_portable) | 35 bool prefer_portable) |
| 35 : url_util_(url_util), | 36 : url_util_(url_util), |
| 36 manifest_base_url_(manifest_base_url), | 37 manifest_base_url_(manifest_base_url), |
| 37 sandbox_isa_(sandbox_isa), | 38 sandbox_isa_(sandbox_isa), |
| 38 prefer_portable_(prefer_portable), | 39 prefer_portable_(prefer_portable), |
| 39 dictionary_(Json::nullValue) { } | 40 dictionary_(Json::nullValue) { } |
| 40 virtual ~JsonManifest() { } | 41 virtual ~JsonManifest() { } |
| 41 | 42 |
| 42 // Initialize the manifest object for use by later lookups. The return | 43 // Initialize the manifest object for use by later lookups. The return |
| 43 // value is true if the manifest parses correctly and matches the schema. | 44 // value is true if the manifest parses correctly and matches the schema. |
| 44 bool Init(const nacl::string& json, ErrorInfo* error_info); | 45 bool Init(const nacl::string& json, ErrorInfo* error_info); |
| 45 | 46 |
| 46 // Gets the full program URL for the current sandbox ISA from the | 47 // Gets the full program URL for the current sandbox ISA from the |
| 47 // manifest file. Sets |pnacl_translate| to |true| if the program is | 48 // manifest file. |
| 48 // portable bitcode that must be translated. | |
| 49 virtual bool GetProgramURL(nacl::string* full_url, | 49 virtual bool GetProgramURL(nacl::string* full_url, |
| 50 nacl::string* cache_identity, | 50 PnaclOptions* pnacl_options, |
| 51 ErrorInfo* error_info, | 51 ErrorInfo* error_info) const; |
| 52 bool* pnacl_translate) const; | |
| 53 | 52 |
| 54 // Resolves a URL relative to the manifest base URL | 53 // Resolves a URL relative to the manifest base URL |
| 55 virtual bool ResolveURL(const nacl::string& relative_url, | 54 virtual bool ResolveURL(const nacl::string& relative_url, |
| 56 nacl::string* full_url, | 55 nacl::string* full_url, |
| 57 ErrorInfo* error_info) const; | 56 ErrorInfo* error_info) const; |
| 58 | 57 |
| 59 // Gets the file names from the "files" section of the manifest. No | 58 // Gets the file names from the "files" section of the manifest. No |
| 60 // checking that the keys' values are proper ISA dictionaries -- it | 59 // checking that the keys' values are proper ISA dictionaries -- it |
| 61 // is assumed that other consistency checks take care of that, and | 60 // is assumed that other consistency checks take care of that, and |
| 62 // that the keys are appropriate for use with ResolveKey. | 61 // that the keys are appropriate for use with ResolveKey. |
| 63 virtual bool GetFileKeys(std::set<nacl::string>* keys) const; | 62 virtual bool GetFileKeys(std::set<nacl::string>* keys) const; |
| 64 | 63 |
| 65 // Resolves a key from the "files" section to a fully resolved URL, | 64 // Resolves a key from the "files" section to a fully resolved URL, |
| 66 // i.e., relative URL values are fully expanded relative to the | 65 // i.e., relative URL values are fully expanded relative to the |
| 67 // manifest's URL (via ResolveURL). |pnacl_translate| tells the caller | 66 // manifest's URL (via ResolveURL). |
| 68 // whether the resolution requires a pnacl translation step. | |
| 69 // If there was an error, details are reported via error_info. | 67 // If there was an error, details are reported via error_info. |
| 70 virtual bool ResolveKey(const nacl::string& key, | 68 virtual bool ResolveKey(const nacl::string& key, |
| 71 nacl::string* full_url, | 69 nacl::string* full_url, |
| 72 nacl::string* cache_identity, | 70 PnaclOptions* pnacl_options, |
| 73 ErrorInfo* error_info, | 71 ErrorInfo* error_info) const; |
| 74 bool* pnacl_translate) const; | |
| 75 | 72 |
| 76 private: | 73 private: |
| 77 NACL_DISALLOW_COPY_AND_ASSIGN(JsonManifest); | 74 NACL_DISALLOW_COPY_AND_ASSIGN(JsonManifest); |
| 78 | 75 |
| 79 // Checks that |dictionary_| is a valid manifest, according to the schema. | 76 // Checks that |dictionary_| is a valid manifest, according to the schema. |
| 80 // Returns true on success, and sets |error_info| to a detailed message | 77 // Returns true on success, and sets |error_info| to a detailed message |
| 81 // if not. | 78 // if not. |
| 82 bool MatchesSchema(ErrorInfo* error_info); | 79 bool MatchesSchema(ErrorInfo* error_info); |
| 83 | 80 |
| 84 const pp::URLUtil_Dev* url_util_; | 81 const pp::URLUtil_Dev* url_util_; |
| 85 nacl::string manifest_base_url_; | 82 nacl::string manifest_base_url_; |
| 86 nacl::string sandbox_isa_; | 83 nacl::string sandbox_isa_; |
| 87 // Determines whether portable programs are chosen in manifest files over | 84 // Determines whether portable programs are chosen in manifest files over |
| 88 // native programs. | 85 // native programs. |
| 89 bool prefer_portable_; | 86 bool prefer_portable_; |
| 90 | 87 |
| 91 Json::Value dictionary_; | 88 Json::Value dictionary_; |
| 92 }; | 89 }; |
| 93 | 90 |
| 94 | 91 |
| 95 } // namespace plugin | 92 } // namespace plugin |
| 96 | 93 |
| 97 #endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_JSON_MANIFEST_H_ | 94 #endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_JSON_MANIFEST_H_ |
| OLD | NEW |