Update To 11.40.268.0
[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   void FetchRange(const std::string& range);
38
39   // Stop sending the stream to the client.
40   // Overrides the base Close so we can cancel our fetching the URL if
41   // it is still loading.
42   bool Close(NPReason reason) override;
43   WebPluginResourceClient* AsResourceClient() override;
44   void CancelRequest() override;
45
46   // WebPluginResourceClient methods
47   void WillSendRequest(const GURL& url, int http_status_code) override;
48   void DidReceiveResponse(const std::string& mime_type,
49                           const std::string& headers,
50                           uint32 expected_length,
51                           uint32 last_modified,
52                           bool request_is_seekable) override;
53   void DidReceiveData(const char* buffer, int length, int data_offset) override;
54   void DidFinishLoading(unsigned long resource_id) override;
55   void DidFail(unsigned long resource_id) override;
56   bool IsMultiByteResponseExpected() override;
57   int ResourceId() override;
58   void AddRangeRequestResourceId(unsigned long resource_id) override;
59
60  protected:
61   ~PluginStreamUrl() override;
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
73   // Ids of additional resources requested via range requests issued on
74   // seekable streams.
75   // This is used when we're loading resources through the renderer, i.e. not
76   // using plugin_url_fetcher_.
77   std::vector<unsigned long> range_requests_;
78   // This is used when we're using plugin_url_fetcher_.
79   std::vector<PluginURLFetcher*> range_request_fetchers_;
80
81   // If the plugin participates in HTTP URL redirect handling then this member
82   // holds the url being redirected to while we wait for the plugin to make a
83   // decision on whether to allow or deny the redirect.
84   std::string pending_redirect_url_;
85
86   scoped_ptr<PluginURLFetcher> plugin_url_fetcher_;
87
88   DISALLOW_COPY_AND_ASSIGN(PluginStreamUrl);
89 };
90
91 }  // namespace content
92
93 #endif // CONTENT_CHILD_NPAPI_PLUGIN_STREAM_URL_H_