Notify the UI delegate when a MediaDocument's natural size changes
authorjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 23 Jul 2015 23:46:59 +0000 (23:46 +0000)
committerjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 23 Jul 2015 23:46:59 +0000 (23:46 +0000)
https://bugs.webkit.org/show_bug.cgi?id=147182

Reviewed by Simon Fraser.

Source/WebCore:

Notify the MediaDocument that it's underlying media element has changed its natural size, either when
the media engine notifies us that the size changed, or when the ready state progresses to HAVE_METADATA.

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::setReadyState): Notify the media document.
(WebCore::HTMLMediaElement::mediaPlayerSizeChanged): Ditto.
* html/MediaDocument.cpp:
(WebCore::MediaDocument::mediaElementNaturalSizeChanged): Pass to the chrome client.
* html/MediaDocument.h:
* page/ChromeClient.h:

Source/WebKit2:

Pipe notifications of media document natural size changes up from the chrome client, through
to the UIProcess,  through the page client, through the WKWebView, to the UIDelegate.

* UIProcess/API/APIUIClient.h:
(API::UIClient::mediaDocumentNaturalSizeChanged):
* UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _mediaDocumentNaturalSizeChanged:]):
* UIProcess/API/Cocoa/WKWebViewInternal.h:
* UIProcess/Cocoa/UIDelegate.h:
* UIProcess/Cocoa/UIDelegate.mm:
(WebKit::UIDelegate::setDelegate):
(WebKit::UIDelegate::UIClient::mediaDocumentNaturalSizeChanged):
* UIProcess/PageClient.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::mediaDocumentNaturalSizeChanged):
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:
* UIProcess/ios/PageClientImplIOS.h:
* UIProcess/ios/PageClientImplIOS.mm:
(WebKit::PageClientImpl::mediaDocumentNaturalSizeChanged):
* UIProcess/mac/PageClientImpl.h:
* UIProcess/mac/PageClientImpl.mm:
(WebKit::PageClientImpl::mediaDocumentNaturalSizeChanged):
* WebProcess/WebCoreSupport/WebChromeClient.h:
* WebProcess/WebCoreSupport/WebChromeClient.cpp:
(WebKit::WebChromeClient::mediaDocumentNaturalSizeChanged):
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::mediaDocumentNaturalSizeChanged):
* WebProcess/WebPage/WebPage.h:
* UIProcess/API/gtk/PageClientImpl.h: Add default, empty implementation of new pure-virtual method.
* UIProcess/efl/WebViewEfl.h: Ditto.

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

26 files changed:
Source/WebCore/ChangeLog
Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/html/MediaDocument.cpp
Source/WebCore/html/MediaDocument.h
Source/WebCore/page/ChromeClient.h
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/APIUIClient.h
Source/WebKit2/UIProcess/API/Cocoa/WKUIDelegatePrivate.h
Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit2/UIProcess/API/Cocoa/WKWebViewInternal.h
Source/WebKit2/UIProcess/API/gtk/PageClientImpl.h
Source/WebKit2/UIProcess/Cocoa/UIDelegate.h
Source/WebKit2/UIProcess/Cocoa/UIDelegate.mm
Source/WebKit2/UIProcess/PageClient.h
Source/WebKit2/UIProcess/WebPageProxy.cpp
Source/WebKit2/UIProcess/WebPageProxy.h
Source/WebKit2/UIProcess/WebPageProxy.messages.in
Source/WebKit2/UIProcess/efl/WebViewEfl.h
Source/WebKit2/UIProcess/ios/PageClientImplIOS.h
Source/WebKit2/UIProcess/ios/PageClientImplIOS.mm
Source/WebKit2/UIProcess/mac/PageClientImpl.h
Source/WebKit2/UIProcess/mac/PageClientImpl.mm
Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp
Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.h
Source/WebKit2/WebProcess/WebPage/WebPage.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.h

index adc2825..ee81f94 100644 (file)
@@ -1,3 +1,21 @@
+2015-07-21  Jer Noble  <jer.noble@apple.com>
+
+        Notify the UI delegate when a MediaDocument's natural size changes
+        https://bugs.webkit.org/show_bug.cgi?id=147182
+
+        Reviewed by Simon Fraser.
+
+        Notify the MediaDocument that it's underlying media element has changed its natural size, either when
+        the media engine notifies us that the size changed, or when the ready state progresses to HAVE_METADATA.
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::setReadyState): Notify the media document.
+        (WebCore::HTMLMediaElement::mediaPlayerSizeChanged): Ditto.
+        * html/MediaDocument.cpp:
+        (WebCore::MediaDocument::mediaElementNaturalSizeChanged): Pass to the chrome client.
+        * html/MediaDocument.h:
+        * page/ChromeClient.h:
+
 2015-07-22  Simon Fraser  <simon.fraser@apple.com>
 
         Layer z-ordering is incorrect when scrolling on page witih position:fixed
index b043b84..7b2deaa 100644 (file)
@@ -2115,6 +2115,9 @@ void HTMLMediaElement::setReadyState(MediaPlayer::ReadyState state)
         if (renderer())
             renderer()->updateFromElement();
 
+        if (is<MediaDocument>(document()))
+            downcast<MediaDocument>(document()).mediaElementNaturalSizeChanged(expandedIntSize(m_player->naturalSize()));
+
         logMediaLoadRequest(document().page(), m_player->engineDescription(), String(), true);
     }
 
@@ -4386,6 +4389,9 @@ void HTMLMediaElement::mediaPlayerSizeChanged(MediaPlayer*)
 {
     LOG(Media, "HTMLMediaElement::mediaPlayerSizeChanged(%p)", this);
 
+    if (is<MediaDocument>(document()) && m_player)
+        downcast<MediaDocument>(document()).mediaElementNaturalSizeChanged(expandedIntSize(m_player->naturalSize()));
+
     beginProcessingMediaPlayerCallback();
     if (renderer())
         renderer()->updateFromElement();
index efe1b1f..2e8103e 100644 (file)
@@ -28,6 +28,8 @@
 #if ENABLE(VIDEO)
 #include "MediaDocument.h"
 
+#include "Chrome.h"
+#include "ChromeClient.h"
 #include "DocumentLoader.h"
 #include "EventNames.h"
 #include "ExceptionCodePlaceholder.h"
@@ -259,5 +261,17 @@ void MediaDocument::replaceMediaElementTimerFired()
     }
 }
 
+void MediaDocument::mediaElementNaturalSizeChanged(const IntSize& newSize)
+{
+    if (ownerElement())
+        return;
+
+    if (newSize.isZero())
+        return;
+
+    if (page())
+        page()->chrome().client().mediaDocumentNaturalSizeChanged(newSize);
+}
+
 }
 #endif
index 1cca785..ba69187 100644 (file)
@@ -41,6 +41,7 @@ public:
     virtual ~MediaDocument();
 
     void mediaElementSawUnsupportedTracks();
+    void mediaElementNaturalSizeChanged(const IntSize&);
     String outgoingReferrer() const { return m_outgoingReferrer; }
 
 private:
index 4f8143d..5fc116e 100644 (file)
@@ -449,6 +449,10 @@ public:
     virtual void playbackTargetPickerClientStateDidChange(uint64_t /*contextId*/, MediaProducer::MediaStateFlags) { }
 #endif
 
+#if ENABLE(VIDEO)
+    virtual void mediaDocumentNaturalSizeChanged(const WebCore::IntSize&) { }
+#endif
+
 protected:
     virtual ~ChromeClient() { }
 };
index f1d10d8..f6ee4e6 100644 (file)
@@ -1,3 +1,43 @@
+2015-07-21  Jer Noble  <jer.noble@apple.com>
+
+        Notify the UI delegate when a MediaDocument's natural size changes
+        https://bugs.webkit.org/show_bug.cgi?id=147182
+
+        Reviewed by Simon Fraser.
+
+        Pipe notifications of media document natural size changes up from the chrome client, through
+        to the UIProcess,  through the page client, through the WKWebView, to the UIDelegate.
+
+        * UIProcess/API/APIUIClient.h:
+        (API::UIClient::mediaDocumentNaturalSizeChanged):
+        * UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _mediaDocumentNaturalSizeChanged:]):
+        * UIProcess/API/Cocoa/WKWebViewInternal.h:
+        * UIProcess/Cocoa/UIDelegate.h:
+        * UIProcess/Cocoa/UIDelegate.mm:
+        (WebKit::UIDelegate::setDelegate):
+        (WebKit::UIDelegate::UIClient::mediaDocumentNaturalSizeChanged):
+        * UIProcess/PageClient.h:
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::mediaDocumentNaturalSizeChanged):
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebPageProxy.messages.in:
+        * UIProcess/ios/PageClientImplIOS.h:
+        * UIProcess/ios/PageClientImplIOS.mm:
+        (WebKit::PageClientImpl::mediaDocumentNaturalSizeChanged):
+        * UIProcess/mac/PageClientImpl.h:
+        * UIProcess/mac/PageClientImpl.mm:
+        (WebKit::PageClientImpl::mediaDocumentNaturalSizeChanged):
+        * WebProcess/WebCoreSupport/WebChromeClient.h:
+        * WebProcess/WebCoreSupport/WebChromeClient.cpp:
+        (WebKit::WebChromeClient::mediaDocumentNaturalSizeChanged):
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::mediaDocumentNaturalSizeChanged):
+        * WebProcess/WebPage/WebPage.h:
+        * UIProcess/API/gtk/PageClientImpl.h: Add default, empty implementation of new pure-virtual method.
+        * UIProcess/efl/WebViewEfl.h: Ditto.
+
 2015-07-23  Enrica Casucci  <enrica@apple.com>
 
         Removing one incorrect annotation from the previous change.
index d62f2da..0341345 100644 (file)
@@ -167,6 +167,10 @@ public:
 #endif
 
     virtual void didClickAutoFillButton(WebKit::WebPageProxy&, API::Object*) { }
+
+#if ENABLE(VIDEO)
+    virtual void mediaDocumentNaturalSizeChanged(const WebCore::IntSize&) { }
+#endif
 };
 
 } // namespace API
index 0dd1a99..e946c33 100644 (file)
@@ -54,6 +54,7 @@ struct UIEdgeInsets;
 - (void)_webViewFullscreenMayReturnToInline:(WKWebView *)webView;
 - (void)_webViewDidEnterFullscreen:(WKWebView *)webView WK_AVAILABLE(WK_MAC_TBA, 8_3);
 - (void)_webViewDidExitFullscreen:(WKWebView *)webView WK_AVAILABLE(WK_MAC_TBA, 8_3);
+- (void)_webView:(WKWebView *)webView mediaDocumentNaturalSizeChanged:(CGSize)size;
 
 #if TARGET_OS_IPHONE
 - (BOOL)_webView:(WKWebView *)webView shouldIncludeAppLinkActionsForElement:(_WKActivatedElementInfo *)element WK_AVAILABLE(NA, WK_IOS_TBA);
index 88943ce..97f56c5 100644 (file)
@@ -1881,6 +1881,15 @@ static WebCore::FloatPoint constrainContentOffset(WebCore::FloatPoint contentOff
 }
 #endif // PLATFORM(MAC)
 
+#if ENABLE(VIDEO)
+- (void)_mediaDocumentNaturalSizeChanged:(NSSize)newSize
+{
+    id <WKUIDelegatePrivate> uiDelegate = static_cast<id <WKUIDelegatePrivate>>([self UIDelegate]);
+    if ([uiDelegate respondsToSelector:@selector(_webView:mediaDocumentNaturalSizeChanged:)])
+        [uiDelegate _webView:self mediaDocumentNaturalSizeChanged:newSize];
+}
+#endif
+
 @end
 
 @implementation WKWebView (WKPrivate)
index d2def23..3a7a62d 100644 (file)
@@ -116,6 +116,10 @@ struct PrintInfo;
 
 - (WKPageRef)_pageForTesting;
 
+#if ENABLE(VIDEO)
+- (void)_mediaDocumentNaturalSizeChanged:(CGSize)newSize;
+#endif
+
 @end
 
 WKWebView* fromWebPageProxy(WebKit::WebPageProxy&);
index 11e7757..cfdee64 100644 (file)
@@ -135,6 +135,10 @@ private:
 
     virtual void didChangeBackgroundColor() override;
 
+#if ENABLE(VIDEO)
+    virtual void mediaDocumentNaturalSizeChanged(const WebCore::IntSize&) override { }
+#endif
+
     virtual void refView() override;
     virtual void derefView() override;
 
index fe1dd96..7e71dba 100644 (file)
@@ -76,6 +76,9 @@ private:
         virtual RetainPtr<NSArray> actionsForElement(_WKActivatedElementInfo *, RetainPtr<NSArray> defaultActions) override;
         virtual void didNotHandleTapAsClick(const WebCore::IntPoint&) override;
 #endif
+#if ENABLE(VIDEO)
+        virtual void mediaDocumentNaturalSizeChanged(const WebCore::IntSize&) override;
+#endif
 
         UIDelegate& m_uiDelegate;
     };
@@ -103,6 +106,9 @@ private:
         bool webViewActionsForElementDefaultActions : 1;
         bool webViewDidNotHandleTapAsClickAtPoint : 1;
 #endif
+#if ENABLE(VIDEO)
+        bool webViewMediaDocumentNaturalSizeChanged : 1;
+#endif
     } m_delegateMethods;
 };
 
index 57e0adc..ec95750 100644 (file)
@@ -85,6 +85,9 @@ void UIDelegate::setDelegate(id <WKUIDelegate> delegate)
     m_delegateMethods.webViewActionsForElementDefaultActions = [delegate respondsToSelector:@selector(_webView:actionsForElement:defaultActions:)];
     m_delegateMethods.webViewDidNotHandleTapAsClickAtPoint = [delegate respondsToSelector:@selector(_webView:didNotHandleTapAsClickAtPoint:)];
 #endif
+#if ENABLE(VIDEO)
+    m_delegateMethods.webViewMediaDocumentNaturalSizeChanged = [delegate respondsToSelector:@selector(_webView:mediaDocumentNaturalSizeChanged:)];
+#endif
 }
 
 UIDelegate::UIClient::UIClient(UIDelegate& uiDelegate)
@@ -338,6 +341,20 @@ void UIDelegate::UIClient::didNotHandleTapAsClick(const WebCore::IntPoint& point
 }
 #endif
 
+#if ENABLE(VIDEO)
+void UIDelegate::UIClient::mediaDocumentNaturalSizeChanged(const WebCore::IntSize& newSize)
+{
+    if (!m_uiDelegate.m_delegateMethods.webViewMediaDocumentNaturalSizeChanged)
+        return;
+
+    auto delegate = m_uiDelegate.m_delegate.get();
+    if (!delegate)
+        return;
+
+    [static_cast<id <WKUIDelegatePrivate>>(delegate) _webView:m_uiDelegate.m_webView mediaDocumentNaturalSizeChanged:newSize];
+}
+#endif
+
 } // namespace WebKit
 
 #endif // WK_API_ENABLED
index 5ba2d10..1638cc4 100644 (file)
@@ -329,6 +329,10 @@ public:
     virtual WebCore::WebMediaSessionManager& mediaSessionManager() = 0;
 #endif
 
+#if ENABLE(VIDEO)
+    virtual void mediaDocumentNaturalSizeChanged(const WebCore::IntSize&) = 0;
+#endif
+
     virtual void refView() = 0;
     virtual void derefView() = 0;
 };
index 25368c4..d7ebfc8 100644 (file)
@@ -6014,6 +6014,13 @@ void WebPageProxy::installViewStateChangeCompletionHandler(void (^completionHand
 }
 #endif
 
+#if ENABLE(VIDEO)
+void WebPageProxy::mediaDocumentNaturalSizeChanged(const WebCore::IntSize& newSize)
+{
+    m_uiClient->mediaDocumentNaturalSizeChanged(newSize);
+}
+#endif
+
 void WebPageProxy::setShouldDispatchFakeMouseMoveEvents(bool shouldDispatchFakeMouseMoveEvents)
 {
     m_process->send(Messages::WebPage::SetShouldDispatchFakeMouseMoveEvents(shouldDispatchFakeMouseMoveEvents), m_pageID);
index 9d8e909..21d2288 100644 (file)
@@ -1477,6 +1477,10 @@ private:
     void useFixedLayoutDidChange(bool useFixedLayout) { m_useFixedLayout = useFixedLayout; }
     void fixedLayoutSizeDidChange(WebCore::IntSize fixedLayoutSize) { m_fixedLayoutSize = fixedLayoutSize; }
 
+#if ENABLE(VIDEO)
+    void mediaDocumentNaturalSizeChanged(const WebCore::IntSize&);
+#endif
+
     void handleAutoFillButtonClick(const UserData&);
 
     void handleMessage(IPC::Connection&, const String& messageName, const UserData& messageBody);
index c03db54..f32bb7a 100644 (file)
@@ -444,6 +444,10 @@ messages -> WebPageProxy {
     PlaybackTargetPickerClientStateDidChange(uint64_t contextId, unsigned mediaState)
 #endif
 
+#if ENABLE(VIDEO)
+    MediaDocumentNaturalSizeChanged(WebCore::IntSize newSize)
+#endif
+
     UseFixedLayoutDidChange(bool useFixedLayout)
     FixedLayoutSizeDidChange(WebCore::IntSize fixedLayoutSize)
 }
index a0caf10..3622247 100644 (file)
@@ -90,6 +90,10 @@ private:
     virtual void didFinishLoadForMainFrame() override final { }
     virtual void didSameDocumentNavigationForMainFrame(SameDocumentNavigationType) override final { }
 
+#if ENABLE(VIDEO)
+    virtual void mediaDocumentNaturalSizeChanged(const WebCore::IntSize&) override final { }
+#endif
+
     virtual void refView() override final { }
     virtual void derefView() override final { }
 
index cc40b56..1585f05 100644 (file)
@@ -186,6 +186,10 @@ private:
 
     virtual void didChangeBackgroundColor() override;
 
+#if ENABLE(VIDEO)
+    virtual void mediaDocumentNaturalSizeChanged(const WebCore::IntSize&) override;
+#endif
+
     virtual void refView() override;
     virtual void derefView() override;
 
index a0816c4..7569fbc 100644 (file)
@@ -739,6 +739,14 @@ void PageClientImpl::didChangeBackgroundColor()
     [m_webView _updateScrollViewBackground];
 }
 
+#if ENABLE(VIDEO)
+void PageClientImpl::mediaDocumentNaturalSizeChanged(const IntSize& newSize)
+{
+    [m_webView _mediaDocumentNaturalSizeChanged:newSize];
+}
+#endif
+
+
 void PageClientImpl::refView()
 {
     [m_contentView retain];
index abe394b..c69eea6 100644 (file)
@@ -203,6 +203,10 @@ private:
 
     virtual void didChangeBackgroundColor() override;
 
+#if ENABLE(VIDEO)
+    virtual void mediaDocumentNaturalSizeChanged(const WebCore::IntSize&) override;
+#endif
+
     WKView *m_wkView;
     WKWebView *m_webView;
     RetainPtr<WKEditorUndoTargetObjC> m_undoTarget;
index 81d0b1b..3bbdf18 100644 (file)
@@ -836,6 +836,13 @@ WebCore::WebMediaSessionManager& PageClientImpl::mediaSessionManager()
 }
 #endif
 
+#if ENABLE(VIDEO)
+void PageClientImpl::mediaDocumentNaturalSizeChanged(const IntSize& newSize)
+{
+    [m_webView _mediaDocumentNaturalSizeChanged:newSize];
+}
+#endif
+
 void PageClientImpl::refView()
 {
     CFRetain(m_wkView);
index 939dccc..5dfb18b 100644 (file)
@@ -1158,5 +1158,11 @@ void WebChromeClient::playbackTargetPickerClientStateDidChange(uint64_t contextI
 }
 #endif
 
+#if ENABLE(VIDEO)
+void WebChromeClient::mediaDocumentNaturalSizeChanged(const WebCore::IntSize& newSize)
+{
+    m_page->mediaDocumentNaturalSizeChanged(newSize);
+}
+#endif
 
 } // namespace WebKit
index 1653dfc..8af49b1 100644 (file)
@@ -323,6 +323,10 @@ private:
     virtual void playbackTargetPickerClientStateDidChange(uint64_t, WebCore::MediaProducer::MediaStateFlags) override;
 #endif
 
+#if ENABLE(VIDEO)
+    virtual void mediaDocumentNaturalSizeChanged(const WebCore::IntSize&) override;
+#endif
+
     String m_cachedToolTip;
     mutable RefPtr<WebFrame> m_cachedFrameSetLargestFrame;
     mutable bool m_cachedMainFrameHasHorizontalScrollbar;
index c53eb9d..94684d4 100644 (file)
@@ -5031,4 +5031,11 @@ void WebPage::setUserContentExtensionsEnabled(bool userContentExtensionsEnabled)
     m_page->setUserContentExtensionsEnabled(userContentExtensionsEnabled);
 }
 
+#if ENABLE(VIDEO)
+void WebPage::mediaDocumentNaturalSizeChanged(const IntSize& newSize)
+{
+    send(Messages::WebPageProxy::MediaDocumentNaturalSizeChanged(newSize));
+}
+#endif
+
 } // namespace WebKit
index eaa70e3..f46fda6 100644 (file)
@@ -902,6 +902,10 @@ public:
     void setInputMethodState(bool);
 #endif
 
+#if ENABLE(VIDEO)
+    void mediaDocumentNaturalSizeChanged(const WebCore::IntSize&);
+#endif
+
 private:
     WebPage(uint64_t pageID, const WebPageCreationParameters&);