| OLD | NEW |
| 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 #ifndef CHROME_RENDERER_SAFE_BROWSING_SAFE_BROWSING_URL_LOADER_THROTTLE_H_ | 5 #ifndef CHROME_RENDERER_SAFE_BROWSING_RENDERER_URL_LOADER_THROTTLE_H_ |
| 6 #define CHROME_RENDERER_SAFE_BROWSING_SAFE_BROWSING_URL_LOADER_THROTTLE_H_ | 6 #define CHROME_RENDERER_SAFE_BROWSING_RENDERER_URL_LOADER_THROTTLE_H_ |
| 7 | 7 |
| 8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
| 9 #include "components/safe_browsing/common/safe_browsing.mojom.h" | 9 #include "components/safe_browsing/common/safe_browsing.mojom.h" |
| 10 #include "content/public/common/url_loader_throttle.h" | 10 #include "content/public/common/url_loader_throttle.h" |
| 11 | 11 |
| 12 namespace chrome { | |
| 13 namespace mojom { | |
| 14 class SafeBrowsing; | |
| 15 } | |
| 16 } | |
| 17 | |
| 18 namespace safe_browsing { | 12 namespace safe_browsing { |
| 19 | 13 |
| 20 // SafeBrowsingURLLoaderThrottle queries SafeBrowsing to determine whether the | 14 // RendererURLLoaderThrottle is used in renderer processes to query |
| 21 // URL and also redirect URLs are safe to load. It defers response processing | 15 // SafeBrowsing and determine whether a URL and its redirect URLs are safe to |
| 22 // until all URL checks are completed; cancels the load if any URLs turn out to | 16 // load. It defers response processing until all URL checks are completed; |
| 23 // be bad. | 17 // cancels the load if any URLs turn out to be bad. |
| 24 class SafeBrowsingURLLoaderThrottle : public content::URLLoaderThrottle { | 18 class RendererURLLoaderThrottle : public content::URLLoaderThrottle { |
| 25 public: | 19 public: |
| 26 // |safe_browsing| must stay alive until WillStartRequest() (if it is called) | 20 // |safe_browsing| must stay alive until WillStartRequest() (if it is called) |
| 27 // or the end of this object. | 21 // or the end of this object. |
| 28 // |render_frame_id| is used for displaying SafeBrowsing UI when necessary. | 22 // |render_frame_id| is used for displaying SafeBrowsing UI when necessary. |
| 29 SafeBrowsingURLLoaderThrottle(mojom::SafeBrowsing* safe_browsing, | 23 RendererURLLoaderThrottle(mojom::SafeBrowsing* safe_browsing, |
| 30 int render_frame_id); | 24 int render_frame_id); |
| 31 ~SafeBrowsingURLLoaderThrottle() override; | 25 ~RendererURLLoaderThrottle() override; |
| 32 | 26 |
| 33 // content::URLLoaderThrottle implementation. | 27 // content::URLLoaderThrottle implementation. |
| 34 void WillStartRequest(const GURL& url, | 28 void WillStartRequest(const GURL& url, |
| 35 int load_flags, | 29 int load_flags, |
| 36 content::ResourceType resource_type, | 30 content::ResourceType resource_type, |
| 37 bool* defer) override; | 31 bool* defer) override; |
| 38 void WillRedirectRequest(const net::RedirectInfo& redirect_info, | 32 void WillRedirectRequest(const net::RedirectInfo& redirect_info, |
| 39 bool* defer) override; | 33 bool* defer) override; |
| 40 void WillProcessResponse(bool* defer) override; | 34 void WillProcessResponse(bool* defer) override; |
| 41 | 35 |
| 42 private: | 36 private: |
| 43 void OnCheckUrlResult(bool safe); | 37 void OnCheckUrlResult(bool safe); |
| 44 | 38 |
| 45 void OnConnectionError(); | 39 void OnConnectionError(); |
| 46 | 40 |
| 47 mojom::SafeBrowsing* safe_browsing_; | 41 mojom::SafeBrowsing* safe_browsing_; |
| 48 const int render_frame_id_; | 42 const int render_frame_id_; |
| 49 | 43 |
| 50 mojom::SafeBrowsingUrlCheckerPtr url_checker_; | 44 mojom::SafeBrowsingUrlCheckerPtr url_checker_; |
| 51 | 45 |
| 52 size_t pending_checks_ = 0; | 46 size_t pending_checks_ = 0; |
| 53 bool blocked_ = false; | 47 bool blocked_ = false; |
| 54 | 48 |
| 55 base::WeakPtrFactory<SafeBrowsingURLLoaderThrottle> weak_factory_; | 49 base::WeakPtrFactory<RendererURLLoaderThrottle> weak_factory_; |
| 56 }; | 50 }; |
| 57 | 51 |
| 58 } // namespace safe_browsing | 52 } // namespace safe_browsing |
| 59 | 53 |
| 60 #endif // CHROME_RENDERER_SAFE_BROWSING_SAFE_BROWSING_URL_LOADER_THROTTLE_H_ | 54 #endif // CHROME_RENDERER_SAFE_BROWSING_RENDERER_URL_LOADER_THROTTLE_H_ |
| OLD | NEW |