• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // FIXME: remove this relative path once consumers from glue are removed.
35 #include "../public/WebNavigationPolicy.h"
36 #include "FrameLoaderClient.h"
37 #include "KURL.h"
38 #include <wtf/PassOwnPtr.h>
39 #include <wtf/RefPtr.h>
40 
41 
42 namespace WebKit {
43 
44 class WebFrameImpl;
45 class WebPluginContainerImpl;
46 class WebPluginLoadObserver;
47 
48 class FrameLoaderClientImpl : public WebCore::FrameLoaderClient {
49 public:
50     FrameLoaderClientImpl(WebFrameImpl* webFrame);
51     ~FrameLoaderClientImpl();
52 
webFrame()53     WebFrameImpl* webFrame() const { return m_webFrame; }
54 
55     // WebCore::FrameLoaderClient ----------------------------------------------
56 
57     virtual void frameLoaderDestroyed();
58 
59     // Notifies the WebView delegate that the JS window object has been cleared,
60     // giving it a chance to bind native objects to the window before script
61     // parsing begins.
62     virtual void dispatchDidClearWindowObjectInWorld(WebCore::DOMWrapperWorld*);
63     virtual void documentElementAvailable();
64 
65     // A frame's V8 context was created or destroyed.
66     virtual void didCreateScriptContextForFrame();
67     virtual void didDestroyScriptContextForFrame();
68 
69     // A context untied to a frame was created (through evaluateInIsolatedWorld).
70     // This context is not tied to the lifetime of its frame, and is destroyed
71     // in garbage collection.
72     virtual void didCreateIsolatedScriptContext();
73 
74     virtual bool hasWebView() const;
75     virtual bool hasFrameView() const;
76     virtual void makeRepresentation(WebCore::DocumentLoader*);
77     virtual void forceLayout();
78     virtual void forceLayoutForNonHTML();
79     virtual void setCopiesOnScroll();
80     virtual void detachedFromParent2();
81     virtual void detachedFromParent3();
82     virtual void assignIdentifierToInitialRequest(unsigned long identifier, WebCore::DocumentLoader*, const WebCore::ResourceRequest&);
83     virtual void dispatchWillSendRequest(WebCore::DocumentLoader*, unsigned long identifier, WebCore::ResourceRequest&, const WebCore::ResourceResponse& redirectResponse);
84     virtual bool shouldUseCredentialStorage(WebCore::DocumentLoader*, unsigned long identifier);
85     virtual void dispatchDidReceiveAuthenticationChallenge(WebCore::DocumentLoader*, unsigned long identifier, const WebCore::AuthenticationChallenge&);
86     virtual void dispatchDidCancelAuthenticationChallenge(WebCore::DocumentLoader*, unsigned long identifier, const WebCore::AuthenticationChallenge&);
87     virtual void dispatchDidReceiveResponse(WebCore::DocumentLoader*, unsigned long identifier, const WebCore::ResourceResponse&);
88     virtual void dispatchDidReceiveContentLength(WebCore::DocumentLoader*, unsigned long identifier, int lengthReceived);
89     virtual void dispatchDidFinishLoading(WebCore::DocumentLoader*, unsigned long identifier);
90     virtual void dispatchDidFailLoading(WebCore::DocumentLoader*, unsigned long identifier, const WebCore::ResourceError&);
91     virtual bool dispatchDidLoadResourceFromMemoryCache(WebCore::DocumentLoader*, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&, int length);
92     virtual void dispatchDidLoadResourceByXMLHttpRequest(unsigned long identifier, const WebCore::ScriptString&);
93     virtual void dispatchDidHandleOnloadEvents();
94     virtual void dispatchDidReceiveServerRedirectForProvisionalLoad();
95     virtual void dispatchDidCancelClientRedirect();
96     virtual void dispatchWillPerformClientRedirect(const WebCore::KURL&, double interval, double fireDate);
97     virtual void dispatchDidChangeLocationWithinPage();
98     virtual void dispatchDidPushStateWithinPage();
99     virtual void dispatchDidReplaceStateWithinPage();
100     virtual void dispatchDidPopStateWithinPage();
101     virtual void dispatchWillClose();
102     virtual void dispatchDidReceiveIcon();
103     virtual void dispatchDidStartProvisionalLoad();
104     virtual void dispatchDidReceiveTitle(const WebCore::String& title);
105     virtual void dispatchDidCommitLoad();
106     virtual void dispatchDidFailProvisionalLoad(const WebCore::ResourceError&);
107     virtual void dispatchDidFailLoad(const WebCore::ResourceError&);
108     virtual void dispatchDidFinishDocumentLoad();
109     virtual void dispatchDidFinishLoad();
110     virtual void dispatchDidFirstLayout();
111     virtual void dispatchDidFirstVisuallyNonEmptyLayout();
112     virtual WebCore::Frame* dispatchCreatePage();
113     virtual void dispatchShow();
114     virtual void dispatchDecidePolicyForMIMEType(WebCore::FramePolicyFunction function, const WebCore::String& mime_type, const WebCore::ResourceRequest&);
115     virtual void dispatchDecidePolicyForNewWindowAction(WebCore::FramePolicyFunction function, const WebCore::NavigationAction& action, const WebCore::ResourceRequest& request, PassRefPtr<WebCore::FormState> form_state, const WebCore::String& frame_name);
116     virtual void dispatchDecidePolicyForNavigationAction(WebCore::FramePolicyFunction function, const WebCore::NavigationAction& action, const WebCore::ResourceRequest& request, PassRefPtr<WebCore::FormState> form_state);
117     virtual void cancelPolicyCheck();
118     virtual void dispatchUnableToImplementPolicy(const WebCore::ResourceError&);
119     virtual void dispatchWillSubmitForm(WebCore::FramePolicyFunction, PassRefPtr<WebCore::FormState>);
120     virtual void dispatchDidLoadMainResource(WebCore::DocumentLoader*);
121     virtual void revertToProvisionalState(WebCore::DocumentLoader*);
122     virtual void setMainDocumentError(WebCore::DocumentLoader*, const WebCore::ResourceError&);
willChangeEstimatedProgress()123     virtual void willChangeEstimatedProgress() { }
didChangeEstimatedProgress()124     virtual void didChangeEstimatedProgress() { }
125     virtual void postProgressStartedNotification();
126     virtual void postProgressEstimateChangedNotification();
127     virtual void postProgressFinishedNotification();
128     virtual void setMainFrameDocumentReady(bool);
129     virtual void startDownload(const WebCore::ResourceRequest&);
130     virtual void willChangeTitle(WebCore::DocumentLoader*);
131     virtual void didChangeTitle(WebCore::DocumentLoader*);
132     virtual void committedLoad(WebCore::DocumentLoader*, const char*, int);
133     virtual void finishedLoading(WebCore::DocumentLoader*);
134     virtual void updateGlobalHistory();
135     virtual void updateGlobalHistoryRedirectLinks();
136     virtual bool shouldGoToHistoryItem(WebCore::HistoryItem*) const;
137     virtual void dispatchDidAddBackForwardItem(WebCore::HistoryItem*) const;
138     virtual void dispatchDidRemoveBackForwardItem(WebCore::HistoryItem*) const;
139     virtual void dispatchDidChangeBackForwardIndex() const;
140     virtual void didDisplayInsecureContent();
141     virtual void didRunInsecureContent(WebCore::SecurityOrigin*);
142     virtual WebCore::ResourceError blockedError(const WebCore::ResourceRequest&);
143     virtual WebCore::ResourceError cancelledError(const WebCore::ResourceRequest&);
144     virtual WebCore::ResourceError cannotShowURLError(const WebCore::ResourceRequest&);
145     virtual WebCore::ResourceError interruptForPolicyChangeError(const WebCore::ResourceRequest&);
146     virtual WebCore::ResourceError cannotShowMIMETypeError(const WebCore::ResourceResponse&);
147     virtual WebCore::ResourceError fileDoesNotExistError(const WebCore::ResourceResponse&);
148     virtual WebCore::ResourceError pluginWillHandleLoadError(const WebCore::ResourceResponse&);
149     virtual bool shouldFallBack(const WebCore::ResourceError&);
150     virtual bool canHandleRequest(const WebCore::ResourceRequest&) const;
151     virtual bool canShowMIMEType(const WebCore::String& MIMEType) const;
152     virtual bool representationExistsForURLScheme(const WebCore::String& URLScheme) const;
153     virtual WebCore::String generatedMIMETypeForURLScheme(const WebCore::String& URLScheme) const;
154     virtual void frameLoadCompleted();
155     virtual void saveViewStateToItem(WebCore::HistoryItem*);
156     virtual void restoreViewState();
157     virtual void provisionalLoadStarted();
158     virtual void didFinishLoad();
159     virtual void prepareForDataSourceReplacement();
160     virtual PassRefPtr<WebCore::DocumentLoader> createDocumentLoader(
161         const WebCore::ResourceRequest&, const WebCore::SubstituteData&);
162     virtual void setTitle(const WebCore::String& title, const WebCore::KURL&);
163     virtual WebCore::String userAgent(const WebCore::KURL&);
164     virtual void savePlatformDataToCachedFrame(WebCore::CachedFrame*);
165     virtual void transitionToCommittedFromCachedFrame(WebCore::CachedFrame*);
166     virtual void transitionToCommittedForNewPage();
167     virtual bool canCachePage() const;
168     virtual void download(
169         WebCore::ResourceHandle*, const WebCore::ResourceRequest&,
170         const WebCore::ResourceRequest& initialRequest,
171         const WebCore::ResourceResponse&);
172     virtual PassRefPtr<WebCore::Frame> createFrame(
173         const WebCore::KURL& url, const WebCore::String& name,
174         WebCore::HTMLFrameOwnerElement* ownerElement,
175         const WebCore::String& referrer, bool allowsScrolling,
176         int marginWidth, int marginHeight);
177     virtual PassRefPtr<WebCore::Widget> createPlugin(
178         const WebCore::IntSize&, WebCore::HTMLPlugInElement*, const WebCore::KURL&,
179         const Vector<WebCore::String>&, const Vector<WebCore::String>&,
180         const WebCore::String&, bool loadManually);
181     virtual void redirectDataToPlugin(WebCore::Widget* pluginWidget);
182     virtual PassRefPtr<WebCore::Widget> createJavaAppletWidget(
183         const WebCore::IntSize&,
184         WebCore::HTMLAppletElement*,
185         const WebCore::KURL& /* base_url */,
186         const Vector<WebCore::String>& paramNames,
187         const Vector<WebCore::String>& paramValues);
188     virtual WebCore::ObjectContentType objectContentType(
189         const WebCore::KURL& url, const WebCore::String& mimeType);
190     virtual WebCore::String overrideMediaType() const;
191     virtual void didPerformFirstNavigation() const;
192     virtual void registerForIconNotification(bool listen = true);
193     virtual void didChangeScrollOffset();
194     virtual bool allowJavaScript(bool enabledPerSettings);
195     virtual bool allowPlugins(bool enabledPerSettings);
196     virtual bool allowImages(bool enabledPerSettings);
197 
198 private:
199     void makeDocumentView();
200 
201     // Given a NavigationAction, determine the associated WebNavigationPolicy.
202     // For example, a middle click means "open in background tab".
203     static bool actionSpecifiesNavigationPolicy(
204         const WebCore::NavigationAction& action, WebNavigationPolicy* policy);
205 
206     // Called when a dummy back-forward navigation is intercepted.
207     void handleBackForwardNavigation(const WebCore::KURL&);
208 
209     PassOwnPtr<WebPluginLoadObserver> pluginLoadObserver();
210 
211     // The WebFrame that owns this object and manages its lifetime. Therefore,
212     // the web frame object is guaranteed to exist.
213     WebFrameImpl* m_webFrame;
214 
215     // True if makeRepresentation was called.  We don't actually have a concept
216     // of a "representation", but we need to know when we're expected to have one.
217     // See finishedLoading().
218     bool m_hasRepresentation;
219 
220     // Used to help track client redirects. When a provisional load starts, it
221     // has no redirects in its chain. But in the case of client redirects, we want
222     // to add that initial load as a redirect. When we get a new provisional load
223     // and the dest URL matches that load, we know that it was the result of a
224     // previous client redirect and the source should be added as a redirect.
225     // Both should be empty if unused.
226     WebCore::KURL m_expectedClientRedirectSrc;
227     WebCore::KURL m_expectedClientRedirectDest;
228 
229     // Contains a pointer to the plugin widget.
230     RefPtr<WebPluginContainerImpl> m_pluginWidget;
231 
232     // Indicates if we need to send over the initial notification to the plugin
233     // which specifies that the plugin should be ready to accept data.
234     bool m_sentInitialResponseToPlugin;
235 
236     // The navigation policy to use for the next call to dispatchCreatePage.
237     WebNavigationPolicy m_nextNavigationPolicy;
238 };
239 
240 } // namespace WebKit
241 
242 #endif
243