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 #if ENABLE(TIZEN_WEBKIT2_NOTIFY_POPUP_REPLY_STATUS)
69 void PageUIClientEfl::notifyPopupReplyWaitingState(WKPageRef, bool isWaiting, const void* clientInfo)
71 ewkViewNotifyPopupReplyWaitingState(toPageUIClientEfl(clientInfo)->m_viewImpl->view(), isWaiting);
75 bool PageUIClientEfl::runJavaScriptAlert(WKPageRef, WKStringRef alertText, WKFrameRef, const void* clientInfo)
77 return ewkViewRunJavaScriptAlert(toPageUIClientEfl(clientInfo)->m_viewImpl->view(), alertText);
80 bool PageUIClientEfl::runJavaScriptConfirm(WKPageRef, WKStringRef message, WKFrameRef, const void* clientInfo)
82 return ewkViewRunJavaScriptConfirm(toPageUIClientEfl(clientInfo)->m_viewImpl->view(), message);
85 bool PageUIClientEfl::runJavaScriptPrompt(WKPageRef, WKStringRef message, WKStringRef defaultValue, WKFrameRef, const void* clientInfo)
87 return ewkViewRunJavaScriptPrompt(toPageUIClientEfl(clientInfo)->m_viewImpl->view(), message, defaultValue);
90 void PageUIClientEfl::runJavaScriptAlert(WKPageRef, WKStringRef alertText, WKFrameRef, const void* clientInfo)
92 toPageUIClientEfl(clientInfo)->m_viewImpl->requestJSAlertPopup(WKEinaSharedString(alertText));
95 bool PageUIClientEfl::runJavaScriptConfirm(WKPageRef, WKStringRef message, WKFrameRef, const void* clientInfo)
97 return toPageUIClientEfl(clientInfo)->m_viewImpl->requestJSConfirmPopup(WKEinaSharedString(message));
100 WKStringRef PageUIClientEfl::runJavaScriptPrompt(WKPageRef, WKStringRef message, WKStringRef defaultValue, WKFrameRef, const void* clientInfo)
102 WKEinaSharedString value = toPageUIClientEfl(clientInfo)->m_viewImpl->requestJSPromptPopup(WKEinaSharedString(message), WKEinaSharedString(defaultValue));
103 return value ? WKStringCreateWithUTF8CString(value) : 0;
107 #if ENABLE(INPUT_TYPE_COLOR)
108 void PageUIClientEfl::showColorPicker(WKPageRef, WKStringRef initialColor, WKColorPickerResultListenerRef listener, const void* clientInfo)
110 PageUIClientEfl* pageUIClient = toPageUIClientEfl(clientInfo);
111 WebCore::Color color = WebCore::Color(WebKit::toWTFString(initialColor));
112 pageUIClient->m_viewImpl->requestColorPicker(color.red(), color.green(), color.blue(), color.alpha(), listener);
115 void PageUIClientEfl::hideColorPicker(WKPageRef, const void* clientInfo)
117 PageUIClientEfl* pageUIClient = toPageUIClientEfl(clientInfo);
118 pageUIClient->m_viewImpl->dismissColorPicker();
122 #if ENABLE(SQL_DATABASE)
123 #if ENABLE(TIZEN_SQL_DATABASE)
124 bool PageUIClientEfl::exceededDatabaseQuota(WKPageRef, WKFrameRef, WKSecurityOriginRef origin, WKStringRef displayName, unsigned long long expectedUsage, const void *clientInfo)
126 return ewkViewExceededDatabaseQuota(toPageUIClientEfl(clientInfo)->m_viewImpl->view(), origin, displayName, expectedUsage);
129 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)
131 EwkViewImpl* viewImpl = toPageUIClientEfl(clientInfo)->m_viewImpl;
132 return viewImpl->informDatabaseQuotaReached(toImpl(databaseName)->string(), toImpl(displayName)->string(), currentQuota, currentOriginUsage, currentDatabaseUsage, expectedUsage);
137 void PageUIClientEfl::focus(WKPageRef, const void* clientInfo)
139 evas_object_focus_set(toPageUIClientEfl(clientInfo)->m_viewImpl->view(), true);
142 void PageUIClientEfl::unfocus(WKPageRef, const void* clientInfo)
144 #if ENABLE(TIZEN_TAKE_FOCUS)
147 evas_object_focus_set(toPageUIClientEfl(clientInfo)->m_viewImpl->view(), false);
150 void PageUIClientEfl::takeFocus(WKPageRef, WKFocusDirection, const void* clientInfo)
152 #if ENABLE(TIZEN_TAKE_FOCUS)
155 // FIXME: this is only a partial implementation.
156 evas_object_focus_set(toPageUIClientEfl(clientInfo)->m_viewImpl->view(), false);
159 WKRect PageUIClientEfl::getWindowFrame(WKPageRef, const void* clientInfo)
161 int x, y, width, height;
163 #if ENABLE(TIZEN_VIEWPORT_META_TAG)
164 ewkViewGetWindowFrame(toPageUIClientEfl(clientInfo)->m_viewImpl->view(), &x, &y, &width, &height);
165 return WKRectMake(x, y, width, height);
167 Ecore_Evas* ee = ecore_evas_ecore_evas_get(evas_object_evas_get(toPageUIClientEfl(clientInfo)->m_viewImpl->view()));
168 ecore_evas_request_geometry_get(ee, &x, &y, &width, &height);
170 return WKRectMake(x, y, width, height);
173 void PageUIClientEfl::setWindowFrame(WKPageRef, WKRect frame, const void* clientInfo)
176 // FIXME : It is not required just for Mobile Browser. But the solution for desktop browser is required.
179 Ecore_Evas* ee = ecore_evas_ecore_evas_get(evas_object_evas_get(toPageUIClientEfl(clientInfo)->m_viewImpl->view()));
180 ecore_evas_move_resize(ee, frame.origin.x, frame.origin.y, frame.size.width, frame.size.height);
184 #if ENABLE(TIZEN_SUPPORT_BEFORE_UNLOAD_CONFIRM_PANEL)
185 bool PageUIClientEfl::runBeforeUnloadConfirmPanel(WKPageRef, WKStringRef message, WKFrameRef, const void* clientInfo)
187 return ewk_view_run_before_unload_confirm_panel(toPageUIClientEfl(clientInfo)->m_viewImpl->view(), message);
191 bool PageUIClientEfl::runOpenPanel(WKPageRef, WKFrameRef, WKOpenPanelParametersRef parameters, WKOpenPanelResultListenerRef listener, const void* clientInfo)
193 return ewkViewRunOpenPanel(toPageUIClientEfl(clientInfo)->m_viewImpl->view(), parameters, listener);
196 void PageUIClientEfl::decidePolicyForGeolocationPermissionRequest(WKPageRef page, WKFrameRef, WKSecurityOriginRef origin, WKGeolocationPermissionRequestRef permissionRequest, const void* clientInfo)
198 #if ENABLE(TIZEN_GEOLOCATION)
199 Evas_Object* ewkView = toPageUIClientEfl(clientInfo)->m_viewImpl->view();
200 Ewk_Geolocation_Permission_Request* geolocationPermissionRequest = ewkGeolocationCreatePermissionRequest(page, permissionRequest, origin);
201 ewkViewRequestGeolocationPermission(ewkView, geolocationPermissionRequest);
203 if(!ewkGeolocationIsPermissionRequestSuspended(geolocationPermissionRequest))
204 if(!ewkGeolocationIsPermissionRequestDecided(geolocationPermissionRequest))
205 WKGeolocationPermissionRequestDeny(permissionRequest);
209 #if ENABLE(TIZEN_NOTIFICATIONS)
210 void PageUIClientEfl::decidePolicyForNotificationPermissionRequest(WKPageRef, WKSecurityOriginRef origin, WKNotificationPermissionRequestRef permissionRequest, const void* clientInfo)
212 Evas_Object* ewkView = toPageUIClientEfl(clientInfo)->m_viewImpl->view();
213 Ewk_Notification_Permission_Request* ewkNotificationPermissionRequest = ewkNotificationCreatePermissionRequest(ewkView, permissionRequest, origin);
214 ewkViewRequestNotificationPermission(ewkView, ewkNotificationPermissionRequest);
216 if(!ewkNotificationIsPermissionRequestSuspended(ewkNotificationPermissionRequest))
217 if(!ewkNotificationIsPermissionRequestDecided(ewkNotificationPermissionRequest))
218 WKNotificationPermissionRequestDeny(ewkNotificationGetWKNotificationPermissionRequest(ewkNotificationPermissionRequest));
221 #endif // #if OS(TIZEN)
223 PageUIClientEfl::PageUIClientEfl(EwkViewImpl* viewImpl)
224 : m_viewImpl(viewImpl)
226 WKPageRef pageRef = m_viewImpl->wkPage();
229 WKPageUIClient uiClient;
230 memset(&uiClient, 0, sizeof(WKPageUIClient));
231 uiClient.version = kWKPageUIClientCurrentVersion;
232 uiClient.clientInfo = this;
233 uiClient.close = closePage;
234 uiClient.createNewPage = createNewPage;
235 uiClient.runJavaScriptAlert = runJavaScriptAlert;
236 uiClient.runJavaScriptConfirm = runJavaScriptConfirm;
237 uiClient.runJavaScriptPrompt = runJavaScriptPrompt;
238 uiClient.takeFocus = takeFocus;
239 uiClient.focus = focus;
240 uiClient.unfocus = unfocus;
241 uiClient.getWindowFrame = getWindowFrame;
242 uiClient.setWindowFrame = setWindowFrame;
243 #if ENABLE(SQL_DATABASE)
244 uiClient.exceededDatabaseQuota = exceededDatabaseQuota;
247 #if ENABLE(INPUT_TYPE_COLOR)
248 uiClient.showColorPicker = showColorPicker;
249 uiClient.hideColorPicker = hideColorPicker;
252 #if ENABLE(TIZEN_WEBKIT2_NOTIFY_POPUP_REPLY_STATUS)
253 uiClient.notifyPopupReplyWaitingState = notifyPopupReplyWaitingState;
257 #if ENABLE(TIZEN_SUPPORT_BEFORE_UNLOAD_CONFIRM_PANEL)
258 uiClient.runBeforeUnloadConfirmPanel = runBeforeUnloadConfirmPanel;
260 uiClient.runOpenPanel = runOpenPanel;
261 uiClient.decidePolicyForGeolocationPermissionRequest = decidePolicyForGeolocationPermissionRequest;
262 #if ENABLE(TIZEN_NOTIFICATIONS)
263 uiClient.decidePolicyForNotificationPermissionRequest = decidePolicyForNotificationPermissionRequest;
267 WKPageSetPageUIClient(pageRef, &uiClient);
270 } // namespace WebKit