- add sources.
[platform/framework/web/crosswalk.git] / src / content / child / npapi / plugin_stream_url.h
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 "base/memory/scoped_ptr.h"
11 #include "content/child/npapi/plugin_stream.h"
12 #include "content/child/npapi/webplugin_resource_client.h"
13 #include "url/gurl.h"
14
15 namespace content {
16 class PluginInstance;
17 class PluginURLFetcher;
18
19 // A NPAPI Stream based on a URL.
20 class PluginStreamUrl : public PluginStream,
21                         public WebPluginResourceClient {
22  public:
23   // Create a new stream for sending to the plugin by fetching
24   // a URL. If notifyNeeded is set, then the plugin will be notified
25   // when the stream has been fully sent to the plugin.  Initialize
26   // must be called before the object is used.
27   PluginStreamUrl(unsigned long resource_id,
28                   const GURL &url,
29                   PluginInstance *instance,
30                   bool notify_needed,
31                   void *notify_data);
32
33   void SetPluginURLFetcher(PluginURLFetcher* fetcher);
34
35   void URLRedirectResponse(bool allow);
36
37   // Stop sending the stream to the client.
38   // Overrides the base Close so we can cancel our fetching the URL if
39   // it is still loading.
40   virtual bool Close(NPReason reason) OVERRIDE;
41   virtual WebPluginResourceClient* AsResourceClient() OVERRIDE;
42   virtual void CancelRequest() OVERRIDE;
43
44   // WebPluginResourceClient methods
45   virtual void WillSendRequest(const GURL& url, int http_status_code) OVERRIDE;
46   virtual void DidReceiveResponse(const std::string& mime_type,
47                                   const std::string& headers,
48                                   uint32 expected_length,
49                                   uint32 last_modified,
50                                   bool request_is_seekable) OVERRIDE;
51   virtual void DidReceiveData(const char* buffer,
52                               int length,
53                               int data_offset) OVERRIDE;
54   virtual void DidFinishLoading(unsigned long resource_id) OVERRIDE;
55   virtual void DidFail(unsigned long resource_id) OVERRIDE;
56   virtual bool IsMultiByteResponseExpected() OVERRIDE;
57   virtual int ResourceId() OVERRIDE;
58   virtual void AddRangeRequestResourceId(unsigned long resource_id) OVERRIDE;
59
60  protected:
61   virtual ~PluginStreamUrl();
62
63  private:
64   void SetDeferLoading(bool value);
65
66   // In case of a redirect, this can be called to update the url.  But it must
67   // be called before Open().
68   void UpdateUrl(const char* url);
69
70   GURL url_;
71   unsigned long id_;
72   // Ids of additional resources requested via range requests issued on
73   // seekable streams.
74   std::vector<unsigned long> range_requests_;
75
76   // If the plugin participates in HTTP URL redirect handling then this member
77   // holds the url being redirected to while we wait for the plugin to make a
78   // decision on whether to allow or deny the redirect.
79   std::string pending_redirect_url_;
80
81   scoped_ptr<PluginURLFetcher> plugin_url_fetcher_;
82
83   DISALLOW_COPY_AND_ASSIGN(PluginStreamUrl);
84 };
85
86 }  // namespace content
87
88 #endif // CONTENT_CHILD_NPAPI_PLUGIN_STREAM_URL_H_