Skip to content

Commit

Permalink
Make UnifiedPDFEnabled setting work on iOS
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=264341
rdar://118062175

Reviewed by Richard Robinson.

* Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml:
Don't show the Unified PDF preference if the compile-time flag isn't enabled.

* Source/WebKit/UIProcess/Cocoa/WKWebViewContentProviderRegistry.mm:
(-[WKWebViewContentProviderRegistry initWithConfiguration:]):
Don't register WKPDFView as a custom content provider when Unified PDF is enabled.

* Source/WebCore/rendering/RenderLayerBacking.h:
* Source/WebCore/plugins/PluginViewBase.h:
(WebCore::PluginViewBase::willProvidePluginLayer const): Deleted.
(WebCore::PluginViewBase::attachPluginLayer): Deleted.
(WebCore::PluginViewBase::detachPluginLayer): Deleted.
* Source/WebCore/rendering/RenderEmbeddedObject.cpp:
(WebCore::RenderEmbeddedObject::requiresAcceleratedCompositing const):
* Source/WebCore/rendering/RenderLayerBacking.cpp:
(WebCore::RenderLayerBacking::updateConfiguration):
(WebCore::RenderLayerBacking::layerWillBeDestroyed): Deleted.
* Source/WebKitLegacy/mac/WebCoreSupport/WebFrameLoaderClient.mm:
(WebFrameLoaderClient::createPlugin):
(PluginWidgetIOS::PluginWidgetIOS): Deleted.
(PluginWidgetIOS::platformLayer const): Deleted.
(PluginWidgetIOS::willProvidePluginLayer const): Deleted.
(PluginWidgetIOS::attachPluginLayer): Deleted.
(PluginWidgetIOS::detachPluginLayer): Deleted.
Remove WebKitLegacy-specific plugin compositing code, which is both unused
and conflicting with our desire to use the Unified PDF plugin in modern WebKit
on iOS. Removing this will make iOS WebKit respect layerHostingStrategy(), which
the Unified PDF plugin depends on.

Canonical link: https://commits.webkit.org/270339@main
  • Loading branch information
hortont424 committed Nov 7, 2023
1 parent c1ff317 commit e2dca80
Show file tree
Hide file tree
Showing 11 changed files with 6 additions and 103 deletions.
1 change: 1 addition & 0 deletions Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6744,6 +6744,7 @@ UnifiedPDFEnabled:
category: security
humanReadableName: "Unified PDF Viewer"
humanReadableDescription: "Enable Unified PDF Viewer"
condition: ENABLE(UNIFIED_PDF)
defaultValue:
WebKitLegacy:
default: false
Expand Down
6 changes: 0 additions & 6 deletions Source/WebCore/plugins/PluginViewBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,6 @@ class PluginViewBase : public Widget {

virtual void layerHostingStrategyDidChange() { }

#if PLATFORM(IOS_FAMILY)
virtual bool willProvidePluginLayer() const { return false; }
virtual void attachPluginLayer() { }
virtual void detachPluginLayer() { }
#endif

virtual bool scroll(ScrollDirection, ScrollGranularity) { return false; }
virtual ScrollPosition scrollPositionForTesting() const { return { }; }

Expand Down
5 changes: 0 additions & 5 deletions Source/WebCore/rendering/RenderEmbeddedObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,7 @@ bool RenderEmbeddedObject::requiresAcceleratedCompositing() const
auto* pluginViewBase = dynamicDowncast<PluginViewBase>(widget());
if (!pluginViewBase)
return false;
#if PLATFORM(IOS_FAMILY)
// The timing of layer creation is different on the phone, since the plugin can only be manipulated from the main thread.
return pluginViewBase->willProvidePluginLayer();
#else
return pluginViewBase->layerHostingStrategy() != PluginLayerHostingStrategy::None;
#endif
}

#if !PLATFORM(IOS_FAMILY)
Expand Down
8 changes: 0 additions & 8 deletions Source/WebCore/rendering/RenderLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2387,14 +2387,6 @@ void RenderLayer::beginTransparencyLayers(GraphicsContext& context, const LayerP
}
}

#if PLATFORM(IOS_FAMILY)
void RenderLayer::willBeDestroyed()
{
if (RenderLayerBacking* layerBacking = backing())
layerBacking->layerWillBeDestroyed();
}
#endif

bool RenderLayer::isDescendantOf(const RenderLayer& layer) const
{
for (auto* ancestor = this; ancestor; ancestor = ancestor->parent()) {
Expand Down
4 changes: 0 additions & 4 deletions Source/WebCore/rendering/RenderLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,6 @@ class RenderLayer : public CanMakeWeakPtr<RenderLayer>, public CanMakeCheckedPtr
WEBCORE_EXPORT RenderLayerScrollableArea* scrollableArea() const;
WEBCORE_EXPORT RenderLayerScrollableArea* ensureLayerScrollableArea();

#if PLATFORM(IOS_FAMILY)
// Called before the renderer's widget (if any) has been nulled out.
void willBeDestroyed();
#endif
String name() const;

Page& page() const { return renderer().page(); }
Expand Down
18 changes: 0 additions & 18 deletions Source/WebCore/rendering/RenderLayerBacking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -582,16 +582,6 @@ bool RenderLayerBacking::shouldSetContentsDisplayDelegate() const
}

#if PLATFORM(IOS_FAMILY)
void RenderLayerBacking::layerWillBeDestroyed()
{
auto& renderer = this->renderer();
if (RenderLayerCompositor::isCompositedPlugin(renderer)) {
auto* pluginViewBase = downcast<PluginViewBase>(downcast<RenderWidget>(renderer).widget());
if (pluginViewBase && m_graphicsLayer->contentsLayerForMedia())
pluginViewBase->detachPluginLayer();
}
}

bool RenderLayerBacking::needsIOSDumpRenderTreeMainFrameRenderViewLayerIsAlwaysOpaqueHack(const GraphicsLayer& layer) const
{
if (m_isMainFrameRenderViewLayer && IOSApplication::isDumpRenderTree()) {
Expand Down Expand Up @@ -1155,13 +1145,6 @@ bool RenderLayerBacking::updateConfiguration(const RenderLayer* compositingAnces
if (!pluginViewBase)
return;

#if PLATFORM(IOS_FAMILY)
// FIXME: This code can probably be removed: webkit.org/b/262808
if (pluginViewBase && !m_graphicsLayer->contentsLayerForMedia()) {
pluginViewBase->detachPluginLayer();
pluginViewBase->attachPluginLayer();
}
#else
switch (pluginViewBase->layerHostingStrategy()) {
case PluginLayerHostingStrategy::None:
break;
Expand All @@ -1172,7 +1155,6 @@ bool RenderLayerBacking::updateConfiguration(const RenderLayer* compositingAnces
// layer is parented in RenderLayerCompositor::updateBackingAndHierarchy().
break;
}
#endif
};

if (RenderLayerCompositor::isCompositedPlugin(renderer()))
Expand Down
4 changes: 0 additions & 4 deletions Source/WebCore/rendering/RenderLayerBacking.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ class RenderLayerBacking final : public GraphicsLayerClient {
explicit RenderLayerBacking(RenderLayer&);
~RenderLayerBacking();

#if PLATFORM(IOS_FAMILY)
void layerWillBeDestroyed();
#endif

// Do cleanup while layer->backing() is still valid.
void willBeDestroyed();

Expand Down
3 changes: 0 additions & 3 deletions Source/WebCore/rendering/RenderLayerModelObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,6 @@ void RenderLayerModelObject::destroyLayer()
{
ASSERT(!hasLayer());
ASSERT(m_layer);
#if PLATFORM(IOS_FAMILY)
m_layer->willBeDestroyed();
#endif
m_layer = nullptr;
}

Expand Down
5 changes: 0 additions & 5 deletions Source/WebCore/rendering/RenderWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,6 @@ RenderWidget::RenderWidget(Type type, HTMLFrameOwnerElement& element, RenderStyl

void RenderWidget::willBeDestroyed()
{
#if PLATFORM(IOS_FAMILY)
if (hasLayer())
layer()->willBeDestroyed();
#endif

if (AXObjectCache* cache = document().existingAXObjectCache()) {
cache->childrenChanged(this->parent());
cache->remove(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#if PLATFORM(IOS_FAMILY)

#import "WKPDFView.h"
#import "WKPreferencesInternal.h"
#import "WKUSDPreviewView.h"
#import "WKWebViewInternal.h"
#import "WebPageProxy.h"
Expand All @@ -51,9 +52,10 @@ - (instancetype)initWithConfiguration:(WKWebViewConfiguration *)configuration
return nil;

#if ENABLE(WKPDFVIEW)
// FIXME: When the UnifiedPDF Plugin is available, we need to undo this registration.
for (auto& type : WebCore::MIMETypeRegistry::pdfMIMETypes())
[self registerProvider:[WKPDFView class] forMIMEType:@(type.characters())];
if (!configuration.preferences->_preferences->unifiedPDFEnabled()) {
for (auto& type : WebCore::MIMETypeRegistry::pdfMIMETypes())
[self registerProvider:[WKPDFView class] forMIMEType:@(type.characters())];
}
#endif

#if USE(SYSTEM_PREVIEW)
Expand Down
47 changes: 0 additions & 47 deletions Source/WebKitLegacy/mac/WebCoreSupport/WebFrameLoaderClient.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1732,49 +1732,6 @@ virtual void invalidateRect(const WebCore::IntRect& rect)
}
};

#if PLATFORM(IOS_FAMILY)
@interface WAKView (UIKitSecretsWebKitKnowsAboutSeeUIWebPlugInView)
- (PlatformLayer *)pluginLayer;
- (BOOL)willProvidePluginLayer;
- (void)attachPluginLayer;
- (void)detachPluginLayer;
@end

class PluginWidgetIOS : public PluginWidget {
public:
PluginWidgetIOS(WAKView *view)
: PluginWidget(view)
{
}

virtual PlatformLayer* platformLayer() const
{
if (![platformWidget() respondsToSelector:@selector(pluginLayer)])
return nullptr;

return [platformWidget() pluginLayer];
}

virtual bool willProvidePluginLayer() const
{
return [platformWidget() respondsToSelector:@selector(willProvidePluginLayer)]
&& [platformWidget() willProvidePluginLayer];
}

virtual void attachPluginLayer()
{
if ([platformWidget() respondsToSelector:@selector(attachPluginLayer)])
[platformWidget() attachPluginLayer];
}

virtual void detachPluginLayer()
{
if ([platformWidget() respondsToSelector:@selector(detachPluginLayer)])
[platformWidget() detachPluginLayer];
}
};
#endif // PLATFORM(IOS_FAMILY)

static bool shouldBlockPlugin(WebBasePluginPackage *)
{
return true;
Expand Down Expand Up @@ -1876,11 +1833,7 @@ static bool shouldBlockPlugin(WebBasePluginPackage *)
}

ASSERT(view);
#if PLATFORM(IOS_FAMILY)
return adoptRef(new PluginWidgetIOS(view));
#else
return adoptRef(new PluginWidget(view));
#endif

END_BLOCK_OBJC_EXCEPTIONS

Expand Down

0 comments on commit e2dca80

Please sign in to comment.