| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_BROWSER_LOADER_SAFE_BROWSING_RESOURCE_THROTTLE_H_ | 5 #ifndef CHROME_BROWSER_LOADER_SAFE_BROWSING_RESOURCE_THROTTLE_H_ |
| 6 #define CHROME_BROWSER_LOADER_SAFE_BROWSING_RESOURCE_THROTTLE_H_ | 6 #define CHROME_BROWSER_LOADER_SAFE_BROWSING_RESOURCE_THROTTLE_H_ |
| 7 | 7 |
| 8 #include <string> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/macros.h" | |
| 12 #include "base/memory/ref_counted.h" | |
| 13 #include "base/time/time.h" | |
| 14 #include "base/timer/timer.h" | |
| 15 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | |
| 16 #include "chrome/browser/safe_browsing/ui_manager.h" | |
| 17 #include "components/safe_browsing/base_resource_throttle.h" | |
| 18 #include "components/safe_browsing/base_ui_manager.h" | |
| 19 #include "components/safe_browsing_db/database_manager.h" | |
| 20 #include "components/security_interstitials/content/unsafe_resource.h" | |
| 21 #include "content/public/browser/resource_throttle.h" | |
| 22 #include "content/public/common/resource_type.h" | 8 #include "content/public/common/resource_type.h" |
| 23 #include "url/gurl.h" | |
| 24 | |
| 25 namespace content { | |
| 26 class ResourceRequestInfo; | |
| 27 } | |
| 28 | 9 |
| 29 namespace net { | 10 namespace net { |
| 30 class URLRequest; | 11 class URLRequest; |
| 31 } | 12 } |
| 32 | 13 |
| 33 namespace safe_browsing { | 14 namespace safe_browsing { |
| 34 class BaseUIManager; | 15 class ResourceThrottle; |
| 16 class SafeBrowsingService; |
| 35 } | 17 } |
| 36 | 18 |
| 37 // SafeBrowsingResourceThrottle functions as its base class | 19 // SafeBrowsingResourceThrottle functions as its base class |
| 38 // safe_browsing::BaseResourceThrottle, but dispatches to either the local or | 20 // safe_browsing::BaseResourceThrottle, but dispatches to either the local or |
| 39 // remote SafeBrowsingDatabaseManager, depending on if running on desktop or | 21 // remote SafeBrowsingDatabaseManager, depending on if running on desktop or |
| 40 // mobile. It also has its own chrome-specific prerender check of redirect URLs | 22 // mobile. It also has its own chrome-specific prerender check of redirect URLs |
| 41 // inside StartDisplayingBlockingPage(). | 23 // inside StartDisplayingBlockingPage(). |
| 42 // | 24 // |
| 43 // See also safe_browsing::BaseResourceThrottle for details on how the safe | 25 // See also safe_browsing::BaseResourceThrottle for details on how the safe |
| 44 // browsing check occurs. | 26 // browsing check occurs. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 55 // | 37 // |
| 56 // On mobile (ifdef SAFE_BROWSING_DB_REMOTE): | 38 // On mobile (ifdef SAFE_BROWSING_DB_REMOTE): |
| 57 // ----------------------------------------- | 39 // ----------------------------------------- |
| 58 // The check is started and runs in parallel with the resource load. If the | 40 // The check is started and runs in parallel with the resource load. If the |
| 59 // check is not complete by the time the headers are loaded, the request is | 41 // check is not complete by the time the headers are loaded, the request is |
| 60 // suspended until the URL is classified. We let the headers load on mobile | 42 // suspended until the URL is classified. We let the headers load on mobile |
| 61 // since the RemoteSafeBrowsingDatabase checks always have some non-zero | 43 // since the RemoteSafeBrowsingDatabase checks always have some non-zero |
| 62 // latency -- there no synchronous pass. This parallelism helps | 44 // latency -- there no synchronous pass. This parallelism helps |
| 63 // performance. Redirects are handled the same way as desktop so they | 45 // performance. Redirects are handled the same way as desktop so they |
| 64 // always defer. | 46 // always defer. |
| 65 class SafeBrowsingResourceThrottle | |
| 66 : public safe_browsing::BaseResourceThrottle { | |
| 67 public: | |
| 68 // Will construct a SafeBrowsingResourceThrottle, or return NULL | |
| 69 // if on Android and not in the field trial. | |
| 70 static SafeBrowsingResourceThrottle* MaybeCreate( | |
| 71 net::URLRequest* request, | |
| 72 content::ResourceType resource_type, | |
| 73 safe_browsing::SafeBrowsingService* sb_service); | |
| 74 | 47 |
| 75 const char* GetNameForLogging() const override; | 48 extern safe_browsing::ResourceThrottle* MaybeCreateSafeBrowsingResourceThrottle( |
| 76 | 49 net::URLRequest* request, |
| 77 protected: | 50 content::ResourceType resource_type, |
| 78 SafeBrowsingResourceThrottle(const net::URLRequest* request, | 51 safe_browsing::SafeBrowsingService* sb_service); |
| 79 content::ResourceType resource_type, | |
| 80 safe_browsing::SafeBrowsingService* sb_service); | |
| 81 | |
| 82 private: | |
| 83 ~SafeBrowsingResourceThrottle() override; | |
| 84 | |
| 85 // This posts a task to destroy prerender contents | |
| 86 void MaybeDestroyPrerenderContents( | |
| 87 const content::ResourceRequestInfo* info) override; | |
| 88 | |
| 89 void StartDisplayingBlockingPageHelper( | |
| 90 security_interstitials::UnsafeResource resource) override; | |
| 91 | |
| 92 // Starts displaying the safe browsing interstitial page if it's not | |
| 93 // prerendering. Called on the UI thread. | |
| 94 static void StartDisplayingBlockingPage( | |
| 95 const base::WeakPtr<safe_browsing::BaseResourceThrottle>& throttle, | |
| 96 scoped_refptr<safe_browsing::BaseUIManager> ui_manager, | |
| 97 const security_interstitials::UnsafeResource& resource); | |
| 98 | |
| 99 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingResourceThrottle); | |
| 100 }; | |
| 101 | 52 |
| 102 #endif // CHROME_BROWSER_LOADER_SAFE_BROWSING_RESOURCE_THROTTLE_H_ | 53 #endif // CHROME_BROWSER_LOADER_SAFE_BROWSING_RESOURCE_THROTTLE_H_ |
| OLD | NEW |