• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2006 Zack Rusin <zack@kde.org>
3  * Copyright (C) 2006, 2011 Apple Inc. All rights reserved.
4  * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
5  * Copyright (C) 2008 Collabora Ltd. All rights reserved.
6  *
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
19  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
22  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26  * 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 #ifndef FrameLoaderClientQt_h
31 #define FrameLoaderClientQt_h
32 
33 
34 #include "Frame.h"
35 #include "FrameLoader.h"
36 #include "FrameLoaderClient.h"
37 #include "KURL.h"
38 #include <wtf/OwnPtr.h>
39 #include "PluginView.h"
40 #include "RefCounted.h"
41 #include "ResourceError.h"
42 #include "ResourceResponse.h"
43 #include <QUrl>
44 #include <qobject.h>
45 #include <wtf/Forward.h>
46 class QWebFrame;
47 
48 namespace WebCore {
49 
50 class AuthenticationChallenge;
51 class DocumentLoader;
52 class Element;
53 class FormState;
54 class NavigationAction;
55 class FrameNetworkingContext;
56 class ResourceLoader;
57 
58 struct LoadErrorResetToken;
59 
60 class FrameLoaderClientQt : public QObject, public FrameLoaderClient {
61     Q_OBJECT
62 
63     friend class ::QWebFrame;
64     void callPolicyFunction(FramePolicyFunction function, PolicyAction action);
65     void callErrorPageExtension(const ResourceError&);
66 signals:
67     void loadStarted();
68     void loadProgress(int d);
69     void loadFinished(bool);
70     void titleChanged(const QString& title);
71 
72 public:
73     FrameLoaderClientQt();
74     ~FrameLoaderClientQt();
75     virtual void frameLoaderDestroyed();
76 
77     void setFrame(QWebFrame* webFrame, Frame* frame);
78 
79     virtual bool hasWebView() const; // mainly for assertions
80 
81     virtual void makeRepresentation(DocumentLoader*);
82     virtual void forceLayout();
83     virtual void forceLayoutForNonHTML();
84 
85     virtual void setCopiesOnScroll();
86 
87     virtual void detachedFromParent2();
88     virtual void detachedFromParent3();
89 
90     virtual void assignIdentifierToInitialRequest(unsigned long identifier, WebCore::DocumentLoader*, const WebCore::ResourceRequest&);
91 
92     virtual void dispatchWillSendRequest(WebCore::DocumentLoader*, unsigned long, WebCore::ResourceRequest&, const WebCore::ResourceResponse&);
93     virtual bool shouldUseCredentialStorage(DocumentLoader*, unsigned long identifier);
94     virtual void dispatchDidReceiveAuthenticationChallenge(DocumentLoader*, unsigned long identifier, const AuthenticationChallenge&);
95     virtual void dispatchDidCancelAuthenticationChallenge(DocumentLoader*, unsigned long identifier, const AuthenticationChallenge&);
96     virtual void dispatchDidReceiveResponse(WebCore::DocumentLoader*, unsigned long, const WebCore::ResourceResponse&);
97     virtual void dispatchDidReceiveContentLength(WebCore::DocumentLoader*, unsigned long, int);
98     virtual void dispatchDidFinishLoading(WebCore::DocumentLoader*, unsigned long);
99     virtual void dispatchDidFailLoading(WebCore::DocumentLoader*, unsigned long, const WebCore::ResourceError&);
100     virtual bool dispatchDidLoadResourceFromMemoryCache(WebCore::DocumentLoader*, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&, int);
101 
102     virtual void dispatchDidHandleOnloadEvents();
103     virtual void dispatchDidReceiveServerRedirectForProvisionalLoad();
104     virtual void dispatchDidCancelClientRedirect();
105     virtual void dispatchWillPerformClientRedirect(const KURL&, double interval, double fireDate);
106     virtual void dispatchDidChangeLocationWithinPage();
107     virtual void dispatchDidPushStateWithinPage();
108     virtual void dispatchDidReplaceStateWithinPage();
109     virtual void dispatchDidPopStateWithinPage();
110     virtual void dispatchWillClose();
111     virtual void dispatchDidReceiveIcon();
112     virtual void dispatchDidStartProvisionalLoad();
113     virtual void dispatchDidReceiveTitle(const StringWithDirection&);
114     virtual void dispatchDidChangeIcons();
115     virtual void dispatchDidCommitLoad();
116     virtual void dispatchDidFailProvisionalLoad(const ResourceError&);
117     virtual void dispatchDidFailLoad(const WebCore::ResourceError&);
118     virtual void dispatchDidFinishDocumentLoad();
119     virtual void dispatchDidFinishLoad();
120     virtual void dispatchDidFirstLayout();
121     virtual void dispatchDidFirstVisuallyNonEmptyLayout();
122 
123     virtual WebCore::Frame* dispatchCreatePage(const WebCore::NavigationAction&);
124     virtual void dispatchShow();
125 
126     virtual void dispatchDecidePolicyForResponse(FramePolicyFunction function, const WebCore::ResourceResponse&, const WebCore::ResourceRequest&);
127     virtual void dispatchDecidePolicyForNewWindowAction(FramePolicyFunction function, const WebCore::NavigationAction&, const WebCore::ResourceRequest&, PassRefPtr<FormState>, const WTF::String&);
128     virtual void dispatchDecidePolicyForNavigationAction(FramePolicyFunction function, const WebCore::NavigationAction&, const WebCore::ResourceRequest&, PassRefPtr<FormState>);
129     virtual void cancelPolicyCheck();
130 
131     virtual void dispatchUnableToImplementPolicy(const WebCore::ResourceError&);
132 
dispatchWillSendSubmitEvent(HTMLFormElement *)133     virtual void dispatchWillSendSubmitEvent(HTMLFormElement*) { }
134     virtual void dispatchWillSubmitForm(FramePolicyFunction, PassRefPtr<FormState>);
135 
136     virtual void dispatchDidLoadMainResource(DocumentLoader*);
137     virtual void revertToProvisionalState(DocumentLoader*);
138     virtual void setMainDocumentError(DocumentLoader*, const ResourceError&);
139 
140     virtual void postProgressStartedNotification();
141     virtual void postProgressEstimateChangedNotification();
142     virtual void postProgressFinishedNotification();
143 
144     virtual void setMainFrameDocumentReady(bool);
145 
146     virtual void startDownload(const WebCore::ResourceRequest&);
147 
148     virtual void willChangeTitle(DocumentLoader*);
149     virtual void didChangeTitle(DocumentLoader*);
150 
151     virtual void committedLoad(WebCore::DocumentLoader*, const char*, int);
152     virtual void finishedLoading(DocumentLoader*);
153 
154     virtual void updateGlobalHistory();
155     virtual void updateGlobalHistoryRedirectLinks();
156     virtual bool shouldGoToHistoryItem(HistoryItem*) const;
157     virtual bool shouldStopLoadingForHistoryItem(HistoryItem*) const;
158     virtual void dispatchDidAddBackForwardItem(HistoryItem*) const;
159     virtual void dispatchDidRemoveBackForwardItem(HistoryItem*) const;
160     virtual void dispatchDidChangeBackForwardIndex() const;
161     virtual void didDisplayInsecureContent();
162     virtual void didRunInsecureContent(SecurityOrigin*, const KURL&);
163 
164     virtual ResourceError cancelledError(const ResourceRequest&);
165     virtual ResourceError blockedError(const ResourceRequest&);
166     virtual ResourceError cannotShowURLError(const ResourceRequest&);
167     virtual ResourceError interruptForPolicyChangeError(const ResourceRequest&);
168 
169     virtual ResourceError cannotShowMIMETypeError(const ResourceResponse&);
170     virtual ResourceError fileDoesNotExistError(const ResourceResponse&);
171     virtual ResourceError pluginWillHandleLoadError(const ResourceResponse&);
172 
173     virtual bool shouldFallBack(const ResourceError&);
174 
175     virtual bool canHandleRequest(const WebCore::ResourceRequest&) const;
176     virtual bool canShowMIMEType(const String& MIMEType) const;
177     virtual bool canShowMIMETypeAsHTML(const String& MIMEType) const;
178     virtual bool representationExistsForURLScheme(const String& URLScheme) const;
179     virtual String generatedMIMETypeForURLScheme(const String& URLScheme) const;
180 
181     virtual void frameLoadCompleted();
182     virtual void saveViewStateToItem(WebCore::HistoryItem*);
183     virtual void restoreViewState();
184     virtual void provisionalLoadStarted();
185     virtual void didFinishLoad();
186     virtual void prepareForDataSourceReplacement();
187 
188     virtual WTF::PassRefPtr<WebCore::DocumentLoader> createDocumentLoader(const WebCore::ResourceRequest&, const WebCore::SubstituteData&);
189     virtual void setTitle(const StringWithDirection&, const KURL&);
190 
191     virtual String userAgent(const WebCore::KURL&);
192 
193     virtual void savePlatformDataToCachedFrame(WebCore::CachedFrame*);
194     virtual void transitionToCommittedFromCachedFrame(WebCore::CachedFrame*);
195     virtual void transitionToCommittedForNewPage();
196 
197     virtual void didSaveToPageCache();
198     virtual void didRestoreFromPageCache();
199 
200     virtual void dispatchDidBecomeFrameset(bool);
201 
202     virtual bool canCachePage() const;
203     virtual void download(WebCore::ResourceHandle*, const WebCore::ResourceRequest&, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&);
204 
205     virtual PassRefPtr<Frame> createFrame(const KURL& url, const String& name, HTMLFrameOwnerElement* ownerElement,
206                                const String& referrer, bool allowsScrolling, int marginWidth, int marginHeight);
207     virtual void didTransferChildFrameToNewDocument(WebCore::Page*);
208     virtual void transferLoadingResourceFromPage(unsigned long, WebCore::DocumentLoader*, const WebCore::ResourceRequest&, WebCore::Page*);
209     virtual PassRefPtr<Widget> createPlugin(const IntSize&, HTMLPlugInElement*, const KURL&, const Vector<String>&, const Vector<String>&, const String&, bool);
210     virtual void redirectDataToPlugin(Widget* pluginWidget);
211 
212     virtual PassRefPtr<Widget> createJavaAppletWidget(const IntSize&, HTMLAppletElement*, const KURL& baseURL, const Vector<String>& paramNames, const Vector<String>& paramValues);
213 
214     virtual ObjectContentType objectContentType(const KURL&, const String& mimeTypeIn, bool shouldPreferPlugInsForImages);
215     virtual String overrideMediaType() const;
216 
217     virtual void dispatchDidClearWindowObjectInWorld(DOMWrapperWorld*);
218     virtual void documentElementAvailable();
219     virtual void didPerformFirstNavigation() const;
220 
221 #if USE(V8)
222     // A frame's V8 context was created or destroyed.
223     virtual void didCreateScriptContextForFrame();
224     virtual void didDestroyScriptContextForFrame();
225 
226     // A context untied to a frame was created (through evaluateInIsolatedWorld).
227     // This context is not tied to the lifetime of its frame, and is destroyed
228     // in garbage collection.
229     virtual void didCreateIsolatedScriptContext();
230 
231     // Returns true if we should allow the given V8 extension to be added to
232     // the script context at the currently loading page and given extension group.
allowScriptExtension(const String & extensionName,int extensionGroup)233     virtual bool allowScriptExtension(const String& extensionName, int extensionGroup) { return false; }
234 #endif
235 
236     virtual void registerForIconNotification(bool);
237 
238     QString chooseFile(const QString& oldFile);
239 
240     virtual PassRefPtr<FrameNetworkingContext> createNetworkingContext();
241 
lastRequestedUrl()242     const KURL& lastRequestedUrl() const { return m_lastRequestedUrl; }
243 
244     static bool dumpFrameLoaderCallbacks;
245     static bool dumpUserGestureInFrameLoaderCallbacks;
246     static bool dumpResourceLoadCallbacks;
247     static bool dumpResourceResponseMIMETypes;
248     static QString dumpResourceLoadCallbacksPath;
249     static bool sendRequestReturnsNullOnRedirect;
250     static bool sendRequestReturnsNull;
251     static QStringList sendRequestClearHeaders;
252     static bool policyDelegateEnabled;
253     static bool policyDelegatePermissive;
254     static bool deferMainResourceDataLoad;
255     static bool dumpHistoryCallbacks;
256     static QMap<QString, QString> URLsToRedirect;
257 
258 private slots:
259     void onIconLoadedForPageURL(const QString&);
260 
261 private:
262     Frame *m_frame;
263     QWebFrame *m_webFrame;
264     ResourceResponse m_response;
265 
266     // Plugin view to redirect data to
267     WebCore::PluginView* m_pluginView;
268     bool m_hasSentResponseToPlugin;
269 
270     // True if makeRepresentation was called.  We don't actually have a concept
271     // of a "representation", but we need to know when we're expected to have one.
272     // See finishedLoading().
273     bool m_hasRepresentation;
274 
275     KURL m_lastRequestedUrl;
276     ResourceError m_loadError;
277 };
278 
279 }
280 
281 #endif
282