1 // Copyright (c) 2013 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_BROWSER_LOADER_STREAM_RESOURCE_HANDLER_H_
6 #define CONTENT_BROWSER_LOADER_STREAM_RESOURCE_HANDLER_H_
8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "content/browser/loader/resource_handler.h"
11 #include "content/browser/streams/stream_write_observer.h"
22 // Redirect this resource to a stream.
23 class StreamResourceHandler : public StreamWriteObserver,
24 public ResourceHandler {
26 // |origin| will be used to construct the URL for the Stream. See
27 // WebCore::BlobURL and and WebCore::SecurityOrigin in Blink to understand
28 // how origin check is done on resource loading.
29 StreamResourceHandler(net::URLRequest* request,
30 StreamRegistry* registry,
32 virtual ~StreamResourceHandler();
34 virtual bool OnUploadProgress(uint64 position, uint64 size) OVERRIDE;
36 // Not needed, as this event handler ought to be the final resource.
37 virtual bool OnRequestRedirected(const net::RedirectInfo& redirect_info,
38 ResourceResponse* resp,
39 bool* defer) OVERRIDE;
41 virtual bool OnResponseStarted(ResourceResponse* resp,
42 bool* defer) OVERRIDE;
44 virtual bool OnWillStart(const GURL& url, bool* defer) OVERRIDE;
46 virtual bool OnBeforeNetworkStart(const GURL& url, bool* defer) OVERRIDE;
48 // Create a new buffer to store received data.
49 virtual bool OnWillRead(scoped_refptr<net::IOBuffer>* buf,
51 int min_size) OVERRIDE;
53 // A read was completed, forward the data to the Stream.
54 virtual bool OnReadCompleted(int bytes_read, bool* defer) OVERRIDE;
56 virtual void OnResponseCompleted(const net::URLRequestStatus& status,
57 const std::string& sec_info,
58 bool* defer) OVERRIDE;
60 virtual void OnDataDownloaded(int bytes_downloaded) OVERRIDE;
62 Stream* stream() { return stream_.get(); }
65 virtual void OnSpaceAvailable(Stream* stream) OVERRIDE;
66 virtual void OnClose(Stream* stream) OVERRIDE;
68 scoped_refptr<Stream> stream_;
69 scoped_refptr<net::IOBuffer> read_buffer_;
70 DISALLOW_COPY_AND_ASSIGN(StreamResourceHandler);
73 } // namespace content
75 #endif // CONTENT_BROWSER_LOADER_STREAM_RESOURCE_HANDLER_H_