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_BROWSER_LOADER_BUFFERED_RESOURCE_HANDLER_H_
6 #define CONTENT_BROWSER_LOADER_BUFFERED_RESOURCE_HANDLER_H_
11 #include "base/memory/weak_ptr.h"
12 #include "content/browser/loader/layered_resource_handler.h"
13 #include "content/public/browser/resource_controller.h"
20 class ResourceDispatcherHostImpl
;
23 // Used to buffer a request until enough data has been received.
24 class BufferedResourceHandler
25 : public LayeredResourceHandler
,
26 public ResourceController
{
28 BufferedResourceHandler(scoped_ptr
<ResourceHandler
> next_handler
,
29 ResourceDispatcherHostImpl
* host
,
30 net::URLRequest
* request
);
31 virtual ~BufferedResourceHandler();
34 // ResourceHandler implementation:
35 virtual void SetController(ResourceController
* controller
) OVERRIDE
;
36 virtual bool OnResponseStarted(int request_id
,
37 ResourceResponse
* response
,
38 bool* defer
) OVERRIDE
;
39 virtual bool OnWillRead(int request_id
,
40 scoped_refptr
<net::IOBuffer
>* buf
,
42 int min_size
) OVERRIDE
;
43 virtual bool OnReadCompleted(int request_id
, int bytes_read
,
44 bool* defer
) OVERRIDE
;
45 virtual void OnResponseCompleted(int request_id
,
46 const net::URLRequestStatus
& status
,
47 const std::string
& security_info
,
48 bool* defer
) OVERRIDE
;
50 // ResourceController implementation:
51 virtual void Resume() OVERRIDE
;
52 virtual void Cancel() OVERRIDE
;
53 virtual void CancelAndIgnore() OVERRIDE
;
54 virtual void CancelWithError(int error_code
) OVERRIDE
;
56 bool ProcessResponse(bool* defer
);
58 bool ShouldSniffContent();
59 bool DetermineMimeType();
60 bool SelectNextHandler(bool* defer
);
61 bool UseAlternateNextHandler(scoped_ptr
<ResourceHandler
> handler
);
63 bool ReplayReadCompleted(bool* defer
);
64 void CallReplayReadCompleted();
67 bool HasSupportingPlugin(bool* is_stale
);
69 // Copies data from |read_buffer_| to |next_handler_|.
70 bool CopyReadBufferToNextHandler(int request_id
);
72 // Called on the IO thread once the list of plugins has been loaded.
73 void OnPluginsLoaded(const std::vector
<WebPluginInfo
>& plugins
);
78 // In this state, we are filling read_buffer_ with data for the purpose
79 // of sniffing the mime type of the response.
82 // In this state, we are select an appropriate downstream ResourceHandler
83 // based on the mime type of the response. We are also potentially waiting
84 // for plugins to load so that we can determine if a plugin is available to
85 // handle the mime type.
88 // In this state, we are replaying buffered events (OnResponseStarted and
89 // OnReadCompleted) to the downstream ResourceHandler.
92 // In this state, we are just a blind pass-through ResourceHandler.
97 scoped_refptr
<ResourceResponse
> response_
;
98 ResourceDispatcherHostImpl
* host_
;
99 scoped_refptr
<net::IOBuffer
> read_buffer_
;
100 int read_buffer_size_
;
104 bool must_download_is_set_
;
106 base::WeakPtrFactory
<BufferedResourceHandler
> weak_ptr_factory_
;
108 DISALLOW_COPY_AND_ASSIGN(BufferedResourceHandler
);
111 } // namespace content
113 #endif // CONTENT_BROWSER_LOADER_BUFFERED_RESOURCE_HANDLER_H_