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