[iOS] Send the full list of file upload URLs and types in PasteboardItemInfo
[WebKit-https.git] / Source / WebCore / platform / ios / VideoFullscreenInterfaceAVKit.h
1 /*
2  * Copyright (C) 2014-2018 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
27 #pragma once
28
29 #if PLATFORM(IOS_FAMILY)
30
31 #include "EventListener.h"
32 #include "HTMLMediaElementEnums.h"
33 #include "PlatformLayer.h"
34 #include "PlaybackSessionInterfaceAVKit.h"
35 #include "VideoFullscreenModel.h"
36 #include <objc/objc.h>
37 #include <wtf/Forward.h>
38 #include <wtf/Function.h>
39 #include <wtf/RefCounted.h>
40 #include <wtf/RefPtr.h>
41 #include <wtf/RetainPtr.h>
42 #include <wtf/RunLoop.h>
43
44 OBJC_CLASS UIViewController;
45 OBJC_CLASS UIWindow;
46 OBJC_CLASS UIView;
47 OBJC_CLASS CALayer;
48 OBJC_CLASS WebAVPlayerController;
49 OBJC_CLASS WebAVPlayerLayerView;
50 OBJC_CLASS WebAVPlayerLayer;
51 OBJC_CLASS WebAVPlayerViewController;
52 OBJC_CLASS WebAVPlayerViewControllerDelegate;
53 OBJC_CLASS NSError;
54
55 namespace WebCore {
56 class IntRect;
57 class FloatSize;
58 class VideoFullscreenModel;
59 class VideoFullscreenChangeObserver;
60
61 class VideoFullscreenInterfaceAVKit final
62     : public VideoFullscreenModelClient
63     , public PlaybackSessionModelClient
64     , public ThreadSafeRefCounted<VideoFullscreenInterfaceAVKit> {
65
66 public:
67     WEBCORE_EXPORT static Ref<VideoFullscreenInterfaceAVKit> create(PlaybackSessionInterfaceAVKit&);
68     virtual ~VideoFullscreenInterfaceAVKit();
69     WEBCORE_EXPORT void setVideoFullscreenModel(VideoFullscreenModel*);
70     WEBCORE_EXPORT void setVideoFullscreenChangeObserver(VideoFullscreenChangeObserver*);
71     PlaybackSessionInterfaceAVKit& playbackSessionInterface() const { return m_playbackSessionInterface.get(); }
72     PlaybackSessionModel* playbackSessionModel() const { return m_playbackSessionInterface->playbackSessionModel(); }
73
74     // VideoFullscreenModelClient
75     WEBCORE_EXPORT void hasVideoChanged(bool) final;
76     WEBCORE_EXPORT void videoDimensionsChanged(const FloatSize&) final;
77
78     // PlaybackSessionModelClient
79     WEBCORE_EXPORT void externalPlaybackChanged(bool enabled, PlaybackSessionModel::ExternalPlaybackTargetType, const String& localizedDeviceName) final;
80
81     WEBCORE_EXPORT void setupFullscreen(UIView&, const IntRect& initialRect, UIView *, HTMLMediaElementEnums::VideoFullscreenMode, bool allowsPictureInPicturePlayback, bool standby);
82     WEBCORE_EXPORT void enterFullscreen();
83     WEBCORE_EXPORT void exitFullscreen(const IntRect& finalRect);
84     WEBCORE_EXPORT void cleanupFullscreen();
85     WEBCORE_EXPORT void invalidate();
86     WEBCORE_EXPORT void requestHideAndExitFullscreen();
87     WEBCORE_EXPORT void preparedToReturnToInline(bool visible, const IntRect& inlineRect);
88     WEBCORE_EXPORT void preparedToExitFullscreen();
89     WEBCORE_EXPORT void setHasVideoContentLayer(bool);
90     WEBCORE_EXPORT void setInlineRect(const IntRect&, bool visible);
91
92     enum class ExitFullScreenReason {
93         DoneButtonTapped,
94         FullScreenButtonTapped,
95         PinchGestureHandled,
96         RemoteControlStopEventReceived,
97         PictureInPictureStarted
98     };
99
100     class Mode {
101         HTMLMediaElementEnums::VideoFullscreenMode m_mode { HTMLMediaElementEnums::VideoFullscreenModeNone };
102
103     public:
104         Mode() = default;
105         Mode(const Mode&) = default;
106         Mode(HTMLMediaElementEnums::VideoFullscreenMode mode) : m_mode(mode) { }
107         void operator=(HTMLMediaElementEnums::VideoFullscreenMode mode) { m_mode = mode; }
108         HTMLMediaElementEnums::VideoFullscreenMode mode() const { return m_mode; }
109
110         void setModeValue(HTMLMediaElementEnums::VideoFullscreenMode mode, bool value) { value ? setMode(mode) : clearMode(mode); }
111         void setMode(HTMLMediaElementEnums::VideoFullscreenMode mode) { m_mode |= mode; }
112         void clearMode(HTMLMediaElementEnums::VideoFullscreenMode mode) { m_mode &= ~mode; }
113         bool hasMode(HTMLMediaElementEnums::VideoFullscreenMode mode) const { return m_mode & mode; }
114
115         bool isPictureInPicture() const { return m_mode == HTMLMediaElementEnums::VideoFullscreenModePictureInPicture; }
116         bool isFullscreen() const { return m_mode == HTMLMediaElementEnums::VideoFullscreenModeStandard; }
117
118         void setPictureInPicture(bool value) { setModeValue(HTMLMediaElementEnums::VideoFullscreenModePictureInPicture, value); }
119         void setFullscreen(bool value) { setModeValue(HTMLMediaElementEnums::VideoFullscreenModeStandard, value); }
120
121         bool hasFullscreen() const { return hasMode(HTMLMediaElementEnums::VideoFullscreenModeStandard); }
122         bool hasPictureInPicture() const { return hasMode(HTMLMediaElementEnums::VideoFullscreenModePictureInPicture); }
123
124         bool hasVideo() const { return m_mode & (HTMLMediaElementEnums::VideoFullscreenModeStandard | HTMLMediaElementEnums::VideoFullscreenModePictureInPicture); }
125     };
126
127     Mode m_currentMode;
128     Mode m_targetMode;
129
130     VideoFullscreenModel* videoFullscreenModel() const { return m_videoFullscreenModel; }
131     bool shouldExitFullscreenWithReason(ExitFullScreenReason);
132     HTMLMediaElementEnums::VideoFullscreenMode mode() const { return m_currentMode.mode(); }
133     bool allowsPictureInPicturePlayback() const { return m_allowsPictureInPicturePlayback; }
134     WEBCORE_EXPORT bool mayAutomaticallyShowVideoPictureInPicture() const;
135     void fullscreenMayReturnToInline(WTF::Function<void(bool)>&& callback);
136     bool wirelessVideoPlaybackDisabled() const;
137     WEBCORE_EXPORT void applicationDidBecomeActive();
138
139     void willStartPictureInPicture();
140     void didStartPictureInPicture();
141     void failedToStartPictureInPicture();
142     void willStopPictureInPicture();
143     void didStopPictureInPicture();
144     void prepareForPictureInPictureStopWithCompletionHandler(void (^)(BOOL));
145     void exitFullscreenHandler(BOOL success, NSError *);
146     void enterFullscreenHandler(BOOL success, NSError *);
147     bool isPlayingVideoInEnhancedFullscreen() const;
148
149     WEBCORE_EXPORT void setMode(HTMLMediaElementEnums::VideoFullscreenMode);
150     void clearMode(HTMLMediaElementEnums::VideoFullscreenMode);
151     bool hasMode(HTMLMediaElementEnums::VideoFullscreenMode mode) const { return m_currentMode.hasMode(mode); }
152
153 #if PLATFORM(IOS_FAMILY)
154     UIViewController *presentingViewController();
155     UIViewController *fullscreenViewController() const { return m_viewController.get(); }
156     WebAVPlayerLayerView* playerLayerView() const { return m_playerLayerView.get(); }
157     WEBCORE_EXPORT bool pictureInPictureWasStartedWhenEnteringBackground() const;
158 #endif
159
160 protected:
161     WEBCORE_EXPORT VideoFullscreenInterfaceAVKit(PlaybackSessionInterfaceAVKit&);
162
163     void doSetup();
164     void finalizeSetup();
165     void doExitFullscreen();
166     void returnToStandby();
167     void doEnterFullscreen();
168     void watchdogTimerFired();
169     WebAVPlayerController *playerController() const;
170
171     Ref<PlaybackSessionInterfaceAVKit> m_playbackSessionInterface;
172     RetainPtr<WebAVPlayerViewControllerDelegate> m_playerViewControllerDelegate;
173     RetainPtr<WebAVPlayerViewController> m_playerViewController;
174     VideoFullscreenModel* m_videoFullscreenModel { nullptr };
175     VideoFullscreenChangeObserver* m_fullscreenChangeObserver { nullptr };
176
177     // These are only used when fullscreen is presented in a separate window.
178     RetainPtr<UIWindow> m_window;
179     RetainPtr<UIViewController> m_viewController;
180     RetainPtr<UIView> m_videoView;
181     RetainPtr<UIView> m_parentView;
182     RetainPtr<UIWindow> m_parentWindow;
183     RetainPtr<WebAVPlayerLayerView> m_playerLayerView;
184     WTF::Function<void(bool)> m_prepareToInlineCallback;
185     RunLoop::Timer<VideoFullscreenInterfaceAVKit> m_watchdogTimer;
186     FloatRect m_inlineRect;
187     RouteSharingPolicy m_routeSharingPolicy { RouteSharingPolicy::Default };
188     String m_routingContextUID;
189     bool m_allowsPictureInPicturePlayback { false };
190     bool m_wirelessVideoPlaybackDisabled { true };
191     bool m_shouldReturnToFullscreenWhenStoppingPiP { false };
192     bool m_restoringFullscreenForPictureInPictureStop { false };
193
194     bool m_setupNeedsInlineRect { false };
195     bool m_exitFullscreenNeedInlineRect { false };
196
197     bool m_finalizeSetupNeedsVideoContentLayer { false };
198     bool m_cleanupNeedsReturnVideoContentLayer { false };
199
200     bool m_returnToStandbyNeedsReturnVideoContentLayer { false };
201     bool m_finalizeSetupNeedsReturnVideoContentLayer { false };
202
203     bool m_exitFullscreenNeedsExitFullscreen { false };
204     bool m_exitFullscreenNeedsExitPictureInPicture { false };
205     bool m_exitFullscreenNeedsReturnContentLayer { false };
206
207     bool m_enterFullscreenNeedsEnterFullscreen { false };
208     bool m_enterFullscreenNeedsExitFullscreen { false };
209     bool m_enterFullscreenNeedsEnterPictureInPicture { false };
210     bool m_enterFullscreenNeedsExitPictureInPicture { false };
211
212     bool m_hasVideoContentLayer { false };
213
214     bool m_hasUpdatedInlineRect { false };
215     bool m_inlineIsVisible { false };
216     bool m_standby { false };
217     bool m_targetStandby { false };
218
219     bool m_waitingForPreparedToExit { false };
220 };
221
222 }
223
224 #endif // PLATFORM(IOS_FAMILY)
225