1 // Copyright 2014 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef COMPONENTS_NACL_RENDERER_JSON_MANIFEST_H_ 6 #define COMPONENTS_NACL_RENDERER_JSON_MANIFEST_H_ 7 8 #include <memory> 9 #include <set> 10 #include <string> 11 #include <utility> 12 13 #include "base/values.h" 14 #include "components/nacl/renderer/ppb_nacl_private.h" 15 16 namespace nacl { 17 class JsonManifest; 18 struct NaClResourcePrefetchRequest; 19 20 class JsonManifest { 21 public: 22 struct ErrorInfo { 23 PP_NaClError error; 24 std::string string; 25 }; 26 27 JsonManifest(const std::string& manifest_base_url, 28 const std::string& sandbox_isa, 29 bool pnacl_debug); 30 ~JsonManifest(); 31 32 // Initialize the manifest object for use by later lookups. Returns 33 // true if the manifest parses correctly and matches the schema. 34 bool Init(const std::string& json_manifest, ErrorInfo* error_info); 35 36 // Gets the full program URL for the current sandbox ISA from the 37 // manifest file. 38 bool GetProgramURL(std::string* full_url, 39 PP_PNaClOptions* pnacl_options, 40 ErrorInfo* error_info) const; 41 42 // Gets all the keys and their URLs in the "files" section that are 43 // prefetchable. 44 void GetPrefetchableFiles( 45 std::vector<NaClResourcePrefetchRequest>* out_files) const; 46 47 // Resolves a key from the "files" section to a fully resolved URL, 48 // i.e., relative URL values are fully expanded relative to the 49 // manifest's URL (via ResolveURL). 50 // If there was an error, details are reported via error_info. 51 bool ResolveKey(const std::string& key, 52 std::string* full_url, 53 PP_PNaClOptions* pnacl_options) const; 54 55 private: 56 bool MatchesSchema(ErrorInfo* error_info); 57 bool GetKeyUrl(const base::Value::Dict& dictionary, 58 const std::string& key, 59 std::string* full_url, 60 PP_PNaClOptions* pnacl_options) const; 61 bool GetURLFromISADictionary(const base::Value::Dict& parent_dictionary, 62 const std::string& parent_key, 63 std::string* url, 64 PP_PNaClOptions* pnacl_options, 65 ErrorInfo* error_info) const; 66 67 std::string manifest_base_url_; 68 std::string sandbox_isa_; 69 bool pnacl_debug_; 70 71 // The dictionary of manifest information parsed in Init(). 72 base::Value::Dict dictionary_; 73 }; 74 75 } // namespace nacl 76 77 #endif // COMPONENTS_NACL_RENDERER_JSON_MANIFEST_H_ 78