Move URL from WebCore to WTF
[WebKit-https.git] / Source / WebKitLegacy / mac / WebCoreSupport / WebFrameLoaderClient.h
1 /*
2  * Copyright (C) 2006-2017 Apple 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
6  * are met:
7  *
8  * 1.  Redistributions of source code must retain the above copyright
9  *     notice, this list of conditions and the following disclaimer. 
10  * 2.  Redistributions in binary form must reproduce the above copyright
11  *     notice, this list of conditions and the following disclaimer in the
12  *     documentation and/or other materials provided with the distribution. 
13  * 3.  Neither the name of Apple Inc. ("Apple") nor the names of
14  *     its contributors may be used to endorse or promote products derived
15  *     from this software without specific prior written permission. 
16  *
17  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28
29 #import <WebCore/FrameLoaderClient.h>
30 #import <WebCore/Timer.h>
31 #import <wtf/Forward.h>
32 #import <wtf/HashMap.h>
33 #import <wtf/RetainPtr.h>
34 #import <wtf/WeakObjCPtr.h>
35
36 @class WebDownload;
37 @class WebFrame;
38 @class WebFramePolicyListener;
39 @class WebHistoryItem;
40 @class WebResource;
41
42 namespace PAL {
43 class SessionID;
44 }
45
46 namespace WebCore {
47 class AuthenticationChallenge;
48 class CachedFrame;
49 class HistoryItem;
50 class ProtectionSpace;
51 class ResourceLoader;
52 class ResourceRequest;
53 }
54
55 class WebFrameLoaderClient : public WebCore::FrameLoaderClient {
56 public:
57     WebFrameLoaderClient(WebFrame* = 0);
58
59     void setWebFrame(WebFrame* webFrame) { m_webFrame = webFrame; }
60     WebFrame* webFrame() const { return m_webFrame.get(); }
61
62 private:
63     void frameLoaderDestroyed() final;
64     bool hasWebView() const final; // mainly for assertions
65
66     std::optional<uint64_t> pageID() const final;
67     std::optional<uint64_t> frameID() const final;
68     PAL::SessionID sessionID() const final;
69
70     void makeRepresentation(WebCore::DocumentLoader*) final;
71     bool hasHTMLView() const final;
72 #if PLATFORM(IOS_FAMILY)
73     bool forceLayoutOnRestoreFromPageCache() final;
74 #endif
75     void forceLayoutForNonHTML() final;
76
77     void setCopiesOnScroll() final;
78
79     void detachedFromParent2() final;
80     void detachedFromParent3() final;
81
82     void convertMainResourceLoadToDownload(WebCore::DocumentLoader*, PAL::SessionID, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&) final;
83
84     void assignIdentifierToInitialRequest(unsigned long identifier, WebCore::DocumentLoader*, const WebCore::ResourceRequest&) final;
85
86     void dispatchWillSendRequest(WebCore::DocumentLoader*, unsigned long identifier, WebCore::ResourceRequest&, const WebCore::ResourceResponse& redirectResponse) final;
87     bool shouldUseCredentialStorage(WebCore::DocumentLoader*, unsigned long identifier) final;
88     void dispatchDidReceiveAuthenticationChallenge(WebCore::DocumentLoader*, unsigned long identifier, const WebCore::AuthenticationChallenge&) final;
89 #if USE(PROTECTION_SPACE_AUTH_CALLBACK)
90     bool canAuthenticateAgainstProtectionSpace(WebCore::DocumentLoader*, unsigned long identifier, const WebCore::ProtectionSpace&) final;
91 #endif
92
93 #if PLATFORM(IOS_FAMILY)
94     RetainPtr<CFDictionaryRef> connectionProperties(WebCore::DocumentLoader*, unsigned long identifier) final;
95 #endif
96
97     void dispatchDidReceiveResponse(WebCore::DocumentLoader*, unsigned long identifier, const WebCore::ResourceResponse&) final;
98     void dispatchDidReceiveContentLength(WebCore::DocumentLoader*, unsigned long identifier, int dataLength) final;
99     void dispatchDidFinishLoading(WebCore::DocumentLoader*, unsigned long identifier) final;
100 #if ENABLE(DATA_DETECTION)
101     void dispatchDidFinishDataDetection(NSArray *detectionResults) final;
102 #endif
103     void dispatchDidFailLoading(WebCore::DocumentLoader*, unsigned long identifier, const WebCore::ResourceError&) final;
104
105     void willCacheResponse(WebCore::DocumentLoader*, unsigned long identifier, NSCachedURLResponse*, CompletionHandler<void(NSCachedURLResponse *)>&&) const final;
106
107     void dispatchDidDispatchOnloadEvents() final;
108     void dispatchDidReceiveServerRedirectForProvisionalLoad() final;
109     void dispatchDidCancelClientRedirect() final;
110     void dispatchWillPerformClientRedirect(const URL&, double interval, WallTime fireDate, WebCore::LockBackForwardList) final;
111     void dispatchDidChangeLocationWithinPage() final;
112     void dispatchDidPushStateWithinPage() final;
113     void dispatchDidReplaceStateWithinPage() final;
114     void dispatchDidPopStateWithinPage() final;
115     
116     void dispatchWillClose() final;
117     void dispatchDidStartProvisionalLoad() final;
118     void dispatchDidReceiveTitle(const WebCore::StringWithDirection&) final;
119     void dispatchDidCommitLoad(std::optional<WebCore::HasInsecureContent>) final;
120     void dispatchDidFailProvisionalLoad(const WebCore::ResourceError&) final;
121     void dispatchDidFailLoad(const WebCore::ResourceError&) final;
122     void dispatchDidFinishDocumentLoad() final;
123     void dispatchDidFinishLoad() final;
124     void dispatchDidReachLayoutMilestone(OptionSet<WebCore::LayoutMilestone>) final;
125
126     WebCore::Frame* dispatchCreatePage(const WebCore::NavigationAction&) final;
127     void dispatchShow() final;
128
129     void dispatchDecidePolicyForResponse(const WebCore::ResourceResponse&, const WebCore::ResourceRequest&, WebCore::FramePolicyFunction&&) final;
130     void dispatchDecidePolicyForNewWindowAction(const WebCore::NavigationAction&, const WebCore::ResourceRequest&, WebCore::FormState*, const WTF::String& frameName, WebCore::FramePolicyFunction&&) final;
131     void dispatchDecidePolicyForNavigationAction(const WebCore::NavigationAction&, const WebCore::ResourceRequest&, const WebCore::ResourceResponse& redirectResponse, WebCore::FormState*, WebCore::PolicyDecisionMode, WebCore::FramePolicyFunction&&) final;
132     void cancelPolicyCheck() final;
133
134     void dispatchUnableToImplementPolicy(const WebCore::ResourceError&) final;
135
136     void dispatchWillSendSubmitEvent(Ref<WebCore::FormState>&&) final;
137     void dispatchWillSubmitForm(WebCore::FormState&, CompletionHandler<void()>&&) final;
138
139     void revertToProvisionalState(WebCore::DocumentLoader*) final;
140     void setMainDocumentError(WebCore::DocumentLoader*, const WebCore::ResourceError&) final;
141     bool dispatchDidLoadResourceFromMemoryCache(WebCore::DocumentLoader*, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&, int length) final;
142
143     void setMainFrameDocumentReady(bool) final;
144
145     void startDownload(const WebCore::ResourceRequest&, const String& suggestedName = String()) final;
146
147     void willChangeTitle(WebCore::DocumentLoader*) final;
148     void didChangeTitle(WebCore::DocumentLoader*) final;
149
150     void willReplaceMultipartContent() final { }
151     void didReplaceMultipartContent() final;
152
153     void committedLoad(WebCore::DocumentLoader*, const char*, int) final;
154     void finishedLoading(WebCore::DocumentLoader*) final;
155     void updateGlobalHistory() final;
156     void updateGlobalHistoryRedirectLinks() final;
157
158     bool shouldGoToHistoryItem(WebCore::HistoryItem&) const final;
159
160     void didDisplayInsecureContent() final;
161     void didRunInsecureContent(WebCore::SecurityOrigin&, const URL&) final;
162     void didDetectXSS(const URL&, bool didBlockEntirePage) final;
163
164     WebCore::ResourceError cancelledError(const WebCore::ResourceRequest&) final;
165     WebCore::ResourceError blockedError(const WebCore::ResourceRequest&) final;
166     WebCore::ResourceError blockedByContentBlockerError(const WebCore::ResourceRequest&) final;
167     WebCore::ResourceError cannotShowURLError(const WebCore::ResourceRequest&) final;
168     WebCore::ResourceError interruptedForPolicyChangeError(const WebCore::ResourceRequest&) final;
169 #if ENABLE(CONTENT_FILTERING)
170     WebCore::ResourceError blockedByContentFilterError(const WebCore::ResourceRequest&) final;
171 #endif
172
173     WebCore::ResourceError cannotShowMIMETypeError(const WebCore::ResourceResponse&) final;
174     WebCore::ResourceError fileDoesNotExistError(const WebCore::ResourceResponse&) final;
175     WebCore::ResourceError pluginWillHandleLoadError(const WebCore::ResourceResponse&) final;
176
177     bool shouldFallBack(const WebCore::ResourceError&) final;
178
179     WTF::String userAgent(const URL&) final;
180     
181     void savePlatformDataToCachedFrame(WebCore::CachedFrame*) final;
182     void transitionToCommittedFromCachedFrame(WebCore::CachedFrame*) final;
183 #if PLATFORM(IOS_FAMILY)
184     void didRestoreFrameHierarchyForCachedFrame() final;
185 #endif
186     void transitionToCommittedForNewPage() final;
187
188     void didSaveToPageCache() final;
189     void didRestoreFromPageCache() final;
190
191     void dispatchDidBecomeFrameset(bool) final;
192
193     bool canHandleRequest(const WebCore::ResourceRequest&) const final;
194     bool canShowMIMEType(const WTF::String& MIMEType) const final;
195     bool canShowMIMETypeAsHTML(const WTF::String& MIMEType) const final;
196     bool representationExistsForURLScheme(const WTF::String& URLScheme) const final;
197     WTF::String generatedMIMETypeForURLScheme(const WTF::String& URLScheme) const final;
198
199     void frameLoadCompleted() final;
200     void saveViewStateToItem(WebCore::HistoryItem&) final;
201     void restoreViewState() final;
202     void provisionalLoadStarted() final;
203     void didFinishLoad() final;
204     void prepareForDataSourceReplacement() final;
205     Ref<WebCore::DocumentLoader> createDocumentLoader(const WebCore::ResourceRequest&, const WebCore::SubstituteData&) final;
206     void updateCachedDocumentLoader(WebCore::DocumentLoader&) final { }
207
208     void setTitle(const WebCore::StringWithDirection&, const URL&) final;
209
210     RefPtr<WebCore::Frame> createFrame(const URL&, const WTF::String& name, WebCore::HTMLFrameOwnerElement&,
211         const WTF::String& referrer) final;
212     RefPtr<WebCore::Widget> createPlugin(const WebCore::IntSize&, WebCore::HTMLPlugInElement&, const URL&,
213     const Vector<WTF::String>&, const Vector<WTF::String>&, const WTF::String&, bool) final;
214     void recreatePlugin(WebCore::Widget*) final;
215     void redirectDataToPlugin(WebCore::Widget&) final;
216
217 #if ENABLE(WEBGL)
218     WebCore::WebGLLoadPolicy webGLPolicyForURL(const URL&) const final;
219     WebCore::WebGLLoadPolicy resolveWebGLPolicyForURL(const URL&) const final;
220 #endif
221
222     RefPtr<WebCore::Widget> createJavaAppletWidget(const WebCore::IntSize&, WebCore::HTMLAppletElement&, const URL& baseURL,
223         const Vector<WTF::String>& paramNames, const Vector<WTF::String>& paramValues) final;
224     
225     WebCore::ObjectContentType objectContentType(const URL&, const WTF::String& mimeType) final;
226     WTF::String overrideMediaType() const final;
227     
228     void dispatchDidClearWindowObjectInWorld(WebCore::DOMWrapperWorld&) final;
229
230 #if PLATFORM(IOS_FAMILY)
231     bool shouldLoadMediaElementURL(const URL&) const final;
232 #endif
233
234     RemoteAXObjectRef accessibilityRemoteObject() final { return 0; }
235     
236     RetainPtr<WebFramePolicyListener> setUpPolicyListener(WebCore::FramePolicyFunction&&, WebCore::PolicyAction defaultPolicy, NSURL *appLinkURL = nil);
237
238     NSDictionary *actionDictionary(const WebCore::NavigationAction&, WebCore::FormState*) const;
239     
240     bool canCachePage() const final;
241
242     Ref<WebCore::FrameNetworkingContext> createNetworkingContext() final;
243
244     bool shouldPaintBrokenImage(const URL&) const final;
245
246 #if USE(QUICK_LOOK)
247     RefPtr<WebCore::PreviewLoaderClient> createPreviewLoaderClient(const String& fileName, const String& uti) final;
248 #endif
249
250 #if ENABLE(CONTENT_FILTERING)
251     void contentFilterDidBlockLoad(WebCore::ContentFilterUnblockHandler) final;
252 #endif
253
254     void prefetchDNS(const String&) final;
255
256     void getLoadDecisionForIcons(const Vector<std::pair<WebCore::LinkIcon&, uint64_t>>&) final;
257     void finishedLoadingIcon(uint64_t, WebCore::SharedBuffer*) final;
258
259     uint64_t m_activeIconLoadCallbackID { 0 };
260
261     RetainPtr<WebFrame> m_webFrame;
262
263     WeakObjCPtr<WebFramePolicyListener> m_policyListener;
264 };