611fcb86dbe63ad733b1201756a152ddcb9361c0
[WebKit-https.git] / Source / WebKit / WebProcess / WebCoreSupport / WebFrameLoaderClient.h
1 /*
2  * Copyright (C) 2010-2016 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  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #pragma once
27
28 #include "WebPageProxyIdentifier.h"
29 #include <WebCore/FrameLoaderClient.h>
30 #include <pal/SessionID.h>
31
32 namespace WebKit {
33
34 class PluginView;
35 class WebFrame;
36 struct WebsitePoliciesData;
37     
38 class WebFrameLoaderClient final : public WebCore::FrameLoaderClient {
39 public:
40     WebFrameLoaderClient();
41     ~WebFrameLoaderClient();
42
43     void setWebFrame(WebFrame* webFrame) { m_frame = webFrame; }
44     WebFrame* webFrame() const { return m_frame; }
45
46     bool frameHasCustomContentProvider() const { return m_frameHasCustomContentProvider; }
47
48     void setUseIconLoadingClient(bool useIconLoadingClient) { m_useIconLoadingClient = useIconLoadingClient; }
49
50     void applyToDocumentLoader(WebsitePoliciesData&&);
51
52     Optional<WebPageProxyIdentifier> webPageProxyID() const;
53     Optional<WebCore::PageIdentifier> pageID() const final;
54     Optional<WebCore::FrameIdentifier> frameID() const final;
55
56 #if ENABLE(RESOURCE_LOAD_STATISTICS)
57     bool hasFrameSpecificStorageAccess() final { return !!m_frameSpecificStorageAccessIdentifier; }
58     
59     struct FrameSpecificStorageAccessIdentifier {
60         WebCore::FrameIdentifier frameID;
61         WebCore::PageIdentifier pageID;
62     };
63     void setHasFrameSpecificStorageAccess(FrameSpecificStorageAccessIdentifier&&);
64 #endif
65     
66 private:
67     void frameLoaderDestroyed() final;
68
69     bool hasHTMLView() const final;
70     bool hasWebView() const final;
71     
72     void makeRepresentation(WebCore::DocumentLoader*) final;
73 #if PLATFORM(IOS_FAMILY)
74     bool forceLayoutOnRestoreFromBackForwardCache() final;
75 #endif
76     void forceLayoutForNonHTML() final;
77     
78     void setCopiesOnScroll() final;
79     
80     void detachedFromParent2() final;
81     void detachedFromParent3() 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 #if PLATFORM(IOS_FAMILY)
92     RetainPtr<CFDictionaryRef> connectionProperties(WebCore::DocumentLoader*, unsigned long identifier) final;
93 #endif
94     void dispatchDidReceiveResponse(WebCore::DocumentLoader*, unsigned long identifier, const WebCore::ResourceResponse&) final;
95     void dispatchDidReceiveContentLength(WebCore::DocumentLoader*, unsigned long identifier, int dataLength) final;
96     void dispatchDidFinishLoading(WebCore::DocumentLoader*, unsigned long identifier) final;
97     void dispatchDidFailLoading(WebCore::DocumentLoader*, unsigned long identifier, const WebCore::ResourceError&) final;
98     bool dispatchDidLoadResourceFromMemoryCache(WebCore::DocumentLoader*, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&, int length) final;
99 #if ENABLE(DATA_DETECTION)
100     void dispatchDidFinishDataDetection(NSArray *detectionResults) final;
101 #endif
102     void dispatchDidChangeMainDocument() final;
103     void dispatchWillChangeDocument(const URL& currentUrl, const URL& newUrl) final;
104
105     void dispatchDidDispatchOnloadEvents() final;
106     void dispatchDidReceiveServerRedirectForProvisionalLoad() final;
107     void dispatchDidChangeProvisionalURL() 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     void dispatchWillClose() final;
115     void dispatchDidStartProvisionalLoad() final;
116     void dispatchDidReceiveTitle(const WebCore::StringWithDirection&) final;
117     void dispatchDidCommitLoad(Optional<WebCore::HasInsecureContent>) final;
118     void dispatchDidFailProvisionalLoad(const WebCore::ResourceError&, WebCore::WillContinueLoading) final;
119     void dispatchDidFailLoad(const WebCore::ResourceError&) final;
120     void dispatchDidFinishDocumentLoad() final;
121     void dispatchDidFinishLoad() final;
122     void dispatchDidExplicitOpen(const URL&) final;
123
124     void dispatchDidReachLayoutMilestone(OptionSet<WebCore::LayoutMilestone>) final;
125     void dispatchDidLayout() final;
126
127     WebCore::Frame* dispatchCreatePage(const WebCore::NavigationAction&) final;
128     void dispatchShow() final;
129     
130     void dispatchDecidePolicyForResponse(const WebCore::ResourceResponse&, const WebCore::ResourceRequest&, WebCore::PolicyCheckIdentifier, const String&, WebCore::FramePolicyFunction&&) final;
131     void dispatchDecidePolicyForNewWindowAction(const WebCore::NavigationAction&, const WebCore::ResourceRequest&, WebCore::FormState*, const String& frameName, WebCore::PolicyCheckIdentifier, WebCore::FramePolicyFunction&&) final;
132     void dispatchDecidePolicyForNavigationAction(const WebCore::NavigationAction&, const WebCore::ResourceRequest&, const WebCore::ResourceResponse& redirectResponse, WebCore::FormState*, WebCore::PolicyDecisionMode, WebCore::PolicyCheckIdentifier, WebCore::FramePolicyFunction&&) final;
133     void cancelPolicyCheck() final;
134     
135     void dispatchUnableToImplementPolicy(const WebCore::ResourceError&) final;
136     
137     void dispatchWillSendSubmitEvent(Ref<WebCore::FormState>&&) final;
138     void dispatchWillSubmitForm(WebCore::FormState&, CompletionHandler<void()>&&) final;
139     
140     void revertToProvisionalState(WebCore::DocumentLoader*) final;
141     void setMainDocumentError(WebCore::DocumentLoader*, const WebCore::ResourceError&) 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     
156     void updateGlobalHistory() final;
157     void updateGlobalHistoryRedirectLinks() final;
158     
159     bool shouldGoToHistoryItem(WebCore::HistoryItem&) const final;
160
161     void didDisplayInsecureContent() final;
162     void didRunInsecureContent(WebCore::SecurityOrigin&, const URL&) final;
163     void didDetectXSS(const URL&, bool didBlockEntirePage) final;
164
165     WebCore::ResourceError cancelledError(const WebCore::ResourceRequest&) final;
166     WebCore::ResourceError blockedError(const WebCore::ResourceRequest&) final;
167     WebCore::ResourceError blockedByContentBlockerError(const WebCore::ResourceRequest&) final;
168     WebCore::ResourceError cannotShowURLError(const WebCore::ResourceRequest&) final;
169     WebCore::ResourceError interruptedForPolicyChangeError(const WebCore::ResourceRequest&) final;
170 #if ENABLE(CONTENT_FILTERING)
171     WebCore::ResourceError blockedByContentFilterError(const WebCore::ResourceRequest&) final;
172 #endif
173     
174     WebCore::ResourceError cannotShowMIMETypeError(const WebCore::ResourceResponse&) final;
175     WebCore::ResourceError fileDoesNotExistError(const WebCore::ResourceResponse&) final;
176     WebCore::ResourceError pluginWillHandleLoadError(const WebCore::ResourceResponse&) final;
177     
178     bool shouldFallBack(const WebCore::ResourceError&) final;
179     
180     bool canHandleRequest(const WebCore::ResourceRequest&) const final;
181     bool canShowMIMEType(const String& MIMEType) const final;
182     bool canShowMIMETypeAsHTML(const String& MIMEType) const final;
183     bool representationExistsForURLScheme(const String& URLScheme) const final;
184     String generatedMIMETypeForURLScheme(const String& URLScheme) const final;
185     
186     void frameLoadCompleted() final;
187     void saveViewStateToItem(WebCore::HistoryItem&) final;
188     void restoreViewState() final;
189     void provisionalLoadStarted() final;
190     void didFinishLoad() final;
191     void prepareForDataSourceReplacement() final;
192     
193     Ref<WebCore::DocumentLoader> createDocumentLoader(const WebCore::ResourceRequest&, const WebCore::SubstituteData&) final;
194     void updateCachedDocumentLoader(WebCore::DocumentLoader&) final;
195
196     void setTitle(const WebCore::StringWithDirection&, const URL&) final;
197     
198     String userAgent(const URL&) final;
199
200     String overrideContentSecurityPolicy() const final;
201
202     void savePlatformDataToCachedFrame(WebCore::CachedFrame*) final;
203     void transitionToCommittedFromCachedFrame(WebCore::CachedFrame*) final;
204 #if PLATFORM(IOS_FAMILY)
205     void didRestoreFrameHierarchyForCachedFrame() final;
206 #endif
207     void transitionToCommittedForNewPage() final;
208
209     void didRestoreFromBackForwardCache() final;
210
211     void dispatchDidBecomeFrameset(bool) final;
212
213     bool canCachePage() const final;
214     void convertMainResourceLoadToDownload(WebCore::DocumentLoader*, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&) final;
215
216     RefPtr<WebCore::Frame> createFrame(const URL&, const String& name, WebCore::HTMLFrameOwnerElement&, const String& referrer) final;
217
218     RefPtr<WebCore::Widget> createPlugin(const WebCore::IntSize&, WebCore::HTMLPlugInElement&, const URL&, const Vector<String>&, const Vector<String>&, const String&, bool loadManually) final;
219     void redirectDataToPlugin(WebCore::Widget&) final;
220     
221 #if ENABLE(WEBGL)
222     WebCore::WebGLLoadPolicy webGLPolicyForURL(const URL&) const final;
223     WebCore::WebGLLoadPolicy resolveWebGLPolicyForURL(const URL&) const final;
224 #endif // ENABLE(WEBGL)
225
226     RefPtr<WebCore::Widget> createJavaAppletWidget(const WebCore::IntSize&, WebCore::HTMLAppletElement&, const URL& baseURL, const Vector<String>& paramNames, const Vector<String>& paramValues) final;
227     
228     WebCore::ObjectContentType objectContentType(const URL&, const String& mimeType) final;
229     String overrideMediaType() const final;
230
231     void dispatchDidClearWindowObjectInWorld(WebCore::DOMWrapperWorld&) final;
232     
233     void dispatchGlobalObjectAvailable(WebCore::DOMWrapperWorld&) final;
234     void dispatchWillDisconnectDOMWindowExtensionFromGlobalObject(WebCore::DOMWindowExtension*) final;
235     void dispatchDidReconnectDOMWindowExtensionToGlobalObject(WebCore::DOMWindowExtension*) final;
236     void dispatchWillDestroyGlobalObjectForDOMWindowExtension(WebCore::DOMWindowExtension*) final;
237
238     void willInjectUserScript(WebCore::DOMWrapperWorld&) final;
239
240 #if PLATFORM(COCOA)
241     RemoteAXObjectRef accessibilityRemoteObject() final;
242     
243     void willCacheResponse(WebCore::DocumentLoader*, unsigned long identifier, NSCachedURLResponse*, CompletionHandler<void(NSCachedURLResponse *)>&&) const final;
244
245     NSDictionary *dataDetectionContext() final;
246 #endif
247
248     void didChangeScrollOffset() final;
249
250     bool allowScript(bool enabledPerSettings) final;
251
252     bool shouldForceUniversalAccessFromLocalURL(const URL&) final;
253
254     Ref<WebCore::FrameNetworkingContext> createNetworkingContext() final;
255
256     void forcePageTransitionIfNeeded() final;
257
258 #if USE(QUICK_LOOK)
259     RefPtr<WebCore::PreviewLoaderClient> createPreviewLoaderClient(const String& fileName, const String& uti) final;
260 #endif
261
262 #if ENABLE(CONTENT_FILTERING)
263     void contentFilterDidBlockLoad(WebCore::ContentFilterUnblockHandler) final;
264 #endif
265
266     void prefetchDNS(const String&) final;
267
268     void didRestoreScrollPosition() final;
269
270     void getLoadDecisionForIcons(const Vector<std::pair<WebCore::LinkIcon&, uint64_t>>&) final;
271     void finishedLoadingIcon(uint64_t callbackIdentifier, WebCore::SharedBuffer*) final;
272
273     void didCreateWindow(WebCore::DOMWindow&) final;
274
275 #if ENABLE(APPLICATION_MANIFEST)
276     void finishedLoadingApplicationManifest(uint64_t, const Optional<WebCore::ApplicationManifest>&) final;
277 #endif
278
279     WebFrame* m_frame;
280     RefPtr<PluginView> m_pluginView;
281     bool m_hasSentResponseToPluginView;
282     bool m_didCompletePageTransition;
283     bool m_frameHasCustomContentProvider;
284     bool m_frameCameFromBackForwardCache;
285     bool m_useIconLoadingClient { false };
286 #if ENABLE(RESOURCE_LOAD_STATISTICS)
287     Optional<FrameSpecificStorageAccessIdentifier> m_frameSpecificStorageAccessIdentifier;
288 #endif
289 };
290
291 // As long as EmptyFrameLoaderClient exists in WebCore, this can return 0.
292 inline WebFrameLoaderClient* toWebFrameLoaderClient(WebCore::FrameLoaderClient& client)
293 {
294     return client.isEmptyFrameLoaderClient() ? 0 : static_cast<WebFrameLoaderClient*>(&client);
295 }
296
297 } // namespace WebKit