| 1 | /* |
| 2 | * Copyright (C) 2006-2017 Apple Inc. All rights reserved. |
| 3 | * Copyright (C) 2011 Google Inc. All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * |
| 9 | * 1. Redistributions of source code must retain the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer. |
| 11 | * 2. Redistributions in binary form must reproduce the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer in the |
| 13 | * documentation and/or other materials provided with the distribution. |
| 14 | * 3. Neither the name of Apple Inc. ("Apple") nor the names of |
| 15 | * its contributors may be used to endorse or promote products derived |
| 16 | * from this software without specific prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
| 19 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 21 | * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
| 22 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 25 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | */ |
| 29 | |
| 30 | #pragma once |
| 31 | |
| 32 | #include "CachedRawResourceClient.h" |
| 33 | #include "CachedResourceHandle.h" |
| 34 | #include "ContentSecurityPolicyClient.h" |
| 35 | #include "DeviceOrientationOrMotionPermissionState.h" |
| 36 | #include "DocumentIdentifier.h" |
| 37 | #include "DocumentWriter.h" |
| 38 | #include "FrameDestructionObserver.h" |
| 39 | #include "LinkIcon.h" |
| 40 | #include "LoadTiming.h" |
| 41 | #include "NavigationAction.h" |
| 42 | #include "ResourceError.h" |
| 43 | #include "ResourceLoaderOptions.h" |
| 44 | #include "ResourceRequest.h" |
| 45 | #include "ResourceResponse.h" |
| 46 | #include "SecurityPolicyViolationEvent.h" |
| 47 | #include "ServiceWorkerRegistrationData.h" |
| 48 | #include "StringWithDirection.h" |
| 49 | #include "StyleSheetContents.h" |
| 50 | #include "SubstituteData.h" |
| 51 | #include "Timer.h" |
| 52 | #include <wtf/HashSet.h> |
| 53 | #include <wtf/OptionSet.h> |
| 54 | #include <wtf/RefPtr.h> |
| 55 | #include <wtf/Vector.h> |
| 56 | |
| 57 | #if ENABLE(APPLICATION_MANIFEST) |
| 58 | #include "ApplicationManifest.h" |
| 59 | #endif |
| 60 | |
| 61 | #if HAVE(RUNLOOP_TIMER) |
| 62 | #include <wtf/RunLoopTimer.h> |
| 63 | #endif |
| 64 | |
| 65 | #if PLATFORM(COCOA) |
| 66 | #include <wtf/SchedulePair.h> |
| 67 | #endif |
| 68 | |
| 69 | namespace WebCore { |
| 70 | |
| 71 | class ApplicationCacheHost; |
| 72 | class ApplicationManifestLoader; |
| 73 | class Archive; |
| 74 | class ArchiveResource; |
| 75 | class ArchiveResourceCollection; |
| 76 | class CachedRawResource; |
| 77 | class CachedResourceLoader; |
| 78 | class ContentFilter; |
| 79 | struct ; |
| 80 | class FormState; |
| 81 | class Frame; |
| 82 | class FrameLoader; |
| 83 | class IconLoader; |
| 84 | class Page; |
| 85 | class PreviewConverter; |
| 86 | class ResourceLoader; |
| 87 | class SharedBuffer; |
| 88 | class SWClientConnection; |
| 89 | class SubresourceLoader; |
| 90 | class SubstituteResource; |
| 91 | |
| 92 | enum class ShouldContinue; |
| 93 | |
| 94 | using ResourceLoaderMap = HashMap<unsigned long, RefPtr<ResourceLoader>>; |
| 95 | |
| 96 | enum class AutoplayPolicy : uint8_t { |
| 97 | Default, // Uses policies specified in document settings. |
| 98 | Allow, |
| 99 | AllowWithoutSound, |
| 100 | Deny, |
| 101 | }; |
| 102 | |
| 103 | enum class AutoplayQuirk : uint8_t { |
| 104 | SynthesizedPauseEvents = 1 << 0, |
| 105 | InheritedUserGestures = 1 << 1, |
| 106 | ArbitraryUserGestures = 1 << 2, |
| 107 | PerDocumentAutoplayBehavior = 1 << 3, |
| 108 | }; |
| 109 | |
| 110 | enum class : uint8_t { |
| 111 | , // Uses policies specified in frame settings. |
| 112 | , |
| 113 | , |
| 114 | }; |
| 115 | |
| 116 | enum class MetaViewportPolicy : uint8_t { |
| 117 | Default, |
| 118 | Respect, |
| 119 | Ignore, |
| 120 | }; |
| 121 | |
| 122 | enum class MediaSourcePolicy : uint8_t { |
| 123 | Default, |
| 124 | Disable, |
| 125 | Enable |
| 126 | }; |
| 127 | |
| 128 | enum class SimulatedMouseEventsDispatchPolicy : uint8_t { |
| 129 | Default, |
| 130 | Allow, |
| 131 | Deny, |
| 132 | }; |
| 133 | |
| 134 | enum class LegacyOverflowScrollingTouchPolicy : uint8_t { |
| 135 | Default, |
| 136 | Disable, |
| 137 | Enable, |
| 138 | }; |
| 139 | |
| 140 | class DocumentLoader |
| 141 | : public RefCounted<DocumentLoader> |
| 142 | , public FrameDestructionObserver |
| 143 | , public ContentSecurityPolicyClient |
| 144 | , private CachedRawResourceClient { |
| 145 | WTF_MAKE_FAST_ALLOCATED; |
| 146 | friend class ContentFilter; |
| 147 | public: |
| 148 | static Ref<DocumentLoader> create(const ResourceRequest& request, const SubstituteData& data) |
| 149 | { |
| 150 | return adoptRef(*new DocumentLoader(request, data)); |
| 151 | } |
| 152 | WEBCORE_EXPORT virtual ~DocumentLoader(); |
| 153 | |
| 154 | void attachToFrame(Frame&); |
| 155 | |
| 156 | WEBCORE_EXPORT virtual void detachFromFrame(); |
| 157 | |
| 158 | WEBCORE_EXPORT FrameLoader* frameLoader() const; |
| 159 | WEBCORE_EXPORT SubresourceLoader* mainResourceLoader() const; |
| 160 | WEBCORE_EXPORT RefPtr<SharedBuffer> mainResourceData() const; |
| 161 | |
| 162 | DocumentWriter& writer() const { return m_writer; } |
| 163 | |
| 164 | const ResourceRequest& originalRequest() const; |
| 165 | const ResourceRequest& originalRequestCopy() const; |
| 166 | |
| 167 | const ResourceRequest& request() const; |
| 168 | ResourceRequest& request(); |
| 169 | |
| 170 | CachedResourceLoader& cachedResourceLoader() { return m_cachedResourceLoader; } |
| 171 | |
| 172 | const SubstituteData& substituteData() const { return m_substituteData; } |
| 173 | |
| 174 | const URL& url() const; |
| 175 | const URL& unreachableURL() const; |
| 176 | |
| 177 | const URL& originalURL() const; |
| 178 | const URL& responseURL() const; |
| 179 | const String& responseMIMEType() const; |
| 180 | #if PLATFORM(IOS_FAMILY) |
| 181 | // FIXME: This method seems to violate the encapsulation of this class. |
| 182 | WEBCORE_EXPORT void setResponseMIMEType(const String&); |
| 183 | #endif |
| 184 | const String& currentContentType() const; |
| 185 | void replaceRequestURLForSameDocumentNavigation(const URL&); |
| 186 | bool isStopping() const { return m_isStopping; } |
| 187 | void stopLoading(); |
| 188 | void setCommitted(bool committed) { m_committed = committed; } |
| 189 | bool isCommitted() const { return m_committed; } |
| 190 | WEBCORE_EXPORT bool isLoading() const; |
| 191 | |
| 192 | const ResourceError& mainDocumentError() const { return m_mainDocumentError; } |
| 193 | |
| 194 | const ResourceResponse& response() const { return m_response; } |
| 195 | |
| 196 | // FIXME: This method seems to violate the encapsulation of this class. |
| 197 | void setResponse(const ResourceResponse& response) { m_response = response; } |
| 198 | |
| 199 | bool isClientRedirect() const { return m_isClientRedirect; } |
| 200 | void setIsClientRedirect(bool isClientRedirect) { m_isClientRedirect = isClientRedirect; } |
| 201 | void dispatchOnloadEvents(); |
| 202 | bool wasOnloadDispatched() { return m_wasOnloadDispatched; } |
| 203 | WEBCORE_EXPORT bool isLoadingInAPISense() const; |
| 204 | WEBCORE_EXPORT void setTitle(const StringWithDirection&); |
| 205 | const String& overrideEncoding() const { return m_overrideEncoding; } |
| 206 | |
| 207 | #if PLATFORM(COCOA) |
| 208 | void schedule(SchedulePair&); |
| 209 | void unschedule(SchedulePair&); |
| 210 | #endif |
| 211 | |
| 212 | #if ENABLE(WEB_ARCHIVE) || ENABLE(MHTML) |
| 213 | void setArchive(Ref<Archive>&&); |
| 214 | WEBCORE_EXPORT void addAllArchiveResources(Archive&); |
| 215 | WEBCORE_EXPORT void addArchiveResource(Ref<ArchiveResource>&&); |
| 216 | RefPtr<Archive> popArchiveForSubframe(const String& frameName, const URL&); |
| 217 | WEBCORE_EXPORT SharedBuffer* parsedArchiveData() const; |
| 218 | |
| 219 | WEBCORE_EXPORT bool scheduleArchiveLoad(ResourceLoader&, const ResourceRequest&); |
| 220 | #endif |
| 221 | |
| 222 | void scheduleSubstituteResourceLoad(ResourceLoader&, SubstituteResource&); |
| 223 | void scheduleCannotShowURLError(ResourceLoader&); |
| 224 | |
| 225 | // Return the ArchiveResource for the URL only when loading an Archive |
| 226 | WEBCORE_EXPORT ArchiveResource* archiveResourceForURL(const URL&) const; |
| 227 | |
| 228 | WEBCORE_EXPORT RefPtr<ArchiveResource> mainResource() const; |
| 229 | |
| 230 | // Return an ArchiveResource for the URL, either creating from live data or |
| 231 | // pulling from the ArchiveResourceCollection. |
| 232 | WEBCORE_EXPORT RefPtr<ArchiveResource> subresource(const URL&) const; |
| 233 | |
| 234 | WEBCORE_EXPORT Vector<Ref<ArchiveResource>> subresources() const; |
| 235 | |
| 236 | #ifndef NDEBUG |
| 237 | bool isSubstituteLoadPending(ResourceLoader*) const; |
| 238 | #endif |
| 239 | void cancelPendingSubstituteLoad(ResourceLoader*); |
| 240 | |
| 241 | void addResponse(const ResourceResponse&); |
| 242 | const Vector<ResourceResponse>& responses() const { return m_responses; } |
| 243 | |
| 244 | const NavigationAction& triggeringAction() const { return m_triggeringAction; } |
| 245 | void setTriggeringAction(NavigationAction&&); |
| 246 | void setOverrideEncoding(const String& encoding) { m_overrideEncoding = encoding; } |
| 247 | void setLastCheckedRequest(ResourceRequest&& request) { m_lastCheckedRequest = WTFMove(request); } |
| 248 | const ResourceRequest& lastCheckedRequest() { return m_lastCheckedRequest; } |
| 249 | |
| 250 | void stopRecordingResponses(); |
| 251 | const StringWithDirection& title() const { return m_pageTitle; } |
| 252 | |
| 253 | WEBCORE_EXPORT URL urlForHistory() const; |
| 254 | WEBCORE_EXPORT bool urlForHistoryReflectsFailure() const; |
| 255 | |
| 256 | // These accessors accommodate WebCore's somewhat fickle custom of creating history |
| 257 | // items for redirects, but only sometimes. For "source" and "destination", |
| 258 | // these accessors return the URL that would have been used if a history |
| 259 | // item were created. This allows WebKit to link history items reflecting |
| 260 | // redirects into a chain from start to finish. |
| 261 | String clientRedirectSourceForHistory() const { return m_clientRedirectSourceForHistory; } // null if no client redirect occurred. |
| 262 | String clientRedirectDestinationForHistory() const { return urlForHistory(); } |
| 263 | void setClientRedirectSourceForHistory(const String& clientRedirectSourceForHistory) { m_clientRedirectSourceForHistory = clientRedirectSourceForHistory; } |
| 264 | |
| 265 | String serverRedirectSourceForHistory() const { return (urlForHistory() == url() || url() == WTF::blankURL()) ? String() : urlForHistory().string(); } // null if no server redirect occurred. |
| 266 | String serverRedirectDestinationForHistory() const { return url(); } |
| 267 | |
| 268 | bool didCreateGlobalHistoryEntry() const { return m_didCreateGlobalHistoryEntry; } |
| 269 | void setDidCreateGlobalHistoryEntry(bool didCreateGlobalHistoryEntry) { m_didCreateGlobalHistoryEntry = didCreateGlobalHistoryEntry; } |
| 270 | |
| 271 | bool subresourceLoadersArePageCacheAcceptable() const { return m_subresourceLoadersArePageCacheAcceptable; } |
| 272 | |
| 273 | void setDefersLoading(bool); |
| 274 | void setMainResourceDataBufferingPolicy(DataBufferingPolicy); |
| 275 | |
| 276 | void startLoadingMainResource(); |
| 277 | WEBCORE_EXPORT void cancelMainResourceLoad(const ResourceError&); |
| 278 | void willContinueMainResourceLoadAfterRedirect(const ResourceRequest&); |
| 279 | |
| 280 | bool isLoadingMainResource() const { return m_loadingMainResource; } |
| 281 | bool isLoadingMultipartContent() const { return m_isLoadingMultipartContent; } |
| 282 | |
| 283 | void stopLoadingPlugIns(); |
| 284 | void stopLoadingSubresources(); |
| 285 | WEBCORE_EXPORT void stopLoadingAfterXFrameOptionsOrContentSecurityPolicyDenied(unsigned long identifier, const ResourceResponse&); |
| 286 | |
| 287 | bool userContentExtensionsEnabled() const { return m_userContentExtensionsEnabled; } |
| 288 | void setUserContentExtensionsEnabled(bool enabled) { m_userContentExtensionsEnabled = enabled; } |
| 289 | |
| 290 | #if ENABLE(DEVICE_ORIENTATION) |
| 291 | DeviceOrientationOrMotionPermissionState deviceOrientationAndMotionAccessState() const { return m_deviceOrientationAndMotionAccessState; } |
| 292 | void setDeviceOrientationAndMotionAccessState(DeviceOrientationOrMotionPermissionState state) { m_deviceOrientationAndMotionAccessState = state; } |
| 293 | #endif |
| 294 | |
| 295 | AutoplayPolicy autoplayPolicy() const { return m_autoplayPolicy; } |
| 296 | void setAutoplayPolicy(AutoplayPolicy policy) { m_autoplayPolicy = policy; } |
| 297 | |
| 298 | void setCustomUserAgent(const String& customUserAgent) { m_customUserAgent = customUserAgent; } |
| 299 | const String& customUserAgent() const { return m_customUserAgent; } |
| 300 | |
| 301 | void setCustomJavaScriptUserAgentAsSiteSpecificQuirks(const String& customUserAgent) { m_customJavaScriptUserAgentAsSiteSpecificQuirks = customUserAgent; } |
| 302 | const String& customJavaScriptUserAgentAsSiteSpecificQuirks() const { return m_customJavaScriptUserAgentAsSiteSpecificQuirks; } |
| 303 | |
| 304 | void setCustomNavigatorPlatform(const String& customNavigatorPlatform) { m_customNavigatorPlatform = customNavigatorPlatform; } |
| 305 | const String& customNavigatorPlatform() const { return m_customNavigatorPlatform; } |
| 306 | |
| 307 | OptionSet<AutoplayQuirk> allowedAutoplayQuirks() const { return m_allowedAutoplayQuirks; } |
| 308 | void setAllowedAutoplayQuirks(OptionSet<AutoplayQuirk> allowedQuirks) { m_allowedAutoplayQuirks = allowedQuirks; } |
| 309 | |
| 310 | PopUpPolicy () const { return m_popUpPolicy; } |
| 311 | void (PopUpPolicy ) { m_popUpPolicy = popUpPolicy; } |
| 312 | |
| 313 | MetaViewportPolicy metaViewportPolicy() const { return m_metaViewportPolicy; } |
| 314 | void setMetaViewportPolicy(MetaViewportPolicy policy) { m_metaViewportPolicy = policy; } |
| 315 | |
| 316 | MediaSourcePolicy mediaSourcePolicy() const { return m_mediaSourcePolicy; } |
| 317 | void setMediaSourcePolicy(MediaSourcePolicy policy) { m_mediaSourcePolicy = policy; } |
| 318 | |
| 319 | SimulatedMouseEventsDispatchPolicy simulatedMouseEventsDispatchPolicy() const { return m_simulatedMouseEventsDispatchPolicy; } |
| 320 | void setSimulatedMouseEventsDispatchPolicy(SimulatedMouseEventsDispatchPolicy policy) { m_simulatedMouseEventsDispatchPolicy = policy; } |
| 321 | |
| 322 | LegacyOverflowScrollingTouchPolicy legacyOverflowScrollingTouchPolicy() const { return m_legacyOverflowScrollingTouchPolicy; } |
| 323 | void setLegacyOverflowScrollingTouchPolicy(LegacyOverflowScrollingTouchPolicy policy) { m_legacyOverflowScrollingTouchPolicy = policy; } |
| 324 | |
| 325 | void addSubresourceLoader(ResourceLoader*); |
| 326 | void removeSubresourceLoader(LoadCompletionType, ResourceLoader*); |
| 327 | void addPlugInStreamLoader(ResourceLoader&); |
| 328 | void removePlugInStreamLoader(ResourceLoader&); |
| 329 | |
| 330 | void subresourceLoaderFinishedLoadingOnePart(ResourceLoader*); |
| 331 | |
| 332 | void setDeferMainResourceDataLoad(bool defer) { m_deferMainResourceDataLoad = defer; } |
| 333 | |
| 334 | void didTellClientAboutLoad(const String& url); |
| 335 | bool haveToldClientAboutLoad(const String& url) { return m_resourcesClientKnowsAbout.contains(url); } |
| 336 | void recordMemoryCacheLoadForFutureClientNotification(const ResourceRequest&); |
| 337 | void takeMemoryCacheLoadsForClientNotification(Vector<ResourceRequest>& loads); |
| 338 | |
| 339 | LoadTiming& timing() { return m_loadTiming; } |
| 340 | void resetTiming() { m_loadTiming = LoadTiming(); } |
| 341 | |
| 342 | // The WebKit layer calls this function when it's ready for the data to actually be added to the document. |
| 343 | WEBCORE_EXPORT void commitData(const char* bytes, size_t length); |
| 344 | |
| 345 | ApplicationCacheHost& applicationCacheHost() const; |
| 346 | ApplicationCacheHost* applicationCacheHostUnlessBeingDestroyed() const; |
| 347 | |
| 348 | void checkLoadComplete(); |
| 349 | |
| 350 | // The URL of the document resulting from this DocumentLoader. |
| 351 | URL documentURL() const; |
| 352 | |
| 353 | #if USE(QUICK_LOOK) |
| 354 | void setPreviewConverter(std::unique_ptr<PreviewConverter>&&); |
| 355 | PreviewConverter* previewConverter() const; |
| 356 | #endif |
| 357 | |
| 358 | #if ENABLE(CONTENT_EXTENSIONS) |
| 359 | void addPendingContentExtensionSheet(const String& identifier, StyleSheetContents&); |
| 360 | void addPendingContentExtensionDisplayNoneSelector(const String& identifier, const String& selector, uint32_t selectorID); |
| 361 | #endif |
| 362 | |
| 363 | void setShouldOpenExternalURLsPolicy(ShouldOpenExternalURLsPolicy shouldOpenExternalURLsPolicy) { m_shouldOpenExternalURLsPolicy = shouldOpenExternalURLsPolicy; } |
| 364 | ShouldOpenExternalURLsPolicy shouldOpenExternalURLsPolicyToPropagate() const; |
| 365 | |
| 366 | #if ENABLE(CONTENT_FILTERING) |
| 367 | ContentFilter* contentFilter() const; |
| 368 | #endif |
| 369 | |
| 370 | bool isAlwaysOnLoggingAllowed() const; |
| 371 | |
| 372 | void startIconLoading(); |
| 373 | WEBCORE_EXPORT void didGetLoadDecisionForIcon(bool decision, uint64_t loadIdentifier, uint64_t newCallbackID); |
| 374 | void finishedLoadingIcon(IconLoader&, SharedBuffer*); |
| 375 | |
| 376 | const Vector<LinkIcon>& linkIcons() const { return m_linkIcons; } |
| 377 | |
| 378 | #if ENABLE(APPLICATION_MANIFEST) |
| 379 | WEBCORE_EXPORT uint64_t loadApplicationManifest(); |
| 380 | void finishedLoadingApplicationManifest(ApplicationManifestLoader&); |
| 381 | #endif |
| 382 | |
| 383 | WEBCORE_EXPORT void (Vector<CustomHeaderFields>&&); |
| 384 | const Vector<CustomHeaderFields>& () const { return m_customHeaderFields; } |
| 385 | |
| 386 | void setAllowsWebArchiveForMainFrame(bool allowsWebArchiveForMainFrame) { m_allowsWebArchiveForMainFrame = allowsWebArchiveForMainFrame; } |
| 387 | bool allowsWebArchiveForMainFrame() const { return m_allowsWebArchiveForMainFrame; } |
| 388 | |
| 389 | void setDownloadAttribute(const String& attribute) { m_downloadAttribute = attribute; } |
| 390 | const String& downloadAttribute() const { return m_downloadAttribute; } |
| 391 | |
| 392 | WEBCORE_EXPORT void applyPoliciesToSettings(); |
| 393 | |
| 394 | protected: |
| 395 | WEBCORE_EXPORT DocumentLoader(const ResourceRequest&, const SubstituteData&); |
| 396 | |
| 397 | WEBCORE_EXPORT virtual void attachToFrame(); |
| 398 | |
| 399 | bool m_deferMainResourceDataLoad { true }; |
| 400 | |
| 401 | private: |
| 402 | Document* document() const; |
| 403 | |
| 404 | #if ENABLE(SERVICE_WORKER) |
| 405 | void matchRegistration(const URL&, CompletionHandler<void(Optional<ServiceWorkerRegistrationData>&&)>&&); |
| 406 | #endif |
| 407 | void registerTemporaryServiceWorkerClient(const URL&); |
| 408 | void unregisterTemporaryServiceWorkerClient(); |
| 409 | |
| 410 | void loadMainResource(ResourceRequest&&); |
| 411 | |
| 412 | void setRequest(const ResourceRequest&); |
| 413 | |
| 414 | void commitIfReady(); |
| 415 | void setMainDocumentError(const ResourceError&); |
| 416 | void commitLoad(const char*, int); |
| 417 | void clearMainResourceLoader(); |
| 418 | |
| 419 | void setupForReplace(); |
| 420 | void maybeFinishLoadingMultipartContent(); |
| 421 | |
| 422 | bool maybeCreateArchive(); |
| 423 | #if ENABLE(WEB_ARCHIVE) || ENABLE(MHTML) |
| 424 | void clearArchiveResources(); |
| 425 | #endif |
| 426 | |
| 427 | void willSendRequest(ResourceRequest&&, const ResourceResponse&, CompletionHandler<void(ResourceRequest&&)>&&); |
| 428 | void finishedLoading(); |
| 429 | void mainReceivedError(const ResourceError&); |
| 430 | WEBCORE_EXPORT void redirectReceived(CachedResource&, ResourceRequest&&, const ResourceResponse&, CompletionHandler<void(ResourceRequest&&)>&&) override; |
| 431 | WEBCORE_EXPORT void responseReceived(CachedResource&, const ResourceResponse&, CompletionHandler<void()>&&) override; |
| 432 | WEBCORE_EXPORT void dataReceived(CachedResource&, const char* data, int length) override; |
| 433 | WEBCORE_EXPORT void notifyFinished(CachedResource&) override; |
| 434 | |
| 435 | void responseReceived(const ResourceResponse&, CompletionHandler<void()>&&); |
| 436 | void dataReceived(const char* data, int length); |
| 437 | |
| 438 | bool maybeLoadEmpty(); |
| 439 | |
| 440 | bool isMultipartReplacingLoad() const; |
| 441 | bool isPostOrRedirectAfterPost(const ResourceRequest&, const ResourceResponse&); |
| 442 | |
| 443 | bool tryLoadingRequestFromApplicationCache(); |
| 444 | bool tryLoadingSubstituteData(); |
| 445 | bool tryLoadingRedirectRequestFromApplicationCache(const ResourceRequest&); |
| 446 | #if ENABLE(SERVICE_WORKER) |
| 447 | void restartLoadingDueToServiceWorkerRegistrationChange(ResourceRequest&&, Optional<ServiceWorkerRegistrationData>&&); |
| 448 | #endif |
| 449 | void continueAfterContentPolicy(PolicyAction); |
| 450 | |
| 451 | void stopLoadingForPolicyChange(); |
| 452 | ResourceError interruptedForPolicyChangeError() const; |
| 453 | |
| 454 | #if HAVE(RUNLOOP_TIMER) |
| 455 | typedef RunLoopTimer<DocumentLoader> DocumentLoaderTimer; |
| 456 | #else |
| 457 | typedef Timer DocumentLoaderTimer; |
| 458 | #endif |
| 459 | void handleSubstituteDataLoadNow(); |
| 460 | void startDataLoadTimer(); |
| 461 | |
| 462 | void deliverSubstituteResourcesAfterDelay(); |
| 463 | void substituteResourceDeliveryTimerFired(); |
| 464 | |
| 465 | void clearMainResource(); |
| 466 | |
| 467 | void cancelPolicyCheckIfNeeded(); |
| 468 | void becomeMainResourceClient(); |
| 469 | |
| 470 | void notifyFinishedLoadingIcon(uint64_t callbackIdentifier, SharedBuffer*); |
| 471 | |
| 472 | #if ENABLE(APPLICATION_MANIFEST) |
| 473 | void notifyFinishedLoadingApplicationManifest(uint64_t callbackIdentifier, Optional<ApplicationManifest>); |
| 474 | #endif |
| 475 | |
| 476 | // ContentSecurityPolicyClient |
| 477 | WEBCORE_EXPORT void addConsoleMessage(MessageSource, MessageLevel, const String&, unsigned long requestIdentifier) final; |
| 478 | WEBCORE_EXPORT void sendCSPViolationReport(URL&&, Ref<FormData>&&) final; |
| 479 | WEBCORE_EXPORT void enqueueSecurityPolicyViolationEvent(SecurityPolicyViolationEvent::Init&&) final; |
| 480 | |
| 481 | bool disallowWebArchive() const; |
| 482 | |
| 483 | Ref<CachedResourceLoader> m_cachedResourceLoader; |
| 484 | |
| 485 | CachedResourceHandle<CachedRawResource> m_mainResource; |
| 486 | ResourceLoaderMap m_subresourceLoaders; |
| 487 | ResourceLoaderMap m_multipartSubresourceLoaders; |
| 488 | ResourceLoaderMap m_plugInStreamLoaders; |
| 489 | |
| 490 | mutable DocumentWriter m_writer; |
| 491 | |
| 492 | // A reference to actual request used to create the data source. |
| 493 | // This should only be used by the resourceLoadDelegate's |
| 494 | // identifierForInitialRequest:fromDatasource: method. It is |
| 495 | // not guaranteed to remain unchanged, as requests are mutable. |
| 496 | ResourceRequest m_originalRequest; |
| 497 | |
| 498 | SubstituteData m_substituteData; |
| 499 | |
| 500 | // A copy of the original request used to create the data source. |
| 501 | // We have to copy the request because requests are mutable. |
| 502 | ResourceRequest m_originalRequestCopy; |
| 503 | |
| 504 | // The 'working' request. It may be mutated |
| 505 | // several times from the original request to include additional |
| 506 | // headers, cookie information, canonicalization and redirects. |
| 507 | ResourceRequest m_request; |
| 508 | |
| 509 | ResourceResponse m_response; |
| 510 | |
| 511 | ResourceError m_mainDocumentError; |
| 512 | |
| 513 | bool m_originalSubstituteDataWasValid; |
| 514 | bool m_committed { false }; |
| 515 | bool m_isStopping { false }; |
| 516 | bool m_gotFirstByte { false }; |
| 517 | bool m_isClientRedirect { false }; |
| 518 | bool m_isLoadingMultipartContent { false }; |
| 519 | |
| 520 | // FIXME: Document::m_processingLoadEvent and DocumentLoader::m_wasOnloadDispatched are roughly the same |
| 521 | // and should be merged. |
| 522 | bool m_wasOnloadDispatched { false }; |
| 523 | |
| 524 | StringWithDirection m_pageTitle; |
| 525 | |
| 526 | String m_overrideEncoding; |
| 527 | |
| 528 | // The action that triggered loading - we keep this around for the |
| 529 | // benefit of the various policy handlers. |
| 530 | NavigationAction m_triggeringAction; |
| 531 | |
| 532 | // The last request that we checked click policy for - kept around |
| 533 | // so we can avoid asking again needlessly. |
| 534 | ResourceRequest m_lastCheckedRequest; |
| 535 | |
| 536 | // We retain all the received responses so we can play back the |
| 537 | // WebResourceLoadDelegate messages if the item is loaded from the |
| 538 | // page cache. |
| 539 | Vector<ResourceResponse> m_responses; |
| 540 | bool m_stopRecordingResponses { false }; |
| 541 | |
| 542 | typedef HashMap<RefPtr<ResourceLoader>, RefPtr<SubstituteResource>> SubstituteResourceMap; |
| 543 | SubstituteResourceMap m_pendingSubstituteResources; |
| 544 | Timer m_substituteResourceDeliveryTimer; |
| 545 | |
| 546 | std::unique_ptr<ArchiveResourceCollection> m_archiveResourceCollection; |
| 547 | #if ENABLE(WEB_ARCHIVE) || ENABLE(MHTML) |
| 548 | RefPtr<Archive> m_archive; |
| 549 | RefPtr<SharedBuffer> m_parsedArchiveData; |
| 550 | #endif |
| 551 | |
| 552 | HashSet<String> m_resourcesClientKnowsAbout; |
| 553 | Vector<ResourceRequest> m_resourcesLoadedFromMemoryCacheForClientNotification; |
| 554 | |
| 555 | String m_clientRedirectSourceForHistory; |
| 556 | bool m_didCreateGlobalHistoryEntry { false }; |
| 557 | |
| 558 | bool m_loadingMainResource { false }; |
| 559 | LoadTiming m_loadTiming; |
| 560 | |
| 561 | MonotonicTime m_timeOfLastDataReceived; |
| 562 | unsigned long m_identifierForLoadWithoutResourceLoader { 0 }; |
| 563 | |
| 564 | DocumentLoaderTimer m_dataLoadTimer; |
| 565 | bool m_waitingForContentPolicy { false }; |
| 566 | bool m_waitingForNavigationPolicy { false }; |
| 567 | |
| 568 | HashMap<uint64_t, LinkIcon> m_iconsPendingLoadDecision; |
| 569 | HashMap<std::unique_ptr<IconLoader>, uint64_t> m_iconLoaders; |
| 570 | Vector<LinkIcon> m_linkIcons; |
| 571 | |
| 572 | #if ENABLE(APPLICATION_MANIFEST) |
| 573 | HashMap<std::unique_ptr<ApplicationManifestLoader>, uint64_t> m_applicationManifestLoaders; |
| 574 | #endif |
| 575 | |
| 576 | Vector<CustomHeaderFields> ; |
| 577 | |
| 578 | bool m_subresourceLoadersArePageCacheAcceptable { false }; |
| 579 | ShouldOpenExternalURLsPolicy m_shouldOpenExternalURLsPolicy { ShouldOpenExternalURLsPolicy::ShouldNotAllow }; |
| 580 | |
| 581 | std::unique_ptr<ApplicationCacheHost> m_applicationCacheHost; |
| 582 | |
| 583 | #if ENABLE(CONTENT_FILTERING) |
| 584 | std::unique_ptr<ContentFilter> m_contentFilter; |
| 585 | #endif |
| 586 | |
| 587 | #if USE(QUICK_LOOK) |
| 588 | std::unique_ptr<PreviewConverter> m_previewConverter; |
| 589 | #endif |
| 590 | |
| 591 | #if ENABLE(CONTENT_EXTENSIONS) |
| 592 | HashMap<String, RefPtr<StyleSheetContents>> m_pendingNamedContentExtensionStyleSheets; |
| 593 | HashMap<String, Vector<std::pair<String, uint32_t>>> m_pendingContentExtensionDisplayNoneSelectors; |
| 594 | #endif |
| 595 | String m_customUserAgent; |
| 596 | String m_customJavaScriptUserAgentAsSiteSpecificQuirks; |
| 597 | String m_customNavigatorPlatform; |
| 598 | bool m_userContentExtensionsEnabled { true }; |
| 599 | #if ENABLE(DEVICE_ORIENTATION) |
| 600 | DeviceOrientationOrMotionPermissionState m_deviceOrientationAndMotionAccessState { DeviceOrientationOrMotionPermissionState::Prompt }; |
| 601 | #endif |
| 602 | AutoplayPolicy m_autoplayPolicy { AutoplayPolicy::Default }; |
| 603 | OptionSet<AutoplayQuirk> m_allowedAutoplayQuirks; |
| 604 | PopUpPolicy { PopUpPolicy::Default }; |
| 605 | MetaViewportPolicy m_metaViewportPolicy { MetaViewportPolicy::Default }; |
| 606 | MediaSourcePolicy m_mediaSourcePolicy { MediaSourcePolicy::Default }; |
| 607 | SimulatedMouseEventsDispatchPolicy m_simulatedMouseEventsDispatchPolicy { SimulatedMouseEventsDispatchPolicy::Default }; |
| 608 | LegacyOverflowScrollingTouchPolicy m_legacyOverflowScrollingTouchPolicy { LegacyOverflowScrollingTouchPolicy::Default }; |
| 609 | |
| 610 | #if ENABLE(SERVICE_WORKER) |
| 611 | Optional<ServiceWorkerRegistrationData> m_serviceWorkerRegistrationData; |
| 612 | struct TemporaryServiceWorkerClient { |
| 613 | DocumentIdentifier documentIdentifier; |
| 614 | Ref<SWClientConnection> serviceWorkerConnection; |
| 615 | }; |
| 616 | Optional<TemporaryServiceWorkerClient> m_temporaryServiceWorkerClient; |
| 617 | #endif |
| 618 | |
| 619 | #ifndef NDEBUG |
| 620 | bool m_hasEverBeenAttached { false }; |
| 621 | #endif |
| 622 | |
| 623 | bool m_allowsWebArchiveForMainFrame { false }; |
| 624 | String m_downloadAttribute; |
| 625 | }; |
| 626 | |
| 627 | inline void DocumentLoader::recordMemoryCacheLoadForFutureClientNotification(const ResourceRequest& request) |
| 628 | { |
| 629 | m_resourcesLoadedFromMemoryCacheForClientNotification.append(request); |
| 630 | } |
| 631 | |
| 632 | inline void DocumentLoader::takeMemoryCacheLoadsForClientNotification(Vector<ResourceRequest>& loadsSet) |
| 633 | { |
| 634 | loadsSet.swap(m_resourcesLoadedFromMemoryCacheForClientNotification); |
| 635 | m_resourcesLoadedFromMemoryCacheForClientNotification.clear(); |
| 636 | } |
| 637 | |
| 638 | inline const ResourceRequest& DocumentLoader::originalRequest() const |
| 639 | { |
| 640 | return m_originalRequest; |
| 641 | } |
| 642 | |
| 643 | inline const ResourceRequest& DocumentLoader::originalRequestCopy() const |
| 644 | { |
| 645 | return m_originalRequestCopy; |
| 646 | } |
| 647 | |
| 648 | inline const ResourceRequest& DocumentLoader::request() const |
| 649 | { |
| 650 | return m_request; |
| 651 | } |
| 652 | |
| 653 | inline ResourceRequest& DocumentLoader::request() |
| 654 | { |
| 655 | return m_request; |
| 656 | } |
| 657 | |
| 658 | inline const URL& DocumentLoader::url() const |
| 659 | { |
| 660 | return m_request.url(); |
| 661 | } |
| 662 | |
| 663 | inline const URL& DocumentLoader::originalURL() const |
| 664 | { |
| 665 | return m_originalRequestCopy.url(); |
| 666 | } |
| 667 | |
| 668 | inline const URL& DocumentLoader::responseURL() const |
| 669 | { |
| 670 | return m_response.url(); |
| 671 | } |
| 672 | |
| 673 | inline const String& DocumentLoader::responseMIMEType() const |
| 674 | { |
| 675 | return m_response.mimeType(); |
| 676 | } |
| 677 | |
| 678 | inline const String& DocumentLoader::currentContentType() const |
| 679 | { |
| 680 | return m_writer.mimeType(); |
| 681 | } |
| 682 | |
| 683 | inline const URL& DocumentLoader::unreachableURL() const |
| 684 | { |
| 685 | return m_substituteData.failingURL(); |
| 686 | } |
| 687 | |
| 688 | inline ApplicationCacheHost& DocumentLoader::applicationCacheHost() const |
| 689 | { |
| 690 | // For a short time while the document loader is being destroyed, m_applicationCacheHost is null. |
| 691 | // It's not acceptable to call this function during that time. |
| 692 | ASSERT(m_applicationCacheHost); |
| 693 | return *m_applicationCacheHost; |
| 694 | } |
| 695 | |
| 696 | inline ApplicationCacheHost* DocumentLoader::applicationCacheHostUnlessBeingDestroyed() const |
| 697 | { |
| 698 | return m_applicationCacheHost.get(); |
| 699 | } |
| 700 | |
| 701 | #if ENABLE(CONTENT_FILTERING) |
| 702 | |
| 703 | inline ContentFilter* DocumentLoader::contentFilter() const |
| 704 | { |
| 705 | return m_contentFilter.get(); |
| 706 | } |
| 707 | |
| 708 | #endif |
| 709 | |
| 710 | inline void DocumentLoader::didTellClientAboutLoad(const String& url) |
| 711 | { |
| 712 | #if !PLATFORM(COCOA) |
| 713 | // Don't include data URLs here, as if a lot of data is loaded that way, we hold on to the (large) URL string for too long. |
| 714 | if (protocolIs(url, "data" )) |
| 715 | return; |
| 716 | #endif |
| 717 | if (!url.isEmpty()) |
| 718 | m_resourcesClientKnowsAbout.add(url); |
| 719 | } |
| 720 | |
| 721 | } |
| 722 | |