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_SAFE_BROWSING_URL_CHECKER_IMPL_H_ |
| 6 #define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_URL_CHECKER_IMPL_H_ |
| 7 |
| 8 #include <vector> |
| 9 |
| 10 #include "base/macros.h" |
| 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/timer/timer.h" |
| 14 #include "chrome/common/safe_browsing.mojom.h" |
| 15 #include "components/safe_browsing_db/database_manager.h" |
| 16 #include "content/public/common/resource_type.h" |
| 17 #include "url/gurl.h" |
| 18 |
| 19 namespace content { |
| 20 class WebContents; |
| 21 } |
| 22 |
| 23 namespace security_interstitials { |
| 24 struct UnsafeResource; |
| 25 } |
| 26 |
| 27 namespace safe_browsing { |
| 28 |
| 29 class SafeBrowsingUIManager; |
| 30 class BaseUIManager; |
| 31 |
| 32 // A SafeBrowsingUrlCheckerImpl instance is used to perform SafeBrowsing check |
| 33 // for a URL and its redirect URLs. It implements Mojo interface so that it can |
| 34 // be used to handle queries from renderers. But it is also used to handle |
| 35 // queries from the browser. In that case, the public methods are called |
| 36 // directly instead of through Mojo. |
| 37 // Used when --enable-network-service is in effect. |
| 38 // |
| 39 // TODO(yzshen): Handle the case where SafeBrowsing is not enabled, or |
| 40 // !database_manager()->IsSupported(). |
| 41 // TODO(yzshen): Make sure it also works on Andorid. |
| 42 // TODO(yzshen): Do all the logging like what BaseResourceThrottle does. |
| 43 class SafeBrowsingUrlCheckerImpl : public chrome::mojom::SafeBrowsingUrlChecker, |
| 44 public SafeBrowsingDatabaseManager::Client { |
| 45 public: |
| 46 SafeBrowsingUrlCheckerImpl( |
| 47 int load_flags, |
| 48 content::ResourceType resource_type, |
| 49 scoped_refptr<SafeBrowsingDatabaseManager> database_manager, |
| 50 scoped_refptr<SafeBrowsingUIManager> ui_manager, |
| 51 const base::Callback<content::WebContents*()>& web_contents_getter); |
| 52 |
| 53 ~SafeBrowsingUrlCheckerImpl() override; |
| 54 |
| 55 // chrome::mojom::SafeBrowsingUrlChecker implementation. |
| 56 void CheckUrl(const GURL& url, CheckUrlCallback callback) override; |
| 57 |
| 58 private: |
| 59 // SafeBrowsingDatabaseManager::Client implementation: |
| 60 void OnCheckBrowseUrlResult(const GURL& url, |
| 61 SBThreatType threat_type, |
| 62 const ThreatMetadata& metadata) override; |
| 63 |
| 64 static void StartDisplayingBlockingPage( |
| 65 const base::WeakPtr<SafeBrowsingUrlCheckerImpl>& checker, |
| 66 scoped_refptr<BaseUIManager> ui_manager, |
| 67 const security_interstitials::UnsafeResource& resource); |
| 68 |
| 69 void OnCheckUrlTimeout(); |
| 70 |
| 71 void ProcessUrls(); |
| 72 |
| 73 void BlockAndProcessUrls(); |
| 74 |
| 75 void OnBlockingPageComplete(bool proceed); |
| 76 |
| 77 enum State { |
| 78 // Haven't started checking or checking is complete. |
| 79 STATE_NONE, |
| 80 // We have one outstanding URL-check. |
| 81 STATE_CHECKING_URL, |
| 82 // We're displaying a blocking page. |
| 83 STATE_DISPLAYING_BLOCKING_PAGE, |
| 84 // The blocking page has returned *not* to proceed. |
| 85 STATE_BLOCKED |
| 86 }; |
| 87 |
| 88 const int load_flags_; |
| 89 const content::ResourceType resource_type_; |
| 90 base::Callback<content::WebContents*()> web_contents_getter_; |
| 91 scoped_refptr<SafeBrowsingDatabaseManager> database_manager_; |
| 92 scoped_refptr<BaseUIManager> ui_manager_; |
| 93 |
| 94 // The redirect chain for this resource, including the original URL and |
| 95 // subsequent redirect URLs. |
| 96 std::vector<GURL> urls_; |
| 97 // Callbacks corresponding to |urls_| to report check results. |urls_| and |
| 98 // |callbacks_| are always of the same size. |
| 99 std::vector<CheckUrlCallback> callbacks_; |
| 100 // |urls_| before |next_index_| have been checked. If |next_index_| is smaller |
| 101 // than the size of |urls_|, the URL at |next_index_| is being processed. |
| 102 size_t next_index_ = 0; |
| 103 |
| 104 State state_ = STATE_NONE; |
| 105 |
| 106 // Timer to abort the SafeBrowsing check if it takes too long. |
| 107 base::OneShotTimer timer_; |
| 108 |
| 109 base::WeakPtrFactory<SafeBrowsingUrlCheckerImpl> weak_factory_; |
| 110 |
| 111 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingUrlCheckerImpl); |
| 112 }; |
| 113 |
| 114 } // namespace safe_browsing |
| 115 |
| 116 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_URL_CHECKER_IMPL_H_ |
OLD | NEW |