Home | History | Annotate | Download | only in npapi
      1 // Copyright (c) 2012 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 #ifndef CONTENT_CHILD_NPAPI_PLUGIN_STREAM_URL_H_
      6 #define CONTENT_CHILD_NPAPI_PLUGIN_STREAM_URL_H_
      7 
      8 #include <vector>
      9 
     10 #include "content/child/npapi/plugin_stream.h"
     11 #include "content/child/npapi/webplugin.h"
     12 #include "url/gurl.h"
     13 
     14 namespace content {
     15 
     16 class PluginInstance;
     17 
     18 // A NPAPI Stream based on a URL.
     19 class PluginStreamUrl : public PluginStream,
     20                         public WebPluginResourceClient {
     21  public:
     22   // Create a new stream for sending to the plugin by fetching
     23   // a URL. If notifyNeeded is set, then the plugin will be notified
     24   // when the stream has been fully sent to the plugin.  Initialize
     25   // must be called before the object is used.
     26   PluginStreamUrl(unsigned long resource_id,
     27                   const GURL &url,
     28                   PluginInstance *instance,
     29                   bool notify_needed,
     30                   void *notify_data);
     31 
     32   // Stop sending the stream to the client.
     33   // Overrides the base Close so we can cancel our fetching the URL if
     34   // it is still loading.
     35   virtual bool Close(NPReason reason) OVERRIDE;
     36   virtual WebPluginResourceClient* AsResourceClient() OVERRIDE;
     37   virtual void CancelRequest() OVERRIDE;
     38 
     39   // WebPluginResourceClient methods
     40   virtual void WillSendRequest(const GURL& url, int http_status_code) OVERRIDE;
     41   virtual void DidReceiveResponse(const std::string& mime_type,
     42                                   const std::string& headers,
     43                                   uint32 expected_length,
     44                                   uint32 last_modified,
     45                                   bool request_is_seekable) OVERRIDE;
     46   virtual void DidReceiveData(const char* buffer,
     47                               int length,
     48                               int data_offset) OVERRIDE;
     49   virtual void DidFinishLoading(unsigned long resource_id) OVERRIDE;
     50   virtual void DidFail(unsigned long resource_id) OVERRIDE;
     51   virtual bool IsMultiByteResponseExpected() OVERRIDE;
     52   virtual int ResourceId() OVERRIDE;
     53   virtual void AddRangeRequestResourceId(unsigned long resource_id) OVERRIDE;
     54 
     55  protected:
     56   virtual ~PluginStreamUrl();
     57 
     58  private:
     59   void SetDeferLoading(bool value);
     60 
     61   GURL url_;
     62   unsigned long id_;
     63   // Ids of additional resources requested via range requests issued on
     64   // seekable streams.
     65   std::vector<unsigned long> range_requests_;
     66 
     67   DISALLOW_COPY_AND_ASSIGN(PluginStreamUrl);
     68 };
     69 
     70 }  // namespace content
     71 
     72 #endif // CONTENT_CHILD_NPAPI_PLUGIN_STREAM_URL_H_
     73