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