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

Unified 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: continue review in split cl 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 side-by-side diff with in-line comments
Download patch
Index: components/web_restriction/web_restriction_resource_throttle.cc
diff --git a/components/web_restriction/web_restriction_resource_throttle.cc b/components/web_restriction/web_restriction_resource_throttle.cc
new file mode 100644
index 0000000000000000000000000000000000000000..147f63e51be8968c87ab4bb05cc7d8e74fd17e19
--- /dev/null
+++ b/components/web_restriction/web_restriction_resource_throttle.cc
@@ -0,0 +1,62 @@
+// Copyright 2015 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 "components/web_restriction/web_restriction_resource_throttle.h"
+
+#include "base/bind.h"
+#include "components/web_restriction/web_restriction_provider.h"
+#include "content/public/browser/resource_controller.h"
+#include "net/base/net_errors.h"
+#include "net/url_request/redirect_info.h"
+#include "net/url_request/url_request.h"
+
+namespace web_restriction {
+
+WebRestrictionResourceThrottle::WebRestrictionResourceThrottle(
+ WebRestrictionProvider* provider,
+ const GURL& request_url,
+ bool is_main_frame)
+ : provider_(provider),
+ request_url_(request_url),
+ is_main_frame_(is_main_frame),
+ weak_ptr_factory_(this) {}
+
+WebRestrictionResourceThrottle::~WebRestrictionResourceThrottle() {}
+
+void WebRestrictionResourceThrottle::WillStartRequest(bool* defer) {
+ *defer = ShouldDefer(request_url_);
+}
+
+void WebRestrictionResourceThrottle::WillRedirectRequest(
+ const net::RedirectInfo& redirect_info,
+ bool* defer) {
+ *defer = ShouldDefer(redirect_info.new_url);
+}
+
+const char* WebRestrictionResourceThrottle::GetNameForLogging() const {
+ return "WebRestrictionResourceThrottle";
+}
+
+bool WebRestrictionResourceThrottle::ShouldDefer(const GURL& url) {
+ // For requests to function correctly, we need to allow subresources.
+ if (provider_->SupportsRequest() && !is_main_frame_)
+ return false;
+ UrlAccess access = provider_->ShouldProceed(
+ is_main_frame_, url,
+ base::Bind(&WebRestrictionResourceThrottle::OnCheckResult,
+ weak_ptr_factory_.GetWeakPtr()));
+ if (access == DISALLOW)
+ OnCheckResult(false);
+ return access == PENDING;
+}
+
+void WebRestrictionResourceThrottle::OnCheckResult(const bool should_proceed) {
+ if (should_proceed) {
+ controller()->Resume();
+ } else {
+ controller()->CancelWithError(net::ERR_BLOCKED_BY_ADMINISTRATOR);
+ }
+}
+
+} // namespace web_restriction

Powered by Google App Engine
This is Rietveld 408576698