FrameLoaderClientImpl.h revision 2fc2651226baac27029e38c9d6ef883fa32084db
1/*
2 * Copyright (C) 2009 Google 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 are
6 * met:
7 *
8 *     * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *     * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 *     * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#ifndef FrameLoaderClientImpl_h
32#define FrameLoaderClientImpl_h
33
34#include "FrameLoaderClient.h"
35#include "KURL.h"
36#include "WebNavigationPolicy.h"
37#include <wtf/PassOwnPtr.h>
38#include <wtf/RefPtr.h>
39
40namespace WebKit {
41
42class WebFrameImpl;
43class WebPluginContainerImpl;
44class WebPluginLoadObserver;
45
46class FrameLoaderClientImpl : public WebCore::FrameLoaderClient {
47public:
48    FrameLoaderClientImpl(WebFrameImpl* webFrame);
49    ~FrameLoaderClientImpl();
50
51    WebFrameImpl* webFrame() const { return m_webFrame; }
52
53    // WebCore::FrameLoaderClient ----------------------------------------------
54
55    virtual void frameLoaderDestroyed();
56
57    // Notifies the WebView delegate that the JS window object has been cleared,
58    // giving it a chance to bind native objects to the window before script
59    // parsing begins.
60    virtual void dispatchDidClearWindowObjectInWorld(WebCore::DOMWrapperWorld*);
61    virtual void documentElementAvailable();
62
63    // A frame's V8 context was created or destroyed.
64    virtual void didCreateScriptContextForFrame();
65    virtual void didDestroyScriptContextForFrame();
66
67    // A context untied to a frame was created (through evaluateInIsolatedWorld).
68    // This context is not tied to the lifetime of its frame, and is destroyed
69    // in garbage collection.
70    virtual void didCreateIsolatedScriptContext();
71
72    // Returns true if we should allow the given V8 extension to be added to
73    // the script context at the currently loading page and given extension group.
74    virtual bool allowScriptExtension(const String& extensionName, int extensionGroup);
75
76    virtual bool hasWebView() const;
77    virtual bool hasFrameView() const;
78    virtual void makeRepresentation(WebCore::DocumentLoader*);
79    virtual void forceLayout();
80    virtual void forceLayoutForNonHTML();
81    virtual void setCopiesOnScroll();
82    virtual void detachedFromParent2();
83    virtual void detachedFromParent3();
84    virtual void assignIdentifierToInitialRequest(unsigned long identifier, WebCore::DocumentLoader*, const WebCore::ResourceRequest&);
85    virtual void dispatchWillSendRequest(WebCore::DocumentLoader*, unsigned long identifier, WebCore::ResourceRequest&, const WebCore::ResourceResponse& redirectResponse);
86    virtual bool shouldUseCredentialStorage(WebCore::DocumentLoader*, unsigned long identifier);
87    virtual void dispatchDidReceiveAuthenticationChallenge(WebCore::DocumentLoader*, unsigned long identifier, const WebCore::AuthenticationChallenge&);
88    virtual void dispatchDidCancelAuthenticationChallenge(WebCore::DocumentLoader*, unsigned long identifier, const WebCore::AuthenticationChallenge&);
89    virtual void dispatchDidReceiveResponse(WebCore::DocumentLoader*, unsigned long identifier, const WebCore::ResourceResponse&);
90    virtual void dispatchDidReceiveContentLength(WebCore::DocumentLoader*, unsigned long identifier, int lengthReceived);
91    virtual void dispatchDidFinishLoading(WebCore::DocumentLoader*, unsigned long identifier);
92    virtual void dispatchDidFailLoading(WebCore::DocumentLoader*, unsigned long identifier, const WebCore::ResourceError&);
93    virtual bool dispatchDidLoadResourceFromMemoryCache(WebCore::DocumentLoader*, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&, int length);
94    virtual void dispatchDidHandleOnloadEvents();
95    virtual void dispatchDidReceiveServerRedirectForProvisionalLoad();
96    virtual void dispatchDidCancelClientRedirect();
97    virtual void dispatchWillPerformClientRedirect(const WebCore::KURL&, double interval, double fireDate);
98    virtual void dispatchDidNavigateWithinPage();
99    virtual void dispatchDidChangeLocationWithinPage();
100    virtual void dispatchDidPushStateWithinPage();
101    virtual void dispatchDidReplaceStateWithinPage();
102    virtual void dispatchDidPopStateWithinPage();
103    virtual void dispatchWillClose();
104    virtual void dispatchDidReceiveIcon();
105    virtual void dispatchDidStartProvisionalLoad();
106    virtual void dispatchDidReceiveTitle(const WTF::String& title);
107    virtual void dispatchDidChangeIcons();
108    virtual void dispatchDidCommitLoad();
109    virtual void dispatchDidFailProvisionalLoad(const WebCore::ResourceError&);
110    virtual void dispatchDidFailLoad(const WebCore::ResourceError&);
111    virtual void dispatchDidFinishDocumentLoad();
112    virtual void dispatchDidFinishLoad();
113    virtual void dispatchDidFirstLayout();
114    virtual void dispatchDidFirstVisuallyNonEmptyLayout();
115    virtual WebCore::Frame* dispatchCreatePage(const WebCore::NavigationAction&);
116    virtual void dispatchShow();
117    virtual void dispatchDecidePolicyForMIMEType(WebCore::FramePolicyFunction function, const WTF::String& mime_type, const WebCore::ResourceRequest&);
118    virtual void dispatchDecidePolicyForNewWindowAction(WebCore::FramePolicyFunction function, const WebCore::NavigationAction& action, const WebCore::ResourceRequest& request, PassRefPtr<WebCore::FormState> form_state, const WTF::String& frame_name);
119    virtual void dispatchDecidePolicyForNavigationAction(WebCore::FramePolicyFunction function, const WebCore::NavigationAction& action, const WebCore::ResourceRequest& request, PassRefPtr<WebCore::FormState> form_state);
120    virtual void cancelPolicyCheck();
121    virtual void dispatchUnableToImplementPolicy(const WebCore::ResourceError&);
122    virtual void dispatchWillSendSubmitEvent(WebCore::HTMLFormElement*);
123    virtual void dispatchWillSubmitForm(WebCore::FramePolicyFunction, PassRefPtr<WebCore::FormState>);
124    virtual void dispatchDidLoadMainResource(WebCore::DocumentLoader*);
125    virtual void revertToProvisionalState(WebCore::DocumentLoader*);
126    virtual void setMainDocumentError(WebCore::DocumentLoader*, const WebCore::ResourceError&);
127    virtual void willChangeEstimatedProgress() { }
128    virtual void didChangeEstimatedProgress() { }
129    virtual void postProgressStartedNotification();
130    virtual void postProgressEstimateChangedNotification();
131    virtual void postProgressFinishedNotification();
132    virtual void setMainFrameDocumentReady(bool);
133    virtual void startDownload(const WebCore::ResourceRequest&);
134    virtual void willChangeTitle(WebCore::DocumentLoader*);
135    virtual void didChangeTitle(WebCore::DocumentLoader*);
136    virtual void committedLoad(WebCore::DocumentLoader*, const char*, int);
137    virtual void finishedLoading(WebCore::DocumentLoader*);
138    virtual void updateGlobalHistory();
139    virtual void updateGlobalHistoryRedirectLinks();
140    virtual bool shouldGoToHistoryItem(WebCore::HistoryItem*) const;
141    virtual void dispatchDidAddBackForwardItem(WebCore::HistoryItem*) const;
142    virtual void dispatchDidRemoveBackForwardItem(WebCore::HistoryItem*) const;
143    virtual void dispatchDidChangeBackForwardIndex() const;
144    virtual void didDisplayInsecureContent();
145    virtual void didRunInsecureContent(WebCore::SecurityOrigin*, const WebCore::KURL& insecureURL);
146    virtual WebCore::ResourceError blockedError(const WebCore::ResourceRequest&);
147    virtual WebCore::ResourceError cancelledError(const WebCore::ResourceRequest&);
148    virtual WebCore::ResourceError cannotShowURLError(const WebCore::ResourceRequest&);
149    virtual WebCore::ResourceError interruptForPolicyChangeError(const WebCore::ResourceRequest&);
150    virtual WebCore::ResourceError cannotShowMIMETypeError(const WebCore::ResourceResponse&);
151    virtual WebCore::ResourceError fileDoesNotExistError(const WebCore::ResourceResponse&);
152    virtual WebCore::ResourceError pluginWillHandleLoadError(const WebCore::ResourceResponse&);
153    virtual bool shouldFallBack(const WebCore::ResourceError&);
154    virtual bool canHandleRequest(const WebCore::ResourceRequest&) const;
155    virtual bool canShowMIMEType(const WTF::String& MIMEType) const;
156    virtual bool canShowMIMETypeAsHTML(const String& MIMEType) const;
157    virtual bool representationExistsForURLScheme(const WTF::String& URLScheme) const;
158    virtual WTF::String generatedMIMETypeForURLScheme(const WTF::String& URLScheme) const;
159    virtual void frameLoadCompleted();
160    virtual void saveViewStateToItem(WebCore::HistoryItem*);
161    virtual void restoreViewState();
162    virtual void provisionalLoadStarted();
163    virtual void didFinishLoad();
164    virtual void prepareForDataSourceReplacement();
165    virtual PassRefPtr<WebCore::DocumentLoader> createDocumentLoader(
166        const WebCore::ResourceRequest&, const WebCore::SubstituteData&);
167    virtual void setTitle(const WTF::String& title, const WebCore::KURL&);
168    virtual WTF::String userAgent(const WebCore::KURL&);
169    virtual void savePlatformDataToCachedFrame(WebCore::CachedFrame*);
170    virtual void transitionToCommittedFromCachedFrame(WebCore::CachedFrame*);
171    virtual void transitionToCommittedForNewPage();
172    virtual void didSaveToPageCache();
173    virtual void didRestoreFromPageCache();
174    virtual void dispatchDidBecomeFrameset(bool);
175    virtual bool canCachePage() const;
176    virtual void download(
177        WebCore::ResourceHandle*, const WebCore::ResourceRequest&,
178        const WebCore::ResourceRequest& initialRequest,
179        const WebCore::ResourceResponse&);
180    virtual PassRefPtr<WebCore::Frame> createFrame(
181        const WebCore::KURL& url, const WTF::String& name,
182        WebCore::HTMLFrameOwnerElement* ownerElement,
183        const WTF::String& referrer, bool allowsScrolling,
184        int marginWidth, int marginHeight);
185    virtual void didTransferChildFrameToNewDocument(WebCore::Page*);
186    virtual void transferLoadingResourceFromPage(unsigned long, WebCore::DocumentLoader*, const WebCore::ResourceRequest&, WebCore::Page*);
187    virtual PassRefPtr<WebCore::Widget> createPlugin(
188        const WebCore::IntSize&, WebCore::HTMLPlugInElement*, const WebCore::KURL&,
189        const Vector<WTF::String>&, const Vector<WTF::String>&,
190        const WTF::String&, bool loadManually);
191    virtual void redirectDataToPlugin(WebCore::Widget* pluginWidget);
192    virtual PassRefPtr<WebCore::Widget> createJavaAppletWidget(
193        const WebCore::IntSize&,
194        WebCore::HTMLAppletElement*,
195        const WebCore::KURL& /* base_url */,
196        const Vector<WTF::String>& paramNames,
197        const Vector<WTF::String>& paramValues);
198    virtual WebCore::ObjectContentType objectContentType(
199        const WebCore::KURL& url, const WTF::String& mimeType);
200    virtual WTF::String overrideMediaType() const;
201    virtual void didPerformFirstNavigation() const;
202    virtual void registerForIconNotification(bool listen = true);
203    virtual void didChangeScrollOffset();
204    virtual bool allowJavaScript(bool enabledPerSettings);
205    virtual bool allowPlugins(bool enabledPerSettings);
206    virtual bool allowImages(bool enabledPerSettings);
207    virtual void didNotAllowScript();
208    virtual void didNotAllowPlugins();
209
210    virtual PassRefPtr<WebCore::FrameNetworkingContext> createNetworkingContext();
211
212private:
213    void makeDocumentView();
214
215    // Given a NavigationAction, determine the associated WebNavigationPolicy.
216    // For example, a middle click means "open in background tab".
217    static bool actionSpecifiesNavigationPolicy(
218        const WebCore::NavigationAction& action, WebNavigationPolicy* policy);
219
220    PassOwnPtr<WebPluginLoadObserver> pluginLoadObserver();
221
222    // The WebFrame that owns this object and manages its lifetime. Therefore,
223    // the web frame object is guaranteed to exist.
224    WebFrameImpl* m_webFrame;
225
226    // True if makeRepresentation was called.  We don't actually have a concept
227    // of a "representation", but we need to know when we're expected to have one.
228    // See finishedLoading().
229    bool m_hasRepresentation;
230
231    // Used to help track client redirects. When a provisional load starts, it
232    // has no redirects in its chain. But in the case of client redirects, we want
233    // to add that initial load as a redirect. When we get a new provisional load
234    // and the dest URL matches that load, we know that it was the result of a
235    // previous client redirect and the source should be added as a redirect.
236    // Both should be empty if unused.
237    WebCore::KURL m_expectedClientRedirectSrc;
238    WebCore::KURL m_expectedClientRedirectDest;
239
240    // Contains a pointer to the plugin widget.
241    RefPtr<WebPluginContainerImpl> m_pluginWidget;
242
243    // Indicates if we need to send over the initial notification to the plugin
244    // which specifies that the plugin should be ready to accept data.
245    bool m_sentInitialResponseToPlugin;
246
247    // The navigation policy to use for the next call to dispatchCreatePage.
248    WebNavigationPolicy m_nextNavigationPolicy;
249};
250
251} // namespace WebKit
252
253#endif
254