2 * Copyright (C) 2010, 2011 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.
27 #include "WebUIClient.h"
29 #include "ImmutableDictionary.h"
30 #include "NativeWebKeyboardEvent.h"
31 #include "NativeWebWheelEvent.h"
32 #include "NotificationPermissionRequest.h"
33 #include "WKAPICast.h"
34 #if ENABLE(TIZEN_INPUT_COLOR_PICKER) // wait for upstream
35 #include "WebColorPickerResultListenerProxy.h"
37 #include "WebNumber.h"
38 #include "WebOpenPanelResultListenerProxy.h"
39 #include "WebPageProxy.h"
40 #include <WebCore/FloatRect.h>
41 #include <WebCore/IntSize.h>
42 #include <WebCore/WindowFeatures.h>
44 #include <wtf/text/WTFString.h>
46 using namespace WebCore;
50 PassRefPtr<WebPageProxy> WebUIClient::createNewPage(WebPageProxy* page, const ResourceRequest& resourceRequest, const WindowFeatures& windowFeatures, WebEvent::Modifiers modifiers, WebMouseEvent::Button button)
52 if (!m_client.version && !m_client.createNewPage_deprecatedForUseWithV0)
55 if (m_client.version == kWKPageUIClientCurrentVersion && !m_client.createNewPage)
58 ImmutableDictionary::MapType map;
59 if (windowFeatures.xSet)
60 map.set("x", WebDouble::create(windowFeatures.x));
61 if (windowFeatures.ySet)
62 map.set("y", WebDouble::create(windowFeatures.y));
63 if (windowFeatures.widthSet)
64 map.set("width", WebDouble::create(windowFeatures.width));
65 if (windowFeatures.heightSet)
66 map.set("height", WebDouble::create(windowFeatures.height));
67 map.set("menuBarVisible", WebBoolean::create(windowFeatures.menuBarVisible));
68 map.set("statusBarVisible", WebBoolean::create(windowFeatures.statusBarVisible));
69 map.set("toolBarVisible", WebBoolean::create(windowFeatures.toolBarVisible));
70 map.set("locationBarVisible", WebBoolean::create(windowFeatures.locationBarVisible));
71 map.set("scrollbarsVisible", WebBoolean::create(windowFeatures.scrollbarsVisible));
72 map.set("resizable", WebBoolean::create(windowFeatures.resizable));
73 map.set("fullscreen", WebBoolean::create(windowFeatures.fullscreen));
74 map.set("dialog", WebBoolean::create(windowFeatures.dialog));
75 RefPtr<ImmutableDictionary> featuresMap = ImmutableDictionary::adopt(map);
77 if (!m_client.version)
78 return adoptRef(toImpl(m_client.createNewPage_deprecatedForUseWithV0(toAPI(page), toAPI(featuresMap.get()), toAPI(modifiers), toAPI(button), m_client.clientInfo)));
80 RefPtr<WebURLRequest> request = WebURLRequest::create(resourceRequest);
81 return adoptRef(toImpl(m_client.createNewPage(toAPI(page), toAPI(request.get()), toAPI(featuresMap.get()), toAPI(modifiers), toAPI(button), m_client.clientInfo)));
84 void WebUIClient::showPage(WebPageProxy* page)
86 if (!m_client.showPage)
89 m_client.showPage(toAPI(page), m_client.clientInfo);
92 void WebUIClient::close(WebPageProxy* page)
97 m_client.close(toAPI(page), m_client.clientInfo);
100 void WebUIClient::takeFocus(WebPageProxy* page, WKFocusDirection direction)
102 if (!m_client.takeFocus)
105 m_client.takeFocus(toAPI(page), direction, m_client.clientInfo);
108 void WebUIClient::focus(WebPageProxy* page)
113 m_client.focus(toAPI(page), m_client.clientInfo);
116 void WebUIClient::unfocus(WebPageProxy* page)
118 if (!m_client.unfocus)
121 m_client.unfocus(toAPI(page), m_client.clientInfo);
125 bool WebUIClient::runJavaScriptAlert(WebPageProxy* page, const String& message, WebFrameProxy* frame)
127 #if ENABLE(TIZEN_WEBKIT2_EFL_WTR)
131 if (!m_client.runJavaScriptAlert)
134 return m_client.runJavaScriptAlert(toAPI(page), toAPI(message.impl()), toAPI(frame), m_client.clientInfo);
137 bool WebUIClient::runJavaScriptConfirm(WebPageProxy* page, const String& message, WebFrameProxy* frame)
139 #if ENABLE(TIZEN_WEBKIT2_EFL_WTR)
143 if (!m_client.runJavaScriptConfirm)
146 return m_client.runJavaScriptConfirm(toAPI(page), toAPI(message.impl()), toAPI(frame), m_client.clientInfo);
149 bool WebUIClient::runJavaScriptPrompt(WebPageProxy* page, const String& message, const String& defaultValue, WebFrameProxy* frame)
151 #if ENABLE(TIZEN_WEBKIT2_EFL_WTR)
155 if (!m_client.runJavaScriptPrompt)
158 return m_client.runJavaScriptPrompt(toAPI(page), toAPI(message.impl()), toAPI(defaultValue.impl()), toAPI(frame), m_client.clientInfo);
161 void WebUIClient::runJavaScriptAlert(WebPageProxy* page, const String& message, WebFrameProxy* frame)
163 #if ENABLE(TIZEN_WEBKIT2_EFL_WTR)
167 if (!m_client.runJavaScriptAlert)
170 m_client.runJavaScriptAlert(toAPI(page), toAPI(message.impl()), toAPI(frame), m_client.clientInfo);
173 bool WebUIClient::runJavaScriptConfirm(WebPageProxy* page, const String& message, WebFrameProxy* frame)
175 #if ENABLE(TIZEN_WEBKIT2_EFL_WTR)
179 if (!m_client.runJavaScriptConfirm)
182 return m_client.runJavaScriptConfirm(toAPI(page), toAPI(message.impl()), toAPI(frame), m_client.clientInfo);
185 String WebUIClient::runJavaScriptPrompt(WebPageProxy* page, const String& message, const String& defaultValue, WebFrameProxy* frame)
187 #if ENABLE(TIZEN_WEBKIT2_EFL_WTR)
191 if (!m_client.runJavaScriptPrompt)
194 WebString* string = toImpl(m_client.runJavaScriptPrompt(toAPI(page), toAPI(message.impl()), toAPI(defaultValue.impl()), toAPI(frame), m_client.clientInfo));
198 String result = string->string();
205 void WebUIClient::setStatusText(WebPageProxy* page, const String& text)
207 if (!m_client.setStatusText)
210 m_client.setStatusText(toAPI(page), toAPI(text.impl()), m_client.clientInfo);
213 void WebUIClient::mouseDidMoveOverElement(WebPageProxy* page, const WebHitTestResult::Data& data, WebEvent::Modifiers modifiers, APIObject* userData)
215 if (!m_client.mouseDidMoveOverElement && !m_client.mouseDidMoveOverElement_deprecatedForUseWithV0)
218 if (m_client.version == kWKPageUIClientCurrentVersion && !m_client.mouseDidMoveOverElement)
221 if (!m_client.version) {
222 m_client.mouseDidMoveOverElement_deprecatedForUseWithV0(toAPI(page), toAPI(modifiers), toAPI(userData), m_client.clientInfo);
226 RefPtr<WebHitTestResult> webHitTestResult = WebHitTestResult::create(data);
227 m_client.mouseDidMoveOverElement(toAPI(page), toAPI(webHitTestResult.get()), toAPI(modifiers), toAPI(userData), m_client.clientInfo);
230 void WebUIClient::unavailablePluginButtonClicked(WebPageProxy* page, WKPluginUnavailabilityReason pluginUnavailabilityReason, const String& mimeType, const String& url, const String& pluginsPageURL)
232 if (pluginUnavailabilityReason == kWKPluginUnavailabilityReasonPluginMissing) {
233 if (m_client.missingPluginButtonClicked_deprecatedForUseWithV0)
234 m_client.missingPluginButtonClicked_deprecatedForUseWithV0(toAPI(page), toAPI(mimeType.impl()), toAPI(url.impl()), toAPI(pluginsPageURL.impl()), m_client.clientInfo);
237 if (!m_client.unavailablePluginButtonClicked)
240 m_client.unavailablePluginButtonClicked(toAPI(page), pluginUnavailabilityReason, toAPI(mimeType.impl()), toAPI(url.impl()), toAPI(pluginsPageURL.impl()), m_client.clientInfo);
244 bool WebUIClient::implementsDidNotHandleKeyEvent() const
246 return m_client.didNotHandleKeyEvent;
249 void WebUIClient::didNotHandleKeyEvent(WebPageProxy* page, const NativeWebKeyboardEvent& event)
251 if (!m_client.didNotHandleKeyEvent)
253 m_client.didNotHandleKeyEvent(toAPI(page), event.nativeEvent(), m_client.clientInfo);
256 bool WebUIClient::implementsDidNotHandleWheelEvent() const
258 return m_client.didNotHandleWheelEvent;
261 void WebUIClient::didNotHandleWheelEvent(WebPageProxy* page, const NativeWebWheelEvent& event)
263 if (!m_client.didNotHandleWheelEvent)
265 m_client.didNotHandleWheelEvent(toAPI(page), event.nativeEvent(), m_client.clientInfo);
268 bool WebUIClient::toolbarsAreVisible(WebPageProxy* page)
270 if (!m_client.toolbarsAreVisible)
272 return m_client.toolbarsAreVisible(toAPI(page), m_client.clientInfo);
275 void WebUIClient::setToolbarsAreVisible(WebPageProxy* page, bool visible)
277 if (!m_client.setToolbarsAreVisible)
279 m_client.setToolbarsAreVisible(toAPI(page), visible, m_client.clientInfo);
282 bool WebUIClient::menuBarIsVisible(WebPageProxy* page)
284 if (!m_client.menuBarIsVisible)
286 return m_client.menuBarIsVisible(toAPI(page), m_client.clientInfo);
289 void WebUIClient::setMenuBarIsVisible(WebPageProxy* page, bool visible)
291 if (!m_client.setMenuBarIsVisible)
293 m_client.setMenuBarIsVisible(toAPI(page), visible, m_client.clientInfo);
296 bool WebUIClient::statusBarIsVisible(WebPageProxy* page)
298 if (!m_client.statusBarIsVisible)
300 return m_client.statusBarIsVisible(toAPI(page), m_client.clientInfo);
303 void WebUIClient::setStatusBarIsVisible(WebPageProxy* page, bool visible)
305 if (!m_client.setStatusBarIsVisible)
307 m_client.setStatusBarIsVisible(toAPI(page), visible, m_client.clientInfo);
310 bool WebUIClient::isResizable(WebPageProxy* page)
312 if (!m_client.isResizable)
314 return m_client.isResizable(toAPI(page), m_client.clientInfo);
317 void WebUIClient::setIsResizable(WebPageProxy* page, bool resizable)
319 if (!m_client.setIsResizable)
321 m_client.setIsResizable(toAPI(page), resizable, m_client.clientInfo);
324 void WebUIClient::setWindowFrame(WebPageProxy* page, const FloatRect& frame)
326 if (!m_client.setWindowFrame)
329 m_client.setWindowFrame(toAPI(page), toAPI(frame), m_client.clientInfo);
332 FloatRect WebUIClient::windowFrame(WebPageProxy* page)
334 if (!m_client.getWindowFrame)
337 return toFloatRect(m_client.getWindowFrame(toAPI(page), m_client.clientInfo));
340 bool WebUIClient::canRunBeforeUnloadConfirmPanel() const
342 return m_client.runBeforeUnloadConfirmPanel;
345 bool WebUIClient::runBeforeUnloadConfirmPanel(WebPageProxy* page, const String& message, WebFrameProxy* frame)
347 if (!m_client.runBeforeUnloadConfirmPanel)
350 return m_client.runBeforeUnloadConfirmPanel(toAPI(page), toAPI(message.impl()), toAPI(frame), m_client.clientInfo);
353 void WebUIClient::didDraw(WebPageProxy* page)
355 if (!m_client.didDraw)
358 m_client.didDraw(toAPI(page), m_client.clientInfo);
361 void WebUIClient::pageDidScroll(WebPageProxy* page)
363 if (!m_client.pageDidScroll)
366 m_client.pageDidScroll(toAPI(page), m_client.clientInfo);
369 unsigned long long WebUIClient::exceededDatabaseQuota(WebPageProxy* page, WebFrameProxy* frame, WebSecurityOrigin* origin, const String& databaseName, const String& databaseDisplayName, unsigned long long currentQuota, unsigned long long currentOriginUsage, unsigned long long currentDatabaseUsage, unsigned long long expectedUsage)
371 if (!m_client.exceededDatabaseQuota)
374 return m_client.exceededDatabaseQuota(toAPI(page), toAPI(frame), toAPI(origin), toAPI(databaseName.impl()), toAPI(databaseDisplayName.impl()), currentQuota, currentOriginUsage, currentDatabaseUsage, expectedUsage, m_client.clientInfo);
377 bool WebUIClient::runOpenPanel(WebPageProxy* page, WebFrameProxy* frame, WebOpenPanelParameters* parameters, WebOpenPanelResultListenerProxy* listener)
379 if (!m_client.runOpenPanel)
382 m_client.runOpenPanel(toAPI(page), toAPI(frame), toAPI(parameters), toAPI(listener), m_client.clientInfo);
386 bool WebUIClient::decidePolicyForGeolocationPermissionRequest(WebPageProxy* page, WebFrameProxy* frame, WebSecurityOrigin* origin, GeolocationPermissionRequestProxy* permissionRequest)
388 if (!m_client.decidePolicyForGeolocationPermissionRequest)
391 m_client.decidePolicyForGeolocationPermissionRequest(toAPI(page), toAPI(frame), toAPI(origin), toAPI(permissionRequest), m_client.clientInfo);
395 bool WebUIClient::decidePolicyForNotificationPermissionRequest(WebPageProxy* page, WebSecurityOrigin* origin, NotificationPermissionRequest* permissionRequest)
397 if (!m_client.decidePolicyForNotificationPermissionRequest)
400 m_client.decidePolicyForNotificationPermissionRequest(toAPI(page), toAPI(origin), toAPI(permissionRequest), m_client.clientInfo);
404 float WebUIClient::headerHeight(WebPageProxy* page, WebFrameProxy* frame)
406 if (!m_client.headerHeight)
409 return m_client.headerHeight(toAPI(page), toAPI(frame), m_client.clientInfo);
412 float WebUIClient::footerHeight(WebPageProxy* page, WebFrameProxy* frame)
414 if (!m_client.footerHeight)
417 return m_client.footerHeight(toAPI(page), toAPI(frame), m_client.clientInfo);
420 void WebUIClient::drawHeader(WebPageProxy* page, WebFrameProxy* frame, const WebCore::FloatRect& rect)
422 if (!m_client.drawHeader)
425 m_client.drawHeader(toAPI(page), toAPI(frame), toAPI(rect), m_client.clientInfo);
428 void WebUIClient::drawFooter(WebPageProxy* page, WebFrameProxy* frame, const WebCore::FloatRect& rect)
430 if (!m_client.drawFooter)
433 m_client.drawFooter(toAPI(page), toAPI(frame), toAPI(rect), m_client.clientInfo);
436 void WebUIClient::printFrame(WebPageProxy* page, WebFrameProxy* frame)
438 if (!m_client.printFrame)
441 m_client.printFrame(toAPI(page), toAPI(frame), m_client.clientInfo);
444 bool WebUIClient::canRunModal() const
446 return m_client.runModal;
449 void WebUIClient::runModal(WebPageProxy* page)
451 if (!m_client.runModal)
454 m_client.runModal(toAPI(page), m_client.clientInfo);
457 void WebUIClient::saveDataToFileInDownloadsFolder(WebPageProxy* page, const String& suggestedFilename, const String& mimeType, const String& originatingURLString, WebData* data)
459 if (!m_client.saveDataToFileInDownloadsFolder)
462 m_client.saveDataToFileInDownloadsFolder(toAPI(page), toAPI(suggestedFilename.impl()), toAPI(mimeType.impl()), toURLRef(originatingURLString.impl()), toAPI(data), m_client.clientInfo);
465 bool WebUIClient::shouldInterruptJavaScript(WebPageProxy* page)
467 if (!m_client.shouldInterruptJavaScript)
470 return m_client.shouldInterruptJavaScript(toAPI(page), m_client.clientInfo);
473 #if ENABLE(TIZEN_INPUT_COLOR_PICKER) // wait for upstream
474 #if ENABLE(INPUT_TYPE_COLOR)
475 bool WebUIClient::showColorPicker(WebPageProxy* page, const String& initialColor, WebColorPickerResultListenerProxy* listener)
477 if (!m_client.showColorPicker)
480 m_client.showColorPicker(toAPI(page), toAPI(initialColor.impl()), toAPI(listener), m_client.clientInfo);
484 bool WebUIClient::hideColorPicker(WebPageProxy* page)
486 if (!m_client.hideColorPicker)
489 m_client.hideColorPicker(toAPI(page), m_client.clientInfo);
495 } // namespace WebKit