Refactoring : Move AuthAttempt and Authenticators to chromeos/login
[chromium-blink-merge.git] / chrome / browser / supervised_user / supervised_user_resource_throttle.cc
blob8cf1cebc604bfa02e9f54b0d4a955a047be9a678
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"
7 #include "base/bind.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,
20 bool is_main_frame,
21 const SupervisedUserURLFilter* url_filter)
22 : request_(request),
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,
30 const GURL& url,
31 bool* defer) {
32 // Only treat main frame requests for now (ignoring subresources).
33 if (!is_main_frame_)
34 return;
36 if (url_filter_->GetFilteringBehaviorForURL(url) !=
37 SupervisedUserURLFilter::BLOCK) {
38 return;
41 *defer = true;
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,
47 base::Bind(
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,
57 bool* defer) {
58 ShowInterstitialIfNeeded(true, new_url, defer);
61 const char* SupervisedUserResourceThrottle::GetNameForLogging() const {
62 return "SupervisedUserResourceThrottle";
65 void SupervisedUserResourceThrottle::OnInterstitialResult(
66 bool continue_request) {
67 if (continue_request)
68 controller()->Resume();
69 else
70 controller()->Cancel();