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

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: incorporated feedback 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/render_view_host.h"
10 #include "content/public/browser/resource_request_info.h"
11 #include "content/public/browser/resource_throttle_controller.h"
12 #include "content/public/browser/web_contents.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::ResourceRequestInfo;
20 using content::WebContents;
21
22 namespace {
23
24 void CheckShouldIgnoreNavigationOnUIThread(
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* rvh =
33 RenderViewHost::FromID(render_process_id, render_view_id);
34 WebContents* web_contents =
35 rvh ? WebContents::FromRenderViewHost(rvh) : NULL;
36 bool should_ignore_navigation = false;
37 if (web_contents) {
38 should_ignore_navigation = web_contents->ShouldIgnoreNavigation(
39 url, referrer, is_content_initiated);
40 }
41
42 BrowserThread::PostTask(
43 BrowserThread::IO,
44 FROM_HERE,
45 base::Bind(callback, should_ignore_navigation));
46 }
47
48 } // namespace
49
50 InterceptNavigationResourceThrottle::InterceptNavigationResourceThrottle(
51 net::URLRequest* request)
52 : request_(request),
53 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
54 }
55
56 InterceptNavigationResourceThrottle::
57 ~InterceptNavigationResourceThrottle() {
58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
59 }
60
61 void InterceptNavigationResourceThrottle::WillStartRequest(bool* defer) {
62 *defer = ShouldDeferRequestForURL(request_->url());
63 }
64
65 void InterceptNavigationResourceThrottle::WillRedirectRequest(
66 const GURL& new_url,
67 bool* defer) {
68 *defer = ShouldDeferRequestForURL(new_url);
69 }
70
71 bool InterceptNavigationResourceThrottle::ShouldDeferRequestForURL(
72 const GURL& url) {
73 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request_);
74 if (!info)
75 return false;
76
77 int render_process_id, render_view_id;
78 if (!info->GetAssociatedRenderView(&render_process_id, &render_view_id)) {
79 return false;
80 }
81
82 // This class should only be instantiated for top level frame requests.
83 DCHECK(info->IsMainFrame());
84
85 BrowserThread::PostTask(
86 BrowserThread::UI,
87 FROM_HERE,
88 base::Bind(
89 &CheckShouldIgnoreNavigationOnUIThread,
90 render_process_id,
91 render_view_id,
92 url,
93 Referrer(GURL(request_->referrer()), info->GetReferrerPolicy()),
94 info->HasUserGesture(),
95 base::Bind(&InterceptNavigationResourceThrottle::OnResultObtained,
96 weak_ptr_factory_.GetWeakPtr())));
97 return true;
98 }
99
100 void InterceptNavigationResourceThrottle::OnResultObtained(
101 bool should_ignore_navigation) {
102 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
103
104 if (should_ignore_navigation) {
105 controller()->CancelWithHandledExternallyStatus();
106 } else {
107 controller()->Resume();
108 }
109 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698