WebUIClient.cpp revision 65f03d4f644ce73618e5f4f50dd694b26f55ae12
1/*
2 * Copyright (C) 2010 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 "WebUIClient.h"
27
28#include "ImmutableDictionary.h"
29#include "NativeWebKeyboardEvent.h"
30#include "WKAPICast.h"
31#include "WebNumber.h"
32#include "WebOpenPanelResultListenerProxy.h"
33#include "WebPageProxy.h"
34#include <WebCore/FloatRect.h>
35#include <WebCore/IntSize.h>
36#include <WebCore/WindowFeatures.h>
37#include <string.h>
38#include <wtf/text/WTFString.h>
39
40using namespace WebCore;
41
42namespace WebKit {
43
44PassRefPtr<WebPageProxy> WebUIClient::createNewPage(WebPageProxy* page, const WindowFeatures& windowFeatures, WebEvent::Modifiers modifiers, WebMouseEvent::Button button)
45{
46    if (!m_client.createNewPage)
47        return 0;
48
49    ImmutableDictionary::MapType map;
50    if (windowFeatures.xSet)
51        map.set("x", WebDouble::create(windowFeatures.x));
52    if (windowFeatures.ySet)
53        map.set("y", WebDouble::create(windowFeatures.y));
54    if (windowFeatures.widthSet)
55        map.set("width", WebDouble::create(windowFeatures.width));
56    if (windowFeatures.heightSet)
57        map.set("height", WebDouble::create(windowFeatures.height));
58    map.set("menuBarVisible", WebBoolean::create(windowFeatures.menuBarVisible));
59    map.set("statusBarVisible", WebBoolean::create(windowFeatures.statusBarVisible));
60    map.set("toolBarVisible", WebBoolean::create(windowFeatures.toolBarVisible));
61    map.set("scrollbarsVisible", WebBoolean::create(windowFeatures.scrollbarsVisible));
62    map.set("resizable", WebBoolean::create(windowFeatures.resizable));
63    map.set("fullscreen", WebBoolean::create(windowFeatures.fullscreen));
64    map.set("dialog", WebBoolean::create(windowFeatures.dialog));
65    RefPtr<ImmutableDictionary> featuresMap = ImmutableDictionary::adopt(map);
66
67    return adoptRef(toImpl(m_client.createNewPage(toAPI(page), toAPI(featuresMap.get()), toAPI(modifiers), toAPI(button), m_client.clientInfo)));
68}
69
70void WebUIClient::showPage(WebPageProxy* page)
71{
72    if (!m_client.showPage)
73        return;
74
75    m_client.showPage(toAPI(page), m_client.clientInfo);
76}
77
78void WebUIClient::close(WebPageProxy* page)
79{
80    if (!m_client.close)
81        return;
82
83    m_client.close(toAPI(page), m_client.clientInfo);
84}
85
86void WebUIClient::runJavaScriptAlert(WebPageProxy* page, const String& message, WebFrameProxy* frame)
87{
88    if (!m_client.runJavaScriptAlert)
89        return;
90
91    m_client.runJavaScriptAlert(toAPI(page), toAPI(message.impl()), toAPI(frame), m_client.clientInfo);
92}
93
94bool WebUIClient::runJavaScriptConfirm(WebPageProxy* page, const String& message, WebFrameProxy* frame)
95{
96    if (!m_client.runJavaScriptConfirm)
97        return false;
98
99    return m_client.runJavaScriptConfirm(toAPI(page), toAPI(message.impl()), toAPI(frame), m_client.clientInfo);
100}
101
102String WebUIClient::runJavaScriptPrompt(WebPageProxy* page, const String& message, const String& defaultValue, WebFrameProxy* frame)
103{
104    if (!m_client.runJavaScriptPrompt)
105        return String();
106
107    WebString* string = toImpl(m_client.runJavaScriptPrompt(toAPI(page), toAPI(message.impl()), toAPI(defaultValue.impl()), toAPI(frame), m_client.clientInfo));
108    if (!string)
109        return String();
110
111    String result = string->string();
112    string->deref();
113
114    return result;
115}
116
117void WebUIClient::setStatusText(WebPageProxy* page, const String& text)
118{
119    if (!m_client.setStatusText)
120        return;
121
122    m_client.setStatusText(toAPI(page), toAPI(text.impl()), m_client.clientInfo);
123}
124
125void WebUIClient::mouseDidMoveOverElement(WebPageProxy* page, WebEvent::Modifiers modifiers, APIObject* userData)
126{
127    if (!m_client.mouseDidMoveOverElement)
128        return;
129
130    m_client.mouseDidMoveOverElement(toAPI(page), toAPI(modifiers), toAPI(userData), m_client.clientInfo);
131}
132
133void WebUIClient::missingPluginButtonClicked(WebPageProxy* page, const String& mimeType, const String& url)
134{
135    if (!m_client.missingPluginButtonClicked)
136        return;
137
138    m_client.missingPluginButtonClicked(toAPI(page), toAPI(mimeType.impl()), toAPI(url.impl()), m_client.clientInfo);
139}
140
141void WebUIClient::didNotHandleKeyEvent(WebPageProxy* page, const NativeWebKeyboardEvent& event)
142{
143    if (!m_client.didNotHandleKeyEvent)
144        return;
145    m_client.didNotHandleKeyEvent(toAPI(page), event.nativeEvent(), m_client.clientInfo);
146}
147
148bool WebUIClient::toolbarsAreVisible(WebPageProxy* page)
149{
150    if (!m_client.toolbarsAreVisible)
151        return true;
152    return m_client.toolbarsAreVisible(toAPI(page), m_client.clientInfo);
153
154}
155void WebUIClient::setToolbarsAreVisible(WebPageProxy* page, bool visible)
156{
157    if (!m_client.setToolbarsAreVisible)
158        return;
159    m_client.setToolbarsAreVisible(toAPI(page), visible, m_client.clientInfo);
160}
161
162bool WebUIClient::menuBarIsVisible(WebPageProxy* page)
163{
164    if (!m_client.menuBarIsVisible)
165        return true;
166    return m_client.menuBarIsVisible(toAPI(page), m_client.clientInfo);
167}
168
169void WebUIClient::setMenuBarIsVisible(WebPageProxy* page, bool visible)
170{
171    if (!m_client.setMenuBarIsVisible)
172        return;
173    m_client.setMenuBarIsVisible(toAPI(page), visible, m_client.clientInfo);
174}
175
176bool WebUIClient::statusBarIsVisible(WebPageProxy* page)
177{
178    if (!m_client.statusBarIsVisible)
179        return true;
180    return m_client.statusBarIsVisible(toAPI(page), m_client.clientInfo);
181}
182
183void WebUIClient::setStatusBarIsVisible(WebPageProxy* page, bool visible)
184{
185    if (!m_client.setStatusBarIsVisible)
186        return;
187    m_client.setStatusBarIsVisible(toAPI(page), visible, m_client.clientInfo);
188}
189
190bool WebUIClient::isResizable(WebPageProxy* page)
191{
192    if (!m_client.isResizable)
193        return true;
194    return m_client.isResizable(toAPI(page), m_client.clientInfo);
195}
196
197void WebUIClient::setIsResizable(WebPageProxy* page, bool resizable)
198{
199    if (!m_client.setIsResizable)
200        return;
201    m_client.setIsResizable(toAPI(page), resizable, m_client.clientInfo);
202}
203
204void WebUIClient::setWindowFrame(WebPageProxy* page, const FloatRect& frame)
205{
206    if (!m_client.setWindowFrame)
207        return;
208
209    m_client.setWindowFrame(toAPI(page), toAPI(frame), m_client.clientInfo);
210}
211
212FloatRect WebUIClient::windowFrame(WebPageProxy* page)
213{
214    if (!m_client.getWindowFrame)
215        return FloatRect();
216
217    return toFloatRect(m_client.getWindowFrame(toAPI(page), m_client.clientInfo));
218}
219
220bool WebUIClient::canRunBeforeUnloadConfirmPanel()
221{
222    return m_client.runBeforeUnloadConfirmPanel;
223}
224
225bool WebUIClient::runBeforeUnloadConfirmPanel(WebPageProxy* page, const String& message, WebFrameProxy* frame)
226{
227    if (!m_client.runBeforeUnloadConfirmPanel)
228        return true;
229
230    return m_client.runBeforeUnloadConfirmPanel(toAPI(page), toAPI(message.impl()), toAPI(frame), m_client.clientInfo);
231}
232
233void WebUIClient::didDraw(WebPageProxy* page)
234{
235    if (!m_client.didDraw)
236        return;
237
238    m_client.didDraw(toAPI(page), m_client.clientInfo);
239}
240
241void WebUIClient::pageDidScroll(WebPageProxy* page)
242{
243    if (!m_client.pageDidScroll)
244        return;
245
246    m_client.pageDidScroll(toAPI(page), m_client.clientInfo);
247}
248
249unsigned long long WebUIClient::exceededDatabaseQuota(WebPageProxy* page, WebFrameProxy* frame, WebSecurityOrigin* origin, const String& databaseName, const String& databaseDisplayName, unsigned long long currentQuota, unsigned long long currentUsage, unsigned long long expectedUsage)
250{
251    if (!m_client.exceededDatabaseQuota)
252        return currentQuota;
253
254    return m_client.exceededDatabaseQuota(toAPI(page), toAPI(frame), toAPI(origin), toAPI(databaseName.impl()), toAPI(databaseDisplayName.impl()), currentQuota, currentUsage, expectedUsage, m_client.clientInfo);
255}
256
257bool WebUIClient::runOpenPanel(WebPageProxy* page, WebFrameProxy* frame, const WebOpenPanelParameters::Data& parameterData, WebOpenPanelResultListenerProxy* listener)
258{
259    if (!m_client.runOpenPanel)
260        return false;
261
262    RefPtr<WebOpenPanelParameters> parameters = WebOpenPanelParameters::create(parameterData);
263    m_client.runOpenPanel(toAPI(page), toAPI(frame), toAPI(parameters.get()), toAPI(listener), m_client.clientInfo);
264    return true;
265}
266
267bool WebUIClient::decidePolicyForGeolocationPermissionRequest(WebPageProxy* page, WebFrameProxy* frame, WebSecurityOrigin* origin, GeolocationPermissionRequestProxy* permissionRequest)
268{
269    if (!m_client.decidePolicyForGeolocationPermissionRequest)
270        return false;
271
272    m_client.decidePolicyForGeolocationPermissionRequest(toAPI(page), toAPI(frame), toAPI(origin), toAPI(permissionRequest), m_client.clientInfo);
273    return true;
274}
275
276} // namespace WebKit
277