5ab31e51299e39bf281bafe5aae3cfccf8135eae
[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 PAL {
33 class SessionID;
34 }
35
36 namespace WebKit {
37
38 class PluginView;
39 class WebFrame;
40 struct WebsitePoliciesData;
41     
42 class WebFrameLoaderClient final : public WebCore::FrameLoaderClient {
43 public:
44     WebFrameLoaderClient();
45     ~WebFrameLoaderClient();
46
47     void setWebFrame(WebFrame* webFrame) { m_frame = webFrame; }
48     WebFrame* webFrame() const { return m_frame; }
49
50     bool frameHasCustomContentProvider() const { return m_frameHasCustomContentProvider; }
51
52     void setUseIconLoadingClient(bool useIconLoadingClient) { m_useIconLoadingClient = useIconLoadingClient; }
53
54     void applyToDocumentLoader(WebsitePoliciesData&&);
55
56     Optional<WebPageProxyIdentifier> webPageProxyID() const;
57     Optional<WebCore::PageIdentifier> pageID() const final;
58     Optional<WebCore::FrameIdentifier> frameID() const final;
59     PAL::SessionID sessionID() const final;
60
61 #if ENABLE(RESOURCE_LOAD_STATISTICS)
62     bool hasFrameSpecificStorageAccess() final { return !!m_frameSpecificStorageAccessIdentifier; }
63     
64     struct FrameSpecificStorageAccessIdentifier {
65         PAL::SessionID sessionID;
66         WebCore::FrameIdentifier frameID;
67         WebCore::PageIdentifier pageID;
68     };
69     void setHasFrameSpecificStorageAccess(FrameSpecificStorageAccessIdentifier&&);
70 #endif
71     
72 private:
73     void frameLoaderDestroyed() final;
74
75     bool hasHTMLView() const final;
76     bool hasWebView() const final;
77     
78     void makeRepresentation(WebCore::DocumentLoader*) final;
79 #if PLATFORM(IOS_FAMILY)
80     bool forceLayoutOnRestoreFromPageCache() final;
81 #endif
82     void forceLayoutForNonHTML() final;
83     
84     void setCopiesOnScroll() final;
85     
86     void detachedFromParent2() final;
87     void detachedFromParent3() final;
88     
89     void assignIdentifierToInitialRequest(unsigned long identifier, WebCore::DocumentLoader*, const WebCore::ResourceRequest&) final;
90     
91     void dispatchWillSendRequest(WebCore::DocumentLoader*, unsigned long identifier, WebCore::ResourceRequest&, const WebCore::ResourceResponse& redirectResponse) final;
92     bool shouldUseCredentialStorage(WebCore::DocumentLoader*, unsigned long identifier) final;
93     void dispatchDidReceiveAuthenticationChallenge(WebCore::DocumentLoader*, unsigned long identifier, const WebCore::AuthenticationChallenge&) final;
94 #if USE(PROTECTION_SPACE_AUTH_CALLBACK)
95     bool canAuthenticateAgainstProtectionSpace(WebCore::DocumentLoader*, unsigned long identifier, const WebCore::ProtectionSpace&) final;
96 #endif
97 #if PLATFORM(IOS_FAMILY)
98     RetainPtr<CFDictionaryRef> connectionProperties(WebCore::DocumentLoader*, unsigned long identifier) final;
99 #endif
100     void dispatchDidReceiveResponse(WebCore::DocumentLoader*, unsigned long identifier, const WebCore::ResourceResponse&) final;
101     void dispatchDidReceiveContentLength(WebCore::DocumentLoader*, unsigned long identifier, int dataLength) final;
102     void dispatchDidFinishLoading(WebCore::DocumentLoader*, unsigned long identifier) final;
103     void dispatchDidFailLoading(WebCore::DocumentLoader*, unsigned long identifier, const WebCore::ResourceError&) final;
104     bool dispatchDidLoadResourceFromMemoryCache(WebCore::DocumentLoader*, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&, int length) final;
105 #if ENABLE(DATA_DETECTION)
106     void dispatchDidFinishDataDetection(NSArray *detectionResults) final;
107 #endif
108     void dispatchDidChangeMainDocument() final;
109     void dispatchWillChangeDocument(const URL& currentUrl, const URL& newUrl) final;
110
111     void dispatchDidDispatchOnloadEvents() final;
112     void dispatchDidReceiveServerRedirectForProvisionalLoad() final;
113     void dispatchDidChangeProvisionalURL() final;
114     void dispatchDidCancelClientRedirect() final;
115     void dispatchWillPerformClientRedirect(const URL&, double interval, WallTime fireDate, WebCore::LockBackForwardList) final;
116     void dispatchDidChangeLocationWithinPage() final;
117     void dispatchDidPushStateWithinPage() final;
118     void dispatchDidReplaceStateWithinPage() final;
119     void dispatchDidPopStateWithinPage() final;
120     void dispatchWillClose() final;
121     void dispatchDidStartProvisionalLoad() final;
122     void dispatchDidReceiveTitle(const WebCore::StringWithDirection&) final;
123     void dispatchDidCommitLoad(Optional<WebCore::HasInsecureContent>) final;
124     void dispatchDidFailProvisionalLoad(const WebCore::ResourceError&, WebCore::WillContinueLoading) final;
125     void dispatchDidFailLoad(const WebCore::ResourceError&) final;
126     void dispatchDidFinishDocumentLoad() final;
127     void dispatchDidFinishLoad() final;
128     void dispatchDidExplicitOpen(const URL&) final;
129
130     void dispatchDidReachLayoutMilestone(OptionSet<WebCore::LayoutMilestone>) final;
131     void dispatchDidLayout() final;
132
133     WebCore::Frame* dispatchCreatePage(const WebCore::NavigationAction&) final;
134     void dispatchShow() final;
135     
136     void dispatchDecidePolicyForResponse(const WebCore::ResourceResponse&, const WebCore::ResourceRequest&, WebCore::PolicyCheckIdentifier, const String&, WebCore::FramePolicyFunction&&) final;
137     void dispatchDecidePolicyForNewWindowAction(const WebCore::NavigationAction&, const WebCore::ResourceRequest&, WebCore::FormState*, const String& frameName, WebCore::PolicyCheckIdentifier, WebCore::FramePolicyFunction&&) final;
138     void dispatchDecidePolicyForNavigationAction(const WebCore::NavigationAction&, const WebCore::ResourceRequest&, const WebCore::ResourceResponse& redirectResponse, WebCore::FormState*, WebCore::PolicyDecisionMode, WebCore::PolicyCheckIdentifier, WebCore::FramePolicyFunction&&) final;
139     void cancelPolicyCheck() final;
140     
141     void dispatchUnableToImplementPolicy(const WebCore::ResourceError&) final;
142     
143     void dispatchWillSendSubmitEvent(Ref<WebCore::FormState>&&) final;
144     void dispatchWillSubmitForm(WebCore::FormState&, CompletionHandler<void()>&&) final;
145     
146     void revertToProvisionalState(WebCore::DocumentLoader*) final;
147     void setMainDocumentError(WebCore::DocumentLoader*, const WebCore::ResourceError&) final;
148     
149     void setMainFrameDocumentReady(bool) final;
150     
151     void startDownload(const WebCore::ResourceRequest&, const String& suggestedName = String()) final;
152     
153     void willChangeTitle(WebCore::DocumentLoader*) final;
154     void didChangeTitle(WebCore::DocumentLoader*) final;
155
156     void willReplaceMultipartContent() final;
157     void didReplaceMultipartContent() final;
158
159     void committedLoad(WebCore::DocumentLoader*, const char*, int) final;
160     void finishedLoading(WebCore::DocumentLoader*) final;
161     
162     void updateGlobalHistory() final;
163     void updateGlobalHistoryRedirectLinks() final;
164     
165     bool shouldGoToHistoryItem(WebCore::HistoryItem&) const final;
166
167     void didDisplayInsecureContent() final;
168     void didRunInsecureContent(WebCore::SecurityOrigin&, const URL&) final;
169     void didDetectXSS(const URL&, bool didBlockEntirePage) final;
170
171     WebCore::ResourceError cancelledError(const WebCore::ResourceRequest&) final;
172     WebCore::ResourceError blockedError(const WebCore::ResourceRequest&) final;
173     WebCore::ResourceError blockedByContentBlockerError(const WebCore::ResourceRequest&) final;
174     WebCore::ResourceError cannotShowURLError(const WebCore::ResourceRequest&) final;
175     WebCore::ResourceError interruptedForPolicyChangeError(const WebCore::ResourceRequest&) final;
176 #if ENABLE(CONTENT_FILTERING)
177     WebCore::ResourceError blockedByContentFilterError(const WebCore::ResourceRequest&) final;
178 #endif
179     
180     WebCore::ResourceError cannotShowMIMETypeError(const WebCore::ResourceResponse&) final;
181     WebCore::ResourceError fileDoesNotExistError(const WebCore::ResourceResponse&) final;
182     WebCore::ResourceError pluginWillHandleLoadError(const WebCore::ResourceResponse&) final;
183     
184     bool shouldFallBack(const WebCore::ResourceError&) final;
185     
186     bool canHandleRequest(const WebCore::ResourceRequest&) const final;
187     bool canShowMIMEType(const String& MIMEType) const final;
188     bool canShowMIMETypeAsHTML(const String& MIMEType) const final;
189     bool representationExistsForURLScheme(const String& URLScheme) const final;
190     String generatedMIMETypeForURLScheme(const String& URLScheme) const final;
191     
192     void frameLoadCompleted() final;
193     void saveViewStateToItem(WebCore::HistoryItem&) final;
194     void restoreViewState() final;
195     void provisionalLoadStarted() final;
196     void didFinishLoad() final;
197     void prepareForDataSourceReplacement() final;
198     
199     Ref<WebCore::DocumentLoader> createDocumentLoader(const WebCore::ResourceRequest&, const WebCore::SubstituteData&) final;
200     void updateCachedDocumentLoader(WebCore::DocumentLoader&) final;
201
202     void setTitle(const WebCore::StringWithDirection&, const URL&) final;
203     
204     String userAgent(const URL&) final;
205
206     String overrideContentSecurityPolicy() const final;
207
208     void savePlatformDataToCachedFrame(WebCore::CachedFrame*) final;
209     void transitionToCommittedFromCachedFrame(WebCore::CachedFrame*) final;
210 #if PLATFORM(IOS_FAMILY)
211     void didRestoreFrameHierarchyForCachedFrame() final;
212 #endif
213     void transitionToCommittedForNewPage() final;
214
215     void didSaveToPageCache() final;
216     void didRestoreFromPageCache() final;
217
218     void dispatchDidBecomeFrameset(bool) final;
219
220     bool canCachePage() const final;
221     void convertMainResourceLoadToDownload(WebCore::DocumentLoader*, PAL::SessionID, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&) final;
222
223     RefPtr<WebCore::Frame> createFrame(const URL&, const String& name, WebCore::HTMLFrameOwnerElement&, const String& referrer) final;
224
225     RefPtr<WebCore::Widget> createPlugin(const WebCore::IntSize&, WebCore::HTMLPlugInElement&, const URL&, const Vector<String>&, const Vector<String>&, const String&, bool loadManually) final;
226     void redirectDataToPlugin(WebCore::Widget&) final;
227     
228 #if ENABLE(WEBGL)
229     WebCore::WebGLLoadPolicy webGLPolicyForURL(const URL&) const final;
230     WebCore::WebGLLoadPolicy resolveWebGLPolicyForURL(const URL&) const final;
231 #endif // ENABLE(WEBGL)
232
233     RefPtr<WebCore::Widget> createJavaAppletWidget(const WebCore::IntSize&, WebCore::HTMLAppletElement&, const URL& baseURL, const Vector<String>& paramNames, const Vector<String>& paramValues) final;
234     
235     WebCore::ObjectContentType objectContentType(const URL&, const String& mimeType) final;
236     String overrideMediaType() const final;
237
238     void dispatchDidClearWindowObjectInWorld(WebCore::DOMWrapperWorld&) final;
239     
240     void dispatchGlobalObjectAvailable(WebCore::DOMWrapperWorld&) final;
241     void dispatchWillDisconnectDOMWindowExtensionFromGlobalObject(WebCore::DOMWindowExtension*) final;
242     void dispatchDidReconnectDOMWindowExtensionToGlobalObject(WebCore::DOMWindowExtension*) final;
243     void dispatchWillDestroyGlobalObjectForDOMWindowExtension(WebCore::DOMWindowExtension*) final;
244
245     void willInjectUserScript(WebCore::DOMWrapperWorld&) final;
246
247 #if PLATFORM(COCOA)
248     RemoteAXObjectRef accessibilityRemoteObject() final;
249     
250     void willCacheResponse(WebCore::DocumentLoader*, unsigned long identifier, NSCachedURLResponse*, CompletionHandler<void(NSCachedURLResponse *)>&&) const final;
251
252     NSDictionary *dataDetectionContext() final;
253 #endif
254
255     void didChangeScrollOffset() final;
256
257     bool allowScript(bool enabledPerSettings) final;
258
259     bool shouldForceUniversalAccessFromLocalURL(const URL&) final;
260
261     Ref<WebCore::FrameNetworkingContext> createNetworkingContext() final;
262
263     void forcePageTransitionIfNeeded() final;
264
265 #if USE(QUICK_LOOK)
266     RefPtr<WebCore::PreviewLoaderClient> createPreviewLoaderClient(const String& fileName, const String& uti) final;
267 #endif
268
269 #if ENABLE(CONTENT_FILTERING)
270     void contentFilterDidBlockLoad(WebCore::ContentFilterUnblockHandler) final;
271 #endif
272
273     void prefetchDNS(const String&) final;
274
275     void didRestoreScrollPosition() final;
276
277     void getLoadDecisionForIcons(const Vector<std::pair<WebCore::LinkIcon&, uint64_t>>&) final;
278     void finishedLoadingIcon(uint64_t callbackIdentifier, WebCore::SharedBuffer*) final;
279
280     void didCreateWindow(WebCore::DOMWindow&) final;
281
282 #if ENABLE(APPLICATION_MANIFEST)
283     void finishedLoadingApplicationManifest(uint64_t, const Optional<WebCore::ApplicationManifest>&) final;
284 #endif
285
286     WebFrame* m_frame;
287     RefPtr<PluginView> m_pluginView;
288     bool m_hasSentResponseToPluginView;
289     bool m_didCompletePageTransition;
290     bool m_frameHasCustomContentProvider;
291     bool m_frameCameFromPageCache;
292     bool m_useIconLoadingClient { false };
293 #if ENABLE(RESOURCE_LOAD_STATISTICS)
294     Optional<FrameSpecificStorageAccessIdentifier> m_frameSpecificStorageAccessIdentifier;
295 #endif
296 };
297
298 // As long as EmptyFrameLoaderClient exists in WebCore, this can return 0.
299 inline WebFrameLoaderClient* toWebFrameLoaderClient(WebCore::FrameLoaderClient& client)
300 {
301     return client.isEmptyFrameLoaderClient() ? 0 : static_cast<WebFrameLoaderClient*>(&client);
302 }
303
304 } // namespace WebKit