2 * Copyright 2007, The Android Open Source Project
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
26 #ifndef FrameLoaderClientAndroid_h
27 #define FrameLoaderClientAndroid_h
29 #include "CacheBuilder.h"
30 #include "FrameLoaderClient.h"
31 #include "ResourceResponse.h"
32 #include "WebIconDatabase.h"
33 #include <wtf/Forward.h>
36 class PluginManualLoader;
39 using namespace WebCore;
44 class FrameLoaderClientAndroid : public FrameLoaderClient,
45 WebIconDatabaseClient {
47 FrameLoaderClientAndroid(WebFrame* webframe);
49 Frame* getFrame() { return m_frame; }
50 static FrameLoaderClientAndroid* get(const Frame* frame);
52 void setFrame(Frame* frame) { m_frame = frame; }
53 WebFrame* webFrame() const { return m_webFrame; }
55 virtual void frameLoaderDestroyed();
57 virtual bool hasWebView() const; // mainly for assertions
59 virtual void makeRepresentation(DocumentLoader*);
60 virtual void forceLayout();
61 virtual void forceLayoutForNonHTML();
63 virtual void setCopiesOnScroll();
65 virtual void detachedFromParent2();
66 virtual void detachedFromParent3();
68 virtual void assignIdentifierToInitialRequest(unsigned long identifier, DocumentLoader*, const ResourceRequest&);
70 virtual void dispatchWillSendRequest(DocumentLoader*, unsigned long identifier, ResourceRequest&, const ResourceResponse& redirectResponse);
71 virtual bool shouldUseCredentialStorage(DocumentLoader*, unsigned long identifier);
72 virtual void dispatchDidReceiveAuthenticationChallenge(DocumentLoader*, unsigned long identifier, const AuthenticationChallenge&);
73 virtual void dispatchDidCancelAuthenticationChallenge(DocumentLoader*, unsigned long identifier, const AuthenticationChallenge&);
74 virtual void dispatchDidReceiveResponse(DocumentLoader*, unsigned long identifier, const ResourceResponse&);
75 virtual void dispatchDidReceiveContentLength(DocumentLoader*, unsigned long identifier, int lengthReceived);
76 virtual void dispatchDidFinishLoading(DocumentLoader*, unsigned long identifier);
77 virtual void dispatchDidFailLoading(DocumentLoader*, unsigned long identifier, const ResourceError&);
78 virtual bool dispatchDidLoadResourceFromMemoryCache(DocumentLoader*, const ResourceRequest&, const ResourceResponse&, int length);
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();
100 virtual Frame* dispatchCreatePage(const NavigationAction&);
101 virtual void dispatchShow();
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();
108 virtual void dispatchUnableToImplementPolicy(const ResourceError&);
110 virtual void dispatchWillSubmitForm(FramePolicyFunction, PassRefPtr<FormState>);
112 virtual void dispatchDidLoadMainResource(DocumentLoader*);
113 virtual void revertToProvisionalState(DocumentLoader*);
114 virtual void setMainDocumentError(DocumentLoader*, const ResourceError&);
116 virtual void willChangeEstimatedProgress();
117 virtual void didChangeEstimatedProgress();
118 virtual void postProgressStartedNotification();
119 virtual void postProgressEstimateChangedNotification();
120 virtual void postProgressFinishedNotification();
122 virtual void setMainFrameDocumentReady(bool);
124 virtual void startDownload(const ResourceRequest&);
126 virtual void willChangeTitle(DocumentLoader*);
127 virtual void didChangeTitle(DocumentLoader*);
129 virtual void committedLoad(DocumentLoader*, const char*, int);
130 virtual void finishedLoading(DocumentLoader*);
132 virtual void updateGlobalHistory();
133 virtual void updateGlobalHistoryRedirectLinks();
135 virtual bool shouldGoToHistoryItem(HistoryItem*) const;
137 virtual void didDisplayInsecureContent();
138 virtual void didRunInsecureContent(SecurityOrigin*);
140 virtual void dispatchDidAddBackForwardItem(HistoryItem*) const;
141 virtual void dispatchDidRemoveBackForwardItem(HistoryItem*) const;
142 virtual void dispatchDidChangeBackForwardIndex() const;
144 virtual ResourceError cancelledError(const ResourceRequest&);
145 virtual ResourceError blockedError(const ResourceRequest&);
146 virtual ResourceError cannotShowURLError(const ResourceRequest&);
147 virtual ResourceError interruptForPolicyChangeError(const ResourceRequest&);
149 virtual ResourceError cannotShowMIMETypeError(const ResourceResponse&);
150 virtual ResourceError fileDoesNotExistError(const ResourceResponse&);
151 virtual ResourceError pluginWillHandleLoadError(const ResourceResponse&);
153 virtual bool shouldFallBack(const ResourceError&);
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;
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();
168 virtual PassRefPtr<DocumentLoader> createDocumentLoader(const ResourceRequest&, const SubstituteData&);
169 virtual void setTitle(const String& title, const KURL&);
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
176 virtual String userAgent(const KURL&);
178 virtual void savePlatformDataToCachedFrame(WebCore::CachedFrame*);
179 virtual void transitionToCommittedFromCachedFrame(WebCore::CachedFrame*);
180 virtual void transitionToCommittedForNewPage();
182 virtual void dispatchDidBecomeFrameset(bool isFrameSet);
184 virtual bool canCachePage() const;
185 virtual void download(ResourceHandle*, const ResourceRequest&, const ResourceRequest&, const ResourceResponse&);
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);
193 virtual WTF::PassRefPtr<Widget> createJavaAppletWidget(const IntSize&, HTMLAppletElement*, const KURL& baseURL, const WTF::Vector<String>& paramNames, const WTF::Vector<String>& paramValues);
195 virtual ObjectContentType objectContentType(const KURL& url, const String& mimeType);
196 virtual String overrideMediaType() const;
198 virtual void dispatchDidClearWindowObjectInWorld(DOMWrapperWorld*);
199 virtual void documentElementAvailable();
200 virtual void didPerformFirstNavigation() const;
203 // TODO(benm): Implement
204 virtual void didCreateScriptContextForFrame() { }
205 virtual void didDestroyScriptContextForFrame() { }
206 virtual void didCreateIsolatedScriptContext() { }
208 virtual bool allowScriptExtension(const String& extensionName, int extensionGroup) { return false; }
211 virtual void registerForIconNotification(bool listen = true);
213 virtual void dispatchDidReceiveTouchIconURL(const String& url, bool precomposed);
215 virtual PassRefPtr<FrameNetworkingContext> createNetworkingContext();
217 // WebIconDatabaseClient api
218 virtual void didAddIconForPageUrl(const String& pageUrl);
220 // FIXME: this doesn't really go here, but it's better than Frame
221 CacheBuilder& getCacheBuilder() { return m_cacheBuilder; }
223 void enableOnDemandPlugins() { m_onDemandPluginsEnabled = true; }
225 void dispatchDidChangeIcons();
226 void dispatchWillSendSubmitEvent(HTMLFormElement*) { }
228 CacheBuilder m_cacheBuilder;
230 WebFrame* m_webFrame;
231 PluginManualLoader* m_manualLoader;
232 bool m_hasSentResponseToPlugin;
233 bool m_onDemandPluginsEnabled;
235 enum ResourceErrors {
236 InternalErrorCancelled = -99,
237 InternalErrorCannotShowUrl,
238 InternalErrorInterrupted,
239 InternalErrorCannotShowMimeType,
240 InternalErrorFileDoesNotExist,
241 InternalErrorPluginWillHandleLoadError,
245 /* XXX: These must match android.net.http.EventHandler */
246 enum EventHandlerErrors {
249 ErrorUnsupportedAuthScheme = -3,
255 ErrorRedirectLoop = -9,
256 ErrorUnsupportedScheme = -10,
257 ErrorFailedSslHandshake = -11,
260 ErrorFileNotFound = -14,
261 ErrorTooManyRequests = -15
263 friend class CacheBuilder;