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"
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
,
21 const ManagedModeURLFilter
* url_filter
)
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
,
32 // Only treat main frame requests for now (ignoring subresources).
36 if (url_filter_
->GetFilteringBehaviorForURL(url
) !=
37 ManagedModeURLFilter::BLOCK
) {
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
,
57 ShowInterstitialIfNeeded(true, new_url
, defer
);
60 const char* ManagedModeResourceThrottle::GetNameForLogging() const {
61 return "ManagedModeResourceThrottle";
64 void ManagedModeResourceThrottle::OnInterstitialResult(bool continue_request
) {
66 controller()->Resume();
68 controller()->Cancel();