Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(408)

Side by Side Diff: chrome/browser/renderer_host/intercept_navigation_resource_throttle.cc

Issue 10310124: Implement a ResourceThrottle for URL overriding in Chrome on Android. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: removed code from web_contents_impl Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/intercept_navigation_resource_throttle.h"
6
7 #include "base/callback.h"
8 #include "content/public/browser/browser_thread.h"
9 #include "content/public/browser/child_process_security_policy.h"
10 #include "content/public/browser/render_view_host.h"
11 #include "content/public/browser/render_process_host.h"
12 #include "content/public/browser/resource_request_info.h"
13 #include "content/public/browser/resource_throttle_controller.h"
14 #include "content/public/browser/web_contents.h"
15 #include "content/public/browser/web_contents_delegate.h"
16 #include "content/public/common/referrer.h"
17 #include "net/url_request/url_request.h"
18
19 using content::BrowserThread;
20 using content::ChildProcessSecurityPolicy;
21 using content::Referrer;
22 using content::RenderViewHost;
23 using content::ResourceRequestInfo;
24 using content::WebContents;
25 using content::WebContentsDelegate;
26
27 namespace {
28
29 void CheckShouldIgnoreNavigationOnUIThread(
30 int render_process_id,
31 int render_view_id,
32 const GURL& url,
33 const Referrer& referrer,
34 bool is_content_initiated,
35 base::Callback<void(bool)> callback) {
36
37 RenderViewHost* rvh =
38 RenderViewHost::FromID(render_process_id, render_view_id);
39 WebContents* web_contents =
40 rvh ? WebContents::FromRenderViewHost(rvh) : NULL;
41 WebContentsDelegate* web_contents_delegate =
42 web_contents ? web_contents->GetDelegate() : NULL;
43
44 GURL validated_url(url);
45 RenderViewHost::FilterURL(
46 ChildProcessSecurityPolicy::GetInstance(),
47 rvh->GetProcess()->GetID(),
48 false,
49 &validated_url);
50
51 bool should_ignore_navigation = false;
52 if (web_contents_delegate) {
53 should_ignore_navigation = web_contents_delegate->ShouldIgnoreNavigation(
54 web_contents, validated_url, referrer, is_content_initiated);
55 }
56
57 BrowserThread::PostTask(
58 BrowserThread::IO,
59 FROM_HERE,
60 base::Bind(callback, should_ignore_navigation));
61 }
62
63 } // namespace
64
65 InterceptNavigationResourceThrottle::InterceptNavigationResourceThrottle(
66 net::URLRequest* request)
67 : request_(request),
68 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
69 }
70
71 InterceptNavigationResourceThrottle::
72 ~InterceptNavigationResourceThrottle() {
73 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
74 }
75
76 void InterceptNavigationResourceThrottle::WillStartRequest(bool* defer) {
77 *defer = ShouldDeferRequestForURL(request_->url());
78 }
79
80 void InterceptNavigationResourceThrottle::WillRedirectRequest(
81 const GURL& new_url,
82 bool* defer) {
83 *defer = ShouldDeferRequestForURL(new_url);
84 }
85
86 bool InterceptNavigationResourceThrottle::ShouldDeferRequestForURL(
87 const GURL& url) {
88 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request_);
89 if (!info)
90 return false;
91
92 int render_process_id, render_view_id;
93 if (!info->GetAssociatedRenderView(&render_process_id, &render_view_id)) {
94 return false;
95 }
96
97 // This class should only be instantiated for top level frame requests.
98 DCHECK(info->IsMainFrame());
99
100 BrowserThread::PostTask(
101 BrowserThread::UI,
102 FROM_HERE,
103 base::Bind(
104 &CheckShouldIgnoreNavigationOnUIThread,
105 render_process_id,
106 render_view_id,
107 url,
108 Referrer(GURL(request_->referrer()), info->GetReferrerPolicy()),
109 info->HasUserGesture(),
110 base::Bind(&InterceptNavigationResourceThrottle::OnResultObtained,
111 weak_ptr_factory_.GetWeakPtr())));
112 return true;
113 }
114
115 void InterceptNavigationResourceThrottle::OnResultObtained(
116 bool should_ignore_navigation) {
117 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
118
119 if (should_ignore_navigation) {
120 // TODO: Cancel() results in a CANCELLED status but what we really want is
121 // a HANDLED_EXTERNALLY status.
122 controller()->Cancel();
123 } else {
124 controller()->Resume();
125 }
126 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698