| 1 | /* |
| 2 | * Copyright (C) 2006-2017 Apple Inc. All rights reserved. |
| 3 | * Copyright (C) 2012 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 "FrameLoaderTypes.h" |
| 33 | #include "LayoutMilestone.h" |
| 34 | #include "LinkIcon.h" |
| 35 | #include <functional> |
| 36 | #include <wtf/Forward.h> |
| 37 | #include <wtf/WallTime.h> |
| 38 | #include <wtf/text/WTFString.h> |
| 39 | |
| 40 | #if ENABLE(APPLICATION_MANIFEST) |
| 41 | #include "ApplicationManifest.h" |
| 42 | #endif |
| 43 | |
| 44 | #if ENABLE(CONTENT_FILTERING) |
| 45 | #include "ContentFilterUnblockHandler.h" |
| 46 | #endif |
| 47 | |
| 48 | #if PLATFORM(COCOA) |
| 49 | #ifdef __OBJC__ |
| 50 | #import <Foundation/Foundation.h> |
| 51 | typedef id RemoteAXObjectRef; |
| 52 | #else |
| 53 | typedef void* RemoteAXObjectRef; |
| 54 | #endif |
| 55 | #endif |
| 56 | |
| 57 | #if PLATFORM(COCOA) |
| 58 | OBJC_CLASS NSArray; |
| 59 | OBJC_CLASS NSCachedURLResponse; |
| 60 | OBJC_CLASS NSDictionary; |
| 61 | OBJC_CLASS NSView; |
| 62 | #endif |
| 63 | |
| 64 | namespace PAL { |
| 65 | class SessionID; |
| 66 | } |
| 67 | |
| 68 | namespace WebCore { |
| 69 | |
| 70 | class AuthenticationChallenge; |
| 71 | class CachedFrame; |
| 72 | class CachedResourceRequest; |
| 73 | class Color; |
| 74 | class DOMWindow; |
| 75 | class DOMWindowExtension; |
| 76 | class DOMWrapperWorld; |
| 77 | class DocumentLoader; |
| 78 | class Element; |
| 79 | class FormState; |
| 80 | class Frame; |
| 81 | class FrameLoader; |
| 82 | class FrameNetworkingContext; |
| 83 | class HTMLAppletElement; |
| 84 | class HTMLFormElement; |
| 85 | class HTMLFrameOwnerElement; |
| 86 | class HTMLPlugInElement; |
| 87 | class HistoryItem; |
| 88 | class IntSize; |
| 89 | class MessageEvent; |
| 90 | class NavigationAction; |
| 91 | class Page; |
| 92 | class PluginViewBase; |
| 93 | class PreviewLoaderClient; |
| 94 | class ProtectionSpace; |
| 95 | class RTCPeerConnectionHandler; |
| 96 | class ResourceError; |
| 97 | class ResourceHandle; |
| 98 | class ResourceRequest; |
| 99 | class ResourceResponse; |
| 100 | class SecurityOrigin; |
| 101 | class SharedBuffer; |
| 102 | class SubstituteData; |
| 103 | class Widget; |
| 104 | |
| 105 | enum class LockBackForwardList : bool; |
| 106 | enum class PolicyDecisionMode; |
| 107 | |
| 108 | struct StringWithDirection; |
| 109 | |
| 110 | typedef WTF::Function<void (PolicyAction, PolicyCheckIdentifier)> FramePolicyFunction; |
| 111 | |
| 112 | class WEBCORE_EXPORT FrameLoaderClient { |
| 113 | WTF_MAKE_FAST_ALLOCATED; |
| 114 | public: |
| 115 | // An inline function cannot be the first non-abstract virtual function declared |
| 116 | // in the class as it results in the vtable being generated as a weak symbol. |
| 117 | // This hurts performance (in Mac OS X at least, when loading frameworks), so we |
| 118 | // don't want to do it in WebKit. |
| 119 | virtual bool hasHTMLView() const; |
| 120 | |
| 121 | virtual ~FrameLoaderClient() = default; |
| 122 | |
| 123 | virtual void frameLoaderDestroyed() = 0; |
| 124 | |
| 125 | virtual bool hasWebView() const = 0; // mainly for assertions |
| 126 | |
| 127 | virtual void makeRepresentation(DocumentLoader*) = 0; |
| 128 | |
| 129 | virtual Optional<uint64_t> pageID() const = 0; |
| 130 | virtual Optional<uint64_t> frameID() const = 0; |
| 131 | virtual PAL::SessionID sessionID() const = 0; |
| 132 | |
| 133 | #if PLATFORM(IOS_FAMILY) |
| 134 | // Returns true if the client forced the layout. |
| 135 | virtual bool forceLayoutOnRestoreFromPageCache() = 0; |
| 136 | #endif |
| 137 | virtual void forceLayoutForNonHTML() = 0; |
| 138 | |
| 139 | virtual void setCopiesOnScroll() = 0; |
| 140 | |
| 141 | virtual void detachedFromParent2() = 0; |
| 142 | virtual void detachedFromParent3() = 0; |
| 143 | |
| 144 | virtual void assignIdentifierToInitialRequest(unsigned long identifier, DocumentLoader*, const ResourceRequest&) = 0; |
| 145 | |
| 146 | virtual void dispatchWillSendRequest(DocumentLoader*, unsigned long identifier, ResourceRequest&, const ResourceResponse& redirectResponse) = 0; |
| 147 | virtual bool shouldUseCredentialStorage(DocumentLoader*, unsigned long identifier) = 0; |
| 148 | virtual void dispatchDidReceiveAuthenticationChallenge(DocumentLoader*, unsigned long identifier, const AuthenticationChallenge&) = 0; |
| 149 | #if USE(PROTECTION_SPACE_AUTH_CALLBACK) |
| 150 | virtual bool canAuthenticateAgainstProtectionSpace(DocumentLoader*, unsigned long identifier, const ProtectionSpace&) = 0; |
| 151 | #endif |
| 152 | |
| 153 | #if PLATFORM(IOS_FAMILY) |
| 154 | virtual RetainPtr<CFDictionaryRef> connectionProperties(DocumentLoader*, unsigned long identifier) = 0; |
| 155 | #endif |
| 156 | |
| 157 | virtual void dispatchDidReceiveResponse(DocumentLoader*, unsigned long identifier, const ResourceResponse&) = 0; |
| 158 | virtual void dispatchDidReceiveContentLength(DocumentLoader*, unsigned long identifier, int dataLength) = 0; |
| 159 | virtual void dispatchDidFinishLoading(DocumentLoader*, unsigned long identifier) = 0; |
| 160 | virtual void dispatchDidFailLoading(DocumentLoader*, unsigned long identifier, const ResourceError&) = 0; |
| 161 | virtual bool dispatchDidLoadResourceFromMemoryCache(DocumentLoader*, const ResourceRequest&, const ResourceResponse&, int length) = 0; |
| 162 | |
| 163 | virtual void dispatchDidDispatchOnloadEvents() = 0; |
| 164 | virtual void dispatchDidReceiveServerRedirectForProvisionalLoad() = 0; |
| 165 | virtual void dispatchDidChangeProvisionalURL() { } |
| 166 | virtual void dispatchDidCancelClientRedirect() = 0; |
| 167 | virtual void dispatchWillPerformClientRedirect(const URL&, double interval, WallTime fireDate, LockBackForwardList) = 0; |
| 168 | virtual void dispatchDidChangeMainDocument() { } |
| 169 | virtual void dispatchWillChangeDocument(const URL&, const URL&) { } |
| 170 | virtual void dispatchDidNavigateWithinPage() { } |
| 171 | virtual void dispatchDidChangeLocationWithinPage() = 0; |
| 172 | virtual void dispatchDidPushStateWithinPage() = 0; |
| 173 | virtual void dispatchDidReplaceStateWithinPage() = 0; |
| 174 | virtual void dispatchDidPopStateWithinPage() = 0; |
| 175 | virtual void dispatchWillClose() = 0; |
| 176 | virtual void dispatchDidReceiveIcon() { } |
| 177 | virtual void dispatchDidStartProvisionalLoad() = 0; |
| 178 | virtual void dispatchDidReceiveTitle(const StringWithDirection&) = 0; |
| 179 | virtual void dispatchDidCommitLoad(Optional<HasInsecureContent>) = 0; |
| 180 | virtual void dispatchDidFailProvisionalLoad(const ResourceError&, WillContinueLoading) = 0; |
| 181 | virtual void dispatchDidFailLoad(const ResourceError&) = 0; |
| 182 | virtual void dispatchDidFinishDocumentLoad() = 0; |
| 183 | virtual void dispatchDidFinishLoad() = 0; |
| 184 | virtual void dispatchDidExplicitOpen(const URL&) { } |
| 185 | #if ENABLE(DATA_DETECTION) |
| 186 | virtual void dispatchDidFinishDataDetection(NSArray *detectionResults) = 0; |
| 187 | #endif |
| 188 | |
| 189 | virtual void dispatchDidLayout() { } |
| 190 | virtual void dispatchDidReachLayoutMilestone(OptionSet<LayoutMilestone>) { } |
| 191 | |
| 192 | virtual Frame* dispatchCreatePage(const NavigationAction&) = 0; |
| 193 | virtual void dispatchShow() = 0; |
| 194 | |
| 195 | virtual void dispatchDecidePolicyForResponse(const ResourceResponse&, const ResourceRequest&, PolicyCheckIdentifier, const String& downloadAttribute, FramePolicyFunction&&) = 0; |
| 196 | virtual void dispatchDecidePolicyForNewWindowAction(const NavigationAction&, const ResourceRequest&, FormState*, const String& frameName, PolicyCheckIdentifier, FramePolicyFunction&&) = 0; |
| 197 | virtual void dispatchDecidePolicyForNavigationAction(const NavigationAction&, const ResourceRequest&, const ResourceResponse& redirectResponse, FormState*, PolicyDecisionMode, PolicyCheckIdentifier, FramePolicyFunction&&) = 0; |
| 198 | virtual void cancelPolicyCheck() = 0; |
| 199 | |
| 200 | virtual void dispatchUnableToImplementPolicy(const ResourceError&) = 0; |
| 201 | |
| 202 | virtual void dispatchWillSendSubmitEvent(Ref<FormState>&&) = 0; |
| 203 | virtual void dispatchWillSubmitForm(FormState&, CompletionHandler<void()>&&) = 0; |
| 204 | |
| 205 | virtual void revertToProvisionalState(DocumentLoader*) = 0; |
| 206 | virtual void setMainDocumentError(DocumentLoader*, const ResourceError&) = 0; |
| 207 | |
| 208 | virtual void setMainFrameDocumentReady(bool) = 0; |
| 209 | |
| 210 | virtual void startDownload(const ResourceRequest&, const String& suggestedName = String()) = 0; |
| 211 | |
| 212 | virtual void willChangeTitle(DocumentLoader*) = 0; |
| 213 | virtual void didChangeTitle(DocumentLoader*) = 0; |
| 214 | |
| 215 | virtual void willReplaceMultipartContent() = 0; |
| 216 | virtual void didReplaceMultipartContent() = 0; |
| 217 | |
| 218 | virtual void committedLoad(DocumentLoader*, const char*, int) = 0; |
| 219 | virtual void finishedLoading(DocumentLoader*) = 0; |
| 220 | |
| 221 | virtual void updateGlobalHistory() = 0; |
| 222 | virtual void updateGlobalHistoryRedirectLinks() = 0; |
| 223 | |
| 224 | virtual bool shouldGoToHistoryItem(HistoryItem&) const = 0; |
| 225 | |
| 226 | // This frame has set its opener to null, disowning it for the lifetime of the frame. |
| 227 | // See http://html.spec.whatwg.org/#dom-opener. |
| 228 | // FIXME: JSC should allow disowning opener. - <https://bugs.webkit.org/show_bug.cgi?id=103913>. |
| 229 | virtual void didDisownOpener() { } |
| 230 | |
| 231 | // This frame has displayed inactive content (such as an image) from an |
| 232 | // insecure source. Inactive content cannot spread to other frames. |
| 233 | virtual void didDisplayInsecureContent() = 0; |
| 234 | |
| 235 | // The indicated security origin has run active content (such as a |
| 236 | // script) from an insecure source. Note that the insecure content can |
| 237 | // spread to other frames in the same origin. |
| 238 | virtual void didRunInsecureContent(SecurityOrigin&, const URL&) = 0; |
| 239 | virtual void didDetectXSS(const URL&, bool didBlockEntirePage) = 0; |
| 240 | |
| 241 | virtual ResourceError cancelledError(const ResourceRequest&) = 0; |
| 242 | virtual ResourceError blockedError(const ResourceRequest&) = 0; |
| 243 | virtual ResourceError blockedByContentBlockerError(const ResourceRequest&) = 0; |
| 244 | virtual ResourceError cannotShowURLError(const ResourceRequest&) = 0; |
| 245 | virtual ResourceError interruptedForPolicyChangeError(const ResourceRequest&) = 0; |
| 246 | #if ENABLE(CONTENT_FILTERING) |
| 247 | virtual ResourceError blockedByContentFilterError(const ResourceRequest&) = 0; |
| 248 | #endif |
| 249 | |
| 250 | virtual ResourceError cannotShowMIMETypeError(const ResourceResponse&) = 0; |
| 251 | virtual ResourceError fileDoesNotExistError(const ResourceResponse&) = 0; |
| 252 | virtual ResourceError pluginWillHandleLoadError(const ResourceResponse&) = 0; |
| 253 | |
| 254 | virtual bool shouldFallBack(const ResourceError&) = 0; |
| 255 | |
| 256 | virtual bool canHandleRequest(const ResourceRequest&) const = 0; |
| 257 | virtual bool canShowMIMEType(const String& MIMEType) const = 0; |
| 258 | virtual bool canShowMIMETypeAsHTML(const String& MIMEType) const = 0; |
| 259 | virtual bool representationExistsForURLScheme(const String& URLScheme) const = 0; |
| 260 | virtual String generatedMIMETypeForURLScheme(const String& URLScheme) const = 0; |
| 261 | |
| 262 | virtual void frameLoadCompleted() = 0; |
| 263 | virtual void saveViewStateToItem(HistoryItem&) = 0; |
| 264 | virtual void restoreViewState() = 0; |
| 265 | virtual void provisionalLoadStarted() = 0; |
| 266 | virtual void didFinishLoad() = 0; |
| 267 | virtual void prepareForDataSourceReplacement() = 0; |
| 268 | |
| 269 | virtual Ref<DocumentLoader> createDocumentLoader(const ResourceRequest&, const SubstituteData&) = 0; |
| 270 | virtual void updateCachedDocumentLoader(DocumentLoader&) = 0; |
| 271 | virtual void setTitle(const StringWithDirection&, const URL&) = 0; |
| 272 | |
| 273 | virtual String userAgent(const URL&) = 0; |
| 274 | |
| 275 | virtual String overrideContentSecurityPolicy() const { return String(); } |
| 276 | |
| 277 | virtual void savePlatformDataToCachedFrame(CachedFrame*) = 0; |
| 278 | virtual void transitionToCommittedFromCachedFrame(CachedFrame*) = 0; |
| 279 | #if PLATFORM(IOS_FAMILY) |
| 280 | virtual void didRestoreFrameHierarchyForCachedFrame() = 0; |
| 281 | #endif |
| 282 | virtual void transitionToCommittedForNewPage() = 0; |
| 283 | |
| 284 | virtual void didSaveToPageCache() = 0; |
| 285 | virtual void didRestoreFromPageCache() = 0; |
| 286 | |
| 287 | virtual void dispatchDidBecomeFrameset(bool) = 0; // Can change due to navigation or DOM modification. |
| 288 | |
| 289 | virtual bool canCachePage() const = 0; |
| 290 | virtual void convertMainResourceLoadToDownload(DocumentLoader*, PAL::SessionID, const ResourceRequest&, const ResourceResponse&) = 0; |
| 291 | |
| 292 | virtual RefPtr<Frame> createFrame(const URL&, const String& name, HTMLFrameOwnerElement&, const String& referrer) = 0; |
| 293 | virtual RefPtr<Widget> createPlugin(const IntSize&, HTMLPlugInElement&, const URL&, const Vector<String>&, const Vector<String>&, const String&, bool loadManually) = 0; |
| 294 | virtual void redirectDataToPlugin(Widget&) = 0; |
| 295 | |
| 296 | virtual RefPtr<Widget> createJavaAppletWidget(const IntSize&, HTMLAppletElement&, const URL& baseURL, const Vector<String>& paramNames, const Vector<String>& paramValues) = 0; |
| 297 | |
| 298 | virtual ObjectContentType objectContentType(const URL&, const String& mimeType) = 0; |
| 299 | virtual String overrideMediaType() const = 0; |
| 300 | |
| 301 | virtual void dispatchDidClearWindowObjectInWorld(DOMWrapperWorld&) = 0; |
| 302 | |
| 303 | virtual void registerForIconNotification() { } |
| 304 | |
| 305 | #if PLATFORM(COCOA) |
| 306 | // Allow an accessibility object to retrieve a Frame parent if there's no PlatformWidget. |
| 307 | virtual RemoteAXObjectRef accessibilityRemoteObject() = 0; |
| 308 | virtual void willCacheResponse(DocumentLoader*, unsigned long identifier, NSCachedURLResponse*, CompletionHandler<void(NSCachedURLResponse *)>&&) const = 0; |
| 309 | virtual NSDictionary *dataDetectionContext() { return nullptr; } |
| 310 | #endif |
| 311 | |
| 312 | #if USE(CFURLCONNECTION) |
| 313 | // FIXME: Windows should use willCacheResponse - <https://bugs.webkit.org/show_bug.cgi?id=57257>. |
| 314 | virtual bool shouldCacheResponse(DocumentLoader*, unsigned long identifier, const ResourceResponse&, const unsigned char* data, unsigned long long length) = 0; |
| 315 | #endif |
| 316 | |
| 317 | virtual bool shouldAlwaysUsePluginDocument(const String& /*mimeType*/) const { return false; } |
| 318 | virtual bool shouldLoadMediaElementURL(const URL&) const { return true; } |
| 319 | |
| 320 | virtual void didChangeScrollOffset() { } |
| 321 | |
| 322 | virtual bool allowScript(bool enabledPerSettings) { return enabledPerSettings; } |
| 323 | |
| 324 | // Clients that generally disallow universal access can make exceptions for particular URLs. |
| 325 | virtual bool shouldForceUniversalAccessFromLocalURL(const URL&) { return false; } |
| 326 | |
| 327 | virtual Ref<FrameNetworkingContext> createNetworkingContext() = 0; |
| 328 | |
| 329 | virtual bool shouldPaintBrokenImage(const URL&) const { return true; } |
| 330 | |
| 331 | virtual void dispatchGlobalObjectAvailable(DOMWrapperWorld&) { } |
| 332 | virtual void dispatchWillDisconnectDOMWindowExtensionFromGlobalObject(DOMWindowExtension*) { } |
| 333 | virtual void dispatchDidReconnectDOMWindowExtensionToGlobalObject(DOMWindowExtension*) { } |
| 334 | virtual void dispatchWillDestroyGlobalObjectForDOMWindowExtension(DOMWindowExtension*) { } |
| 335 | |
| 336 | virtual void willInjectUserScript(DOMWrapperWorld&) { } |
| 337 | |
| 338 | #if ENABLE(WEB_RTC) |
| 339 | virtual void dispatchWillStartUsingPeerConnectionHandler(RTCPeerConnectionHandler*) { } |
| 340 | #endif |
| 341 | |
| 342 | #if ENABLE(WEBGL) |
| 343 | virtual bool allowWebGL(bool enabledPerSettings) { return enabledPerSettings; } |
| 344 | // Informs the embedder that a WebGL canvas inside this frame received a lost context |
| 345 | // notification with the given GL_ARB_robustness guilt/innocence code (see Extensions3D.h). |
| 346 | virtual void didLoseWebGLContext(int) { } |
| 347 | virtual WebGLLoadPolicy webGLPolicyForURL(const URL&) const { return WebGLAllowCreation; } |
| 348 | virtual WebGLLoadPolicy resolveWebGLPolicyForURL(const URL&) const { return WebGLAllowCreation; } |
| 349 | #endif |
| 350 | |
| 351 | virtual void forcePageTransitionIfNeeded() { } |
| 352 | |
| 353 | // FIXME (bug 116233): We need to get rid of EmptyFrameLoaderClient completely, then this will no longer be needed. |
| 354 | virtual bool isEmptyFrameLoaderClient() { return false; } |
| 355 | |
| 356 | #if USE(QUICK_LOOK) |
| 357 | virtual RefPtr<PreviewLoaderClient> createPreviewLoaderClient(const String&, const String&) = 0; |
| 358 | #endif |
| 359 | |
| 360 | #if ENABLE(CONTENT_FILTERING) |
| 361 | virtual void contentFilterDidBlockLoad(ContentFilterUnblockHandler) { } |
| 362 | #endif |
| 363 | |
| 364 | virtual void prefetchDNS(const String&) = 0; |
| 365 | |
| 366 | virtual void didRestoreScrollPosition() { } |
| 367 | |
| 368 | virtual void getLoadDecisionForIcons(const Vector<std::pair<WebCore::LinkIcon&, uint64_t>>&) { } |
| 369 | virtual void finishedLoadingIcon(uint64_t, SharedBuffer*) { } |
| 370 | |
| 371 | virtual void didCreateWindow(DOMWindow&) { } |
| 372 | |
| 373 | #if ENABLE(APPLICATION_MANIFEST) |
| 374 | virtual void finishedLoadingApplicationManifest(uint64_t, const Optional<ApplicationManifest>&) { } |
| 375 | #endif |
| 376 | |
| 377 | #if ENABLE(RESOURCE_LOAD_STATISTICS) |
| 378 | virtual bool hasFrameSpecificStorageAccess() { return false; } |
| 379 | virtual void setHasFrameSpecificStorageAccess(bool) { } |
| 380 | #endif |
| 381 | }; |
| 382 | |
| 383 | } // namespace WebCore |
| 384 | |