1 /* 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 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 * 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of 14 * its contributors may be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 #ifndef FrameLoaderClient_h 30 #define FrameLoaderClient_h 31 32 #include "FrameLoaderTypes.h" 33 #include "IconURL.h" 34 #include "ScrollTypes.h" 35 #include <wtf/Forward.h> 36 #include <wtf/Vector.h> 37 38 #if PLATFORM(MAC) 39 #ifdef __OBJC__ 40 #import <Foundation/Foundation.h> 41 typedef id RemoteAXObjectRef; 42 #else 43 typedef void* RemoteAXObjectRef; 44 #endif 45 #endif 46 47 typedef class _jobject* jobject; 48 49 #if PLATFORM(MAC) && !defined(__OBJC__) 50 class NSCachedURLResponse; 51 class NSView; 52 #endif 53 54 namespace WebCore { 55 56 class AuthenticationChallenge; 57 class CachedFrame; 58 class Color; 59 class DOMWrapperWorld; 60 class DocumentLoader; 61 class Element; 62 class FormState; 63 class Frame; 64 class FrameLoader; 65 class FrameNetworkingContext; 66 class HistoryItem; 67 class HTMLAppletElement; 68 class HTMLFormElement; 69 class HTMLFrameOwnerElement; 70 #if ENABLE(PLUGIN_PROXY_FOR_VIDEO) 71 class HTMLMediaElement; 72 #endif 73 class HTMLPlugInElement; 74 class IntSize; 75 class KURL; 76 class NavigationAction; 77 class Page; 78 class ProtectionSpace; 79 class PluginView; 80 class PolicyChecker; 81 class ResourceError; 82 class ResourceHandle; 83 class ResourceLoader; 84 class ResourceRequest; 85 class ResourceResponse; 86 class SecurityOrigin; 87 class SharedBuffer; 88 class StringWithDirection; 89 class SubstituteData; 90 class Widget; 91 92 typedef void (PolicyChecker::*FramePolicyFunction)(PolicyAction); 93 94 class FrameLoaderClient { 95 public: 96 // An inline function cannot be the first non-abstract virtual function declared 97 // in the class as it results in the vtable being generated as a weak symbol. 98 // This hurts performance (in Mac OS X at least, when loadig frameworks), so we 99 // don't want to do it in WebKit. 100 virtual bool hasHTMLView() const; 101 ~FrameLoaderClient()102 virtual ~FrameLoaderClient() { } 103 104 virtual void frameLoaderDestroyed() = 0; 105 106 virtual bool hasWebView() const = 0; // mainly for assertions 107 108 virtual void makeRepresentation(DocumentLoader*) = 0; 109 virtual void forceLayout() = 0; 110 virtual void forceLayoutForNonHTML() = 0; 111 112 virtual void setCopiesOnScroll() = 0; 113 114 virtual void detachedFromParent2() = 0; 115 virtual void detachedFromParent3() = 0; 116 117 virtual void assignIdentifierToInitialRequest(unsigned long identifier, DocumentLoader*, const ResourceRequest&) = 0; 118 119 virtual void dispatchWillSendRequest(DocumentLoader*, unsigned long identifier, ResourceRequest&, const ResourceResponse& redirectResponse) = 0; 120 virtual bool shouldUseCredentialStorage(DocumentLoader*, unsigned long identifier) = 0; 121 virtual void dispatchDidReceiveAuthenticationChallenge(DocumentLoader*, unsigned long identifier, const AuthenticationChallenge&) = 0; 122 virtual void dispatchDidCancelAuthenticationChallenge(DocumentLoader*, unsigned long identifier, const AuthenticationChallenge&) = 0; 123 #if USE(PROTECTION_SPACE_AUTH_CALLBACK) 124 virtual bool canAuthenticateAgainstProtectionSpace(DocumentLoader*, unsigned long identifier, const ProtectionSpace&) = 0; 125 #endif 126 virtual void dispatchDidReceiveResponse(DocumentLoader*, unsigned long identifier, const ResourceResponse&) = 0; 127 virtual void dispatchDidReceiveContentLength(DocumentLoader*, unsigned long identifier, int dataLength) = 0; 128 virtual void dispatchDidFinishLoading(DocumentLoader*, unsigned long identifier) = 0; 129 virtual void dispatchDidFailLoading(DocumentLoader*, unsigned long identifier, const ResourceError&) = 0; 130 virtual bool dispatchDidLoadResourceFromMemoryCache(DocumentLoader*, const ResourceRequest&, const ResourceResponse&, int length) = 0; 131 132 virtual void dispatchDidHandleOnloadEvents() = 0; 133 virtual void dispatchDidReceiveServerRedirectForProvisionalLoad() = 0; 134 virtual void dispatchDidCancelClientRedirect() = 0; 135 virtual void dispatchWillPerformClientRedirect(const KURL&, double interval, double fireDate) = 0; dispatchDidNavigateWithinPage()136 virtual void dispatchDidNavigateWithinPage() { } 137 virtual void dispatchDidChangeLocationWithinPage() = 0; 138 virtual void dispatchDidPushStateWithinPage() = 0; 139 virtual void dispatchDidReplaceStateWithinPage() = 0; 140 virtual void dispatchDidPopStateWithinPage() = 0; 141 virtual void dispatchWillClose() = 0; 142 virtual void dispatchDidReceiveIcon() = 0; 143 virtual void dispatchDidStartProvisionalLoad() = 0; 144 virtual void dispatchDidReceiveTitle(const StringWithDirection&) = 0; 145 virtual void dispatchDidChangeIcons(IconType) = 0; 146 virtual void dispatchDidCommitLoad() = 0; 147 virtual void dispatchDidFailProvisionalLoad(const ResourceError&) = 0; 148 virtual void dispatchDidFailLoad(const ResourceError&) = 0; 149 virtual void dispatchDidFinishDocumentLoad() = 0; 150 virtual void dispatchDidFinishLoad() = 0; 151 virtual void dispatchDidFirstLayout() = 0; 152 virtual void dispatchDidFirstVisuallyNonEmptyLayout() = 0; 153 154 virtual Frame* dispatchCreatePage(const NavigationAction&) = 0; 155 virtual void dispatchShow() = 0; 156 157 virtual void dispatchDecidePolicyForResponse(FramePolicyFunction, const ResourceResponse&, const ResourceRequest&) = 0; 158 virtual void dispatchDecidePolicyForNewWindowAction(FramePolicyFunction, const NavigationAction&, const ResourceRequest&, PassRefPtr<FormState>, const String& frameName) = 0; 159 virtual void dispatchDecidePolicyForNavigationAction(FramePolicyFunction, const NavigationAction&, const ResourceRequest&, PassRefPtr<FormState>) = 0; 160 virtual void cancelPolicyCheck() = 0; 161 162 virtual void dispatchUnableToImplementPolicy(const ResourceError&) = 0; 163 164 virtual void dispatchWillSendSubmitEvent(HTMLFormElement*) = 0; 165 virtual void dispatchWillSubmitForm(FramePolicyFunction, PassRefPtr<FormState>) = 0; 166 167 virtual void dispatchDidLoadMainResource(DocumentLoader*) = 0; 168 virtual void revertToProvisionalState(DocumentLoader*) = 0; 169 virtual void setMainDocumentError(DocumentLoader*, const ResourceError&) = 0; 170 171 // Maybe these should go into a ProgressTrackerClient some day willChangeEstimatedProgress()172 virtual void willChangeEstimatedProgress() { } didChangeEstimatedProgress()173 virtual void didChangeEstimatedProgress() { } 174 virtual void postProgressStartedNotification() = 0; 175 virtual void postProgressEstimateChangedNotification() = 0; 176 virtual void postProgressFinishedNotification() = 0; 177 178 virtual void setMainFrameDocumentReady(bool) = 0; 179 180 virtual void startDownload(const ResourceRequest&) = 0; 181 182 virtual void willChangeTitle(DocumentLoader*) = 0; 183 virtual void didChangeTitle(DocumentLoader*) = 0; 184 185 virtual void committedLoad(DocumentLoader*, const char*, int) = 0; 186 virtual void finishedLoading(DocumentLoader*) = 0; 187 188 virtual void updateGlobalHistory() = 0; 189 virtual void updateGlobalHistoryRedirectLinks() = 0; 190 191 virtual bool shouldGoToHistoryItem(HistoryItem*) const = 0; 192 virtual bool shouldStopLoadingForHistoryItem(HistoryItem*) const = 0; 193 virtual void dispatchDidAddBackForwardItem(HistoryItem*) const = 0; 194 virtual void dispatchDidRemoveBackForwardItem(HistoryItem*) const = 0; 195 virtual void dispatchDidChangeBackForwardIndex() const = 0; updateGlobalHistoryItemForPage()196 virtual void updateGlobalHistoryItemForPage() { } 197 198 // This frame has displayed inactive content (such as an image) from an 199 // insecure source. Inactive content cannot spread to other frames. 200 virtual void didDisplayInsecureContent() = 0; 201 202 // The indicated security origin has run active content (such as a 203 // script) from an insecure source. Note that the insecure content can 204 // spread to other frames in the same origin. 205 virtual void didRunInsecureContent(SecurityOrigin*, const KURL&) = 0; 206 207 virtual ResourceError cancelledError(const ResourceRequest&) = 0; 208 virtual ResourceError blockedError(const ResourceRequest&) = 0; 209 virtual ResourceError cannotShowURLError(const ResourceRequest&) = 0; 210 virtual ResourceError interruptForPolicyChangeError(const ResourceRequest&) = 0; 211 212 virtual ResourceError cannotShowMIMETypeError(const ResourceResponse&) = 0; 213 virtual ResourceError fileDoesNotExistError(const ResourceResponse&) = 0; 214 virtual ResourceError pluginWillHandleLoadError(const ResourceResponse&) = 0; 215 216 virtual bool shouldFallBack(const ResourceError&) = 0; 217 218 virtual bool canHandleRequest(const ResourceRequest&) const = 0; 219 virtual bool canShowMIMEType(const String& MIMEType) const = 0; 220 virtual bool canShowMIMETypeAsHTML(const String& MIMEType) const = 0; 221 virtual bool representationExistsForURLScheme(const String& URLScheme) const = 0; 222 virtual String generatedMIMETypeForURLScheme(const String& URLScheme) const = 0; 223 224 virtual void frameLoadCompleted() = 0; 225 virtual void saveViewStateToItem(HistoryItem*) = 0; 226 virtual void restoreViewState() = 0; 227 virtual void provisionalLoadStarted() = 0; 228 virtual void didFinishLoad() = 0; 229 virtual void prepareForDataSourceReplacement() = 0; 230 231 virtual PassRefPtr<DocumentLoader> createDocumentLoader(const ResourceRequest&, const SubstituteData&) = 0; 232 virtual void setTitle(const StringWithDirection&, const KURL&) = 0; 233 234 virtual String userAgent(const KURL&) = 0; 235 236 virtual void savePlatformDataToCachedFrame(CachedFrame*) = 0; 237 virtual void transitionToCommittedFromCachedFrame(CachedFrame*) = 0; 238 virtual void transitionToCommittedForNewPage() = 0; 239 240 virtual void didSaveToPageCache() = 0; 241 virtual void didRestoreFromPageCache() = 0; 242 243 virtual void dispatchDidBecomeFrameset(bool) = 0; // Can change due to navigation or DOM modification. 244 245 virtual bool canCachePage() const = 0; 246 virtual void download(ResourceHandle*, const ResourceRequest&, const ResourceRequest&, const ResourceResponse&) = 0; 247 248 virtual PassRefPtr<Frame> createFrame(const KURL& url, const String& name, HTMLFrameOwnerElement* ownerElement, 249 const String& referrer, bool allowsScrolling, int marginWidth, int marginHeight) = 0; 250 virtual void didTransferChildFrameToNewDocument(Page* oldPage) = 0; 251 virtual void transferLoadingResourceFromPage(unsigned long identifier, DocumentLoader*, const ResourceRequest&, Page* oldPage) = 0; 252 virtual PassRefPtr<Widget> createPlugin(const IntSize&, HTMLPlugInElement*, const KURL&, const Vector<String>&, const Vector<String>&, const String&, bool loadManually) = 0; 253 virtual void redirectDataToPlugin(Widget* pluginWidget) = 0; 254 255 virtual PassRefPtr<Widget> createJavaAppletWidget(const IntSize&, HTMLAppletElement*, const KURL& baseURL, const Vector<String>& paramNames, const Vector<String>& paramValues) = 0; 256 dispatchDidFailToStartPlugin(const PluginView *)257 virtual void dispatchDidFailToStartPlugin(const PluginView*) const { } 258 #if ENABLE(PLUGIN_PROXY_FOR_VIDEO) 259 virtual PassRefPtr<Widget> createMediaPlayerProxyPlugin(const IntSize&, HTMLMediaElement*, const KURL&, const Vector<String>&, const Vector<String>&, const String&) = 0; 260 virtual void hideMediaPlayerProxyPlugin(Widget*) = 0; 261 virtual void showMediaPlayerProxyPlugin(Widget*) = 0; 262 #endif 263 264 virtual ObjectContentType objectContentType(const KURL&, const String& mimeType, bool shouldPreferPlugInsForImages) = 0; 265 virtual String overrideMediaType() const = 0; 266 267 virtual void dispatchDidClearWindowObjectInWorld(DOMWrapperWorld*) = 0; 268 virtual void documentElementAvailable() = 0; 269 virtual void didPerformFirstNavigation() const = 0; // "Navigation" here means a transition from one page to another that ends up in the back/forward list. 270 271 #if USE(V8) 272 virtual void didCreateScriptContextForFrame() = 0; 273 virtual void didDestroyScriptContextForFrame() = 0; 274 virtual void didCreateIsolatedScriptContext() = 0; 275 virtual bool allowScriptExtension(const String& extensionName, int extensionGroup) = 0; 276 #endif 277 278 virtual void registerForIconNotification(bool listen = true) = 0; 279 280 #if PLATFORM(MAC) 281 // Allow an accessibility object to retrieve a Frame parent if there's no PlatformWidget. 282 virtual RemoteAXObjectRef accessibilityRemoteObject() = 0; 283 #if ENABLE(JAVA_BRIDGE) javaApplet(NSView *)284 virtual jobject javaApplet(NSView*) { return 0; } 285 #endif 286 virtual NSCachedURLResponse* willCacheResponse(DocumentLoader*, unsigned long identifier, NSCachedURLResponse*) const = 0; 287 #endif 288 #if PLATFORM(WIN) && USE(CFNETWORK) 289 // FIXME: Windows should use willCacheResponse - <https://bugs.webkit.org/show_bug.cgi?id=57257>. 290 virtual bool shouldCacheResponse(DocumentLoader*, unsigned long identifier, const ResourceResponse&, const unsigned char* data, unsigned long long length) = 0; 291 #endif 292 shouldUsePluginDocument(const String &)293 virtual bool shouldUsePluginDocument(const String& /*mimeType*/) const { return false; } shouldLoadMediaElementURL(const KURL &)294 virtual bool shouldLoadMediaElementURL(const KURL&) const { return true; } 295 didChangeScrollOffset()296 virtual void didChangeScrollOffset() { } 297 allowJavaScript(bool enabledPerSettings)298 virtual bool allowJavaScript(bool enabledPerSettings) { return enabledPerSettings; } allowPlugins(bool enabledPerSettings)299 virtual bool allowPlugins(bool enabledPerSettings) { return enabledPerSettings; } allowImages(bool enabledPerSettings)300 virtual bool allowImages(bool enabledPerSettings) { return enabledPerSettings; } 301 302 // This callback notifies the client that the frame was about to run 303 // JavaScript but did not because allowJavaScript returned false. We 304 // have a separate callback here because there are a number of places 305 // that need to know if JavaScript is enabled but are not necessarily 306 // preparing to execute script. didNotAllowScript()307 virtual void didNotAllowScript() { } 308 // This callback is similar, but for plugins. didNotAllowPlugins()309 virtual void didNotAllowPlugins() { } 310 311 virtual PassRefPtr<FrameNetworkingContext> createNetworkingContext() = 0; 312 shouldPaintBrokenImage(const KURL &)313 virtual bool shouldPaintBrokenImage(const KURL&) const { return true; } 314 }; 315 316 } // namespace WebCore 317 318 #endif // FrameLoaderClient_h 319