OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #include "chrome/browser/renderer_host/ignore_navigation_resource_throttle.h" | |
6 | |
7 #include "base/callback.h" | |
8 #include "content/public/browser/browser_thread.h" | |
9 #include "content/public/browser/render_view_host.h" | |
10 #include "content/public/browser/render_view_host_delegate.h" | |
11 #include "content/public/browser/resource_request_info.h" | |
12 #include "content/public/browser/resource_throttle_controller.h" | |
13 #include "content/public/common/referrer.h" | |
14 #include "net/url_request/url_request.h" | |
15 | |
16 using content::BrowserThread; | |
17 using content::Referrer; | |
18 using content::RenderViewHost; | |
19 using content::RenderViewHostDelegate; | |
20 using content::ResourceRequestInfo; | |
21 | |
22 namespace { | |
23 | |
24 void CheckShouldIgnoreNavigationOnUiThread( | |
darin (slow to review)
2012/05/23 18:18:29
nit: UiThread -> UIThread
mkosiba (inactive)
2012/05/28 16:06:52
Done.
| |
25 int render_process_id, | |
26 int render_view_id, | |
27 const GURL& url, | |
28 const Referrer& referrer, | |
29 bool is_content_initiated, | |
30 base::Callback<void(bool)> callback) { | |
31 | |
32 RenderViewHost* render_view_host = | |
33 RenderViewHost::FromID(render_process_id, render_view_id); | |
34 RenderViewHostDelegate* render_view_host_delegate = | |
35 render_view_host ? render_view_host->GetDelegate() : NULL; | |
36 bool should_ignore_navigation = false; | |
37 if (render_view_host_delegate) { | |
38 should_ignore_navigation = | |
39 render_view_host_delegate->ShouldIgnoreNavigation( | |
40 render_view_host, url, referrer, is_content_initiated); | |
41 } | |
42 | |
43 BrowserThread::PostTask( | |
44 BrowserThread::IO, | |
45 FROM_HERE, | |
46 base::Bind(callback, should_ignore_navigation)); | |
47 } | |
48 | |
49 } // namespace | |
50 | |
51 IgnoreNavigationResourceThrottle::IgnoreNavigationResourceThrottle( | |
52 net::URLRequest* request) | |
53 : request_(request), | |
54 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | |
55 } | |
56 | |
57 IgnoreNavigationResourceThrottle:: | |
58 ~IgnoreNavigationResourceThrottle() { | |
59 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
60 } | |
61 | |
62 void IgnoreNavigationResourceThrottle::WillStartRequest(bool* defer) { | |
63 *defer = ShouldDeferRequestForUrl(request_->url()); | |
darin (slow to review)
2012/05/23 18:18:29
nit: ForUrl -> ForURL
mkosiba (inactive)
2012/05/28 16:06:52
Done.
| |
64 } | |
65 | |
66 void IgnoreNavigationResourceThrottle::WillRedirectRequest( | |
67 const GURL& new_url, | |
68 bool* defer) { | |
69 *defer = ShouldDeferRequestForUrl(new_url); | |
70 } | |
71 | |
72 bool IgnoreNavigationResourceThrottle::ShouldDeferRequestForUrl( | |
73 const GURL& url) { | |
74 int render_process_id, render_view_id; | |
75 if (!ResourceRequestInfo::GetRenderViewForRequest( | |
76 request_, | |
77 &render_process_id, | |
78 &render_view_id)) { | |
79 return false; | |
80 } | |
81 | |
82 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request_); | |
darin (slow to review)
2012/05/23 18:18:29
you should just call ResourceRequestInfo::GetAssoc
mkosiba (inactive)
2012/05/28 16:06:52
Done.
| |
83 // The ShouldIngoreNavigationResourceThrottle should only be created for top | |
darin (slow to review)
2012/05/23 18:18:29
nit: what is a "ShouldIngoreNavigationResourceThro
mkosiba (inactive)
2012/05/28 16:06:52
Done.
| |
84 // level frame requests. | |
85 DCHECK(info->IsMainFrame()); | |
86 | |
87 BrowserThread::PostTask( | |
88 BrowserThread::UI, | |
89 FROM_HERE, | |
90 base::Bind( | |
91 &CheckShouldIgnoreNavigationOnUiThread, | |
92 render_process_id, | |
93 render_view_id, | |
94 url, | |
95 Referrer(GURL(request_->referrer()), info->GetReferrerPolicy()), | |
96 info->HasUserGesture(), | |
97 base::Bind(&IgnoreNavigationResourceThrottle::OnResultObtained, | |
98 weak_ptr_factory_.GetWeakPtr()))); | |
99 return true; | |
100 } | |
101 | |
102 void IgnoreNavigationResourceThrottle::OnResultObtained( | |
103 bool should_ignore_navigation) { | |
104 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
105 | |
106 if (should_ignore_navigation) { | |
107 controller()->Cancel(); | |
darin (slow to review)
2012/05/23 18:18:29
this may not be the ideal way to cancel the reques
mkosiba (inactive)
2012/05/28 16:06:52
Done.
| |
108 } else { | |
109 controller()->Resume(); | |
110 } | |
111 } | |
OLD | NEW |