| Index: android_webview/browser/aw_safe_browsing_resource_throttle.cc
|
| diff --git a/android_webview/browser/aw_safe_browsing_resource_throttle.cc b/android_webview/browser/aw_safe_browsing_resource_throttle.cc
|
| index b77c97d9b14174bbddb37d76e943a3b162ff7774..161f4e9a55a6d995539bc17efff75e115c15692a 100644
|
| --- a/android_webview/browser/aw_safe_browsing_resource_throttle.cc
|
| +++ b/android_webview/browser/aw_safe_browsing_resource_throttle.cc
|
| @@ -4,44 +4,77 @@
|
|
|
| #include "android_webview/browser/aw_safe_browsing_resource_throttle.h"
|
|
|
| +#include <utility>
|
| +
|
| #include "android_webview/browser/aw_safe_browsing_ui_manager.h"
|
| #include "base/macros.h"
|
| -#include "components/safe_browsing/base_resource_throttle.h"
|
| +#include "components/safe_browsing/base_ui_manager.h"
|
| +#include "components/safe_browsing/resource_throttle.h"
|
| #include "components/safe_browsing_db/database_manager.h"
|
| #include "components/security_interstitials/content/unsafe_resource.h"
|
| +#include "content/public/browser/browser_thread.h"
|
| #include "content/public/common/resource_type.h"
|
| #include "net/base/net_errors.h"
|
| #include "net/url_request/url_request.h"
|
|
|
| namespace android_webview {
|
|
|
| -// static
|
| -AwSafeBrowsingResourceThrottle* AwSafeBrowsingResourceThrottle::MaybeCreate(
|
| - net::URLRequest* request,
|
| - content::ResourceType resource_type,
|
| - scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> database_manager,
|
| - scoped_refptr<AwSafeBrowsingUIManager> ui_manager) {
|
| - if (database_manager->IsSupported()) {
|
| - return new AwSafeBrowsingResourceThrottle(request, resource_type,
|
| - database_manager, ui_manager);
|
| +namespace {
|
| +
|
| +void StartDisplayingBlockingPageOnUIThread(
|
| + scoped_refptr<safe_browsing::BaseUIManager> ui_manager,
|
| + const security_interstitials::UnsafeResource& resource,
|
| + base::OnceClosure cancel_on_io_thread) {
|
| + content::WebContents* web_contents = resource.web_contents_getter.Run();
|
| + if (web_contents) {
|
| + ui_manager->DisplayBlockingPage(resource);
|
| + return;
|
| }
|
| - return nullptr;
|
| +
|
| + // Tab is gone or it's being prerendered.
|
| + content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE,
|
| + std::move(cancel_on_io_thread));
|
| }
|
|
|
| -AwSafeBrowsingResourceThrottle::AwSafeBrowsingResourceThrottle(
|
| +class AwSafeBrowsingResourceThrottleDelegate final
|
| + : public safe_browsing::ResourceThrottle::Delegate {
|
| + public:
|
| + AwSafeBrowsingResourceThrottleDelegate() {}
|
| + ~AwSafeBrowsingResourceThrottleDelegate() final {}
|
| +
|
| + void MaybeDestroyPrerenderContents(const net::URLRequest* request) final {
|
| + // No prerender contents exist in the WebView, therefore none need to be
|
| + // destroyed.
|
| + }
|
| +
|
| + void StartDisplayingBlockingPage(
|
| + const security_interstitials::UnsafeResource& resource,
|
| + scoped_refptr<BaseUIManager> ui_manager,
|
| + base::OnceClosure cancel_on_io_thread) final {
|
| + content::BrowserThread::PostTask(
|
| + content::BrowserThread::UI, FROM_HERE,
|
| + base::BindOnce(&StartDisplayingBlockingPageOnUIThread,
|
| + std::move(ui_manager), resource,
|
| + std::move(cancel_on_io_thread)));
|
| + }
|
| +
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(AwSafeBrowsingResourceThrottleDelegate);
|
| +};
|
| +
|
| +} // namespace
|
| +
|
| +safe_browsing::ResourceThrottle* MaybeCreateAwSafeBrowsingResourceThrottle(
|
| net::URLRequest* request,
|
| content::ResourceType resource_type,
|
| scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> database_manager,
|
| - scoped_refptr<AwSafeBrowsingUIManager> ui_manager)
|
| - : safe_browsing::BaseResourceThrottle(request,
|
| - resource_type,
|
| - database_manager,
|
| - ui_manager) {}
|
| -
|
| -AwSafeBrowsingResourceThrottle::~AwSafeBrowsingResourceThrottle() {}
|
| + scoped_refptr<AwSafeBrowsingUIManager> ui_manager) {
|
| + if (!database_manager->IsSupported())
|
| + return nullptr;
|
|
|
| -void AwSafeBrowsingResourceThrottle::CancelResourceLoad() {
|
| - CancelWithError(net::ERR_FAILED);
|
| + return new safe_browsing::ResourceThrottle(
|
| + request, resource_type, database_manager, ui_manager,
|
| + new AwSafeBrowsingResourceThrottleDelegate());
|
| }
|
|
|
| } // namespace android_webview
|
|
|