Title: [187251] trunk/Source
Revision
187251
Author
[email protected]
Date
2015-07-23 14:15:28 -0700 (Thu, 23 Jul 2015)

Log Message

[iOS] Add an explicit API to allow media documents to (temporarily) play inline
https://bugs.webkit.org/show_bug.cgi?id=147181

Reviewed by Beth Dakin.

Source/WebCore:

Add listeners for the new allowsMediaDocumentInlinePlayback API. When this value becomes
NO, force any playing MediaDocuments to enter fullscreen mode.

* dom/Document.cpp:
(WebCore::Document::registerForAllowsMediaDocumentInlinePlaybackChangedCallbacks): Added registration method.
(WebCore::Document::unregisterForAllowsMediaDocumentInlinePlaybackChangedCallbacks): Added deregistration method.
(WebCore::Document::allowsMediaDocumentInlinePlaybackChanged): Notify all listeners.
* dom/Document.h:
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::registerWithDocument): Listen for allowsMediaDocumentInlinePlayback changes.
(WebCore::HTMLMediaElement::unregisterWithDocument): Stop listening to same.
(WebCore::HTMLMediaElement::allowsMediaDocumentInlinePlaybackChanged): Enter fullscreen mode if the value
    changes to false during playback.
* html/HTMLMediaElement.h:
* html/MediaElementSession.cpp:
(WebCore::MediaElementSession::requiresFullscreenForVideoPlayback): Early true if the override value is set.
* page/Page.cpp:
(WebCore::Page::setAllowsMediaDocumentInlinePlayback): Notify all documents of the changed value.
* page/Page.h:
(WebCore::Page::allowsMediaDocumentInlinePlayback): Simple getter.

Source/WebKit2:

Add a WKWebView(Private) API which allows MediaDocuments loaded by the view to play their contents inline, regardless
of whether inline playback is restricted on the current device.

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _setRequiresUserActionForMediaPlayback:]): Added. Pass through to WebPageProxy.
(-[WKWebView _allowsMediaDocumentInlinePlayback]): Ditto.
* UIProcess/API/Cocoa/WKWebViewPrivate.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::allowsMediaDocumentInlinePlayback): Simple getter.
(WebKit::WebPageProxy::setAllowsMediaDocumentInlinePlayback): Set, and conditionally pass the new value to WebPage.
* UIProcess/WebPageProxy.h:
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::setAllowsMediaDocumentInlinePlayback): Set, and conditionally notify WebCore page of the change.
* WebProcess/WebPage/WebPage.h:
(WebKit::WebPage::allowsMediaDocumentInlinePlayback): Simple getter.
* WebProcess/WebPage/WebPage.messages.in: Add new messages.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (187250 => 187251)


--- trunk/Source/WebCore/ChangeLog	2015-07-23 20:53:47 UTC (rev 187250)
+++ trunk/Source/WebCore/ChangeLog	2015-07-23 21:15:28 UTC (rev 187251)
@@ -1,3 +1,31 @@
+2015-07-21  Jer Noble  <[email protected]>
+
+        [iOS] Add an explicit API to allow media documents to (temporarily) play inline
+        https://bugs.webkit.org/show_bug.cgi?id=147181
+
+        Reviewed by Beth Dakin.
+
+        Add listeners for the new allowsMediaDocumentInlinePlayback API. When this value becomes
+        NO, force any playing MediaDocuments to enter fullscreen mode.
+
+        * dom/Document.cpp:
+        (WebCore::Document::registerForAllowsMediaDocumentInlinePlaybackChangedCallbacks): Added registration method.
+        (WebCore::Document::unregisterForAllowsMediaDocumentInlinePlaybackChangedCallbacks): Added deregistration method.
+        (WebCore::Document::allowsMediaDocumentInlinePlaybackChanged): Notify all listeners.
+        * dom/Document.h:
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::registerWithDocument): Listen for allowsMediaDocumentInlinePlayback changes.
+        (WebCore::HTMLMediaElement::unregisterWithDocument): Stop listening to same.
+        (WebCore::HTMLMediaElement::allowsMediaDocumentInlinePlaybackChanged): Enter fullscreen mode if the value
+            changes to false during playback.
+        * html/HTMLMediaElement.h:
+        * html/MediaElementSession.cpp:
+        (WebCore::MediaElementSession::requiresFullscreenForVideoPlayback): Early true if the override value is set.
+        * page/Page.cpp:
+        (WebCore::Page::setAllowsMediaDocumentInlinePlayback): Notify all documents of the changed value.
+        * page/Page.h:
+        (WebCore::Page::allowsMediaDocumentInlinePlayback): Simple getter.
+
 2015-07-23  Devin Rousso  <[email protected]>
 
         Web Inspector: Add a function to CSSCompletions to get a list of supported system fonts

Modified: trunk/Source/WebCore/dom/Document.cpp (187250 => 187251)


--- trunk/Source/WebCore/dom/Document.cpp	2015-07-23 20:53:47 UTC (rev 187250)
+++ trunk/Source/WebCore/dom/Document.cpp	2015-07-23 21:15:28 UTC (rev 187251)
@@ -1614,6 +1614,25 @@
     return pageVisibilityState() != PageVisibilityStateVisible;
 }
 
+
+#if ENABLE(VIDEO)
+void Document::registerForAllowsMediaDocumentInlinePlaybackChangedCallbacks(HTMLMediaElement& element)
+{
+    m_allowsMediaDocumentInlinePlaybackElements.add(&element);
+}
+
+void Document::unregisterForAllowsMediaDocumentInlinePlaybackChangedCallbacks(HTMLMediaElement& element)
+{
+    m_allowsMediaDocumentInlinePlaybackElements.remove(&element);
+}
+
+void Document::allowsMediaDocumentInlinePlaybackChanged()
+{
+    for (auto* element : m_allowsMediaDocumentInlinePlaybackElements)
+        element->allowsMediaDocumentInlinePlaybackChanged();
+}
+#endif
+
 #if ENABLE(CSP_NEXT)
 DOMSecurityPolicy& Document::securityPolicy()
 {

Modified: trunk/Source/WebCore/dom/Document.h (187250 => 187251)


--- trunk/Source/WebCore/dom/Document.h	2015-07-23 20:53:47 UTC (rev 187250)
+++ trunk/Source/WebCore/dom/Document.h	2015-07-23 21:15:28 UTC (rev 187251)
@@ -1014,6 +1014,12 @@
     void registerForVisibilityStateChangedCallbacks(Element*);
     void unregisterForVisibilityStateChangedCallbacks(Element*);
 
+#if ENABLE(VIDEO)
+    void registerForAllowsMediaDocumentInlinePlaybackChangedCallbacks(HTMLMediaElement&);
+    void unregisterForAllowsMediaDocumentInlinePlaybackChangedCallbacks(HTMLMediaElement&);
+    void allowsMediaDocumentInlinePlaybackChanged();
+#endif
+
     WEBCORE_EXPORT void setShouldCreateRenderers(bool);
     bool shouldCreateRenderers();
 
@@ -1550,6 +1556,9 @@
 #endif
 
     HashSet<Element*> m_visibilityStateCallbackElements;
+#if ENABLE(VIDEO)
+    HashSet<HTMLMediaElement*> m_allowsMediaDocumentInlinePlaybackElements;
+#endif
 
     HashMap<StringImpl*, Element*, CaseFoldingHash> m_elementsByAccessKey;
     bool m_accessKeyMapValid;

Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (187250 => 187251)


--- trunk/Source/WebCore/html/HTMLMediaElement.cpp	2015-07-23 20:53:47 UTC (rev 187250)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp	2015-07-23 21:15:28 UTC (rev 187251)
@@ -518,6 +518,8 @@
     document.registerForPageCacheSuspensionCallbacks(this);
 #endif
 
+    document.registerForAllowsMediaDocumentInlinePlaybackChangedCallbacks(*this);
+
     document.addAudioProducer(this);
     addElementToDocumentMap(*this, document);
 }
@@ -550,6 +552,8 @@
     document.unregisterForPageCacheSuspensionCallbacks(this);
 #endif
 
+    document.unregisterForAllowsMediaDocumentInlinePlaybackChangedCallbacks(*this);
+
     document.removeAudioProducer(this);
     removeElementFromDocumentMap(*this, document);
 }
@@ -3882,7 +3886,7 @@
     m_resizeTaskQueue.enqueueTask(task);
 #endif
 }
-    
+
 void HTMLMediaElement::setSelectedTextTrack(TextTrack* trackToSelect)
 {
     TextTrackList* trackList = textTracks();
@@ -6528,6 +6532,12 @@
 
 #endif
 
+void HTMLMediaElement::allowsMediaDocumentInlinePlaybackChanged()
+{
+    if (potentiallyPlaying() && m_mediaSession->requiresFullscreenForVideoPlayback(*this) && !isFullscreen())
+        enterFullscreen();
 }
 
+}
+
 #endif

Modified: trunk/Source/WebCore/html/HTMLMediaElement.h (187250 => 187251)


--- trunk/Source/WebCore/html/HTMLMediaElement.h	2015-07-23 20:53:47 UTC (rev 187250)
+++ trunk/Source/WebCore/html/HTMLMediaElement.h	2015-07-23 21:15:28 UTC (rev 187251)
@@ -448,6 +448,8 @@
 
     void layoutSizeChanged();
 
+    void allowsMediaDocumentInlinePlaybackChanged();
+
 protected:
     HTMLMediaElement(const QualifiedName&, Document&, bool);
     virtual ~HTMLMediaElement();

Modified: trunk/Source/WebCore/html/MediaElementSession.cpp (187250 => 187251)


--- trunk/Source/WebCore/html/MediaElementSession.cpp	2015-07-23 20:53:47 UTC (rev 187250)
+++ trunk/Source/WebCore/html/MediaElementSession.cpp	2015-07-23 21:15:28 UTC (rev 187251)
@@ -344,6 +344,10 @@
 
 bool MediaElementSession::requiresFullscreenForVideoPlayback(const HTMLMediaElement& element) const
 {
+    Page* page = element.document().page();
+    if (element.document().isMediaDocument() && !element.document().ownerElement() && page && page->allowsMediaDocumentInlinePlayback())
+        return false;
+
     if (!PlatformMediaSessionManager::sharedManager().sessionRestrictsInlineVideoPlayback(*this))
         return false;
 

Modified: trunk/Source/WebCore/page/Page.cpp (187250 => 187251)


--- trunk/Source/WebCore/page/Page.cpp	2015-07-23 20:53:47 UTC (rev 187250)
+++ trunk/Source/WebCore/page/Page.cpp	2015-07-23 21:15:28 UTC (rev 187251)
@@ -1736,4 +1736,20 @@
     return *m_testTrigger;
 }
 
+#if ENABLE(VIDEO)
+void Page::setAllowsMediaDocumentInlinePlayback(bool flag)
+{
+    if (m_allowsMediaDocumentInlinePlayback == flag)
+        return;
+    m_allowsMediaDocumentInlinePlayback = flag;
+
+    Vector<Ref<Document>> documents;
+    for (Frame* frame = m_mainFrame.get(); frame; frame = frame->tree().traverseNext())
+        documents.append(*frame->document());
+
+    for (auto& document : documents)
+        document->allowsMediaDocumentInlinePlaybackChanged();
+}
+#endif
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/page/Page.h (187250 => 187251)


--- trunk/Source/WebCore/page/Page.h	2015-07-23 20:53:47 UTC (rev 187250)
+++ trunk/Source/WebCore/page/Page.h	2015-07-23 21:15:28 UTC (rev 187251)
@@ -460,6 +460,11 @@
     void clearTrigger() { m_testTrigger = nullptr; }
     bool expectsWheelEventTriggers() const { return !!m_testTrigger; }
 
+#if ENABLE(VIDEO)
+    WEBCORE_EXPORT bool allowsMediaDocumentInlinePlayback() const { return m_allowsMediaDocumentInlinePlayback; }
+    WEBCORE_EXPORT void setAllowsMediaDocumentInlinePlayback(bool);
+#endif
+
 private:
     WEBCORE_EXPORT void initGroup();
 
@@ -619,6 +624,7 @@
     MediaProducer::MediaStateFlags m_mediaState { MediaProducer::IsNotPlaying };
     
     bool m_userContentExtensionsEnabled { true };
+    bool m_allowsMediaDocumentInlinePlayback { false };
 };
 
 inline PageGroup& Page::group()

Modified: trunk/Source/WebKit2/ChangeLog (187250 => 187251)


--- trunk/Source/WebKit2/ChangeLog	2015-07-23 20:53:47 UTC (rev 187250)
+++ trunk/Source/WebKit2/ChangeLog	2015-07-23 21:15:28 UTC (rev 187251)
@@ -1,3 +1,27 @@
+2015-07-21  Jer Noble  <[email protected]>
+
+        [iOS] Add an explicit API to allow media documents to (temporarily) play inline
+        https://bugs.webkit.org/show_bug.cgi?id=147181
+
+        Reviewed by Beth Dakin.
+
+        Add a WKWebView(Private) API which allows MediaDocuments loaded by the view to play their contents inline, regardless
+        of whether inline playback is restricted on the current device.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _setRequiresUserActionForMediaPlayback:]): Added. Pass through to WebPageProxy.
+        (-[WKWebView _allowsMediaDocumentInlinePlayback]): Ditto.
+        * UIProcess/API/Cocoa/WKWebViewPrivate.h:
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::allowsMediaDocumentInlinePlayback): Simple getter.
+        (WebKit::WebPageProxy::setAllowsMediaDocumentInlinePlayback): Set, and conditionally pass the new value to WebPage.
+        * UIProcess/WebPageProxy.h:
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::setAllowsMediaDocumentInlinePlayback): Set, and conditionally notify WebCore page of the change.
+        * WebProcess/WebPage/WebPage.h:
+        (WebKit::WebPage::allowsMediaDocumentInlinePlayback): Simple getter.
+        * WebProcess/WebPage/WebPage.messages.in: Add new messages.
+
 2015-07-23  Beth Dakin  <[email protected]>
 
         Should not allow previews of 1x1 images

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm (187250 => 187251)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm	2015-07-23 20:53:47 UTC (rev 187250)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm	2015-07-23 21:15:28 UTC (rev 187251)
@@ -2583,6 +2583,24 @@
     return nil;
 }
 
+#pragma mark media playback restrictions
+
+- (BOOL)_allowsMediaDocumentInlinePlayback
+{
+#if PLATFORM(IOS)
+    return _page->allowsMediaDocumentInlinePlayback();
+#else
+    return NO;
+#endif
+}
+
+- (void)_setAllowsMediaDocumentInlinePlayback:(BOOL)flag
+{
+#if PLATFORM(IOS)
+    _page->setAllowsMediaDocumentInlinePlayback(flag);
+#endif
+}
+
 #pragma mark iOS-specific methods
 
 #if PLATFORM(IOS)

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h (187250 => 187251)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h	2015-07-23 20:53:47 UTC (rev 187250)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h	2015-07-23 21:15:28 UTC (rev 187251)
@@ -208,6 +208,9 @@
 @property (nonatomic, readonly) NSArray *_scrollPerformanceData WK_AVAILABLE(WK_MAC_TBA, WK_IOS_TBA);
 
 - (void)_saveBackForwardSnapshotForItem:(WKBackForwardListItem *)item WK_AVAILABLE(WK_MAC_TBA, WK_IOS_TBA);
+
+@property (nonatomic, getter=_allowsMediaDocumentInlinePlayback, setter=_setAllowsMediaDocumentInlinePlayback:) BOOL _allowsMediaDocumentInlinePlayback;
+
 @end
 
 #endif

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp (187250 => 187251)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp	2015-07-23 20:53:47 UTC (rev 187250)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp	2015-07-23 21:15:28 UTC (rev 187251)
@@ -3983,6 +3983,20 @@
 {
     return m_videoFullscreenManager;
 }
+
+bool WebPageProxy::allowsMediaDocumentInlinePlayback() const
+{
+    return m_allowsMediaDocumentInlinePlayback;
+}
+
+void WebPageProxy::setAllowsMediaDocumentInlinePlayback(bool allows)
+{
+    if (m_allowsMediaDocumentInlinePlayback == allows)
+        return;
+    m_allowsMediaDocumentInlinePlayback = allows;
+
+    m_process->send(Messages::WebPage::SetAllowsMediaDocumentInlinePlayback(flag), m_pageID);
+}
 #endif
 
 // BackForwardList

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.h (187250 => 187251)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2015-07-23 20:53:47 UTC (rev 187250)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2015-07-23 21:15:28 UTC (rev 187251)
@@ -333,6 +333,9 @@
 #endif
 #if PLATFORM(IOS)
     RefPtr<WebVideoFullscreenManagerProxy> videoFullscreenManager();
+
+    bool allowsMediaDocumentInlinePlayback() const;
+    void setAllowsMediaDocumentInlinePlayback(bool);
 #endif
 
 #if ENABLE(CONTEXT_MENUS)
@@ -1574,6 +1577,7 @@
     WebCore::ViewState::Flags m_viewState;
     bool m_viewWasEverInWindow;
 #if PLATFORM(IOS)
+    bool m_allowsMediaDocumentInlinePlayback { false };
     bool m_alwaysRunsAtForegroundPriority;
     ProcessThrottler::ForegroundActivityToken m_activityToken;
 #endif

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp (187250 => 187251)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp	2015-07-23 20:53:47 UTC (rev 187250)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp	2015-07-23 21:15:28 UTC (rev 187251)
@@ -3009,6 +3009,11 @@
         m_videoFullscreenManager = WebVideoFullscreenManager::create(this);
     return m_videoFullscreenManager.get();
 }
+
+void WebPage::setAllowsMediaDocumentInlinePlayback(bool allows)
+{
+    m_page->setAllowsMediaDocumentInlinePlayback(allows);
+}
 #endif
 
 #if ENABLE(FULLSCREEN_API)

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h (187250 => 187251)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h	2015-07-23 20:53:47 UTC (rev 187250)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h	2015-07-23 21:15:28 UTC (rev 187251)
@@ -236,6 +236,8 @@
 
 #if PLATFORM(IOS)
     WebVideoFullscreenManager* videoFullscreenManager();
+    void setAllowsMediaDocumentInlinePlayback(bool);
+    bool allowsMediaDocumentInlinePlayback() const { return m_allowsMediaDocumentInlinePlayback; }
 #endif
 
 #if ENABLE(FULLSCREEN_API)
@@ -1258,6 +1260,7 @@
     RefPtr<WebInspectorUI> m_inspectorUI;
 #if PLATFORM(IOS)
     RefPtr<WebVideoFullscreenManager> m_videoFullscreenManager;
+    bool m_allowsMediaDocumentInlinePlayback { false };
 #endif
 #if ENABLE(FULLSCREEN_API)
     RefPtr<WebFullScreenManager> m_fullScreenManager;

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in (187250 => 187251)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in	2015-07-23 20:53:47 UTC (rev 187250)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in	2015-07-23 21:15:28 UTC (rev 187251)
@@ -95,6 +95,7 @@
     ContentSizeCategoryDidChange(String contentSizeCategory)
     ExecuteEditCommandWithCallback(String name, uint64_t callbackID)
     GetLookupContextAtPoint(WebCore::IntPoint point, uint64_t callbackID)
+    SetAllowsMediaDocumentInlinePlayback(bool allows)
 #endif
 
 #if ENABLE(REMOTE_INSPECTOR)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to