2 * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Flora License, Version 1.1 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * @author Yunchan Cho (yunchan.cho@samsung.com)
23 #include <ewk_context.h>
25 #include <Core/Util/Log.h>
26 #include "InjectedScript.h"
29 std::map<const std::string, const Evas_Smart_Cb> WebView::m_smartCallbacksMap =
31 {"load,started", WebView::loadStartedCallback},
32 {"load,finished", WebView::loadFinishedCallback},
33 {"title,changed", WebView::titleChangedCallback},
34 {"uri,changed", WebView::uriChangedCallback},
35 {"load,progress", WebView::loadProgressCallback},
36 {"load,progress,finished", WebView::loadProgressFinishedCallback},
37 {"process,crashed", WebView::processCrashedCallback},
38 {"create,window", WebView::createWindowCallback},
39 {"close,window", WebView::closeWindowCallback},
40 {"policy,navigation,decide", WebView::policyNavigationDecideCallback},
41 {"policy,newwindow,decide", WebView::policyNewWindowDecideCallback},
42 {"policy,response,decide", WebView::pageResponseDecideCallback},
43 {"contextmenu,customize", WebView::contextmenuCustomizeCallback},
44 {"form,submit", WebView::formSubmitCallback},
45 {"request,geolocation,permission", WebView::geolocationPermissionRequestCallback},
46 {"notification,show", WebView::notificationShowCallback},
47 {"notification,cancel", WebView::notificationCancelCallback},
48 {"notification,permission,request", WebView::notificationPermissionRequestCallback},
49 {"database,quota,exceeded", WebView::databaseUsagePermissionRequestCallback},
50 {"filesystem,permission,request", WebView::fileSystemPermissionRequestCallback},
51 {"fullscreen,enterfullscreen", WebView::enterFullscreenCallback},
52 {"fullscreen,exitfullscreen", WebView::exitFullscreenCallback},
53 {"inputmethod,changed", WebView::imeChangedCallback},
54 {"editorclient,ime,opened", WebView::imeOpenedCallback},
55 {"editorclient,ime,closed", WebView::imeClosedCallback},
56 {"usermedia,permission,request", WebView::usermediaPermissionRequestCallback},
57 {"protocolhandler,registration,requested", WebView::protocolHandlerRegistrationCallback},
58 {"protocolhandler,isregistered", WebView::protocolHandlerIsRegisteredCallback},
59 {"protocolhandler,unregistration,requested", WebView::protocolHandlerUnregistrationCallback},
60 {"contenthandler,registration,requested", WebView::contentHandlerRegistrationCallback},
61 {"contenthandler,isregistered", WebView::contentHandlerIsRegisteredCallback},
62 {"contenthandler,unregistration,requested", WebView::contentHandlerUnregistrationCallback},
63 {"request,certificate,confirm", WebView::certificateConfirmRequestCallback}
66 WebView::WebView(Evas_Object* win, Ewk_Context* ewkContext)
69 , m_ewkContext(ewkContext)
78 std::string& startUrl, int width, int height,
79 WebViewCallback didCreateBaseWebView, void* data)
83 m_topWebview = ewk_view_add_with_context(
84 evas_object_evas_get(m_win), m_ewkContext);
85 if (!setBasicSetting(m_topWebview)) {
90 // inform base webview to caller
91 if (didCreateBaseWebView) {
92 didCreateBaseWebView(data, static_cast<void*>(m_topWebview));
95 // check scheme of url
96 std::string url = validateUrl(startUrl);
97 LogD("load: %s", url.c_str());
98 evas_object_resize(m_topWebview, width, height);
99 evas_object_show(m_topWebview);
100 ewk_view_url_set(m_topWebview, url.c_str());
109 // TODO If created webviews are managed by WebView Class,
110 // add code regarding created all webviews
111 if (!unsetBasicSetting(m_topWebview)) {
114 evas_object_del(m_topWebview);
120 bool WebView::suspend()
123 ewk_view_page_visibility_state_set(
124 m_topWebview, EWK_PAGE_VISIBILITY_STATE_HIDDEN, EINA_FALSE);
125 ewk_view_visibility_set(m_topWebview, EINA_FALSE);
126 ewk_view_suspend(m_topWebview);
130 bool WebView::resume()
133 ewk_view_resume(m_topWebview);
134 ewk_view_page_visibility_state_set(
135 m_topWebview, EWK_PAGE_VISIBILITY_STATE_VISIBLE, EINA_FALSE);
136 ewk_view_visibility_set(m_topWebview, EINA_TRUE);
140 bool WebView::setBasicSetting(Evas_Object* webview)
148 for (auto it = m_smartCallbacksMap.begin();
149 it != m_smartCallbacksMap.end(); it++) {
150 evas_object_smart_callback_add(
151 webview, it->first.c_str(), it->second, this);
154 // set specific features
155 Ewk_Settings* setting = ewk_view_settings_get(webview);
156 // set user agent like WRT, or Browser?
157 // ewk_view_user_agent_set(webview, "some_ua_string");
158 ewk_settings_plugins_enabled_set(setting, EINA_TRUE);
159 ewk_settings_javascript_enabled_set(setting, EINA_TRUE);
160 ewk_settings_loads_images_automatically_set(setting, EINA_TRUE);
161 ewk_settings_auto_fitting_set(setting, EINA_FALSE);
164 ewk_view_page_visibility_state_set(
165 webview, EWK_PAGE_VISIBILITY_STATE_VISIBLE, EINA_TRUE);
168 ewk_view_orientation_lock_callback_set(
169 webview, orientationLockCallback, this);
171 evas_object_color_set(webview, 0, 0, 0, 0);
176 bool WebView::unsetBasicSetting(Evas_Object* webview)
184 for (auto it = m_smartCallbacksMap.begin();
185 it != m_smartCallbacksMap.end(); it++) {
186 evas_object_smart_callback_del(
187 m_topWebview, it->first.c_str(), it->second);
190 ewk_view_orientation_lock_callback_set(m_topWebview, NULL, NULL);
194 std::string WebView::validateUrl(std::string& url)
199 return std::string();
202 if((!url.compare(0, 4, "http")) ||
203 (!url.compare(0, 5, "https")) ||
204 (!url.compare(0, 4, "file")))
209 std::string newUrl("file://");
214 void WebView::loadStartedCallback(
215 void* data, Evas_Object* obj, void* eventInfo)
219 WebView* This = static_cast<WebView*>(data);
220 const char* injectedScript = INJECTED_SCRIPT;
221 ewk_view_script_execute(obj, injectedScript, executeScriptCallback, This);
222 This->didLoadStarted(obj);
225 void WebView::loadFinishedCallback(
226 void* data, Evas_Object* obj, void* eventInfo)
230 WebView* This = static_cast<WebView*>(data);
231 This->didLoadFinished(obj);
234 void WebView::titleChangedCallback(
235 void* data, Evas_Object* obj, void* eventInfo)
239 WebView* This = static_cast<WebView*>(data);
240 This->didTitleChanged(obj, eventInfo);
243 void WebView::uriChangedCallback(
244 void* data, Evas_Object* obj, void* eventInfo)
248 WebView* This = static_cast<WebView*>(data);
249 This->didUriChanged(obj, eventInfo);
252 void WebView::loadProgressCallback(
253 void* data, Evas_Object* obj, void* eventInfo)
257 WebView* This = static_cast<WebView*>(data);
258 This->didLoadProgress(obj, eventInfo);
261 void WebView::loadProgressFinishedCallback(
262 void* data, Evas_Object* obj, void* eventInfo)
266 WebView* This = static_cast<WebView*>(data);
267 This->didLoadProgressFinished(obj);
270 void WebView::processCrashedCallback(
271 void* data, Evas_Object* obj, void* eventInfo)
275 WebView* This = static_cast<WebView*>(data);
276 This->didProcessCrashed(obj);
279 void WebView::createWindowCallback(
280 void* data, Evas_Object* obj, void* eventInfo)
284 WebView* This = static_cast<WebView*>(data);
285 This->didCreateWindow(obj, eventInfo);
288 void WebView::closeWindowCallback(
289 void* data, Evas_Object* obj, void* eventInfo)
293 WebView* This = static_cast<WebView*>(data);
294 This->didCloseWindow(obj);
297 void WebView::policyNavigationDecideCallback(
298 void* data, Evas_Object* obj, void* eventInfo)
302 WebView* This = static_cast<WebView*>(data);
303 This->didPolicyNavigationDecide(obj, eventInfo);
306 void WebView::policyNewWindowDecideCallback(
307 void* data, Evas_Object* obj, void* eventInfo)
311 WebView* This = static_cast<WebView*>(data);
312 This->didPolicyNewWindowDecide(obj, eventInfo);
315 void WebView::pageResponseDecideCallback(
316 void* data, Evas_Object* obj, void* eventInfo)
320 WebView* This = static_cast<WebView*>(data);
321 This->didPageResponseDecide(obj);
324 void WebView::contextmenuCustomizeCallback(
325 void* data, Evas_Object* obj, void* eventInfo)
329 WebView* This = static_cast<WebView*>(data);
330 This->didContextmenuCustomize(obj, eventInfo);
333 void WebView::formSubmitCallback(
334 void* data, Evas_Object *obj, void* eventInfo)
338 WebView* This = static_cast<WebView*>(data);
339 This->didFormSubmit(obj);
342 void WebView::geolocationPermissionRequestCallback(
343 void* data, Evas_Object* obj, void* eventInfo)
347 WebView* This = static_cast<WebView*>(data);
348 This->didGeolocationPermissionRequest(obj, eventInfo);
351 void WebView::notificationShowCallback(
352 void* data, Evas_Object* obj, void* eventInfo)
356 WebView* This = static_cast<WebView*>(data);
357 This->didNotificationShow(obj, eventInfo);
360 void WebView::notificationCancelCallback(
361 void* data, Evas_Object* obj, void* eventInfo)
365 WebView* This = static_cast<WebView*>(data);
366 This->didNotificationCancel(obj, eventInfo);
369 void WebView::notificationPermissionRequestCallback(
370 void* data, Evas_Object* obj, void* eventInfo)
374 WebView* This = static_cast<WebView*>(data);
375 This->didNotificationPermissionRequest(obj, eventInfo);
378 void WebView::databaseUsagePermissionRequestCallback(
379 void* data, Evas_Object* obj, void* eventInfo)
383 WebView* This = static_cast<WebView*>(data);
384 This->didDatabaseUsagePermissionRequest(obj, eventInfo);
387 void WebView::fileSystemPermissionRequestCallback(
388 void* data, Evas_Object* obj, void* eventInfo)
392 WebView* This = static_cast<WebView*>(data);
393 This->didFilesystemPermissionRequest(obj, eventInfo);
396 void WebView::enterFullscreenCallback(
397 void* data, Evas_Object* obj, void* eventInfo)
401 WebView* This = static_cast<WebView*>(data);
402 This->didEnterFullscreen(obj);
405 void WebView::exitFullscreenCallback(
406 void* data, Evas_Object* obj, void* eventInfo)
410 WebView* This = static_cast<WebView*>(data);
411 This->didExitFullscreen(obj);
414 void WebView::imeChangedCallback(
415 void* data, Evas_Object* obj, void* eventInfo)
419 WebView* This = static_cast<WebView*>(data);
420 This->didImeChanged(obj, eventInfo);
423 void WebView::imeOpenedCallback(
424 void* data, Evas_Object* obj, void* eventInfo)
428 WebView* This = static_cast<WebView*>(data);
429 This->didImeOpened(obj);
432 void WebView::imeClosedCallback(
433 void* data, Evas_Object* obj, void* eventInfo)
437 WebView* This = static_cast<WebView*>(data);
438 This->didImeClosed(obj);
441 void WebView::usermediaPermissionRequestCallback(
442 void* data, Evas_Object* obj, void* eventInfo)
446 WebView* This = static_cast<WebView*>(data);
447 This->didUsermediaPermissionRequest(obj, eventInfo);
450 void WebView::protocolHandlerRegistrationCallback(
451 void* data, Evas_Object* obj, void* eventInfo)
455 WebView* This = static_cast<WebView*>(data);
456 This->didProtocolHandlerRegistration(obj, eventInfo);
459 void WebView::protocolHandlerIsRegisteredCallback(
460 void* data, Evas_Object* obj, void* eventInfo)
464 WebView* This = static_cast<WebView*>(data);
465 This->didProtocolHandlerIsRegistered(obj, eventInfo);
468 void WebView::protocolHandlerUnregistrationCallback(
469 void* data, Evas_Object* obj, void* eventInfo)
473 WebView* This = static_cast<WebView*>(data);
474 This->didProtocolHandlerUnregistration(obj, eventInfo);
477 void WebView::contentHandlerRegistrationCallback(
478 void* data, Evas_Object* obj, void* eventInfo)
482 WebView* This = static_cast<WebView*>(data);
483 This->didContentHandlerRegistration(obj, eventInfo);
486 void WebView::contentHandlerIsRegisteredCallback(
487 void* data, Evas_Object* obj, void* eventInfo)
491 WebView* This = static_cast<WebView*>(data);
492 This->didContentHandlerIsRegistered(obj, eventInfo);
495 void WebView::contentHandlerUnregistrationCallback(
496 void* data, Evas_Object* obj, void* eventInfo)
500 WebView* This = static_cast<WebView*>(data);
501 This->didContentHandlerUnregistration(obj, eventInfo);
504 void WebView::certificateConfirmRequestCallback(
505 void* data, Evas_Object* obj, void* eventInfo)
509 WebView* This = static_cast<WebView*>(data);
510 This->didCertificateConfirmRequest(obj, eventInfo);
513 void WebView::didLoadStarted(Evas_Object* obj)
516 // This Will be implemented by derived class
519 void WebView::didLoadFinished(Evas_Object* obj)
522 // This Will be implemented by derived class
525 void WebView::didTitleChanged(Evas_Object* obj, void* eventInfo)
528 // This Will be implemented by derived class
531 void WebView::didUriChanged(Evas_Object* obj, void* eventInfo)
534 // This Will be implemented by derived class
537 void WebView::didLoadProgress(Evas_Object* obj, void* eventInfo)
540 // This Will be implemented by derived class
543 void WebView::didLoadProgressFinished(Evas_Object* obj)
546 // This Will be implemented by derived class
549 void WebView::didProcessCrashed(Evas_Object* obj)
552 // This Will be implemented by derived class
555 void WebView::didCreateWindow(Evas_Object* obj, void* eventInfo)
558 // This Will be implemented by derived class
561 void WebView::didCloseWindow(Evas_Object* obj)
564 // This Will be implemented by derived class
567 void WebView::didPolicyNavigationDecide(Evas_Object* obj, void* eventInfo)
570 // This Will be implemented by derived class
573 void WebView::didPolicyNewWindowDecide(Evas_Object* obj, void* eventInfo)
576 // This Will be implemented by derived class
579 void WebView::didPageResponseDecide(Evas_Object* obj)
582 // This Will be implemented by derived class
585 void WebView::didContextmenuCustomize(Evas_Object* obj, void* eventInfo)
588 // This Will be implemented by derived class
591 void WebView::didFormSubmit(Evas_Object* obj)
594 // This Will be implemented by derived class
597 void WebView::didGeolocationPermissionRequest(Evas_Object* obj, void* eventInfo)
600 // This Will be implemented by derived class
603 void WebView::didNotificationShow(Evas_Object* obj, void* eventInfo)
606 // This Will be implemented by derived class
609 void WebView::didNotificationCancel(Evas_Object* obj, void* eventInfo)
612 // This Will be implemented by derived class
615 void WebView::didNotificationPermissionRequest(Evas_Object* obj, void* eventInfo)
618 // This Will be implemented by derived class
621 void WebView::didDatabaseUsagePermissionRequest(Evas_Object* obj, void* eventInfo)
624 // This Will be implemented by derived class
627 void WebView::didFilesystemPermissionRequest(Evas_Object* obj, void* eventInfo)
630 // This Will be implemented by derived class
633 void WebView::didEnterFullscreen(Evas_Object* obj)
636 // This Will be implemented by derived class
639 void WebView::didExitFullscreen(Evas_Object* obj)
642 // This Will be implemented by derived class
645 void WebView::didImeChanged(Evas_Object* obj, void* eventInfo)
648 // This Will be implemented by derived class
651 void WebView::didImeOpened(Evas_Object* obj)
654 // This Will be implemented by derived class
657 void WebView::didImeClosed(Evas_Object* obj)
660 // This Will be implemented by derived class
663 void WebView::didUsermediaPermissionRequest(Evas_Object* obj, void* eventInfo)
666 // This Will be implemented by derived class
669 void WebView::didProtocolHandlerRegistration(Evas_Object* obj, void* eventInfo)
672 // This Will be implemented by derived class
675 void WebView::didProtocolHandlerIsRegistered(Evas_Object* obj, void* eventInfo)
678 // This Will be implemented by derived class
681 void WebView::didProtocolHandlerUnregistration(Evas_Object* obj, void* eventInfo)
684 // This Will be implemented by derived class
687 void WebView::didContentHandlerRegistration(Evas_Object* obj, void* eventInfo)
690 // This Will be implemented by derived class
693 void WebView::didContentHandlerIsRegistered(Evas_Object* obj, void* eventInfo)
696 // This Will be implemented by derived class
699 void WebView::didContentHandlerUnregistration(Evas_Object* obj, void* eventInfo)
702 // This Will be implemented by derived class
705 void WebView::didCertificateConfirmRequest(Evas_Object* obj, void* eventInfo)
708 // This Will be implemented by derived class
711 Eina_Bool WebView::orientationLockCallback(
712 Evas_Object* obj, Eina_Bool needLock, int orientation, void* data)
718 void WebView::executeScriptCallback(
719 Evas_Object* obj, const char* result, void* data)