Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / managed_mode / managed_mode_resource_throttle.cc
blob001508db5b8a30456f08df7f9c99ce4e9323df4f
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.
5 #include "chrome/browser/managed_mode/managed_mode_resource_throttle.h"
7 #include "base/bind.h"
8 #include "chrome/browser/managed_mode/managed_mode_interstitial.h"
9 #include "chrome/browser/managed_mode/managed_mode_navigation_observer.h"
10 #include "chrome/browser/managed_mode/managed_mode_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 ManagedModeResourceThrottle::ManagedModeResourceThrottle(
19 const net::URLRequest* request,
20 bool is_main_frame,
21 const ManagedModeURLFilter* url_filter)
22 : request_(request),
23 is_main_frame_(is_main_frame),
24 url_filter_(url_filter),
25 weak_ptr_factory_(this) {}
27 ManagedModeResourceThrottle::~ManagedModeResourceThrottle() {}
29 void ManagedModeResourceThrottle::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 ManagedModeURLFilter::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(&ManagedModeNavigationObserver::OnRequestBlocked,
46 info->GetChildID(), info->GetRouteID(), url,
47 base::Bind(&ManagedModeResourceThrottle::OnInterstitialResult,
48 weak_ptr_factory_.GetWeakPtr())));
51 void ManagedModeResourceThrottle::WillStartRequest(bool* defer) {
52 ShowInterstitialIfNeeded(false, request_->url(), defer);
55 void ManagedModeResourceThrottle::WillRedirectRequest(const GURL& new_url,
56 bool* defer) {
57 ShowInterstitialIfNeeded(true, new_url, defer);
60 const char* ManagedModeResourceThrottle::GetNameForLogging() const {
61 return "ManagedModeResourceThrottle";
64 void ManagedModeResourceThrottle::OnInterstitialResult(bool continue_request) {
65 if (continue_request)
66 controller()->Resume();
67 else
68 controller()->Cancel();