LEFT | RIGHT |
1 /* | 1 /* |
2 * Copyright (C) 2018 Google Inc. All rights reserved. | 2 * Copyright (C) 2018 Google LLC. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
12 * | 12 * |
(...skipping 14 matching lines...) Expand all Loading... |
27 | 27 |
28 #import "WKFoundation.h" | 28 #import "WKFoundation.h" |
29 | 29 |
30 #if WK_API_ENABLED | 30 #if WK_API_ENABLED |
31 | 31 |
32 #import "WKNavigationDelegatePrivate.h" | 32 #import "WKNavigationDelegatePrivate.h" |
33 #import "WebsitePoliciesData.h" | 33 #import "WebsitePoliciesData.h" |
34 #import <WebCore/URL.h> | 34 #import <WebCore/URL.h> |
35 #import <WebCore/URLHash.h> | 35 #import <WebCore/URLHash.h> |
36 #import <wtf/HashSet.h> | 36 #import <wtf/HashSet.h> |
| 37 #import <wtf/WeakPtr.h> |
37 | 38 |
38 @class WKWebView; | 39 @class WKWebView; |
39 | 40 |
40 namespace API { | 41 namespace API { |
41 class NavigationAction; | 42 class NavigationAction; |
42 } | 43 } |
43 | 44 |
44 namespace WebKit { | 45 namespace WebKit { |
45 | 46 |
46 class WebFramePolicyListenerProxy; | 47 class WebFramePolicyListenerProxy; |
47 | 48 |
48 class SafeBrowsingController { | 49 class SafeBrowsingController { |
49 public: | 50 public: |
50 explicit SafeBrowsingController(WKWebView *); | 51 explicit SafeBrowsingController(WKWebView *); |
51 ~SafeBrowsingController(); | 52 ~SafeBrowsingController(); |
52 | 53 |
53 using NavigationPolicyDecider = WTF::Function<void(WTF::Function<void(WKNavi
gationActionPolicy, std::optional<WebsitePoliciesData>&&)>&&)>; | 54 using NavigationPolicyDecider = WTF::Function<void(WTF::Function<void(WKNavi
gationActionPolicy, std::optional<WebsitePoliciesData>&&)>&&)>; |
54 | 55 |
55 void checkURL(Ref<API::NavigationAction>&&, NavigationPolicyDecider&&, Ref<W
ebFramePolicyListenerProxy>&& listener); | 56 void checkURL(Ref<API::NavigationAction>&&, NavigationPolicyDecider&&, Ref<W
ebFramePolicyListenerProxy>&&); |
56 | |
57 // Just to make m_webView get used somewhere. | |
58 void placeholder(); | |
59 | 57 |
60 private: | 58 private: |
| 59 enum class SafeBrowsingResult { Safe, Unsafe }; |
61 struct SafeBrowsingCheck { | 60 struct SafeBrowsingCheck { |
62 SafeBrowsingCheck(Ref<WebFramePolicyListenerProxy>&& listener, Ref<API::
NavigationAction>&& navigationAction) | 61 SafeBrowsingCheck(Ref<WebFramePolicyListenerProxy>&& listener, Ref<API::
NavigationAction>&& navigationAction) |
63 : listener(WTFMove(listener)) | 62 : listener(WTFMove(listener)) |
64 , navigationAction(WTFMove(navigationAction)) | 63 , navigationAction(WTFMove(navigationAction)) |
65 { | 64 { |
66 } | 65 } |
67 | 66 |
68 std::optional<WKNavigationActionPolicy> navigationPolicyDecision; | 67 std::optional<WKNavigationActionPolicy> navigationPolicyDecision; |
69 std::optional<WebsitePoliciesData> websitePoliciesData; | 68 std::optional<WebsitePoliciesData> websitePoliciesData; |
70 | 69 std::optional<SafeBrowsingResult> safeBrowsingResult; |
71 // FIXME: Use an std::optional<EnumType> for the SB result. | |
72 // Using std::optional<bool> is too confusing for readability. | |
73 bool safeBrowsingLookUpComplete = false; | |
74 bool isUnsafe = false; | |
75 Ref<WebFramePolicyListenerProxy> listener; | 70 Ref<WebFramePolicyListenerProxy> listener; |
76 Ref<API::NavigationAction> navigationAction; | 71 Ref<API::NavigationAction> navigationAction; |
77 }; | 72 }; |
78 | 73 |
79 void receivedNavigationPolicyDecision(SafeBrowsingCheck&, WKNavigationAction
Policy, std::optional<WebsitePoliciesData>&&); | 74 void receivedNavigationPolicyDecision(SafeBrowsingCheck&, WKNavigationAction
Policy, std::optional<WebsitePoliciesData>&&); |
80 | 75 |
81 // Takes a |SafeBrowsingCheck*| rather than |SafeBrowsingCheck&| since the | 76 // Takes a |SafeBrowsingCheck*| rather than |SafeBrowsingCheck&| since the |
82 // check might have already been destroyed, e.g., if the embedder's navigati
on | 77 // check might have already been destroyed, e.g., if the embedder's navigati
on |
83 // policy response was to ignore the navigation. | 78 // policy response was to ignore the navigation. |
84 void receivedSafeBrowsingDecision(SafeBrowsingCheck*, bool isUnsafe); | 79 void receivedSafeBrowsingResult(SafeBrowsingCheck*, SafeBrowsingResult); |
85 | 80 |
86 void maybeFinishedCheck(SafeBrowsingCheck&); | 81 void maybeFinishedCheck(SafeBrowsingCheck&); |
87 | 82 |
88 WKWebView *m_webView; | 83 WKWebView *m_webView; |
89 HashSet<std::unique_ptr<SafeBrowsingCheck>> m_checks; | 84 HashSet<std::unique_ptr<SafeBrowsingCheck>> m_checks; |
90 HashSet<WebCore::URL> m_warningIgnoredUrls; | 85 HashSet<WebCore::URL> m_warningIgnoredUrls; |
| 86 WeakPtrFactory<SafeBrowsingController> m_weakPtrFactory; |
91 static const char* s_warningPageUrl; | 87 static const char* s_warningPageUrl; |
92 }; | 88 }; |
93 | 89 |
94 } // namespace WebKit | 90 } // namespace WebKit |
95 | 91 |
96 #endif // WK_API_ENABLED | 92 #endif // WK_API_ENABLED |
LEFT | RIGHT |