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

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

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

Powered by Google App Engine
This is Rietveld 408576698