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

Side by Side 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 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 using WebContentsGetter = RequestChecker::Delegate::WebContentsGetter;
52 Delegate() {}
53 virtual ~Delegate() {}
54 virtual void MaybeDestroyPrerenderContents(
55 const WebContentsGetter& web_contents_getter) = 0;
56 virtual void StartDisplayingBlockingPage(
57 const security_interstitials::UnsafeResource& resource,
58 scoped_refptr<BaseUIManager> ui_manager,
59 base::OnceClosure cancel_on_io_thread) = 0;
60
61 private:
62 DISALLOW_COPY_AND_ASSIGN(Delegate);
63 };
64
65 ResourceThrottle(const net::URLRequest* request,
66 content::ResourceType resource_type,
67 scoped_refptr<SafeBrowsingDatabaseManager> database_manager,
68 scoped_refptr<BaseUIManager> ui_manager,
69 std::unique_ptr<Delegate> delegate);
70
71 ~ResourceThrottle() final;
72
73 // content::ResourceThrottle implementation (called on IO thread):
74 void WillStartRequest(bool* defer) final;
75 void WillRedirectRequest(const net::RedirectInfo& redirect_info,
76 bool* defer) final;
77 void WillProcessResponse(bool* defer) final;
78 bool MustProcessResponseBeforeReadingBody() final;
79
80 const char* GetNameForLogging() const final;
81
82 // RequestChecker::Delegate implementation.
83 void MaybeDestroyPrerenderContents(
84 const WebContentsGetter& web_contents_getter) final;
85 RequestChecker::Delegate::WebContentsGetter GetWebContentsGetterForRequest(
86 const net::URLRequest* request) const final;
87 void StartDisplayingBlockingPage(
88 const security_interstitials::UnsafeResource& resource,
89 scoped_refptr<BaseUIManager> ui_manager) final;
90 void CancelResourceLoad() final;
91 void ResumeResourceRequest() final;
92
93 private:
94 RequestChecker request_checker_;
95 std::unique_ptr<Delegate> delegate_;
96 base::WeakPtrFactory<ResourceThrottle> weak_factory_;
97
98 DISALLOW_COPY_AND_ASSIGN(ResourceThrottle);
99 };
100
101 } // namespace safe_browsing
102
103 #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