-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
WKWebViewInternal.h
366 lines (275 loc) · 12.1 KB
/
WKWebViewInternal.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
/*
* Copyright (C) 2014-2023 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#import "PDFPluginIdentifier.h"
#import <WebKit/WKShareSheet.h>
#import <WebKit/WKWebViewConfiguration.h>
#import <WebKit/WKWebViewPrivate.h>
#import "_WKAttachmentInternal.h"
#import "_WKWebViewPrintFormatterInternal.h"
#import <variant>
#import <wtf/CompletionHandler.h>
#import <wtf/NakedPtr.h>
#import <wtf/RefPtr.h>
#import <wtf/RetainPtr.h>
#import <wtf/WeakObjCPtr.h>
#if PLATFORM(IOS_FAMILY)
#import "DynamicViewportSizeUpdate.h"
#import "UIKitSPI.h"
#import "WKContentView.h"
#import "WKContentViewInteraction.h"
#import "WKFullScreenWindowControllerIOS.h"
#import <WebCore/FloatRect.h>
#import <WebCore/IntDegrees.h>
#import <WebCore/LengthBox.h>
#import <WebCore/PlatformLayerIdentifier.h>
#import <WebCore/ViewportArguments.h>
#endif
#if PLATFORM(IOS_FAMILY)
#define WK_WEB_VIEW_PROTOCOLS <UIScrollViewDelegate>
#endif
#if PLATFORM(MAC)
#define WK_WEB_VIEW_PROTOCOLS <WKShareSheetDelegate>
#endif
#if !defined(WK_WEB_VIEW_PROTOCOLS)
#define WK_WEB_VIEW_PROTOCOLS
#endif
#if USE(APPKIT)
using CocoaEdgeInsets = NSEdgeInsets;
#endif
#if PLATFORM(IOS_FAMILY)
using CocoaEdgeInsets = UIEdgeInsets;
#endif
typedef const struct OpaqueWKPage* WKPageRef;
namespace API {
class Attachment;
}
namespace WebCore {
struct AppHighlight;
struct ExceptionDetails;
enum class WheelScrollGestureState : uint8_t;
}
namespace WebKit {
enum class ContinueUnsafeLoad : bool;
class IconLoadingDelegate;
class NavigationState;
class ResourceLoadDelegate;
class SafeBrowsingWarning;
class ViewSnapshot;
class WebPageProxy;
class UIDelegate;
struct PrintInfo;
#if PLATFORM(MAC)
class WebViewImpl;
#endif
#if PLATFORM(IOS_FAMILY)
class ViewGestureController;
#endif
}
@class WKContentView;
@class WKPasswordView;
@class WKSafeBrowsingWarning;
@class WKScrollView;
@class WKWebViewContentProviderRegistry;
@class _WKFrameHandle;
#if PLATFORM(IOS_FAMILY)
@class WKFullScreenWindowController;
@protocol WKWebViewContentProvider;
#endif
#if PLATFORM(MAC)
@class WKTextFinderClient;
#endif
@protocol _WKTextManipulationDelegate;
@protocol _WKInputDelegate;
@protocol _WKAppHighlightDelegate;
#if PLATFORM(IOS_FAMILY)
struct LiveResizeParameters {
CGFloat viewWidth;
CGPoint initialScrollPosition;
};
// This holds state that should be reset when the web process exits.
struct PerWebProcessState {
CGFloat viewportMetaTagWidth { WebCore::ViewportArguments::ValueAuto };
CGFloat initialScaleFactor { 1 };
BOOL hasCommittedLoadForMainFrame { NO };
BOOL needsResetViewStateAfterCommitLoadForMainFrame { NO };
WebKit::DynamicViewportUpdateMode dynamicViewportUpdateMode { WebKit::DynamicViewportUpdateMode::NotResizing };
BOOL waitingForEndAnimatedResize { NO };
BOOL waitingForCommitAfterAnimatedResize { NO };
CGFloat animatedResizeOriginalContentWidth { 0 };
CGRect animatedResizeOldBounds { CGRectZero }; // FIXME: Use std::optional<>
std::optional<WebCore::FloatPoint> scrollOffsetToRestore;
std::optional<WebCore::FloatPoint> unobscuredCenterToRestore;
WebCore::Color scrollViewBackgroundColor;
BOOL invokingUIScrollViewDelegateCallback { NO };
BOOL didDeferUpdateVisibleContentRectsForUIScrollViewDelegateCallback { NO };
BOOL didDeferUpdateVisibleContentRectsForAnyReason { NO };
BOOL didDeferUpdateVisibleContentRectsForUnstableScrollView { NO };
BOOL currentlyAdjustingScrollViewInsetsForKeyboard { NO };
BOOL hasScheduledVisibleRectUpdate { NO };
BOOL commitDidRestoreScrollPosition { NO };
BOOL avoidsUnsafeArea { YES };
BOOL viewportMetaTagWidthWasExplicit { NO };
BOOL viewportMetaTagCameFromImageDocument { NO };
std::optional<WebCore::FloatSize> lastSentViewLayoutSize;
std::optional<WebCore::IntDegrees> lastSentDeviceOrientation;
std::optional<WebCore::IntDegrees> lastSentOrientationForMediaCapture;
std::optional<CGFloat> lastSentMinimumEffectiveDeviceWidth;
std::optional<CGRect> frozenVisibleContentRect;
std::optional<CGRect> frozenUnobscuredContentRect;
WebKit::TransactionID firstPaintAfterCommitLoadTransactionID;
WebKit::TransactionID lastTransactionID;
std::optional<WebKit::TransactionID> firstTransactionIDAfterPageRestore;
WebCore::PlatformLayerIdentifier pendingFindLayerID;
WebCore::PlatformLayerIdentifier committedFindLayerID;
std::optional<LiveResizeParameters> liveResizeParameters;
};
#endif // PLATFORM(IOS_FAMILY)
@interface WKWebView () WK_WEB_VIEW_PROTOCOLS {
@package
RetainPtr<WKWebViewConfiguration> _configuration;
RefPtr<WebKit::WebPageProxy> _page;
std::unique_ptr<WebKit::NavigationState> _navigationState;
std::unique_ptr<WebKit::UIDelegate> _uiDelegate;
std::unique_ptr<WebKit::IconLoadingDelegate> _iconLoadingDelegate;
std::unique_ptr<WebKit::ResourceLoadDelegate> _resourceLoadDelegate;
WeakObjCPtr<id <_WKTextManipulationDelegate>> _textManipulationDelegate;
WeakObjCPtr<id <_WKInputDelegate>> _inputDelegate;
WeakObjCPtr<id <_WKAppHighlightDelegate>> _appHighlightDelegate;
RetainPtr<WKSafeBrowsingWarning> _safeBrowsingWarning;
std::optional<BOOL> _resolutionForShareSheetImmediateCompletionForTesting;
_WKSelectionAttributes _selectionAttributes;
_WKRenderingProgressEvents _observedRenderingProgressEvents;
BOOL _usePlatformFindUI;
CocoaEdgeInsets _minimumViewportInset;
CocoaEdgeInsets _maximumViewportInset;
#if PLATFORM(MAC)
std::unique_ptr<WebKit::WebViewImpl> _impl;
RetainPtr<WKTextFinderClient> _textFinderClient;
// Only used with UI-side compositing.
RetainPtr<WKScrollView> _scrollView;
RetainPtr<WKContentView> _contentView;
#endif // PLATFORM(MAC)
#if PLATFORM(IOS_FAMILY)
RetainPtr<WKScrollView> _scrollView;
RetainPtr<WKContentView> _contentView;
std::unique_ptr<WebKit::ViewGestureController> _gestureController;
Vector<BlockPtr<void ()>> _visibleContentRectUpdateCallbacks;
#if ENABLE(FULLSCREEN_API)
RetainPtr<WKFullScreenWindowController> _fullScreenWindowController;
#endif
BOOL _findInteractionEnabled;
#if HAVE(UIFINDINTERACTION)
RetainPtr<UIFindInteraction> _findInteraction;
#endif
RetainPtr<_WKRemoteObjectRegistry> _remoteObjectRegistry;
PerWebProcessState _perProcessState;
std::optional<CGSize> _viewLayoutSizeOverride;
std::optional<CGSize> _minimumUnobscuredSizeOverride;
std::optional<CGSize> _maximumUnobscuredSizeOverride;
CGRect _inputViewBoundsInWindow;
BOOL _fastClickingIsDisabled;
BOOL _allowsLinkPreview;
UIEdgeInsets _obscuredInsets;
BOOL _haveSetObscuredInsets;
BOOL _isChangingObscuredInsetsInteractively;
UIEdgeInsets _unobscuredSafeAreaInsets;
BOOL _haveSetUnobscuredSafeAreaInsets;
BOOL _needsToPresentLockdownModeMessage;
UIRectEdge _obscuredInsetEdgesAffectedBySafeArea;
UIInterfaceOrientationMask _supportedInterfaceOrientations;
UIInterfaceOrientation _interfaceOrientationOverride;
BOOL _overridesInterfaceOrientation;
BOOL _allowsViewportShrinkToFit;
WebKit::DynamicViewportSizeUpdateID _currentDynamicViewportSizeUpdateID;
CATransform3D _resizeAnimationTransformAdjustments;
CGFloat _animatedResizeOldMinimumEffectiveDeviceWidth;
WebCore::IntDegrees _animatedResizeOldOrientation;
UIEdgeInsets _animatedResizeOldObscuredInsets;
RetainPtr<UIView> _resizeAnimationView;
CGFloat _lastAdjustmentForScroller;
RetainPtr<id> _endLiveResizeNotificationObserver;
WebCore::FloatBoxExtent _obscuredInsetsWhenSaved;
double _scaleToRestore;
#if HAVE(UIKIT_RESIZABLE_WINDOWS)
Vector<RetainPtr<id<_UIInvalidatable>>> _resizeAssertions;
#endif
BOOL _allowsBackForwardNavigationGestures;
RetainPtr<UIView <WKWebViewContentProvider>> _customContentView;
RetainPtr<UIView> _customContentFixedOverlayView;
RetainPtr<NSTimer> _enclosingScrollViewScrollTimer;
BOOL _didScrollSinceLastTimerFire;
// This value tracks the current adjustment added to the bottom inset due to the keyboard sliding out from the bottom
// when computing obscured content insets. This is used when updating the visible content rects where we should not
// include this adjustment.
CGFloat _totalScrollViewBottomInsetAdjustmentForKeyboard;
BOOL _alwaysSendNextVisibleContentRectUpdate;
BOOL _contentViewShouldBecomeFirstResponderAfterNavigationGesture;
Vector<WTF::Function<void ()>> _callbacksDeferredDuringResize;
RetainPtr<NSMutableArray> _stableStatePresentationUpdateCallbacks;
RetainPtr<WKPasswordView> _passwordView;
OptionSet<WebKit::ViewStabilityFlag> _viewStabilityWhenVisibleContentRectUpdateScheduled;
std::optional<WebCore::WheelScrollGestureState> _currentScrollGestureState;
uint64_t _wheelEventCountInCurrentScrollGesture;
_WKDragInteractionPolicy _dragInteractionPolicy;
// For release-logging for <rdar://problem/39281269>.
MonotonicTime _timeOfRequestForVisibleContentRectUpdate;
MonotonicTime _timeOfLastVisibleContentRectUpdate;
std::optional<MonotonicTime> _timeOfFirstVisibleContentRectUpdateWithPendingCommit;
NSUInteger _focusPreservationCount;
NSUInteger _activeFocusedStateRetainCount;
RetainPtr<NSArray<NSNumber *>> _scrollViewDefaultAllowedTouchTypes;
#endif
}
- (BOOL)_isValid;
- (void)_didChangeEditorState;
#if ENABLE(ATTACHMENT_ELEMENT)
- (void)_didRemoveAttachment:(API::Attachment&)attachment;
- (void)_didInsertAttachment:(API::Attachment&)attachment withSource:(NSString *)source;
- (void)_didInvalidateDataForAttachment:(API::Attachment&)attachment;
#endif
#if ENABLE(APP_HIGHLIGHTS)
- (void)_storeAppHighlight:(const WebCore::AppHighlight&)info;
#endif
- (void)_internalDoAfterNextPresentationUpdate:(void (^)(void))updateBlock withoutWaitingForPainting:(BOOL)withoutWaitingForPainting withoutWaitingForAnimatedResize:(BOOL)withoutWaitingForAnimatedResize;
- (void)_doAfterNextVisibleContentRectAndPresentationUpdate:(void (^)(void))updateBlock;
- (void)_recalculateViewportSizesWithMinimumViewportInset:(CocoaEdgeInsets)minimumViewportInset maximumViewportInset:(CocoaEdgeInsets)maximumViewportInset throwOnInvalidInput:(BOOL)throwOnInvalidInput;
- (void)_showSafeBrowsingWarning:(const WebKit::SafeBrowsingWarning&)warning completionHandler:(CompletionHandler<void(std::variant<WebKit::ContinueUnsafeLoad, URL>&&)>&&)completionHandler;
- (void)_clearSafeBrowsingWarning;
- (void)_clearSafeBrowsingWarningIfForMainFrameNavigation;
- (std::optional<BOOL>)_resolutionForShareSheetImmediateCompletionForTesting;
- (WKPageRef)_pageForTesting;
- (NakedPtr<WebKit::WebPageProxy>)_page;
@end
RetainPtr<NSError> nsErrorFromExceptionDetails(const WebCore::ExceptionDetails&);
#if ENABLE(FULLSCREEN_API) && PLATFORM(IOS_FAMILY)
@interface WKWebView (FullScreenAPI_Internal)
-(WKFullScreenWindowController *)fullScreenWindowController;
@end
#endif
#if PLATFORM(IOS_FAMILY)
@interface WKWebView (_WKWebViewPrintFormatter)
@property (nonatomic, readonly) id <_WKWebViewPrintProvider> _printProvider;
@end
#endif