OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <string> | 5 #include <string> |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "ppapi/c/private/ppb_nacl_private.h" | 8 #include "ppapi/c/private/ppb_nacl_private.h" |
9 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h" | 9 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h" |
10 | 10 |
11 namespace blink { | 11 namespace blink { |
12 struct WebURLError; | 12 struct WebURLError; |
13 class WebURLLoader; | 13 class WebURLLoader; |
14 class WebURLResponse; | 14 class WebURLResponse; |
15 } | 15 } |
16 | 16 |
17 namespace nacl { | 17 namespace nacl { |
18 | 18 |
19 // Downloads a NaCl manifest (.nmf) and returns the contents of the file to | 19 // Downloads a NaCl manifest (.nmf) and returns the contents of the file to |
20 // caller through a callback. | 20 // caller through a callback. |
21 class ManifestDownloader : public blink::WebURLLoaderClient { | 21 class ManifestDownloader : public blink::WebURLLoaderClient { |
22 public: | 22 public: |
23 typedef base::Callback<void(PP_NaClError, const std::string&)> | 23 typedef base::Callback<void(PP_NaClError, const std::string&)> |
24 ManifestDownloaderCallback; | 24 ManifestDownloaderCallback; |
25 | 25 |
26 ManifestDownloader(bool is_installed, ManifestDownloaderCallback cb); | 26 ManifestDownloader(bool is_installed, ManifestDownloaderCallback cb); |
27 virtual ~ManifestDownloader(); | 27 virtual ~ManifestDownloader(); |
28 | 28 |
| 29 // This is a pretty arbitrary limit on the byte size of the NaCl manifest |
| 30 // file. |
| 31 // Note that the resulting string object has to have at least one byte extra |
| 32 // for the null termination character. |
| 33 static const size_t kNaClManifestMaxFileBytes = 1024 * 1024; |
| 34 |
29 private: | 35 private: |
30 // WebURLLoaderClient implementation. | 36 // WebURLLoaderClient implementation. |
31 virtual void didReceiveResponse(blink::WebURLLoader* loader, | 37 virtual void didReceiveResponse(blink::WebURLLoader* loader, |
32 const blink::WebURLResponse& response); | 38 const blink::WebURLResponse& response); |
33 virtual void didReceiveData(blink::WebURLLoader* loader, | 39 virtual void didReceiveData(blink::WebURLLoader* loader, |
34 const char* data, | 40 const char* data, |
35 int data_length, | 41 int data_length, |
36 int encoded_data_length); | 42 int encoded_data_length); |
37 virtual void didFinishLoading(blink::WebURLLoader* loader, | 43 virtual void didFinishLoading(blink::WebURLLoader* loader, |
38 double finish_time, | 44 double finish_time, |
39 int64_t total_encoded_data_length); | 45 int64_t total_encoded_data_length); |
40 virtual void didFail(blink::WebURLLoader* loader, | 46 virtual void didFail(blink::WebURLLoader* loader, |
41 const blink::WebURLError& error); | 47 const blink::WebURLError& error); |
42 | 48 |
43 bool is_installed_; | 49 bool is_installed_; |
44 ManifestDownloaderCallback cb_; | 50 ManifestDownloaderCallback cb_; |
45 std::string buffer_; | 51 std::string buffer_; |
46 int status_code_; | 52 int status_code_; |
47 PP_NaClError pp_nacl_error_; | 53 PP_NaClError pp_nacl_error_; |
48 }; | 54 }; |
49 | 55 |
50 } // namespace nacl | 56 } // namespace nacl |
OLD | NEW |