Fix the iOS build
[WebKit-https.git] / Source / WebKit / mac / WebView / WebView.mm
index a984104..6c66875 100644 (file)
@@ -97,6 +97,7 @@
 #import "WebProgressTrackerClient.h"
 #import "WebScriptDebugDelegate.h"
 #import "WebScriptWorldInternal.h"
+#import "WebSelectionServiceController.h"
 #import "WebStorageManagerInternal.h"
 #import "WebSystemInterface.h"
 #import "WebTextCompletionController.h"
 #import <WebCore/GCController.h>
 #import <WebCore/GeolocationController.h>
 #import <WebCore/GeolocationError.h>
-#import <WebCore/HTMLMediaElement.h>
 #import <WebCore/HTMLNames.h>
+#import <WebCore/HTMLVideoElement.h>
 #import <WebCore/HistoryController.h>
 #import <WebCore/HistoryItem.h>
 #import <WebCore/IconDatabase.h>
 #import <WebCore/MIMETypeRegistry.h>
 #import <WebCore/MainFrame.h>
 #import <WebCore/MemoryPressureHandler.h>
+#import <WebCore/NSURLFileTypeMappingsSPI.h>
 #import <WebCore/NodeList.h>
 #import <WebCore/Notification.h>
 #import <WebCore/NotificationController.h>
 #import <wtf/StdLibExtras.h>
 
 #if !PLATFORM(IOS)
+#import "WebActionMenuController.h"
 #import "WebContextMenuClient.h"
 #import "WebFullScreenController.h"
 #import "WebNSEventExtras.h"
 #import "WebNSPasteboardExtras.h"
 #import "WebNSPrintOperationExtras.h"
 #import "WebPDFView.h"
+#import <WebCore/NSViewSPI.h>
 #import <WebCore/WebVideoFullscreenController.h>
 #else
 #import "MemoryMeasure.h"
 #import <WebKitLegacy/WebDashboardRegion.h>
 #endif
 
-#if ENABLE(DISK_IMAGE_CACHE) && PLATFORM(IOS)
-#import "WebDiskImageCacheClientIOS.h"
-#import <WebCore/DiskImageCacheIOS.h>
-#endif
-
 #if ENABLE(REMOTE_INSPECTOR)
 #import <JavaScriptCore/RemoteInspector.h>
 #if PLATFORM(IOS)
 #include <WebCore/QuickLook.h>
 #endif
 
-#if ENABLE(TOUCH_EVENTS)
+#if ENABLE(IOS_TOUCH_EVENTS)
 #import <WebCore/WebEventRegion.h>
 #endif
 
-#if ENABLE(DISK_IMAGE_CACHE)
-#import "WebDiskImageCacheClientIOS.h"
-#import <WebCore/DiskImageCacheIOS.h>
+#if ENABLE(GAMEPAD)
+#import <WebCore/HIDGamepadProvider.h>
 #endif
 
 #if !PLATFORM(IOS)
 - (NSView *)_hitTest:(NSPoint *)aPoint dragTypes:(NSSet *)types;
 - (void)_autoscrollForDraggingInfo:(id)dragInfo timeDelta:(NSTimeInterval)repeatDelta;
 - (BOOL)_shouldAutoscrollForDraggingInfo:(id)dragInfo;
+- (void)_windowChangedKeyState;
 @end
 
 @interface NSWindow (WebNSWindowDetails)
@@ -673,22 +672,14 @@ static CFMutableSetRef allWebViewsSet;
 
 @implementation WebView (WebPrivate)
 
-static String userVisibleWebKitVersionString()
+static String webKitBundleVersionString()
 {
-    // If the version is longer than 3 digits then the leading digits represent the version of the OS. Our user agent
-    // string should not include the leading digits, so strip them off and report the rest as the version. <rdar://problem/4997547>
-    NSString *fullVersion = [[NSBundle bundleForClass:[WebView class]] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey];
-    NSRange nonDigitRange = [fullVersion rangeOfCharacterFromSet:[[NSCharacterSet decimalDigitCharacterSet] invertedSet]];
-    if (nonDigitRange.location == NSNotFound && fullVersion.length > 3)
-        return [fullVersion substringFromIndex:fullVersion.length - 3];
-    if (nonDigitRange.location != NSNotFound && nonDigitRange.location > 3)
-        return [fullVersion substringFromIndex:nonDigitRange.location - 3];
-    return fullVersion;
+    return [[NSBundle bundleForClass:[WebView class]] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey];
 }
 
 + (NSString *)_standardUserAgentWithApplicationName:(NSString *)applicationName
 {
-    return standardUserAgentWithApplicationName(applicationName, userVisibleWebKitVersionString());
+    return standardUserAgentWithApplicationName(applicationName, webKitBundleVersionString());
 }
 
 #if PLATFORM(IOS)
@@ -838,6 +829,18 @@ static bool shouldUseLegacyBackgroundSizeShorthandBehavior()
     return shouldUseLegacyBackgroundSizeShorthandBehavior;
 }
 
+#if ENABLE(GAMEPAD)
+static void WebKitInitializeGamepadProviderIfNecessary()
+{
+    static bool initialized = false;
+    if (initialized)
+        return;
+
+    GamepadProvider::shared().setSharedProvider(HIDGamepadProvider::shared());
+    initialized = true;
+}
+#endif
+
 - (void)_commonInitializationWithFrameName:(NSString *)frameName groupName:(NSString *)groupName
 {
     WebCoreThreadViolationCheckRoundTwo();
@@ -893,8 +896,8 @@ static bool shouldUseLegacyBackgroundSizeShorthandBehavior()
 #endif
         WebKitInitializeStorageIfNecessary();
         WebKitInitializeApplicationCachePathIfNecessary();
-#if ENABLE(DISK_IMAGE_CACHE) && PLATFORM(IOS)
-        WebKitInitializeWebDiskImageCache();
+#if ENABLE(GAMEPAD)
+        WebKitInitializeGamepadProviderIfNecessary();
 #endif
         
         Settings::setDefaultMinDOMTimerInterval(0.004);
@@ -1037,12 +1040,8 @@ static bool shouldUseLegacyBackgroundSizeShorthandBehavior()
 #endif
 }
 
-- (id)_initWithFrame:(NSRect)f frameName:(NSString *)frameName groupName:(NSString *)groupName usesDocumentViews:(BOOL)usesDocumentViews
+- (id)_initWithFrame:(NSRect)f frameName:(NSString *)frameName groupName:(NSString *)groupName
 {
-    // FIXME: Remove the usesDocumentViews parameter; it's only here for compatibility with WebKit nightly builds
-    // running against Safari 5 on Leopard.
-    ASSERT(usesDocumentViews);
-
     self = [super initWithFrame:f];
     if (!self)
         return nil;
@@ -1064,6 +1063,12 @@ static bool shouldUseLegacyBackgroundSizeShorthandBehavior()
     [self setMaintainsBackForwardList: YES];
 #if !PLATFORM(IOS)
     _private->page->setDeviceScaleFactor([self _deviceScaleFactor]);
+
+    if ([self respondsToSelector:@selector(setActionMenu:)]) {
+        RetainPtr<NSMenu> actionMenu = adoptNS([[NSMenu alloc] init]);
+        self.actionMenu = actionMenu.get();
+        _private->actionMenuController = [[WebActionMenuController alloc] initWithWebView:self];
+    }
 #endif
     return self;
 }
@@ -1090,7 +1095,7 @@ static bool shouldUseLegacyBackgroundSizeShorthandBehavior()
     NSEnumerator *enumerator = [MIMETypes objectEnumerator];
     NSString *MIMEType;
     while ((MIMEType = [enumerator nextObject]) != nil) {
-        NSArray *extensionsForType = WKGetExtensionsForMIMEType(MIMEType);
+        NSArray *extensionsForType = [[NSURLFileTypeMappings sharedMappings] extensionsForMIMEType:MIMEType];
         if (extensionsForType) {
             [extensions addObjectsFromArray:extensionsForType];
         }
@@ -1189,14 +1194,7 @@ static bool shouldUseLegacyBackgroundSizeShorthandBehavior()
     [self setGroupName:groupName];
 
 #if ENABLE(REMOTE_INSPECTOR)
-    // Production installs always disallow debugging simple HTML documents.
-    // Internal installs allow debugging simple HTML documents (TextFields) if the Internal Setting is enabled.
-    if (!isInternalInstall())
-        _private->page->setRemoteInspectionAllowed(false);
-    else {
-        static BOOL textFieldInspectionEnabled = [[NSUserDefaults standardUserDefaults] boolForKey:WebKitTextFieldRemoteInspectionEnabledPreferenceKey];
-        _private->page->setRemoteInspectionAllowed(textFieldInspectionEnabled);
-    }
+    _private->page->setRemoteInspectionAllowed(isInternalInstall());
 #endif
     
     [self _updateScreenScaleFromWindow];
@@ -1228,13 +1226,6 @@ static bool shouldUseLegacyBackgroundSizeShorthandBehavior()
 
     tileControllerMemoryHandler().trimUnparentedTilesToTarget(0);
 
-#if ENABLE(DISK_IMAGE_CACHE)
-    {
-        WebKit::MemoryMeasure measurer("Memory warning: flushing images to disk.");
-        WebCore::memoryCache()->flushCachedImagesToDisk();
-    }
-#endif
-
     [WebStorageManager closeIdleLocalStorageDatabases];
 
     [WebView _releaseMemoryNow];
@@ -1454,13 +1445,6 @@ static NSMutableSet *knownPluginMIMETypes()
     return NO;
 }
 
-#if !PLATFORM(IOS)
-+ (void)_setAlwaysUseATSU:(BOOL)f
-{
-    [self _setAlwaysUsesComplexTextCodePath:f];
-}
-#endif
-
 + (void)_setAlwaysUsesComplexTextCodePath:(BOOL)f
 {
     Font::setCodePath(f ? Font::Complex : Font::Auto);
@@ -1501,7 +1485,7 @@ static NSMutableSet *knownPluginMIMETypes()
 #if !PLATFORM(IOS)
 + (NSString *)suggestedFileExtensionForMIMEType:(NSString *)type
 {
-    return WKGetPreferredExtensionForMIMEType(type);
+    return [[NSURLFileTypeMappings sharedMappings] preferredExtensionForMIMEType:type];
 }
 #endif
 
@@ -1578,9 +1562,8 @@ static NSMutableSet *knownPluginMIMETypes()
     _private->mainViewIsScrollingOrZooming = NO;
     [self setDefersCallbacks:NO];
     [[self mainFrame] setTimeoutsPaused:NO];
-    FrameView* view = [self _mainCoreFrame]->view();
-    if (view && view->renderView())
-        view->renderView()->resumePausedImageAnimationsIfNeeded();
+    if (FrameView* view = [self _mainCoreFrame]->view())
+        view->resumeVisibleImageAnimationsIncludingSubframes();
 }
 
 - (void)_setResourceLoadSchedulerSuspended:(BOOL)suspend
@@ -1705,7 +1688,7 @@ static bool fastDocumentTeardownEnabled()
     }
 
 #if ENABLE(VIDEO) && !PLATFORM(IOS)
-    [self _exitFullscreen];
+    [self _exitVideoFullscreen];
 #endif
 
 #if PLATFORM(IOS)
@@ -1727,6 +1710,7 @@ static bool fastDocumentTeardownEnabled()
     [self setUIDelegate:nil];
 
     [_private->inspector webViewClosed];
+    [_private->actionMenuController webViewClosed];
 #endif
 
 #if !PLATFORM(IOS)
@@ -1804,7 +1788,7 @@ static bool fastDocumentTeardownEnabled()
 #if !PLATFORM(IOS)
     // Get the MIME type from the extension.
     if ([extension length] != 0) {
-        MIMEType = WKGetMIMETypeForExtension(extension);
+        MIMEType = [[NSURLFileTypeMappings sharedMappings] MIMETypeForExtension:extension];
     }
 #endif
 
@@ -2124,17 +2108,6 @@ static bool needsSelfRetainWhileLoadingQuirk()
 #endif
 }
 
-- (BOOL)_needsUnrestrictedGetMatchedCSSRules
-{
-#if !PLATFORM(IOS)
-    static bool needsUnrestrictedGetMatchedCSSRules = !WebKitLinkedOnOrAfter(WEBKIT_FIRST_VERSION_WITH_GET_MATCHED_CSS_RULES_RESTRICTIONS) && applicationIsSafari();
-    return needsUnrestrictedGetMatchedCSSRules;
-#else
-    // FIXME: <rdar://problem/8963684> Implement linked-on-or-after check for needsUnrestrictedGetMatchedCSSRules
-    return NO;
-#endif
-}
-
 - (void)_preferencesChangedNotification:(NSNotification *)notification
 {
 #if PLATFORM(IOS)
@@ -2279,7 +2252,6 @@ static bool needsSelfRetainWhileLoadingQuirk()
     settings.setAsynchronousSpellCheckingEnabled([preferences asynchronousSpellCheckingEnabled]);
     settings.setHyperlinkAuditingEnabled([preferences hyperlinkAuditingEnabled]);
     settings.setUsePreHTML5ParserQuirks([self _needsPreHTML5ParserQuirks]);
-    settings.setCrossOriginCheckInGetMatchedCSSRulesDisabled([self _needsUnrestrictedGetMatchedCSSRules]);
     settings.setInteractiveFormValidationEnabled([self interactiveFormValidationEnabled]);
     settings.setValidationMessageTimerMagnification([self validationMessageTimerMagnification]);
 
@@ -2316,6 +2288,14 @@ static bool needsSelfRetainWhileLoadingQuirk()
     settings.setPlugInSnapshottingEnabled([preferences plugInSnapshottingEnabled]);
 
     settings.setFixedPositionCreatesStackingContext(true);
+#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
+    settings.setAcceleratedCompositingForFixedPositionEnabled(true);
+#endif
+
+#if ENABLE(RUBBER_BANDING)
+    // FIXME: https://bugs.webkit.org/show_bug.cgi?id=136131
+    settings.setRubberBandingForSubScrollableRegionsEnabled(false);
+#endif
 
 #if PLATFORM(IOS)
     settings.setStandalone([preferences _standalone]);
@@ -2342,8 +2322,6 @@ static bool needsSelfRetainWhileLoadingQuirk()
 #if ENABLE(IOS_TEXT_AUTOSIZING)
     settings.setMinimumZoomFontSize([preferences _minimumZoomFontSize]);
 #endif
-
-    settings.setAllowNavigationToInvalidURL(!WebKitLinkedOnOrAfter(WEBKIT_FIRST_VERSION_WITH_NAVIGATION_URL_VALIDATION));
 #endif // PLATFORM(IOS)
 
 #if PLATFORM(MAC)
@@ -2365,9 +2343,6 @@ static bool needsSelfRetainWhileLoadingQuirk()
     settings.setShowsURLsInToolTips([preferences showsURLsInToolTips]);
     settings.setShowsToolTipOverTruncatedText([preferences showsToolTipOverTruncatedText]);
     settings.setQTKitEnabled([preferences isQTKitEnabled]);
-
-    // FIXME: Should we enable this following <rdar://problem/15290404>?
-    settings.setMultithreadedWebGLEnabled([preferences multithreadedWebGLEnabled]);
 #endif // PLATFORM(MAC)
 
 #if ENABLE(SQL_DATABASE)
@@ -2380,6 +2355,7 @@ static bool needsSelfRetainWhileLoadingQuirk()
 
 #if ENABLE(SERVICE_CONTROLS)
     settings.setImageControlsEnabled([preferences imageControlsEnabled]);
+    settings.setServiceControlsEnabled([preferences serviceControlsEnabled]);
 #endif
 
 #if ENABLE(VIDEO_TRACK)
@@ -2404,8 +2380,10 @@ static bool needsSelfRetainWhileLoadingQuirk()
     settings.setHiddenPageDOMTimerThrottlingEnabled([preferences hiddenPageDOMTimerThrottlingEnabled]);
 #endif
 
-#if ENABLE(PAGE_VISIBILITY_API)
     settings.setHiddenPageCSSAnimationSuspensionEnabled([preferences hiddenPageCSSAnimationSuspensionEnabled]);
+
+#if ENABLE(GAMEPAD)
+    RuntimeEnabledFeatures::sharedFeatures().setGamepadsEnabled([preferences gamepadsEnabled]);
 #endif
 
     NSTimeInterval timeout = [preferences incrementalRenderingSuppressionTimeoutInSeconds];
@@ -2419,13 +2397,6 @@ static bool needsSelfRetainWhileLoadingQuirk()
     if (_private->zoomsTextOnly != zoomsTextOnly)
         [self _setZoomMultiplier:_private->zoomMultiplier isTextOnly:zoomsTextOnly];
 
-#if ENABLE(DISK_IMAGE_CACHE) && PLATFORM(IOS)
-    DiskImageCache& diskImageCache = WebCore::diskImageCache();
-    diskImageCache.setEnabled([preferences diskImageCacheEnabled]);
-    diskImageCache.setMinimumImageSize([preferences diskImageCacheMinimumImageSize]);
-    diskImageCache.setMaximumCacheSize([preferences diskImageCacheMaximumCacheSize]);
-#endif
-
 #if PLATFORM(IOS)
     [[self window] setTileBordersVisible:[preferences showDebugBorders]];
     [[self window] setTilePaintCountsVisible:[preferences showRepaintCounter]];
@@ -2998,8 +2969,8 @@ static inline IMP getMethod(id o, SEL s)
     NSView *documentView = [[kit(&frameView->frame()) frameView] documentView];
 
     for (const auto& widget: frameView->children()) {
-        if (widget->isFrameView()) {
-            [self _addScrollerDashboardRegionsForFrameView:toFrameView(widget.get()) dashboardRegions:regions];
+        if (is<FrameView>(*widget)) {
+            [self _addScrollerDashboardRegionsForFrameView:downcast<FrameView>(widget.get()) dashboardRegions:regions];
             continue;
         }
 
@@ -3070,7 +3041,7 @@ static inline IMP getMethod(id o, SEL s)
             [regionValues release];
         }
 
-        WebDashboardRegion *webRegion = [[WebDashboardRegion alloc] initWithRect:pixelSnappedIntRect(region.bounds) clip:pixelSnappedIntRect(region.clip) type:type];
+        WebDashboardRegion *webRegion = [[WebDashboardRegion alloc] initWithRect:snappedIntRect(region.bounds) clip:snappedIntRect(region.clip) type:type];
         [regionValues addObject:webRegion];
         [webRegion release];
     }
@@ -3453,7 +3424,7 @@ static inline IMP getMethod(id o, SEL s)
             continue;
         
         if (layerForWidget->contentsLayerForMedia() != layer) {
-            layerForWidget->setContentsToMedia(layer);
+            layerForWidget->setContentsToPlatformLayer(layer, GraphicsLayer::ContentsLayerForMedia);
             // We need to make sure the layer hierachy change is applied immediately.
             if (mainCoreFrame->view())
                 mainCoreFrame->view()->flushCompositingStateIncludingSubframes();
@@ -3697,6 +3668,11 @@ static inline IMP getMethod(id o, SEL s)
         if (rect.isEmpty())
             continue;
 
+        // Note that these rectangles are in the coordinate system of the document (inside the WebHTMLView), which is not
+        // the same as the coordinate system of the WebView. If you want to do comparisons with locations in the WebView,
+        // you must convert between the two using WAKView's convertRect:toView: selector. This will take care of scaling
+        // and translations (which are relevant for right-to-left column layout).
+
         // The event region wants this points in this order:
         //  p2------p3
         //  |       |
@@ -3923,7 +3899,7 @@ static inline IMP getMethod(id o, SEL s)
     NSMutableArray* rectsArray = [[NSMutableArray alloc] initWithCapacity:repaintRects.size()];
     
     for (unsigned i = 0; i < repaintRects.size(); ++i)
-        [rectsArray addObject:[NSValue valueWithRect:pixelSnappedIntRect(LayoutRect(repaintRects[i]))]];
+        [rectsArray addObject:[NSValue valueWithRect:snappedIntRect(LayoutRect(repaintRects[i]))]];
 
     return [rectsArray autorelease];
 }
@@ -4325,10 +4301,8 @@ static Vector<String> toStringVector(NSArray* patterns)
 
 - (WebPageVisibilityState)_visibilityState
 {
-#if ENABLE(PAGE_VISIBILITY_API) || ENABLE(HIDDEN_PAGE_DOM_TIMER_THROTTLING)
     if (_private->page)
         return kit(_private->page->visibilityState());
-#endif
     return WebPageVisibilityStateVisible;
 }
 
@@ -5001,7 +4975,7 @@ static bool needsWebViewInitThreadWorkaround()
 #endif
 
     WebCoreThreadViolationCheckRoundTwo();
-    return [self _initWithFrame:f frameName:frameName groupName:groupName usesDocumentViews:YES];
+    return [self _initWithFrame:f frameName:frameName groupName:groupName];
 }
 
 #if !PLATFORM(IOS)
@@ -5293,11 +5267,27 @@ static NSString * const backingPropertyOldScaleFactorKey = @"NSBackingPropertyOl
         _private->page->chrome().windowScreenDidChange((PlatformDisplayID)[[[[[self window] screen] deviceDescription] objectForKey:@"NSScreenNumber"] intValue]);
 }
 
+- (void)_windowChangedKeyState
+{
+    [self _updateActiveState];
+    [super _windowChangedKeyState];
+}
+
 - (void)windowKeyStateChanged:(NSNotification *)notification
 {
     [self _updateActiveState];
 }
 
+- (void)viewDidHide
+{
+    [self _updateVisibilityState];
+}
+
+- (void)viewDidUnhide
+{
+    [self _updateVisibilityState];
+}
+
 - (void)_windowWillOrderOnScreen:(NSNotification *)notification
 {
     if (![self shouldUpdateWhileOffscreen])
@@ -7806,10 +7796,6 @@ static inline uint64_t roundUpToPowerOf2(uint64_t num)
         break;
     }
     case WebCacheModelPrimaryWebBrowser: {
-#if PLATFORM(IOS)
-        WebPreferences *preferences = [WebPreferences standardPreferences];
-        int prefValue;
-#endif
         // Page cache capacity (in pages)
         // (Research indicates that value / page drops substantially after 3 pages.)
         if (memSize >= 2048)
@@ -7829,9 +7815,6 @@ static inline uint64_t roundUpToPowerOf2(uint64_t num)
         // Reducing the capacity by 1 reduces overall back-forward performance.
         if (pageCacheCapacity > 0)
             pageCacheCapacity -= 1;
-        prefValue = [preferences _pageCacheSize];
-        if (prefValue >= 0)
-            pageCacheCapacity = prefValue;
 #endif
 
         // Object cache capacities (in bytes)
@@ -7847,12 +7830,6 @@ static inline uint64_t roundUpToPowerOf2(uint64_t num)
         else if (memSize >= 512)
             cacheTotalCapacity = 32 * 1024 * 1024;
 
-#if PLATFORM(IOS)
-        prefValue = [preferences _objectCacheSize];
-        if (prefValue >= 0)
-            cacheTotalCapacity = prefValue;
-#endif
-
         cacheMinDeadCapacity = cacheTotalCapacity / 4;
         cacheMaxDeadCapacity = cacheTotalCapacity / 2;
 
@@ -7867,10 +7844,6 @@ static inline uint64_t roundUpToPowerOf2(uint64_t num)
             nsurlCacheMemoryCapacity = 16 * 1024 * 1024;
         else
             nsurlCacheMemoryCapacity = 8 * 1024 * 1024;
-        
-        prefValue = [preferences _NSURLMemoryCacheSize];
-        if (prefValue >= 0)
-            nsurlCacheMemoryCapacity = prefValue;
 #else
         // Foundation memory cache capacity (in bytes)
         // (These values are small because WebCore does most caching itself.)
@@ -7899,10 +7872,6 @@ static inline uint64_t roundUpToPowerOf2(uint64_t num)
             nsurlCacheDiskCapacity = 50 * 1024 * 1024;
 
 #if PLATFORM(IOS)
-        prefValue = [preferences _NSURLDiskCacheSize];
-        if (prefValue >= 0)
-            nsurlCacheDiskCapacity = prefValue;
-
         // TileCache layer pool capacity, in bytes.
         if (memSize >= 1024)
             tileLayerPoolCapacity = 48 * 1024 * 1024;
@@ -8405,39 +8374,36 @@ bool LayerFlushController::flushLayers()
 #endif
 
 #if ENABLE(VIDEO)
-- (void)_enterFullscreenForNode:(WebCore::Node*)node
+- (void)_enterVideoFullscreenForVideoElement:(WebCore::HTMLVideoElement*)videoElement
 {
-    ASSERT(isHTMLVideoElement(node));
-    HTMLMediaElement* videoElement = toHTMLMediaElement(node);
-
     if (_private->fullscreenController) {
-        if ([_private->fullscreenController mediaElement] == videoElement) {
+        if ([_private->fullscreenController videoElement] == videoElement) {
             // The backend may just warn us that the underlaying plaftormMovie()
             // has changed. Just force an update.
-            [_private->fullscreenController setMediaElement:videoElement];
+            [_private->fullscreenController setVideoElement:videoElement];
             return; // No more to do.
         }
 
-        // First exit Fullscreen for the old mediaElement.
-        [_private->fullscreenController mediaElement]->exitFullscreen();
+        // First exit Fullscreen for the old videoElement.
+        [_private->fullscreenController videoElement]->exitFullscreen();
         // This previous call has to trigger _exitFullscreen,
         // which has to clear _private->fullscreenController.
         ASSERT(!_private->fullscreenController);
     }
     if (!_private->fullscreenController) {
         _private->fullscreenController = [[WebVideoFullscreenController alloc] init];
-        [_private->fullscreenController setMediaElement:videoElement];
+        [_private->fullscreenController setVideoElement:videoElement];
 #if PLATFORM(IOS)
-        [_private->fullscreenController enterFullscreen:nil];
+        [_private->fullscreenController enterFullscreen:(UIView *)[[[self window] hostLayer] delegate]];
 #else
         [_private->fullscreenController enterFullscreen:[[self window] screen]];
 #endif
     }
     else
-        [_private->fullscreenController setMediaElement:videoElement];
+        [_private->fullscreenController setVideoElement:videoElement];
 }
 
-- (void)_exitFullscreen
+- (void)_exitVideoFullscreen
 {
     if (!_private->fullscreenController)
         return;
@@ -8540,6 +8506,15 @@ static void glibContextIterationCallback(CFRunLoopObserverRef, CFRunLoopActivity
 }
 #endif
 
+#if ENABLE(SERVICE_CONTROLS)
+- (WebSelectionServiceController&)_selectionServiceController
+{
+    if (!_private->_selectionServiceController)
+        _private->_selectionServiceController = std::make_unique<WebSelectionServiceController>(self);
+    return *_private->_selectionServiceController;
+}
+#endif
+
 - (NSPoint)_convertPointFromRootView:(NSPoint)point
 {
     return NSMakePoint(point.x, [self bounds].size.height - point.y);
@@ -8550,6 +8525,16 @@ static void glibContextIterationCallback(CFRunLoopObserverRef, CFRunLoopActivity
     return NSMakeRect(rect.origin.x, [self bounds].size.height - rect.origin.y - rect.size.height, rect.size.width, rect.size.height);
 }
 
+#if !PLATFORM(IOS)
+- (void)prepareForMenu:(NSMenu *)menu withEvent:(NSEvent *)event
+{
+    if (menu != self.actionMenu)
+        return;
+
+    [_private->actionMenuController prepareForMenu:menu withEvent:event];
+}
+#endif
+
 @end
 
 @implementation WebView (WebViewDeviceOrientation)
@@ -8668,7 +8653,7 @@ static void glibContextIterationCallback(CFRunLoopObserverRef, CFRunLoopActivity
 {
 #if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS)
     JSContextRef context = [[self mainFrame] globalContext];
-    WebCore::Notification* notification = toNotification(toJS(toJS(context), jsNotification));
+    WebCore::Notification* notification = JSNotification::toWrapped(toJS(toJS(context), jsNotification));
     return static_cast<WebNotificationClient*>(NotificationController::clientFrom(_private->page))->notificationIDForTesting(notification);
 #else
     return 0;