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.
5 #ifndef CONTENT_CHILD_NPAPI_PLUGIN_STREAM_URL_H_
6 #define CONTENT_CHILD_NPAPI_PLUGIN_STREAM_URL_H_
10 #include "base/memory/scoped_ptr.h"
11 #include "content/child/npapi/plugin_stream.h"
12 #include "content/child/npapi/webplugin_resource_client.h"
17 class PluginURLFetcher;
19 // A NPAPI Stream based on a URL.
20 class PluginStreamUrl : public PluginStream,
21 public WebPluginResourceClient {
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,
29 PluginInstance *instance,
33 void SetPluginURLFetcher(PluginURLFetcher* fetcher);
35 void URLRedirectResponse(bool allow);
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;
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,
50 bool request_is_seekable) OVERRIDE;
51 virtual void DidReceiveData(const char* buffer,
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;
61 virtual ~PluginStreamUrl();
64 void SetDeferLoading(bool value);
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);
72 // Ids of additional resources requested via range requests issued on
74 std::vector<unsigned long> range_requests_;
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_;
81 scoped_ptr<PluginURLFetcher> plugin_url_fetcher_;
83 DISALLOW_COPY_AND_ASSIGN(PluginStreamUrl);
86 } // namespace content
88 #endif // CONTENT_CHILD_NPAPI_PLUGIN_STREAM_URL_H_