WebServiceWorkerProvider::handleFetch() does not need to take in a sessionID
[WebKit-https.git] / Source / WebKit / WebProcess / Network / WebLoaderStrategy.cpp
1 /*
2  * Copyright (C) 2012, 2015, 2018 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
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,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
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
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
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #include "config.h"
27 #include "WebLoaderStrategy.h"
28
29 #include "DataReference.h"
30 #include "HangDetectionDisabler.h"
31 #include "Logging.h"
32 #include "NetworkConnectionToWebProcessMessages.h"
33 #include "NetworkProcessConnection.h"
34 #include "NetworkResourceLoadParameters.h"
35 #include "SharedBufferDataReference.h"
36 #include "WebCompiledContentRuleList.h"
37 #include "WebCoreArgumentCoders.h"
38 #include "WebErrors.h"
39 #include "WebFrame.h"
40 #include "WebFrameLoaderClient.h"
41 #include "WebPage.h"
42 #include "WebPageProxyMessages.h"
43 #include "WebProcess.h"
44 #include "WebProcessPoolMessages.h"
45 #include "WebResourceLoader.h"
46 #include "WebSWContextManagerConnection.h"
47 #include "WebServiceWorkerProvider.h"
48 #include "WebURLSchemeHandlerProxy.h"
49 #include "WebURLSchemeTaskProxy.h"
50 #include <WebCore/ApplicationCacheHost.h>
51 #include <WebCore/CachedResource.h>
52 #include <WebCore/ContentSecurityPolicy.h>
53 #include <WebCore/DiagnosticLoggingClient.h>
54 #include <WebCore/DiagnosticLoggingKeys.h>
55 #include <WebCore/Document.h>
56 #include <WebCore/DocumentLoader.h>
57 #include <WebCore/FetchOptions.h>
58 #include <WebCore/Frame.h>
59 #include <WebCore/FrameLoader.h>
60 #include <WebCore/NetscapePlugInStreamLoader.h>
61 #include <WebCore/NetworkLoadInformation.h>
62 #include <WebCore/PlatformStrategies.h>
63 #include <WebCore/ReferrerPolicy.h>
64 #include <WebCore/ResourceLoader.h>
65 #include <WebCore/RuntimeApplicationChecks.h>
66 #include <WebCore/RuntimeEnabledFeatures.h>
67 #include <WebCore/SecurityOrigin.h>
68 #include <WebCore/Settings.h>
69 #include <WebCore/SubresourceLoader.h>
70 #include <WebCore/UserContentProvider.h>
71 #include <pal/SessionID.h>
72 #include <wtf/CompletionHandler.h>
73 #include <wtf/text/CString.h>
74
75 #if USE(QUICK_LOOK)
76 #include <WebCore/QuickLook.h>
77 #endif
78
79 #define RELEASE_LOG_IF_ALLOWED(permissionChecker, fmt, ...) RELEASE_LOG_IF(permissionChecker.isAlwaysOnLoggingAllowed(), Network, "%p - WebLoaderStrategy::" fmt, this, ##__VA_ARGS__)
80 #define RELEASE_LOG_ERROR_IF_ALLOWED(permissionChecker, fmt, ...) RELEASE_LOG_ERROR_IF(permissionChecker.isAlwaysOnLoggingAllowed(), Network, "%p - WebLoaderStrategy::" fmt, this, ##__VA_ARGS__)
81
82 namespace WebKit {
83 using namespace WebCore;
84
85 WebLoaderStrategy::WebLoaderStrategy()
86     : m_internallyFailedLoadTimer(RunLoop::main(), this, &WebLoaderStrategy::internallyFailedLoadTimerFired)
87 {
88 }
89
90 WebLoaderStrategy::~WebLoaderStrategy()
91 {
92 }
93
94 void WebLoaderStrategy::loadResource(Frame& frame, CachedResource& resource, ResourceRequest&& request, const ResourceLoaderOptions& options, CompletionHandler<void(RefPtr<SubresourceLoader>&&)>&& completionHandler)
95 {
96     SubresourceLoader::create(frame, resource, WTFMove(request), options, [this, referrerPolicy = options.referrerPolicy, completionHandler = WTFMove(completionHandler), resource = CachedResourceHandle<CachedResource>(&resource), frame = makeRef(frame)] (RefPtr<SubresourceLoader>&& loader) mutable {
97         if (loader)
98             scheduleLoad(*loader, resource.get(), referrerPolicy == ReferrerPolicy::NoReferrerWhenDowngrade);
99         else
100             RELEASE_LOG_IF_ALLOWED(frame.get(), "loadResource: Unable to create SubresourceLoader (frame = %p", &frame);
101         completionHandler(WTFMove(loader));
102     });
103 }
104
105 void WebLoaderStrategy::schedulePluginStreamLoad(Frame& frame, NetscapePlugInStreamLoaderClient& client, ResourceRequest&& request, CompletionHandler<void(RefPtr<NetscapePlugInStreamLoader>&&)>&& completionHandler)
106 {
107     NetscapePlugInStreamLoader::create(frame, client, WTFMove(request), [this, completionHandler = WTFMove(completionHandler), frame = makeRef(frame)] (RefPtr<NetscapePlugInStreamLoader>&& loader) mutable {
108         if (loader)
109             scheduleLoad(*loader, 0, frame->document()->referrerPolicy() == ReferrerPolicy::NoReferrerWhenDowngrade);
110         completionHandler(WTFMove(loader));
111     });
112 }
113
114 static Seconds maximumBufferingTime(CachedResource* resource)
115 {
116     if (!resource)
117         return 0_s;
118
119     switch (resource->type()) {
120     case CachedResource::Type::Beacon:
121     case CachedResource::Type::Ping:
122     case CachedResource::Type::CSSStyleSheet:
123     case CachedResource::Type::Script:
124 #if ENABLE(SVG_FONTS)
125     case CachedResource::Type::SVGFontResource:
126 #endif
127     case CachedResource::Type::FontResource:
128 #if ENABLE(APPLICATION_MANIFEST)
129     case CachedResource::Type::ApplicationManifest:
130 #endif
131         return Seconds::infinity();
132     case CachedResource::Type::ImageResource:
133         return 500_ms;
134     case CachedResource::Type::MediaResource:
135         return 50_ms;
136     case CachedResource::Type::MainResource:
137     case CachedResource::Type::Icon:
138     case CachedResource::Type::RawResource:
139     case CachedResource::Type::SVGDocumentResource:
140     case CachedResource::Type::LinkPrefetch:
141 #if ENABLE(VIDEO_TRACK)
142     case CachedResource::Type::TextTrackResource:
143 #endif
144 #if ENABLE(XSLT)
145     case CachedResource::Type::XSLStyleSheet:
146 #endif
147         return 0_s;
148     }
149
150     ASSERT_NOT_REACHED();
151     return 0_s;
152 }
153
154 void WebLoaderStrategy::scheduleLoad(ResourceLoader& resourceLoader, CachedResource* resource, bool shouldClearReferrerOnHTTPSToHTTPRedirect)
155 {
156     ResourceLoadIdentifier identifier = resourceLoader.identifier();
157     ASSERT(identifier);
158
159     auto& frameLoaderClient = resourceLoader.frameLoader()->client();
160
161     WebResourceLoader::TrackingParameters trackingParameters;
162     if (auto* webFrameLoaderClient = toWebFrameLoaderClient(frameLoaderClient))
163         trackingParameters.webPageProxyID = webFrameLoaderClient->webPageProxyID().valueOr(WebPageProxyIdentifier { });
164 #if ENABLE(SERVICE_WORKER)
165     else if (is<ServiceWorkerFrameLoaderClient>(frameLoaderClient))
166         trackingParameters.webPageProxyID = downcast<ServiceWorkerFrameLoaderClient>(frameLoaderClient).webPageProxyID();
167 #endif
168     trackingParameters.pageID = frameLoaderClient.pageID().valueOr(PageIdentifier { });
169     trackingParameters.frameID = frameLoaderClient.frameID().valueOr(FrameIdentifier { });
170     trackingParameters.resourceID = identifier;
171     auto sessionID = frameLoaderClient.sessionID();
172
173 #if ENABLE(WEB_ARCHIVE) || ENABLE(MHTML)
174     // If the DocumentLoader schedules this as an archive resource load,
175     // then we should remember the ResourceLoader in our records but not schedule it in the NetworkProcess.
176     if (resourceLoader.documentLoader()->scheduleArchiveLoad(resourceLoader, resourceLoader.request())) {
177         LOG(NetworkScheduling, "(WebProcess) WebLoaderStrategy::scheduleLoad, url '%s' will be handled as an archive resource.", resourceLoader.url().string().utf8().data());
178         RELEASE_LOG_IF_ALLOWED(resourceLoader, "scheduleLoad: URL will be handled as an archive resource (frame = %p, pageID = %" PRIu64 ", frameID = %" PRIu64 ", resourceID = %" PRIu64 ")", resourceLoader.frame(), trackingParameters.pageID.toUInt64(), trackingParameters.frameID.toUInt64(), identifier);
179         m_webResourceLoaders.set(identifier, WebResourceLoader::create(resourceLoader, trackingParameters));
180         return;
181     }
182 #endif
183
184     if (resourceLoader.documentLoader()->applicationCacheHost().maybeLoadResource(resourceLoader, resourceLoader.request(), resourceLoader.request().url())) {
185         LOG(NetworkScheduling, "(WebProcess) WebLoaderStrategy::scheduleLoad, url '%s' will be loaded from application cache.", resourceLoader.url().string().utf8().data());
186         RELEASE_LOG_IF_ALLOWED(resourceLoader, "scheduleLoad: URL will be loaded from application cache (frame = %p, pageID = %" PRIu64 ", frameID = %" PRIu64 ", resourceID = %" PRIu64 ")", resourceLoader.frame(), trackingParameters.pageID.toUInt64(), trackingParameters.frameID.toUInt64(), identifier);
187         m_webResourceLoaders.set(identifier, WebResourceLoader::create(resourceLoader, trackingParameters));
188         return;
189     }
190
191     if (resourceLoader.request().url().protocolIsData()) {
192         LOG(NetworkScheduling, "(WebProcess) WebLoaderStrategy::scheduleLoad, url '%s' will be loaded as data.", resourceLoader.url().string().utf8().data());
193         RELEASE_LOG_IF_ALLOWED(resourceLoader, "scheduleLoad: URL will be loaded as data (frame = %p, pageID = %" PRIu64 ", frameID = %" PRIu64 ", resourceID = %" PRIu64 ")", resourceLoader.frame(), trackingParameters.pageID.toUInt64(), trackingParameters.frameID.toUInt64(), identifier);
194         startLocalLoad(resourceLoader);
195         return;
196     }
197
198 #if USE(QUICK_LOOK)
199     if (isQuickLookPreviewURL(resourceLoader.request().url())) {
200         LOG(NetworkScheduling, "(WebProcess) WebLoaderStrategy::scheduleLoad, url '%s' will be handled as a QuickLook resource.", resourceLoader.url().string().utf8().data());
201         RELEASE_LOG_IF_ALLOWED(resourceLoader, "scheduleLoad: URL will be handled as a QuickLook resource (frame = %p, pageID = %" PRIu64 ", frameID = %" PRIu64 ", resourceID = %" PRIu64 ")", resourceLoader.frame(), trackingParameters.pageID.toUInt64(), trackingParameters.frameID.toUInt64(), identifier);
202         startLocalLoad(resourceLoader);
203         return;
204     }
205 #endif
206
207 #if USE(SOUP)
208     // For apps that call g_resource_load in a web extension.
209     // https://blogs.gnome.org/alexl/2012/01/26/resources-in-glib/
210     if (resourceLoader.request().url().protocolIs("resource")) {
211         LOG(NetworkScheduling, "(WebProcess) WebLoaderStrategy::scheduleLoad, url '%s' will be handled as a GResource.", resourceLoader.url().string().utf8().data());
212         RELEASE_LOG_IF_ALLOWED(resourceLoader, "scheduleLoad: URL will be handled as a GResource (frame = %p, pageID = %" PRIu64 ", frameID = %" PRIu64 ", resourceID = %" PRIu64 ")", resourceLoader.frame(), trackingParameters.pageID.toUInt64(), trackingParameters.frameID.toUInt64(), identifier);
213         startLocalLoad(resourceLoader);
214         return;
215     }
216 #endif
217
218 #if ENABLE(SERVICE_WORKER)
219     RELEASE_LOG_IF_ALLOWED(!!resourceLoader.options().serviceWorkerRegistrationIdentifier && resourceLoader, "scheduleLoad: URL will be scheduled through ServiceWorker or Network Process (frame = %p, pageID = %" PRIu64 ", frameID = %" PRIu64 ", resourceID = %" PRIu64 ")", resourceLoader.frame(), trackingParameters.pageID.toUInt64(), trackingParameters.frameID.toUInt64(), identifier);
220
221     WebServiceWorkerProvider::singleton().handleFetch(resourceLoader, shouldClearReferrerOnHTTPSToHTTPRedirect, [this, trackingParameters, identifier, sessionID, shouldClearReferrerOnHTTPSToHTTPRedirect, maximumBufferingTime = maximumBufferingTime(resource), resourceLoader = makeRef(resourceLoader)] (ServiceWorkerClientFetch::Result result) mutable {
222         if (result != ServiceWorkerClientFetch::Result::Unhandled) {
223             LOG(NetworkScheduling, "(WebProcess) WebLoaderStrategy::scheduleLoad, url '%s' will be scheduled through ServiceWorker handle fetch algorithm", resourceLoader->url().string().latin1().data());
224             RELEASE_LOG_IF_ALLOWED(resourceLoader.get(), "scheduleLoad: URL will be scheduled through ServiceWorker handle fetch algorithm (frame = %p, pageID = %" PRIu64 ", frameID = %" PRIu64 ", resourceID = %" PRIu64 ")", resourceLoader->frame(), trackingParameters.pageID.toUInt64(), trackingParameters.frameID.toUInt64(), identifier);
225             return;
226         }
227         if (resourceLoader->options().serviceWorkersMode == ServiceWorkersMode::Only) {
228             RELEASE_LOG_ERROR_IF_ALLOWED(resourceLoader.get(), "scheduleLoad: unable to schedule URL through ServiceWorker handle fetch algorithm (frame = %p, pageID = %" PRIu64 ", frameID = %" PRIu64 ", resourceID = %" PRIu64 ")", resourceLoader->frame(), trackingParameters.pageID.toUInt64(), trackingParameters.frameID.toUInt64(), identifier);
229             callOnMainThread([resourceLoader = WTFMove(resourceLoader)] {
230                 auto error = internalError(resourceLoader->request().url());
231                 error.setType(ResourceError::Type::Cancellation);
232                 resourceLoader->didFail(error);
233             });
234             return;
235         }
236
237         if (!WebProcess::singleton().webLoaderStrategy().tryLoadingUsingURLSchemeHandler(resourceLoader)) {
238             RELEASE_LOG_IF_ALLOWED(resourceLoader.get(), "scheduleLoad: URL will be scheduled with the NetworkProcess (frame = %p, pageID = %" PRIu64 ", frameID = %" PRIu64 ", resourceID = %" PRIu64 ")", resourceLoader->frame(), trackingParameters.pageID.toUInt64(), trackingParameters.frameID.toUInt64(), identifier);
239             WebProcess::singleton().webLoaderStrategy().scheduleLoadFromNetworkProcess(resourceLoader.get(), resourceLoader->request(), trackingParameters, sessionID, shouldClearReferrerOnHTTPSToHTTPRedirect, maximumBufferingTime);
240             return;
241         }
242
243         RELEASE_LOG_IF_ALLOWED(resourceLoader.get(), "scheduleLoad: URL not handled by any handlers (frame = %p, pageID = %" PRIu64 ", frameID = %" PRIu64 ", resourceID = %" PRIu64 ")", resourceLoader->frame(), trackingParameters.pageID.toUInt64(), trackingParameters.frameID.toUInt64(), identifier);
244     });
245 #else
246     if (!tryLoadingUsingURLSchemeHandler(resourceLoader)) {
247         RELEASE_LOG_IF_ALLOWED(resourceLoader, "scheduleLoad: URL will be scheduled with the NetworkProcess (frame = %p, pageID = %" PRIu64 ", frameID = %" PRIu64 ", resourceID = %" PRIu64 ")", resourceLoader.frame(), trackingParameters.pageID.toUInt64(), trackingParameters.frameID.toUInt64(), identifier);
248         scheduleLoadFromNetworkProcess(resourceLoader, resourceLoader.request(), trackingParameters, sessionID, shouldClearReferrerOnHTTPSToHTTPRedirect, maximumBufferingTime(resource));
249         return;
250     }
251     RELEASE_LOG_IF_ALLOWED(resourceLoader, "scheduleLoad: URL not handled by any handlers (frame = %p, pageID = %" PRIu64 ", frameID = %" PRIu64 ", resourceID = %" PRIu64 ")", resourceLoader.frame(), trackingParameters.pageID.toUInt64(), trackingParameters.frameID.toUInt64(), identifier);
252 #endif
253 }
254
255 bool WebLoaderStrategy::tryLoadingUsingURLSchemeHandler(ResourceLoader& resourceLoader)
256 {
257     auto* webFrameLoaderClient = toWebFrameLoaderClient(resourceLoader.frameLoader()->client());
258     auto* webFrame = webFrameLoaderClient ? webFrameLoaderClient->webFrame() : nullptr;
259     auto* webPage = webFrame ? webFrame->page() : nullptr;
260     if (webPage) {
261         if (auto* handler = webPage->urlSchemeHandlerForScheme(resourceLoader.request().url().protocol().toStringWithoutCopying())) {
262             LOG(NetworkScheduling, "(WebProcess) WebLoaderStrategy::scheduleLoad, URL '%s' will be handled by a UIProcess URL scheme handler.", resourceLoader.url().string().utf8().data());
263             RELEASE_LOG_IF_ALLOWED(resourceLoader, "scheduleLoad: URL will be handled by a UIProcess URL scheme handler (frame = %p, resourceID = %lu)", resourceLoader.frame(), resourceLoader.identifier());
264
265             handler->startNewTask(resourceLoader);
266             return true;
267         }
268     }
269     return false;
270 }
271
272 void WebLoaderStrategy::scheduleLoadFromNetworkProcess(ResourceLoader& resourceLoader, const ResourceRequest& request, const WebResourceLoader::TrackingParameters& trackingParameters, PAL::SessionID sessionID, bool shouldClearReferrerOnHTTPSToHTTPRedirect, Seconds maximumBufferingTime)
273 {
274     ResourceLoadIdentifier identifier = resourceLoader.identifier();
275     ASSERT(identifier);
276
277     LOG(NetworkScheduling, "(WebProcess) WebLoaderStrategy::scheduleLoad, url '%s' will be scheduled with the NetworkProcess with priority %d", resourceLoader.url().string().latin1().data(), static_cast<int>(resourceLoader.request().priority()));
278
279     ContentSniffingPolicy contentSniffingPolicy = resourceLoader.shouldSniffContent() ? ContentSniffingPolicy::SniffContent : ContentSniffingPolicy::DoNotSniffContent;
280     ContentEncodingSniffingPolicy contentEncodingSniffingPolicy = resourceLoader.shouldSniffContentEncoding() ? ContentEncodingSniffingPolicy::Sniff : ContentEncodingSniffingPolicy::DoNotSniff;
281     StoredCredentialsPolicy storedCredentialsPolicy = resourceLoader.shouldUseCredentialStorage() ? StoredCredentialsPolicy::Use : StoredCredentialsPolicy::DoNotUse;
282
283     NetworkResourceLoadParameters loadParameters { sessionID };
284     loadParameters.identifier = identifier;
285     loadParameters.webPageProxyID = trackingParameters.webPageProxyID;
286     loadParameters.webPageID = trackingParameters.pageID;
287     loadParameters.webFrameID = trackingParameters.frameID;
288     loadParameters.parentPID = presentingApplicationPID();
289     loadParameters.request = request;
290     loadParameters.contentSniffingPolicy = contentSniffingPolicy;
291     loadParameters.contentEncodingSniffingPolicy = contentEncodingSniffingPolicy;
292     loadParameters.storedCredentialsPolicy = storedCredentialsPolicy;
293     // If there is no WebFrame then this resource cannot be authenticated with the client.
294     loadParameters.clientCredentialPolicy = (loadParameters.webFrameID && loadParameters.webPageID && resourceLoader.isAllowedToAskUserForCredentials()) ? ClientCredentialPolicy::MayAskClientForCredentials : ClientCredentialPolicy::CannotAskClientForCredentials;
295     loadParameters.shouldClearReferrerOnHTTPSToHTTPRedirect = shouldClearReferrerOnHTTPSToHTTPRedirect;
296     loadParameters.needsCertificateInfo = resourceLoader.shouldIncludeCertificateInfo();
297     loadParameters.maximumBufferingTime = maximumBufferingTime;
298     loadParameters.options = resourceLoader.options();
299     loadParameters.preflightPolicy = resourceLoader.options().preflightPolicy;
300     loadParameters.isHTTPSUpgradeEnabled = resourceLoader.frame() ? resourceLoader.frame()->settings().HTTPSUpgradeEnabled() : false;
301
302     auto* document = resourceLoader.frame() ? resourceLoader.frame()->document() : nullptr;
303     if (resourceLoader.options().cspResponseHeaders)
304         loadParameters.cspResponseHeaders = resourceLoader.options().cspResponseHeaders;
305     else if (document && !document->shouldBypassMainWorldContentSecurityPolicy() && resourceLoader.options().contentSecurityPolicyImposition == ContentSecurityPolicyImposition::DoPolicyCheck) {
306         if (auto* contentSecurityPolicy = document->contentSecurityPolicy())
307             loadParameters.cspResponseHeaders = contentSecurityPolicy->responseHeaders();
308     }
309
310 #if ENABLE(CONTENT_EXTENSIONS)
311     if (document) {
312         loadParameters.mainDocumentURL = document->topDocument().url();
313         // FIXME: Instead of passing userContentControllerIdentifier, the NetworkProcess should be able to get it using webPageId.
314         auto* webFrameLoaderClient = toWebFrameLoaderClient(resourceLoader.frame()->loader().client());
315         auto* webFrame = webFrameLoaderClient ? webFrameLoaderClient->webFrame() : nullptr;
316         auto* webPage = webFrame ? webFrame->page() : nullptr;
317         if (webPage)
318             loadParameters.userContentControllerIdentifier = webPage->userContentControllerIdentifier();
319     }
320 #endif
321
322     // FIXME: All loaders should provide their origin if navigation mode is cors/no-cors/same-origin.
323     // As a temporary approach, we use the document origin if available or the HTTP Origin header otherwise.
324     if (is<SubresourceLoader>(resourceLoader)) {
325         auto& loader = downcast<SubresourceLoader>(resourceLoader);
326         loadParameters.sourceOrigin = loader.origin();
327
328         if (auto* headers = loader.originalHeaders())
329             loadParameters.originalRequestHeaders = *headers;
330     }
331
332     if (!loadParameters.sourceOrigin && document)
333         loadParameters.sourceOrigin = &document->securityOrigin();
334     if (!loadParameters.sourceOrigin) {
335         auto origin = request.httpOrigin();
336         if (!origin.isNull())
337             loadParameters.sourceOrigin = SecurityOrigin::createFromString(origin);
338     }
339     if (document)
340         loadParameters.topOrigin = &document->topOrigin();
341
342     if (loadParameters.options.mode != FetchOptions::Mode::Navigate) {
343         ASSERT(loadParameters.sourceOrigin);
344         if (!loadParameters.sourceOrigin) {
345             RELEASE_LOG_ERROR_IF_ALLOWED(resourceLoader, "scheduleLoad: no sourceOrigin (frame = %p, priority = %d, pageID = %" PRIu64 ", frameID = %" PRIu64 ", resourceID = %" PRIu64 ")", resourceLoader.frame(), static_cast<int>(resourceLoader.request().priority()), loadParameters.webPageID.toUInt64(), loadParameters.webFrameID.toUInt64(), loadParameters.identifier);
346             scheduleInternallyFailedLoad(resourceLoader);
347             return;
348         }
349     }
350
351     loadParameters.shouldRestrictHTTPResponseAccess = shouldPerformSecurityChecks();
352
353     loadParameters.isMainFrameNavigation = resourceLoader.frame() && resourceLoader.frame()->isMainFrame() && resourceLoader.options().mode == FetchOptions::Mode::Navigate;
354
355     loadParameters.isMainResourceNavigationForAnyFrame = resourceLoader.frame() && resourceLoader.options().mode == FetchOptions::Mode::Navigate;
356
357     loadParameters.shouldEnableCrossOriginResourcePolicy = RuntimeEnabledFeatures::sharedFeatures().crossOriginResourcePolicyEnabled() && !loadParameters.isMainFrameNavigation;
358
359     if (resourceLoader.options().mode == FetchOptions::Mode::Navigate) {
360         Vector<RefPtr<SecurityOrigin>> frameAncestorOrigins;
361         for (auto* frame = resourceLoader.frame()->tree().parent(); frame; frame = frame->tree().parent())
362             frameAncestorOrigins.append(makeRefPtr(frame->document()->securityOrigin()));
363         loadParameters.frameAncestorOrigins = WTFMove(frameAncestorOrigins);
364     }
365
366     ASSERT((loadParameters.webPageID && loadParameters.webFrameID) || loadParameters.clientCredentialPolicy == ClientCredentialPolicy::CannotAskClientForCredentials);
367
368     RELEASE_LOG_IF_ALLOWED(resourceLoader, "scheduleLoad: Resource is being scheduled with the NetworkProcess (frame = %p, priority = %d, pageID = %" PRIu64 ", frameID = %" PRIu64 ", resourceID = %" PRIu64 ")", resourceLoader.frame(), static_cast<int>(resourceLoader.request().priority()), loadParameters.webPageID.toUInt64(), loadParameters.webFrameID.toUInt64(), loadParameters.identifier);
369     if (!WebProcess::singleton().ensureNetworkProcessConnection().connection().send(Messages::NetworkConnectionToWebProcess::ScheduleResourceLoad(loadParameters), 0)) {
370         RELEASE_LOG_ERROR_IF_ALLOWED(resourceLoader, "scheduleLoad: Unable to schedule resource with the NetworkProcess (frame = %p, priority = %d, pageID = %" PRIu64 ", frameID = %" PRIu64 ", resourceID = %" PRIu64 ")", resourceLoader.frame(), static_cast<int>(resourceLoader.request().priority()), loadParameters.webPageID.toUInt64(), loadParameters.webFrameID.toUInt64(), loadParameters.identifier);
371         // We probably failed to schedule this load with the NetworkProcess because it had crashed.
372         // This load will never succeed so we will schedule it to fail asynchronously.
373         scheduleInternallyFailedLoad(resourceLoader);
374         return;
375     }
376
377     auto loader = WebResourceLoader::create(resourceLoader, trackingParameters);
378     if (resourceLoader.originalRequest().hasUpload()) {
379         if (m_loadersWithUploads.isEmpty())
380             WebProcess::singleton().parentProcessConnection()->send(Messages::WebProcessPool::SetWebProcessHasUploads(Process::identifier()), 0);
381         m_loadersWithUploads.add(loader.ptr());
382     }
383
384     m_webResourceLoaders.set(identifier, WTFMove(loader));
385 }
386
387 void WebLoaderStrategy::scheduleInternallyFailedLoad(WebCore::ResourceLoader& resourceLoader)
388 {
389     m_internallyFailedResourceLoaders.add(&resourceLoader);
390     m_internallyFailedLoadTimer.startOneShot(0_s);
391 }
392
393 void WebLoaderStrategy::internallyFailedLoadTimerFired()
394 {
395     for (auto& resourceLoader : copyToVector(m_internallyFailedResourceLoaders))
396         resourceLoader->didFail(internalError(resourceLoader->url()));
397 }
398
399 void WebLoaderStrategy::startLocalLoad(WebCore::ResourceLoader& resourceLoader)
400 {
401     resourceLoader.start();
402     m_webResourceLoaders.set(resourceLoader.identifier(), WebResourceLoader::create(resourceLoader, { }));
403 }
404
405 void WebLoaderStrategy::addURLSchemeTaskProxy(WebURLSchemeTaskProxy& task)
406 {
407     auto result = m_urlSchemeTasks.add(task.identifier(), &task);
408     ASSERT_UNUSED(result, result.isNewEntry);
409 }
410
411 void WebLoaderStrategy::removeURLSchemeTaskProxy(WebURLSchemeTaskProxy& task)
412 {
413     m_urlSchemeTasks.remove(task.identifier());
414 }
415
416 void WebLoaderStrategy::remove(ResourceLoader* resourceLoader)
417 {
418     ASSERT(resourceLoader);
419     LOG(NetworkScheduling, "(WebProcess) WebLoaderStrategy::remove, url '%s'", resourceLoader->url().string().utf8().data());
420
421     if (auto task = m_urlSchemeTasks.take(resourceLoader->identifier())) {
422         ASSERT(!m_internallyFailedResourceLoaders.contains(resourceLoader));
423         task->stopLoading();
424         return;
425     }
426
427     if (m_internallyFailedResourceLoaders.contains(resourceLoader)) {
428         m_internallyFailedResourceLoaders.remove(resourceLoader);
429         return;
430     }
431     
432     ResourceLoadIdentifier identifier = resourceLoader->identifier();
433     if (!identifier) {
434         LOG_ERROR("WebLoaderStrategy removing a ResourceLoader that has no identifier.");
435         return;
436     }
437
438 #if ENABLE(SERVICE_WORKER)
439     if (WebServiceWorkerProvider::singleton().cancelFetch(makeObjectIdentifier<FetchIdentifierType>(identifier)))
440         return;
441 #endif
442
443     RefPtr<WebResourceLoader> loader = m_webResourceLoaders.take(identifier);
444     // Loader may not be registered if we created it, but haven't scheduled yet (a bundle client can decide to cancel such request via willSendRequest).
445     if (!loader)
446         return;
447
448     WebProcess::singleton().ensureNetworkProcessConnection().connection().send(Messages::NetworkConnectionToWebProcess::RemoveLoadIdentifier(identifier), 0);
449
450     if (m_loadersWithUploads.remove(loader.get()) && m_loadersWithUploads.isEmpty())
451         WebProcess::singleton().parentProcessConnection()->send(Messages::WebProcessPool::ClearWebProcessHasUploads { Process::identifier() }, 0);
452
453     // It's possible that this WebResourceLoader might be just about to message back to the NetworkProcess (e.g. ContinueWillSendRequest)
454     // but there's no point in doing so anymore.
455     loader->detachFromCoreLoader();
456 }
457
458 void WebLoaderStrategy::setDefersLoading(ResourceLoader&, bool)
459 {
460 }
461
462 void WebLoaderStrategy::crossOriginRedirectReceived(ResourceLoader*, const URL&)
463 {
464     // We handle cross origin redirects entirely within the NetworkProcess.
465     // We override this call in the WebProcess to make it a no-op.
466 }
467
468 void WebLoaderStrategy::servePendingRequests(ResourceLoadPriority)
469 {
470     // This overrides the base class version.
471     // We don't need to do anything as this is handled by the network process.
472 }
473
474 void WebLoaderStrategy::suspendPendingRequests()
475 {
476     // Network process does keep requests in pending state.
477 }
478
479 void WebLoaderStrategy::resumePendingRequests()
480 {
481     // Network process does keep requests in pending state.
482 }
483
484 void WebLoaderStrategy::networkProcessCrashed()
485 {
486     RELEASE_LOG_ERROR(Network, "WebLoaderStrategy::networkProcessCrashed: failing all pending resource loaders");
487
488     for (auto& loader : m_webResourceLoaders.values()) {
489         scheduleInternallyFailedLoad(*loader->resourceLoader());
490         loader->detachFromCoreLoader();
491     }
492
493     m_webResourceLoaders.clear();
494
495     auto pingLoadCompletionHandlers = WTFMove(m_pingLoadCompletionHandlers);
496     for (auto& pingLoadCompletionHandler : pingLoadCompletionHandlers.values())
497         pingLoadCompletionHandler(internalError(URL()), { });
498
499     auto preconnectCompletionHandlers = WTFMove(m_preconnectCompletionHandlers);
500     for (auto& preconnectCompletionHandler : preconnectCompletionHandlers.values())
501         preconnectCompletionHandler(internalError(URL()));
502 }
503
504 static bool shouldClearReferrerOnHTTPSToHTTPRedirect(Frame* frame)
505 {
506     if (frame) {
507         if (auto* document = frame->document())
508             return document->referrerPolicy() == ReferrerPolicy::NoReferrerWhenDowngrade;
509     }
510     return true;
511 }
512
513 Optional<WebLoaderStrategy::SyncLoadResult> WebLoaderStrategy::tryLoadingSynchronouslyUsingURLSchemeHandler(FrameLoader& frameLoader, ResourceLoadIdentifier identifier, const ResourceRequest& request)
514 {
515     auto* webFrameLoaderClient = toWebFrameLoaderClient(frameLoader.client());
516     auto* webFrame = webFrameLoaderClient ? webFrameLoaderClient->webFrame() : nullptr;
517     auto* webPage = webFrame ? webFrame->page() : nullptr;
518     if (!webPage)
519         return WTF::nullopt;
520
521     auto* handler = webPage->urlSchemeHandlerForScheme(request.url().protocol().toStringWithoutCopying());
522     if (!handler)
523         return WTF::nullopt;
524
525     LOG(NetworkScheduling, "(WebProcess) WebLoaderStrategy::scheduleLoad, sync load to URL '%s' will be handled by a UIProcess URL scheme handler.", request.url().string().utf8().data());
526
527     SyncLoadResult result;
528     handler->loadSynchronously(identifier, request, result.response, result.error, result.data);
529
530     return result;
531 }
532
533 void WebLoaderStrategy::loadResourceSynchronously(FrameLoader& frameLoader, unsigned long resourceLoadIdentifier, const ResourceRequest& request, ClientCredentialPolicy clientCredentialPolicy,  const FetchOptions& options, const HTTPHeaderMap& originalRequestHeaders, ResourceError& error, ResourceResponse& response, Vector<char>& data)
534 {
535     WebFrameLoaderClient* webFrameLoaderClient = toWebFrameLoaderClient(frameLoader.client());
536     WebFrame* webFrame = webFrameLoaderClient ? webFrameLoaderClient->webFrame() : nullptr;
537     WebPage* webPage = webFrame ? webFrame->page() : nullptr;
538
539     auto webPageProxyID = webPage ? webPage->webPageProxyIdentifier() : WebPageProxyIdentifier { };
540     auto pageID = webPage ? webPage->identifier() : PageIdentifier { };
541     auto frameID = webFrame ? webFrame->frameID() : FrameIdentifier { };
542     auto sessionID = webPage ? webPage->sessionID() : PAL::SessionID::defaultSessionID();
543
544     auto* document = frameLoader.frame().document();
545     if (!document) {
546         RELEASE_LOG_ERROR_IF_ALLOWED(sessionID, "loadResourceSynchronously: no document (pageID = %" PRIu64 ", frameID = %" PRIu64 ", resourceID = %lu)", pageID.toUInt64(), frameID.toUInt64(), resourceLoadIdentifier);
547         error = internalError(request.url());
548         return;
549     }
550
551     if (auto syncLoadResult = tryLoadingSynchronouslyUsingURLSchemeHandler(frameLoader, resourceLoadIdentifier, request)) {
552         RELEASE_LOG_ERROR_IF_ALLOWED(sessionID, "loadResourceSynchronously: failed calling tryLoadingSynchronouslyUsingURLSchemeHandler (pageID = %" PRIu64 ", frameID = %" PRIu64 ", resourceID = %lu, error = %d)", pageID.toUInt64(), frameID.toUInt64(), resourceLoadIdentifier, syncLoadResult->error.errorCode());
553         error = WTFMove(syncLoadResult->error);
554         response = WTFMove(syncLoadResult->response);
555         data = WTFMove(syncLoadResult->data);
556         return;
557     }
558
559     NetworkResourceLoadParameters loadParameters { sessionID };
560     loadParameters.identifier = resourceLoadIdentifier;
561     loadParameters.webPageProxyID = webPageProxyID;
562     loadParameters.webPageID = pageID;
563     loadParameters.webFrameID = frameID;
564     loadParameters.parentPID = presentingApplicationPID();
565     loadParameters.request = request;
566     loadParameters.contentSniffingPolicy = ContentSniffingPolicy::SniffContent;
567     loadParameters.contentEncodingSniffingPolicy = ContentEncodingSniffingPolicy::Sniff;
568     loadParameters.storedCredentialsPolicy = options.credentials == FetchOptions::Credentials::Omit ? StoredCredentialsPolicy::DoNotUse : StoredCredentialsPolicy::Use;
569     loadParameters.clientCredentialPolicy = clientCredentialPolicy;
570     loadParameters.shouldClearReferrerOnHTTPSToHTTPRedirect = shouldClearReferrerOnHTTPSToHTTPRedirect(webFrame ? webFrame->coreFrame() : nullptr);
571     loadParameters.shouldRestrictHTTPResponseAccess = shouldPerformSecurityChecks();
572
573     loadParameters.options = options;
574     loadParameters.sourceOrigin = &document->securityOrigin();
575     loadParameters.topOrigin = &document->topOrigin();
576     if (!document->shouldBypassMainWorldContentSecurityPolicy()) {
577         if (auto* contentSecurityPolicy = document->contentSecurityPolicy())
578             loadParameters.cspResponseHeaders = contentSecurityPolicy->responseHeaders();
579     }
580     loadParameters.originalRequestHeaders = originalRequestHeaders;
581
582     data.shrink(0);
583
584     HangDetectionDisabler hangDetectionDisabler;
585     IPC::UnboundedSynchronousIPCScope unboundedSynchronousIPCScope;
586
587     bool shouldNotifyOfUpload = request.hasUpload() && m_loadersWithUploads.isEmpty();
588     if (shouldNotifyOfUpload)
589         WebProcess::singleton().parentProcessConnection()->send(Messages::WebProcessPool::SetWebProcessHasUploads { Process::identifier() }, 0);
590
591     if (!WebProcess::singleton().ensureNetworkProcessConnection().connection().sendSync(Messages::NetworkConnectionToWebProcess::PerformSynchronousLoad(loadParameters), Messages::NetworkConnectionToWebProcess::PerformSynchronousLoad::Reply(error, response, data), 0)) {
592         RELEASE_LOG_ERROR_IF_ALLOWED(sessionID, "loadResourceSynchronously: failed sending synchronous network process message (pageID = %" PRIu64 ", frameID = %" PRIu64 ", resourceID = %lu)", pageID.toUInt64(), frameID.toUInt64(), resourceLoadIdentifier);
593         if (auto* page = webPage ? webPage->corePage() : nullptr)
594             page->diagnosticLoggingClient().logDiagnosticMessage(WebCore::DiagnosticLoggingKeys::internalErrorKey(), WebCore::DiagnosticLoggingKeys::synchronousMessageFailedKey(), WebCore::ShouldSample::No);
595         response = ResourceResponse();
596         error = internalError(request.url());
597     }
598
599     if (shouldNotifyOfUpload)
600         WebProcess::singleton().parentProcessConnection()->send(Messages::WebProcessPool::ClearWebProcessHasUploads { Process::identifier() }, 0);
601 }
602
603 void WebLoaderStrategy::pageLoadCompleted(Page& page)
604 {
605     WebProcess::singleton().ensureNetworkProcessConnection().connection().send(Messages::NetworkConnectionToWebProcess::PageLoadCompleted(WebPage::fromCorePage(page).identifier()), 0);
606 }
607
608 static uint64_t generateLoadIdentifier()
609 {
610     static uint64_t identifier = 0;
611     return ++identifier;
612 }
613
614 bool WebLoaderStrategy::usePingLoad() const
615 {
616     return !RuntimeEnabledFeatures::sharedFeatures().fetchAPIKeepAliveEnabled();
617 }
618
619 void WebLoaderStrategy::startPingLoad(Frame& frame, ResourceRequest& request, const HTTPHeaderMap& originalRequestHeaders, const FetchOptions& options, ContentSecurityPolicyImposition policyCheck, PingLoadCompletionHandler&& completionHandler)
620 {
621     auto* document = frame.document();
622     if (!document) {
623         if (completionHandler)
624             completionHandler(internalError(request.url()), { });
625         return;
626     }
627
628     NetworkResourceLoadParameters loadParameters { frame.page() ? frame.page()->sessionID() : PAL::SessionID::defaultSessionID() };
629     loadParameters.identifier = generateLoadIdentifier();
630     loadParameters.request = request;
631     loadParameters.sourceOrigin = &document->securityOrigin();
632     loadParameters.topOrigin = &document->topOrigin();
633     loadParameters.parentPID = presentingApplicationPID();
634     loadParameters.storedCredentialsPolicy = options.credentials == FetchOptions::Credentials::Omit ? StoredCredentialsPolicy::DoNotUse : StoredCredentialsPolicy::Use;
635     loadParameters.options = options;
636     loadParameters.originalRequestHeaders = originalRequestHeaders;
637     loadParameters.shouldClearReferrerOnHTTPSToHTTPRedirect = shouldClearReferrerOnHTTPSToHTTPRedirect(&frame);
638     loadParameters.shouldRestrictHTTPResponseAccess = shouldPerformSecurityChecks();
639     if (policyCheck == ContentSecurityPolicyImposition::DoPolicyCheck && !document->shouldBypassMainWorldContentSecurityPolicy()) {
640         if (auto* contentSecurityPolicy = document->contentSecurityPolicy())
641             loadParameters.cspResponseHeaders = contentSecurityPolicy->responseHeaders();
642     }
643
644 #if ENABLE(CONTENT_EXTENSIONS)
645     loadParameters.mainDocumentURL = document->topDocument().url();
646     // FIXME: Instead of passing userContentControllerIdentifier, we should just pass webPageId to NetworkProcess.
647     WebFrameLoaderClient* webFrameLoaderClient = toWebFrameLoaderClient(frame.loader().client());
648     WebFrame* webFrame = webFrameLoaderClient ? webFrameLoaderClient->webFrame() : nullptr;
649     WebPage* webPage = webFrame ? webFrame->page() : nullptr;
650     if (webPage)
651         loadParameters.userContentControllerIdentifier = webPage->userContentControllerIdentifier();
652 #endif
653
654     if (completionHandler)
655         m_pingLoadCompletionHandlers.add(loadParameters.identifier, WTFMove(completionHandler));
656
657     WebProcess::singleton().ensureNetworkProcessConnection().connection().send(Messages::NetworkConnectionToWebProcess::LoadPing { loadParameters }, 0);
658 }
659
660 void WebLoaderStrategy::didFinishPingLoad(uint64_t pingLoadIdentifier, ResourceError&& error, ResourceResponse&& response)
661 {
662     if (auto completionHandler = m_pingLoadCompletionHandlers.take(pingLoadIdentifier))
663         completionHandler(WTFMove(error), WTFMove(response));
664 }
665
666 void WebLoaderStrategy::preconnectTo(FrameLoader& frameLoader, const URL& url, StoredCredentialsPolicy storedCredentialsPolicy, PreconnectCompletionHandler&& completionHandler)
667 {
668     uint64_t preconnectionIdentifier = generateLoadIdentifier();
669     auto addResult = m_preconnectCompletionHandlers.add(preconnectionIdentifier, WTFMove(completionHandler));
670     ASSERT_UNUSED(addResult, addResult.isNewEntry);
671
672     auto* webFrameLoaderClient = toWebFrameLoaderClient(frameLoader.client());
673     if (!webFrameLoaderClient) {
674         completionHandler(internalError(url));
675         return;
676     }
677     auto* webFrame = webFrameLoaderClient->webFrame();
678     if (!webFrame) {
679         completionHandler(internalError(url));
680         return;
681     }
682     auto* webPage = webFrame->page();
683     if (!webPage) {
684         completionHandler(internalError(url));
685         return;
686     }
687
688     NetworkResourceLoadParameters parameters { webPage->sessionID() };
689     parameters.request = ResourceRequest { url };
690     parameters.webPageProxyID = webPage->webPageProxyIdentifier();
691     parameters.webPageID = webPage->identifier();
692     parameters.webFrameID = webFrame->frameID();
693     parameters.parentPID = presentingApplicationPID();
694     parameters.storedCredentialsPolicy = storedCredentialsPolicy;
695     parameters.shouldPreconnectOnly = PreconnectOnly::Yes;
696     parameters.shouldRestrictHTTPResponseAccess = shouldPerformSecurityChecks();
697     // FIXME: Use the proper destination once all fetch options are passed.
698     parameters.options.destination = FetchOptions::Destination::EmptyString;
699
700     WebProcess::singleton().ensureNetworkProcessConnection().connection().send(Messages::NetworkConnectionToWebProcess::PreconnectTo(preconnectionIdentifier, WTFMove(parameters)), 0);
701 }
702
703 void WebLoaderStrategy::didFinishPreconnection(uint64_t preconnectionIdentifier, ResourceError&& error)
704 {
705     if (auto completionHandler = m_preconnectCompletionHandlers.take(preconnectionIdentifier))
706         completionHandler(WTFMove(error));
707 }
708
709 bool WebLoaderStrategy::isOnLine() const
710 {
711     return m_isOnLine;
712 }
713
714 void WebLoaderStrategy::addOnlineStateChangeListener(Function<void(bool)>&& listener)
715 {
716     WebProcess::singleton().ensureNetworkProcessConnection();
717     m_onlineStateChangeListeners.append(WTFMove(listener));
718 }
719
720 void WebLoaderStrategy::setOnLineState(bool isOnLine)
721 {
722     if (m_isOnLine == isOnLine)
723         return;
724
725     m_isOnLine = isOnLine;
726     for (auto& listener : m_onlineStateChangeListeners)
727         listener(isOnLine);
728 }
729
730 void WebLoaderStrategy::setCaptureExtraNetworkLoadMetricsEnabled(bool enabled)
731 {
732     WebProcess::singleton().ensureNetworkProcessConnection().connection().send(Messages::NetworkConnectionToWebProcess::SetCaptureExtraNetworkLoadMetricsEnabled(enabled), 0);
733 }
734
735 ResourceResponse WebLoaderStrategy::responseFromResourceLoadIdentifier(uint64_t resourceLoadIdentifier)
736 {
737     ResourceResponse response;
738     WebProcess::singleton().ensureNetworkProcessConnection().connection().sendSync(Messages::NetworkConnectionToWebProcess::GetNetworkLoadInformationResponse { resourceLoadIdentifier }, Messages::NetworkConnectionToWebProcess::GetNetworkLoadInformationResponse::Reply { response }, 0);
739     return response;
740 }
741
742 Vector<NetworkTransactionInformation> WebLoaderStrategy::intermediateLoadInformationFromResourceLoadIdentifier(uint64_t resourceLoadIdentifier)
743 {
744     Vector<NetworkTransactionInformation> information;
745     WebProcess::singleton().ensureNetworkProcessConnection().connection().sendSync(Messages::NetworkConnectionToWebProcess::GetNetworkLoadIntermediateInformation { resourceLoadIdentifier }, Messages::NetworkConnectionToWebProcess::GetNetworkLoadIntermediateInformation::Reply { information }, 0);
746     return information;
747 }
748
749 NetworkLoadMetrics WebLoaderStrategy::networkMetricsFromResourceLoadIdentifier(uint64_t resourceLoadIdentifier)
750 {
751     NetworkLoadMetrics networkMetrics;
752     WebProcess::singleton().ensureNetworkProcessConnection().connection().sendSync(Messages::NetworkConnectionToWebProcess::TakeNetworkLoadInformationMetrics { resourceLoadIdentifier }, Messages::NetworkConnectionToWebProcess::TakeNetworkLoadInformationMetrics::Reply { networkMetrics }, 0);
753     return networkMetrics;
754 }
755
756 bool WebLoaderStrategy::shouldPerformSecurityChecks() const
757 {
758     return RuntimeEnabledFeatures::sharedFeatures().restrictedHTTPResponseAccess();
759 }
760
761 bool WebLoaderStrategy::havePerformedSecurityChecks(const ResourceResponse& response) const
762 {
763     if (!shouldPerformSecurityChecks())
764         return false;
765     switch (response.source()) {
766     case ResourceResponse::Source::ApplicationCache:
767     case ResourceResponse::Source::MemoryCache:
768     case ResourceResponse::Source::MemoryCacheAfterValidation:
769     case ResourceResponse::Source::ServiceWorker:
770     case ResourceResponse::Source::InspectorOverride:
771         return false;
772     case ResourceResponse::Source::DiskCache:
773     case ResourceResponse::Source::DiskCacheAfterValidation:
774     case ResourceResponse::Source::Network:
775     case ResourceResponse::Source::Unknown:
776         return true;
777     }
778     ASSERT_NOT_REACHED();
779     return false;
780 }
781
782 } // namespace WebKit
783
784 #undef RELEASE_LOG_IF_ALLOWED
785 #undef RELEASE_LOG_ERROR_IF_ALLOWED