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