Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Side by Side Diff: android_webview/browser/aw_safe_browsing_resource_throttle.cc

Issue 2876473003: [ABANDONED] [WIP] Refactor SafeBrowsingResourceThrottle in preparation for WebSocket (Closed)
Patch Set: Minor fixes Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/memory/ptr_util.h"
12 #include "components/safe_browsing/base_ui_manager.h"
13 #include "components/safe_browsing/resource_throttle.h"
10 #include "components/safe_browsing_db/database_manager.h" 14 #include "components/safe_browsing_db/database_manager.h"
11 #include "components/security_interstitials/content/unsafe_resource.h" 15 #include "components/security_interstitials/content/unsafe_resource.h"
16 #include "content/public/browser/browser_thread.h"
12 #include "content/public/common/resource_type.h" 17 #include "content/public/common/resource_type.h"
13 #include "net/base/net_errors.h" 18 #include "net/base/net_errors.h"
14 #include "net/url_request/url_request.h" 19 #include "net/url_request/url_request.h"
15 20
16 namespace android_webview { 21 namespace android_webview {
17 22
18 // static 23 namespace {
19 AwSafeBrowsingResourceThrottle* AwSafeBrowsingResourceThrottle::MaybeCreate( 24
25 void StartDisplayingBlockingPageOnUIThread(
26 scoped_refptr<safe_browsing::BaseUIManager> ui_manager,
27 const security_interstitials::UnsafeResource& resource,
28 base::OnceClosure cancel_on_io_thread) {
29 content::WebContents* web_contents = resource.web_contents_getter.Run();
30 if (web_contents) {
31 ui_manager->DisplayBlockingPage(resource);
32 return;
33 }
34
35 // Tab is gone or it's being prerendered.
36 content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE,
37 std::move(cancel_on_io_thread));
38 }
39
40 class AwSafeBrowsingResourceThrottleDelegate final
41 : public safe_browsing::ResourceThrottle::Delegate {
42 public:
43 AwSafeBrowsingResourceThrottleDelegate() {}
44 ~AwSafeBrowsingResourceThrottleDelegate() final {}
45
46 void MaybeDestroyPrerenderContents(
47 const WebContentsGetter& web_contents_getter) final {
48 // No prerender contents exist in the WebView, therefore none need to be
49 // destroyed.
50 }
51
52 void StartDisplayingBlockingPage(
53 const security_interstitials::UnsafeResource& resource,
54 scoped_refptr<safe_browsing::BaseUIManager> ui_manager,
55 base::OnceClosure cancel_on_io_thread) final {
56 content::BrowserThread::PostTask(
57 content::BrowserThread::UI, FROM_HERE,
58 base::BindOnce(&StartDisplayingBlockingPageOnUIThread,
59 std::move(ui_manager), resource,
60 std::move(cancel_on_io_thread)));
61 }
62
63 private:
64 DISALLOW_COPY_AND_ASSIGN(AwSafeBrowsingResourceThrottleDelegate);
65 };
66
67 } // namespace
68
69 std::unique_ptr<content::ResourceThrottle>
70 MaybeCreateAwSafeBrowsingResourceThrottle(
20 net::URLRequest* request, 71 net::URLRequest* request,
21 content::ResourceType resource_type, 72 content::ResourceType resource_type,
22 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> database_manager, 73 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> database_manager,
23 scoped_refptr<AwSafeBrowsingUIManager> ui_manager) { 74 scoped_refptr<AwSafeBrowsingUIManager> ui_manager) {
24 if (database_manager->IsSupported()) { 75 if (!database_manager->IsSupported())
25 return new AwSafeBrowsingResourceThrottle(request, resource_type, 76 return nullptr;
26 database_manager, ui_manager);
27 }
28 return nullptr;
29 }
30 77
31 AwSafeBrowsingResourceThrottle::AwSafeBrowsingResourceThrottle( 78 return base::MakeUnique<safe_browsing::ResourceThrottle>(
32 net::URLRequest* request, 79 request, resource_type, database_manager, ui_manager,
33 content::ResourceType resource_type, 80 base::MakeUnique<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 } 81 }
46 82
47 } // namespace android_webview 83 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698