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 #include "chrome/browser/net/prerender_interceptor.h" | |
6 | |
7 #include <string> | |
8 | |
9 #include "base/logging.h" | |
10 #include "chrome/browser/browser_thread.h" | |
11 #include "chrome/browser/io_thread.h" | |
12 #include "googleurl/src/gurl.h" | |
13 #include "net/base/load_flags.h" | |
14 | |
15 DISABLE_RUNNABLE_METHOD_REFCOUNT(chrome_browser_net::PrerenderInterceptor); | |
16 | |
17 namespace chrome_browser_net { | |
18 | |
19 PrerenderInterceptor::PrerenderInterceptor() | |
20 : ALLOW_THIS_IN_INITIALIZER_LIST( | |
21 callback_(NewCallback(this, | |
22 &PrerenderInterceptor::PrerenderDispatch))) { | |
23 net::URLRequest::RegisterRequestInterceptor(this); | |
24 } | |
25 | |
26 PrerenderInterceptor::PrerenderInterceptor( | |
27 PrerenderInterceptorCallback* callback) | |
28 : callback_(callback) { | |
29 net::URLRequest::RegisterRequestInterceptor(this); | |
30 } | |
31 | |
32 PrerenderInterceptor::~PrerenderInterceptor() { | |
33 net::URLRequest::UnregisterRequestInterceptor(this); | |
34 } | |
35 | |
36 net::URLRequestJob* PrerenderInterceptor::MaybeIntercept( | |
37 net::URLRequest* request) { | |
38 return NULL; | |
39 } | |
40 | |
41 net::URLRequestJob* PrerenderInterceptor::MaybeInterceptResponse( | |
42 net::URLRequest* request) { | |
43 // TODO(gavinp): unfortunately, we can't figure out the origin | |
44 // of this request here on systems where the referrer is blocked by | |
45 // configuration. | |
46 | |
47 // TODO(gavinp): note that the response still might be intercepted | |
48 // by a later interceptor. Should we write an interposing delegate | |
49 // and only prerender dispatch on requests that aren't intercepted? | |
50 // Or is this a slippery slope? | |
51 | |
52 if (request->load_flags() & net::LOAD_PREFETCH) { | |
53 std::string mime_type; | |
54 request->GetMimeType(&mime_type); | |
55 if (mime_type == "text/html") | |
56 BrowserThread::PostTask( | |
57 BrowserThread::UI, | |
58 FROM_HERE, | |
59 NewRunnableMethod(this, | |
60 &PrerenderInterceptor::RunCallbackFromUIThread, | |
61 request->url())); | |
62 } | |
63 return NULL; | |
64 } | |
65 | |
66 void PrerenderInterceptor::RunCallbackFromUIThread(const GURL& url) { | |
67 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
68 callback_->Run(url); | |
69 } | |
70 | |
71 void PrerenderInterceptor::PrerenderDispatch( | |
72 const GURL& url) { | |
73 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
74 DVLOG(2) << "PrerenderDispatchOnUIThread: url=" << url; | |
75 } | |
76 | |
77 } // namespace chrome_browser_net | |
OLD | NEW |