| 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 #include "android_webview/browser/aw_safe_browsing_resource_throttle.h" | 5 #include "android_webview/browser/aw_safe_browsing_resource_throttle.h" |
| 6 | 6 |
| 7 #include <utility> |
| 8 |
| 7 #include "android_webview/browser/aw_safe_browsing_ui_manager.h" | 9 #include "android_webview/browser/aw_safe_browsing_ui_manager.h" |
| 8 #include "base/macros.h" | 10 #include "base/macros.h" |
| 9 #include "components/safe_browsing/base_resource_throttle.h" | 11 #include "components/safe_browsing/base_ui_manager.h" |
| 12 #include "components/safe_browsing/resource_throttle.h" |
| 10 #include "components/safe_browsing_db/database_manager.h" | 13 #include "components/safe_browsing_db/database_manager.h" |
| 11 #include "components/security_interstitials/content/unsafe_resource.h" | 14 #include "components/security_interstitials/content/unsafe_resource.h" |
| 15 #include "content/public/browser/browser_thread.h" |
| 12 #include "content/public/common/resource_type.h" | 16 #include "content/public/common/resource_type.h" |
| 13 #include "net/base/net_errors.h" | 17 #include "net/base/net_errors.h" |
| 14 #include "net/url_request/url_request.h" | 18 #include "net/url_request/url_request.h" |
| 15 | 19 |
| 16 namespace android_webview { | 20 namespace android_webview { |
| 17 | 21 |
| 18 // static | 22 namespace { |
| 19 AwSafeBrowsingResourceThrottle* AwSafeBrowsingResourceThrottle::MaybeCreate( | 23 |
| 24 void StartDisplayingBlockingPageOnUIThread( |
| 25 scoped_refptr<safe_browsing::BaseUIManager> ui_manager, |
| 26 const security_interstitials::UnsafeResource& resource, |
| 27 base::OnceClosure cancel_on_io_thread) { |
| 28 content::WebContents* web_contents = resource.web_contents_getter.Run(); |
| 29 if (web_contents) { |
| 30 ui_manager->DisplayBlockingPage(resource); |
| 31 return; |
| 32 } |
| 33 |
| 34 // Tab is gone or it's being prerendered. |
| 35 content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, |
| 36 std::move(cancel_on_io_thread)); |
| 37 } |
| 38 |
| 39 class AwSafeBrowsingResourceThrottleDelegate final |
| 40 : public safe_browsing::ResourceThrottle::Delegate { |
| 41 public: |
| 42 AwSafeBrowsingResourceThrottleDelegate() {} |
| 43 ~AwSafeBrowsingResourceThrottleDelegate() final {} |
| 44 |
| 45 void MaybeDestroyPrerenderContents(const net::URLRequest* request) final { |
| 46 // No prerender contents exist in the WebView, therefore none need to be |
| 47 // destroyed. |
| 48 } |
| 49 |
| 50 void StartDisplayingBlockingPage( |
| 51 const security_interstitials::UnsafeResource& resource, |
| 52 scoped_refptr<BaseUIManager> ui_manager, |
| 53 base::OnceClosure cancel_on_io_thread) final { |
| 54 content::BrowserThread::PostTask( |
| 55 content::BrowserThread::UI, FROM_HERE, |
| 56 base::BindOnce(&StartDisplayingBlockingPageOnUIThread, |
| 57 std::move(ui_manager), resource, |
| 58 std::move(cancel_on_io_thread))); |
| 59 } |
| 60 |
| 61 private: |
| 62 DISALLOW_COPY_AND_ASSIGN(AwSafeBrowsingResourceThrottleDelegate); |
| 63 }; |
| 64 |
| 65 } // namespace |
| 66 |
| 67 safe_browsing::ResourceThrottle* MaybeCreateAwSafeBrowsingResourceThrottle( |
| 20 net::URLRequest* request, | 68 net::URLRequest* request, |
| 21 content::ResourceType resource_type, | 69 content::ResourceType resource_type, |
| 22 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> database_manager, | 70 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> database_manager, |
| 23 scoped_refptr<AwSafeBrowsingUIManager> ui_manager) { | 71 scoped_refptr<AwSafeBrowsingUIManager> ui_manager) { |
| 24 if (database_manager->IsSupported()) { | 72 if (!database_manager->IsSupported()) |
| 25 return new AwSafeBrowsingResourceThrottle(request, resource_type, | 73 return nullptr; |
| 26 database_manager, ui_manager); | |
| 27 } | |
| 28 return nullptr; | |
| 29 } | |
| 30 | 74 |
| 31 AwSafeBrowsingResourceThrottle::AwSafeBrowsingResourceThrottle( | 75 return new safe_browsing::ResourceThrottle( |
| 32 net::URLRequest* request, | 76 request, resource_type, database_manager, ui_manager, |
| 33 content::ResourceType resource_type, | 77 new AwSafeBrowsingResourceThrottleDelegate()); |
| 34 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> database_manager, | |
| 35 scoped_refptr<AwSafeBrowsingUIManager> ui_manager) | |
| 36 : safe_browsing::BaseResourceThrottle(request, | |
| 37 resource_type, | |
| 38 database_manager, | |
| 39 ui_manager) {} | |
| 40 | |
| 41 AwSafeBrowsingResourceThrottle::~AwSafeBrowsingResourceThrottle() {} | |
| 42 | |
| 43 void AwSafeBrowsingResourceThrottle::CancelResourceLoad() { | |
| 44 CancelWithError(net::ERR_FAILED); | |
| 45 } | 78 } |
| 46 | 79 |
| 47 } // namespace android_webview | 80 } // namespace android_webview |
| OLD | NEW |