Enable -Wcast-qual for WebInspectorUI, WebKitLegacy, WebKit projects
[WebKit-https.git] / Source / WebKitLegacy / mac / WebView / WebMediaPlaybackTargetPicker.mm
1 /*
2  * Copyright (C) 2015 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
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.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #import "WebMediaPlaybackTargetPicker.h"
27
28 #if ENABLE(WIRELESS_PLAYBACK_TARGET) && !PLATFORM(IOS)
29
30 #import <WebCore/MediaPlaybackTarget.h>
31 #import <WebCore/Page.h>
32 #import <WebCore/WebMediaSessionManager.h>
33
34 std::unique_ptr<WebMediaPlaybackTargetPicker> WebMediaPlaybackTargetPicker::create(WebCore::Page& page)
35 {
36     return std::make_unique<WebMediaPlaybackTargetPicker>(page);
37 }
38
39 WebMediaPlaybackTargetPicker::WebMediaPlaybackTargetPicker(WebCore::Page& page)
40     : m_page(&page)
41 {
42 }
43
44 void WebMediaPlaybackTargetPicker::addPlaybackTargetPickerClient(uint64_t contextId)
45 {
46     WebCore::WebMediaSessionManager::shared().addPlaybackTargetPickerClient(*this, contextId);
47 }
48
49 void WebMediaPlaybackTargetPicker::removePlaybackTargetPickerClient(uint64_t contextId)
50 {
51     WebCore::WebMediaSessionManager::shared().removePlaybackTargetPickerClient(*this, contextId);
52 }
53
54 void WebMediaPlaybackTargetPicker::showPlaybackTargetPicker(uint64_t contextId, const WebCore::FloatRect& rect, bool hasVideo)
55 {
56     WebCore::WebMediaSessionManager::shared().showPlaybackTargetPicker(*this, contextId, WebCore::IntRect(rect), hasVideo);
57 }
58
59 void WebMediaPlaybackTargetPicker::playbackTargetPickerClientStateDidChange(uint64_t contextId, WebCore::MediaProducer::MediaStateFlags state)
60 {
61     WebCore::WebMediaSessionManager::shared().clientStateDidChange(*this, contextId, state);
62 }
63
64 void WebMediaPlaybackTargetPicker::setMockMediaPlaybackTargetPickerEnabled(bool enabled)
65 {
66     WebCore::WebMediaSessionManager::shared().setMockMediaPlaybackTargetPickerEnabled(enabled);
67 }
68
69 void WebMediaPlaybackTargetPicker::setMockMediaPlaybackTargetPickerState(const String& name, WebCore::MediaPlaybackTargetContext::State state)
70 {
71     WebCore::WebMediaSessionManager::shared().setMockMediaPlaybackTargetPickerState(name, state);
72 }
73
74 void WebMediaPlaybackTargetPicker::setPlaybackTarget(uint64_t contextId, Ref<WebCore::MediaPlaybackTarget>&& target)
75 {
76     if (!m_page)
77         return;
78
79     m_page->setPlaybackTarget(contextId, WTFMove(target));
80 }
81
82 void WebMediaPlaybackTargetPicker::externalOutputDeviceAvailableDidChange(uint64_t contextId, bool available)
83 {
84     if (!m_page)
85         return;
86
87     m_page->playbackTargetAvailabilityDidChange(contextId, available);
88 }
89
90 void WebMediaPlaybackTargetPicker::setShouldPlayToPlaybackTarget(uint64_t contextId, bool shouldPlay)
91 {
92     if (!m_page)
93         return;
94
95     m_page->setShouldPlayToPlaybackTarget(contextId, shouldPlay);
96 }
97
98 void WebMediaPlaybackTargetPicker::invalidate()
99 {
100     m_page = nullptr;
101     WebCore::WebMediaSessionManager::shared().removeAllPlaybackTargetPickerClients(*this);
102 }
103
104 #endif