Rollout r231818, as it introduced regression on tickets.com.
[WebKit-https.git] / Source / WebKit / UIProcess / WebFullScreenManagerProxy.cpp
1 /*
2  * Copyright (C) 2011 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. 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.
24  */
25
26 #include "config.h"
27 #include "WebFullScreenManagerProxy.h"
28
29 #if ENABLE(FULLSCREEN_API)
30
31 #include "APIFullscreenClient.h"
32 #include "WebAutomationSession.h"
33 #include "WebFullScreenManagerMessages.h"
34 #include "WebFullScreenManagerProxyMessages.h"
35 #include "WebPageProxy.h"
36 #include "WebProcessPool.h"
37 #include "WebProcessProxy.h"
38 #include <WebCore/IntRect.h>
39
40 using namespace WebCore;
41
42 namespace WebKit {
43
44 Ref<WebFullScreenManagerProxy> WebFullScreenManagerProxy::create(WebPageProxy& page, WebFullScreenManagerProxyClient& client)
45 {
46     return adoptRef(*new WebFullScreenManagerProxy(page, client));
47 }
48
49 WebFullScreenManagerProxy::WebFullScreenManagerProxy(WebPageProxy& page, WebFullScreenManagerProxyClient& client)
50     : m_page(&page)
51     , m_client(&client)
52 {
53     m_page->process().addMessageReceiver(Messages::WebFullScreenManagerProxy::messageReceiverName(), m_page->pageID(), *this);
54 }
55
56 WebFullScreenManagerProxy::~WebFullScreenManagerProxy()
57 {
58 }
59
60 void WebFullScreenManagerProxy::willEnterFullScreen()
61 {
62     m_page->fullscreenClient().willEnterFullscreen(m_page);
63     m_page->process().send(Messages::WebFullScreenManager::WillEnterFullScreen(), m_page->pageID());
64 }
65
66 void WebFullScreenManagerProxy::didEnterFullScreen()
67 {
68     m_page->fullscreenClient().didEnterFullscreen(m_page);
69     m_page->process().send(Messages::WebFullScreenManager::DidEnterFullScreen(), m_page->pageID());
70
71     if (m_page->isControlledByAutomation()) {
72         if (WebAutomationSession* automationSession = m_page->process().processPool().automationSession())
73             automationSession->didEnterFullScreenForPage(*m_page);
74     }
75 }
76
77 void WebFullScreenManagerProxy::willExitFullScreen()
78 {
79     m_page->fullscreenClient().willExitFullscreen(m_page);
80     m_page->process().send(Messages::WebFullScreenManager::WillExitFullScreen(), m_page->pageID());
81 }
82
83 void WebFullScreenManagerProxy::didExitFullScreen()
84 {
85     m_page->fullscreenClient().didExitFullscreen(m_page);
86     m_page->process().send(Messages::WebFullScreenManager::DidExitFullScreen(), m_page->pageID());
87     
88     if (m_page->isControlledByAutomation()) {
89         if (WebAutomationSession* automationSession = m_page->process().processPool().automationSession())
90             automationSession->didExitFullScreenForPage(*m_page);
91     }
92 }
93
94 void WebFullScreenManagerProxy::setAnimatingFullScreen(bool animating)
95 {
96     m_page->process().send(Messages::WebFullScreenManager::SetAnimatingFullScreen(animating), m_page->pageID());
97 }
98
99 void WebFullScreenManagerProxy::requestExitFullScreen()
100 {
101     m_page->process().send(Messages::WebFullScreenManager::RequestExitFullScreen(), m_page->pageID());
102 }
103
104 void WebFullScreenManagerProxy::supportsFullScreen(bool withKeyboard, bool& supports)
105 {
106 #if PLATFORM(IOS)
107     supports = !withKeyboard;
108 #else
109     supports = true;
110 #endif
111 }
112
113 void WebFullScreenManagerProxy::saveScrollPosition()
114 {
115     m_page->process().send(Messages::WebFullScreenManager::SaveScrollPosition(), m_page->pageID());
116 }
117
118 void WebFullScreenManagerProxy::restoreScrollPosition()
119 {
120     m_page->process().send(Messages::WebFullScreenManager::RestoreScrollPosition(), m_page->pageID());
121 }
122
123 void WebFullScreenManagerProxy::setFullscreenInsetTop(double inset)
124 {
125     m_page->process().send(Messages::WebFullScreenManager::SetFullscreenInsetTop(inset), m_page->pageID());
126 }
127
128 void WebFullScreenManagerProxy::setFullscreenAutoHideDelay(double delay)
129 {
130     m_page->process().send(Messages::WebFullScreenManager::SetFullscreenAutoHideDelay(delay), m_page->pageID());
131 }
132
133 void WebFullScreenManagerProxy::invalidate()
134 {
135     m_page->process().removeMessageReceiver(Messages::WebFullScreenManagerProxy::messageReceiverName(), m_page->pageID());
136
137     if (!m_client)
138         return;
139
140     m_client->closeFullScreenManager();
141     m_client = nullptr;
142 }
143
144 void WebFullScreenManagerProxy::close()
145 {
146     if (!m_client)
147         return;
148     m_client->closeFullScreenManager();
149 }
150
151 bool WebFullScreenManagerProxy::isFullScreen()
152 {
153     if (!m_client)
154         return false;
155     return m_client->isFullScreen();
156 }
157
158 void WebFullScreenManagerProxy::enterFullScreen()
159 {
160     if (!m_client)
161         return;
162     m_client->enterFullScreen();
163 }
164
165 void WebFullScreenManagerProxy::exitFullScreen()
166 {
167     if (!m_client)
168         return;
169     m_client->exitFullScreen();
170 }
171     
172 void WebFullScreenManagerProxy::beganEnterFullScreen(const IntRect& initialFrame, const IntRect& finalFrame)
173 {
174     if (!m_client)
175         return;
176     m_client->beganEnterFullScreen(initialFrame, finalFrame);
177 }
178
179 void WebFullScreenManagerProxy::beganExitFullScreen(const IntRect& initialFrame, const IntRect& finalFrame)
180 {
181     if (!m_client)
182         return;
183     m_client->beganExitFullScreen(initialFrame, finalFrame);
184 }
185
186 } // namespace WebKit
187
188 #endif // ENABLE(FULLSCREEN_API)