2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (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://www.apache.org/licenses/LICENSE-2.0
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.
17 * @file view_logic.cpp
18 * @author Pawel Sikorski (p.sikorsk@samsung.com)
19 * @author Lukasz Wrzosek (l.wrzosek@samsung.com)
20 * @author Yunchan Cho (yunchan.cho@samsung.com)
21 * @brief View logic for Webkit2
23 #include "view_logic.h"
27 #include <dpl/assert.h>
28 #include <dpl/log/log.h>
29 #include <dpl/optional.h>
30 #include <dpl/string.h>
32 #include <appcore-common.h>
34 #include <widget_model.h>
35 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
37 #include <common/application_data.h>
38 #include <common/application_launcher.h>
39 #include <common/scheme.h>
40 #include <common/roaming_agent.h>
42 #include <common/view_logic_apps_support.h>
43 #include <common/view_logic_custom_header_support.h>
44 #include <common/view_logic_password_support.h>
45 #include <common/view_logic_security_support.h>
46 #include <common/view_logic_storage_support.h>
47 #include <common/view_logic_uri_support.h>
48 #include <common/view_logic_user_agent_support.h>
49 #include <common/view_logic_vibration_support.h>
50 #include <common/view_logic_web_notification_support.h>
51 #include <view_logic_scheme_support.h>
52 #include "view_logic_geolocation_support_webkit2.h"
53 #include "view_logic_utils.h"
54 #include "bundles/plugin_module_support.h"
56 #include <ewk_context.h>
57 #include <ewk_context_menu.h>
58 #include <ewk_form_data.h>
59 #include <ewk_network.h>
60 #include <ewk_notification.h>
62 #include <ewk_setting.h>
66 #include <WKContextMenuItem.h>
67 #include <WKURLResponseEfl.h>
68 #include <WKURLRequestEfl.h>
69 #include <js_overlay_types.h>
70 #include <i_runnable_widget_object.h>
74 const char * const bundlePath = "/usr/lib/wrt-wk2-bundles/libwrt-wk2-bundle.so";
75 const char * const willSendMessageName = "will_send_msg";
76 const char * const uriChangedMessageName = "uri_changed_msg";
77 const char * const URICHANGE_PLUGIN_STOP_ONLY = "plugin_stop_only";
78 const char * const URICHANGE_PLUGIN_RESTART = "plugin_restart";
79 const char * const URICHANGE_PLUGIN_NO_CHANGE = "plugin_no_change";
80 const char * const URICHANGE_BLOCKED_URL = "null";
81 const char* PATTERN_URI_CHANGE = "^(([^:/\\?#]+)://[^\\?#]*)";
82 const int MAX_NUM_CONTEXT_MENU_ITEMS = 10;
85 const char * const EWK_CREATE_WINDOW = "create,window";
86 const char * const EWK_CLOSE_WINDOW = "close,window";
87 const char * const EWK_CONTEXTMENU_CUSTOMIZE = "contextmenu,customize";
88 const char * const EWK_FORM_SUBMIT = "form,submit";
89 const char * const EWK_REQUEST_GEOLOCATION_PERMISSION =
90 "request,geolocation,permission";
91 const char * const EWK_NOTIFICATION_SHOW = "notification,show";
92 const char * const EWK_NOTIFICATION_CANCEL = "notification,cancel";
93 const char * const EWK_NOTIFICATION_PERMISSION_REQUEST =
94 "notification,permission,request";
95 const char * const EWK_VIBRATION_VIBRATE = "vibration,vibrate";
96 const char * const EWK_VIBRATION_CANCEL = "vibration,cancel";
100 void ViewLogic::createWebView(Ewk_Context* context,
104 initializeEwkContext(context);
105 Assert(NULL != m_ewkContext);
111 void ViewLogic::destroyWebView()
114 finalizeEwkContext();
118 void ViewLogic::initialize()
120 LogDebug("Initializing");
121 ApplicationLauncherSingleton::Instance().Touch();
123 appcore_set_event_callback(
124 APPCORE_EVENT_LOW_MEMORY,
125 &appcoreLowMemoryCallback,
129 void ViewLogic::terminate()
131 LogDebug("terminating view logic");
135 LogError("Widget model not created");
140 void ViewLogic::prepareView(WidgetModel* m, const std::string &startUrl)
142 LogDebug("View prepare");
146 m_startUrl = ViewModule::UriSupport::getUri(m_model, startUrl);
148 Assert(NULL != m_ewkContext);
153 ewkClientInit(m_currentEwkView);
154 prepareEwkView(m_currentEwkView);
155 initializePluginLoading();
158 void ViewLogic::initializePluginLoading()
160 // inform wrt information for plugin loading to web process
161 PluginModuleSupport::start(
163 m_model->Handle.Get(),
164 elm_config_scale_get(),
165 ApplicationDataSingleton::Instance().getEncodedBundle(),
167 m_model->SettingList.Get().isEncrypted());
170 void ViewLogic::initializeSupport()
172 // set local stroage database path
173 WrtDB::WidgetDAOReadOnly dao(m_model->Handle.Get());
174 ewk_context_web_storage_path_set(m_ewkContext,
175 dao.getPrivateLocalStoragePath().c_str());
176 m_schemeSupport.reset(new SchemeSupport(m_model->Type.Get().appType));
177 ViewModule::StorageSupport::initializeStorage(m_model);
178 m_appsSupport->initialize(m_model);
179 m_vibrationSupport->initialize();
180 ViewModule::GeolocationSupport::Webkit2::initialize(m_model->Handle.Get());
181 ViewModule::GeolocationSupport::Webkit2::
182 adjustGeolocationModuleState(m_currentEwkView);
185 void ViewLogic::showWidget()
187 LogDebug("showing widget");
188 Assert(NULL != m_currentEwkView && "ewk_view not created at this point");
189 if (m_currentUri.empty()) {
190 LogError("Localized current URI doesn't exist");
194 LogInfo("m_currentUri: " << m_currentUri);
196 RoamingAgentSingleton::Instance().setDisconnectCallback(
197 DPL::MakeDelegate(this,
198 &ViewLogic::disconnectNetworkConnectionsFunction));
201 WKURLRef baseUrl = WKURLCreateWithUTF8CString(
202 m_currentUri.c_str());
204 LogError("URL creation failed");
207 WKPageLoadURL(ewk_view_WKPage_get(m_currentEwkView), baseUrl);
210 if (m_cbs->bufferSet) {
211 m_cbs->bufferSet(m_currentEwkView, m_cbsData);
215 void ViewLogic::hideWidget()
217 LogDebug("hiding widget");
218 RoamingAgentSingleton::Instance().unsetDisconnectCallback();
219 ViewModule::StorageSupport::deinitializeStorage(m_model);
220 m_appsSupport->deinitialize();
221 m_vibrationSupport->deinitialize();
222 // almost terminate time spends for terminate webkit.
223 // after block this evas_object_del code, webkit will be destoryed
224 // with parent evas_object(~WindowData())
225 //FOREACH(it, m_ewkViewList) {
226 // evas_object_del(*it);
228 m_ewkViewList.clear();
231 void ViewLogic::suspendWidget()
233 LogInfo("Pausing widget");
236 if (!m_currentEwkView) {
237 LogWarning("Cannot suspend widget without view");
239 suspendWebkit(m_currentEwkView);
242 // call user callback
243 if (m_cbs->suspend) {
244 m_cbs->suspend(true, m_cbsData);
248 void ViewLogic::resumeWidget()
250 LogInfo("Resume widget");
253 if (m_currentEwkView) {
254 resumeWebkit(m_currentEwkView);
258 elm_win_activate(m_window);
260 evas_object_focus_set(m_currentEwkView, EINA_TRUE);
262 // call user callback
264 m_cbs->resume(true, m_cbsData);
268 void ViewLogic::resetWidget()
270 LogInfo("Resetting Widget");
272 // check if already created webview exists
273 if (!m_ewkViewList.size()) {
274 // create new webview
277 ewkClientInit(m_currentEwkView);
278 prepareEwkView(m_currentEwkView);
280 bundle *bundle = ApplicationDataSingleton::Instance().getBundle();
281 const char *operation = appsvc_get_operation(bundle);
282 LogInfo("operation : " << operation);
284 !strcmp(operation, APPSVC_OPERATION_DEFAULT)) {
285 // ignore default operation that is reserved by system
286 // just activate current window
287 LogInfo("raise window");
288 elm_win_raise(m_window);
289 resumeWebkit(m_currentEwkView);
293 // check if current url is service url for this tizen service
294 std::string requestedUri =
295 ViewModule::UriSupport::getUri(m_model, m_startUrl);
296 DPL::OptionalString servicedUri = ViewModule::UriSupport::localizeURI(
297 DPL::FromUTF8String(requestedUri.c_str()),
299 if (m_currentUri == DPL::ToUTF8String(*servicedUri)) {
300 // set only encoded bundle
301 double scale = elm_config_scale_get();
303 PluginModuleSupport::setCustomProperties(
306 ApplicationDataSingleton::Instance().getEncodedBundle());
307 // dispatch 'appservice' js event
308 PluginModuleSupport::dispatchJavaScriptEvent(
310 WrtPlugins::W3C::ServiceCustomEvent);
313 elm_win_raise(m_window);
315 resumeWebkit(m_currentEwkView);
318 m_currentUri = DPL::ToUTF8String(*servicedUri);
322 // inform wrt information for plugin loading to web process
323 PluginModuleSupport::start(
325 m_model->Handle.Get(),
326 elm_config_scale_get(),
327 ApplicationDataSingleton::Instance().getEncodedBundle(),
329 m_model->SettingList.Get().isEncrypted());
332 WKURLRef baseUrl = WKURLCreateWithUTF8CString(
333 m_currentUri.c_str());
335 LogError("URL creation failed");
338 WKPageLoadURL(ewk_view_WKPage_get(m_currentEwkView), baseUrl);
340 resumeWebkit(m_currentEwkView);
342 // call user callback
344 m_cbs->reset(true, m_cbsData);
346 if (m_cbs->bufferSet) {
347 m_cbs->bufferSet(m_currentEwkView, m_cbsData);
351 void ViewLogic::goBack()
353 if (WKPageCanGoBack(ewk_view_WKPage_get(m_currentEwkView))) {
354 WKPageGoBack(ewk_view_WKPage_get(m_currentEwkView));
356 if (1 >= m_ewkViewList.size()) {
357 // If there is no previous page, widget move to backgroud.
358 LogInfo("Widget move to backgroud");
359 elm_win_lower(m_window);
361 // Back to previous webview
362 LogInfo("Widget move to previous webview");
363 ecore_idler_add(windowCloseIdlerCallback, this);
368 Evas_Object* ViewLogic::getCurrentWebview()
370 LogInfo("get current webview");
371 return m_currentEwkView;
374 void ViewLogic::setUserCallbacks(WRT::UserCallbacksPtr cbs, void *data)
380 void ViewLogic::initializeEwkContext(Ewk_Context* newEwkContext)
382 LogInfo("initializeEwkContext called");
383 Assert(newEwkContext && "Ewk_Context provided can not be null");
384 // bundle callback setting
385 ewk_context_message_from_injected_bundle_callback_set(
387 contextMessageFromInjectedBundleCallback,
388 static_cast<void*>(this));
390 // proxy server setting
391 char *proxyAddress = vconf_get_str(VCONFKEY_NETWORK_PROXY);
392 if ((!proxyAddress) || (strlen(proxyAddress) == 0)
393 || (strstr(proxyAddress, "0.0.0.0")))
395 LogInfo("proxy address is empty");
396 ewk_context_proxy_uri_set(newEwkContext, NULL);
398 LogInfo("proxy address [" << proxyAddress << "]");
399 ewk_context_proxy_uri_set(newEwkContext, proxyAddress);
408 const char *theme = elm_theme_get(NULL);
411 LogInfo("theme is " << m_theme);
414 // set download callback
415 //WKContextDownloadClient downloadClient = {
416 // kWKContextDownloadClientCurrentVersion,
419 // 0, // didReceiveAuthenticationChallenge
420 // 0, // didReceiveResponse
421 // 0, // didReceiveData
422 // 0, // shouldDecodeSourceDataOfMIMEType
423 // 0, // decideDestinationWithSuggestedFilename
424 // 0, // didCreateDestination
428 // 0 // processDidCrash
430 // WKContextSetDownloadClient(newEwkContext, &downloadClient);
431 ewk_context_did_start_download_callback_set(
433 didStartDownloadCallback,
436 // set to member value
437 m_ewkContext = newEwkContext;
440 void ViewLogic::finalizeEwkContext()
442 LogInfo("finalizeEwkContext called");
443 ewk_context_delete(m_ewkContext);
448 ViewLogic::ViewLogic():
453 m_appsSupport(new ViewModule::AppsSupport()),
454 m_vibrationSupport(new ViewModule::VibrationSupport()),
456 m_cbs(new WRT::UserCallbacks),
461 ViewLogic::~ViewLogic ()
465 void ViewLogic::ewkClientInit(Evas_Object *wkView) {
466 Assert(NULL != wkView && "ewk_view not created at this point");
468 ViewModule::GeolocationSupport::Webkit2::
469 initialize(m_model->Handle.Get());
471 WKPageLoaderClient loaderClient = {
472 kWKPageLoaderClientCurrentVersion, /* version */
473 static_cast<void*>(this), /* clientinfo */
474 didStartProvisionalLoadForFrameCallback, /* didStartProvisionalLoadForFrame */
475 0, /* didReceiveServerRedirectForProvisionalLoadForFrame */
476 0, /* didFailProvisionalLoadWithErrorForFrame */
477 0, /* didCommitLoadForFrame */
478 0, /* didFinishDocumentLoadForFrame */
479 didFinishLoadForFrameCallback, /* didFinishLoadForFrame */
480 0, /* didFailLoadWithErrorForFrame */
481 0, /* didSameDocumentNavigationForFrame */
482 didReceiveTitleForFrameCallback, /* didReceiveTitleForFrame */
483 0, /* didFirstLayoutForFrame */
484 0, /* didFirstVisuallyNonEmptyLayoutForFrame */
485 0, /* didRemoveFrameFromHierarchy */
486 0, /* didDisplayInsecureContentForFrame */
487 0, /* didRunInsecureContentForFrame */
488 0, /* canAuthenticateAgainstProtectionSpaceInFrame */
489 0, /* didReceiveAuthenticationChallengeInFrame */
490 didStartProgressCallback, /* didStartProgressCallback */
491 didChangeProgressCallback, /* didChangeProgress */
492 didFinishProgressCallback, /* didFinishProgress */
493 0, /* processDidBecomeUnresponsive */
494 0, /* processDidBecomeResponsive */
495 processDidCrashCallback, /* processDidCrash */
496 0, /* didChangeBackForwardList */
497 0, /* shouldGoToBackForwardListItem */
498 0, /* didFailToInitializePlugin */
499 0, /* didDetectXSSForFrame */
500 0, /* didNewFirstVisuallyNonEmptyLayout */
501 0, /* willGoToBackForwardListItem */
502 0, /* interactionOccurredWhileProcessUnresponsive */
503 0, /* pluginDidFail */
505 WKPageSetPageLoaderClient(ewk_view_WKPage_get(wkView), &loaderClient);
507 //WKPageUIClient uiClient = {
508 // kWKPageUIClientCurrentVersion, /* version */
509 // static_cast<void*>(this), /* clientInfo */
510 // 0, /* createNewPage_deprecatedForUseWithV0 */
512 // closeCallback, /* close */
513 // 0, /* takeFocus */
516 // 0, /* runJavaScriptAlert */
517 // 0, /* runJavaScriptConfirm */
518 // 0, /* runJavaScriptPrompt */
519 // 0, /* setStatusText */
520 // 0, /* mouseDidMoveOverElement */
521 // 0, /* missingPluginButtonClicked */
522 // 0, /* didNotHandleKeyEvent */
523 // 0, /* didNotHandleWheelEvent */
524 // 0, /* toolbarsAreVisible */
525 // 0, /* setToolbarsAreVisible */
526 // 0, /* menuBarIsVisible */
527 // 0, /* setMenuBarIsVisible */
528 // 0, /* statusBarIsVisible */
529 // 0, /* setStatusBarIsVisible */
530 // 0, /* isResizable */
531 // 0, /* setIsResizable */
532 // 0, /* getWindowFrame */
533 // 0, /* setWindowFrame */
534 // 0, /* runBeforeUnloadConfirmPanel */
536 // 0, /* pageDidScroll */
537 // 0, /* exceededDatabaseQuota */
538 // 0, /* runOpenPanel */
539 // decidePolicyForGeolocationPermissionRequestCallback, /* decidePolicyForGeolocationPermissionRequest */
540 // 0, /* headerHeight */
541 // 0, /* footerHeight */
542 // 0, /* drawHeader */
543 // 0, /* drawFooter */
544 // 0, /* printFrame */
546 // 0, /* didCompleteRubberBandForMainFrame */
547 // 0, /* saveDataToFileInDownloadsFolder */
548 // 0, /* shouldInterruptJavaScript */
549 // createNewPageCallback, /* createNewPage */
550 // 0, /* mouseDidMoveOverElement */
551 // decidePolicyForNotificationPermissionRequestCallback, /* decidePolicyForNotificationPermissionRequest */
553 //WKPageSetPageUIClient(ewk_view_page_get(wkView), &uiClient);
554 evas_object_smart_callback_add(
557 createWindowCallback,
559 evas_object_smart_callback_add(
565 WKPagePolicyClient policyClient = {
566 kWKPagePolicyClientCurrentVersion, /* version */
567 static_cast<void*>(this), /* clientInfo */
568 pageDecidePolicyForNavigationActionCallback, /* decidePolicyForNavigationAction */
569 pageDecidePolicyForNewWindowActionCallback, /* decidePolicyForNewWindowAction */
570 pageDecidePolicyForResponseCallback,
571 0, /* unableToImplementPolicy */
573 WKPageSetPagePolicyClient(ewk_view_WKPage_get(wkView),
576 // EWK ContextMenu Callback
577 //WKPageContextMenuClient contextMenuClient = {
578 // kWKPageContextMenuClientCurrentVersion, /* version */
579 // static_cast<void*>(this), /* clientInfo */
580 // 0, /* getContextMenuFromProposedMenu_deprecatedForUseWithV0 */
581 // 0, /* customContextMenuItemSelected */
582 // 0, /* contextMenuDismissed */
583 // pageContextMenuForGetMenuCallback /* getContextMenuFromProposedMenu */
585 //WKPageSetPageContextMenuClient(ewk_view_page_get(wkView),
586 // &contextMenuClient);
587 evas_object_smart_callback_add(
589 EWK_CONTEXTMENU_CUSTOMIZE,
590 contextmenuCustomizeCallback,
593 // WKPageFormClient formClient = {
594 // kWKPageFormClientCurrentVersion, /* version */
595 // static_cast<void*>(this), /* clientInfo */
596 // willSubmitFormCallback, /* willSubmitForm */
598 // WKPageSetPageFormClient(ewk_view_page_get(wkView), &formClient);
599 evas_object_smart_callback_add(
605 // EWK Geolocation Callback
606 //WKGeolocationProvider geolocation_provider = {
607 // kWKGeolocationProviderCurrentVersion,
609 // startUpdatingCallback,
610 // stopUpdatingCallback
612 //WKGeolocationManagerRef geolocation_manager_ref
613 // = WKContextGetGeolocationManager(m_wkctx);
614 //WKGeolocationManagerSetProvider(geolocation_manager_ref,
615 // &geolocation_provider);
616 evas_object_smart_callback_add(
618 EWK_REQUEST_GEOLOCATION_PERMISSION,
619 geolocationPermissionRequestCallback,
621 // EWK Notification Callback
622 //WKNotificationProvider notificationProvider = {
623 // kWKNotificationProviderCurrentVersion, /* version */
624 // static_cast<void*>(this), /* clientinfo */
625 // showNotificationCallback, /* show */
627 // 0, /* didDestroyNotification */
628 // 0, /* addNotificationManager */
629 // 0, /* removeNotificationManager */
630 // 0, /* notificationPermissions */
631 // 0, /* clearNotifications */
633 //WKNotificationManagerSetProvider(WKContextGetNotificationManager(m_wkctx),
634 // ¬ificationProvider);
635 evas_object_smart_callback_add(
637 EWK_NOTIFICATION_SHOW,
638 notificationShowCallback,
640 evas_object_smart_callback_add(
642 EWK_NOTIFICATION_CANCEL,
643 notificationCancelCallback,
645 evas_object_smart_callback_add(
647 EWK_NOTIFICATION_PERMISSION_REQUEST,
648 notificationPermissionRequestCallback,
650 evas_object_smart_callback_add(
652 EWK_VIBRATION_VIBRATE,
653 vibrationVibrateCallback,
655 evas_object_smart_callback_add(
657 EWK_VIBRATION_CANCEL,
658 vibrationCancelCallback,
661 // EWK Orientation Callback
662 ewk_view_orientation_lock_callback_set(
664 orientationLockCallback,
668 void ViewLogic::ewkClientDeinit(Evas_Object *wkView) {
669 LogDebug("ewkClientDeinit");
670 Assert(NULL != wkView && "ewk_view not created at this point");
672 // deinit WKPageLoaderClient
673 WKPageLoaderClient loaderClient = {
676 0, /* didStartProvisionalLoadForFrame */
677 0, /* didReceiveServerRedirectForProvisionalLoadForFrame */
678 0, /* didFailProvisionalLoadWithErrorForFrame */
679 0, /* didCommitLoadForFrame */
680 0, /* didFinishDocumentLoadForFrame */
681 0, /* didFinishLoadForFrame */
682 0, /* didFailLoadWithErrorForFrame */
683 0, /* didSameDocumentNavigationForFrame */
684 0, /* didReceiveTitleForFrame */
685 0, /* didFirstLayoutForFrame */
686 0, /* didFirstVisuallyNonEmptyLayoutForFrame */
687 0, /* didRemoveFrameFromHierarchy */
688 0, /* didDisplayInsecureContentForFrame */
689 0, /* didRunInsecureContentForFrame */
690 0, /* canAuthenticateAgainstProtectionSpaceInFrame */
691 0, /* didReceiveAuthenticationChallengeInFrame */
692 0, /* didStartProgressCallback */
693 0, /* didChangeProgress */
694 0, /* didFinishProgress */
695 0, /* processDidBecomeUnresponsive */
696 0, /* processDidBecomeResponsive */
697 0, /* processDidCrash */
698 0, /* didChangeBackForwardList */
699 0, /* shouldGoToBackForwardListItem */
700 0, /* didFailToInitializePlugin */
701 0, /* didDetectXSSForFrame */
702 0, /* didNewFirstVisuallyNonEmptyLayout */
703 0, /* willGoToBackForwardListItem */
704 0, /* interactionOccurredWhileProcessUnresponsive */
705 0, /* pluginDidFail */
707 WKPageSetPageLoaderClient(ewk_view_WKPage_get(wkView),
710 // deinit WKPageUIClient
711 //WKPageUIClient uiClient = {
713 // 0, /* clientInfo */
714 // 0, /* createNewPage_deprecatedForUseWithV0 */
717 // 0, /* takeFocus */
720 // 0, /* runJavaScriptAlert */
721 // 0, /* runJavaScriptConfirm */
722 // 0, /* runJavaScriptPrompt */
723 // 0, /* setStatusText */
724 // 0, /* mouseDidMoveOverElement */
725 // 0, /* missingPluginButtonClicked */
726 // 0, /* didNotHandleKeyEvent */
727 // 0, /* didNotHandleWheelEvent */
728 // 0, /* toolbarsAreVisible */
729 // 0, /* setToolbarsAreVisible */
730 // 0, /* menuBarIsVisible */
731 // 0, /* setMenuBarIsVisible */
732 // 0, /* statusBarIsVisible */
733 // 0, /* setStatusBarIsVisible */
734 // 0, /* isResizable */
735 // 0, /* setIsResizable */
736 // 0, /* getWindowFrame */
737 // 0, /* setWindowFrame */
738 // 0, /* runBeforeUnloadConfirmPanel */
740 // 0, /* pageDidScroll */
741 // 0, /* exceededDatabaseQuota */
742 // 0, /* runOpenPanel */
743 // 0, /* decidePolicyForGeolocationPermissionRequest */
744 // 0, /* headerHeight */
745 // 0, /* footerHeight */
746 // 0, /* drawHeader */
747 // 0, /* drawFooter */
748 // 0, /* printFrame */
750 // 0, /* didCompleteRubberBandForMainFrame */
751 // 0, /* saveDataToFileInDownloadsFolder */
752 // 0, /* shouldInterruptJavaScript */
753 // 0, /* createNewPage */
754 // 0, /* mouseDidMoveOverElement */
755 // 0, /* decidePolicyForNotificationPermissionRequest */
757 //WKPageSetPageUIClient(ewk_view_page_get(wkView), &uiClient);
758 evas_object_smart_callback_del(
761 createWindowCallback);
762 evas_object_smart_callback_del(
765 closeWindowCallback);
768 // deinit WKPagePolicyClient
769 WKPagePolicyClient policyClient = {
772 0, /* decidePolicyForNavigationAction */
773 0, /* decidePolicyForNewWindowAction */
774 0, /* decidePolicyForResponse */
775 0, /* unableToImplementPolicy */
777 WKPageSetPagePolicyClient(ewk_view_WKPage_get(wkView),
780 // EWK ContextMenu Callback
781 evas_object_smart_callback_del(
783 EWK_CONTEXTMENU_CUSTOMIZE,
784 contextmenuCustomizeCallback);
785 // deinit WKPageFormClient
786 // WKPageFormClient formClient = {
788 // 0, /* clientInfo */
789 // 0, /* willSubmitForm */
791 // WKPageSetPageFormClient(ewk_view_page_get(wkView), &formClient);
792 evas_object_smart_callback_del(
796 // EWK Geolocation Callback
797 evas_object_smart_callback_del(
799 EWK_REQUEST_GEOLOCATION_PERMISSION,
800 geolocationPermissionRequestCallback);
801 // EWK Notification Callback
802 evas_object_smart_callback_del(
804 EWK_NOTIFICATION_SHOW,
805 notificationShowCallback);
806 evas_object_smart_callback_del(
808 EWK_NOTIFICATION_CANCEL,
809 notificationCancelCallback);
810 evas_object_smart_callback_del(
812 EWK_NOTIFICATION_PERMISSION_REQUEST,
813 notificationPermissionRequestCallback);
815 evas_object_smart_callback_del(
817 EWK_VIBRATION_VIBRATE,
818 vibrationVibrateCallback);
819 evas_object_smart_callback_del(
821 EWK_VIBRATION_CANCEL,
822 vibrationCancelCallback);
824 // EWK Orientation Callback
825 ewk_view_orientation_lock_callback_set(
831 void ViewLogic::createEwkView()
833 LogDebug("createEwkVeiw");
834 Evas_Object* newEwkView = ewk_view_add_with_context(
835 evas_object_evas_get(m_window),
839 LogError("WKView creation failed");
844 // even arguments pass the ewkContext, this API should be called
845 // after webkit Evas_Object is created
846 ewk_context_cookies_policy_set(m_ewkContext, EWK_COOKIE_JAR_ACCEPT_ALWAYS);
848 m_ewkViewList.push_back(newEwkView);
849 m_currentEwkView = newEwkView;
853 void ViewLogic::setStartPage()
855 //TODO: actually this localization should be done in requestWillSend
856 // callback, but Webkit2 denies access to local files if it detects
857 // that first loaded file is not 'local' so it wan't work
858 DPL::OptionalString localizedUri = ViewModule::UriSupport::localizeURI(
859 DPL::FromUTF8String(m_startUrl.c_str()),
861 m_currentUri = DPL::ToUTF8String(*localizedUri);
864 void ViewLogic::prepareEwkView(Evas_Object *wkView)
866 LogDebug("prepareEwkView called");
868 Ewk_Setting* setting = ewk_view_setting_get(wkView);
871 auto userAgentString =
872 ViewModule::UserAgentSupport::getUserAgentFromVconf();
873 if (!userAgentString.empty()) {
874 LogDebug("Setting custom user agent as: " << userAgentString);
875 ewk_view_user_agent_set(wkView, userAgentString.c_str());
878 // set custom header : language
879 using namespace ViewModule::CustomHeaderSupport;
880 std::string customHeaderString = getValueByField(ACCEPT_LANGUAGE);
881 if (!customHeaderString.empty()) {
882 LogDebug("custom field=[" << ACCEPT_LANGUAGE << "]");
883 LogDebug("custom value=[" << customHeaderString << "]");
884 ewk_view_custom_header_add(wkView,
885 ACCEPT_LANGUAGE.c_str(),
886 customHeaderString.c_str());
889 // enable webkit plugins
890 WrtDB::WidgetDAOReadOnly dao(m_model->Handle.Get());
891 if (dao.getWebkitPluginsRequired()) {
892 ewk_setting_enable_plugins_set(setting, EINA_TRUE);
894 ewk_setting_enable_plugins_set(setting, EINA_FALSE);
897 // The followings are not implemeted yet by webkit2
898 // ewk_view_setting_accelerated_compositing_enable_set(EINA_TRUE);
899 // ewk_view_mode_set();
900 // ewk_view_setting_enable_specified_plugin_set(EINA_TRUE, FLASH_MIME_TYPE);
901 // ewk_view_setting_html5video_external_player_enable_set(EINA_FALSE);
902 // ewk_view_show_ime_on_autofocus_set(EINA_TRUE);
903 // elm_webview_show_magnifier_set(EINA_FALSE);
904 ewk_setting_enable_scripts_set(setting, EINA_TRUE);
905 ewk_setting_auto_load_images_set(setting, EINA_TRUE);
906 ewk_setting_auto_fitting_set(setting, EINA_FALSE);
908 // disable zoom option when user click the input field
909 // this option is useful with the normal website
910 // for the make user friendly, disable auto zoom in the webapp
911 // The followings are not implemeted yet by webkit2
912 // elm_webview_input_field_zoom_set(EINA_FALSE);
914 // set cookie database path
915 // The followings are not implemeted yet by webkit2
916 // ewk_cookies_file_set(dao.getCookieDatabasePath().c_str()));
918 // set visibility to WebCore. This value will be used for html5.
919 // also, this value will be changed in the suspend, resume
920 // or create window, close window.
921 ewk_view_page_visibility_state_set(wkView,
922 EWK_PAGE_VISIBILITY_STATE_VISIBLE,
926 void ViewLogic::removeEwkView(Evas_Object *wkView)
928 LogInfo("removeEwkView called");
930 Assert(0 != m_ewkViewList.size());
932 // unregister webview callbacks
933 ewkClientDeinit(wkView);
935 // suspend NPAPI plugin - Not implemented by Webkit2
936 // ewk_view_pause_or_resume_plugins();
937 m_ewkViewList.remove(wkView);
938 evas_object_del(wkView);
941 void ViewLogic::resumeEwkView(Evas_Object *wkView)
943 LogInfo("resumeEwkView called");
946 // register webview callback
947 ewkClientInit(wkView);
950 resumeWebkit(wkView);
955 void ViewLogic::suspendEwkView(Evas_Object *wkView)
957 LogInfo("suspendEwkView called");
961 suspendWebkit(wkView);
963 // unregister webview callbacks
964 ewkClientDeinit(wkView);
968 void ViewLogic::resumeWebkit(Evas_Object *wkView)
970 LogDebug("resumeWebkit");
973 // resume NPAPI plugin
974 // The followings are not implemeted yet by webkit2
975 // ewk_view_pause_or_resume_plugins(false);
976 // ewk_view_pause_or_resume_video_audio(false);
977 // ewk_view_javascript_resume();
978 // ewk_view_enable_render();
979 // ewk_view_reduce_plugins_frame_rate(false);
980 ewk_view_resume(wkView);
981 ewk_view_visibility_set(wkView, EINA_TRUE);
982 ewk_view_page_visibility_state_set(wkView,
983 EWK_PAGE_VISIBILITY_STATE_VISIBLE,
988 void ViewLogic::suspendWebkit(Evas_Object *wkView)
990 LogDebug("suspendWebkit");
993 // suspend the followings
994 // The followings are not implemeted yet by webkit2
995 // ewk_view_pause_or_resume_plugins(true);
996 // ewk_view_pause_or_resume_video_audio(true);
998 // send visibility event to webpage
999 ewk_view_page_visibility_state_set(wkView,
1000 EWK_PAGE_VISIBILITY_STATE_HIDDEN,
1002 ewk_view_suspend(wkView);
1003 ewk_view_visibility_set(wkView, EINA_FALSE);
1007 void ViewLogic::contextMessageFromInjectedBundleCallback(
1013 LogDebug("contextMessageFromInjectedBundleCallback called");
1015 ViewLogic* This = static_cast<ViewLogic*>(clientInfo);
1016 // didRecieveMessageFromInjectedBundleCallback - returnData is null
1017 // didReceiveSynchronousMessageCallback - returnData isn't null
1018 // WKContextInjectedBundleClient bundleClient = {
1019 // kWKContextInjectedBundleClientCurrentVersion,
1020 // static_cast<void*>(this),
1021 // &didRecieveMessageFromInjectedBundleCallback,
1022 // &didReceiveSynchronousMessageCallback
1024 if (NULL == returnData) {
1025 This->didRecieveMessageFromInjectedBundle(name, body);
1027 This->didReceiveSynchronousMessage(name, body, returnData);
1031 void ViewLogic::didStartDownloadCallback(
1032 const char* downloadUrl,
1035 LogDebug("didStartDownloadCallback called");
1037 ViewLogic* This = static_cast<ViewLogic*>(data);
1038 Assert(downloadUrl);
1039 LogDebug("download url = " << downloadUrl);
1040 This->m_appsSupport->downloadRequest(
1046 void ViewLogic::didStartProvisionalLoadForFrameCallback(
1048 WKFrameRef /*frame*/,
1049 WKTypeRef /*userData*/,
1050 const void *clientInfo)
1052 LogDebug("didStartProvisionalLoadForFrameCallback called");
1054 ViewLogic* This = static_cast<ViewLogic*>(const_cast<void*>(clientInfo));
1055 evas_object_focus_set(This->m_currentEwkView, EINA_TRUE);
1058 void ViewLogic::didFinishLoadForFrameCallback(
1061 WKTypeRef /*userData*/,
1062 const void *clientInfo)
1064 LogDebug("didFinishLoadForFrameCallback called");
1066 ViewLogic* This = static_cast<ViewLogic*>(const_cast<void*>(clientInfo));
1069 DPL::OptionalString urlOptionalString = ViewModule::Utils::toString(frame);
1070 if (urlOptionalString.IsNull()) {
1071 LogError("url is empty");
1073 std::string urlStr = DPL::ToUTF8String(*urlOptionalString).c_str();
1074 DPL::OptionalString jsOptionalString =
1075 ViewModule::PasswordSupport::jsForAutoFillData(urlStr.c_str());
1076 if (jsOptionalString.IsNull()) {
1077 LogError("Fail to get JS String");
1079 std::string jsStr = DPL::ToUTF8String(*jsOptionalString).c_str();
1080 ewk_view_script_execute(
1081 This->m_currentEwkView,
1083 didRunJavaScriptCallback,
1088 // call loadFinish callback to wrt-client
1089 if (This->m_cbs->loadFinish) {
1090 This->m_cbs->loadFinish(true, This->m_cbsData);
1093 // check if 'appsevice' event is registed at the current frames.
1094 // If so, dispatch the event to frames.
1095 PluginModuleSupport::dispatchJavaScriptEvent(
1097 WrtPlugins::W3C::ServiceCustomEvent);
1100 void ViewLogic::didReceiveTitleForFrameCallback(
1103 WKFrameRef /*frame*/,
1104 WKTypeRef /*userData*/,
1105 const void* clientInfo)
1107 LogDebug("didReceiveTitleForFrameCallback called");
1109 ViewLogic* This = static_cast<ViewLogic*>(const_cast<void*>(clientInfo));
1111 DPL::OptionalString titleOptionalString =
1112 ViewModule::Utils::toString(title);
1113 if (titleOptionalString.IsNull()) {
1114 LogDebug("title data is empty");
1118 std::string titleStr = DPL::ToUTF8String(*titleOptionalString);
1119 LogDebug("Title = [" << titleStr << "]");
1121 This->m_schemeSupport->HandleTizenScheme(titleStr.c_str(),
1126 void ViewLogic::didStartProgressCallback(WKPageRef /*page*/,
1127 const void* clientinfo)
1129 LogDebug("didStartProgressCallback");
1131 // TODO : Progress control
1134 void ViewLogic::didChangeProgressCallback(WKPageRef page,
1135 const void* /*clientinfo*/)
1137 double progress = WKPageGetEstimatedProgress(page);
1138 LogDebug("didChangeProgressCallback progress = " << progress);
1141 void ViewLogic::didFinishProgressCallback(WKPageRef /*page*/,
1142 const void* clientinfo)
1144 LogDebug("didFinishProgressCallback");
1145 ViewLogic const * const view = static_cast<ViewLogic const * const>(clientinfo);
1146 if (view->m_cbs->progressFinish)
1147 view->m_cbs->progressFinish(view->m_cbsData);
1150 void ViewLogic::createWindowCallback(
1155 LogDebug("createWindowCallback");
1157 ViewLogic* This = static_cast<ViewLogic*>(data);
1159 Evas_Object* currentEwkView = This->m_currentEwkView;
1161 // suspend current ewkview
1162 /* In case we support many pages in parallel
1163 then view should not be suspended*/
1164 //This->suspendEwkView(currentEwkView);
1166 if (This->m_cbs->bufferUnset) {
1167 This->m_cbs->bufferUnset(currentEwkView, This->m_cbsData);
1170 // create new ewkview
1171 This->createEwkView();
1173 Evas_Object* newEwkView = This->m_currentEwkView;
1175 // initialize new ewkview
1176 This->setStartPage();
1177 This->ewkClientInit(newEwkView);
1178 This->prepareEwkView(newEwkView);
1181 if (This->m_cbs->bufferUnset) {
1182 This->m_cbs->bufferSet(newEwkView, This->m_cbsData);
1184 *(static_cast<Evas_Object **>(eventInfo)) = newEwkView;
1187 void ViewLogic::closeWindowCallback(
1189 Evas_Object* /*obj*/,
1190 void* /*eventInfo*/)
1192 LogDebug("closeWindowCallback");
1193 ecore_idler_add(windowCloseIdlerCallback, data);
1196 void ViewLogic::pageDecidePolicyForResponseCallback(
1199 WKURLResponseRef response,
1200 WKURLRequestRef request,
1201 WKFramePolicyListenerRef listener,
1202 WKTypeRef /*userData*/,
1203 const void* clientInfo)
1206 ViewLogic* This = static_cast<ViewLogic*>(const_cast<void*>(clientInfo));
1209 WKStringRef contentTypeRef = WKURLResponseEflCopyContentType(response);
1210 Assert(contentTypeRef);
1211 if (WKFrameCanShowMIMEType(frame, contentTypeRef)) {
1212 LogDebug("Accepting this content type to be used by WK2");
1213 WKFramePolicyListenerUse(listener);
1214 WKRelease(contentTypeRef);
1219 // get uri information
1220 DPL::OptionalString requestOptionalStr =
1221 ViewModule::Utils::toString(request);
1222 if (requestOptionalStr.IsNull()) {
1223 LogDebug("uri data is empty");
1226 std::string uriStr = DPL::ToUTF8String(*requestOptionalStr).c_str();
1227 const char* uri = uriStr.c_str();
1228 LogDebug("uri = [" << uri << "]");
1230 // get content information
1231 DPL::OptionalString contentOptionalStr =
1232 ViewModule::Utils::toString(contentTypeRef);
1233 std::string contentStr;
1234 if (contentOptionalStr.IsNull()) {
1235 LogDebug("content data is empty");
1237 contentStr = DPL::ToUTF8String(*contentOptionalStr).c_str();
1239 LogDebug("content type = [" << contentStr << "]");
1241 // get cookie information
1242 WKStringRef cookiesRef = WKURLRequestEflCopyCookies(request);
1244 DPL::OptionalString cookiesOptionalStr =
1245 ViewModule::Utils::toString(cookiesRef);
1246 std::string cookieStr;
1247 if (cookiesOptionalStr.IsNull()) {
1248 LogDebug("cookies are empty");
1250 cookieStr = DPL::ToUTF8String(*cookiesOptionalStr).c_str();
1252 LogDebug("cookie = [" << cookieStr << "]");
1254 LogDebug("Content not supported, will be opened in external app");
1255 WKFramePolicyListenerIgnore(listener);
1256 This->m_appsSupport->downloadRequest(
1258 contentStr.empty() ? NULL : contentStr.c_str(),
1259 cookieStr.empty() ? NULL : cookieStr.c_str());
1261 WKRelease(contentTypeRef);
1262 WKRelease(cookiesRef);
1265 void ViewLogic::pageDecidePolicyForNavigationActionCallback(
1268 WKFrameNavigationType /*navigationType*/,
1269 WKEventModifiers /*modifiers*/,
1270 WKEventMouseButton /*mouseButton*/,
1271 WKURLRequestRef request,
1272 WKFramePolicyListenerRef listener,
1273 WKTypeRef /*userData*/,
1274 const void* clientInfo)
1276 LogDebug("Accepting URL: " << ViewModule::Utils::toString(request));
1279 ViewLogic* This = static_cast<ViewLogic*>(const_cast<void*>(clientInfo));
1281 if (This->m_schemeSupport->filterURIByScheme(page,
1289 WKFramePolicyListenerUse(listener);
1293 if(This->m_emptyView)
1296 * The view is empty and scheme has been handled externally. When
1297 * user gets back from the external application he'd see blank page
1298 * and won't be able to navigate back. This happens when window.open
1299 * is used to handle schemes like sms/mms/mailto (for example in
1300 * WAC web standards tests: WS-15XX).
1302 * To solve the problem, the empty view is removed from the stack
1303 * and the previous one is shown. This is not an elegant solution
1304 * but we don't have a better one.
1306 LogInfo("Scheme has been handled externally. Removing empty view.");
1307 if (ewk_view_back_possible(This->m_currentEwkView)) {
1308 // go back to previous WKPage
1309 ewk_view_back(This->m_currentEwkView);
1311 // stop current WKPage
1312 ewk_view_stop(This->m_currentEwkView);
1313 ecore_idler_add(windowCloseIdlerCallback, This);
1317 WKFramePolicyListenerIgnore(listener);
1321 void ViewLogic::pageDecidePolicyForNewWindowActionCallback(
1324 WKFrameNavigationType /*navigationType*/,
1325 WKEventModifiers /*modifiers*/,
1326 WKEventMouseButton /*mouseButton*/,
1327 WKURLRequestRef request,
1328 WKStringRef /*frameName*/,
1329 WKFramePolicyListenerRef listener,
1330 WKTypeRef /*userData*/,
1331 const void* clientInfo)
1333 LogDebug("Accepting URL: " << ViewModule::Utils::toString(request));
1336 ViewLogic* This = static_cast<ViewLogic*>(const_cast<void*>(clientInfo));
1338 if (This->m_schemeSupport->filterURIByScheme(page,
1345 WKFramePolicyListenerUse(listener);
1350 WKFramePolicyListenerIgnore(listener);
1354 void ViewLogic::contextmenuCustomizeCallback(
1356 Evas_Object* /*obj*/,
1359 LogDebug("contextmenuCustomizeCallback called");
1362 ViewLogic* This = static_cast<ViewLogic*>(const_cast<void*>(data));
1363 Ewk_Context_Menu* menu = static_cast<Ewk_Context_Menu*>(eventInfo);
1364 if ((This->m_model->Type.Get().appType == WrtDB::APP_TYPE_TIZENWEBAPP) &&
1365 (This->m_model->SettingList.Get().getContextMenu()
1366 == ContextMenu_Disable))
1368 LogDebug("ContextMenu Disable!!");
1369 for (unsigned int idx = 0; idx < ewk_context_menu_item_count(menu);) {
1370 Ewk_Context_Menu_Item* item = ewk_context_menu_nth_item_get(menu, idx);
1372 ewk_context_menu_item_remove(menu, item);
1375 LogDebug("ContextMenu Enable!!");
1376 for (unsigned int idx = 0; idx < ewk_context_menu_item_count(menu);) {
1377 Ewk_Context_Menu_Item* item = ewk_context_menu_nth_item_get(menu, idx);
1379 Ewk_Context_Menu_Item_Tag tag = ewk_context_menu_item_tag_get(item);
1382 case kWKContextMenuItemTagOpenImageInNewWindow:
1383 ewk_context_menu_item_remove(menu, item);
1393 void ViewLogic::formSubmitCallback(
1395 Evas_Object* /*obj*/,
1398 LogDebug("formSubmitCallback called");
1400 Ewk_Form_Data* formData = static_cast<Ewk_Form_Data*>(eventInfo);
1402 const char* uri = ewk_form_data_url_get(formData);
1404 LogError("URL is empty");
1408 Eina_Hash* userData = ewk_form_data_values_get(formData);
1409 ViewModule::PasswordSupport::submitClicked(uri, userData);
1412 void ViewLogic::geolocationPermissionRequestCallback(
1414 Evas_Object* /*obj*/,
1417 LogDebug("geolocationPermissionRequestCallback called");
1419 ViewModule::GeolocationSupport::Webkit2::
1420 geolocationPermissionRequest(eventInfo);
1424 void ViewLogic::notificationShowCallback(
1426 Evas_Object* /*obj*/,
1429 LogDebug("notificationShowCallback called");
1431 ViewLogic* This = static_cast<ViewLogic*>(data);
1434 Ewk_Notification* noti = static_cast<Ewk_Notification*>(eventInfo);
1436 using namespace ViewModule::WebNotification;
1438 WebNotificationDataPtr notiData(
1439 new WebNotificationData(
1441 ewk_notification_id_get(noti)));
1443 DPL::OptionalString string =
1444 DPL::FromUTF8String(ewk_notification_icon_url_get(noti));
1445 if (!string.IsNull()) {
1446 notiData->m_iconURL = DPL::ToUTF8String(*string);
1448 string = DPL::FromUTF8String(ewk_notification_title_get(noti));
1449 if (!string.IsNull()) {
1450 notiData->m_title = DPL::ToUTF8String(*string);
1452 string = DPL::FromUTF8String(ewk_notification_body_get(noti));
1453 if (!string.IsNull()) {
1454 notiData->m_body = DPL::ToUTF8String(*string);
1457 LogInfo("notification id : " << notiData->m_id);
1458 LogInfo("notification iconURL : " << notiData->m_iconURL);
1459 LogInfo("notification title : " << notiData->m_title);
1460 LogInfo("notification body : " << notiData->m_body);
1462 showWebNotification(notiData);
1463 ewk_notification_showed(This->m_ewkContext, ewk_notification_id_get(noti));
1466 void ViewLogic::notificationCancelCallback(
1468 Evas_Object* /*obj*/,
1469 void* /*eventInfo*/)
1471 LogDebug("notificationCancelCallback called");
1474 void ViewLogic::notificationPermissionRequestCallback(
1476 Evas_Object* /*obj*/,
1479 LogDebug("notificationPermissionRequestCallback called");
1481 ViewLogic* This = static_cast<ViewLogic*>(data);
1484 Ewk_Notification_Permission_Request* request =
1485 static_cast<Ewk_Notification_Permission_Request*>(eventInfo);
1486 ewk_notification_permission_request_response(
1493 void ViewLogic::vibrationVibrateCallback(
1495 Evas_Object* /*obj*/,
1498 LogDebug("vibrationVibrateCallback called");
1500 ViewLogic* This = static_cast<ViewLogic*>(data);
1503 const long vibrationTime = *(static_cast<const long*>(eventInfo));
1504 This->m_vibrationSupport->startVibration(vibrationTime);
1508 void ViewLogic::vibrationCancelCallback(
1510 Evas_Object* /*obj*/,
1511 void* /*eventInfo*/)
1513 LogDebug("vibrationCancelCallback called");
1515 ViewLogic* This = static_cast<ViewLogic*>(data);
1516 This->m_vibrationSupport->stopVibration();
1520 // EWK Orientation Callback
1521 Eina_Bool ViewLogic::orientationLockCallback(
1527 LogDebug("orientationLockCallback called");
1529 ViewLogic* This = static_cast<ViewLogic*>(data);
1531 // current implementation doesn't use lock value
1533 if (orientation & EWK_SCREEN_ORIENTATION_PORTRAIT_PRIMARY) {
1534 LogDebug("orientation is portrait-primary");
1535 elm_win_rotation_with_resize_set(This->m_window, 0);
1536 ewk_view_orientation_send(obj, 0);
1537 } else if(orientation & EWK_SCREEN_ORIENTATION_LANDSCAPE_PRIMARY) {
1538 LogDebug("orientation is landscape-primary");
1539 elm_win_rotation_with_resize_set(This->m_window, 270);
1540 ewk_view_orientation_send(obj, 90);
1541 } else if(orientation & EWK_SCREEN_ORIENTATION_PORTRAIT_SECONDARY) {
1542 LogDebug("orientation is portrait-secondary");
1543 elm_win_rotation_with_resize_set(This->m_window, 180);
1544 ewk_view_orientation_send(obj, 180);
1545 } else if(orientation & EWK_SCREEN_ORIENTATION_LANDSCAPE_SECONDARY) {
1546 LogDebug("orientation is landscape-secondary");
1547 elm_win_rotation_with_resize_set(This->m_window, 90);
1548 ewk_view_orientation_send(obj, -90);
1550 LogDebug("Wrong orientation is set");
1556 void ViewLogic::didRunJavaScriptCallback(
1557 Evas_Object* /*obj*/,
1561 LogInfo("didRunJavaScriptCallback called");
1562 LogInfo("result = " << result);
1565 void ViewLogic::backButtonCallback(void* data,
1566 Evas_Object * /*obj*/,
1567 void * /*event_info*/)
1569 LogInfo("BackButtonCallback");
1572 ViewLogic* This = static_cast<ViewLogic*>(data);
1574 if (WKPageCanGoBack(ewk_view_WKPage_get(This->m_currentEwkView))) {
1575 WKPageGoBack(ewk_view_WKPage_get(This->m_currentEwkView));
1577 if (1 >= This->m_ewkViewList.size()) {
1578 // If there is no previous page, widget move to backgroud.
1579 LogInfo("Widget move to backgroud");
1580 elm_win_lower(This->m_window);
1582 // Back to previous webview
1583 LogInfo("Widget move to previous webview");
1584 ecore_idler_add(windowCloseIdlerCallback, This);
1589 Eina_Bool ViewLogic::windowCloseIdlerCallback(void* data)
1591 LogDebug("closeIdlerCallback");
1592 ViewLogic* This = static_cast<ViewLogic*>(data);
1593 This->windowClose();
1594 return ECORE_CALLBACK_CANCEL;
1597 void ViewLogic::processDidCrashCallback(WKPageRef /*page*/,
1598 const void* clientInfo)
1600 LogInfo("processDidCrashCallback");
1602 ViewLogic const * const view =
1603 static_cast<ViewLogic const * const>(clientInfo);
1604 if (view->m_cbs->webCrash) {
1605 view->m_cbs->webCrash(view->m_cbsData);
1609 int ViewLogic::appcoreLowMemoryCallback(void *data)
1611 LogInfo("appcoreLowMemoryCallback");
1613 ViewLogic* This = static_cast<ViewLogic*>(data);
1615 if (NULL == This->m_ewkContext) {
1616 LogInfo("ewk isn't initialize at this moment");
1618 ewk_context_cache_clear(This->m_ewkContext);
1619 ewk_context_notify_low_memory(This->m_ewkContext);
1625 void ViewLogic::didRecieveMessageFromInjectedBundle(
1627 const char* /*body*/)
1629 LogDebug("did recive message " << name);
1632 void ViewLogic::didReceiveSynchronousMessage(
1637 LogDebug("didReceiveSynchronousMessage called");
1642 LogDebug("body is empty");
1646 if (!strcmp(name, willSendMessageName)) {
1647 LogDebug("received : " << willSendMessageName);
1649 bool is_xhr = true; //Webkit2 should inform if it is xhr
1650 DPL::OptionalString ret =
1651 requestWillSend(DPL::FromUTF8String(body), is_xhr);
1653 LogError("Wrong type received");
1656 LogDebug("returning uri: " << ret);
1657 *returnData = strdup(DPL::ToUTF8String(*ret).c_str());
1659 } else if (!strcmp(name, uriChangedMessageName)) {
1660 LogDebug("received : " << uriChangedMessageName);
1661 std::string ret = requestUriChanged(DPL::FromUTF8String(body));
1662 *returnData = strdup(ret.c_str());
1666 DPL::Optional<DPL::String> ViewLogic::requestWillSend(
1667 const DPL::String& inputURI,
1670 DPL::Optional<DPL::String> uri =
1671 ViewModule::UriSupport::localizeURI(inputURI, m_model);
1675 LogDebug("uri is empty");
1680 if (!ViewModule::SecuritySupport::filterURIBySecurity(uri, is_xhr, m_model))
1682 // set blocked uri to open browser later
1683 m_blockedUri = DPL::ToUTF8String(*uri);
1684 LogInfo("set blocked uri to open browser later : " << m_blockedUri);
1685 return DPL::Optional<DPL::String>::Null;
1688 // check roaming state for external scheme
1689 if (m_model->Type.Get().appType == WrtDB::APP_TYPE_TIZENWEBAPP)
1691 LogInfo("TizenWebApp does not need to check roaming status!");
1693 else if (!ViewModule::SecuritySupport::filterURIByRoaming(uri))
1695 LogDebug("Request was blocked by roaming settings: " << uri);
1696 return DPL::Optional<DPL::String>::Null;
1702 std::string ViewLogic::requestUriChanged(const DPL::String& changedURL)
1704 using namespace ViewModule::SecuritySupport;
1706 std::string url = DPL::ToUTF8String(changedURL);
1707 LogInfo("URL = [" << url << "]");
1708 m_emptyView = false;
1711 // If url is same to URICHANGE_BLOCKED_URL,
1712 // this url has been already blocked by willsend.
1713 // So current page should be moved to previous page
1714 if (url == URICHANGE_BLOCKED_URL)
1716 if (m_model->Type.Get().appType == WrtDB::APP_TYPE_TIZENWEBAPP)
1718 // block this page and open it in browser
1719 LogDebug("Request was blocked by WARP: " << url.c_str());
1720 if (!m_blockedUri.empty()) {
1721 LogDebug("open browser : " << m_blockedUri);
1722 bundle* bundleData = bundle_create();
1723 appsvc_set_operation(bundleData, APPSVC_OPERATION_VIEW);
1724 appsvc_set_uri(bundleData, m_blockedUri.c_str());
1725 CONTROLLER_POST_EVENT(
1726 ApplicationLauncher,
1727 ApplicationLauncherEvents::LaunchApplicationByAppService(
1731 m_blockedUri = std::string();
1734 if (ewk_view_back_possible(m_currentEwkView)) {
1735 // go back to previous WKPage
1736 ewk_view_back(m_currentEwkView);
1738 // stop current WKPage
1739 ewk_view_stop(m_currentEwkView);
1740 ecore_idler_add(windowCloseIdlerCallback, this);
1743 // This is used in case of returning previous page
1745 return URICHANGE_PLUGIN_NO_CHANGE;
1750 // Check if this url with 'http' or 'https' is included in whitelist,
1751 // which has lists of accessible external documents and
1752 // used for ONLY Tizen app
1753 std::string matchedScheme;
1754 std::string matchedUri;
1755 pcrecpp::RE(PATTERN_URI_CHANGE).PartialMatch(url.c_str(),
1758 ViewModule::Scheme scheme(matchedScheme);
1759 if (scheme.GetType() == ViewModule::Scheme::HTTP ||
1760 scheme.GetType() == ViewModule::Scheme::HTTPS)
1762 if (m_model->Type.Get().appType == WrtDB::APP_TYPE_TIZENWEBAPP) {
1763 if (!checkWhitelist(url.c_str())) {
1764 LogInfo("This uri is not included in white document list");
1765 return URICHANGE_PLUGIN_STOP_ONLY;
1767 LogInfo("This url is included in WhiteList");
1769 // For WAC app, WRT should block access of device api
1770 // for external documents
1771 return URICHANGE_PLUGIN_STOP_ONLY;
1775 // register javascript object for plugins to be used
1776 LogInfo("Register Plugin Objects");
1777 return URICHANGE_PLUGIN_RESTART;
1780 void ViewLogic::disconnectNetworkConnectionsFunction() {
1782 LogDebug("disconnection network connections");
1783 // API needs Ewk_context
1784 // Re-open after merged below commit
1785 // http://slp-info.sec.samsung.net/gerrit/#change,48358
1786 // ewk_context_network_session_requests_cancel(m_ewkContext);
1790 void ViewLogic::windowClose()
1792 LogDebug("windowClose");
1794 if (1 >= m_ewkViewList.size()) {
1795 if (m_cbs->windowClose) {
1796 m_cbs->windowClose(m_cbsData);
1799 // hide current ewkView
1801 if (m_cbs->bufferUnset) {
1802 m_cbs->bufferUnset(m_currentEwkView, m_cbsData);
1804 removeEwkView(m_currentEwkView);
1806 // get latest ewkView
1807 m_currentEwkView = m_ewkViewList.back();
1808 WKPageRef page = ewk_view_WKPage_get(m_currentEwkView);
1809 WKFrameRef frame = WKPageGetMainFrame(page);
1811 DPL::OptionalString frameURL = ViewModule::Utils::toString(frame);
1812 if (frameURL.IsNull()) {
1813 m_currentUri.clear();
1816 m_currentUri = DPL::ToUTF8String(*frameURL);
1817 m_emptyView = false;
1821 /* In case we support many pages in parallel
1822 then view is not suspended*/
1823 //resumeEwkView(m_currentEwkView);
1826 if (m_cbs->bufferSet) {
1827 m_cbs->bufferSet(m_currentEwkView, m_cbsData);