b4ee9e606c57fcf572e1138639bc14534f378906
[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     Optional<WebCore::PageIdentifier> pageID() const final;
67     Optional<WebCore::FrameIdentifier> frameID() const final;
68
69     void makeRepresentation(WebCore::DocumentLoader*) final;
70     bool hasHTMLView() const final;
71 #if PLATFORM(IOS_FAMILY)
72     bool forceLayoutOnRestoreFromBackForwardCache() final;
73 #endif
74     void forceLayoutForNonHTML() final;
75
76     void setCopiesOnScroll() final;
77
78     void detachedFromParent2() final;
79     void detachedFromParent3() final;
80
81     void convertMainResourceLoadToDownload(WebCore::DocumentLoader*, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&) final;
82
83     void assignIdentifierToInitialRequest(unsigned long identifier, WebCore::DocumentLoader*, const WebCore::ResourceRequest&) final;
84
85     void dispatchWillSendRequest(WebCore::DocumentLoader*, unsigned long identifier, WebCore::ResourceRequest&, const WebCore::ResourceResponse& redirectResponse) final;
86     bool shouldUseCredentialStorage(WebCore::DocumentLoader*, unsigned long identifier) final;
87     void dispatchDidReceiveAuthenticationChallenge(WebCore::DocumentLoader*, unsigned long identifier, const WebCore::AuthenticationChallenge&) final;
88 #if USE(PROTECTION_SPACE_AUTH_CALLBACK)
89     bool canAuthenticateAgainstProtectionSpace(WebCore::DocumentLoader*, unsigned long identifier, const WebCore::ProtectionSpace&) final;
90 #endif
91
92 #if PLATFORM(IOS_FAMILY)
93     RetainPtr<CFDictionaryRef> connectionProperties(WebCore::DocumentLoader*, unsigned long identifier) final;
94 #endif
95
96     void dispatchDidReceiveResponse(WebCore::DocumentLoader*, unsigned long identifier, const WebCore::ResourceResponse&) final;
97     void dispatchDidReceiveContentLength(WebCore::DocumentLoader*, unsigned long identifier, int dataLength) final;
98     void dispatchDidFinishLoading(WebCore::DocumentLoader*, unsigned long identifier) final;
99 #if ENABLE(DATA_DETECTION)
100     void dispatchDidFinishDataDetection(NSArray *detectionResults) final;
101 #endif
102     void dispatchDidFailLoading(WebCore::DocumentLoader*, unsigned long identifier, const WebCore::ResourceError&) final;
103
104     void willCacheResponse(WebCore::DocumentLoader*, unsigned long identifier, NSCachedURLResponse*, CompletionHandler<void(NSCachedURLResponse *)>&&) const final;
105
106     void dispatchDidDispatchOnloadEvents() final;
107     void dispatchDidReceiveServerRedirectForProvisionalLoad() final;
108     void dispatchDidCancelClientRedirect() final;
109     void dispatchWillPerformClientRedirect(const URL&, double interval, WallTime fireDate, WebCore::LockBackForwardList) final;
110     void dispatchDidChangeLocationWithinPage() final;
111     void dispatchDidPushStateWithinPage() final;
112     void dispatchDidReplaceStateWithinPage() final;
113     void dispatchDidPopStateWithinPage() final;
114     
115     void dispatchWillClose() final;
116     void dispatchDidStartProvisionalLoad() final;
117     void dispatchDidReceiveTitle(const WebCore::StringWithDirection&) final;
118     void dispatchDidCommitLoad(Optional<WebCore::HasInsecureContent>) final;
119     void dispatchDidFailProvisionalLoad(const WebCore::ResourceError&, WebCore::WillContinueLoading) final;
120     void dispatchDidFailLoad(const WebCore::ResourceError&) final;
121     void dispatchDidFinishDocumentLoad() final;
122     void dispatchDidFinishLoad() final;
123     void dispatchDidReachLayoutMilestone(OptionSet<WebCore::LayoutMilestone>) final;
124
125     WebCore::Frame* dispatchCreatePage(const WebCore::NavigationAction&) final;
126     void dispatchShow() final;
127
128     void dispatchDecidePolicyForResponse(const WebCore::ResourceResponse&, const WebCore::ResourceRequest&, WebCore::PolicyCheckIdentifier, const String&,  WebCore::FramePolicyFunction&&) final;
129     void dispatchDecidePolicyForNewWindowAction(const WebCore::NavigationAction&, const WebCore::ResourceRequest&, WebCore::FormState*, const WTF::String& frameName, WebCore::PolicyCheckIdentifier, WebCore::FramePolicyFunction&&) final;
130     void dispatchDecidePolicyForNavigationAction(const WebCore::NavigationAction&, const WebCore::ResourceRequest&, const WebCore::ResourceResponse& redirectResponse, WebCore::FormState*, WebCore::PolicyDecisionMode, WebCore::PolicyCheckIdentifier, WebCore::FramePolicyFunction&&) final;
131     void cancelPolicyCheck() final;
132
133     void dispatchUnableToImplementPolicy(const WebCore::ResourceError&) final;
134
135     void dispatchWillSendSubmitEvent(Ref<WebCore::FormState>&&) final;
136     void dispatchWillSubmitForm(WebCore::FormState&, CompletionHandler<void()>&&) final;
137
138     void revertToProvisionalState(WebCore::DocumentLoader*) final;
139     void setMainDocumentError(WebCore::DocumentLoader*, const WebCore::ResourceError&) final;
140     bool dispatchDidLoadResourceFromMemoryCache(WebCore::DocumentLoader*, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&, int length) final;
141
142     void setMainFrameDocumentReady(bool) final;
143
144     void startDownload(const WebCore::ResourceRequest&, const String& suggestedName = String()) final;
145
146     void willChangeTitle(WebCore::DocumentLoader*) final;
147     void didChangeTitle(WebCore::DocumentLoader*) final;
148
149     void willReplaceMultipartContent() final { }
150     void didReplaceMultipartContent() final;
151
152     void committedLoad(WebCore::DocumentLoader*, const char*, int) final;
153     void finishedLoading(WebCore::DocumentLoader*) final;
154     void updateGlobalHistory() final;
155     void updateGlobalHistoryRedirectLinks() final;
156
157     bool shouldGoToHistoryItem(WebCore::HistoryItem&) const final;
158
159     void didDisplayInsecureContent() final;
160     void didRunInsecureContent(WebCore::SecurityOrigin&, const URL&) final;
161     void didDetectXSS(const URL&, bool didBlockEntirePage) final;
162
163     WebCore::ResourceError cancelledError(const WebCore::ResourceRequest&) final;
164     WebCore::ResourceError blockedError(const WebCore::ResourceRequest&) final;
165     WebCore::ResourceError blockedByContentBlockerError(const WebCore::ResourceRequest&) final;
166     WebCore::ResourceError cannotShowURLError(const WebCore::ResourceRequest&) final;
167     WebCore::ResourceError interruptedForPolicyChangeError(const WebCore::ResourceRequest&) final;
168 #if ENABLE(CONTENT_FILTERING)
169     WebCore::ResourceError blockedByContentFilterError(const WebCore::ResourceRequest&) final;
170 #endif
171
172     WebCore::ResourceError cannotShowMIMETypeError(const WebCore::ResourceResponse&) final;
173     WebCore::ResourceError fileDoesNotExistError(const WebCore::ResourceResponse&) final;
174     WebCore::ResourceError pluginWillHandleLoadError(const WebCore::ResourceResponse&) final;
175
176     bool shouldFallBack(const WebCore::ResourceError&) final;
177
178     WTF::String userAgent(const URL&) final;
179     
180     void savePlatformDataToCachedFrame(WebCore::CachedFrame*) final;
181     void transitionToCommittedFromCachedFrame(WebCore::CachedFrame*) final;
182 #if PLATFORM(IOS_FAMILY)
183     void didRestoreFrameHierarchyForCachedFrame() final;
184 #endif
185     void transitionToCommittedForNewPage() final;
186
187     void didRestoreFromBackForwardCache() final;
188
189     void dispatchDidBecomeFrameset(bool) final;
190
191     bool canHandleRequest(const WebCore::ResourceRequest&) const final;
192     bool canShowMIMEType(const WTF::String& MIMEType) const final;
193     bool canShowMIMETypeAsHTML(const WTF::String& MIMEType) const final;
194     bool representationExistsForURLScheme(const WTF::String& URLScheme) const final;
195     WTF::String generatedMIMETypeForURLScheme(const WTF::String& URLScheme) const final;
196
197     void frameLoadCompleted() final;
198     void saveViewStateToItem(WebCore::HistoryItem&) final;
199     void restoreViewState() final;
200     void provisionalLoadStarted() final;
201     void didFinishLoad() final;
202     void prepareForDataSourceReplacement() final;
203     Ref<WebCore::DocumentLoader> createDocumentLoader(const WebCore::ResourceRequest&, const WebCore::SubstituteData&) final;
204     void updateCachedDocumentLoader(WebCore::DocumentLoader&) final { }
205
206     void setTitle(const WebCore::StringWithDirection&, const URL&) final;
207
208     RefPtr<WebCore::Frame> createFrame(const URL&, const WTF::String& name, WebCore::HTMLFrameOwnerElement&,
209         const WTF::String& referrer) final;
210     RefPtr<WebCore::Widget> createPlugin(const WebCore::IntSize&, WebCore::HTMLPlugInElement&, const URL&,
211     const Vector<WTF::String>&, const Vector<WTF::String>&, const WTF::String&, bool) final;
212     void redirectDataToPlugin(WebCore::Widget&) final;
213
214 #if ENABLE(WEBGL)
215     WebCore::WebGLLoadPolicy webGLPolicyForURL(const URL&) const final;
216     WebCore::WebGLLoadPolicy resolveWebGLPolicyForURL(const URL&) const final;
217 #endif
218
219     RefPtr<WebCore::Widget> createJavaAppletWidget(const WebCore::IntSize&, WebCore::HTMLAppletElement&, const URL& baseURL,
220         const Vector<WTF::String>& paramNames, const Vector<WTF::String>& paramValues) final;
221     
222     WebCore::ObjectContentType objectContentType(const URL&, const WTF::String& mimeType) final;
223     WTF::String overrideMediaType() const final;
224     
225     void dispatchDidClearWindowObjectInWorld(WebCore::DOMWrapperWorld&) final;
226
227 #if PLATFORM(IOS_FAMILY)
228     bool shouldLoadMediaElementURL(const URL&) const final;
229 #endif
230
231     RemoteAXObjectRef accessibilityRemoteObject() final { return 0; }
232     
233     RetainPtr<WebFramePolicyListener> setUpPolicyListener(WebCore::PolicyCheckIdentifier, WebCore::FramePolicyFunction&&, WebCore::PolicyAction defaultPolicy, NSURL *appLinkURL = nil);
234
235     NSDictionary *actionDictionary(const WebCore::NavigationAction&, WebCore::FormState*) const;
236     
237     bool canCachePage() const final;
238
239     Ref<WebCore::FrameNetworkingContext> createNetworkingContext() final;
240
241     bool shouldPaintBrokenImage(const URL&) const final;
242
243 #if USE(QUICK_LOOK)
244     RefPtr<WebCore::PreviewLoaderClient> createPreviewLoaderClient(const String& fileName, const String& uti) final;
245 #endif
246
247 #if ENABLE(CONTENT_FILTERING)
248     void contentFilterDidBlockLoad(WebCore::ContentFilterUnblockHandler) final;
249 #endif
250
251     void prefetchDNS(const String&) final;
252
253     void getLoadDecisionForIcons(const Vector<std::pair<WebCore::LinkIcon&, uint64_t>>&) final;
254     void finishedLoadingIcon(uint64_t, WebCore::SharedBuffer*) final;
255
256     uint64_t m_activeIconLoadCallbackID { 0 };
257
258     RetainPtr<WebFrame> m_webFrame;
259
260     WeakObjCPtr<WebFramePolicyListener> m_policyListener;
261 };
262
263 WebDataSource *dataSource(WebCore::DocumentLoader*);
264 void addTypesFromClass(NSMutableDictionary *, Class, NSArray *);