Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(510)

Side by Side Diff: components/web_restriction/web_restriction_resource_throttle.cc

Issue 1423713015: [WIP] WebRestrictions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 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.
4
5 #include "components/web_restriction/web_restriction_resource_throttle.h"
6
7 #include "base/bind.h"
8 #include "components/web_restriction/web_restriction_provider.h"
9 #include "content/public/browser/resource_controller.h"
10 #include "net/base/net_errors.h"
11 #include "net/url_request/redirect_info.h"
12 #include "net/url_request/url_request.h"
13
14 namespace web_restriction {
15
16 WebRestrictionResourceThrottle::WebRestrictionResourceThrottle(
17 WebRestrictionProvider* provider,
18 const GURL& request_url,
19 bool is_main_frame)
20 : provider_(provider),
21 request_url_(request_url),
22 is_main_frame_(is_main_frame),
23 weak_ptr_factory_(this) {}
24
25 WebRestrictionResourceThrottle::~WebRestrictionResourceThrottle() {}
26
27 void WebRestrictionResourceThrottle::WillStartRequest(bool* defer) {
28 *defer = ShouldDefer(request_url_);
29 }
30
31 void WebRestrictionResourceThrottle::WillRedirectRequest(
32 const net::RedirectInfo& redirect_info,
33 bool* defer) {
34 *defer = ShouldDefer(redirect_info.new_url);
35 }
36
37 const char* WebRestrictionResourceThrottle::GetNameForLogging() const {
38 return "WebRestrictionResourceThrottle";
39 }
40
41 bool WebRestrictionResourceThrottle::ShouldDefer(const GURL& url) {
42 // For requests to function correctly, we need to allow subresources.
43 if (provider_->SupportsRequest() && !is_main_frame_)
44 return false;
45 UrlAccess access = provider_->ShouldProceed(is_main_frame_, url);
Bernhard Bauer 2016/01/22 17:32:32 Hm… we call this method, and if it returns UNKNOWN
knn 2016/01/25 11:54:24 This looks much better now! Thanks!
46 switch (access) {
47 case UNKNOWN:
48 provider_->ShouldProceed(
49 is_main_frame_, url,
50 base::Bind(&WebRestrictionResourceThrottle::OnCheckResult,
51 weak_ptr_factory_.GetWeakPtr()));
52 break;
53 case DISALLOW:
54 OnCheckResult(false);
55 case ALLOW:
56 break;
57 default:
Bernhard Bauer 2016/01/22 17:32:32 Remove this; the compiler will check it for you.
knn 2016/01/25 11:54:24 Done.
58 NOTREACHED();
59 }
60 return access == UNKNOWN;
61 }
62
63 void WebRestrictionResourceThrottle::OnCheckResult(const bool should_proceed) {
64 if (should_proceed) {
65 controller()->Resume();
66 } else {
67 controller()->CancelWithError(net::ERR_BLOCKED_BY_ADMINISTRATOR);
68 }
69 }
70
71 } // namespace web_restriction
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698