1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/managed_mode/managed_mode_resource_throttle.h"
#include "base/bind.h"
#include "chrome/browser/managed_mode/managed_mode_interstitial.h"
#include "chrome/browser/managed_mode/managed_mode_navigation_observer.h"
#include "chrome/browser/managed_mode/managed_mode_url_filter.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/resource_controller.h"
#include "content/public/browser/resource_request_info.h"
#include "net/url_request/url_request.h"
using content::BrowserThread;
ManagedModeResourceThrottle::ManagedModeResourceThrottle(
const net::URLRequest* request,
bool is_main_frame,
const ManagedModeURLFilter* url_filter)
: request_(request),
is_main_frame_(is_main_frame),
url_filter_(url_filter),
weak_ptr_factory_(this) {}
ManagedModeResourceThrottle::~ManagedModeResourceThrottle() {}
void ManagedModeResourceThrottle::ShowInterstitialIfNeeded(bool is_redirect,
const GURL& url,
bool* defer) {
// Only treat main frame requests for now (ignoring subresources).
if (!is_main_frame_)
return;
if (url_filter_->GetFilteringBehaviorForURL(url) !=
ManagedModeURLFilter::BLOCK) {
return;
}
*defer = true;
const content::ResourceRequestInfo* info =
content::ResourceRequestInfo::ForRequest(request_);
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
base::Bind(&ManagedModeNavigationObserver::OnRequestBlocked,
info->GetChildID(), info->GetRouteID(), url,
base::Bind(&ManagedModeResourceThrottle::OnInterstitialResult,
weak_ptr_factory_.GetWeakPtr())));
}
void ManagedModeResourceThrottle::WillStartRequest(bool* defer) {
ShowInterstitialIfNeeded(false, request_->url(), defer);
}
void ManagedModeResourceThrottle::WillRedirectRequest(const GURL& new_url,
bool* defer) {
ShowInterstitialIfNeeded(true, new_url, defer);
}
const char* ManagedModeResourceThrottle::GetNameForLogging() const {
return "ManagedModeResourceThrottle";
}
void ManagedModeResourceThrottle::OnInterstitialResult(bool continue_request) {
if (continue_request)
controller()->Resume();
else
controller()->Cancel();
}
|