Web Inspector: Debugger: debug hooks should also be emitted for the first sub-express...
[WebKit-https.git] / Source / WebKit / WebProcess / WebCoreSupport / WebFrameLoaderClient.h
1 /*
2  * Copyright (C) 2010-2020 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     explicit WebFrameLoaderClient(Ref<WebFrame>&&);
41     ~WebFrameLoaderClient();
42
43     WebFrame& webFrame() const { return m_frame.get(); }
44
45     bool frameHasCustomContentProvider() const { return m_frameHasCustomContentProvider; }
46
47     void setUseIconLoadingClient(bool useIconLoadingClient) { m_useIconLoadingClient = useIconLoadingClient; }
48
49     void applyToDocumentLoader(WebsitePoliciesData&&);
50
51     Optional<WebPageProxyIdentifier> webPageProxyID() const;
52     Optional<WebCore::PageIdentifier> pageID() const final;
53     Optional<WebCore::FrameIdentifier> frameID() const final;
54
55 #if ENABLE(RESOURCE_LOAD_STATISTICS)
56     bool hasFrameSpecificStorageAccess() final { return !!m_frameSpecificStorageAccessIdentifier; }
57     
58     struct FrameSpecificStorageAccessIdentifier {
59         WebCore::FrameIdentifier frameID;
60         WebCore::PageIdentifier pageID;
61     };
62     void setHasFrameSpecificStorageAccess(FrameSpecificStorageAccessIdentifier&&);
63     void didLoadFromRegistrableDomain(WebCore::RegistrableDomain&&) final;
64 #endif
65
66     WebCore::AllowsContentJavaScript allowsContentJavaScriptFromMostRecentNavigation() const final;
67
68 private:
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>, Optional<WebCore::UsedLegacyTLS>) 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&, const String& mimeType) final;
123
124     void dispatchDidReachLayoutMilestone(OptionSet<WebCore::LayoutMilestone>) final;
125     void dispatchDidReachVisuallyNonEmptyState() final;
126     void dispatchDidLayout() final;
127
128     WebCore::Frame* dispatchCreatePage(const WebCore::NavigationAction&) final;
129     void dispatchShow() final;
130     
131     void dispatchDecidePolicyForResponse(const WebCore::ResourceResponse&, const WebCore::ResourceRequest&, WebCore::PolicyCheckIdentifier, const String&, WebCore::FramePolicyFunction&&) final;
132     void dispatchDecidePolicyForNewWindowAction(const WebCore::NavigationAction&, const WebCore::ResourceRequest&, WebCore::FormState*, const String& frameName, WebCore::PolicyCheckIdentifier, WebCore::FramePolicyFunction&&) final;
133     void dispatchDecidePolicyForNavigationAction(const WebCore::NavigationAction&, const WebCore::ResourceRequest&, const WebCore::ResourceResponse& redirectResponse, WebCore::FormState*, WebCore::PolicyDecisionMode, WebCore::PolicyCheckIdentifier, WebCore::FramePolicyFunction&&) final;
134     void cancelPolicyCheck() final;
135     
136     void dispatchUnableToImplementPolicy(const WebCore::ResourceError&) final;
137     
138     void dispatchWillSendSubmitEvent(Ref<WebCore::FormState>&&) final;
139     void dispatchWillSubmitForm(WebCore::FormState&, CompletionHandler<void()>&&) final;
140     
141     void revertToProvisionalState(WebCore::DocumentLoader*) final;
142     void setMainDocumentError(WebCore::DocumentLoader*, const WebCore::ResourceError&) final;
143     
144     void setMainFrameDocumentReady(bool) final;
145     
146     void startDownload(const WebCore::ResourceRequest&, const String& suggestedName = String()) final;
147     
148     void willChangeTitle(WebCore::DocumentLoader*) final;
149     void didChangeTitle(WebCore::DocumentLoader*) final;
150
151     void willReplaceMultipartContent() final;
152     void didReplaceMultipartContent() final;
153
154     void committedLoad(WebCore::DocumentLoader*, const char*, int) final;
155     void finishedLoading(WebCore::DocumentLoader*) final;
156     
157     void updateGlobalHistory() final;
158     void updateGlobalHistoryRedirectLinks() final;
159     
160     bool shouldGoToHistoryItem(WebCore::HistoryItem&) const final;
161
162     void didDisplayInsecureContent() final;
163     void didRunInsecureContent(WebCore::SecurityOrigin&, const URL&) final;
164     void didDetectXSS(const URL&, bool didBlockEntirePage) final;
165
166     WebCore::ResourceError cancelledError(const WebCore::ResourceRequest&) const final;
167     WebCore::ResourceError blockedError(const WebCore::ResourceRequest&) const final;
168     WebCore::ResourceError blockedByContentBlockerError(const WebCore::ResourceRequest&) const final;
169     WebCore::ResourceError cannotShowURLError(const WebCore::ResourceRequest&) const final;
170     WebCore::ResourceError interruptedForPolicyChangeError(const WebCore::ResourceRequest&) const final;
171 #if ENABLE(CONTENT_FILTERING)
172     WebCore::ResourceError blockedByContentFilterError(const WebCore::ResourceRequest&) const final;
173 #endif
174     
175     WebCore::ResourceError cannotShowMIMETypeError(const WebCore::ResourceResponse&) const final;
176     WebCore::ResourceError fileDoesNotExistError(const WebCore::ResourceResponse&) const final;
177     WebCore::ResourceError pluginWillHandleLoadError(const WebCore::ResourceResponse&) const final;
178     
179     bool shouldFallBack(const WebCore::ResourceError&) const final;
180     
181     bool canHandleRequest(const WebCore::ResourceRequest&) const final;
182     bool canShowMIMEType(const String& MIMEType) const final;
183     bool canShowMIMETypeAsHTML(const String& MIMEType) const final;
184     bool representationExistsForURLScheme(const String& URLScheme) const final;
185     String generatedMIMETypeForURLScheme(const String& URLScheme) const final;
186     
187     void frameLoadCompleted() final;
188     void saveViewStateToItem(WebCore::HistoryItem&) final;
189     void restoreViewState() final;
190     void provisionalLoadStarted() final;
191     void didFinishLoad() final;
192     void prepareForDataSourceReplacement() final;
193     
194     Ref<WebCore::DocumentLoader> createDocumentLoader(const WebCore::ResourceRequest&, const WebCore::SubstituteData&) final;
195     void updateCachedDocumentLoader(WebCore::DocumentLoader&) final;
196
197     void setTitle(const WebCore::StringWithDirection&, const URL&) final;
198     
199     String userAgent(const URL&) const final;
200
201     String overrideContentSecurityPolicy() const final;
202
203     void savePlatformDataToCachedFrame(WebCore::CachedFrame*) final;
204     void transitionToCommittedFromCachedFrame(WebCore::CachedFrame*) final;
205 #if PLATFORM(IOS_FAMILY)
206     void didRestoreFrameHierarchyForCachedFrame() final;
207 #endif
208     void transitionToCommittedForNewPage() final;
209
210     void didRestoreFromBackForwardCache() final;
211
212     void dispatchDidBecomeFrameset(bool) final;
213
214     bool canCachePage() const final;
215     void convertMainResourceLoadToDownload(WebCore::DocumentLoader*, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&) final;
216
217     RefPtr<WebCore::Frame> createFrame(const URL&, const String& name, WebCore::HTMLFrameOwnerElement&, const String& referrer) final;
218
219     RefPtr<WebCore::Widget> createPlugin(const WebCore::IntSize&, WebCore::HTMLPlugInElement&, const URL&, const Vector<String>&, const Vector<String>&, const String&, bool loadManually) final;
220     void redirectDataToPlugin(WebCore::Widget&) final;
221     
222 #if ENABLE(WEBGL)
223     WebCore::WebGLLoadPolicy webGLPolicyForURL(const URL&) const final;
224     WebCore::WebGLLoadPolicy resolveWebGLPolicyForURL(const URL&) const final;
225 #endif // ENABLE(WEBGL)
226
227     RefPtr<WebCore::Widget> createJavaAppletWidget(const WebCore::IntSize&, WebCore::HTMLAppletElement&, const URL& baseURL, const Vector<String>& paramNames, const Vector<String>& paramValues) final;
228     
229     WebCore::ObjectContentType objectContentType(const URL&, const String& mimeType) final;
230     String overrideMediaType() const final;
231
232     void dispatchDidClearWindowObjectInWorld(WebCore::DOMWrapperWorld&) final;
233     
234     void dispatchGlobalObjectAvailable(WebCore::DOMWrapperWorld&) final;
235     void dispatchWillDisconnectDOMWindowExtensionFromGlobalObject(WebCore::DOMWindowExtension*) final;
236     void dispatchDidReconnectDOMWindowExtensionToGlobalObject(WebCore::DOMWindowExtension*) final;
237     void dispatchWillDestroyGlobalObjectForDOMWindowExtension(WebCore::DOMWindowExtension*) final;
238
239     void willInjectUserScript(WebCore::DOMWrapperWorld&) final;
240
241 #if PLATFORM(COCOA)
242     RemoteAXObjectRef accessibilityRemoteObject() final;
243     
244     void willCacheResponse(WebCore::DocumentLoader*, unsigned long identifier, NSCachedURLResponse*, CompletionHandler<void(NSCachedURLResponse *)>&&) const final;
245
246     NSDictionary *dataDetectionContext() final;
247 #endif
248
249     void didChangeScrollOffset() final;
250
251     bool allowScript(bool enabledPerSettings) final;
252
253     bool shouldForceUniversalAccessFromLocalURL(const URL&) final;
254
255     Ref<WebCore::FrameNetworkingContext> createNetworkingContext() final;
256
257     void completePageTransitionIfNeeded() final;
258
259 #if USE(QUICK_LOOK)
260     RefPtr<WebCore::LegacyPreviewLoaderClient> createPreviewLoaderClient(const String& fileName, const String& uti) final;
261 #endif
262
263 #if ENABLE(CONTENT_FILTERING)
264     void contentFilterDidBlockLoad(WebCore::ContentFilterUnblockHandler) final;
265 #endif
266
267     void prefetchDNS(const String&) final;
268
269     void didRestoreScrollPosition() final;
270
271     void getLoadDecisionForIcons(const Vector<std::pair<WebCore::LinkIcon&, uint64_t>>&) final;
272     void finishedLoadingIcon(uint64_t callbackIdentifier, WebCore::SharedBuffer*) final;
273
274     void didCreateWindow(WebCore::DOMWindow&) final;
275
276 #if ENABLE(APPLICATION_MANIFEST)
277     void finishedLoadingApplicationManifest(uint64_t, const Optional<WebCore::ApplicationManifest>&) final;
278 #endif
279
280     Ref<WebFrame> m_frame;
281     RefPtr<PluginView> m_pluginView;
282     bool m_hasSentResponseToPluginView { false };
283     bool m_didCompletePageTransition { false };
284     bool m_frameHasCustomContentProvider { false };
285     bool m_frameCameFromBackForwardCache { false };
286     bool m_useIconLoadingClient { false };
287 #if ENABLE(RESOURCE_LOAD_STATISTICS)
288     Optional<FrameSpecificStorageAccessIdentifier> m_frameSpecificStorageAccessIdentifier;
289 #endif
290
291     bool hasNavigatedAwayFromAppBoundDomain() final;
292     bool needsInAppBrowserPrivacyQuirks() const final;
293 };
294
295 // As long as EmptyFrameLoaderClient exists in WebCore, this can return 0.
296 inline WebFrameLoaderClient* toWebFrameLoaderClient(WebCore::FrameLoaderClient& client)
297 {
298     return client.isEmptyFrameLoaderClient() ? 0 : static_cast<WebFrameLoaderClient*>(&client);
299 }
300
301 } // namespace WebKit