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)
25 #include <ewk_context.h>
27 #include <Core/Util/Log.h>
30 // injection javascript file regarding creating js object used by box and pd
31 static const std::string injectionFile("/usr/share/web-provider/injection.js");
33 std::map<const std::string, const Evas_Smart_Cb> WebView::m_smartCallbacksMap =
35 {"load,started", WebView::loadStartedCallback},
36 {"load,finished", WebView::loadFinishedCallback},
37 {"title,changed", WebView::titleChangedCallback},
38 {"uri,changed", WebView::uriChangedCallback},
39 {"load,progress", WebView::loadProgressCallback},
40 {"load,progress,finished", WebView::loadProgressFinishedCallback},
41 {"process,crashed", WebView::processCrashedCallback},
42 {"create,window", WebView::createWindowCallback},
43 {"close,window", WebView::closeWindowCallback},
44 {"policy,navigation,decide", WebView::policyNavigationDecideCallback},
45 {"policy,newwindow,decide", WebView::policyNewWindowDecideCallback},
46 {"policy,response,decide", WebView::pageResponseDecideCallback},
47 {"contextmenu,customize", WebView::contextmenuCustomizeCallback},
48 {"form,submit", WebView::formSubmitCallback},
49 {"request,geolocation,permission", WebView::geolocationPermissionRequestCallback},
50 {"notification,show", WebView::notificationShowCallback},
51 {"notification,cancel", WebView::notificationCancelCallback},
52 {"notification,permission,request", WebView::notificationPermissionRequestCallback},
53 {"database,quota,exceeded", WebView::databaseUsagePermissionRequestCallback},
54 {"filesystem,permission,request", WebView::fileSystemPermissionRequestCallback},
55 {"fullscreen,enterfullscreen", WebView::enterFullscreenCallback},
56 {"fullscreen,exitfullscreen", WebView::exitFullscreenCallback},
57 {"inputmethod,changed", WebView::imeChangedCallback},
58 {"editorclient,ime,opened", WebView::imeOpenedCallback},
59 {"editorclient,ime,closed", WebView::imeClosedCallback},
60 {"usermedia,permission,request", WebView::usermediaPermissionRequestCallback},
61 {"protocolhandler,registration,requested", WebView::protocolHandlerRegistrationCallback},
62 {"protocolhandler,isregistered", WebView::protocolHandlerIsRegisteredCallback},
63 {"protocolhandler,unregistration,requested", WebView::protocolHandlerUnregistrationCallback},
64 {"contenthandler,registration,requested", WebView::contentHandlerRegistrationCallback},
65 {"contenthandler,isregistered", WebView::contentHandlerIsRegisteredCallback},
66 {"contenthandler,unregistration,requested", WebView::contentHandlerUnregistrationCallback},
67 {"request,certificate,confirm", WebView::certificateConfirmRequestCallback}
70 WebView::WebView(Evas_Object* win, Ewk_Context* ewkContext)
73 , m_ewkContext(ewkContext)
82 std::string& startUrl, int width, int height,
83 WebViewCallback didCreateBaseWebView, void* data)
87 m_topWebview = ewk_view_add_with_context(
88 evas_object_evas_get(m_win), m_ewkContext);
89 if (!setBasicSetting(m_topWebview)) {
94 // inform base webview to caller
95 if (didCreateBaseWebView) {
96 didCreateBaseWebView(data, static_cast<void*>(m_topWebview));
99 // check scheme of url
100 std::string url = validateUrl(startUrl);
101 LogD("load: %s", url.c_str());
102 evas_object_resize(m_topWebview, width, height);
103 evas_object_show(m_topWebview);
104 ewk_view_url_set(m_topWebview, url.c_str());
113 // TODO If created webviews are managed by WebView Class,
114 // add code regarding created all webviews
115 if (!unsetBasicSetting(m_topWebview)) {
118 evas_object_del(m_topWebview);
124 bool WebView::suspend()
127 ewk_view_page_visibility_state_set(
128 m_topWebview, EWK_PAGE_VISIBILITY_STATE_HIDDEN, EINA_FALSE);
129 ewk_view_visibility_set(m_topWebview, EINA_FALSE);
130 ewk_view_suspend(m_topWebview);
134 bool WebView::resume()
137 ewk_view_resume(m_topWebview);
138 ewk_view_page_visibility_state_set(
139 m_topWebview, EWK_PAGE_VISIBILITY_STATE_VISIBLE, EINA_FALSE);
140 ewk_view_visibility_set(m_topWebview, EINA_TRUE);
144 bool WebView::setBasicSetting(Evas_Object* webview)
152 for (auto it = m_smartCallbacksMap.begin();
153 it != m_smartCallbacksMap.end(); it++) {
154 evas_object_smart_callback_add(
155 webview, it->first.c_str(), it->second, this);
158 // set specific features
159 Ewk_Settings* setting = ewk_view_settings_get(webview);
160 // set user agent like WRT, or Browser?
161 // ewk_view_user_agent_set(webview, "some_ua_string");
162 ewk_settings_plugins_enabled_set(setting, EINA_TRUE);
163 ewk_settings_javascript_enabled_set(setting, EINA_TRUE);
164 ewk_settings_loads_images_automatically_set(setting, EINA_TRUE);
165 ewk_settings_auto_fitting_set(setting, EINA_FALSE);
168 ewk_view_page_visibility_state_set(
169 webview, EWK_PAGE_VISIBILITY_STATE_VISIBLE, EINA_TRUE);
172 ewk_view_orientation_lock_callback_set(
173 webview, orientationLockCallback, this);
175 evas_object_color_set(webview, 0, 0, 0, 0);
180 bool WebView::unsetBasicSetting(Evas_Object* webview)
188 for (auto it = m_smartCallbacksMap.begin();
189 it != m_smartCallbacksMap.end(); it++) {
190 evas_object_smart_callback_del(
191 m_topWebview, it->first.c_str(), it->second);
194 ewk_view_orientation_lock_callback_set(m_topWebview, NULL, NULL);
198 std::string WebView::validateUrl(std::string& url)
203 return std::string();
206 if((!url.compare(0, 4, "http")) ||
207 (!url.compare(0, 5, "https")) ||
208 (!url.compare(0, 4, "file")))
213 std::string newUrl("file://");
218 void WebView::loadStartedCallback(
219 void* data, Evas_Object* obj, void* eventInfo)
223 WebView* This = static_cast<WebView*>(data);
225 std::ifstream jsFile(injectionFile);
226 std::string script((std::istreambuf_iterator<char>(jsFile)),
227 std::istreambuf_iterator<char>());
228 LogD("injected js code: %s", script.c_str());
230 ewk_view_script_execute(obj, script.c_str(), executeScriptCallback, This);
231 This->didLoadStarted(obj);
234 void WebView::loadFinishedCallback(
235 void* data, Evas_Object* obj, void* eventInfo)
239 WebView* This = static_cast<WebView*>(data);
240 This->didLoadFinished(obj);
243 void WebView::titleChangedCallback(
244 void* data, Evas_Object* obj, void* eventInfo)
248 WebView* This = static_cast<WebView*>(data);
249 This->didTitleChanged(obj, eventInfo);
252 void WebView::uriChangedCallback(
253 void* data, Evas_Object* obj, void* eventInfo)
257 WebView* This = static_cast<WebView*>(data);
258 This->didUriChanged(obj, eventInfo);
261 void WebView::loadProgressCallback(
262 void* data, Evas_Object* obj, void* eventInfo)
266 WebView* This = static_cast<WebView*>(data);
267 This->didLoadProgress(obj, eventInfo);
270 void WebView::loadProgressFinishedCallback(
271 void* data, Evas_Object* obj, void* eventInfo)
275 WebView* This = static_cast<WebView*>(data);
276 This->didLoadProgressFinished(obj);
279 void WebView::processCrashedCallback(
280 void* data, Evas_Object* obj, void* eventInfo)
284 WebView* This = static_cast<WebView*>(data);
285 This->didProcessCrashed(obj);
288 void WebView::createWindowCallback(
289 void* data, Evas_Object* obj, void* eventInfo)
293 WebView* This = static_cast<WebView*>(data);
294 This->didCreateWindow(obj, eventInfo);
297 void WebView::closeWindowCallback(
298 void* data, Evas_Object* obj, void* eventInfo)
302 WebView* This = static_cast<WebView*>(data);
303 This->didCloseWindow(obj);
306 void WebView::policyNavigationDecideCallback(
307 void* data, Evas_Object* obj, void* eventInfo)
311 WebView* This = static_cast<WebView*>(data);
312 This->didPolicyNavigationDecide(obj, eventInfo);
315 void WebView::policyNewWindowDecideCallback(
316 void* data, Evas_Object* obj, void* eventInfo)
320 WebView* This = static_cast<WebView*>(data);
321 This->didPolicyNewWindowDecide(obj, eventInfo);
324 void WebView::pageResponseDecideCallback(
325 void* data, Evas_Object* obj, void* eventInfo)
329 WebView* This = static_cast<WebView*>(data);
330 This->didPageResponseDecide(obj);
333 void WebView::contextmenuCustomizeCallback(
334 void* data, Evas_Object* obj, void* eventInfo)
338 WebView* This = static_cast<WebView*>(data);
339 This->didContextmenuCustomize(obj, eventInfo);
342 void WebView::formSubmitCallback(
343 void* data, Evas_Object *obj, void* eventInfo)
347 WebView* This = static_cast<WebView*>(data);
348 This->didFormSubmit(obj);
351 void WebView::geolocationPermissionRequestCallback(
352 void* data, Evas_Object* obj, void* eventInfo)
356 WebView* This = static_cast<WebView*>(data);
357 This->didGeolocationPermissionRequest(obj, eventInfo);
360 void WebView::notificationShowCallback(
361 void* data, Evas_Object* obj, void* eventInfo)
365 WebView* This = static_cast<WebView*>(data);
366 This->didNotificationShow(obj, eventInfo);
369 void WebView::notificationCancelCallback(
370 void* data, Evas_Object* obj, void* eventInfo)
374 WebView* This = static_cast<WebView*>(data);
375 This->didNotificationCancel(obj, eventInfo);
378 void WebView::notificationPermissionRequestCallback(
379 void* data, Evas_Object* obj, void* eventInfo)
383 WebView* This = static_cast<WebView*>(data);
384 This->didNotificationPermissionRequest(obj, eventInfo);
387 void WebView::databaseUsagePermissionRequestCallback(
388 void* data, Evas_Object* obj, void* eventInfo)
392 WebView* This = static_cast<WebView*>(data);
393 This->didDatabaseUsagePermissionRequest(obj, eventInfo);
396 void WebView::fileSystemPermissionRequestCallback(
397 void* data, Evas_Object* obj, void* eventInfo)
401 WebView* This = static_cast<WebView*>(data);
402 This->didFilesystemPermissionRequest(obj, eventInfo);
405 void WebView::enterFullscreenCallback(
406 void* data, Evas_Object* obj, void* eventInfo)
410 WebView* This = static_cast<WebView*>(data);
411 This->didEnterFullscreen(obj);
414 void WebView::exitFullscreenCallback(
415 void* data, Evas_Object* obj, void* eventInfo)
419 WebView* This = static_cast<WebView*>(data);
420 This->didExitFullscreen(obj);
423 void WebView::imeChangedCallback(
424 void* data, Evas_Object* obj, void* eventInfo)
428 WebView* This = static_cast<WebView*>(data);
429 This->didImeChanged(obj, eventInfo);
432 void WebView::imeOpenedCallback(
433 void* data, Evas_Object* obj, void* eventInfo)
437 WebView* This = static_cast<WebView*>(data);
438 This->didImeOpened(obj);
441 void WebView::imeClosedCallback(
442 void* data, Evas_Object* obj, void* eventInfo)
446 WebView* This = static_cast<WebView*>(data);
447 This->didImeClosed(obj);
450 void WebView::usermediaPermissionRequestCallback(
451 void* data, Evas_Object* obj, void* eventInfo)
455 WebView* This = static_cast<WebView*>(data);
456 This->didUsermediaPermissionRequest(obj, eventInfo);
459 void WebView::protocolHandlerRegistrationCallback(
460 void* data, Evas_Object* obj, void* eventInfo)
464 WebView* This = static_cast<WebView*>(data);
465 This->didProtocolHandlerRegistration(obj, eventInfo);
468 void WebView::protocolHandlerIsRegisteredCallback(
469 void* data, Evas_Object* obj, void* eventInfo)
473 WebView* This = static_cast<WebView*>(data);
474 This->didProtocolHandlerIsRegistered(obj, eventInfo);
477 void WebView::protocolHandlerUnregistrationCallback(
478 void* data, Evas_Object* obj, void* eventInfo)
482 WebView* This = static_cast<WebView*>(data);
483 This->didProtocolHandlerUnregistration(obj, eventInfo);
486 void WebView::contentHandlerRegistrationCallback(
487 void* data, Evas_Object* obj, void* eventInfo)
491 WebView* This = static_cast<WebView*>(data);
492 This->didContentHandlerRegistration(obj, eventInfo);
495 void WebView::contentHandlerIsRegisteredCallback(
496 void* data, Evas_Object* obj, void* eventInfo)
500 WebView* This = static_cast<WebView*>(data);
501 This->didContentHandlerIsRegistered(obj, eventInfo);
504 void WebView::contentHandlerUnregistrationCallback(
505 void* data, Evas_Object* obj, void* eventInfo)
509 WebView* This = static_cast<WebView*>(data);
510 This->didContentHandlerUnregistration(obj, eventInfo);
513 void WebView::certificateConfirmRequestCallback(
514 void* data, Evas_Object* obj, void* eventInfo)
518 WebView* This = static_cast<WebView*>(data);
519 This->didCertificateConfirmRequest(obj, eventInfo);
522 void WebView::didLoadStarted(Evas_Object* obj)
525 // This Will be implemented by derived class
528 void WebView::didLoadFinished(Evas_Object* obj)
531 // This Will be implemented by derived class
534 void WebView::didTitleChanged(Evas_Object* obj, void* eventInfo)
537 // This Will be implemented by derived class
540 void WebView::didUriChanged(Evas_Object* obj, void* eventInfo)
543 // This Will be implemented by derived class
546 void WebView::didLoadProgress(Evas_Object* obj, void* eventInfo)
549 // This Will be implemented by derived class
552 void WebView::didLoadProgressFinished(Evas_Object* obj)
555 // This Will be implemented by derived class
558 void WebView::didProcessCrashed(Evas_Object* obj)
561 // This Will be implemented by derived class
564 void WebView::didCreateWindow(Evas_Object* obj, void* eventInfo)
567 // This Will be implemented by derived class
570 void WebView::didCloseWindow(Evas_Object* obj)
573 // This Will be implemented by derived class
576 void WebView::didPolicyNavigationDecide(Evas_Object* obj, void* eventInfo)
579 // This Will be implemented by derived class
582 void WebView::didPolicyNewWindowDecide(Evas_Object* obj, void* eventInfo)
585 // This Will be implemented by derived class
588 void WebView::didPageResponseDecide(Evas_Object* obj)
591 // This Will be implemented by derived class
594 void WebView::didContextmenuCustomize(Evas_Object* obj, void* eventInfo)
597 // This Will be implemented by derived class
600 void WebView::didFormSubmit(Evas_Object* obj)
603 // This Will be implemented by derived class
606 void WebView::didGeolocationPermissionRequest(Evas_Object* obj, void* eventInfo)
609 // This Will be implemented by derived class
612 void WebView::didNotificationShow(Evas_Object* obj, void* eventInfo)
615 // This Will be implemented by derived class
618 void WebView::didNotificationCancel(Evas_Object* obj, void* eventInfo)
621 // This Will be implemented by derived class
624 void WebView::didNotificationPermissionRequest(Evas_Object* obj, void* eventInfo)
627 // This Will be implemented by derived class
630 void WebView::didDatabaseUsagePermissionRequest(Evas_Object* obj, void* eventInfo)
633 // This Will be implemented by derived class
636 void WebView::didFilesystemPermissionRequest(Evas_Object* obj, void* eventInfo)
639 // This Will be implemented by derived class
642 void WebView::didEnterFullscreen(Evas_Object* obj)
645 // This Will be implemented by derived class
648 void WebView::didExitFullscreen(Evas_Object* obj)
651 // This Will be implemented by derived class
654 void WebView::didImeChanged(Evas_Object* obj, void* eventInfo)
657 // This Will be implemented by derived class
660 void WebView::didImeOpened(Evas_Object* obj)
663 // This Will be implemented by derived class
666 void WebView::didImeClosed(Evas_Object* obj)
669 // This Will be implemented by derived class
672 void WebView::didUsermediaPermissionRequest(Evas_Object* obj, void* eventInfo)
675 // This Will be implemented by derived class
678 void WebView::didProtocolHandlerRegistration(Evas_Object* obj, void* eventInfo)
681 // This Will be implemented by derived class
684 void WebView::didProtocolHandlerIsRegistered(Evas_Object* obj, void* eventInfo)
687 // This Will be implemented by derived class
690 void WebView::didProtocolHandlerUnregistration(Evas_Object* obj, void* eventInfo)
693 // This Will be implemented by derived class
696 void WebView::didContentHandlerRegistration(Evas_Object* obj, void* eventInfo)
699 // This Will be implemented by derived class
702 void WebView::didContentHandlerIsRegistered(Evas_Object* obj, void* eventInfo)
705 // This Will be implemented by derived class
708 void WebView::didContentHandlerUnregistration(Evas_Object* obj, void* eventInfo)
711 // This Will be implemented by derived class
714 void WebView::didCertificateConfirmRequest(Evas_Object* obj, void* eventInfo)
717 // This Will be implemented by derived class
720 Eina_Bool WebView::orientationLockCallback(
721 Evas_Object* obj, Eina_Bool needLock, int orientation, void* data)
727 void WebView::executeScriptCallback(
728 Evas_Object* obj, const char* result, void* data)