OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2010 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 CHROME_BROWSER_PRERENDER_PRERENDER_RESOURCE_HANDLER_H_ | |
6 #define CHROME_BROWSER_PRERENDER_PRERENDER_RESOURCE_HANDLER_H_ | |
7 #pragma once | |
8 | |
9 #include <string> | |
10 | |
11 #include "base/callback.h" | |
12 #include "chrome/browser/prerender/prerender_manager.h" | |
13 #include "chrome/browser/renderer_host/resource_handler.h" | |
14 | |
15 namespace net { | |
16 class URLRequest; | |
17 } | |
18 | |
willchan no longer on Chromium
2010/12/17 21:45:17
I think we should start enforcing namespace chrome
cbentzel
2010/12/19 00:40:56
The chromium-dev email led to me believe this woul
| |
19 // The PrerenderResourceHandler initiates prerendering of web pages | |
20 // under the following conditions: | |
21 // - The profile which initiated the request allows prerendering. | |
22 // - The initial request is a GET for a PREFETCH resource type. | |
23 // - The final URL (after redirects) has a scheme of http or https. | |
24 // - The response status code is a 200. | |
25 // - The MIME type of the response (sniffed or explicit) is text/html. | |
26 class PrerenderResourceHandler : public ResourceHandler { | |
27 public: | |
28 PrerenderResourceHandler(ResourceHandler* next_handler, | |
29 PrerenderManager* prerender_manager); | |
30 | |
31 // Determines if a request could be used for prerendering. Whether | |
32 // prerendering actually happens is contingent on the server response. | |
33 static bool CouldPrerender(const net::URLRequest* request); | |
willchan no longer on Chromium
2010/12/17 21:45:17
My preference is to use const reference rather tha
cbentzel
2010/12/19 00:40:56
Done.
| |
34 | |
35 // OnResponseStarted will ask the |prerender_maanger| to start | |
36 // prerendering the requested resource if it is of an appropriate | |
37 // content type. The next handler is still invoked. | |
38 virtual bool OnResponseStarted(int request_id, | |
39 ResourceResponse* response); | |
40 | |
41 // The following methods simply delegate to the next_handler. | |
42 virtual bool OnUploadProgress(int request_id, | |
43 uint64 position, | |
44 uint64 size); | |
45 virtual bool OnRequestRedirected(int request_id, const GURL& url, | |
46 ResourceResponse* response, | |
47 bool* defer); | |
48 virtual bool OnWillStart(int request_id, const GURL& url, bool* defer); | |
49 | |
50 virtual bool OnWillRead(int request_id, | |
51 net::IOBuffer** buf, | |
52 int* buf_size, | |
53 int min_size); | |
54 | |
55 virtual bool OnReadCompleted(int request_id, int* bytes_read); | |
56 | |
57 virtual bool OnResponseCompleted(int request_id, | |
58 const URLRequestStatus& status, | |
59 const std::string& security_info); | |
60 | |
61 virtual void OnRequestClosed(); | |
62 | |
63 protected: | |
64 virtual ~PrerenderResourceHandler(); | |
65 | |
66 private: | |
67 friend class PrerenderResourceHandlerTest; | |
68 typedef Callback1<const GURL&>::Type PrerenderCallback; | |
69 | |
70 PrerenderResourceHandler(ResourceHandler* next_handler, | |
71 PrerenderCallback* callback); | |
72 | |
73 void RunCallbackFromUIThread(const GURL& url); | |
74 void StartPrerender(const GURL& url); | |
75 static bool ShouldPrerender(const GURL& url, | |
76 const ResourceResponse* response); | |
77 | |
78 GURL url_; | |
79 scoped_refptr<ResourceHandler> next_handler_; | |
80 scoped_refptr<PrerenderManager> prerender_manager_; | |
81 scoped_ptr<PrerenderCallback> prerender_callback_; | |
82 | |
83 DISALLOW_COPY_AND_ASSIGN(PrerenderResourceHandler); | |
84 }; | |
85 | |
86 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_RESOURCE_HANDLER_H_ | |
OLD | NEW |