Make permission request for geolocation check page
[framework/web/webkit-efl.git] / Source / WebKit2 / UIProcess / efl / PageUIClientEfl.cpp
1 /*
2  * Copyright (C) 2012 Samsung Electronics. All rights reserved.
3  * Copyright (C) 2012 Intel Corporation. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
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.
13  *
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.
25  */
26
27 #include "config.h"
28 #include "PageUIClientEfl.h"
29
30 #include "EwkViewImpl.h"
31 #include "WKAPICast.h"
32 #include "WKEvent.h"
33 #include "WKString.h"
34 #include <Ecore_Evas.h>
35 #include <WebCore/Color.h>
36
37 #if OS(TIZEN)
38 #include "WKGeolocationPermissionRequest.h"
39 #include "WKNotificationPermissionRequest.h"
40 #include "WKPage.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"
47 #include "ewk_view.h"
48 #endif
49
50 namespace WebKit {
51
52 static inline PageUIClientEfl* toPageUIClientEfl(const void* clientInfo)
53 {
54     return static_cast<PageUIClientEfl*>(const_cast<void*>(clientInfo));
55 }
56
57 void PageUIClientEfl::closePage(WKPageRef, const void* clientInfo)
58 {
59     toPageUIClientEfl(clientInfo)->m_viewImpl->closePage();
60 }
61
62 WKPageRef PageUIClientEfl::createNewPage(WKPageRef, WKURLRequestRef, WKDictionaryRef, WKEventModifiers, WKEventMouseButton, const void* clientInfo)
63 {
64     return toPageUIClientEfl(clientInfo)->m_viewImpl->createNewPage();
65 }
66
67 #if OS(TIZEN)
68 #if ENABLE(TIZEN_WEBKIT2_NOTIFY_POPUP_REPLY_STATUS)
69 void PageUIClientEfl::notifyPopupReplyWaitingState(WKPageRef, bool isWaiting, const void* clientInfo)
70 {
71     ewkViewNotifyPopupReplyWaitingState(toPageUIClientEfl(clientInfo)->m_viewImpl->view(), isWaiting);
72 }
73 #endif
74
75 bool PageUIClientEfl::runJavaScriptAlert(WKPageRef, WKStringRef alertText, WKFrameRef, const void* clientInfo)
76 {
77     return ewkViewRunJavaScriptAlert(toPageUIClientEfl(clientInfo)->m_viewImpl->view(), alertText);
78 }
79
80 bool PageUIClientEfl::runJavaScriptConfirm(WKPageRef, WKStringRef message, WKFrameRef, const void* clientInfo)
81 {
82     return ewkViewRunJavaScriptConfirm(toPageUIClientEfl(clientInfo)->m_viewImpl->view(), message);
83 }
84
85 bool PageUIClientEfl::runJavaScriptPrompt(WKPageRef, WKStringRef message, WKStringRef defaultValue, WKFrameRef, const void* clientInfo)
86 {
87     return ewkViewRunJavaScriptPrompt(toPageUIClientEfl(clientInfo)->m_viewImpl->view(), message, defaultValue);
88 }
89 #else
90 void PageUIClientEfl::runJavaScriptAlert(WKPageRef, WKStringRef alertText, WKFrameRef, const void* clientInfo)
91 {
92     toPageUIClientEfl(clientInfo)->m_viewImpl->requestJSAlertPopup(WKEinaSharedString(alertText));
93 }
94
95 bool PageUIClientEfl::runJavaScriptConfirm(WKPageRef, WKStringRef message, WKFrameRef, const void* clientInfo)
96 {
97     return toPageUIClientEfl(clientInfo)->m_viewImpl->requestJSConfirmPopup(WKEinaSharedString(message));
98 }
99
100 WKStringRef PageUIClientEfl::runJavaScriptPrompt(WKPageRef, WKStringRef message, WKStringRef defaultValue, WKFrameRef, const void* clientInfo)
101 {
102     WKEinaSharedString value = toPageUIClientEfl(clientInfo)->m_viewImpl->requestJSPromptPopup(WKEinaSharedString(message), WKEinaSharedString(defaultValue));
103     return value ? WKStringCreateWithUTF8CString(value) : 0;
104 }
105 #endif
106
107 #if ENABLE(INPUT_TYPE_COLOR)
108 void PageUIClientEfl::showColorPicker(WKPageRef, WKStringRef initialColor, WKColorPickerResultListenerRef listener, const void* clientInfo)
109 {
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);
113 }
114
115 void PageUIClientEfl::hideColorPicker(WKPageRef, const void* clientInfo)
116 {
117     PageUIClientEfl* pageUIClient = toPageUIClientEfl(clientInfo);
118     pageUIClient->m_viewImpl->dismissColorPicker();
119 }
120 #endif
121
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)
125 {
126     return ewkViewExceededDatabaseQuota(toPageUIClientEfl(clientInfo)->m_viewImpl->view(), origin, displayName, expectedUsage);
127 }
128 #else
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)
130 {
131     EwkViewImpl* viewImpl = toPageUIClientEfl(clientInfo)->m_viewImpl;
132     return viewImpl->informDatabaseQuotaReached(toImpl(databaseName)->string(), toImpl(displayName)->string(), currentQuota, currentOriginUsage, currentDatabaseUsage, expectedUsage);
133 }
134 #endif
135 #endif
136
137 void PageUIClientEfl::focus(WKPageRef, const void* clientInfo)
138 {
139     evas_object_focus_set(toPageUIClientEfl(clientInfo)->m_viewImpl->view(), true);
140 }
141
142 void PageUIClientEfl::unfocus(WKPageRef, const void* clientInfo)
143 {
144 #if ENABLE(TIZEN_TAKE_FOCUS)
145     return;
146 #endif
147     evas_object_focus_set(toPageUIClientEfl(clientInfo)->m_viewImpl->view(), false);
148 }
149
150 void PageUIClientEfl::takeFocus(WKPageRef, WKFocusDirection, const void* clientInfo)
151 {
152 #if ENABLE(TIZEN_TAKE_FOCUS)
153     return;
154 #endif
155     // FIXME: this is only a partial implementation.
156     evas_object_focus_set(toPageUIClientEfl(clientInfo)->m_viewImpl->view(), false);
157 }
158
159 WKRect PageUIClientEfl::getWindowFrame(WKPageRef, const void* clientInfo)
160 {
161     int x, y, width, height;
162
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);
166 #endif
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);
169
170     return WKRectMake(x, y, width, height);
171 }
172
173 void PageUIClientEfl::setWindowFrame(WKPageRef, WKRect frame, const void* clientInfo)
174 {
175 #if OS(TIZEN)
176     // FIXME : It is not required just for Mobile Browser. But the solution for desktop browser is required.
177     return;
178 #endif
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);
181 }
182
183 #if OS(TIZEN)
184 #if ENABLE(TIZEN_SUPPORT_BEFORE_UNLOAD_CONFIRM_PANEL)
185 bool PageUIClientEfl::runBeforeUnloadConfirmPanel(WKPageRef, WKStringRef message, WKFrameRef, const void* clientInfo)
186 {
187     return ewk_view_run_before_unload_confirm_panel(toPageUIClientEfl(clientInfo)->m_viewImpl->view(), message);
188 }
189 #endif
190
191 bool PageUIClientEfl::runOpenPanel(WKPageRef, WKFrameRef, WKOpenPanelParametersRef parameters, WKOpenPanelResultListenerRef listener, const void* clientInfo)
192 {
193     return ewkViewRunOpenPanel(toPageUIClientEfl(clientInfo)->m_viewImpl->view(), parameters, listener);
194 }
195
196 void PageUIClientEfl::decidePolicyForGeolocationPermissionRequest(WKPageRef page, WKFrameRef, WKSecurityOriginRef origin, WKGeolocationPermissionRequestRef permissionRequest, const void* clientInfo)
197 {
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);
202
203     if(!ewkGeolocationIsPermissionRequestSuspended(geolocationPermissionRequest))
204         if(!ewkGeolocationIsPermissionRequestDecided(geolocationPermissionRequest))
205             WKGeolocationPermissionRequestDeny(permissionRequest);
206 #endif
207 }
208
209 #if ENABLE(TIZEN_NOTIFICATIONS)
210 void PageUIClientEfl::decidePolicyForNotificationPermissionRequest(WKPageRef, WKSecurityOriginRef origin, WKNotificationPermissionRequestRef permissionRequest, const void* clientInfo)
211 {
212     Evas_Object* ewkView = toPageUIClientEfl(clientInfo)->m_viewImpl->view();
213     Ewk_Notification_Permission_Request* ewkNotificationPermissionRequest = ewkNotificationCreatePermissionRequest(ewkView, permissionRequest, origin);
214     ewkViewRequestNotificationPermission(ewkView, ewkNotificationPermissionRequest);
215
216     if(!ewkNotificationIsPermissionRequestSuspended(ewkNotificationPermissionRequest))
217         if(!ewkNotificationIsPermissionRequestDecided(ewkNotificationPermissionRequest))
218             WKNotificationPermissionRequestDeny(ewkNotificationGetWKNotificationPermissionRequest(ewkNotificationPermissionRequest));
219 }
220 #endif
221 #endif // #if OS(TIZEN)
222
223 PageUIClientEfl::PageUIClientEfl(EwkViewImpl* viewImpl)
224     : m_viewImpl(viewImpl)
225 {
226     WKPageRef pageRef = m_viewImpl->wkPage();
227     ASSERT(pageRef);
228
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;
245 #endif
246
247 #if ENABLE(INPUT_TYPE_COLOR)
248     uiClient.showColorPicker = showColorPicker;
249     uiClient.hideColorPicker = hideColorPicker;
250 #endif
251
252 #if ENABLE(TIZEN_WEBKIT2_NOTIFY_POPUP_REPLY_STATUS)
253     uiClient.notifyPopupReplyWaitingState = notifyPopupReplyWaitingState;
254 #endif
255
256 #if OS(TIZEN)
257 #if ENABLE(TIZEN_SUPPORT_BEFORE_UNLOAD_CONFIRM_PANEL)
258     uiClient.runBeforeUnloadConfirmPanel = runBeforeUnloadConfirmPanel;
259 #endif
260     uiClient.runOpenPanel = runOpenPanel;
261     uiClient.decidePolicyForGeolocationPermissionRequest = decidePolicyForGeolocationPermissionRequest;
262 #if ENABLE(TIZEN_NOTIFICATIONS)
263     uiClient.decidePolicyForNotificationPermissionRequest = decidePolicyForNotificationPermissionRequest;
264 #endif
265 #endif
266
267     WKPageSetPageUIClient(pageRef, &uiClient);
268 }
269
270 } // namespace WebKit