Chromium Code Reviews| 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/should_ignore_navigation_resource_throttl e.h" | |
| 6 | |
| 7 #include "base/callback.h" | |
| 8 #include "content/browser/renderer_host/resource_request_info_impl.h" | |
| 9 #include "content/public/browser/browser_thread.h" | |
| 10 #include "content/public/browser/render_view_host.h" | |
| 11 #include "content/public/browser/render_view_host_delegate.h" | |
| 12 #include "content/public/browser/resource_request_info.h" | |
| 13 #include "content/public/browser/resource_throttle_controller.h" | |
| 14 #include "content/public/common/referrer.h" | |
| 15 #include "net/url_request/url_request.h" | |
| 16 | |
| 17 using content::BrowserThread; | |
| 18 using content::Referrer; | |
| 19 using content::RenderViewHost; | |
| 20 using content::RenderViewHostDelegate; | |
| 21 using content::ResourceRequestInfo; | |
| 22 | |
| 23 namespace { | |
| 24 | |
| 25 void CheckShouldIgnoreNavigationOnUiThread( | |
| 26 int render_process_id, | |
| 27 int render_view_id, | |
| 28 const GURL& url, | |
| 29 const Referrer& referrer, | |
| 30 bool is_content_initiated, | |
| 31 base::Callback<void(bool)> callback) { | |
| 32 | |
| 33 RenderViewHost* render_view_host = | |
| 34 RenderViewHost::FromID(render_process_id, render_view_id); | |
| 35 RenderViewHostDelegate* render_view_host_delegate = | |
| 36 render_view_host ? render_view_host->GetDelegate() : NULL; | |
| 37 bool should_ignore_navigation = false; | |
| 38 if (render_view_host_delegate) | |
| 39 should_ignore_navigation = | |
| 40 render_view_host_delegate->ShouldIgnoreNavigation( | |
| 41 render_view_host, url, referrer, is_content_initiated); | |
|
joth
2012/05/11 15:34:13
Enclose in {} when it covers more than one physica
mkosiba (inactive)
2012/05/15 14:20:23
Done.
| |
| 42 | |
| 43 BrowserThread::PostTask( | |
| 44 BrowserThread::IO, | |
| 45 FROM_HERE, | |
| 46 base::Bind(callback, should_ignore_navigation)); | |
| 47 } | |
| 48 | |
| 49 } // anonymous namespace | |
|
joth
2012/05/11 15:34:13
nit: // namespace
mkosiba (inactive)
2012/05/15 14:20:23
Done.
| |
| 50 | |
| 51 ShouldIgnoreNavigationResourceThrottle::ShouldIgnoreNavigationResourceThrottle( | |
| 52 net::URLRequest* request) : request_(request) { | |
|
joth
2012/05/11 15:34:13
nit: initializer on its own line when the c'tor do
mkosiba (inactive)
2012/05/15 14:20:23
Done.
mkosiba (inactive)
2012/05/15 14:20:23
Done.
| |
| 53 } | |
| 54 | |
| 55 ShouldIgnoreNavigationResourceThrottle:: | |
| 56 ~ShouldIgnoreNavigationResourceThrottle() { | |
| 57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 58 } | |
| 59 | |
| 60 void ShouldIgnoreNavigationResourceThrottle::WillStartRequest(bool* defer) { | |
| 61 ShouldDeferRequest(request_->url(), defer); | |
| 62 } | |
| 63 | |
| 64 void ShouldIgnoreNavigationResourceThrottle::WillRedirectRequest( | |
| 65 const GURL& new_url, | |
| 66 bool* defer) { | |
| 67 ShouldDeferRequest(new_url, defer); | |
|
joth
2012/05/11 15:34:13
nit: ShouldDeferRequest is a slightly open name (s
mkosiba (inactive)
2012/05/15 14:20:23
Done
| |
| 68 } | |
| 69 | |
| 70 void ShouldIgnoreNavigationResourceThrottle::ShouldDeferRequest( | |
| 71 const GURL& url, | |
| 72 bool* defer) { | |
| 73 int render_process_id, render_view_id; | |
| 74 if (!ResourceRequestInfo::GetRenderViewForRequest( | |
| 75 request_, | |
| 76 &render_process_id, | |
| 77 &render_view_id)) { | |
| 78 *defer = false; | |
| 79 return; | |
| 80 } | |
| 81 *defer = true; | |
| 82 | |
| 83 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request_); | |
| 84 // The ShouldIngoreNavigationResourceThrottle should only be created for top | |
| 85 // level frame requests. | |
| 86 DCHECK(info->IsMainFrame()); | |
| 87 // TODO: Promote has_user_gesture to ResourceRequestInfo? | |
|
joth
2012/05/11 15:34:13
TODO(mkosiba). Or word as a 'in future we may want
| |
| 88 const bool is_content_initiated = | |
|
joth
2012/05/11 15:34:13
nit: chromium style generally shuns const here. I
mkosiba (inactive)
2012/05/15 14:20:23
Done.
| |
| 89 content::ResourceRequestInfoImpl::ForRequest( | |
| 90 request_)->has_user_gesture(); | |
| 91 | |
| 92 BrowserThread::PostTask( | |
| 93 BrowserThread::UI, | |
| 94 FROM_HERE, | |
| 95 base::Bind( | |
| 96 &CheckShouldIgnoreNavigationOnUiThread, | |
| 97 render_process_id, | |
| 98 render_view_id, | |
| 99 url, | |
| 100 Referrer(GURL(request_->referrer()), info->GetReferrerPolicy()), | |
| 101 is_content_initiated, | |
| 102 base::Bind(&ShouldIgnoreNavigationResourceThrottle::OnResultObtained, | |
| 103 AsWeakPtr()))); | |
|
joth
2012/05/11 15:34:13
currytastic :)
| |
| 104 } | |
| 105 | |
| 106 void ShouldIgnoreNavigationResourceThrottle::OnResultObtained( | |
| 107 bool should_ignore_navigation) { | |
| 108 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 109 | |
| 110 if (should_ignore_navigation) | |
| 111 controller()->Cancel(); | |
| 112 else | |
|
joth
2012/05/11 15:34:13
nit: use braces when there's an else
mkosiba (inactive)
2012/05/15 14:20:23
Done.
| |
| 113 controller()->Resume(); | |
| 114 } | |
| OLD | NEW |