1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 #include "base/callback.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "components/nacl/renderer/ppb_nacl_private.h"
10 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h"
20 // Downloads a NaCl manifest (.nmf) and returns the contents of the file to
21 // caller through a callback.
22 class ManifestDownloader
: public blink::WebURLLoaderClient
{
24 typedef base::Callback
<void(PP_NaClError
, const std::string
&)> Callback
;
26 // This is a pretty arbitrary limit on the byte size of the NaCl manifest
28 // Note that the resulting string object has to have at least one byte extra
29 // for the null termination character.
30 static const size_t kNaClManifestMaxFileBytes
= 1024 * 1024;
32 ManifestDownloader(scoped_ptr
<blink::WebURLLoader
> url_loader
,
35 virtual ~ManifestDownloader();
37 void Load(const blink::WebURLRequest
& request
);
40 // WebURLLoaderClient implementation.
41 virtual void didReceiveResponse(blink::WebURLLoader
* loader
,
42 const blink::WebURLResponse
& response
);
43 virtual void didReceiveData(blink::WebURLLoader
* loader
,
46 int encoded_data_length
);
47 virtual void didFinishLoading(blink::WebURLLoader
* loader
,
49 int64_t total_encoded_data_length
);
50 virtual void didFail(blink::WebURLLoader
* loader
,
51 const blink::WebURLError
& error
);
53 scoped_ptr
<blink::WebURLLoader
> url_loader_
;
58 PP_NaClError pp_nacl_error_
;