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

Unified Diff: components/safe_browsing/resource_throttle.h

Issue 2876473003: [ABANDONED] [WIP] Refactor SafeBrowsingResourceThrottle in preparation for WebSocket (Closed)
Patch Set: Minor fixes Created 3 years, 6 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
« no previous file with comments | « components/safe_browsing/request_checker_unittest.cc ('k') | components/safe_browsing/resource_throttle.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/safe_browsing/resource_throttle.h
diff --git a/components/safe_browsing/resource_throttle.h b/components/safe_browsing/resource_throttle.h
new file mode 100644
index 0000000000000000000000000000000000000000..b23e677d89041484b13eb59cc76ba6afe65450ac
--- /dev/null
+++ b/components/safe_browsing/resource_throttle.h
@@ -0,0 +1,103 @@
+// Copyright (c) 2017 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.
+
+#ifndef COMPONENTS_SAFE_BROWSING_RESOURCE_THROTTLE_H_
+#define COMPONENTS_SAFE_BROWSING_RESOURCE_THROTTLE_H_
+
+#include <memory>
+#include <vector>
+
+#include "base/callback.h"
+#include "base/macros.h"
+#include "base/memory/ref_counted.h"
+#include "components/safe_browsing/request_checker.h"
+#include "content/public/browser/resource_throttle.h"
+#include "content/public/common/resource_type.h"
+
+namespace net {
+class URLRequest;
+}
+
+namespace security_interstitials {
+struct UnsafeResource;
+}
+
+namespace safe_browsing {
+
+class BaseUIManager;
+class SafeBrowsingDatabaseManager;
+
+// ResourceThrottle checks that URLs are "safe" before
+// navigating to them. To be considered "safe", a URL must not appear in the
+// malware/phishing blacklists (see SafeBrowsingService for details).
+//
+// Note that the safe browsing check takes at most kCheckUrlTimeoutMs
+// milliseconds. If it takes longer than this, then the system defaults to
+// treating the URL as safe.
+//
+// If the URL is classified as dangerous, a warning page is thrown up and
+// the request remains suspended. If the user clicks "proceed" on warning
+// page, we resume the request.
+//
+// Note: The ResourceThrottle interface is called in this order:
+// WillStartRequest once, WillRedirectRequest zero or more times, and then
+// WillProcessReponse once.
+class ResourceThrottle final : public content::ResourceThrottle,
+ public RequestChecker::Delegate {
+ public:
+ class Delegate {
+ public:
+ using WebContentsGetter = RequestChecker::Delegate::WebContentsGetter;
+ Delegate() {}
+ virtual ~Delegate() {}
+ virtual void MaybeDestroyPrerenderContents(
+ const WebContentsGetter& web_contents_getter) = 0;
+ virtual void StartDisplayingBlockingPage(
+ const security_interstitials::UnsafeResource& resource,
+ scoped_refptr<BaseUIManager> ui_manager,
+ base::OnceClosure cancel_on_io_thread) = 0;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(Delegate);
+ };
+
+ ResourceThrottle(const net::URLRequest* request,
+ content::ResourceType resource_type,
+ scoped_refptr<SafeBrowsingDatabaseManager> database_manager,
+ scoped_refptr<BaseUIManager> ui_manager,
+ std::unique_ptr<Delegate> delegate);
+
+ ~ResourceThrottle() final;
+
+ // content::ResourceThrottle implementation (called on IO thread):
+ void WillStartRequest(bool* defer) final;
+ void WillRedirectRequest(const net::RedirectInfo& redirect_info,
+ bool* defer) final;
+ void WillProcessResponse(bool* defer) final;
+ bool MustProcessResponseBeforeReadingBody() final;
+
+ const char* GetNameForLogging() const final;
+
+ // RequestChecker::Delegate implementation.
+ void MaybeDestroyPrerenderContents(
+ const WebContentsGetter& web_contents_getter) final;
+ RequestChecker::Delegate::WebContentsGetter GetWebContentsGetterForRequest(
+ const net::URLRequest* request) const final;
+ void StartDisplayingBlockingPage(
+ const security_interstitials::UnsafeResource& resource,
+ scoped_refptr<BaseUIManager> ui_manager) final;
+ void CancelResourceLoad() final;
+ void ResumeResourceRequest() final;
+
+ private:
+ RequestChecker request_checker_;
+ std::unique_ptr<Delegate> delegate_;
+ base::WeakPtrFactory<ResourceThrottle> weak_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(ResourceThrottle);
+};
+
+} // namespace safe_browsing
+
+#endif // COMPONENTS_SAFE_BROWSING_RESOURCE_THROTTLE_H_
« no previous file with comments | « components/safe_browsing/request_checker_unittest.cc ('k') | components/safe_browsing/resource_throttle.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698