Disable AR support in WKWebView clients
authordino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 13 Jun 2018 23:20:49 +0000 (23:20 +0000)
committerdino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 13 Jun 2018 23:20:49 +0000 (23:20 +0000)
https://bugs.webkit.org/show_bug.cgi?id=186611
<rdar://problem/39544684>

Reviewed by Jon Lee.

Since it hasn't been adequately tested, System Preview (AR) should
be disabled by default for WKWebViews.

Source/WebCore:

Add a new RuntimeEnabledFeature to control this, and guard for
this case everywhere we use system previews.

* html/HTMLAnchorElement.cpp:
(WebCore::HTMLAnchorElement::isSystemPreviewLink const):
(WebCore::HTMLAnchorElement::handleClick):
* html/HTMLImageElement.cpp:
(WebCore::HTMLImageElement::isSystemPreviewImage const):
* html/HTMLPictureElement.cpp:
(WebCore::HTMLPictureElement::isSystemPreviewImage const):
* page/RuntimeEnabledFeatures.h:
(WebCore::RuntimeEnabledFeatures::setSystemPreviewEnabled):
(WebCore::RuntimeEnabledFeatures::systemPreviewEnabled const):
* rendering/RenderImage.cpp:
(WebCore::RenderImage::paintIntoRect):

Source/WebKit:

Add a new WebPreference, and SPI into WKWebViewConfiguration. Also
don't register the WebViewContentProvider if the feature is
disabled.

* Shared/WebPreferences.yaml:
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _initializeWithConfiguration:]):
* UIProcess/API/Cocoa/WKWebViewConfiguration.mm:
(-[WKWebViewConfiguration init]):
(-[WKWebViewConfiguration encodeWithCoder:]):
(-[WKWebViewConfiguration initWithCoder:]):
(-[WKWebViewConfiguration copyWithZone:]):
(-[WKWebViewConfiguration _contentProviderRegistry]):
(-[WKWebViewConfiguration _systemPreviewEnabled]):
(-[WKWebViewConfiguration _setSystemPreviewEnabled:]):
* UIProcess/API/Cocoa/WKWebViewConfigurationPrivate.h:
* UIProcess/Cocoa/WKWebViewContentProviderRegistry.h:
* UIProcess/Cocoa/WKWebViewContentProviderRegistry.mm:
(-[WKWebViewContentProviderRegistry initWithConfiguration:]):
(-[WKWebViewContentProviderRegistry init]): Deleted.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@232817 268f45cc-cd09-0410-ab3c-d52691b4dbfc

14 files changed:
Source/WebCore/ChangeLog
Source/WebCore/html/HTMLAnchorElement.cpp
Source/WebCore/html/HTMLImageElement.cpp
Source/WebCore/html/HTMLPictureElement.cpp
Source/WebCore/page/RuntimeEnabledFeatures.h
Source/WebCore/rendering/RenderImage.cpp
Source/WebKit/ChangeLog
Source/WebKit/Shared/WebPreferences.yaml
Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit/UIProcess/API/Cocoa/WKWebViewConfiguration.mm
Source/WebKit/UIProcess/API/Cocoa/WKWebViewConfigurationPrivate.h
Source/WebKit/UIProcess/Cocoa/WKWebViewContentProviderRegistry.h
Source/WebKit/UIProcess/Cocoa/WKWebViewContentProviderRegistry.mm
Tools/WebKitTestRunner/cocoa/TestControllerCocoa.mm

index 0e81413..86e8663 100644 (file)
@@ -1,3 +1,30 @@
+2018-06-13  Dean Jackson  <dino@apple.com>
+
+        Disable AR support in WKWebView clients
+        https://bugs.webkit.org/show_bug.cgi?id=186611
+        <rdar://problem/39544684>
+
+        Reviewed by Jon Lee.
+
+        Since it hasn't been adequately tested, System Preview (AR) should
+        be disabled by default for WKWebViews.
+
+        Add a new RuntimeEnabledFeature to control this, and guard for
+        this case everywhere we use system previews.
+
+        * html/HTMLAnchorElement.cpp:
+        (WebCore::HTMLAnchorElement::isSystemPreviewLink const):
+        (WebCore::HTMLAnchorElement::handleClick):
+        * html/HTMLImageElement.cpp:
+        (WebCore::HTMLImageElement::isSystemPreviewImage const):
+        * html/HTMLPictureElement.cpp:
+        (WebCore::HTMLPictureElement::isSystemPreviewImage const):
+        * page/RuntimeEnabledFeatures.h:
+        (WebCore::RuntimeEnabledFeatures::setSystemPreviewEnabled):
+        (WebCore::RuntimeEnabledFeatures::systemPreviewEnabled const):
+        * rendering/RenderImage.cpp:
+        (WebCore::RenderImage::paintIntoRect):
+
 2018-06-13  Youenn Fablet  <youenn@apple.com>
 
         Supported plugin check should be based on plugin identifier
index aae8b6b..08ca042 100644 (file)
@@ -380,6 +380,9 @@ void HTMLAnchorElement::sendPings(const URL& destinationURL)
 #if USE(SYSTEM_PREVIEW)
 bool HTMLAnchorElement::isSystemPreviewLink() const
 {
+    if (!RuntimeEnabledFeatures::sharedFeatures().systemPreviewEnabled())
+        return false;
+
 #if USE(APPLE_INTERNAL_SDK)
     auto systemPreviewRelValue = getSystemPreviewRelValue();
 #else
@@ -428,7 +431,7 @@ void HTMLAnchorElement::handleClick(Event& event)
 
     SystemPreviewInfo systemPreviewInfo;
 #if USE(SYSTEM_PREVIEW)
-    systemPreviewInfo.isSystemPreview = isSystemPreviewLink();
+    systemPreviewInfo.isSystemPreview = isSystemPreviewLink() && RuntimeEnabledFeatures::sharedFeatures().systemPreviewEnabled();
 
     if (systemPreviewInfo.isSystemPreview) {
         if (auto* child = firstElementChild())
index abe006d..128f907 100644 (file)
@@ -42,6 +42,7 @@
 #include "NodeTraversal.h"
 #include "RenderImage.h"
 #include "RenderView.h"
+#include "RuntimeEnabledFeatures.h"
 #include "Settings.h"
 #include "ShadowRoot.h"
 #include "SizesAttributeParser.h"
@@ -686,6 +687,9 @@ bool HTMLImageElement::willRespondToMouseClickEvents()
 #if USE(SYSTEM_PREVIEW)
 bool HTMLImageElement::isSystemPreviewImage() const
 {
+    if (!RuntimeEnabledFeatures::sharedFeatures().systemPreviewEnabled())
+        return false;
+
     const auto* parent = parentElement();
     if (is<HTMLAnchorElement>(parent))
         return downcast<HTMLAnchorElement>(parent)->isSystemPreviewLink();
index e9c6e7e..aa2aad6 100644 (file)
@@ -30,6 +30,7 @@
 #include "HTMLAnchorElement.h"
 #include "HTMLImageElement.h"
 #include "Logging.h"
+#include "RuntimeEnabledFeatures.h"
 #include <wtf/IsoMallocInlines.h>
 
 namespace WebCore {
@@ -79,6 +80,9 @@ bool HTMLPictureElement::viewportChangeAffectedPicture() const
 #if USE(SYSTEM_PREVIEW)
 bool HTMLPictureElement::isSystemPreviewImage() const
 {
+    if (!RuntimeEnabledFeatures::sharedFeatures().systemPreviewEnabled())
+        return false;
+
     const auto* parent = parentElement();
     if (!is<HTMLAnchorElement>(parent))
         return false;
index 6a687fe..8ac422e 100644 (file)
@@ -265,6 +265,11 @@ public:
     void setDisabledAdaptationsMetaTagEnabled(bool isEnabled) { m_disabledAdaptationsMetaTagEnabled = isEnabled; }
     bool disabledAdaptationsMetaTagEnabled() const { return m_disabledAdaptationsMetaTagEnabled; }
 
+#if USE(SYSTEM_PREVIEW)
+    void setSystemPreviewEnabled(bool isEnabled) { m_systemPreviewEnabled = isEnabled; }
+    bool systemPreviewEnabled() const { return m_systemPreviewEnabled; }
+#endif
+
     WEBCORE_EXPORT static RuntimeEnabledFeatures& sharedFeatures();
 
 private:
@@ -280,7 +285,6 @@ private:
     bool m_isInteractiveFormValidationEnabled { false };
     bool m_isWebAuthenticationEnabled { false };
     bool m_isSecureContextAttributeEnabled { false };
-
     bool m_isDisplayContentsEnabled { true };
     bool m_isShadowDOMEnabled { true };
     bool m_areCustomElementsEnabled { true };
@@ -363,7 +367,6 @@ private:
 #endif
 
     bool m_isImageBitmapOffscreenCanvasEnabled { true };
-
     bool m_isCacheAPIEnabled { false };
     bool m_isFetchAPIEnabled { true };
 
@@ -386,29 +389,24 @@ private:
 #if ENABLE(SERVICE_WORKER)
     bool m_serviceWorkerEnabled { false };
 #endif
-    bool m_fetchAPIKeepAliveEnabled { false };
 
+    bool m_fetchAPIKeepAliveEnabled { false };
     bool m_inspectorAdditionsEnabled { false };
     bool m_webVREnabled { false };
-
     bool m_accessibilityObjectModelEnabled { false };
-
     bool m_mediaCapabilitiesEnabled { false };
-
     bool m_resourceLoadStatisticsDebugMode { false };
-
     bool m_isRestrictedHTTPResponseAccess { true };
-
     bool m_crossOriginResourcePolicyEnabled { true };
-
     bool m_isWebGLCompressedTextureASTCSupportEnabled { false };
-
     bool m_promptForStorageAccessAPIEnabled { false };
-
     bool m_isServerTimingEnabled { false };
-
     bool m_disabledAdaptationsMetaTagEnabled { false };
 
+#if USE(SYSTEM_PREVIEW)
+    bool m_systemPreviewEnabled { false };
+#endif
+
     friend class WTF::NeverDestroyed<RuntimeEnabledFeatures>;
 };
 
index acd99a0..1264152 100644 (file)
@@ -51,6 +51,7 @@
 #include "RenderImageResourceStyleImage.h"
 #include "RenderTheme.h"
 #include "RenderView.h"
+#include "RuntimeEnabledFeatures.h"
 #include "SVGImage.h"
 #include <wtf/IsoMallocInlines.h>
 #include <wtf/StackStats.h>
@@ -594,7 +595,7 @@ ImageDrawResult RenderImage::paintIntoRect(PaintInfo& paintInfo, const FloatRect
         imageResource().cachedImage()->addPendingImageDrawingClient(*this);
 
 #if USE(SYSTEM_PREVIEW)
-    if (imageElement && imageElement->isSystemPreviewImage() && drawResult == ImageDrawResult::DidDraw)
+    if (imageElement && imageElement->isSystemPreviewImage() && drawResult == ImageDrawResult::DidDraw && RuntimeEnabledFeatures::sharedFeatures().systemPreviewEnabled())
         theme().paintSystemPreviewBadge(*img, paintInfo, rect);
 #endif
 
index 3b5789b..cad6659 100644 (file)
@@ -1,3 +1,35 @@
+2018-06-13  Dean Jackson  <dino@apple.com>
+
+        Disable AR support in WKWebView clients
+        https://bugs.webkit.org/show_bug.cgi?id=186611
+        <rdar://problem/39544684>
+
+        Reviewed by Jon Lee.
+
+        Since it hasn't been adequately tested, System Preview (AR) should
+        be disabled by default for WKWebViews.
+
+        Add a new WebPreference, and SPI into WKWebViewConfiguration. Also
+        don't register the WebViewContentProvider if the feature is
+        disabled.
+
+        * Shared/WebPreferences.yaml:
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _initializeWithConfiguration:]):
+        * UIProcess/API/Cocoa/WKWebViewConfiguration.mm:
+        (-[WKWebViewConfiguration init]):
+        (-[WKWebViewConfiguration encodeWithCoder:]):
+        (-[WKWebViewConfiguration initWithCoder:]):
+        (-[WKWebViewConfiguration copyWithZone:]):
+        (-[WKWebViewConfiguration _contentProviderRegistry]):
+        (-[WKWebViewConfiguration _systemPreviewEnabled]):
+        (-[WKWebViewConfiguration _setSystemPreviewEnabled:]):
+        * UIProcess/API/Cocoa/WKWebViewConfigurationPrivate.h:
+        * UIProcess/Cocoa/WKWebViewContentProviderRegistry.h:
+        * UIProcess/Cocoa/WKWebViewContentProviderRegistry.mm:
+        (-[WKWebViewContentProviderRegistry initWithConfiguration:]):
+        (-[WKWebViewContentProviderRegistry init]): Deleted.
+
 2018-06-13  Youenn Fablet  <youenn@apple.com>
 
         Supported plugin check should be based on plugin identifier
index 8512215..d370f59 100644 (file)
@@ -1060,6 +1060,12 @@ MediaCapabilitiesEnabled:
     defaultValue: false
     webcoreBinding: RuntimeEnabledFeatures
 
+SystemPreviewEnabled:
+    type: bool
+    defaultValue: false
+    webcoreBinding: RuntimeEnabledFeatures
+    condition: USE(SYSTEM_PREVIEW)
+
 # For experimental features:
 # The type should be boolean.
 # You must provide a humanReadableName and humanReadableName for all experimental features. They
index 30f4d82..33445e6 100644 (file)
@@ -585,6 +585,9 @@ static void validate(WKWebViewConfiguration *configuration)
     pageConfiguration->preferenceValues().set(WebKit::WebPreferencesKey::userInterfaceDirectionPolicyKey(), WebKit::WebPreferencesStore::Value(static_cast<uint32_t>(WebCore::UserInterfaceDirectionPolicy::Content)));
     pageConfiguration->preferenceValues().set(WebKit::WebPreferencesKey::systemLayoutDirectionKey(), WebKit::WebPreferencesStore::Value(static_cast<uint32_t>(WebCore::LTR)));
     pageConfiguration->preferenceValues().set(WebKit::WebPreferencesKey::allowSettingAnyXHRHeaderFromFileURLsKey(), WebKit::WebPreferencesStore::Value(shouldAllowSettingAnyXHRHeaderFromFileURLs()));
+#if USE(SYSTEM_PREVIEW)
+    pageConfiguration->preferenceValues().set(WebKit::WebPreferencesKey::systemPreviewEnabledKey(), WebKit::WebPreferencesStore::Value(!![_configuration _systemPreviewEnabled]));
+#endif
 #endif
 
     WKAudiovisualMediaTypes mediaTypesRequiringUserGesture = [_configuration mediaTypesRequiringUserActionForPlayback];
index a087564..7cd12c8 100644 (file)
@@ -132,6 +132,7 @@ static _WKDragLiftDelay toDragLiftDelay(NSUInteger value)
     _WKDragLiftDelay _dragLiftDelay;
     BOOL _textInteractionGesturesEnabled;
     BOOL _longPressActionsEnabled;
+    BOOL _systemPreviewEnabled;
 #endif
 
     BOOL _invisibleAutoplayNotPermitted;
@@ -240,6 +241,7 @@ static _WKDragLiftDelay toDragLiftDelay(NSUInteger value)
     _textInteractionGesturesEnabled = YES;
     _longPressActionsEnabled = YES;
 #endif
+    _systemPreviewEnabled = NO;
 #endif // PLATFORM(IOS)
 
     _mediaContentTypesRequiringHardwareSupport = Settings::defaultMediaContentTypesRequiringHardwareSupport();
@@ -284,6 +286,7 @@ static _WKDragLiftDelay toDragLiftDelay(NSUInteger value)
     [coder encodeInteger:self._dragLiftDelay forKey:@"dragLiftDelay"];
     [coder encodeBool:self._textInteractionGesturesEnabled forKey:@"textInteractionGesturesEnabled"];
     [coder encodeBool:self._longPressActionsEnabled forKey:@"longPressActionsEnabled"];
+    [coder encodeBool:self._systemPreviewEnabled forKey:@"systemPreviewEnabled"];
 #else
     [coder encodeInteger:self.userInterfaceDirectionPolicy forKey:@"userInterfaceDirectionPolicy"];
 #endif
@@ -314,6 +317,7 @@ static _WKDragLiftDelay toDragLiftDelay(NSUInteger value)
     self._dragLiftDelay = toDragLiftDelay([coder decodeIntegerForKey:@"dragLiftDelay"]);
     self._textInteractionGesturesEnabled = [coder decodeBoolForKey:@"textInteractionGesturesEnabled"];
     self._longPressActionsEnabled = [coder decodeBoolForKey:@"longPressActionsEnabled"];
+    self._systemPreviewEnabled = [coder decodeBoolForKey:@"systemPreviewEnabled"];
 #else
     auto userInterfaceDirectionPolicyCandidate = static_cast<WKUserInterfaceDirectionPolicy>([coder decodeIntegerForKey:@"userInterfaceDirectionPolicy"]);
     if (userInterfaceDirectionPolicyCandidate == WKUserInterfaceDirectionPolicyContent || userInterfaceDirectionPolicyCandidate == WKUserInterfaceDirectionPolicySystem)
@@ -370,6 +374,7 @@ static _WKDragLiftDelay toDragLiftDelay(NSUInteger value)
     configuration->_dragLiftDelay = self->_dragLiftDelay;
     configuration->_textInteractionGesturesEnabled = self->_textInteractionGesturesEnabled;
     configuration->_longPressActionsEnabled = self->_longPressActionsEnabled;
+    configuration->_systemPreviewEnabled = self->_systemPreviewEnabled;
 #endif
 #if PLATFORM(MAC)
     configuration->_cpuLimit = self->_cpuLimit;
@@ -525,7 +530,7 @@ static NSString *defaultApplicationNameForUserAgent()
 #if PLATFORM(IOS)
 - (WKWebViewContentProviderRegistry *)_contentProviderRegistry
 {
-    return _contentProviderRegistry.get([] { return adoptNS([[WKWebViewContentProviderRegistry alloc] init]); });
+    return _contentProviderRegistry.get([self] { return adoptNS([[WKWebViewContentProviderRegistry alloc] initWithConfiguration:self]); });
 }
 
 - (void)_setContentProviderRegistry:(WKWebViewContentProviderRegistry *)registry
@@ -709,6 +714,15 @@ static NSString *defaultApplicationNameForUserAgent()
     _longPressActionsEnabled = enabled;
 }
 
+- (BOOL)_systemPreviewEnabled
+{
+    return _systemPreviewEnabled;
+}
+
+- (void)_setSystemPreviewEnabled:(BOOL)enabled
+{
+    _systemPreviewEnabled = enabled;
+}
 
 #endif // PLATFORM(IOS)
 
index 2228d69..bd04920 100644 (file)
@@ -79,6 +79,7 @@ typedef NS_ENUM(NSUInteger, _WKDragLiftDelay) {
 @property (nonatomic, setter=_setDragLiftDelay:) _WKDragLiftDelay _dragLiftDelay WK_API_AVAILABLE(ios(11.0));
 @property (nonatomic, setter=_setTextInteractionGesturesEnabled:) BOOL _textInteractionGesturesEnabled WK_API_AVAILABLE(ios(WK_IOS_TBA));
 @property (nonatomic, setter=_setLongPressActionsEnabled:) BOOL _longPressActionsEnabled WK_API_AVAILABLE(ios(WK_IOS_TBA));
+@property (nonatomic, setter=_setSystemPreviewEnabled:) BOOL _systemPreviewEnabled WK_API_AVAILABLE(ios(WK_IOS_TBA));
 #else
 @property (nonatomic, setter=_setShowsURLsInToolTips:) BOOL _showsURLsInToolTips WK_API_AVAILABLE(macosx(10.12));
 @property (nonatomic, setter=_setServiceControlsEnabled:) BOOL _serviceControlsEnabled WK_API_AVAILABLE(macosx(10.12));
index 59b6e3b..8c09793 100644 (file)
@@ -35,10 +35,13 @@ namespace WebKit {
 class WebPageProxy;
 }
 
+@class WKWebViewConfiguration;
 @protocol WKWebViewContentProvider;
 
 @interface WKWebViewContentProviderRegistry : NSObject
 
+- (instancetype)initWithConfiguration:(WKWebViewConfiguration *)configuration;
+
 - (void)addPage:(WebKit::WebPageProxy&)page;
 - (void)removePage:(WebKit::WebPageProxy&)page;
 
index 79b6113..b987896 100644 (file)
@@ -33,6 +33,7 @@
 #import "WKLegacyPDFView.h"
 #import "WKPDFView.h"
 #import "WKSystemPreviewView.h"
+#import "WKWebViewConfigurationPrivate.h"
 #import "WKWebViewInternal.h"
 #import "WebPageProxy.h"
 #import <WebCore/MIMETypeRegistry.h>
@@ -52,7 +53,7 @@ using namespace WebKit;
     HashCountedSet<WebPageProxy*> _pages;
 }
 
-- (instancetype)init
+- (instancetype)initWithConfiguration:(WKWebViewConfiguration *)configuration
 {
     if (!(self = [super init]))
         return nil;
@@ -66,8 +67,10 @@ using namespace WebKit;
 #endif
 
 #if USE(SYSTEM_PREVIEW) && USE(APPLE_INTERNAL_SDK)
-    for (auto& mimeType : getSystemPreviewMIMETypes())
-        [self registerProvider:[WKSystemPreviewView class] forMIMEType:mimeType];
+    if (configuration._systemPreviewEnabled) {
+        for (auto& mimeType : getSystemPreviewMIMETypes())
+            [self registerProvider:[WKSystemPreviewView class] forMIMEType:mimeType];
+    }
 #endif
 
     return self;
index beb023d..e6efb27 100644 (file)
@@ -92,6 +92,10 @@ void initializeWebViewConfiguration(const char* libraryPath, WKStringRef injecte
 #endif
     globalWebViewConfiguration.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeNone;
 #endif
+
+#if USE(SYSTEM_PREVIEW)
+    globalWebViewConfiguration._systemPreviewEnabled = YES;
+#endif
 }
 
 void TestController::cocoaPlatformInitialize()