| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_BROWSER_LOADER_STREAM_RESOURCE_HANDLER_H_ | 5 #ifndef CONTENT_BROWSER_LOADER_STREAM_RESOURCE_HANDLER_H_ |
| 6 #define CONTENT_BROWSER_LOADER_STREAM_RESOURCE_HANDLER_H_ | 6 #define CONTENT_BROWSER_LOADER_STREAM_RESOURCE_HANDLER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "content/browser/loader/resource_handler.h" | 12 #include "content/browser/loader/resource_handler.h" |
| 13 #include "content/browser/loader/stream_writer.h" | 13 #include "content/browser/loader/stream_writer.h" |
| 14 | 14 |
| 15 namespace net { | 15 namespace net { |
| 16 class URLRequest; | 16 class URLRequest; |
| 17 } // namespace net | 17 } // namespace net |
| 18 | 18 |
| 19 namespace content { | 19 namespace content { |
| 20 | 20 |
| 21 class ResourceController; |
| 21 class StreamRegistry; | 22 class StreamRegistry; |
| 22 | 23 |
| 23 // Redirect this resource to a stream. | 24 // Redirect this resource to a stream. |
| 24 class StreamResourceHandler : public ResourceHandler { | 25 class StreamResourceHandler : public ResourceHandler { |
| 25 public: | 26 public: |
| 26 // |origin| will be used to construct the URL for the Stream. See | 27 // |origin| will be used to construct the URL for the Stream. See |
| 27 // WebCore::BlobURL and and WebCore::SecurityOrigin in Blink to understand | 28 // WebCore::BlobURL and and WebCore::SecurityOrigin in Blink to understand |
| 28 // how origin check is done on resource loading. | 29 // how origin check is done on resource loading. |
| 29 StreamResourceHandler(net::URLRequest* request, | 30 StreamResourceHandler(net::URLRequest* request, |
| 30 StreamRegistry* registry, | 31 StreamRegistry* registry, |
| 31 const GURL& origin); | 32 const GURL& origin); |
| 32 ~StreamResourceHandler() override; | 33 ~StreamResourceHandler() override; |
| 33 | 34 |
| 34 void SetController(ResourceController* controller) override; | 35 // Not needed, as this event handler ought to be the final resource. |
| 36 void OnRequestRedirected( |
| 37 const net::RedirectInfo& redirect_info, |
| 38 ResourceResponse* resp, |
| 39 std::unique_ptr<ResourceController> controller) override; |
| 35 | 40 |
| 36 // Not needed, as this event handler ought to be the final resource. | 41 void OnResponseStarted( |
| 37 bool OnRequestRedirected(const net::RedirectInfo& redirect_info, | 42 ResourceResponse* resp, |
| 38 ResourceResponse* resp, | 43 std::unique_ptr<ResourceController> controller) override; |
| 39 bool* defer) override; | |
| 40 | 44 |
| 41 bool OnResponseStarted(ResourceResponse* resp, bool* defer) override; | 45 void OnWillStart(const GURL& url, |
| 42 | 46 std::unique_ptr<ResourceController> controller) override; |
| 43 bool OnWillStart(const GURL& url, bool* defer) override; | |
| 44 | 47 |
| 45 // Create a new buffer to store received data. | 48 // Create a new buffer to store received data. |
| 46 bool OnWillRead(scoped_refptr<net::IOBuffer>* buf, | 49 bool OnWillRead(scoped_refptr<net::IOBuffer>* buf, |
| 47 int* buf_size, | 50 int* buf_size, |
| 48 int min_size) override; | 51 int min_size) override; |
| 49 | 52 |
| 50 // A read was completed, forward the data to the Stream. | 53 // A read was completed, forward the data to the Stream. |
| 51 bool OnReadCompleted(int bytes_read, bool* defer) override; | 54 void OnReadCompleted(int bytes_read, |
| 55 std::unique_ptr<ResourceController> controller) override; |
| 52 | 56 |
| 53 void OnResponseCompleted(const net::URLRequestStatus& status, | 57 void OnResponseCompleted( |
| 54 bool* defer) override; | 58 const net::URLRequestStatus& status, |
| 59 std::unique_ptr<ResourceController> controller) override; |
| 55 | 60 |
| 56 void OnDataDownloaded(int bytes_downloaded) override; | 61 void OnDataDownloaded(int bytes_downloaded) override; |
| 57 | 62 |
| 58 Stream* stream() { return writer_.stream(); } | 63 Stream* stream() { return writer_.stream(); } |
| 59 | 64 |
| 60 private: | 65 private: |
| 61 StreamWriter writer_; | 66 StreamWriter writer_; |
| 62 | 67 |
| 63 DISALLOW_COPY_AND_ASSIGN(StreamResourceHandler); | 68 DISALLOW_COPY_AND_ASSIGN(StreamResourceHandler); |
| 64 }; | 69 }; |
| 65 | 70 |
| 66 } // namespace content | 71 } // namespace content |
| 67 | 72 |
| 68 #endif // CONTENT_BROWSER_LOADER_STREAM_RESOURCE_HANDLER_H_ | 73 #endif // CONTENT_BROWSER_LOADER_STREAM_RESOURCE_HANDLER_H_ |
| OLD | NEW |