| OLD | NEW |
| (Empty) |
| 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_BROWSER_RENDERER_HOST_BUFFERED_RESOURCE_HANDLER_H_ | |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_BUFFERED_RESOURCE_HANDLER_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/memory/weak_ptr.h" | |
| 12 #include "content/browser/renderer_host/layered_resource_handler.h" | |
| 13 #include "content/public/browser/resource_controller.h" | |
| 14 | |
| 15 namespace net { | |
| 16 class URLRequest; | |
| 17 } | |
| 18 | |
| 19 namespace webkit { | |
| 20 struct WebPluginInfo; | |
| 21 } | |
| 22 | |
| 23 namespace content { | |
| 24 class ResourceDispatcherHostImpl; | |
| 25 | |
| 26 // Used to buffer a request until enough data has been received. | |
| 27 class BufferedResourceHandler | |
| 28 : public LayeredResourceHandler, | |
| 29 public ResourceController { | |
| 30 public: | |
| 31 BufferedResourceHandler(scoped_ptr<ResourceHandler> next_handler, | |
| 32 ResourceDispatcherHostImpl* host, | |
| 33 net::URLRequest* request); | |
| 34 virtual ~BufferedResourceHandler(); | |
| 35 | |
| 36 private: | |
| 37 // ResourceHandler implementation: | |
| 38 virtual void SetController(ResourceController* controller) OVERRIDE; | |
| 39 virtual bool OnResponseStarted(int request_id, | |
| 40 ResourceResponse* response, | |
| 41 bool* defer) OVERRIDE; | |
| 42 virtual bool OnWillRead(int request_id, | |
| 43 net::IOBuffer** buf, | |
| 44 int* buf_size, | |
| 45 int min_size) OVERRIDE; | |
| 46 virtual bool OnReadCompleted(int request_id, int bytes_read, | |
| 47 bool* defer) OVERRIDE; | |
| 48 virtual bool OnResponseCompleted(int request_id, | |
| 49 const net::URLRequestStatus& status, | |
| 50 const std::string& security_info) OVERRIDE; | |
| 51 | |
| 52 // ResourceController implementation: | |
| 53 virtual void Resume() OVERRIDE; | |
| 54 virtual void Cancel() OVERRIDE; | |
| 55 virtual void CancelAndIgnore() OVERRIDE; | |
| 56 virtual void CancelWithError(int error_code) OVERRIDE; | |
| 57 | |
| 58 bool ProcessResponse(bool* defer); | |
| 59 | |
| 60 bool ShouldSniffContent(); | |
| 61 bool DetermineMimeType(); | |
| 62 bool SelectNextHandler(bool* defer); | |
| 63 bool UseAlternateNextHandler(scoped_ptr<ResourceHandler> handler); | |
| 64 | |
| 65 bool ReplayReadCompleted(bool* defer); | |
| 66 void CallReplayReadCompleted(); | |
| 67 | |
| 68 bool MustDownload(); | |
| 69 bool HasSupportingPlugin(bool* is_stale); | |
| 70 | |
| 71 // Copies data from |read_buffer_| to |next_handler_|. | |
| 72 bool CopyReadBufferToNextHandler(int request_id); | |
| 73 | |
| 74 // Called on the IO thread once the list of plugins has been loaded. | |
| 75 void OnPluginsLoaded(const std::vector<webkit::WebPluginInfo>& plugins); | |
| 76 | |
| 77 enum State { | |
| 78 STATE_STARTING, | |
| 79 | |
| 80 // In this state, we are filling read_buffer_ with data for the purpose | |
| 81 // of sniffing the mime type of the response. | |
| 82 STATE_BUFFERING, | |
| 83 | |
| 84 // In this state, we are select an appropriate downstream ResourceHandler | |
| 85 // based on the mime type of the response. We are also potentially waiting | |
| 86 // for plugins to load so that we can determine if a plugin is available to | |
| 87 // handle the mime type. | |
| 88 STATE_PROCESSING, | |
| 89 | |
| 90 // In this state, we are replaying buffered events (OnResponseStarted and | |
| 91 // OnReadCompleted) to the downstream ResourceHandler. | |
| 92 STATE_REPLAYING, | |
| 93 | |
| 94 // In this state, we are just a blind pass-through ResourceHandler. | |
| 95 STATE_STREAMING | |
| 96 }; | |
| 97 State state_; | |
| 98 | |
| 99 scoped_refptr<ResourceResponse> response_; | |
| 100 ResourceDispatcherHostImpl* host_; | |
| 101 net::URLRequest* request_; | |
| 102 scoped_refptr<net::IOBuffer> read_buffer_; | |
| 103 int read_buffer_size_; | |
| 104 int bytes_read_; | |
| 105 | |
| 106 bool must_download_; | |
| 107 bool must_download_is_set_; | |
| 108 | |
| 109 base::WeakPtrFactory<BufferedResourceHandler> weak_ptr_factory_; | |
| 110 | |
| 111 DISALLOW_COPY_AND_ASSIGN(BufferedResourceHandler); | |
| 112 }; | |
| 113 | |
| 114 } // namespace content | |
| 115 | |
| 116 #endif // CONTENT_BROWSER_RENDERER_HOST_BUFFERED_RESOURCE_HANDLER_H_ | |
| OLD | NEW |