1 // Copyright 2014 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.
5 #include "chrome/browser/supervised_user/supervised_user_resource_throttle.h"
8 #include "chrome/browser/supervised_user/supervised_user_interstitial.h"
9 #include "chrome/browser/supervised_user/supervised_user_navigation_observer.h"
10 #include "chrome/browser/supervised_user/supervised_user_url_filter.h"
11 #include "content/public/browser/browser_thread.h"
12 #include "content/public/browser/resource_controller.h"
13 #include "content/public/browser/resource_request_info.h"
14 #include "net/url_request/url_request.h"
16 using content::BrowserThread
;
18 SupervisedUserResourceThrottle::SupervisedUserResourceThrottle(
19 const net::URLRequest
* request
,
21 const SupervisedUserURLFilter
* url_filter
)
23 is_main_frame_(is_main_frame
),
24 url_filter_(url_filter
),
25 weak_ptr_factory_(this) {}
27 SupervisedUserResourceThrottle::~SupervisedUserResourceThrottle() {}
29 void SupervisedUserResourceThrottle::ShowInterstitialIfNeeded(bool is_redirect
,
32 // Only treat main frame requests for now (ignoring subresources).
36 if (url_filter_
->GetFilteringBehaviorForURL(url
) !=
37 SupervisedUserURLFilter::BLOCK
) {
42 const content::ResourceRequestInfo
* info
=
43 content::ResourceRequestInfo::ForRequest(request_
);
44 BrowserThread::PostTask(BrowserThread::UI
, FROM_HERE
,
45 base::Bind(&SupervisedUserNavigationObserver::OnRequestBlocked
,
46 info
->GetChildID(), info
->GetRouteID(), url
,
48 &SupervisedUserResourceThrottle::OnInterstitialResult
,
49 weak_ptr_factory_
.GetWeakPtr())));
52 void SupervisedUserResourceThrottle::WillStartRequest(bool* defer
) {
53 ShowInterstitialIfNeeded(false, request_
->url(), defer
);
56 void SupervisedUserResourceThrottle::WillRedirectRequest(const GURL
& new_url
,
58 ShowInterstitialIfNeeded(true, new_url
, defer
);
61 const char* SupervisedUserResourceThrottle::GetNameForLogging() const {
62 return "SupervisedUserResourceThrottle";
65 void SupervisedUserResourceThrottle::OnInterstitialResult(
66 bool continue_request
) {
68 controller()->Resume();
70 controller()->Cancel();