Home | History | Annotate | Download | only in renderer
      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.
      4 
      5 #include <string>
      6 
      7 #include "base/callback.h"
      8 #include "base/memory/scoped_ptr.h"
      9 #include "ppapi/c/private/ppb_nacl_private.h"
     10 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h"
     11 
     12 namespace blink {
     13 struct WebURLError;
     14 class WebURLLoader;
     15 class WebURLResponse;
     16 }
     17 
     18 namespace nacl {
     19 
     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 {
     23  public:
     24   typedef base::Callback<void(PP_NaClError, const std::string&)> Callback;
     25 
     26   // This is a pretty arbitrary limit on the byte size of the NaCl manifest
     27   // file.
     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;
     31 
     32   ManifestDownloader(scoped_ptr<blink::WebURLLoader> url_loader,
     33                      bool is_installed,
     34                      Callback cb);
     35   virtual ~ManifestDownloader();
     36 
     37   void Load(const blink::WebURLRequest& request);
     38 
     39  private:
     40   // WebURLLoaderClient implementation.
     41   virtual void didReceiveResponse(blink::WebURLLoader* loader,
     42                                   const blink::WebURLResponse& response);
     43   virtual void didReceiveData(blink::WebURLLoader* loader,
     44                               const char* data,
     45                               int data_length,
     46                               int encoded_data_length);
     47   virtual void didFinishLoading(blink::WebURLLoader* loader,
     48                                 double finish_time,
     49                                 int64_t total_encoded_data_length);
     50   virtual void didFail(blink::WebURLLoader* loader,
     51                        const blink::WebURLError& error);
     52 
     53   scoped_ptr<blink::WebURLLoader> url_loader_;
     54   bool is_installed_;
     55   Callback cb_;
     56   std::string buffer_;
     57   int status_code_;
     58   PP_NaClError pp_nacl_error_;
     59 };
     60 
     61 }  // namespace nacl
     62