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 "CacheBuilder.h" 30 #include "FrameLoaderClient.h" 31 #include "ResourceResponse.h" 32 #include "WebIconDatabase.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 getFrame()48 Frame* getFrame() { return m_frame; } 49 static FrameLoaderClientAndroid* get(const Frame* frame); 50 setFrame(Frame * frame)51 void setFrame(Frame* frame) { m_frame = frame; } webFrame()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 virtual void dispatchDidLoadResourceByXMLHttpRequest(unsigned long identifier, const ScriptString&); 79 80 virtual void dispatchDidHandleOnloadEvents(); 81 virtual void dispatchDidReceiveServerRedirectForProvisionalLoad(); 82 virtual void dispatchDidCancelClientRedirect(); 83 virtual void dispatchWillPerformClientRedirect(const KURL&, double interval, double fireDate); 84 virtual void dispatchDidChangeLocationWithinPage(); 85 virtual void dispatchDidPushStateWithinPage(); 86 virtual void dispatchDidReplaceStateWithinPage(); 87 virtual void dispatchDidPopStateWithinPage(); 88 virtual void dispatchWillClose(); 89 virtual void dispatchDidReceiveIcon(); 90 virtual void dispatchDidStartProvisionalLoad(); 91 virtual void dispatchDidReceiveTitle(const String& title); 92 virtual void dispatchDidCommitLoad(); 93 virtual void dispatchDidFailProvisionalLoad(const ResourceError&); 94 virtual void dispatchDidFailLoad(const ResourceError&); 95 virtual void dispatchDidFinishDocumentLoad(); 96 virtual void dispatchDidFinishLoad(); 97 virtual void dispatchDidFirstLayout(); 98 virtual void dispatchDidFirstVisuallyNonEmptyLayout(); 99 100 virtual Frame* dispatchCreatePage(); 101 virtual void dispatchShow(); 102 103 virtual void dispatchDecidePolicyForMIMEType(FramePolicyFunction, const String& MIMEType, const ResourceRequest&); 104 virtual void dispatchDecidePolicyForNewWindowAction(FramePolicyFunction, const NavigationAction&, const ResourceRequest&, PassRefPtr<FormState>, const String& frameName); 105 virtual void dispatchDecidePolicyForNavigationAction(FramePolicyFunction, const NavigationAction&, const ResourceRequest&, PassRefPtr<FormState>); 106 virtual void cancelPolicyCheck(); 107 108 virtual void dispatchUnableToImplementPolicy(const ResourceError&); 109 110 virtual void dispatchWillSubmitForm(FramePolicyFunction, PassRefPtr<FormState>); 111 112 virtual void dispatchDidLoadMainResource(DocumentLoader*); 113 virtual void revertToProvisionalState(DocumentLoader*); 114 virtual void setMainDocumentError(DocumentLoader*, const ResourceError&); 115 116 virtual void willChangeEstimatedProgress(); 117 virtual void didChangeEstimatedProgress(); 118 virtual void postProgressStartedNotification(); 119 virtual void postProgressEstimateChangedNotification(); 120 virtual void postProgressFinishedNotification(); 121 122 virtual void setMainFrameDocumentReady(bool); 123 124 virtual void startDownload(const ResourceRequest&); 125 126 virtual void willChangeTitle(DocumentLoader*); 127 virtual void didChangeTitle(DocumentLoader*); 128 129 virtual void committedLoad(DocumentLoader*, const char*, int); 130 virtual void finishedLoading(DocumentLoader*); 131 132 virtual void updateGlobalHistory(); 133 virtual void updateGlobalHistoryRedirectLinks(); 134 135 virtual bool shouldGoToHistoryItem(HistoryItem*) const; 136 137 virtual void didDisplayInsecureContent(); 138 virtual void didRunInsecureContent(SecurityOrigin*); 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 representationExistsForURLScheme(const String& URLScheme) const; 158 virtual String generatedMIMETypeForURLScheme(const String& URLScheme) const; 159 160 virtual void frameLoadCompleted(); 161 virtual void saveViewStateToItem(HistoryItem*); 162 virtual void restoreViewState(); 163 virtual void provisionalLoadStarted(); 164 virtual void didFinishLoad(); 165 virtual void prepareForDataSourceReplacement(); 166 167 virtual PassRefPtr<DocumentLoader> createDocumentLoader(const ResourceRequest&, const SubstituteData&); 168 virtual void setTitle(const String& title, const KURL&); 169 170 virtual String userAgent(const KURL&); 171 172 virtual void savePlatformDataToCachedFrame(WebCore::CachedFrame*); 173 virtual void transitionToCommittedFromCachedFrame(WebCore::CachedFrame*); 174 virtual void transitionToCommittedForNewPage(); 175 176 virtual bool canCachePage() const; 177 virtual void download(ResourceHandle*, const ResourceRequest&, const ResourceRequest&, const ResourceResponse&); 178 179 virtual WTF::PassRefPtr<Frame> createFrame(const KURL& url, const String& name, HTMLFrameOwnerElement* ownerElement, 180 const String& referrer, bool allowsScrolling, int marginWidth, int marginHeight); 181 virtual WTF::PassRefPtr<Widget> createPlugin(const IntSize&, HTMLPlugInElement*, const KURL&, 182 const WTF::Vector<String>&, const WTF::Vector<String>&, 183 const String&, bool loadManually); 184 virtual void redirectDataToPlugin(Widget* pluginWidget); 185 186 virtual WTF::PassRefPtr<Widget> createJavaAppletWidget(const IntSize&, HTMLAppletElement*, const KURL& baseURL, const WTF::Vector<String>& paramNames, const WTF::Vector<String>& paramValues); 187 188 virtual ObjectContentType objectContentType(const KURL& url, const String& mimeType); 189 virtual String overrideMediaType() const; 190 191 virtual void dispatchDidClearWindowObjectInWorld(DOMWrapperWorld*); 192 virtual void documentElementAvailable(); 193 virtual void didPerformFirstNavigation() const; 194 195 #if USE(V8) 196 // TODO(benm): Implement didCreateScriptContextForFrame()197 virtual void didCreateScriptContextForFrame() { } didDestroyScriptContextForFrame()198 virtual void didDestroyScriptContextForFrame() { } didCreateIsolatedScriptContext()199 virtual void didCreateIsolatedScriptContext() { } 200 #endif 201 202 virtual void registerForIconNotification(bool listen = true); 203 204 virtual void dispatchDidReceiveTouchIconURL(const String& url, bool precomposed); 205 206 // WebIconDatabaseClient api 207 virtual void didAddIconForPageUrl(const String& pageUrl); 208 209 // FIXME: this doesn't really go here, but it's better than Frame getCacheBuilder()210 CacheBuilder& getCacheBuilder() { return m_cacheBuilder; } 211 enableOnDemandPlugins()212 void enableOnDemandPlugins() { m_onDemandPluginsEnabled = true; } 213 private: 214 CacheBuilder m_cacheBuilder; 215 Frame* m_frame; 216 WebFrame* m_webFrame; 217 PluginManualLoader* m_manualLoader; 218 bool m_hasSentResponseToPlugin; 219 bool m_onDemandPluginsEnabled; 220 221 enum ResourceErrors { 222 InternalErrorCancelled = -99, 223 InternalErrorCannotShowUrl, 224 InternalErrorInterrupted, 225 InternalErrorCannotShowMimeType, 226 InternalErrorFileDoesNotExist, 227 InternalErrorPluginWillHandleLoadError, 228 InternalErrorLast 229 }; 230 231 /* XXX: These must match android.net.http.EventHandler */ 232 enum EventHandlerErrors { 233 Error = -1, 234 ErrorLookup = -2, 235 ErrorUnsupportedAuthScheme = -3, 236 ErrorAuth = -4, 237 ErrorProxyAuth = -5, 238 ErrorConnect = -6, 239 ErrorIO = -7, 240 ErrorTimeout = -8, 241 ErrorRedirectLoop = -9, 242 ErrorUnsupportedScheme = -10, 243 ErrorFailedSslHandshake = -11, 244 ErrorBadUrl = -12, 245 ErrorFile = -13, 246 ErrorFileNotFound = -14, 247 ErrorTooManyRequests = -15 248 }; 249 friend class CacheBuilder; 250 }; 251 252 } 253 254 #endif 255