forked from WebKit/WebKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWKWebViewIOS.mm
More file actions
3488 lines (2809 loc) · 147 KB
/
WKWebViewIOS.mm
File metadata and controls
3488 lines (2809 loc) · 147 KB
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
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2014-2020 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 "config.h"
#import "WKWebViewIOS.h"
#if PLATFORM(IOS_FAMILY)
#import "FrontBoardServicesSPI.h"
#import "NativeWebWheelEvent.h"
#import "NavigationState.h"
#import "RemoteLayerTreeDrawingAreaProxy.h"
#import "RemoteLayerTreeScrollingPerformanceData.h"
#import "RemoteLayerTreeViews.h"
#import "RemoteScrollingCoordinatorProxy.h"
#import "TapHandlingResult.h"
#import "VideoFullscreenManagerProxy.h"
#import "ViewGestureController.h"
#import "WKBackForwardListItemInternal.h"
#import "WKContentView.h"
#import "WKPasswordView.h"
#import "WKSafeBrowsingWarning.h"
#import "WKScrollView.h"
#import "WKUIDelegatePrivate.h"
#import "WKWebViewConfigurationInternal.h"
#import "WKWebViewContentProvider.h"
#import "WKWebViewContentProviderRegistry.h"
#import "WKWebViewPrivate.h"
#import "WKWebViewPrivateForTestingIOS.h"
#import "WebBackForwardList.h"
#import "WebIOSEventFactory.h"
#import "WebPageProxy.h"
#import "_WKActivatedElementInfoInternal.h"
#import <WebCore/GraphicsContextCG.h>
#import <WebCore/IOSurface.h>
#import <WebCore/LocalCurrentTraitCollection.h>
#import <WebCore/MIMETypeRegistry.h>
#import <WebCore/RuntimeApplicationChecks.h>
#import <WebCore/VersionChecks.h>
#import <pal/spi/cocoa/QuartzCoreSPI.h>
#import <pal/spi/ios/GraphicsServicesSPI.h>
#import <wtf/BlockPtr.h>
#import <wtf/SystemTracing.h>
#import <wtf/cocoa/VectorCocoa.h>
#if ENABLE(DATA_DETECTION)
#import "WKDataDetectorTypesInternal.h"
#endif
#if HAVE(UI_EVENT_ATTRIBUTION)
#import <UIKit/UIEventAttribution.h>
#endif
#define FORWARD_ACTION_TO_WKCONTENTVIEW(_action) \
- (void)_action:(id)sender \
{ \
if (self.usesStandardContentView) \
[_contentView _action ## ForWebView:sender]; \
}
#define WKWEBVIEW_RELEASE_LOG(...) RELEASE_LOG(ViewState, __VA_ARGS__)
static const Seconds delayBeforeNoVisibleContentsRectsLogging = 1_s;
static const Seconds delayBeforeNoCommitsLogging = 5_s;
static const unsigned highlightMargin = 5;
static int32_t deviceOrientationForUIInterfaceOrientation(UIInterfaceOrientation orientation)
{
switch (orientation) {
case UIInterfaceOrientationUnknown:
case UIInterfaceOrientationPortrait:
return 0;
case UIInterfaceOrientationPortraitUpsideDown:
return 180;
case UIInterfaceOrientationLandscapeLeft:
return -90;
case UIInterfaceOrientationLandscapeRight:
return 90;
}
}
@interface UIView (UIViewInternal)
- (UIViewController *)_viewControllerForAncestor;
@end
@interface UIWindow (UIWindowInternal)
- (BOOL)_isHostedInAnotherProcess;
@end
@implementation WKWebView (WKViewInternalIOS)
- (void)setFrame:(CGRect)frame
{
CGRect oldFrame = self.frame;
[super setFrame:frame];
if (!CGSizeEqualToSize(oldFrame.size, frame.size))
[self _frameOrBoundsChanged];
}
- (void)setBounds:(CGRect)bounds
{
CGRect oldBounds = self.bounds;
[super setBounds:bounds];
[_customContentFixedOverlayView setFrame:self.bounds];
if (!CGSizeEqualToSize(oldBounds.size, bounds.size))
[self _frameOrBoundsChanged];
}
- (void)layoutSubviews
{
[_safeBrowsingWarning setFrame:self.bounds];
[super layoutSubviews];
[self _frameOrBoundsChanged];
}
#pragma mark - iOS implementation methods
- (void)_setupScrollAndContentViews
{
CGRect bounds = self.bounds;
_scrollView = adoptNS([[WKScrollView alloc] initWithFrame:bounds]);
[_scrollView setInternalDelegate:self];
[_scrollView setBouncesZoom:YES];
#if HAVE(UISCROLLVIEW_ASYNCHRONOUS_SCROLL_EVENT_HANDLING)
[_scrollView _setAllowsAsyncScrollEvent:YES];
#endif
if ([_scrollView respondsToSelector:@selector(_setAvoidsJumpOnInterruptedBounce:)]) {
[_scrollView setTracksImmediatelyWhileDecelerating:NO];
[_scrollView _setAvoidsJumpOnInterruptedBounce:YES];
}
[self _updateScrollViewInsetAdjustmentBehavior];
[self addSubview:_scrollView.get()];
[self _dispatchSetDeviceOrientation:[self _deviceOrientation]];
[_contentView layer].anchorPoint = CGPointZero;
[_contentView setFrame:bounds];
[_scrollView addSubview:_contentView.get()];
[_scrollView addSubview:[_contentView unscaledView]];
}
- (void)_registerForNotifications
{
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
[center addObserver:self selector:@selector(_keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];
[center addObserver:self selector:@selector(_keyboardDidChangeFrame:) name:UIKeyboardDidChangeFrameNotification object:nil];
[center addObserver:self selector:@selector(_keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[center addObserver:self selector:@selector(_keyboardDidShow:) name:UIKeyboardDidShowNotification object:nil];
[center addObserver:self selector:@selector(_keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
[center addObserver:self selector:@selector(_windowDidRotate:) name:UIWindowDidRotateNotification object:nil];
[center addObserver:self selector:@selector(_contentSizeCategoryDidChange:) name:UIContentSizeCategoryDidChangeNotification object:nil];
[center addObserver:self selector:@selector(_accessibilitySettingsDidChange:) name:UIAccessibilityGrayscaleStatusDidChangeNotification object:nil];
[center addObserver:self selector:@selector(_accessibilitySettingsDidChange:) name:UIAccessibilityInvertColorsStatusDidChangeNotification object:nil];
[center addObserver:self selector:@selector(_accessibilitySettingsDidChange:) name:UIAccessibilityReduceMotionStatusDidChangeNotification object:nil];
}
- (BOOL)_isShowingVideoPictureInPicture
{
#if ENABLE(VIDEO_PRESENTATION_MODE)
if (!_page || !_page->videoFullscreenManager())
return false;
return _page->videoFullscreenManager()->hasMode(WebCore::HTMLMediaElementEnums::VideoFullscreenModePictureInPicture);
#else
return false;
#endif
}
- (BOOL)_mayAutomaticallyShowVideoPictureInPicture
{
#if ENABLE(VIDEO_PRESENTATION_MODE)
if (!_page || !_page->videoFullscreenManager())
return false;
return _page->videoFullscreenManager()->mayAutomaticallyShowVideoPictureInPicture();
#else
return false;
#endif
}
- (void)_incrementFocusPreservationCount
{
++_focusPreservationCount;
}
- (void)_decrementFocusPreservationCount
{
if (_focusPreservationCount)
--_focusPreservationCount;
}
- (void)_resetFocusPreservationCount
{
_focusPreservationCount = 0;
}
- (BOOL)_isRetainingActiveFocusedState
{
// Focus preservation count fulfills the same role as active focus state count.
// However, unlike active focus state, it may be reset to 0 without impacting the
// behavior of -_retainActiveFocusedState, and it's harmless to invoke
// -_decrementFocusPreservationCount after resetting the count to 0.
return _focusPreservationCount || _activeFocusedStateRetainCount;
}
- (int32_t)_deviceOrientation
{
auto orientation = UIInterfaceOrientationUnknown;
auto application = UIApplication.sharedApplication;
ALLOW_DEPRECATED_DECLARATIONS_BEGIN
if (!application._appAdoptsUISceneLifecycle)
orientation = application.statusBarOrientation;
ALLOW_DEPRECATED_DECLARATIONS_END
else if (auto windowScene = self.window.windowScene)
orientation = windowScene.interfaceOrientation;
return deviceOrientationForUIInterfaceOrientation(orientation);
}
- (void)_dynamicUserInterfaceTraitDidChange
{
if (!_page)
return;
_page->effectiveAppearanceDidChange();
[self _updateScrollViewBackground];
}
- (BOOL)_effectiveAppearanceIsDark
{
return self.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark;
}
- (BOOL)_effectiveUserInterfaceLevelIsElevated
{
#if HAVE(OS_DARK_MODE_SUPPORT) && !PLATFORM(WATCHOS)
return self.traitCollection.userInterfaceLevel == UIUserInterfaceLevelElevated;
#else
return NO;
#endif
}
- (void)_populateArchivedSubviews:(NSMutableSet *)encodedViews
{
[super _populateArchivedSubviews:encodedViews];
if (_scrollView)
[encodedViews removeObject:_scrollView.get()];
if (_customContentFixedOverlayView)
[encodedViews removeObject:_customContentFixedOverlayView.get()];
}
- (BOOL)_isBackground
{
if (![self usesStandardContentView] && [_customContentView respondsToSelector:@selector(web_isBackground)])
return [_customContentView web_isBackground];
return [_contentView isBackground];
}
ALLOW_DEPRECATED_DECLARATIONS_BEGIN
- (WKBrowsingContextController *)browsingContextController
{
return [_contentView browsingContextController];
}
ALLOW_DEPRECATED_DECLARATIONS_END
- (BOOL)becomeFirstResponder
{
UIView *currentContentView = self._currentContentView;
if (currentContentView == _contentView && [_contentView superview])
return [_contentView becomeFirstResponderForWebView] || [super becomeFirstResponder];
return [currentContentView becomeFirstResponder] || [super becomeFirstResponder];
}
- (BOOL)canBecomeFirstResponder
{
if (self._currentContentView == _contentView)
return [_contentView canBecomeFirstResponderForWebView];
return YES;
}
- (BOOL)resignFirstResponder
{
if ([_contentView isFirstResponder])
return [_contentView resignFirstResponderForWebView];
return [super resignFirstResponder];
}
FOR_EACH_WKCONTENTVIEW_ACTION(FORWARD_ACTION_TO_WKCONTENTVIEW)
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
#define FORWARD_CANPERFORMACTION_TO_WKCONTENTVIEW(_action) \
if (action == @selector(_action:)) \
return self.usesStandardContentView && [_contentView canPerformActionForWebView:action withSender:sender];
FOR_EACH_WKCONTENTVIEW_ACTION(FORWARD_CANPERFORMACTION_TO_WKCONTENTVIEW)
FOR_EACH_PRIVATE_WKCONTENTVIEW_ACTION(FORWARD_CANPERFORMACTION_TO_WKCONTENTVIEW)
FORWARD_CANPERFORMACTION_TO_WKCONTENTVIEW(_setTextColor:sender)
FORWARD_CANPERFORMACTION_TO_WKCONTENTVIEW(_setFontSize:sender)
FORWARD_CANPERFORMACTION_TO_WKCONTENTVIEW(_setFont:sender)
#undef FORWARD_CANPERFORMACTION_TO_WKCONTENTVIEW
return [super canPerformAction:action withSender:sender];
}
- (id)targetForAction:(SEL)action withSender:(id)sender
{
#define FORWARD_TARGETFORACTION_TO_WKCONTENTVIEW(_action) \
if (action == @selector(_action:) && self.usesStandardContentView) \
return [_contentView targetForActionForWebView:action withSender:sender];
FOR_EACH_WKCONTENTVIEW_ACTION(FORWARD_TARGETFORACTION_TO_WKCONTENTVIEW)
FOR_EACH_PRIVATE_WKCONTENTVIEW_ACTION(FORWARD_TARGETFORACTION_TO_WKCONTENTVIEW)
FORWARD_TARGETFORACTION_TO_WKCONTENTVIEW(_setTextColor:sender)
FORWARD_TARGETFORACTION_TO_WKCONTENTVIEW(_setFontSize:sender)
FORWARD_TARGETFORACTION_TO_WKCONTENTVIEW(_setFont:sender)
#undef FORWARD_TARGETFORACTION_TO_WKCONTENTVIEW
return [super targetForAction:action withSender:sender];
}
- (void)willFinishIgnoringCalloutBarFadeAfterPerformingAction
{
[_contentView willFinishIgnoringCalloutBarFadeAfterPerformingAction];
}
static inline CGFloat floorToDevicePixel(CGFloat input, float deviceScaleFactor)
{
return CGFloor(input * deviceScaleFactor) / deviceScaleFactor;
}
static inline bool pointsEqualInDevicePixels(CGPoint a, CGPoint b, float deviceScaleFactor)
{
return fabs(a.x * deviceScaleFactor - b.x * deviceScaleFactor) < std::numeric_limits<float>::epsilon()
&& fabs(a.y * deviceScaleFactor - b.y * deviceScaleFactor) < std::numeric_limits<float>::epsilon();
}
static CGSize roundScrollViewContentSize(const WebKit::WebPageProxy& page, CGSize contentSize)
{
float deviceScaleFactor = page.deviceScaleFactor();
return CGSizeMake(floorToDevicePixel(contentSize.width, deviceScaleFactor), floorToDevicePixel(contentSize.height, deviceScaleFactor));
}
- (UIView *)_currentContentView
{
return _customContentView ? [_customContentView web_contentView] : _contentView.get();
}
- (WKWebViewContentProviderRegistry *)_contentProviderRegistry
{
return [_configuration _contentProviderRegistry];
}
- (WKSelectionGranularity)_selectionGranularity
{
return [_configuration selectionGranularity];
}
- (void)_setHasCustomContentView:(BOOL)pageHasCustomContentView loadedMIMEType:(const WTF::String&)mimeType
{
Class representationClass = nil;
if (pageHasCustomContentView)
representationClass = [[_configuration _contentProviderRegistry] providerForMIMEType:mimeType];
if (pageHasCustomContentView && representationClass) {
[_customContentView removeFromSuperview];
[_customContentFixedOverlayView removeFromSuperview];
_customContentView = adoptNS([[representationClass alloc] web_initWithFrame:self.bounds webView:self mimeType:mimeType]);
_customContentFixedOverlayView = adoptNS([[UIView alloc] initWithFrame:self.bounds]);
[_customContentFixedOverlayView layer].name = @"CustomContentFixedOverlay";
[_customContentFixedOverlayView setUserInteractionEnabled:NO];
[[_contentView unscaledView] removeFromSuperview];
[_contentView removeFromSuperview];
[_scrollView addSubview:_customContentView.get()];
[self addSubview:_customContentFixedOverlayView.get()];
[_customContentView web_setMinimumSize:self.bounds.size];
[_customContentView web_setFixedOverlayView:_customContentFixedOverlayView.get()];
_scrollViewBackgroundColor = WebCore::Color();
[_scrollView setContentOffset:[self _initialContentOffsetForScrollView]];
[_scrollView _setScrollEnabledInternal:YES];
[self _setAvoidsUnsafeArea:NO];
} else if (_customContentView) {
[_customContentView removeFromSuperview];
_customContentView = nullptr;
[_customContentFixedOverlayView removeFromSuperview];
_customContentFixedOverlayView = nullptr;
[_scrollView addSubview:_contentView.get()];
[_scrollView addSubview:[_contentView unscaledView]];
[_scrollView setContentSize:roundScrollViewContentSize(*_page, [_contentView frame].size)];
[_customContentFixedOverlayView setFrame:self.bounds];
[self addSubview:_customContentFixedOverlayView.get()];
}
if (self.isFirstResponder) {
UIView *currentContentView = self._currentContentView;
if (currentContentView == _contentView ? [_contentView canBecomeFirstResponderForWebView] : currentContentView.canBecomeFirstResponder)
[currentContentView becomeFirstResponder];
}
}
- (void)_didFinishLoadingDataForCustomContentProviderWithSuggestedFilename:(const String&)suggestedFilename data:(NSData *)data
{
ASSERT(_customContentView);
[_customContentView web_setContentProviderData:data suggestedFilename:suggestedFilename];
// FIXME: It may make more sense for custom content providers to invoke this when they're ready,
// because there's no guarantee that all custom content providers will lay out synchronously.
_page->didLayoutForCustomContentProvider();
}
- (void)_handleKeyUIEvent:(::UIEvent *)event
{
// We only want to handle key events from the hardware keyboard when we are
// first responder and a custom content view is installed; otherwise,
// WKContentView will be the first responder and expects to get key events directly.
if ([self isFirstResponder] && event._hidEvent) {
if ([_customContentView respondsToSelector:@selector(web_handleKeyEvent:)]) {
if ([_customContentView web_handleKeyEvent:event])
return;
}
}
[super _handleKeyUIEvent:event];
}
- (void)_willInvokeUIScrollViewDelegateCallback
{
_invokingUIScrollViewDelegateCallback = YES;
}
- (void)_didInvokeUIScrollViewDelegateCallback
{
_invokingUIScrollViewDelegateCallback = NO;
if (_didDeferUpdateVisibleContentRectsForUIScrollViewDelegateCallback) {
_didDeferUpdateVisibleContentRectsForUIScrollViewDelegateCallback = NO;
[self _scheduleVisibleContentRectUpdate];
}
}
static CGFloat contentZoomScale(WKWebView *webView)
{
CGFloat scale = webView._currentContentView.layer.affineTransform.a;
ASSERT(scale == [webView->_scrollView zoomScale]);
return scale;
}
enum class AllowPageBackgroundColorOverride : bool { No, Yes };
static WebCore::Color baseScrollViewBackgroundColor(WKWebView *webView, AllowPageBackgroundColorOverride allowPageBackgroundColorOverride)
{
if (webView->_customContentView)
return WebCore::roundAndClampToSRGBALossy([webView->_customContentView backgroundColor].CGColor);
if (webView->_gestureController) {
WebCore::Color color = webView->_gestureController->backgroundColorForCurrentSnapshot();
if (color.isValid())
return color;
}
if (!webView->_page)
return { };
return allowPageBackgroundColorOverride == AllowPageBackgroundColorOverride::Yes ? webView->_page->underPageBackgroundColor() : webView->_page->pageExtendedBackgroundColor();
}
static WebCore::Color scrollViewBackgroundColor(WKWebView *webView, AllowPageBackgroundColorOverride allowPageBackgroundColorOverride)
{
if (!webView.opaque)
return WebCore::Color::transparentBlack;
#if HAVE(OS_DARK_MODE_SUPPORT)
WebCore::LocalCurrentTraitCollection localTraitCollection(webView.traitCollection);
#endif
WebCore::Color color = baseScrollViewBackgroundColor(webView, allowPageBackgroundColorOverride);
if (!color.isValid() && webView->_contentView)
color = WebCore::roundAndClampToSRGBALossy([webView->_contentView backgroundColor].CGColor);
if (!color.isValid()) {
#if HAVE(OS_DARK_MODE_SUPPORT)
color = WebCore::roundAndClampToSRGBALossy(UIColor.systemBackgroundColor.CGColor);
#else
color = WebCore::Color::white;
#endif
}
CGFloat zoomScale = contentZoomScale(webView);
CGFloat minimumZoomScale = [webView->_scrollView minimumZoomScale];
if (zoomScale < minimumZoomScale) {
CGFloat slope = 12;
CGFloat opacity = std::max<CGFloat>(1 - slope * (minimumZoomScale - zoomScale), 0);
color = color.colorWithAlpha(opacity);
}
return color;
}
- (void)_updateScrollViewBackground
{
auto newScrollViewBackgroundColor = scrollViewBackgroundColor(self, AllowPageBackgroundColorOverride::Yes);
if (_scrollViewBackgroundColor != newScrollViewBackgroundColor) {
_scrollViewBackgroundColor = newScrollViewBackgroundColor;
auto uiBackgroundColor = adoptNS([[UIColor alloc] initWithCGColor:cachedCGColor(newScrollViewBackgroundColor)]);
[_scrollView setBackgroundColor:uiBackgroundColor.get()];
}
// Update the indicator style based on the lightness/darkness of the background color.
auto newPageBackgroundColor = scrollViewBackgroundColor(self, AllowPageBackgroundColorOverride::No);
if (newPageBackgroundColor.lightness() <= .5f && newPageBackgroundColor.isVisible())
[_scrollView setIndicatorStyle:UIScrollViewIndicatorStyleWhite];
else
[_scrollView setIndicatorStyle:UIScrollViewIndicatorStyleBlack];
}
- (void)_videoControlsManagerDidChange
{
#if ENABLE(FULLSCREEN_API)
if (_fullScreenWindowController)
[_fullScreenWindowController videoControlsManagerDidChange];
#endif
}
- (CGPoint)_initialContentOffsetForScrollView
{
auto combinedUnobscuredAndScrollViewInset = [self _computedContentInset];
return CGPointMake(-combinedUnobscuredAndScrollViewInset.left, -combinedUnobscuredAndScrollViewInset.top);
}
- (CGPoint)_contentOffsetAdjustedForObscuredInset:(CGPoint)point
{
CGPoint result = point;
UIEdgeInsets contentInset = [self _computedObscuredInset];
result.x -= contentInset.left;
result.y -= contentInset.top;
return result;
}
- (UIRectEdge)_effectiveObscuredInsetEdgesAffectedBySafeArea
{
if (![self usesStandardContentView])
return UIRectEdgeAll;
return _obscuredInsetEdgesAffectedBySafeArea;
}
- (UIEdgeInsets)_computedObscuredInsetForSafeBrowsingWarning
{
if (_haveSetObscuredInsets)
return _obscuredInsets;
return UIEdgeInsetsAdd(UIEdgeInsetsZero, self._scrollViewSystemContentInset, self._effectiveObscuredInsetEdgesAffectedBySafeArea);
}
- (UIEdgeInsets)_contentInsetsFromSystemMinimumLayoutMargins
{
if (auto controller = [UIViewController _viewControllerForFullScreenPresentationFromView:self]) {
auto margins = controller.systemMinimumLayoutMargins;
auto insets = UIEdgeInsetsMake(margins.top, margins.leading, margins.bottom, margins.trailing);
if (_page && _page->userInterfaceLayoutDirection() == WebCore::UserInterfaceLayoutDirection::RTL)
std::swap(insets.left, insets.right);
if (auto view = controller.viewIfLoaded) {
auto adjustInsetEdge = [](CGFloat& insetEdge, CGFloat distanceFromEdge) {
insetEdge -= std::max<CGFloat>(0, distanceFromEdge);
insetEdge = std::max<CGFloat>(0, insetEdge);
};
auto viewBounds = view.bounds;
auto webViewBoundsInView = [self convertRect:self.bounds toView:view];
adjustInsetEdge(insets.top, CGRectGetMinY(webViewBoundsInView) - CGRectGetMinY(viewBounds));
adjustInsetEdge(insets.left, CGRectGetMinX(webViewBoundsInView) - CGRectGetMinX(viewBounds));
adjustInsetEdge(insets.bottom, CGRectGetMaxY(viewBounds) - CGRectGetMaxY(webViewBoundsInView));
adjustInsetEdge(insets.right, CGRectGetMaxX(viewBounds) - CGRectGetMaxX(webViewBoundsInView));
}
return insets;
}
return UIEdgeInsetsZero;
}
- (UIEdgeInsets)_computedObscuredInset
{
if (!linkedOnOrAfter(WebCore::SDKVersion::FirstWhereScrollViewContentInsetsAreNotObscuringInsets)) {
// For binary compability with third party apps, treat scroll view content insets as obscuring insets when the app is compiled
// against a WebKit version without the fix in r229641.
return [self _computedContentInset];
}
if (_haveSetObscuredInsets)
return _obscuredInsets;
if (self._safeAreaShouldAffectObscuredInsets)
return UIEdgeInsetsAdd(UIEdgeInsetsZero, self._scrollViewSystemContentInset, self._effectiveObscuredInsetEdgesAffectedBySafeArea);
return UIEdgeInsetsZero;
}
- (UIEdgeInsets)_computedContentInset
{
if (_haveSetObscuredInsets)
return _obscuredInsets;
UIEdgeInsets insets = [_scrollView contentInset];
if (self._safeAreaShouldAffectObscuredInsets) {
#if PLATFORM(WATCHOS)
// On watchOS, PepperUICore swizzles -[UIScrollView contentInset], such that it includes -_contentScrollInset as well.
// To avoid double-counting -_contentScrollInset when determining the total content inset, we only apply safe area insets here.
auto additionalScrollViewContentInset = self.safeAreaInsets;
#else
auto additionalScrollViewContentInset = self._scrollViewSystemContentInset;
#endif
insets = UIEdgeInsetsAdd(insets, additionalScrollViewContentInset, self._effectiveObscuredInsetEdgesAffectedBySafeArea);
}
return insets;
}
- (UIEdgeInsets)_computedUnobscuredSafeAreaInset
{
if (_haveSetUnobscuredSafeAreaInsets)
return _unobscuredSafeAreaInsets;
if (!self._safeAreaShouldAffectObscuredInsets) {
auto safeAreaInsets = self.safeAreaInsets;
#if PLATFORM(WATCHOS)
safeAreaInsets = UIEdgeInsetsAdd(safeAreaInsets, self._contentInsetsFromSystemMinimumLayoutMargins, self._effectiveObscuredInsetEdgesAffectedBySafeArea);
#endif
return safeAreaInsets;
}
return UIEdgeInsetsZero;
}
- (void)_processWillSwapOrDidExit
{
// FIXME: Which ones of these need to be done in the process swap case and which ones in the exit case?
[self _hidePasswordView];
[self _cancelAnimatedResize];
if (_gestureController)
_gestureController->disconnectFromProcess();
_viewportMetaTagWidth = WebCore::ViewportArguments::ValueAuto;
_initialScaleFactor = 1;
_hasCommittedLoadForMainFrame = NO;
_needsResetViewStateAfterCommitLoadForMainFrame = NO;
_dynamicViewportUpdateMode = WebKit::DynamicViewportUpdateMode::NotResizing;
_waitingForEndAnimatedResize = NO;
_waitingForCommitAfterAnimatedResize = NO;
_animatedResizeOriginalContentWidth = 0;
_animatedResizeOldBounds = { };
[_contentView setHidden:NO];
_scrollOffsetToRestore = std::nullopt;
_unobscuredCenterToRestore = std::nullopt;
_scrollViewBackgroundColor = WebCore::Color();
_invokingUIScrollViewDelegateCallback = NO;
_didDeferUpdateVisibleContentRectsForUIScrollViewDelegateCallback = NO;
_didDeferUpdateVisibleContentRectsForAnyReason = NO;
_didDeferUpdateVisibleContentRectsForUnstableScrollView = NO;
_currentlyAdjustingScrollViewInsetsForKeyboard = NO;
_lastSentViewLayoutSize = std::nullopt;
_lastSentMaximumUnobscuredSize = std::nullopt;
_lastSentDeviceOrientation = std::nullopt;
_frozenVisibleContentRect = std::nullopt;
_frozenUnobscuredContentRect = std::nullopt;
_firstPaintAfterCommitLoadTransactionID = { };
_firstTransactionIDAfterPageRestore = std::nullopt;
_lastTransactionID = { };
_hasScheduledVisibleRectUpdate = NO;
_commitDidRestoreScrollPosition = NO;
_avoidsUnsafeArea = YES;
}
- (void)_processWillSwap
{
WKWEBVIEW_RELEASE_LOG("%p -[WKWebView _processWillSwap]", self);
[self _processWillSwapOrDidExit];
}
- (void)_processDidExit
{
WKWEBVIEW_RELEASE_LOG("%p -[WKWebView _processDidExit]", self);
[self _processWillSwapOrDidExit];
[_contentView setFrame:self.bounds];
[_scrollView setBackgroundColor:[_contentView backgroundColor]];
[_scrollView setContentOffset:[self _initialContentOffsetForScrollView]];
[_scrollView setZoomScale:1];
}
- (void)_didRelaunchProcess
{
WKWEBVIEW_RELEASE_LOG("%p -[WKWebView _didRelaunchProcess]", self);
_hasScheduledVisibleRectUpdate = NO;
_viewStabilityWhenVisibleContentRectUpdateScheduled = { };
if (_gestureController)
_gestureController->connectToProcess();
}
- (void)_didCommitLoadForMainFrame
{
_firstPaintAfterCommitLoadTransactionID = downcast<WebKit::RemoteLayerTreeDrawingAreaProxy>(*_page->drawingArea()).nextLayerTreeTransactionID();
_hasCommittedLoadForMainFrame = YES;
_needsResetViewStateAfterCommitLoadForMainFrame = YES;
if (![self _scrollViewIsRubberBandingForRefreshControl])
[_scrollView _stopScrollingAndZoomingAnimations];
}
static CGPoint contentOffsetBoundedInValidRange(UIScrollView *scrollView, CGPoint contentOffset)
{
// FIXME: Likely we can remove this special case for watchOS and tvOS.
#if !PLATFORM(WATCHOS) && !PLATFORM(APPLETV)
UIEdgeInsets contentInsets = scrollView.adjustedContentInset;
#else
UIEdgeInsets contentInsets = scrollView.contentInset;
#endif
CGSize contentSize = scrollView.contentSize;
CGSize scrollViewSize = scrollView.bounds.size;
CGPoint minimumContentOffset = CGPointMake(-contentInsets.left, -contentInsets.top);
CGPoint maximumContentOffset = CGPointMake(std::max(minimumContentOffset.x, contentSize.width + contentInsets.right - scrollViewSize.width), std::max(minimumContentOffset.y, contentSize.height + contentInsets.bottom - scrollViewSize.height));
return CGPointMake(std::max(std::min(contentOffset.x, maximumContentOffset.x), minimumContentOffset.x), std::max(std::min(contentOffset.y, maximumContentOffset.y), minimumContentOffset.y));
}
static void changeContentOffsetBoundedInValidRange(UIScrollView *scrollView, WebCore::FloatPoint contentOffset)
{
scrollView.contentOffset = contentOffsetBoundedInValidRange(scrollView, contentOffset);
}
- (WebCore::FloatRect)visibleRectInViewCoordinates
{
WebCore::FloatRect bounds = self.bounds;
bounds.moveBy([_scrollView contentOffset]);
WebCore::FloatRect contentViewBounds = [_contentView bounds];
bounds.intersect(contentViewBounds);
return bounds;
}
- (void)_didCommitLayerTreeDuringAnimatedResize:(const WebKit::RemoteLayerTreeTransaction&)layerTreeTransaction
{
auto updateID = layerTreeTransaction.dynamicViewportSizeUpdateID();
if (updateID != _currentDynamicViewportSizeUpdateID)
return;
double pageScale = layerTreeTransaction.pageScaleFactor();
WebCore::IntPoint scrollPosition = layerTreeTransaction.scrollPosition();
CGFloat animatingScaleTarget = [[_resizeAnimationView layer] transform].m11;
double currentTargetScale = animatingScaleTarget * [[_contentView layer] transform].m11;
double scale = pageScale / currentTargetScale;
_resizeAnimationTransformAdjustments = CATransform3DMakeScale(scale, scale, 1);
CGPoint newContentOffset = [self _contentOffsetAdjustedForObscuredInset:CGPointMake(scrollPosition.x() * pageScale, scrollPosition.y() * pageScale)];
CGPoint currentContentOffset = [_scrollView contentOffset];
_resizeAnimationTransformAdjustments.m41 = (currentContentOffset.x - newContentOffset.x) / animatingScaleTarget;
_resizeAnimationTransformAdjustments.m42 = (currentContentOffset.y - newContentOffset.y) / animatingScaleTarget;
[_resizeAnimationView layer].sublayerTransform = _resizeAnimationTransformAdjustments;
// If we've already passed endAnimatedResize, immediately complete
// the resize when we have an up-to-date layer tree. Otherwise,
// we will defer completion until endAnimatedResize.
_waitingForCommitAfterAnimatedResize = NO;
if (!_waitingForEndAnimatedResize)
[self _didCompleteAnimatedResize];
}
- (void)_trackTransactionCommit:(const WebKit::RemoteLayerTreeTransaction&)layerTreeTransaction
{
if (_didDeferUpdateVisibleContentRectsForUnstableScrollView) {
WKWEBVIEW_RELEASE_LOG("%p (pageProxyID=%llu) -[WKWebView _didCommitLayerTree:] - received a commit (%llu) while deferring visible content rect updates (_dynamicViewportUpdateMode %d, _needsResetViewStateAfterCommitLoadForMainFrame %d (wants commit %llu), sizeChangedSinceLastVisibleContentRectUpdate %d, [_scrollView isZoomBouncing] %d, _currentlyAdjustingScrollViewInsetsForKeyboard %d)",
self, _page->identifier().toUInt64(), layerTreeTransaction.transactionID().toUInt64(), _dynamicViewportUpdateMode, _needsResetViewStateAfterCommitLoadForMainFrame, _firstPaintAfterCommitLoadTransactionID.toUInt64(), [_contentView sizeChangedSinceLastVisibleContentRectUpdate], [_scrollView isZoomBouncing], _currentlyAdjustingScrollViewInsetsForKeyboard);
}
if (_timeOfFirstVisibleContentRectUpdateWithPendingCommit) {
auto timeSinceFirstRequestWithPendingCommit = MonotonicTime::now() - *_timeOfFirstVisibleContentRectUpdateWithPendingCommit;
if (timeSinceFirstRequestWithPendingCommit > delayBeforeNoCommitsLogging)
WKWEBVIEW_RELEASE_LOG("%p (pageProxyID=%llu) -[WKWebView _didCommitLayerTree:] - finally received commit %.2fs after visible content rect update request; transactionID %llu", self, _page->identifier().toUInt64(), timeSinceFirstRequestWithPendingCommit.value(), layerTreeTransaction.transactionID().toUInt64());
_timeOfFirstVisibleContentRectUpdateWithPendingCommit = std::nullopt;
}
}
- (void)_updateScrollViewForTransaction:(const WebKit::RemoteLayerTreeTransaction&)layerTreeTransaction
{
CGSize newContentSize = roundScrollViewContentSize(*_page, [_contentView frame].size);
[_scrollView _setContentSizePreservingContentOffsetDuringRubberband:newContentSize];
[_scrollView setMinimumZoomScale:layerTreeTransaction.minimumScaleFactor()];
[_scrollView setMaximumZoomScale:layerTreeTransaction.maximumScaleFactor()];
[_scrollView _setZoomEnabledInternal:layerTreeTransaction.allowsUserScaling()];
bool hasDockedInputView = !CGRectIsEmpty(_inputViewBoundsInWindow);
bool isZoomed = layerTreeTransaction.pageScaleFactor() > layerTreeTransaction.initialScaleFactor();
bool scrollingNeededToRevealUI = false;
if (_maximumUnobscuredSizeOverride) {
auto unobscuredContentRect = _page->unobscuredContentRect();
auto maxUnobscuredSize = _page->maximumUnobscuredSize();
scrollingNeededToRevealUI = maxUnobscuredSize.width() == unobscuredContentRect.width() && maxUnobscuredSize.height() == unobscuredContentRect.height();
}
bool scrollingEnabled = _page->scrollingCoordinatorProxy()->hasScrollableOrZoomedMainFrame() || hasDockedInputView || isZoomed || scrollingNeededToRevealUI;
[_scrollView _setScrollEnabledInternal:scrollingEnabled];
if (!layerTreeTransaction.scaleWasSetByUIProcess() && ![_scrollView isZooming] && ![_scrollView isZoomBouncing] && ![_scrollView _isAnimatingZoom] && [_scrollView zoomScale] != layerTreeTransaction.pageScaleFactor()) {
LOG_WITH_STREAM(VisibleRects, stream << " updating scroll view with pageScaleFactor " << layerTreeTransaction.pageScaleFactor());
[_scrollView setZoomScale:layerTreeTransaction.pageScaleFactor()];
}
}
- (BOOL)_restoreScrollAndZoomStateForTransaction:(const WebKit::RemoteLayerTreeTransaction&)layerTreeTransaction
{
if (!_firstTransactionIDAfterPageRestore || layerTreeTransaction.transactionID() < _firstTransactionIDAfterPageRestore.value())
return NO;
_firstTransactionIDAfterPageRestore = std::nullopt;
BOOL needUpdateVisibleContentRects = NO;
if (_scrollOffsetToRestore && ![self _scrollViewIsRubberBandingForRefreshControl]) {
WebCore::FloatPoint scaledScrollOffset = _scrollOffsetToRestore.value();
_scrollOffsetToRestore = std::nullopt;
if (WTF::areEssentiallyEqual<float>(contentZoomScale(self), _scaleToRestore)) {
scaledScrollOffset.scale(_scaleToRestore);
WebCore::FloatPoint contentOffsetInScrollViewCoordinates = scaledScrollOffset - WebCore::FloatSize(_obscuredInsetsWhenSaved.left(), _obscuredInsetsWhenSaved.top());
changeContentOffsetBoundedInValidRange(_scrollView.get(), contentOffsetInScrollViewCoordinates);
_commitDidRestoreScrollPosition = YES;
}
needUpdateVisibleContentRects = YES;
}
if (_unobscuredCenterToRestore && ![self _scrollViewIsRubberBandingForRefreshControl]) {
WebCore::FloatPoint unobscuredCenterToRestore = _unobscuredCenterToRestore.value();
_unobscuredCenterToRestore = std::nullopt;
if (WTF::areEssentiallyEqual<float>(contentZoomScale(self), _scaleToRestore)) {
CGRect unobscuredRect = UIEdgeInsetsInsetRect(self.bounds, _obscuredInsets);
WebCore::FloatSize unobscuredContentSizeAtNewScale = WebCore::FloatSize(unobscuredRect.size) / _scaleToRestore;
WebCore::FloatPoint topLeftInDocumentCoordinates = unobscuredCenterToRestore - unobscuredContentSizeAtNewScale / 2;
topLeftInDocumentCoordinates.scale(_scaleToRestore);
topLeftInDocumentCoordinates.moveBy(WebCore::FloatPoint(-_obscuredInsets.left, -_obscuredInsets.top));
changeContentOffsetBoundedInValidRange(_scrollView.get(), topLeftInDocumentCoordinates);
}
needUpdateVisibleContentRects = YES;
}
if (_gestureController)
_gestureController->didRestoreScrollPosition();
return needUpdateVisibleContentRects;
}
- (void)_didCommitLayerTree:(const WebKit::RemoteLayerTreeTransaction&)layerTreeTransaction
{
[self _trackTransactionCommit:layerTreeTransaction];
_lastTransactionID = layerTreeTransaction.transactionID();
if (![self usesStandardContentView])
return;
LOG_WITH_STREAM(VisibleRects, stream << "-[WKWebView " << _page->identifier() << " _didCommitLayerTree:] transactionID " << layerTreeTransaction.transactionID() << " _dynamicViewportUpdateMode " << (int)_dynamicViewportUpdateMode);
bool needUpdateVisibleContentRects = _page->updateLayoutViewportParameters(layerTreeTransaction);
if (_dynamicViewportUpdateMode != WebKit::DynamicViewportUpdateMode::NotResizing) {
[self _didCommitLayerTreeDuringAnimatedResize:layerTreeTransaction];
return;
}
if (_resizeAnimationView)
WKWEBVIEW_RELEASE_LOG("%p -[WKWebView _didCommitLayerTree:] - dynamicViewportUpdateMode is NotResizing, but still have a live resizeAnimationView (unpaired begin/endAnimatedResize?)", self);
[self _updateScrollViewForTransaction:layerTreeTransaction];
_viewportMetaTagWidth = layerTreeTransaction.viewportMetaTagWidth();
_viewportMetaTagWidthWasExplicit = layerTreeTransaction.viewportMetaTagWidthWasExplicit();
_viewportMetaTagCameFromImageDocument = layerTreeTransaction.viewportMetaTagCameFromImageDocument();
_initialScaleFactor = layerTreeTransaction.initialScaleFactor();
if (_page->inStableState() && layerTreeTransaction.isInStableState() && [_stableStatePresentationUpdateCallbacks count]) {
for (dispatch_block_t action in _stableStatePresentationUpdateCallbacks.get())
action();
[_stableStatePresentationUpdateCallbacks removeAllObjects];
_stableStatePresentationUpdateCallbacks = nil;
}
if (![_contentView _mayDisableDoubleTapGesturesDuringSingleTap])
[_contentView _setDoubleTapGesturesEnabled:self._allowsDoubleTapGestures];
[self _updateScrollViewBackground];
[self _setAvoidsUnsafeArea:layerTreeTransaction.avoidsUnsafeArea()];
if (_gestureController)
_gestureController->setRenderTreeSize(layerTreeTransaction.renderTreeSize());
if (_needsResetViewStateAfterCommitLoadForMainFrame && layerTreeTransaction.transactionID() >= _firstPaintAfterCommitLoadTransactionID) {
_needsResetViewStateAfterCommitLoadForMainFrame = NO;
if (![self _scrollViewIsRubberBandingForRefreshControl])
[_scrollView setContentOffset:[self _initialContentOffsetForScrollView]];
if (_observedRenderingProgressEvents & _WKRenderingProgressEventFirstPaint)
_navigationState->didFirstPaint();
needUpdateVisibleContentRects = true;
}
if ([self _restoreScrollAndZoomStateForTransaction:layerTreeTransaction])
needUpdateVisibleContentRects = true;
if (needUpdateVisibleContentRects)
[self _scheduleVisibleContentRectUpdate];
if (WebKit::RemoteLayerTreeScrollingPerformanceData* scrollPerfData = _page->scrollingPerformanceData())
scrollPerfData->didCommitLayerTree([self visibleRectInViewCoordinates]);
}
- (void)_layerTreeCommitComplete
{
_commitDidRestoreScrollPosition = NO;
}
- (void)_couldNotRestorePageState
{
// The gestureController may be waiting for the scroll position to be restored
// in order to remove the swipe snapshot. Since the scroll position could not be
// restored, tell the gestureController it was restored so that it no longer waits
// for it.
if (_gestureController)
_gestureController->didRestoreScrollPosition();
}
- (void)_restorePageScrollPosition:(std::optional<WebCore::FloatPoint>)scrollPosition scrollOrigin:(WebCore::FloatPoint)scrollOrigin previousObscuredInset:(WebCore::FloatBoxExtent)obscuredInsets scale:(double)scale
{
if (_dynamicViewportUpdateMode != WebKit::DynamicViewportUpdateMode::NotResizing) {
// Defer scroll position restoration until after the current resize completes.
RetainPtr<WKWebView> retainedSelf = self;
_callbacksDeferredDuringResize.append([retainedSelf, scrollPosition, scrollOrigin, obscuredInsets, scale] {
[retainedSelf _restorePageScrollPosition:scrollPosition scrollOrigin:scrollOrigin previousObscuredInset:obscuredInsets scale:scale];