Home | History | Annotate | Download | only in WebCoreSupport
      1 /*
      2  * Copyright 2007, The Android Open Source Project
      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  *  * Redistributions of source code must retain the above copyright
      8  *    notice, this list of conditions and the following disclaimer.
      9  *  * Redistributions in binary form must reproduce the above copyright
     10  *    notice, this list of conditions and the following disclaimer in the
     11  *    documentation and/or other materials provided with the distribution.
     12  *
     13  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
     14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
     21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     24  */
     25 
     26 #ifndef FrameLoaderClientAndroid_h
     27 #define FrameLoaderClientAndroid_h
     28 
     29 #include "FrameLoaderClient.h"
     30 #include "ResourceResponse.h"
     31 #include "WebIconDatabase.h"
     32 #include <wtf/Forward.h>
     33 
     34 namespace WebCore {
     35 class PluginManualLoader;
     36 }
     37 
     38 using namespace WebCore;
     39 
     40 namespace android {
     41     class WebFrame;
     42 
     43     class FrameLoaderClientAndroid : public FrameLoaderClient,
     44             WebIconDatabaseClient {
     45     public:
     46         FrameLoaderClientAndroid(WebFrame* webframe);
     47 
     48         Frame* getFrame() { return m_frame; }
     49         static FrameLoaderClientAndroid* get(const Frame* frame);
     50 
     51         void setFrame(Frame* frame) { m_frame = frame; }
     52         WebFrame* webFrame() const { return m_webFrame; }
     53 
     54         virtual void frameLoaderDestroyed();
     55 
     56         virtual bool hasWebView() const; // mainly for assertions
     57 
     58         virtual void makeRepresentation(DocumentLoader*);
     59         virtual void forceLayout();
     60         virtual void forceLayoutForNonHTML();
     61 
     62         virtual void setCopiesOnScroll();
     63 
     64         virtual void detachedFromParent2();
     65         virtual void detachedFromParent3();
     66 
     67         virtual void assignIdentifierToInitialRequest(unsigned long identifier, DocumentLoader*, const ResourceRequest&);
     68 
     69         virtual void dispatchWillSendRequest(DocumentLoader*, unsigned long identifier, ResourceRequest&, const ResourceResponse& redirectResponse);
     70         virtual bool shouldUseCredentialStorage(DocumentLoader*, unsigned long identifier);
     71         virtual void dispatchDidReceiveAuthenticationChallenge(DocumentLoader*, unsigned long identifier, const AuthenticationChallenge&);
     72         virtual void dispatchDidCancelAuthenticationChallenge(DocumentLoader*, unsigned long identifier, const AuthenticationChallenge&);
     73         virtual void dispatchDidReceiveResponse(DocumentLoader*, unsigned long identifier, const ResourceResponse&);
     74         virtual void dispatchDidReceiveContentLength(DocumentLoader*, unsigned long identifier, int lengthReceived);
     75         virtual void dispatchDidFinishLoading(DocumentLoader*, unsigned long identifier);
     76         virtual void dispatchDidFailLoading(DocumentLoader*, unsigned long identifier, const ResourceError&);
     77         virtual bool dispatchDidLoadResourceFromMemoryCache(DocumentLoader*, const ResourceRequest&, const ResourceResponse&, int length);
     78 
     79         virtual void dispatchDidHandleOnloadEvents();
     80         virtual void dispatchDidReceiveServerRedirectForProvisionalLoad();
     81         virtual void dispatchDidCancelClientRedirect();
     82         virtual void dispatchWillPerformClientRedirect(const KURL&, double interval, double fireDate);
     83         virtual void dispatchDidChangeLocationWithinPage();
     84         virtual void dispatchDidPushStateWithinPage();
     85         virtual void dispatchDidReplaceStateWithinPage();
     86         virtual void dispatchDidPopStateWithinPage();
     87         virtual void dispatchWillClose();
     88         virtual void dispatchDidReceiveIcon();
     89         virtual void dispatchDidStartProvisionalLoad();
     90         virtual void dispatchDidReceiveTitle(const StringWithDirection& title);
     91         virtual void dispatchDidCommitLoad();
     92         virtual void dispatchDidFailProvisionalLoad(const ResourceError&);
     93         virtual void dispatchDidFailLoad(const ResourceError&);
     94         virtual void dispatchDidFinishDocumentLoad();
     95         virtual void dispatchDidFinishLoad();
     96         virtual void dispatchDidFirstLayout();
     97         virtual void dispatchDidFirstVisuallyNonEmptyLayout();
     98 
     99         virtual Frame* dispatchCreatePage(const NavigationAction&);
    100         virtual void dispatchShow();
    101 
    102         virtual void dispatchDecidePolicyForResponse(FramePolicyFunction, const ResourceResponse&, const ResourceRequest&);
    103         virtual void dispatchDecidePolicyForNewWindowAction(FramePolicyFunction, const NavigationAction&, const ResourceRequest&, PassRefPtr<FormState>, const String& frameName);
    104         virtual void dispatchDecidePolicyForNavigationAction(FramePolicyFunction, const NavigationAction&, const ResourceRequest&, PassRefPtr<FormState>);
    105         virtual void cancelPolicyCheck();
    106 
    107         virtual void dispatchUnableToImplementPolicy(const ResourceError&);
    108 
    109         virtual void dispatchWillSubmitForm(FramePolicyFunction, PassRefPtr<FormState>);
    110 
    111         virtual void dispatchDidLoadMainResource(DocumentLoader*);
    112         virtual void revertToProvisionalState(DocumentLoader*);
    113         virtual void setMainDocumentError(DocumentLoader*, const ResourceError&);
    114 
    115         virtual void willChangeEstimatedProgress();
    116         virtual void didChangeEstimatedProgress();
    117         virtual void postProgressStartedNotification();
    118         virtual void postProgressEstimateChangedNotification();
    119         virtual void postProgressFinishedNotification();
    120 
    121         virtual void setMainFrameDocumentReady(bool);
    122 
    123         virtual void startDownload(const ResourceRequest&);
    124 
    125         virtual void willChangeTitle(DocumentLoader*);
    126         virtual void didChangeTitle(DocumentLoader*);
    127 
    128         virtual void committedLoad(DocumentLoader*, const char*, int);
    129         virtual void finishedLoading(DocumentLoader*);
    130 
    131         virtual void updateGlobalHistory();
    132         virtual void updateGlobalHistoryRedirectLinks();
    133 
    134         virtual bool shouldGoToHistoryItem(HistoryItem*) const;
    135         virtual bool shouldStopLoadingForHistoryItem(HistoryItem*) const;
    136 
    137         virtual void didDisplayInsecureContent();
    138         virtual void didRunInsecureContent(SecurityOrigin*, const KURL&);
    139 
    140         virtual void dispatchDidAddBackForwardItem(HistoryItem*) const;
    141         virtual void dispatchDidRemoveBackForwardItem(HistoryItem*) const;
    142         virtual void dispatchDidChangeBackForwardIndex() const;
    143 
    144         virtual ResourceError cancelledError(const ResourceRequest&);
    145         virtual ResourceError blockedError(const ResourceRequest&);
    146         virtual ResourceError cannotShowURLError(const ResourceRequest&);
    147         virtual ResourceError interruptForPolicyChangeError(const ResourceRequest&);
    148 
    149         virtual ResourceError cannotShowMIMETypeError(const ResourceResponse&);
    150         virtual ResourceError fileDoesNotExistError(const ResourceResponse&);
    151         virtual ResourceError pluginWillHandleLoadError(const ResourceResponse&);
    152 
    153         virtual bool shouldFallBack(const ResourceError&);
    154 
    155         virtual bool canHandleRequest(const ResourceRequest&) const;
    156         virtual bool canShowMIMEType(const String& MIMEType) const;
    157         virtual bool canShowMIMETypeAsHTML(const String& MIMEType) const;
    158         virtual bool representationExistsForURLScheme(const String& URLScheme) const;
    159         virtual String generatedMIMETypeForURLScheme(const String& URLScheme) const;
    160 
    161         virtual void frameLoadCompleted();
    162         virtual void saveViewStateToItem(HistoryItem*);
    163         virtual void restoreViewState();
    164         virtual void provisionalLoadStarted();
    165         virtual void didFinishLoad();
    166         virtual void prepareForDataSourceReplacement();
    167 
    168         virtual PassRefPtr<DocumentLoader> createDocumentLoader(const ResourceRequest&, const SubstituteData&);
    169         virtual void setTitle(const StringWithDirection& title, const KURL&);
    170 
    171         // This provides the userAgent to WebCore. It is used by WebCore to
    172         // populate navigator.userAgent and to set the HTTP header in
    173         // ResourceRequest objects. We also set a userAgent on WebRequestContext
    174         // for the Chromium HTTP stack, which overrides the value on the
    175         // ResourceRequest.
    176         virtual String userAgent(const KURL&);
    177 
    178         virtual void savePlatformDataToCachedFrame(WebCore::CachedFrame*);
    179         virtual void transitionToCommittedFromCachedFrame(WebCore::CachedFrame*);
    180         virtual void transitionToCommittedForNewPage();
    181 
    182         virtual void dispatchDidBecomeFrameset(bool isFrameSet);
    183 
    184         virtual bool canCachePage() const;
    185         virtual void download(ResourceHandle*, const ResourceRequest&, const ResourceRequest&, const ResourceResponse&);
    186 
    187         virtual WTF::PassRefPtr<Frame> createFrame(const KURL& url, const String& name, HTMLFrameOwnerElement* ownerElement, const String& referrer, bool allowsScrolling, int marginWidth, int marginHeight);
    188         virtual void didTransferChildFrameToNewDocument(WebCore::Page*);
    189         virtual void transferLoadingResourceFromPage(unsigned long identifier, DocumentLoader*, const ResourceRequest&, Page* oldPage);
    190         virtual WTF::PassRefPtr<Widget> createPlugin(const IntSize&, HTMLPlugInElement*, const KURL&, const WTF::Vector<String>&, const WTF::Vector<String>&, const String&, bool loadManually);
    191         virtual void redirectDataToPlugin(Widget* pluginWidget);
    192 
    193         virtual WTF::PassRefPtr<Widget> createJavaAppletWidget(const IntSize&, HTMLAppletElement*, const KURL& baseURL, const WTF::Vector<String>& paramNames, const WTF::Vector<String>& paramValues);
    194 
    195         virtual ObjectContentType objectContentType(const KURL& url, const String& mimeType, bool shouldPreferPlugInsForImages);
    196         virtual String overrideMediaType() const;
    197 
    198         virtual void dispatchDidClearWindowObjectInWorld(DOMWrapperWorld*);
    199         virtual void documentElementAvailable();
    200         virtual void didPerformFirstNavigation() const;
    201 
    202         // TODO: Implement
    203         virtual void didCreateScriptContextForFrame() { }
    204         virtual void didDestroyScriptContextForFrame() { }
    205         virtual void didCreateIsolatedScriptContext() { }
    206 
    207         virtual bool allowScriptExtension(const String& extensionName, int extensionGroup) { return false; }
    208 
    209         virtual void registerForIconNotification(bool listen = true);
    210 
    211         virtual void dispatchDidReceiveTouchIconURL(const String& url, bool precomposed);
    212 
    213         virtual PassRefPtr<FrameNetworkingContext> createNetworkingContext();
    214 
    215         // WebIconDatabaseClient api
    216         virtual void didAddIconForPageUrl(const String& pageUrl);
    217 
    218         void enableOnDemandPlugins() { m_onDemandPluginsEnabled = true; }
    219 
    220         void dispatchDidChangeIcons();
    221         void dispatchWillSendSubmitEvent(HTMLFormElement*);
    222 
    223         virtual void didSaveToPageCache() { }
    224         virtual void didRestoreFromPageCache() { }
    225     private:
    226         Frame* m_frame;
    227         WebFrame* m_webFrame;
    228         PluginManualLoader* m_manualLoader;
    229         bool m_hasSentResponseToPlugin;
    230         bool m_onDemandPluginsEnabled;
    231         mutable bool m_didReceiveServerRedirect;
    232 
    233         enum ResourceErrors {
    234             InternalErrorCancelled = -99,
    235             InternalErrorCannotShowUrl,
    236             InternalErrorInterrupted,
    237             InternalErrorCannotShowMimeType,
    238             InternalErrorFileDoesNotExist,
    239             InternalErrorPluginWillHandleLoadError,
    240             InternalErrorLast
    241         };
    242 
    243         /* XXX: These must match android.net.http.EventHandler */
    244         enum EventHandlerErrors {
    245             Error                      = -1,
    246             ErrorLookup                = -2,
    247             ErrorUnsupportedAuthScheme = -3,
    248             ErrorAuth                  = -4,
    249             ErrorProxyAuth             = -5,
    250             ErrorConnect               = -6,
    251             ErrorIO                    = -7,
    252             ErrorTimeout               = -8,
    253             ErrorRedirectLoop          = -9,
    254             ErrorUnsupportedScheme     = -10,
    255             ErrorFailedSslHandshake    = -11,
    256             ErrorBadUrl                = -12,
    257             ErrorFile                  = -13,
    258             ErrorFileNotFound          = -14,
    259             ErrorTooManyRequests       = -15
    260         };
    261     };
    262 
    263 }
    264 
    265 #endif
    266