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

Side by Side Diff: components/safe_browsing/resource_throttle.h

Issue 2876473003: [ABANDONED] [WIP] Refactor SafeBrowsingResourceThrottle in preparation for WebSocket (Closed)
Patch Set: Finish unit tests Created 3 years, 7 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 (c) 2017 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 #ifndef COMPONENTS_SAFE_BROWSING_RESOURCE_THROTTLE_H_
6 #define COMPONENTS_SAFE_BROWSING_RESOURCE_THROTTLE_H_
7
8 #include <memory>
9 #include <vector>
10
11 #include "base/callback.h"
12 #include "base/macros.h"
13 #include "base/memory/ref_counted.h"
14 #include "components/safe_browsing/request_checker.h"
15 #include "content/public/browser/resource_throttle.h"
16 #include "content/public/common/resource_type.h"
17
18 namespace net {
19 class URLRequest;
20 }
21
22 namespace security_interstitials {
23 struct UnsafeResource;
24 }
25
26 namespace safe_browsing {
27
28 class BaseUIManager;
29 class SafeBrowsingDatabaseManager;
30
31 // ResourceThrottle checks that URLs are "safe" before
32 // navigating to them. To be considered "safe", a URL must not appear in the
33 // malware/phishing blacklists (see SafeBrowsingService for details).
34 //
35 // Note that the safe browsing check takes at most kCheckUrlTimeoutMs
36 // milliseconds. If it takes longer than this, then the system defaults to
37 // treating the URL as safe.
38 //
39 // If the URL is classified as dangerous, a warning page is thrown up and
40 // the request remains suspended. If the user clicks "proceed" on warning
41 // page, we resume the request.
42 //
43 // Note: The ResourceThrottle interface is called in this order:
44 // WillStartRequest once, WillRedirectRequest zero or more times, and then
45 // WillProcessReponse once.
46 class ResourceThrottle final : public content::ResourceThrottle,
47 public RequestChecker::Delegate {
48 public:
49 class Delegate {
50 public:
51 Delegate() {}
52 virtual ~Delegate() {}
53 virtual void MaybeDestroyPrerenderContents(
54 const net::URLRequest* request) = 0;
55 virtual void StartDisplayingBlockingPage(
56 const security_interstitials::UnsafeResource& resource,
57 scoped_refptr<BaseUIManager> ui_manager,
58 base::OnceClosure cancel_on_io_thread) = 0;
59
60 private:
61 DISALLOW_COPY_AND_ASSIGN(Delegate);
62 };
63
64 ResourceThrottle(const net::URLRequest* request,
65 content::ResourceType resource_type,
66 scoped_refptr<SafeBrowsingDatabaseManager> database_manager,
67 scoped_refptr<BaseUIManager> ui_manager,
68 std::unique_ptr<Delegate> delegate);
69
70 ~ResourceThrottle() final;
71
72 // content::ResourceThrottle implementation (called on IO thread):
73 void WillStartRequest(bool* defer) final;
74 void WillRedirectRequest(const net::RedirectInfo& redirect_info,
75 bool* defer) final;
76 void WillProcessResponse(bool* defer) final;
77 bool MustProcessResponseBeforeReadingBody() final;
78
79 const char* GetNameForLogging() const final;
80
81 // RequestChecker::Delegate implementation.
82 void MaybeDestroyPrerenderContents(const net::URLRequest* request) final;
83 RequestChecker::Delegate::WebContentsGetter GetWebContentsGetterForRequest(
84 const net::URLRequest* request) const final;
85 void StartDisplayingBlockingPage(
86 const security_interstitials::UnsafeResource& resource,
87 scoped_refptr<BaseUIManager> ui_manager) final;
88 void CancelResourceLoad() final;
89 void ResumeResourceRequest() final;
90
91 private:
92 RequestChecker request_checker_;
93 std::unique_ptr<Delegate> delegate_;
94 base::WeakPtrFactory<ResourceThrottle> weak_factory_;
95
96 DISALLOW_COPY_AND_ASSIGN(ResourceThrottle);
97 };
98
99 } // namespace safe_browsing
100
101 #endif // COMPONENTS_SAFE_BROWSING_RESOURCE_THROTTLE_H_
OLDNEW
« 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