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(ResourceResponse
* response
,
37 bool* defer
) OVERRIDE
;
38 virtual bool OnWillRead(scoped_refptr
<net::IOBuffer
>* buf
,
40 int min_size
) OVERRIDE
;
41 virtual bool OnReadCompleted(int bytes_read
, bool* defer
) OVERRIDE
;
42 virtual void OnResponseCompleted(const net::URLRequestStatus
& status
,
43 const std::string
& security_info
,
44 bool* defer
) OVERRIDE
;
46 // ResourceController implementation:
47 virtual void Resume() OVERRIDE
;
48 virtual void Cancel() OVERRIDE
;
49 virtual void CancelAndIgnore() OVERRIDE
;
50 virtual void CancelWithError(int error_code
) OVERRIDE
;
52 bool ProcessResponse(bool* defer
);
54 bool ShouldSniffContent();
55 bool DetermineMimeType();
56 bool SelectNextHandler(bool* defer
);
57 bool UseAlternateNextHandler(scoped_ptr
<ResourceHandler
> handler
,
58 const std::string
& payload_for_old_handler
);
60 bool ReplayReadCompleted(bool* defer
);
61 void CallReplayReadCompleted();
64 bool HasSupportingPlugin(bool* is_stale
);
66 // Copies data from |read_buffer_| to |next_handler_|.
67 bool CopyReadBufferToNextHandler();
69 // Called on the IO thread once the list of plugins has been loaded.
70 void OnPluginsLoaded(const std::vector
<WebPluginInfo
>& plugins
);
75 // In this state, we are filling read_buffer_ with data for the purpose
76 // of sniffing the mime type of the response.
79 // In this state, we are select an appropriate downstream ResourceHandler
80 // based on the mime type of the response. We are also potentially waiting
81 // for plugins to load so that we can determine if a plugin is available to
82 // handle the mime type.
85 // In this state, we are replaying buffered events (OnResponseStarted and
86 // OnReadCompleted) to the downstream ResourceHandler.
89 // In this state, we are just a blind pass-through ResourceHandler.
94 scoped_refptr
<ResourceResponse
> response_
;
95 ResourceDispatcherHostImpl
* host_
;
96 scoped_refptr
<net::IOBuffer
> read_buffer_
;
97 int read_buffer_size_
;
101 bool must_download_is_set_
;
103 base::WeakPtrFactory
<BufferedResourceHandler
> weak_ptr_factory_
;
105 DISALLOW_COPY_AND_ASSIGN(BufferedResourceHandler
);
108 } // namespace content
110 #endif // CONTENT_BROWSER_LOADER_BUFFERED_RESOURCE_HANDLER_H_