Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[PluginProxy] Add a setting to disable video plugin proxy support in …
…HTMLMediaElement.

https://bugs.webkit.org/show_bug.cgi?id=123621

Reviewed by Eric Carlson.

Source/WebCore:

Add a new Setting which will disable the video plugin proxy. Enable support for AVFoundation
in iOS (which requries fixing a few compile errors resulting from classes and methods which
are not available on iOS.

* WebCore.exp.in: Export wkAVAssetResolvedURL.
* css/StyleResolver.cpp:
(WebCore::StyleResolver::canShareStyleWithElement): Make conditional upon
    new isVideoPluginProxyEnabled() setting.
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::parseAttribute): Ditto.
* html/HTMLMediaElement.h:
* html/HTMLVideoElement.cpp:
(WebCore::HTMLVideoElement::createRenderer): Ditto.
(WebCore::HTMLVideoElement::attach): Ditto.
(WebCore::HTMLVideoElement::parseAttribute): Ditto.
(HTMLVideoElement::setDisplayMode): Ditto.
* html/HTMLVideoElement.h:
* page/Settings.cpp:
(WebCore::Settings::setVideoPluginProxyEnabled): Simple setter.
* page/Settings.h:
(WebCore::Settings::isVideoPluginProxyEnabled): Simple getter.
* platform/graphics/MediaPlayer.cpp:
(WebCore::installedMediaEngines): Conditionally add MediaPlayerPrivateIOS and always add
    MediaPlayerPriateAVFoundationObjC.
* platform/graphics/MediaPlayerPrivate.h:
(WebCore::MediaPlayerPrivateInterface::deliverNotification): Add default implementation.
(WebCore::MediaPlayerPrivateInterface::setMediaPlayerProxy): Ditto.
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h:
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
(WebCore::MediaPlayerPrivateAVFoundationObjC::MediaPlayerPrivateAVFoundationObjC): Use new
    HAS_ and USE_ macros instead of __MAC_OS_MIN_VERNSION_REQUIRED.
(WebCore::MediaPlayerPrivateAVFoundationObjC::~MediaPlayerPrivateAVFoundationObjC): Ditto.
(WebCore::MediaPlayerPrivateAVFoundationObjC::hasContextRenderer): Ditto.
(WebCore::MediaPlayerPrivateAVFoundationObjC::createContextVideoRenderer): Ditto.
(WebCore::MediaPlayerPrivateAVFoundationObjC::destroyContextVideoRenderer): Ditto.
(WebCore::MediaPlayerPrivateAVFoundationObjC::createAVAssetForURL): Ditto.
(WebCore::MediaPlayerPrivateAVFoundationObjC::paint): Ditto.
(WebCore::MediaPlayerPrivateAVFoundationObjC::createVideoLayer): Use cachedCGColor instead
    of CGColorGetConstantColor.
(WebCore::MediaPlayerPrivateAVFoundationObjC::createVideoOutput): Use CVPixelBuffer pixel
    format constant instead of QuickDraw constant.
(WebCore::MediaPlayerPrivateAVFoundationObjC::createPixelBuffer): Ditto.
(WebCore::MediaPlayerPrivateAVFoundationObjC::paintWithVideoOutput): Draw to intermediary
    CGImage on iOS.
* platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.h:
* platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm:
* platform/ios/WebCoreSystemInterfaceIOS.mm:
* platform/mac/WebCoreSystemInterface.h:

Source/WebKit/mac:

Add a new isVideoPluginProxyEnabled setting.

* WebView/WebPreferenceKeysPrivate.h:
* WebView/WebPreferences.mm:
(+[WebPreferences initialize]): Set isVideoPluginProxyEnabled preference.
(-[WebPreferences isVideoPluginProxyEnabled]): Pass through to Settings.
* WebView/WebPreferencesPrivate.h:
* WebView/WebView.mm:
(-[WebView _preferencesChanged:]): Set isVideoPluginProxyEnabled preference.

Source/WebKit2:

Add WebKit2 functions for setting then new isVideoPluginProxyEnabled preference.

* Shared/WebPreferencesStore.h:
* UIProcess/API/C/WKPreferences.cpp:
(WKPreferencesSetVideoPluginProxyEnabled):
(WKPreferencesGetVideoPluginProxyEnabled):
* UIProcess/API/C/WKPreferences.h:
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::updatePreferences):

Source/WTF:

Enable WTF_USE_AVFOUNDATION and add some HAVE_AVFOUNDATION_* defines
to replace the existing __MAC_OS_X_VERSION_MIN_REQUIRED macros in
MediaPlayerPrivateAVFoundationObjC.mm.

* wtf/Platform.h:

Canonical link: https://commits.webkit.org/141945@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@158599 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
jernoble committed Nov 4, 2013
1 parent d3c1830 commit 5e0e3ce
Show file tree
Hide file tree
Showing 27 changed files with 354 additions and 112 deletions.
13 changes: 13 additions & 0 deletions Source/WTF/ChangeLog
@@ -1,3 +1,16 @@
2013-11-01 Jer Noble <jer.noble@apple.com>

[PluginProxy] Add a setting to disable video plugin proxy support in HTMLMediaElement.
https://bugs.webkit.org/show_bug.cgi?id=123621

Reviewed by Eric Carlson.

Enable WTF_USE_AVFOUNDATION and add some HAVE_AVFOUNDATION_* defines
to replace the existing __MAC_OS_X_VERSION_MIN_REQUIRED macros in
MediaPlayerPrivateAVFoundationObjC.mm.

* wtf/Platform.h:

2013-11-02 Patrick Gansterer <paroga@webkit.org>

Fix compilation of DateMath.cpp with MSVC
Expand Down
18 changes: 12 additions & 6 deletions Source/WTF/wtf/Platform.h
Expand Up @@ -965,24 +965,30 @@
#define ENABLE_BINDING_INTEGRITY 1
#endif

#if PLATFORM(MAC) && !PLATFORM(IOS)
#if PLATFORM(IOS) || PLATFORM(MAC)
#define WTF_USE_AVFOUNDATION 1
#endif

#if (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 60000) || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1080)
#if (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 60000) || ((PLATFORM(MAC) && !PLATFORM(IOS)) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1080)
#define WTF_USE_COREMEDIA 1
#define HAVE_AVFOUNDATION_VIDEO_OUTPUT 1
#endif

#if (PLATFORM(MAC) || (OS(WINDOWS) && USE(CG))) && !PLATFORM(IOS) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1080
#if (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 50000) || ((PLATFORM(MAC) && !PLATFORM(IOS)) || (OS(WINDOWS) && USE(CG)) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1080)
#define HAVE_AVFOUNDATION_MEDIA_SELECTION_GROUP 1
#endif

#if (PLATFORM(MAC) || (OS(WINDOWS) && USE(CG))) && !PLATFORM(IOS) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
#if (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 70000) || (((PLATFORM(MAC) && !PLATFORM(IOS)) || (OS(WINDOWS) && USE(CG))) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090)
#define HAVE_AVFOUNDATION_LEGIBLE_OUTPUT_SUPPORT 1
#define HAVE_MEDIA_ACCESSIBILITY_FRAMEWORK 1
#endif

#if (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 70000) || ((PLATFORM(MAC) || (OS(WINDOWS) && USE(CG))) && !PLATFORM(IOS) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090)
#define HAVE_MEDIA_ACCESSIBILITY_FRAMEWORK 1
#if (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 60000) || ((PLATFORM(MAC) && !PLATFORM(IOS)) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090)
#define HAVE_AVFOUNDATION_LOADER_DELEGATE 1
#endif

#if (PLATFORM(MAC) && !PLATFORM(IOS)) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1080
#define WTF_USE_VIDEOTOOLBOX 1
#endif

#if PLATFORM(MAC) || PLATFORM(GTK) || (PLATFORM(WIN) && !USE(WINGDI) && !PLATFORM(WIN_CAIRO))
Expand Down
56 changes: 56 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,59 @@
2013-11-01 Jer Noble <jer.noble@apple.com>

[PluginProxy] Add a setting to disable video plugin proxy support in HTMLMediaElement.
https://bugs.webkit.org/show_bug.cgi?id=123621

Reviewed by Eric Carlson.

Add a new Setting which will disable the video plugin proxy. Enable support for AVFoundation
in iOS (which requries fixing a few compile errors resulting from classes and methods which
are not available on iOS.

* WebCore.exp.in: Export wkAVAssetResolvedURL.
* css/StyleResolver.cpp:
(WebCore::StyleResolver::canShareStyleWithElement): Make conditional upon
new isVideoPluginProxyEnabled() setting.
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::parseAttribute): Ditto.
* html/HTMLMediaElement.h:
* html/HTMLVideoElement.cpp:
(WebCore::HTMLVideoElement::createRenderer): Ditto.
(WebCore::HTMLVideoElement::attach): Ditto.
(WebCore::HTMLVideoElement::parseAttribute): Ditto.
(HTMLVideoElement::setDisplayMode): Ditto.
* html/HTMLVideoElement.h:
* page/Settings.cpp:
(WebCore::Settings::setVideoPluginProxyEnabled): Simple setter.
* page/Settings.h:
(WebCore::Settings::isVideoPluginProxyEnabled): Simple getter.
* platform/graphics/MediaPlayer.cpp:
(WebCore::installedMediaEngines): Conditionally add MediaPlayerPrivateIOS and always add
MediaPlayerPriateAVFoundationObjC.
* platform/graphics/MediaPlayerPrivate.h:
(WebCore::MediaPlayerPrivateInterface::deliverNotification): Add default implementation.
(WebCore::MediaPlayerPrivateInterface::setMediaPlayerProxy): Ditto.
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h:
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
(WebCore::MediaPlayerPrivateAVFoundationObjC::MediaPlayerPrivateAVFoundationObjC): Use new
HAS_ and USE_ macros instead of __MAC_OS_MIN_VERNSION_REQUIRED.
(WebCore::MediaPlayerPrivateAVFoundationObjC::~MediaPlayerPrivateAVFoundationObjC): Ditto.
(WebCore::MediaPlayerPrivateAVFoundationObjC::hasContextRenderer): Ditto.
(WebCore::MediaPlayerPrivateAVFoundationObjC::createContextVideoRenderer): Ditto.
(WebCore::MediaPlayerPrivateAVFoundationObjC::destroyContextVideoRenderer): Ditto.
(WebCore::MediaPlayerPrivateAVFoundationObjC::createAVAssetForURL): Ditto.
(WebCore::MediaPlayerPrivateAVFoundationObjC::paint): Ditto.
(WebCore::MediaPlayerPrivateAVFoundationObjC::createVideoLayer): Use cachedCGColor instead
of CGColorGetConstantColor.
(WebCore::MediaPlayerPrivateAVFoundationObjC::createVideoOutput): Use CVPixelBuffer pixel
format constant instead of QuickDraw constant.
(WebCore::MediaPlayerPrivateAVFoundationObjC::createPixelBuffer): Ditto.
(WebCore::MediaPlayerPrivateAVFoundationObjC::paintWithVideoOutput): Draw to intermediary
CGImage on iOS.
* platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.h:
* platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm:
* platform/ios/WebCoreSystemInterfaceIOS.mm:
* platform/mac/WebCoreSystemInterface.h:

2013-11-04 Andreas Kling <akling@apple.com>

REGRESSION(r158561): fast/block/float/float-append-child-crash.html asserting.
Expand Down
2 changes: 2 additions & 0 deletions Source/WebCore/WebCore.exp.in
Expand Up @@ -2790,6 +2790,8 @@ __ZN7WebCore16ScriptController16createRootObjectEPv
#if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
__ZN7WebCore16HTMLMediaElement19deliverNotificationE32MediaPlayerProxyNotificationType
__ZN7WebCore16HTMLMediaElement19setMediaPlayerProxyEP19WebMediaPlayerProxy
__ZN7WebCore8Settings24gVideoPluginProxyEnabledE
__ZN7WebCore8Settings26setVideoPluginProxyEnabledEb
__ZN7WebCore9HTMLNames8audioTagE
#endif

Expand Down
16 changes: 11 additions & 5 deletions Source/WebCore/css/StyleResolver.cpp
Expand Up @@ -187,6 +187,10 @@
#include "WebVTTElement.h"
#endif

#if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
#include "HTMLMediaElement.h"
#endif

namespace WebCore {

using namespace HTMLNames;
Expand Down Expand Up @@ -671,13 +675,15 @@ bool StyleResolver::canShareStyleWithElement(StyledElement* element) const
#if USE(ACCELERATED_COMPOSITING)
// Turn off style sharing for elements that can gain layers for reasons outside of the style system.
// See comments in RenderObject::setStyle().
if (element->hasTagName(iframeTag) || element->hasTagName(frameTag) || element->hasTagName(embedTag) || element->hasTagName(objectTag) || element->hasTagName(appletTag) || element->hasTagName(canvasTag)
if (element->hasTagName(iframeTag) || element->hasTagName(frameTag) || element->hasTagName(embedTag) || element->hasTagName(objectTag) || element->hasTagName(appletTag) || element->hasTagName(canvasTag))
return false;

#if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
// With proxying, the media elements are backed by a RenderEmbeddedObject.
|| element->hasTagName(videoTag) || isHTMLAudioElement(element)
#endif
)
// With proxying, the media elements are backed by a RenderEmbeddedObject.
if ((element->hasTagName(videoTag) || element->hasTagName(audioTag)) && toMediaElement(element)->shouldUseVideoPluginProxy())
return false;
#endif

#endif

if (elementHasDirectionAuto(element))
Expand Down
117 changes: 67 additions & 50 deletions Source/WebCore/html/HTMLMediaElement.cpp
Expand Up @@ -547,8 +547,10 @@ void HTMLMediaElement::finishParsingChildren()
m_parsingInProgress = false;

#if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
document().updateStyleIfNeeded();
createMediaPlayerProxy();
if (shouldUseVideoPluginProxy()) {
document().updateStyleIfNeeded();
createMediaPlayerProxy();
}
#endif

#if ENABLE(VIDEO_TRACK)
Expand All @@ -563,28 +565,28 @@ void HTMLMediaElement::finishParsingChildren()
bool HTMLMediaElement::rendererIsNeeded(const RenderStyle& style)
{
#if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
UNUSED_PARAM(style);
return true;
#else
return controls() && HTMLElement::rendererIsNeeded(style);
if (shouldUseVideoPluginProxy())
return true;
#endif
return controls() && HTMLElement::rendererIsNeeded(style);
}

RenderElement* HTMLMediaElement::createRenderer(PassRef<RenderStyle> style)
{
#if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
// Setup the renderer if we already have a proxy widget.
RenderEmbeddedObject* mediaRenderer = new RenderEmbeddedObject(*this, std::move(style));
if (m_proxyWidget) {
mediaRenderer->setWidget(m_proxyWidget);

if (Frame* frame = document().frame())
frame->loader().client().showMediaPlayerProxyPlugin(m_proxyWidget.get());
if (shouldUseVideoPluginProxy()) {
// Setup the renderer if we already have a proxy widget.
RenderEmbeddedObject* mediaRenderer = new RenderEmbeddedObject(*this, std::move(style));
if (m_proxyWidget) {
mediaRenderer->setWidget(m_proxyWidget);

if (Frame* frame = document().frame())
frame->loader().client().showMediaPlayerProxyPlugin(m_proxyWidget.get());
}
return mediaRenderer;
}
return mediaRenderer;
#else
return new RenderMedia(*this, std::move(style));
#endif
return new RenderMedia(*this, std::move(style));
}

bool HTMLMediaElement::childShouldCreateRenderer(const Node* child) const
Expand Down Expand Up @@ -653,7 +655,8 @@ void HTMLMediaElement::willAttachRenderers()
ASSERT(!attached());

#if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
m_needWidgetUpdate = true;
if (shouldUseVideoPluginProxy())
m_needWidgetUpdate = true;
#endif
}

Expand Down Expand Up @@ -681,9 +684,10 @@ void HTMLMediaElement::scheduleDelayedAction(DelayedActionType actionType)

if ((actionType & LoadMediaResource) && !(m_pendingActionFlags & LoadMediaResource)) {
#if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
createMediaPlayerProxy();
if (shouldUseVideoPluginProxy())
createMediaPlayerProxy();
#endif

prepareForLoad();
setFlags(m_pendingActionFlags, LoadMediaResource);
}
Expand Down Expand Up @@ -842,14 +846,15 @@ void HTMLMediaElement::prepareForLoad()
closeMediaSource();
#endif

#if !ENABLE(PLUGIN_PROXY_FOR_VIDEO)
createMediaPlayer();
#else
if (m_player)
m_player->cancelLoad();
else
createMediaPlayerProxy();
#if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
if (shouldUseVideoPluginProxy())
if (m_player)
m_player->cancelLoad();
else
createMediaPlayerProxy();
} else
#endif
createMediaPlayer();

// 4 - If the media element's networkState is not set to NETWORK_EMPTY, then run these substeps
if (m_networkState != NETWORK_EMPTY) {
Expand Down Expand Up @@ -1020,10 +1025,11 @@ void HTMLMediaElement::loadNextSourceChild()
return;
}

#if !ENABLE(PLUGIN_PROXY_FOR_VIDEO)
// Recreate the media player for the new url
createMediaPlayer();
#if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
if (!shouldUseVideoPluginProxy())
#endif
// Recreate the media player for the new url
createMediaPlayer();

m_loadState = LoadingFromSourceElement;
loadResource(mediaURL, contentType, keySystem);
Expand Down Expand Up @@ -4163,14 +4169,11 @@ void HTMLMediaElement::clearMediaPlayer(int flags)
removeAllInbandTracks();
#endif

#if !ENABLE(PLUGIN_PROXY_FOR_VIDEO)

#if ENABLE(MEDIA_SOURCE)
closeMediaSource();
#endif

m_player.clear();
#endif
stopPeriodicTimers();
m_loadTimer.stop();

Expand Down Expand Up @@ -4287,24 +4290,26 @@ void HTMLMediaElement::visibilityStateChanged()
void HTMLMediaElement::defaultEventHandler(Event* event)
{
#if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
auto renderer = this->renderer();
if (!renderer || !renderer->isWidget())
return;
if (shouldUseVideoPluginProxy()) {
auto renderer = this->renderer();
if (!renderer || !renderer->isWidget())
return;

if (Widget* widget = toRenderWidget(renderer)->widget())
widget->handleEvent(event);
#else
HTMLElement::defaultEventHandler(event);
if (Widget* widget = toRenderWidget(renderer)->widget())
widget->handleEvent(event);
return;
}
#endif
HTMLElement::defaultEventHandler(event);
}

bool HTMLMediaElement::willRespondToMouseClickEvents()
{
#if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
return true;
#else
return HTMLElement::willRespondToMouseClickEvents();
if (shouldUseVideoPluginProxy())
return true;
#endif
return HTMLElement::willRespondToMouseClickEvents();
}

#if ENABLE(VIDEO_TRACK)
Expand Down Expand Up @@ -4724,13 +4729,25 @@ bool HTMLMediaElement::createMediaControls()

void HTMLMediaElement::configureMediaControls()
{
#if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
if (shouldUseVideoPluginProxy()) {
if (m_player)
m_player->setControls(controls());

if (!hasMediaControls() && inDocument())
createMediaControls();
return;
}
#endif

#if ENABLE(MEDIA_CONTROLS_SCRIPT)
if (!controls() || !inDocument())
return;

ensureUserAgentShadowRoot();
return;
#elif !ENABLE(PLUGIN_PROXY_FOR_VIDEO)
#endif

if (!controls() || !inDocument()) {
if (hasMediaControls())
mediaControls()->hide();
Expand All @@ -4741,13 +4758,6 @@ void HTMLMediaElement::configureMediaControls()
return;

mediaControls()->show();
#else
if (m_player)
m_player->setControls(controls());

if (!hasMediaControls() && inDocument())
createMediaControls();
#endif
}

#if ENABLE(VIDEO_TRACK)
Expand Down Expand Up @@ -5185,6 +5195,13 @@ void HTMLMediaElement::removeBehaviorsRestrictionsAfterFirstUserGesture()
m_restrictions = NoRestrictions;
}

#if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
bool HTMLMediaElement::shouldUseVideoPluginProxy() const
{
return document()->settings() && document()->settings()->isVideoPluginProxyEnabled();
}
#endif

#if ENABLE(MEDIA_CONTROLS_SCRIPT)
DOMWrapperWorld& HTMLMediaElement::ensureIsolatedWorld()
{
Expand Down

0 comments on commit 5e0e3ce

Please sign in to comment.