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 * |
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' | 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
23 * THE POSSIBILITY OF SUCH DAMAGE. | 23 * THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #pragma once | 26 #pragma once |
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" |
| 33 #import "WebsitePoliciesData.h" |
| 34 #import <WebCore/URL.h> |
| 35 #import <WebCore/URLHash.h> |
| 36 #import <wtf/HashSet.h> |
| 37 #import <wtf/WeakPtr.h> |
| 38 |
32 @class WKWebView; | 39 @class WKWebView; |
33 | 40 |
| 41 namespace API { |
| 42 class NavigationAction; |
| 43 } |
| 44 |
34 namespace WebKit { | 45 namespace WebKit { |
| 46 |
| 47 class WebFramePolicyListenerProxy; |
35 | 48 |
36 class SafeBrowsingController { | 49 class SafeBrowsingController { |
37 public: | 50 public: |
38 explicit SafeBrowsingController(WKWebView *); | 51 explicit SafeBrowsingController(WKWebView *); |
39 ~SafeBrowsingController(); | 52 ~SafeBrowsingController(); |
40 | 53 |
| 54 using NavigationPolicyDecider = WTF::Function<void(WTF::Function<void(WKNavi
gationActionPolicy, std::optional<WebsitePoliciesData>&&)>&&)>; |
| 55 |
| 56 void checkURL(Ref<API::NavigationAction>&&, NavigationPolicyDecider&&, Ref<W
ebFramePolicyListenerProxy>&&); |
| 57 |
41 // Just to make m_webView get used somewhere. | 58 // Just to make m_webView get used somewhere. |
42 void placeholder(); | 59 void placeholder(); |
43 | 60 |
44 private: | 61 private: |
| 62 struct SafeBrowsingCheck { |
| 63 SafeBrowsingCheck(Ref<WebFramePolicyListenerProxy>&& listener, Ref<API::
NavigationAction>&& navigationAction) |
| 64 : listener(WTFMove(listener)) |
| 65 , navigationAction(WTFMove(navigationAction)) |
| 66 { |
| 67 } |
| 68 |
| 69 std::optional<WKNavigationActionPolicy> navigationPolicyDecision; |
| 70 std::optional<WebsitePoliciesData> websitePoliciesData; |
| 71 |
| 72 // FIXME: Use an std::optional<EnumType> for the SB result. |
| 73 // Using std::optional<bool> is too confusing for readability. |
| 74 bool safeBrowsingLookUpComplete = false; |
| 75 bool isUnsafe = false; |
| 76 Ref<WebFramePolicyListenerProxy> listener; |
| 77 Ref<API::NavigationAction> navigationAction; |
| 78 }; |
| 79 |
| 80 void receivedNavigationPolicyDecision(SafeBrowsingCheck&, WKNavigationAction
Policy, std::optional<WebsitePoliciesData>&&); |
| 81 |
| 82 // Takes a |SafeBrowsingCheck*| rather than |SafeBrowsingCheck&| since the |
| 83 // check might have already been destroyed, e.g., if the embedder's navigati
on |
| 84 // policy response was to ignore the navigation. |
| 85 void receivedSafeBrowsingDecision(SafeBrowsingCheck*, bool isUnsafe); |
| 86 |
| 87 void maybeFinishedCheck(SafeBrowsingCheck&); |
| 88 |
45 WKWebView *m_webView; | 89 WKWebView *m_webView; |
| 90 HashSet<std::unique_ptr<SafeBrowsingCheck>> m_checks; |
| 91 HashSet<WebCore::URL> m_warningIgnoredUrls; |
| 92 WeakPtrFactory<SafeBrowsingController> m_weakPtrFactory; |
| 93 static const char* s_warningPageUrl; |
46 }; | 94 }; |
47 | 95 |
48 } // namespace WebKit | 96 } // namespace WebKit |
49 | 97 |
50 #endif // WK_API_ENABLED | 98 #endif // WK_API_ENABLED |
LEFT | RIGHT |