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_MANIFEST_DOWNLOADER_H_ 6 #define COMPONENTS_NACL_RENDERER_MANIFEST_DOWNLOADER_H_ 7 8 #include <stddef.h> 9 #include <stdint.h> 10 11 #include <memory> 12 #include <string> 13 14 #include "base/functional/callback.h" 15 #include "components/nacl/renderer/ppb_nacl_private.h" 16 #include "third_party/blink/public/web/web_associated_url_loader_client.h" 17 18 namespace blink { 19 class WebAssociatedURLLoader; 20 struct WebURLError; 21 class WebURLRequest; 22 class WebURLResponse; 23 } 24 25 namespace nacl { 26 27 // Downloads a NaCl manifest (.nmf) and returns the contents of the file to 28 // caller through a callback. 29 class ManifestDownloader : public blink::WebAssociatedURLLoaderClient { 30 public: 31 typedef base::OnceCallback<void(PP_NaClError, const std::string&)> Callback; 32 33 // This is a pretty arbitrary limit on the byte size of the NaCl manifest 34 // file. 35 // Note that the resulting string object has to have at least one byte extra 36 // for the null termination character. 37 static const size_t kNaClManifestMaxFileBytes = 1024 * 1024; 38 39 ManifestDownloader(std::unique_ptr<blink::WebAssociatedURLLoader> url_loader, 40 bool is_installed, 41 Callback cb); 42 ~ManifestDownloader() override; 43 44 void Load(const blink::WebURLRequest& request); 45 46 private: 47 void Close(); 48 49 // WebAssociatedURLLoaderClient implementation. 50 void DidReceiveResponse(const blink::WebURLResponse& response) override; 51 void DidReceiveData(const char* data, int data_length) override; 52 void DidFinishLoading() override; 53 void DidFail(const blink::WebURLError& error) override; 54 55 std::unique_ptr<blink::WebAssociatedURLLoader> url_loader_; 56 bool is_installed_; 57 Callback cb_; 58 std::string buffer_; 59 int status_code_; 60 PP_NaClError pp_nacl_error_; 61 }; 62 63 } // namespace nacl 64 65 #endif // COMPONENTS_NACL_RENDERER_MANIFEST_DOWNLOADER_H_ 66