2 * Copyright (C) 2014 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
30 #include "HTMLMediaSession.h"
32 #include "HTMLMediaElement.h"
34 #include "MediaSessionManager.h"
36 #include "ScriptController.h"
39 #include "RuntimeApplicationChecksIOS.h"
44 std::unique_ptr<HTMLMediaSession> HTMLMediaSession::create(MediaSessionClient& client)
46 return std::make_unique<HTMLMediaSession>(client);
49 HTMLMediaSession::HTMLMediaSession(MediaSessionClient& client)
50 : MediaSession(client)
51 , m_restrictions(NoRestrictions)
55 void HTMLMediaSession::addBehaviorRestriction(BehaviorRestrictions restriction)
57 m_restrictions |= restriction;
60 void HTMLMediaSession::removeBehaviorRestriction(BehaviorRestrictions restriction)
62 m_restrictions &= ~restriction;
65 bool HTMLMediaSession::playbackPermitted(const HTMLMediaElement&) const
67 if (m_restrictions & RequireUserGestureForRateChange && !ScriptController::processingUserGesture()) {
68 LOG(Media, "HTMLMediaSession::playbackPermitted - returning FALSE");
75 bool HTMLMediaSession::dataLoadingPermitted(const HTMLMediaElement&) const
77 if (m_restrictions & RequireUserGestureForLoad && !ScriptController::processingUserGesture()) {
78 LOG(Media, "HTMLMediaSession::dataLoadingPermitted - returning FALSE");
85 bool HTMLMediaSession::fullscreenPermitted(const HTMLMediaElement&) const
87 if (m_restrictions & RequireUserGestureForFullscreen && !ScriptController::processingUserGesture()) {
88 LOG(Media, "HTMLMediaSession::fullscreenPermitted - returning FALSE");
95 bool HTMLMediaSession::pageAllowsDataLoading(const HTMLMediaElement& element) const
97 Page* page = element.document().page();
98 if (m_restrictions & RequirePageConsentToLoadMedia && page && !page->canStartMedia()) {
99 LOG(Media, "HTMLMediaSession::pageAllowsDataLoading - returning FALSE");
106 bool HTMLMediaSession::pageAllowsPlaybackAfterResuming(const HTMLMediaElement& element) const
108 Page* page = element.document().page();
109 if (m_restrictions & RequirePageConsentToResumeMedia && page && !page->canStartMedia()) {
110 LOG(Media, "HTMLMediaSession::pageAllowsPlaybackAfterResuming - returning FALSE");
117 #if ENABLE(IOS_AIRPLAY)
118 bool HTMLMediaSession::showingPlaybackTargetPickerPermitted(const HTMLMediaElement&) const
120 if (m_restrictions & RequireUserGestureToShowPlaybackTargetPicker && !ScriptController::processingUserGesture()) {
121 LOG(Media, "HTMLMediaSession::showingPlaybackTargetPickerPermitted - returning FALSE");
129 void HTMLMediaSession::clientWillBeginPlayback() const
131 MediaSessionManager::sharedManager().sessionWillBeginPlayback(*this);
134 bool HTMLMediaSession::requiresFullscreenForVideoPlayback(const HTMLMediaElement& element) const
136 if (!MediaSessionManager::sharedManager().sessionRestrictsInlineVideoPlayback(*this))
139 Settings* settings = element.document().settings();
140 if (!settings || !settings->mediaPlaybackAllowsInline())
143 if (element.fastHasAttribute(HTMLNames::webkit_playsinlineAttr))
147 if (applicationIsDumpRenderTree())
156 #endif // ENABLE(VIDEO)