OLD | NEW |
(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 #ifndef CHROME_BROWSER_SAFE_BROWSING_BROWSER_URL_LOADER_THROTTLE_H_ |
| 6 #define CHROME_BROWSER_SAFE_BROWSING_BROWSER_URL_LOADER_THROTTLE_H_ |
| 7 |
| 8 #include <memory> |
| 9 |
| 10 #include "base/callback.h" |
| 11 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" |
| 13 #include "content/public/common/url_loader_throttle.h" |
| 14 |
| 15 namespace content { |
| 16 class WebContents; |
| 17 } |
| 18 |
| 19 namespace safe_browsing { |
| 20 |
| 21 class SafeBrowsingDatabaseManager; |
| 22 class SafeBrowsingUIManager; |
| 23 class SafeBrowsingUrlCheckerImpl; |
| 24 |
| 25 // BrowserURLLoaderThrottle is used in the browser process to query |
| 26 // SafeBrowsing to determine whether a URL and also its redirect URLs are safe |
| 27 // to load. It defers response processing until all URL checks are completed; |
| 28 // cancels the load if any URLs turn out to be bad. |
| 29 // Used when --enable-network-service is in effect. |
| 30 class BrowserURLLoaderThrottle : public content::URLLoaderThrottle { |
| 31 public: |
| 32 // |web_contents_getter| is used for displaying SafeBrowsing UI when |
| 33 // necessary. |
| 34 BrowserURLLoaderThrottle( |
| 35 scoped_refptr<SafeBrowsingDatabaseManager> database_manager, |
| 36 scoped_refptr<SafeBrowsingUIManager> ui_manager, |
| 37 const base::Callback<content::WebContents*()>& web_contents_getter); |
| 38 ~BrowserURLLoaderThrottle() override; |
| 39 |
| 40 // content::URLLoaderThrottle implementation. |
| 41 void WillStartRequest(const GURL& url, |
| 42 int load_flags, |
| 43 content::ResourceType resource_type, |
| 44 bool* defer) override; |
| 45 void WillRedirectRequest(const net::RedirectInfo& redirect_info, |
| 46 bool* defer) override; |
| 47 void WillProcessResponse(bool* defer) override; |
| 48 |
| 49 private: |
| 50 void OnCheckUrlResult(bool safe); |
| 51 |
| 52 // The following two members stay valid until |url_checker_| is created. |
| 53 scoped_refptr<SafeBrowsingDatabaseManager> database_manager_; |
| 54 scoped_refptr<SafeBrowsingUIManager> ui_manager_; |
| 55 |
| 56 base::Callback<content::WebContents*()> web_contents_getter_; |
| 57 |
| 58 std::unique_ptr<SafeBrowsingUrlCheckerImpl> url_checker_; |
| 59 |
| 60 size_t pending_checks_ = 0; |
| 61 bool blocked_ = false; |
| 62 |
| 63 DISALLOW_COPY_AND_ASSIGN(BrowserURLLoaderThrottle); |
| 64 }; |
| 65 |
| 66 } // namespace safe_browsing |
| 67 |
| 68 #endif // CHROME_BROWSER_SAFE_BROWSING_BROWSER_URL_LOADER_THROTTLE_H_ |
OLD | NEW |