Index: chrome/browser/prerender/prerender_resource_handler.h |
diff --git a/chrome/browser/prerender/prerender_resource_handler.h b/chrome/browser/prerender/prerender_resource_handler.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ba875f61217e4fad0741f1db159953f43b959599 |
--- /dev/null |
+++ b/chrome/browser/prerender/prerender_resource_handler.h |
@@ -0,0 +1,86 @@ |
+// Copyright (c) 2010 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CHROME_BROWSER_PRERENDER_PRERENDER_RESOURCE_HANDLER_H_ |
+#define CHROME_BROWSER_PRERENDER_PRERENDER_RESOURCE_HANDLER_H_ |
+#pragma once |
+ |
+#include <string> |
+ |
+#include "base/callback.h" |
+#include "chrome/browser/prerender/prerender_manager.h" |
+#include "chrome/browser/renderer_host/resource_handler.h" |
+ |
+namespace net { |
+class URLRequest; |
+} |
+ |
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
|
+// The PrerenderResourceHandler initiates prerendering of web pages |
+// under the following conditions: |
+// - The profile which initiated the request allows prerendering. |
+// - The initial request is a GET for a PREFETCH resource type. |
+// - The final URL (after redirects) has a scheme of http or https. |
+// - The response status code is a 200. |
+// - The MIME type of the response (sniffed or explicit) is text/html. |
+class PrerenderResourceHandler : public ResourceHandler { |
+ public: |
+ PrerenderResourceHandler(ResourceHandler* next_handler, |
+ PrerenderManager* prerender_manager); |
+ |
+ // Determines if a request could be used for prerendering. Whether |
+ // prerendering actually happens is contingent on the server response. |
+ 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.
|
+ |
+ // OnResponseStarted will ask the |prerender_maanger| to start |
+ // prerendering the requested resource if it is of an appropriate |
+ // content type. The next handler is still invoked. |
+ virtual bool OnResponseStarted(int request_id, |
+ ResourceResponse* response); |
+ |
+ // The following methods simply delegate to the next_handler. |
+ virtual bool OnUploadProgress(int request_id, |
+ uint64 position, |
+ uint64 size); |
+ virtual bool OnRequestRedirected(int request_id, const GURL& url, |
+ ResourceResponse* response, |
+ bool* defer); |
+ virtual bool OnWillStart(int request_id, const GURL& url, bool* defer); |
+ |
+ virtual bool OnWillRead(int request_id, |
+ net::IOBuffer** buf, |
+ int* buf_size, |
+ int min_size); |
+ |
+ virtual bool OnReadCompleted(int request_id, int* bytes_read); |
+ |
+ virtual bool OnResponseCompleted(int request_id, |
+ const URLRequestStatus& status, |
+ const std::string& security_info); |
+ |
+ virtual void OnRequestClosed(); |
+ |
+ protected: |
+ virtual ~PrerenderResourceHandler(); |
+ |
+ private: |
+ friend class PrerenderResourceHandlerTest; |
+ typedef Callback1<const GURL&>::Type PrerenderCallback; |
+ |
+ PrerenderResourceHandler(ResourceHandler* next_handler, |
+ PrerenderCallback* callback); |
+ |
+ void RunCallbackFromUIThread(const GURL& url); |
+ void StartPrerender(const GURL& url); |
+ static bool ShouldPrerender(const GURL& url, |
+ const ResourceResponse* response); |
+ |
+ GURL url_; |
+ scoped_refptr<ResourceHandler> next_handler_; |
+ scoped_refptr<PrerenderManager> prerender_manager_; |
+ scoped_ptr<PrerenderCallback> prerender_callback_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(PrerenderResourceHandler); |
+}; |
+ |
+#endif // CHROME_BROWSER_PRERENDER_PRERENDER_RESOURCE_HANDLER_H_ |