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

Side by Side Diff: chrome/renderer/safe_browsing/safe_browsing_url_loader_throttle.cc

Issue 2900563002: Network service: Safe browsing check for sub-resources from renderer. (Closed)
Patch Set: . 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 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 "chrome/renderer/safe_browsing/safe_browsing_url_loader_throttle.h"
6
7 #include "base/logging.h"
8 #include "net/url_request/redirect_info.h"
9
10 namespace safe_browsing {
11
12 SafeBrowsingURLLoaderThrottle::SafeBrowsingURLLoaderThrottle(
13 chrome::mojom::SafeBrowsing* safe_browsing)
14 : safe_browsing_(safe_browsing), weak_factory_(this) {}
15
16 SafeBrowsingURLLoaderThrottle::~SafeBrowsingURLLoaderThrottle() = default;
17
18 void SafeBrowsingURLLoaderThrottle::WillStartRequest(
19 const GURL& url,
20 int load_flags,
21 content::ResourceType resource_type,
22 bool* defer) {
23 DCHECK_EQ(0u, pending_checks_);
24 DCHECK(!blocked_);
25 DCHECK(!url_checker_);
26
27 pending_checks_++;
28 // Use a weak pointer to self because |safe_browsing_| is not owned by this
29 // object.
30 safe_browsing_->CreateCheckerAndCheck(
31 mojo::MakeRequest(&url_checker_), url, load_flags, resource_type,
32 base::Bind(&SafeBrowsingURLLoaderThrottle::OnCheckUrlResult,
33 weak_factory_.GetWeakPtr()));
34 safe_browsing_ = nullptr;
35
36 url_checker_.set_connection_error_handler(
37 base::Bind(&SafeBrowsingURLLoaderThrottle::OnConnectionError,
38 base::Unretained(this)));
39 }
40
41 void SafeBrowsingURLLoaderThrottle::WillRedirectRequest(
42 const net::RedirectInfo& redirect_info,
43 bool* defer) {
44 // If |blocked_| is true, the resource load has been canceled and there
45 // shouldn't be such a notification.
46 DCHECK(!blocked_);
47
48 if (!url_checker_) {
49 DCHECK_EQ(0u, pending_checks_);
50 return;
51 }
52
53 pending_checks_++;
54 url_checker_->CheckUrl(
55 redirect_info.new_url,
56 base::Bind(&SafeBrowsingURLLoaderThrottle::OnCheckUrlResult,
57 base::Unretained(this)));
58 }
59
60 void SafeBrowsingURLLoaderThrottle::WillProcessResponse(bool* defer) {
61 // If |blocked_| is true, the resource load has been canceled and there
62 // shouldn't be such a notification.
63 DCHECK(!blocked_);
64
65 if (pending_checks_ > 0)
66 *defer = true;
67 }
68
69 void SafeBrowsingURLLoaderThrottle::OnCheckUrlResult(bool result) {
70 if (blocked_ || !url_checker_)
71 return;
72
73 DCHECK_LT(0u, pending_checks_);
74 pending_checks_--;
75
76 if (result) {
77 if (pending_checks_ == 0) {
78 // The resource load is not necessarily deferred, in that case Resume() is
79 // a no-op.
80 delegate_->Resume();
81 }
82 } else {
83 url_checker_.reset();
84 blocked_ = true;
85 pending_checks_ = 0;
86 delegate_->CancelWithError(net::ERR_ABORTED);
87 }
88 }
89
90 void SafeBrowsingURLLoaderThrottle::OnConnectionError() {
91 DCHECK(!blocked_);
92
93 // If a service-side disconnect happens, treate all URLs as if they are safe.
94 url_checker_.reset();
95 pending_checks_ = 0;
96 delegate_->Resume();
97 }
98
99 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698