2 * Copyright (C) 2012 Samsung Electronics. All rights reserved.
3 * Copyright (C) 2012 Intel Corporation. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
18 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
24 * THE POSSIBILITY OF SUCH DAMAGE.
28 #include "PageUIClientEfl.h"
30 #include "EwkViewImpl.h"
31 #include "WKAPICast.h"
34 #include <Ecore_Evas.h>
35 #include <WebCore/Color.h>
38 #include "WKGeolocationPermissionRequest.h"
39 #include "WKNotificationPermissionRequest.h"
41 #include "WKRetainPtr.h"
42 #include "WKSecurityOrigin.h"
43 #include "ewk_geolocation_private.h"
44 #include "ewk_notification.h"
45 #include "ewk_notification_private.h"
46 #include "ewk_view_private.h"
52 static inline PageUIClientEfl* toPageUIClientEfl(const void* clientInfo)
54 return static_cast<PageUIClientEfl*>(const_cast<void*>(clientInfo));
57 void PageUIClientEfl::closePage(WKPageRef, const void* clientInfo)
59 toPageUIClientEfl(clientInfo)->m_viewImpl->closePage();
62 WKPageRef PageUIClientEfl::createNewPage(WKPageRef, WKURLRequestRef, WKDictionaryRef, WKEventModifiers, WKEventMouseButton, const void* clientInfo)
64 return toPageUIClientEfl(clientInfo)->m_viewImpl->createNewPage();
68 bool PageUIClientEfl::runJavaScriptAlert(WKPageRef, WKStringRef alertText, WKFrameRef, const void* clientInfo)
70 return ewkViewRunJavaScriptAlert(toPageUIClientEfl(clientInfo)->m_viewImpl->view(), alertText);
73 bool PageUIClientEfl::runJavaScriptConfirm(WKPageRef, WKStringRef message, WKFrameRef, const void* clientInfo)
75 return ewkViewRunJavaScriptConfirm(toPageUIClientEfl(clientInfo)->m_viewImpl->view(), message);
78 bool PageUIClientEfl::runJavaScriptPrompt(WKPageRef, WKStringRef message, WKStringRef defaultValue, WKFrameRef, const void* clientInfo)
80 return ewkViewRunJavaScriptPrompt(toPageUIClientEfl(clientInfo)->m_viewImpl->view(), message, defaultValue);
83 void PageUIClientEfl::runJavaScriptAlert(WKPageRef, WKStringRef alertText, WKFrameRef, const void* clientInfo)
85 toPageUIClientEfl(clientInfo)->m_viewImpl->requestJSAlertPopup(WKEinaSharedString(alertText));
88 bool PageUIClientEfl::runJavaScriptConfirm(WKPageRef, WKStringRef message, WKFrameRef, const void* clientInfo)
90 return toPageUIClientEfl(clientInfo)->m_viewImpl->requestJSConfirmPopup(WKEinaSharedString(message));
93 WKStringRef PageUIClientEfl::runJavaScriptPrompt(WKPageRef, WKStringRef message, WKStringRef defaultValue, WKFrameRef, const void* clientInfo)
95 WKEinaSharedString value = toPageUIClientEfl(clientInfo)->m_viewImpl->requestJSPromptPopup(WKEinaSharedString(message), WKEinaSharedString(defaultValue));
96 return value ? WKStringCreateWithUTF8CString(value) : 0;
100 #if ENABLE(INPUT_TYPE_COLOR)
101 void PageUIClientEfl::showColorPicker(WKPageRef, WKStringRef initialColor, WKColorPickerResultListenerRef listener, const void* clientInfo)
103 PageUIClientEfl* pageUIClient = toPageUIClientEfl(clientInfo);
104 WebCore::Color color = WebCore::Color(WebKit::toWTFString(initialColor));
105 pageUIClient->m_viewImpl->requestColorPicker(color.red(), color.green(), color.blue(), color.alpha(), listener);
108 void PageUIClientEfl::hideColorPicker(WKPageRef, const void* clientInfo)
110 PageUIClientEfl* pageUIClient = toPageUIClientEfl(clientInfo);
111 pageUIClient->m_viewImpl->dismissColorPicker();
115 #if ENABLE(SQL_DATABASE)
116 #if ENABLE(TIZEN_SQL_DATABASE)
117 bool PageUIClientEfl::exceededDatabaseQuota(WKPageRef, WKFrameRef, WKSecurityOriginRef origin, WKStringRef displayName, unsigned long long expectedUsage, const void *clientInfo)
119 return ewkViewExceededDatabaseQuota(toPageUIClientEfl(clientInfo)->m_viewImpl->view(), origin, displayName, expectedUsage);
122 unsigned long long PageUIClientEfl::exceededDatabaseQuota(WKPageRef, WKFrameRef, WKSecurityOriginRef, WKStringRef databaseName, WKStringRef displayName, unsigned long long currentQuota, unsigned long long currentOriginUsage, unsigned long long currentDatabaseUsage, unsigned long long expectedUsage, const void* clientInfo)
124 EwkViewImpl* viewImpl = toPageUIClientEfl(clientInfo)->m_viewImpl;
125 return viewImpl->informDatabaseQuotaReached(toImpl(databaseName)->string(), toImpl(displayName)->string(), currentQuota, currentOriginUsage, currentDatabaseUsage, expectedUsage);
130 void PageUIClientEfl::focus(WKPageRef, const void* clientInfo)
132 evas_object_focus_set(toPageUIClientEfl(clientInfo)->m_viewImpl->view(), true);
135 void PageUIClientEfl::unfocus(WKPageRef, const void* clientInfo)
137 evas_object_focus_set(toPageUIClientEfl(clientInfo)->m_viewImpl->view(), false);
140 void PageUIClientEfl::takeFocus(WKPageRef, WKFocusDirection, const void* clientInfo)
142 // FIXME: this is only a partial implementation.
143 evas_object_focus_set(toPageUIClientEfl(clientInfo)->m_viewImpl->view(), false);
146 WKRect PageUIClientEfl::getWindowFrame(WKPageRef, const void* clientInfo)
148 int x, y, width, height;
150 #if ENABLE(TIZEN_VIEWPORT_META_TAG)
151 ewkViewGetWindowFrame(toPageUIClientEfl(clientInfo)->m_viewImpl->view(), &x, &y, &width, &height);
152 return WKRectMake(x, y, width, height);
154 Ecore_Evas* ee = ecore_evas_ecore_evas_get(evas_object_evas_get(toPageUIClientEfl(clientInfo)->m_viewImpl->view()));
155 ecore_evas_request_geometry_get(ee, &x, &y, &width, &height);
157 return WKRectMake(x, y, width, height);
160 void PageUIClientEfl::setWindowFrame(WKPageRef, WKRect frame, const void* clientInfo)
162 Ecore_Evas* ee = ecore_evas_ecore_evas_get(evas_object_evas_get(toPageUIClientEfl(clientInfo)->m_viewImpl->view()));
163 ecore_evas_move_resize(ee, frame.origin.x, frame.origin.y, frame.size.width, frame.size.height);
167 #if ENABLE(TIZEN_SUPPORT_BEFORE_UNLOAD_CONFIRM_PANEL)
168 bool PageUIClientEfl::runBeforeUnloadConfirmPanel(WKPageRef, WKStringRef message, WKFrameRef, const void* clientInfo)
170 return ewk_view_run_before_unload_confirm_panel(toPageUIClientEfl(clientInfo)->m_viewImpl->view(), message);
174 bool PageUIClientEfl::runOpenPanel(WKPageRef, WKFrameRef, WKOpenPanelParametersRef parameters, WKOpenPanelResultListenerRef listener, const void* clientInfo)
176 return ewkViewRunOpenPanel(toPageUIClientEfl(clientInfo)->m_viewImpl->view(), parameters, listener);
179 void PageUIClientEfl::decidePolicyForGeolocationPermissionRequest(WKPageRef, WKFrameRef, WKSecurityOriginRef origin, WKGeolocationPermissionRequestRef permissionRequest, const void* clientInfo)
181 #if ENABLE(TIZEN_GEOLOCATION)
182 Evas_Object* ewkView = toPageUIClientEfl(clientInfo)->m_viewImpl->view();
183 Ewk_Geolocation_Permission_Request* geolocationPermissionRequest = ewkGeolocationCreatePermissionRequest(ewkView, permissionRequest, origin);
184 ewkViewRequestGeolocationPermission(ewkView, geolocationPermissionRequest);
186 if(!ewkGeolocationIsPermissionRequestSuspended(geolocationPermissionRequest))
187 if(!ewkGeolocationIsPermissionRequestDecided(geolocationPermissionRequest))
188 WKGeolocationPermissionRequestDeny(permissionRequest);
192 #if ENABLE(TIZEN_NOTIFICATIONS)
193 void PageUIClientEfl::decidePolicyForNotificationPermissionRequest(WKPageRef, WKSecurityOriginRef origin, WKNotificationPermissionRequestRef permissionRequest, const void* clientInfo)
195 Evas_Object* ewkView = toPageUIClientEfl(clientInfo)->m_viewImpl->view();
196 Ewk_Notification_Permission_Request* ewkNotificationPermissionRequest = ewkNotificationCreatePermissionRequest(ewkView, permissionRequest, origin);
197 ewkViewRequestNotificationPermission(ewkView, ewkNotificationPermissionRequest);
199 if(!ewkNotificationIsPermissionRequestSuspended(ewkNotificationPermissionRequest))
200 if(!ewkNotificationIsPermissionRequestDecided(ewkNotificationPermissionRequest))
201 WKNotificationPermissionRequestDeny(ewkNotificationGetWKNotificationPermissionRequest(ewkNotificationPermissionRequest));
204 #endif // #if OS(TIZEN)
206 PageUIClientEfl::PageUIClientEfl(EwkViewImpl* viewImpl)
207 : m_viewImpl(viewImpl)
209 WKPageRef pageRef = m_viewImpl->wkPage();
212 WKPageUIClient uiClient;
213 memset(&uiClient, 0, sizeof(WKPageUIClient));
214 uiClient.version = kWKPageUIClientCurrentVersion;
215 uiClient.clientInfo = this;
216 uiClient.close = closePage;
217 uiClient.createNewPage = createNewPage;
218 uiClient.runJavaScriptAlert = runJavaScriptAlert;
219 uiClient.runJavaScriptConfirm = runJavaScriptConfirm;
220 uiClient.runJavaScriptPrompt = runJavaScriptPrompt;
221 uiClient.takeFocus = takeFocus;
222 uiClient.focus = focus;
223 uiClient.unfocus = unfocus;
224 uiClient.getWindowFrame = getWindowFrame;
225 uiClient.setWindowFrame = setWindowFrame;
226 #if ENABLE(SQL_DATABASE)
227 uiClient.exceededDatabaseQuota = exceededDatabaseQuota;
230 #if ENABLE(INPUT_TYPE_COLOR)
231 uiClient.showColorPicker = showColorPicker;
232 uiClient.hideColorPicker = hideColorPicker;
236 #if ENABLE(TIZEN_SUPPORT_BEFORE_UNLOAD_CONFIRM_PANEL)
237 uiClient.runBeforeUnloadConfirmPanel = runBeforeUnloadConfirmPanel;
239 uiClient.runOpenPanel = runOpenPanel;
240 uiClient.decidePolicyForGeolocationPermissionRequest = decidePolicyForGeolocationPermissionRequest;
241 #if ENABLE(TIZEN_NOTIFICATIONS)
242 uiClient.decidePolicyForNotificationPermissionRequest = decidePolicyForNotificationPermissionRequest;
246 WKPageSetPageUIClient(pageRef, &uiClient);
249 } // namespace WebKit