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

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, 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 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 int render_frame_id)
15 : safe_browsing_(safe_browsing),
16 render_frame_id_(render_frame_id),
17 weak_factory_(this) {}
18
19 SafeBrowsingURLLoaderThrottle::~SafeBrowsingURLLoaderThrottle() = default;
20
21 void SafeBrowsingURLLoaderThrottle::WillStartRequest(
22 const GURL& url,
23 int load_flags,
24 content::ResourceType resource_type,
25 bool* defer) {
26 DCHECK_EQ(0u, pending_checks_);
27 DCHECK(!blocked_);
28 DCHECK(!url_checker_);
29
30 pending_checks_++;
31 // Use a weak pointer to self because |safe_browsing_| is not owned by this
32 // object.
33 safe_browsing_->CreateCheckerAndCheck(
34 render_frame_id_, mojo::MakeRequest(&url_checker_), url, load_flags,
Adam Rice 2017/05/31 06:08:51 Do you need to include "mojo/public/cpp/bindings/i
yzshen1 2017/05/31 23:34:44 Done.
35 resource_type,
36 base::BindOnce(&SafeBrowsingURLLoaderThrottle::OnCheckUrlResult,
37 weak_factory_.GetWeakPtr()));
38 safe_browsing_ = nullptr;
39
40 url_checker_.set_connection_error_handler(
41 base::Bind(&SafeBrowsingURLLoaderThrottle::OnConnectionError,
42 base::Unretained(this)));
43 }
44
45 void SafeBrowsingURLLoaderThrottle::WillRedirectRequest(
46 const net::RedirectInfo& redirect_info,
47 bool* defer) {
48 // If |blocked_| is true, the resource load has been canceled and there
49 // shouldn't be such a notification.
50 DCHECK(!blocked_);
51
52 if (!url_checker_) {
53 DCHECK_EQ(0u, pending_checks_);
54 return;
55 }
56
57 pending_checks_++;
58 url_checker_->CheckUrl(
59 redirect_info.new_url,
60 base::BindOnce(&SafeBrowsingURLLoaderThrottle::OnCheckUrlResult,
61 base::Unretained(this)));
62 }
63
64 void SafeBrowsingURLLoaderThrottle::WillProcessResponse(bool* defer) {
65 // If |blocked_| is true, the resource load has been canceled and there
66 // shouldn't be such a notification.
67 DCHECK(!blocked_);
68
69 if (pending_checks_ > 0)
70 *defer = true;
71 }
72
73 void SafeBrowsingURLLoaderThrottle::OnCheckUrlResult(bool result) {
74 if (blocked_ || !url_checker_)
75 return;
76
77 DCHECK_LT(0u, pending_checks_);
78 pending_checks_--;
79
80 if (result) {
81 if (pending_checks_ == 0) {
82 // The resource load is not necessarily deferred, in that case Resume() is
83 // a no-op.
84 delegate_->Resume();
85 }
86 } else {
87 url_checker_.reset();
88 blocked_ = true;
89 pending_checks_ = 0;
90 delegate_->CancelWithError(net::ERR_ABORTED);
91 }
92 }
93
94 void SafeBrowsingURLLoaderThrottle::OnConnectionError() {
95 DCHECK(!blocked_);
96
97 // If a service-side disconnect happens, treat all URLs as if they are safe.
98 url_checker_.reset();
99 pending_checks_ = 0;
100 delegate_->Resume();
101 }
102
103 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698