Home | History | Annotate | Download | only in loader
      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 "ScrollTypes.h"
     34 #include <wtf/Forward.h>
     35 #include <wtf/Vector.h>
     36 
     37 #if PLATFORM(MAC)
     38 #ifdef __OBJC__
     39 #import <Foundation/Foundation.h>
     40 typedef id RemoteAXObjectRef;
     41 #else
     42 typedef void* RemoteAXObjectRef;
     43 #endif
     44 #endif
     45 
     46 typedef class _jobject* jobject;
     47 
     48 #if PLATFORM(MAC) && !defined(__OBJC__)
     49 class NSCachedURLResponse;
     50 class NSView;
     51 #endif
     52 
     53 namespace WebCore {
     54 
     55     class AuthenticationChallenge;
     56     class CachedFrame;
     57     class Color;
     58     class DOMWrapperWorld;
     59     class DocumentLoader;
     60     class Element;
     61     class FormState;
     62     class Frame;
     63     class FrameLoader;
     64     class FrameNetworkingContext;
     65     class HistoryItem;
     66     class HTMLAppletElement;
     67     class HTMLFormElement;
     68     class HTMLFrameOwnerElement;
     69 #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
     70     class HTMLMediaElement;
     71 #endif
     72     class HTMLPlugInElement;
     73     class IntSize;
     74     class KURL;
     75     class NavigationAction;
     76     class Page;
     77     class ProtectionSpace;
     78     class PluginView;
     79     class PolicyChecker;
     80     class ResourceError;
     81     class ResourceHandle;
     82     class ResourceLoader;
     83     class ResourceRequest;
     84     class ResourceResponse;
     85     class SecurityOrigin;
     86     class SharedBuffer;
     87     class StringWithDirection;
     88     class SubstituteData;
     89     class Widget;
     90 
     91     typedef void (PolicyChecker::*FramePolicyFunction)(PolicyAction);
     92 
     93     class FrameLoaderClient {
     94     public:
     95         // An inline function cannot be the first non-abstract virtual function declared
     96         // in the class as it results in the vtable being generated as a weak symbol.
     97         // This hurts performance (in Mac OS X at least, when loadig frameworks), so we
     98         // don't want to do it in WebKit.
     99         virtual bool hasHTMLView() const;
    100 
    101         virtual ~FrameLoaderClient() { }
    102 
    103         virtual void frameLoaderDestroyed() = 0;
    104 
    105         virtual bool hasWebView() const = 0; // mainly for assertions
    106 
    107         virtual void makeRepresentation(DocumentLoader*) = 0;
    108         virtual void forceLayout() = 0;
    109         virtual void forceLayoutForNonHTML() = 0;
    110 
    111         virtual void setCopiesOnScroll() = 0;
    112 
    113         virtual void detachedFromParent2() = 0;
    114         virtual void detachedFromParent3() = 0;
    115 
    116         virtual void assignIdentifierToInitialRequest(unsigned long identifier, DocumentLoader*, const ResourceRequest&) = 0;
    117 
    118         virtual void dispatchWillSendRequest(DocumentLoader*, unsigned long identifier, ResourceRequest&, const ResourceResponse& redirectResponse) = 0;
    119         virtual bool shouldUseCredentialStorage(DocumentLoader*, unsigned long identifier) = 0;
    120         virtual void dispatchDidReceiveAuthenticationChallenge(DocumentLoader*, unsigned long identifier, const AuthenticationChallenge&) = 0;
    121         virtual void dispatchDidCancelAuthenticationChallenge(DocumentLoader*, unsigned long identifier, const AuthenticationChallenge&) = 0;
    122 #if USE(PROTECTION_SPACE_AUTH_CALLBACK)
    123         virtual bool canAuthenticateAgainstProtectionSpace(DocumentLoader*, unsigned long identifier, const ProtectionSpace&) = 0;
    124 #endif
    125         virtual void dispatchDidReceiveResponse(DocumentLoader*, unsigned long identifier, const ResourceResponse&) = 0;
    126         virtual void dispatchDidReceiveContentLength(DocumentLoader*, unsigned long identifier, int dataLength) = 0;
    127         virtual void dispatchDidFinishLoading(DocumentLoader*, unsigned long identifier) = 0;
    128         virtual void dispatchDidFailLoading(DocumentLoader*, unsigned long identifier, const ResourceError&) = 0;
    129         virtual bool dispatchDidLoadResourceFromMemoryCache(DocumentLoader*, const ResourceRequest&, const ResourceResponse&, int length) = 0;
    130 
    131         virtual void dispatchDidHandleOnloadEvents() = 0;
    132         virtual void dispatchDidReceiveServerRedirectForProvisionalLoad() = 0;
    133         virtual void dispatchDidCancelClientRedirect() = 0;
    134         virtual void dispatchWillPerformClientRedirect(const KURL&, double interval, double fireDate) = 0;
    135         virtual void dispatchDidNavigateWithinPage() { }
    136         virtual void dispatchDidChangeLocationWithinPage() = 0;
    137         virtual void dispatchDidPushStateWithinPage() = 0;
    138         virtual void dispatchDidReplaceStateWithinPage() = 0;
    139         virtual void dispatchDidPopStateWithinPage() = 0;
    140         virtual void dispatchWillClose() = 0;
    141         virtual void dispatchDidReceiveIcon() = 0;
    142         virtual void dispatchDidStartProvisionalLoad() = 0;
    143         virtual void dispatchDidReceiveTitle(const StringWithDirection&) = 0;
    144         virtual void dispatchDidChangeIcons() = 0;
    145         virtual void dispatchDidCommitLoad() = 0;
    146         virtual void dispatchDidFailProvisionalLoad(const ResourceError&) = 0;
    147         virtual void dispatchDidFailLoad(const ResourceError&) = 0;
    148         virtual void dispatchDidFinishDocumentLoad() = 0;
    149         virtual void dispatchDidFinishLoad() = 0;
    150         virtual void dispatchDidFirstLayout() = 0;
    151         virtual void dispatchDidFirstVisuallyNonEmptyLayout() = 0;
    152 
    153         virtual Frame* dispatchCreatePage(const NavigationAction&) = 0;
    154         virtual void dispatchShow() = 0;
    155 
    156         virtual void dispatchDecidePolicyForResponse(FramePolicyFunction, const ResourceResponse&, const ResourceRequest&) = 0;
    157         virtual void dispatchDecidePolicyForNewWindowAction(FramePolicyFunction, const NavigationAction&, const ResourceRequest&, PassRefPtr<FormState>, const String& frameName) = 0;
    158         virtual void dispatchDecidePolicyForNavigationAction(FramePolicyFunction, const NavigationAction&, const ResourceRequest&, PassRefPtr<FormState>) = 0;
    159         virtual void cancelPolicyCheck() = 0;
    160 
    161         virtual void dispatchUnableToImplementPolicy(const ResourceError&) = 0;
    162 
    163         virtual void dispatchWillSendSubmitEvent(HTMLFormElement*) = 0;
    164         virtual void dispatchWillSubmitForm(FramePolicyFunction, PassRefPtr<FormState>) = 0;
    165 
    166         virtual void dispatchDidLoadMainResource(DocumentLoader*) = 0;
    167         virtual void revertToProvisionalState(DocumentLoader*) = 0;
    168         virtual void setMainDocumentError(DocumentLoader*, const ResourceError&) = 0;
    169 
    170         // Maybe these should go into a ProgressTrackerClient some day
    171         virtual void willChangeEstimatedProgress() { }
    172         virtual void didChangeEstimatedProgress() { }
    173         virtual void postProgressStartedNotification() = 0;
    174         virtual void postProgressEstimateChangedNotification() = 0;
    175         virtual void postProgressFinishedNotification() = 0;
    176 
    177         virtual void setMainFrameDocumentReady(bool) = 0;
    178 
    179         virtual void startDownload(const ResourceRequest&) = 0;
    180 
    181         virtual void willChangeTitle(DocumentLoader*) = 0;
    182         virtual void didChangeTitle(DocumentLoader*) = 0;
    183 
    184         virtual void committedLoad(DocumentLoader*, const char*, int) = 0;
    185         virtual void finishedLoading(DocumentLoader*) = 0;
    186 
    187         virtual void updateGlobalHistory() = 0;
    188         virtual void updateGlobalHistoryRedirectLinks() = 0;
    189 
    190         virtual bool shouldGoToHistoryItem(HistoryItem*) const = 0;
    191         virtual bool shouldStopLoadingForHistoryItem(HistoryItem*) const = 0;
    192         virtual void dispatchDidAddBackForwardItem(HistoryItem*) const = 0;
    193         virtual void dispatchDidRemoveBackForwardItem(HistoryItem*) const = 0;
    194         virtual void dispatchDidChangeBackForwardIndex() const = 0;
    195         virtual void updateGlobalHistoryItemForPage() { }
    196 
    197         // This frame has displayed inactive content (such as an image) from an
    198         // insecure source.  Inactive content cannot spread to other frames.
    199         virtual void didDisplayInsecureContent() = 0;
    200 
    201         // The indicated security origin has run active content (such as a
    202         // script) from an insecure source.  Note that the insecure content can
    203         // spread to other frames in the same origin.
    204         virtual void didRunInsecureContent(SecurityOrigin*, const KURL&) = 0;
    205 
    206         virtual ResourceError cancelledError(const ResourceRequest&) = 0;
    207         virtual ResourceError blockedError(const ResourceRequest&) = 0;
    208         virtual ResourceError cannotShowURLError(const ResourceRequest&) = 0;
    209         virtual ResourceError interruptForPolicyChangeError(const ResourceRequest&) = 0;
    210 
    211         virtual ResourceError cannotShowMIMETypeError(const ResourceResponse&) = 0;
    212         virtual ResourceError fileDoesNotExistError(const ResourceResponse&) = 0;
    213         virtual ResourceError pluginWillHandleLoadError(const ResourceResponse&) = 0;
    214 
    215         virtual bool shouldFallBack(const ResourceError&) = 0;
    216 
    217         virtual bool canHandleRequest(const ResourceRequest&) const = 0;
    218         virtual bool canShowMIMEType(const String& MIMEType) const = 0;
    219         virtual bool canShowMIMETypeAsHTML(const String& MIMEType) const = 0;
    220         virtual bool representationExistsForURLScheme(const String& URLScheme) const = 0;
    221         virtual String generatedMIMETypeForURLScheme(const String& URLScheme) const = 0;
    222 
    223         virtual void frameLoadCompleted() = 0;
    224         virtual void saveViewStateToItem(HistoryItem*) = 0;
    225         virtual void restoreViewState() = 0;
    226         virtual void provisionalLoadStarted() = 0;
    227         virtual void didFinishLoad() = 0;
    228         virtual void prepareForDataSourceReplacement() = 0;
    229 
    230         virtual PassRefPtr<DocumentLoader> createDocumentLoader(const ResourceRequest&, const SubstituteData&) = 0;
    231         virtual void setTitle(const StringWithDirection&, const KURL&) = 0;
    232 
    233         virtual String userAgent(const KURL&) = 0;
    234 
    235         virtual void savePlatformDataToCachedFrame(CachedFrame*) = 0;
    236         virtual void transitionToCommittedFromCachedFrame(CachedFrame*) = 0;
    237         virtual void transitionToCommittedForNewPage() = 0;
    238 
    239         virtual void didSaveToPageCache() = 0;
    240         virtual void didRestoreFromPageCache() = 0;
    241 
    242         virtual void dispatchDidBecomeFrameset(bool) = 0; // Can change due to navigation or DOM modification.
    243 
    244         virtual bool canCachePage() const = 0;
    245         virtual void download(ResourceHandle*, const ResourceRequest&, const ResourceRequest&, const ResourceResponse&) = 0;
    246 
    247         virtual PassRefPtr<Frame> createFrame(const KURL& url, const String& name, HTMLFrameOwnerElement* ownerElement,
    248                                    const String& referrer, bool allowsScrolling, int marginWidth, int marginHeight) = 0;
    249         virtual void didTransferChildFrameToNewDocument(Page* oldPage) = 0;
    250         virtual void transferLoadingResourceFromPage(unsigned long identifier, DocumentLoader*, const ResourceRequest&, Page* oldPage) = 0;
    251         virtual PassRefPtr<Widget> createPlugin(const IntSize&, HTMLPlugInElement*, const KURL&, const Vector<String>&, const Vector<String>&, const String&, bool loadManually) = 0;
    252         virtual void redirectDataToPlugin(Widget* pluginWidget) = 0;
    253 
    254         virtual PassRefPtr<Widget> createJavaAppletWidget(const IntSize&, HTMLAppletElement*, const KURL& baseURL, const Vector<String>& paramNames, const Vector<String>& paramValues) = 0;
    255 
    256         virtual void dispatchDidFailToStartPlugin(const PluginView*) const { }
    257 #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
    258         virtual PassRefPtr<Widget> createMediaPlayerProxyPlugin(const IntSize&, HTMLMediaElement*, const KURL&, const Vector<String>&, const Vector<String>&, const String&) = 0;
    259         virtual void hideMediaPlayerProxyPlugin(Widget*) = 0;
    260         virtual void showMediaPlayerProxyPlugin(Widget*) = 0;
    261 #endif
    262 
    263         virtual ObjectContentType objectContentType(const KURL&, const String& mimeType, bool shouldPreferPlugInsForImages) = 0;
    264         virtual String overrideMediaType() const = 0;
    265 
    266         virtual void dispatchDidClearWindowObjectInWorld(DOMWrapperWorld*) = 0;
    267         virtual void documentElementAvailable() = 0;
    268         virtual void didPerformFirstNavigation() const = 0; // "Navigation" here means a transition from one page to another that ends up in the back/forward list.
    269 
    270 #if USE(V8)
    271         virtual void didCreateScriptContextForFrame() = 0;
    272         virtual void didDestroyScriptContextForFrame() = 0;
    273         virtual void didCreateIsolatedScriptContext() = 0;
    274         virtual bool allowScriptExtension(const String& extensionName, int extensionGroup) = 0;
    275 #endif
    276 
    277         virtual void registerForIconNotification(bool listen = true) = 0;
    278 #ifdef ANDROID_APPLE_TOUCH_ICON
    279         virtual void dispatchDidReceiveTouchIconURL(const String& url, bool precomposed) = 0;
    280 #endif
    281 
    282 #if PLATFORM(MAC)
    283         // Allow an accessibility object to retrieve a Frame parent if there's no PlatformWidget.
    284         virtual RemoteAXObjectRef accessibilityRemoteObject() = 0;
    285 #if ENABLE(JAVA_BRIDGE)
    286         virtual jobject javaApplet(NSView*) { return 0; }
    287 #endif
    288         virtual NSCachedURLResponse* willCacheResponse(DocumentLoader*, unsigned long identifier, NSCachedURLResponse*) const = 0;
    289 #endif
    290 #if USE(CFNETWORK)
    291         virtual bool shouldCacheResponse(DocumentLoader*, unsigned long identifier, const ResourceResponse&, const unsigned char* data, unsigned long long length) = 0;
    292 #endif
    293 
    294         virtual bool shouldUsePluginDocument(const String& /*mimeType*/) const { return false; }
    295         virtual bool shouldLoadMediaElementURL(const KURL&) const { return true; }
    296 
    297         virtual void didChangeScrollOffset() { }
    298 
    299         virtual bool allowJavaScript(bool enabledPerSettings) { return enabledPerSettings; }
    300         virtual bool allowPlugins(bool enabledPerSettings) { return enabledPerSettings; }
    301         virtual bool allowImages(bool enabledPerSettings) { return enabledPerSettings; }
    302 
    303         // This callback notifies the client that the frame was about to run
    304         // JavaScript but did not because allowJavaScript returned false. We
    305         // have a separate callback here because there are a number of places
    306         // that need to know if JavaScript is enabled but are not necessarily
    307         // preparing to execute script.
    308         virtual void didNotAllowScript() { }
    309         // This callback is similar, but for plugins.
    310         virtual void didNotAllowPlugins() { }
    311 
    312         virtual PassRefPtr<FrameNetworkingContext> createNetworkingContext() = 0;
    313 
    314         virtual bool shouldPaintBrokenImage(const KURL&) const { return true; }
    315     };
    316 
    317 } // namespace WebCore
    318 
    319 #endif // FrameLoaderClient_h
    320