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 ANDROID_WEBVIEW_BROWSER_SAFE_BROWSING_AW_URL_CHECKER_DELEGATE_IMPL_H_
6 #define ANDROID_WEBVIEW_BROWSER_SAFE_BROWSING_AW_URL_CHECKER_DELEGATE_IMPL_H_
7 
8 #include <string>
9 
10 #include "base/macros.h"
11 #include "base/memory/ref_counted.h"
12 #include "components/safe_browsing/core/browser/url_checker_delegate.h"
13 #include "content/public/browser/web_contents.h"
14 
15 namespace android_webview {
16 
17 class AwSafeBrowsingUIManager;
18 class AwSafeBrowsingAllowlistManager;
19 struct AwWebResourceRequest;
20 
21 class AwUrlCheckerDelegateImpl : public safe_browsing::UrlCheckerDelegate {
22  public:
23   // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.android_webview
24   enum class SafeBrowsingAction {
25     SHOW_INTERSTITIAL,
26     PROCEED,
27     BACK_TO_SAFETY,
28   };
29 
30   AwUrlCheckerDelegateImpl(
31       scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager>
32           database_manager,
33       scoped_refptr<AwSafeBrowsingUIManager> ui_manager,
34       AwSafeBrowsingAllowlistManager* allowlist_manager);
35 
36  private:
37   ~AwUrlCheckerDelegateImpl() override;
38 
39   // Implementation of UrlCheckerDelegate:
40   void MaybeDestroyPrerenderContents(
41       content::WebContents::OnceGetter web_contents_getter) override;
42   void StartDisplayingBlockingPageHelper(
43       const security_interstitials::UnsafeResource& resource,
44       const std::string& method,
45       const net::HttpRequestHeaders& headers,
46       bool is_main_frame,
47       bool has_user_gesture) override;
48   void StartObservingInteractionsForDelayedBlockingPageHelper(
49       const security_interstitials::UnsafeResource& resource,
50       bool is_main_frame) override;
51   bool IsUrlAllowlisted(const GURL& url) override;
52   bool ShouldSkipRequestCheck(const GURL& original_url,
53                               int frame_tree_node_id,
54                               int render_process_id,
55                               int render_frame_id,
56                               bool originated_from_service_worker) override;
57   void NotifySuspiciousSiteDetected(
58       const base::RepeatingCallback<content::WebContents*()>&
59           web_contents_getter) override;
60   const safe_browsing::SBThreatTypeSet& GetThreatTypes() override;
61   safe_browsing::SafeBrowsingDatabaseManager* GetDatabaseManager() override;
62   safe_browsing::BaseUIManager* GetUIManager() override;
63 
64   static void StartApplicationResponse(
65       scoped_refptr<AwSafeBrowsingUIManager> ui_manager,
66       const security_interstitials::UnsafeResource& resource,
67       const AwWebResourceRequest& request);
68 
69   // Follow the application's response to WebViewClient#onSafeBrowsingHit(). If
70   // the action is PROCEED or BACK_TO_SAFETY, then |reporting| will determine if
71   // we should send an extended report. Otherwise, |reporting| determines if we
72   // should allow showing the reporting checkbox or not.
73   static void DoApplicationResponse(
74       scoped_refptr<AwSafeBrowsingUIManager> ui_manager,
75       const security_interstitials::UnsafeResource& resource,
76       const AwWebResourceRequest& request,
77       SafeBrowsingAction action,
78       bool reporting);
79 
80   static void StartDisplayingDefaultBlockingPage(
81       scoped_refptr<AwSafeBrowsingUIManager> ui_manager,
82       const security_interstitials::UnsafeResource& resource);
83 
84   scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> database_manager_;
85   scoped_refptr<AwSafeBrowsingUIManager> ui_manager_;
86   safe_browsing::SBThreatTypeSet threat_types_;
87   AwSafeBrowsingAllowlistManager* allowlist_manager_;
88 
89   DISALLOW_COPY_AND_ASSIGN(AwUrlCheckerDelegateImpl);
90 };
91 
92 }  // namespace android_webview
93 
94 #endif  // ANDROID_WEBVIEW_BROWSER_SAFE_BROWSING_AW_URL_CHECKER_DELEGATE_IMPL_H_
95