LEFT | RIGHT |
1 /* | 1 /* |
2 * Copyright (C) 2014-2016 Apple Inc. All rights reserved. | 2 * Copyright (C) 2014-2016 Apple Inc. 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 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 #import "WebNavigationState.h" | 60 #import "WebNavigationState.h" |
61 #import "WebPageProxy.h" | 61 #import "WebPageProxy.h" |
62 #import "WebProcessProxy.h" | 62 #import "WebProcessProxy.h" |
63 #import "WebProtectionSpace.h" | 63 #import "WebProtectionSpace.h" |
64 #import "_WKErrorRecoveryAttempting.h" | 64 #import "_WKErrorRecoveryAttempting.h" |
65 #import "_WKFrameHandleInternal.h" | 65 #import "_WKFrameHandleInternal.h" |
66 #import "_WKRenderingProgressEventsInternal.h" | 66 #import "_WKRenderingProgressEventsInternal.h" |
67 #import "_WKSameDocumentNavigationTypeInternal.h" | 67 #import "_WKSameDocumentNavigationTypeInternal.h" |
68 #import "_WKWebsitePoliciesInternal.h" | 68 #import "_WKWebsitePoliciesInternal.h" |
69 #import <WebCore/Credential.h> | 69 #import <WebCore/Credential.h> |
| 70 #import <WebCore/SSLKeyGenerator.h> |
70 #import <WebCore/SecurityOriginData.h> | 71 #import <WebCore/SecurityOriginData.h> |
71 #import <WebCore/SerializedCryptoKeyWrap.h> | 72 #import <WebCore/SerializedCryptoKeyWrap.h> |
72 #import <WebCore/URL.h> | 73 #import <WebCore/URL.h> |
73 #import <wtf/BlockPtr.h> | 74 #import <wtf/BlockPtr.h> |
74 #import <wtf/NeverDestroyed.h> | 75 #import <wtf/NeverDestroyed.h> |
75 | 76 |
76 #if HAVE(APP_LINKS) | 77 #if HAVE(APP_LINKS) |
77 #import <pal/spi/cocoa/LaunchServicesSPI.h> | 78 #import <pal/spi/cocoa/LaunchServicesSPI.h> |
78 #endif | 79 #endif |
79 | 80 |
(...skipping 10 matching lines...) Expand all Loading... |
90 static NeverDestroyed<HashMap<WebPageProxy*, NavigationState*>> navigationSt
ates; | 91 static NeverDestroyed<HashMap<WebPageProxy*, NavigationState*>> navigationSt
ates; |
91 | 92 |
92 return navigationStates; | 93 return navigationStates; |
93 } | 94 } |
94 | 95 |
95 NavigationState::NavigationState(WKWebView *webView) | 96 NavigationState::NavigationState(WKWebView *webView) |
96 : m_webView(webView) | 97 : m_webView(webView) |
97 , m_navigationDelegateMethods() | 98 , m_navigationDelegateMethods() |
98 , m_historyDelegateMethods() | 99 , m_historyDelegateMethods() |
99 #if PLATFORM(IOS) | 100 #if PLATFORM(IOS) |
100 , m_releaseActivityTimer(RunLoop::current(), this, &NavigationState::release
NetworkActivityToken) | 101 , m_releaseActivityTimer(RunLoop::current(), this, &NavigationState::release
NetworkActivityTokenAfterLoadCompletion) |
101 #endif | 102 #endif |
102 { | 103 { |
103 ASSERT(m_webView->_page); | 104 ASSERT(m_webView->_page); |
104 ASSERT(!navigationStates().contains(m_webView->_page.get())); | 105 ASSERT(!navigationStates().contains(m_webView->_page.get())); |
105 | 106 |
106 navigationStates().add(m_webView->_page.get(), this); | 107 navigationStates().add(m_webView->_page.get(), this); |
107 m_webView->_page->pageLoadState().addObserver(*this); | 108 m_webView->_page->pageLoadState().addObserver(*this); |
108 m_safeBrowsingController = std::make_unique<SafeBrowsingController>(webView)
; | 109 m_safeBrowsingController = std::make_unique<SafeBrowsingController>(webView)
; |
109 } | 110 } |
110 | 111 |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 delete localCompletionHandler; | 472 delete localCompletionHandler; |
472 }); | 473 }); |
473 }]; | 474 }]; |
474 #else | 475 #else |
475 completionHandler(false); | 476 completionHandler(false); |
476 #endif | 477 #endif |
477 } | 478 } |
478 | 479 |
479 void NavigationState::NavigationClient::decidePolicyForNavigationAction(WebPageP
roxy& webPageProxy, Ref<API::NavigationAction>&& navigationAction, Ref<WebFrameP
olicyListenerProxy>&& listener, API::Object* userInfo) | 480 void NavigationState::NavigationClient::decidePolicyForNavigationAction(WebPageP
roxy& webPageProxy, Ref<API::NavigationAction>&& navigationAction, Ref<WebFrameP
olicyListenerProxy>&& listener, API::Object* userInfo) |
480 { | 481 { |
| 482 ASSERT(webPageProxy.mainFrame()); |
481 auto policyDecider = [&webPageProxy, navigationAction = navigationAction.cop
yRef(), userInfo, this] (WTF::Function<void(WKNavigationActionPolicy, std::optio
nal<WebsitePoliciesData>&&)>&& completionHandler) mutable { | 483 auto policyDecider = [&webPageProxy, navigationAction = navigationAction.cop
yRef(), userInfo, this] (WTF::Function<void(WKNavigationActionPolicy, std::optio
nal<WebsitePoliciesData>&&)>&& completionHandler) mutable { |
482 decidePolicyForNavigationActionInternal(webPageProxy, WTFMove(navigation
Action), WTFMove(completionHandler), userInfo); | 484 decidePolicyForNavigationActionInternal(webPageProxy, WTFMove(navigation
Action), WTFMove(completionHandler), userInfo); |
483 }; | 485 }; |
484 m_navigationState.m_safeBrowsingController->checkURL(WTFMove(navigationActio
n), WTFMove(policyDecider), WTFMove(listener)); | 486 m_navigationState.m_safeBrowsingController->checkURL(WTFMove(navigationActio
n), WTFMove(policyDecider), WTFMove(listener)); |
485 } | 487 } |
486 | 488 |
487 void NavigationState::NavigationClient::decidePolicyForNavigationActionInternal(
WebPageProxy& webPageProxy, Ref<API::NavigationAction>&& navigationAction, WTF::
Function<void(WKNavigationActionPolicy, std::optional<WebsitePoliciesData>&&)>&&
completionHandler, API::Object* userInfo) | 489 void NavigationState::NavigationClient::decidePolicyForNavigationActionInternal(
WebPageProxy& webPageProxy, Ref<API::NavigationAction>&& navigationAction, WTF::
Function<void(WKNavigationActionPolicy, std::optional<WebsitePoliciesData>&&)>&&
completionHandler, API::Object* userInfo) |
488 { | 490 { |
489 String mainFrameURLString = webPageProxy.mainFrame()->url(); | 491 String mainFrameURLString = webPageProxy.mainFrame()->url(); |
490 bool subframeNavigation = navigationAction->targetFrame() && !navigationActi
on->targetFrame()->isMainFrame(); | 492 bool subframeNavigation = navigationAction->targetFrame() && !navigationActi
on->targetFrame()->isMainFrame(); |
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1049 if (!navigationDelegate) | 1051 if (!navigationDelegate) |
1050 return nullptr; | 1052 return nullptr; |
1051 | 1053 |
1052 RetainPtr<NSData> data = [static_cast<id <WKNavigationDelegatePrivate>>(navi
gationDelegate.get()) _webCryptoMasterKeyForWebView:m_navigationState.m_webView]
; | 1054 RetainPtr<NSData> data = [static_cast<id <WKNavigationDelegatePrivate>>(navi
gationDelegate.get()) _webCryptoMasterKeyForWebView:m_navigationState.m_webView]
; |
1053 | 1055 |
1054 return API::Data::createWithoutCopying((const unsigned char*)[data bytes], [
data length], [] (unsigned char*, const void* data) { | 1056 return API::Data::createWithoutCopying((const unsigned char*)[data bytes], [
data length], [] (unsigned char*, const void* data) { |
1055 [(NSData *)data release]; | 1057 [(NSData *)data release]; |
1056 }, data.leakRef()); | 1058 }, data.leakRef()); |
1057 } | 1059 } |
1058 | 1060 |
| 1061 RefPtr<API::String> NavigationState::NavigationClient::signedPublicKeyAndChallen
geString(WebPageProxy& page, unsigned keySizeIndex, const RefPtr<API::String>& c
hallengeString, const WebCore::URL& url) |
| 1062 { |
| 1063 // WebKitTestRunner uses C API. Hence, no SPI is provided to override the fo
llowing function. |
| 1064 return API::String::create(WebCore::signedPublicKeyAndChallengeString(keySiz
eIndex, challengeString->string(), url)); |
| 1065 } |
| 1066 |
1059 #if USE(QUICK_LOOK) | 1067 #if USE(QUICK_LOOK) |
1060 void NavigationState::NavigationClient::didStartLoadForQuickLookDocumentInMainFr
ame(const String& fileName, const String& uti) | 1068 void NavigationState::NavigationClient::didStartLoadForQuickLookDocumentInMainFr
ame(const String& fileName, const String& uti) |
1061 { | 1069 { |
1062 if (!m_navigationState.m_navigationDelegateMethods.webViewDidStartLoadForQui
ckLookDocumentInMainFrame) | 1070 if (!m_navigationState.m_navigationDelegateMethods.webViewDidStartLoadForQui
ckLookDocumentInMainFrame) |
1063 return; | 1071 return; |
1064 | 1072 |
1065 auto navigationDelegate = m_navigationState.m_navigationDelegate.get(); | 1073 auto navigationDelegate = m_navigationState.m_navigationDelegate.get(); |
1066 if (!navigationDelegate) | 1074 if (!navigationDelegate) |
1067 return; | 1075 return; |
1068 | 1076 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1140 | 1148 |
1141 [historyDelegate _webView:m_navigationState.m_webView didUpdateHistoryTitle:
title forURL:[NSURL _web_URLWithWTFString:url]]; | 1149 [historyDelegate _webView:m_navigationState.m_webView didUpdateHistoryTitle:
title forURL:[NSURL _web_URLWithWTFString:url]]; |
1142 } | 1150 } |
1143 | 1151 |
1144 void NavigationState::willChangeIsLoading() | 1152 void NavigationState::willChangeIsLoading() |
1145 { | 1153 { |
1146 [m_webView willChangeValueForKey:@"loading"]; | 1154 [m_webView willChangeValueForKey:@"loading"]; |
1147 } | 1155 } |
1148 | 1156 |
1149 #if PLATFORM(IOS) | 1157 #if PLATFORM(IOS) |
1150 void NavigationState::releaseNetworkActivityToken() | 1158 void NavigationState::releaseNetworkActivityToken(NetworkActivityTokenReleaseRea
son reason) |
1151 { | 1159 { |
1152 RELEASE_LOG_IF(m_webView->_page->isAlwaysOnLoggingAllowed(), ProcessSuspensi
on, "%p UIProcess is releasing a background assertion because a page load comple
ted", this); | 1160 if (!m_activityToken) |
1153 ASSERT(m_activityToken); | 1161 return; |
| 1162 |
| 1163 switch (reason) { |
| 1164 case NetworkActivityTokenReleaseReason::LoadCompleted: |
| 1165 RELEASE_LOG_IF(m_webView->_page->isAlwaysOnLoggingAllowed(), ProcessSusp
ension, "%p NavigationState is releasing background process assertion because a
page load completed", this); |
| 1166 break; |
| 1167 case NetworkActivityTokenReleaseReason::ScreenLocked: |
| 1168 RELEASE_LOG_IF(m_webView->_page->isAlwaysOnLoggingAllowed(), ProcessSusp
ension, "%p NavigationState is releasing background process assertion because th
e screen was locked", this); |
| 1169 break; |
| 1170 } |
1154 m_activityToken = nullptr; | 1171 m_activityToken = nullptr; |
| 1172 m_releaseActivityTimer.stop(); |
1155 } | 1173 } |
1156 #endif | 1174 #endif |
1157 | 1175 |
1158 void NavigationState::didChangeIsLoading() | 1176 void NavigationState::didChangeIsLoading() |
1159 { | 1177 { |
1160 #if PLATFORM(IOS) | 1178 #if PLATFORM(IOS) |
1161 if (m_webView->_page->pageLoadState().isLoading()) { | 1179 if (m_webView->_page->pageLoadState().isLoading()) { |
1162 if (m_releaseActivityTimer.isActive()) | 1180 // We do not take a network activity token if a load starts after the sc
reen has been locked. |
| 1181 if ([UIApp isSuspendedUnderLock]) |
| 1182 return; |
| 1183 |
| 1184 if (m_releaseActivityTimer.isActive()) { |
| 1185 RELEASE_LOG_IF(m_webView->_page->isAlwaysOnLoggingAllowed(), Process
Suspension, "%p - NavigationState keeps its process network assertion because a
new page load started", this); |
1163 m_releaseActivityTimer.stop(); | 1186 m_releaseActivityTimer.stop(); |
1164 else { | 1187 } |
1165 RELEASE_LOG_IF(m_webView->_page->isAlwaysOnLoggingAllowed(), Process
Suspension, "%p - UIProcess is taking a background assertion because a page load
started", this); | 1188 if (!m_activityToken) { |
1166 ASSERT(!m_activityToken); | 1189 RELEASE_LOG_IF(m_webView->_page->isAlwaysOnLoggingAllowed(), Process
Suspension, "%p - NavigationState is taking a process network assertion because
a page load started", this); |
1167 m_activityToken = m_webView->_page->process().throttler().background
ActivityToken(); | 1190 m_activityToken = m_webView->_page->process().throttler().background
ActivityToken(); |
1168 } | 1191 } |
1169 } else { | 1192 } else if (m_activityToken) { |
1170 // Delay releasing the background activity for 3 seconds to give the app
lication a chance to start another navigation | 1193 if (m_webView._isBackground) |
1171 // before suspending the WebContent process <rdar://problem/27910964>. | 1194 releaseNetworkActivityTokenAfterLoadCompletion(); |
1172 m_releaseActivityTimer.startOneShot(3_s); | 1195 else { |
| 1196 // The application is visible so we delay releasing the background a
ctivity for 3 seconds to give it a chance to start another navigation |
| 1197 // before suspending the WebContent process <rdar://problem/27910964
>. |
| 1198 RELEASE_LOG_IF(m_webView->_page->isAlwaysOnLoggingAllowed(), Process
Suspension, "%p - NavigationState will release its process network assertion soo
n because the page load completed", this); |
| 1199 m_releaseActivityTimer.startOneShot(3_s); |
| 1200 } |
1173 } | 1201 } |
1174 #endif | 1202 #endif |
1175 | 1203 |
1176 [m_webView didChangeValueForKey:@"loading"]; | 1204 [m_webView didChangeValueForKey:@"loading"]; |
1177 } | 1205 } |
1178 | 1206 |
1179 void NavigationState::willChangeTitle() | 1207 void NavigationState::willChangeTitle() |
1180 { | 1208 { |
1181 [m_webView willChangeValueForKey:@"title"]; | 1209 [m_webView willChangeValueForKey:@"title"]; |
1182 } | 1210 } |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1264 } | 1292 } |
1265 | 1293 |
1266 void NavigationState::didChangeWebProcessIsResponsive() | 1294 void NavigationState::didChangeWebProcessIsResponsive() |
1267 { | 1295 { |
1268 [m_webView didChangeValueForKey:@"_webProcessIsResponsive"]; | 1296 [m_webView didChangeValueForKey:@"_webProcessIsResponsive"]; |
1269 } | 1297 } |
1270 | 1298 |
1271 } // namespace WebKit | 1299 } // namespace WebKit |
1272 | 1300 |
1273 #endif | 1301 #endif |
LEFT | RIGHT |