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
);
42 // WebURLLoaderClient implementation.
43 virtual void didReceiveResponse(blink::WebURLLoader
* loader
,
44 const blink::WebURLResponse
& response
);
45 virtual void didReceiveData(blink::WebURLLoader
* loader
,
48 int encoded_data_length
);
49 virtual void didFinishLoading(blink::WebURLLoader
* loader
,
51 int64_t total_encoded_data_length
);
52 virtual void didFail(blink::WebURLLoader
* loader
,
53 const blink::WebURLError
& error
);
55 scoped_ptr
<blink::WebURLLoader
> url_loader_
;
60 PP_NaClError pp_nacl_error_
;