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

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

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
« no previous file with comments | « components/safe_browsing/resource_throttle.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "components/safe_browsing/resource_throttle.h"
6
7 #include <utility>
8
9 #include "components/safe_browsing/base_ui_manager.h"
10 #include "components/security_interstitials/content/unsafe_resource.h"
11 #include "content/public/browser/browser_thread.h"
12 #include "content/public/browser/resource_request_info.h"
13 #include "content/public/browser/web_contents.h"
14 #include "net/base/load_flags.h"
15 #include "net/log/net_log_capture_mode.h"
16 #include "net/log/net_log_source.h"
17 #include "net/log/net_log_source_type.h"
18 #include "net/url_request/redirect_info.h"
19 #include "net/url_request/url_request.h"
20
21 namespace safe_browsing {
22
23 ResourceThrottle::ResourceThrottle(
24 const net::URLRequest* request,
25 content::ResourceType resource_type,
26 scoped_refptr<SafeBrowsingDatabaseManager> database_manager,
27 scoped_refptr<BaseUIManager> ui_manager,
28 std::unique_ptr<ResourceThrottle::Delegate> delegate)
29 : request_checker_(request,
30 resource_type,
31 std::move(database_manager),
32 std::move(ui_manager),
33 this),
34 delegate_(std::move(delegate)),
35 weak_factory_(this) {}
36
37 ResourceThrottle::~ResourceThrottle() {}
38
39 void ResourceThrottle::WillStartRequest(bool* defer) {
40 if (request_checker_.CheckNewRequest() == RequestChecker::DEFER)
41 *defer = true;
42 }
43
44 void ResourceThrottle::WillProcessResponse(bool* defer) {
45 if (request_checker_.ShouldDeferResponse() == RequestChecker::DEFER)
46 *defer = true;
47 }
48
49 bool ResourceThrottle::MustProcessResponseBeforeReadingBody() {
50 // On Android, SafeBrowsing may only decide to cancel the request when the
51 // response has been received. Therefore, no part of it should be cached
52 // until this ResourceThrottle has been able to check the response. This
53 // prevents the following scenario:
54 // 1) A request is made for foo.com which has been hacked.
55 // 2) The request is only canceled at WillProcessResponse stage, but part of
56 // it has been cached.
57 // 3) foo.com is no longer hacked and removed from the SafeBrowsing list.
58 // 4) The user requests foo.com, which is not on the SafeBrowsing list. This
59 // is deemed safe. However, the resource is actually served from cache,
60 // using the version that was previously stored.
61 // 5) This results in the user accessing an unsafe resource without being
62 // notified that it's dangerous.
63 // TODO(clamy): Add a browser test that checks this specific scenario.
64 return true; // Harmless when OS != Android
65 }
66
67 void ResourceThrottle::WillRedirectRequest(
68 const net::RedirectInfo& redirect_info,
69 bool* defer) {
70 if (request_checker_.CheckRedirect(redirect_info.new_url) ==
71 RequestChecker::DEFER) {
72 *defer = true;
73 }
74 }
75
76 const char* ResourceThrottle::GetNameForLogging() const {
77 return "safe_browsing::ResourceThrottle";
78 }
79
80 void ResourceThrottle::MaybeDestroyPrerenderContents(
81 const content::ResourceRequestInfo::WebContentsGetter&
82 web_contents_getter) {
83 delegate_->MaybeDestroyPrerenderContents(web_contents_getter);
84 }
85
86 RequestChecker::Delegate::WebContentsGetter
87 ResourceThrottle::GetWebContentsGetterForRequest(
88 const net::URLRequest* request) const {
89 const auto* info = content::ResourceRequestInfo::ForRequest(request);
90 DCHECK(info);
91 return info->GetWebContentsGetterForRequest();
92 }
93
94 void ResourceThrottle::StartDisplayingBlockingPage(
95 const security_interstitials::UnsafeResource& resource,
96 scoped_refptr<BaseUIManager> ui_manager) {
97 delegate_->StartDisplayingBlockingPage(
98 resource, std::move(ui_manager),
99 base::BindOnce(&ResourceThrottle::Cancel, weak_factory_.GetWeakPtr()));
100 }
101
102 void ResourceThrottle::CancelResourceLoad() {
103 Cancel();
104 }
105
106 void ResourceThrottle::ResumeResourceRequest() {
107 Resume();
108 }
109
110 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « components/safe_browsing/resource_throttle.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698