/wrt/src/view/webkit/view_logic.cpp
C++ | 1830 lines | 1306 code | 190 blank | 334 comment | 132 complexity | b0f03fc76f558aeab3e1a074adeffe8b MD5 | raw file
Possible License(s): GPL-3.0, AGPL-3.0, GPL-2.0, MPL-2.0, JSON, WTFPL, CC-BY-SA-4.0, CC-BY-3.0, BSD-3-Clause, LGPL-2.0, MPL-2.0-no-copyleft-exception, AGPL-1.0, 0BSD, Zlib, Unlicense, BSD-2-Clause, Apache-2.0, LGPL-3.0, ISC, MIT, CC-BY-SA-3.0, CC0-1.0, LGPL-2.1
- /*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- /**
- * @file view_logic.cpp
- * @author Pawel Sikorski (p.sikorsk@samsung.com)
- * @author Lukasz Wrzosek (l.wrzosek@samsung.com)
- * @author Yunchan Cho (yunchan.cho@samsung.com)
- * @brief View logic for Webkit2
- */
- #include "view_logic.h"
- #include <cstring>
- #include <string>
- #include <dpl/assert.h>
- #include <dpl/log/log.h>
- #include <dpl/optional.h>
- #include <dpl/string.h>
- #include <appcore-common.h>
- #include <pcrecpp.h>
- #include <widget_model.h>
- #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
- #include <common/application_data.h>
- #include <common/application_launcher.h>
- #include <common/scheme.h>
- #include <common/roaming_agent.h>
- #include <common/view_logic_apps_support.h>
- #include <common/view_logic_custom_header_support.h>
- #include <common/view_logic_password_support.h>
- #include <common/view_logic_security_support.h>
- #include <common/view_logic_storage_support.h>
- #include <common/view_logic_uri_support.h>
- #include <common/view_logic_user_agent_support.h>
- #include <common/view_logic_vibration_support.h>
- #include <common/view_logic_web_notification_support.h>
- #include <view_logic_scheme_support.h>
- #include "view_logic_geolocation_support_webkit2.h"
- #include "view_logic_utils.h"
- #include "bundles/plugin_module_support.h"
- #include <ewk_context.h>
- #include <ewk_context_menu.h>
- #include <ewk_form_data.h>
- #include <ewk_network.h>
- #include <ewk_notification.h>
- #include <ewk_view.h>
- #include <ewk_setting.h>
- #include <WebKit2.h>
- #include <WKPage.h>
- #include <WKContextMenuItem.h>
- #include <WKURLResponseEfl.h>
- #include <WKURLRequestEfl.h>
- #include <js_overlay_types.h>
- #include <i_runnable_widget_object.h>
- namespace {
- const char * const bundlePath = "/usr/lib/wrt-wk2-bundles/libwrt-wk2-bundle.so";
- const char * const willSendMessageName = "will_send_msg";
- const char * const uriChangedMessageName = "uri_changed_msg";
- const char * const URICHANGE_PLUGIN_STOP_ONLY = "plugin_stop_only";
- const char * const URICHANGE_PLUGIN_RESTART = "plugin_restart";
- const char * const URICHANGE_PLUGIN_NO_CHANGE = "plugin_no_change";
- const char * const URICHANGE_BLOCKED_URL = "null";
- const char* PATTERN_URI_CHANGE = "^(([^:/\\?#]+)://[^\\?#]*)";
- const int MAX_NUM_CONTEXT_MENU_ITEMS = 10;
- // ewk callback
- const char * const EWK_CREATE_WINDOW = "create,window";
- const char * const EWK_CLOSE_WINDOW = "close,window";
- const char * const EWK_CONTEXTMENU_CUSTOMIZE = "contextmenu,customize";
- const char * const EWK_FORM_SUBMIT = "form,submit";
- const char * const EWK_REQUEST_GEOLOCATION_PERMISSION =
- "request,geolocation,permission";
- const char * const EWK_NOTIFICATION_SHOW = "notification,show";
- const char * const EWK_NOTIFICATION_CANCEL = "notification,cancel";
- const char * const EWK_NOTIFICATION_PERMISSION_REQUEST =
- "notification,permission,request";
- const char * const EWK_VIBRATION_VIBRATE = "vibration,vibrate";
- const char * const EWK_VIBRATION_CANCEL = "vibration,cancel";
- }
- void ViewLogic::createWebView(Ewk_Context* context,
- Evas_Object* window)
- {
- LogDebug("");
- initializeEwkContext(context);
- Assert(NULL != m_ewkContext);
- Assert(window);
- m_window = window;
- createEwkView();
- }
- void ViewLogic::destroyWebView()
- {
- if (m_ewkContext) {
- finalizeEwkContext();
- }
- }
- void ViewLogic::initialize()
- {
- LogDebug("Initializing");
- ApplicationLauncherSingleton::Instance().Touch();
- appcore_set_event_callback(
- APPCORE_EVENT_LOW_MEMORY,
- &appcoreLowMemoryCallback,
- this);
- }
- void ViewLogic::terminate()
- {
- LogDebug("terminating view logic");
- if (m_model) {
- hideWidget();
- } else {
- LogError("Widget model not created");
- }
- LogDebug("done");
- }
- void ViewLogic::prepareView(WidgetModel* m, const std::string &startUrl)
- {
- LogDebug("View prepare");
- Assert(m);
- m_model = m;
- m_startUrl = ViewModule::UriSupport::getUri(m_model, startUrl);
- Assert(NULL != m_ewkContext);
- Assert(m_window);
- initializeSupport();
- setStartPage();
- ewkClientInit(m_currentEwkView);
- prepareEwkView(m_currentEwkView);
- initializePluginLoading();
- }
- void ViewLogic::initializePluginLoading()
- {
- // inform wrt information for plugin loading to web process
- PluginModuleSupport::start(
- m_ewkContext,
- m_model->Handle.Get(),
- elm_config_scale_get(),
- ApplicationDataSingleton::Instance().getEncodedBundle(),
- m_theme.c_str(),
- m_model->SettingList.Get().isEncrypted());
- }
- void ViewLogic::initializeSupport()
- {
- // set local stroage database path
- WrtDB::WidgetDAOReadOnly dao(m_model->Handle.Get());
- ewk_context_web_storage_path_set(m_ewkContext,
- dao.getPrivateLocalStoragePath().c_str());
- m_schemeSupport.reset(new SchemeSupport(m_model->Type.Get().appType));
- ViewModule::StorageSupport::initializeStorage(m_model);
- m_appsSupport->initialize(m_model);
- m_vibrationSupport->initialize();
- ViewModule::GeolocationSupport::Webkit2::initialize(m_model->Handle.Get());
- ViewModule::GeolocationSupport::Webkit2::
- adjustGeolocationModuleState(m_currentEwkView);
- }
- void ViewLogic::showWidget()
- {
- LogDebug("showing widget");
- Assert(NULL != m_currentEwkView && "ewk_view not created at this point");
- if (m_currentUri.empty()) {
- LogError("Localized current URI doesn't exist");
- return;
- }
- LogInfo("m_currentUri: " << m_currentUri);
- RoamingAgentSingleton::Instance().setDisconnectCallback(
- DPL::MakeDelegate(this,
- &ViewLogic::disconnectNetworkConnectionsFunction));
- // load page
- WKURLRef baseUrl = WKURLCreateWithUTF8CString(
- m_currentUri.c_str());
- if (!baseUrl) {
- LogError("URL creation failed");
- return;
- }
- WKPageLoadURL(ewk_view_WKPage_get(m_currentEwkView), baseUrl);
- WKRelease(baseUrl);
- if (m_cbs->bufferSet) {
- m_cbs->bufferSet(m_currentEwkView, m_cbsData);
- }
- }
- void ViewLogic::hideWidget()
- {
- LogDebug("hiding widget");
- RoamingAgentSingleton::Instance().unsetDisconnectCallback();
- ViewModule::StorageSupport::deinitializeStorage(m_model);
- m_appsSupport->deinitialize();
- m_vibrationSupport->deinitialize();
- // almost terminate time spends for terminate webkit.
- // after block this evas_object_del code, webkit will be destoryed
- // with parent evas_object(~WindowData())
- //FOREACH(it, m_ewkViewList) {
- // evas_object_del(*it);
- //}
- m_ewkViewList.clear();
- }
- void ViewLogic::suspendWidget()
- {
- LogInfo("Pausing widget");
- Assert(m_model);
- if (!m_currentEwkView) {
- LogWarning("Cannot suspend widget without view");
- } else {
- suspendWebkit(m_currentEwkView);
- }
- // call user callback
- if (m_cbs->suspend) {
- m_cbs->suspend(true, m_cbsData);
- }
- };
- void ViewLogic::resumeWidget()
- {
- LogInfo("Resume widget");
- Assert(m_model);
- if (m_currentEwkView) {
- resumeWebkit(m_currentEwkView);
- }
- if (m_window) {
- elm_win_activate(m_window);
- }
- evas_object_focus_set(m_currentEwkView, EINA_TRUE);
- // call user callback
- if (m_cbs->resume) {
- m_cbs->resume(true, m_cbsData);
- }
- };
- void ViewLogic::resetWidget()
- {
- LogInfo("Resetting Widget");
- // check if already created webview exists
- if (!m_ewkViewList.size()) {
- // create new webview
- createEwkView();
- setStartPage();
- ewkClientInit(m_currentEwkView);
- prepareEwkView(m_currentEwkView);
- } else {
- bundle *bundle = ApplicationDataSingleton::Instance().getBundle();
- const char *operation = appsvc_get_operation(bundle);
- LogInfo("operation : " << operation);
- if (operation &&
- !strcmp(operation, APPSVC_OPERATION_DEFAULT)) {
- // ignore default operation that is reserved by system
- // just activate current window
- LogInfo("raise window");
- elm_win_raise(m_window);
- resumeWebkit(m_currentEwkView);
- return;
- }
- // check if current url is service url for this tizen service
- std::string requestedUri =
- ViewModule::UriSupport::getUri(m_model, m_startUrl);
- DPL::OptionalString servicedUri = ViewModule::UriSupport::localizeURI(
- DPL::FromUTF8String(requestedUri.c_str()),
- m_model);
- if (m_currentUri == DPL::ToUTF8String(*servicedUri)) {
- // set only encoded bundle
- double scale = elm_config_scale_get();
- PluginModuleSupport::setCustomProperties(
- m_ewkContext,
- &scale,
- ApplicationDataSingleton::Instance().getEncodedBundle());
- // dispatch 'appservice' js event
- PluginModuleSupport::dispatchJavaScriptEvent(
- m_ewkContext,
- WrtPlugins::W3C::ServiceCustomEvent);
- // window activate
- if (m_window) {
- elm_win_raise(m_window);
- }
- resumeWebkit(m_currentEwkView);
- return;
- } else {
- m_currentUri = DPL::ToUTF8String(*servicedUri);
- }
- }
- // inform wrt information for plugin loading to web process
- PluginModuleSupport::start(
- m_ewkContext,
- m_model->Handle.Get(),
- elm_config_scale_get(),
- ApplicationDataSingleton::Instance().getEncodedBundle(),
- m_theme.c_str(),
- m_model->SettingList.Get().isEncrypted());
- // load page
- WKURLRef baseUrl = WKURLCreateWithUTF8CString(
- m_currentUri.c_str());
- if (!baseUrl) {
- LogError("URL creation failed");
- return;
- }
- WKPageLoadURL(ewk_view_WKPage_get(m_currentEwkView), baseUrl);
- WKRelease(baseUrl);
- resumeWebkit(m_currentEwkView);
- // call user callback
- if (m_cbs->reset) {
- m_cbs->reset(true, m_cbsData);
- }
- if (m_cbs->bufferSet) {
- m_cbs->bufferSet(m_currentEwkView, m_cbsData);
- }
- }
- void ViewLogic::goBack()
- {
- if (WKPageCanGoBack(ewk_view_WKPage_get(m_currentEwkView))) {
- WKPageGoBack(ewk_view_WKPage_get(m_currentEwkView));
- } else {
- if (1 >= m_ewkViewList.size()) {
- // If there is no previous page, widget move to backgroud.
- LogInfo("Widget move to backgroud");
- elm_win_lower(m_window);
- } else {
- // Back to previous webview
- LogInfo("Widget move to previous webview");
- ecore_idler_add(windowCloseIdlerCallback, this);
- }
- }
- }
- Evas_Object* ViewLogic::getCurrentWebview()
- {
- LogInfo("get current webview");
- return m_currentEwkView;
- }
- void ViewLogic::setUserCallbacks(WRT::UserCallbacksPtr cbs, void *data)
- {
- m_cbs = cbs;
- m_cbsData = data;
- }
- void ViewLogic::initializeEwkContext(Ewk_Context* newEwkContext)
- {
- LogInfo("initializeEwkContext called");
- Assert(newEwkContext && "Ewk_Context provided can not be null");
- // bundle callback setting
- ewk_context_message_from_injected_bundle_callback_set(
- newEwkContext,
- contextMessageFromInjectedBundleCallback,
- static_cast<void*>(this));
- // proxy server setting
- char *proxyAddress = vconf_get_str(VCONFKEY_NETWORK_PROXY);
- if ((!proxyAddress) || (strlen(proxyAddress) == 0)
- || (strstr(proxyAddress, "0.0.0.0")))
- {
- LogInfo("proxy address is empty");
- ewk_context_proxy_uri_set(newEwkContext, NULL);
- } else {
- LogInfo("proxy address [" << proxyAddress << "]");
- ewk_context_proxy_uri_set(newEwkContext, proxyAddress);
- }
- if (proxyAddress) {
- free(proxyAddress);
- proxyAddress = NULL;
- }
- // theme setting
- const char *theme = elm_theme_get(NULL);
- if (theme) {
- m_theme = theme;
- LogInfo("theme is " << m_theme);
- }
- // set download callback
- //WKContextDownloadClient downloadClient = {
- // kWKContextDownloadClientCurrentVersion,
- // ewkContext,
- // didStartDownload,
- // 0, // didReceiveAuthenticationChallenge
- // 0, // didReceiveResponse
- // 0, // didReceiveData
- // 0, // shouldDecodeSourceDataOfMIMEType
- // 0, // decideDestinationWithSuggestedFilename
- // 0, // didCreateDestination
- // 0, // didFinish
- // 0, // didFail
- // 0, // didCancel
- // 0 // processDidCrash
- // };
- // WKContextSetDownloadClient(newEwkContext, &downloadClient);
- ewk_context_did_start_download_callback_set(
- newEwkContext,
- didStartDownloadCallback,
- this);
- // set to member value
- m_ewkContext = newEwkContext;
- }
- void ViewLogic::finalizeEwkContext()
- {
- LogInfo("finalizeEwkContext called");
- ewk_context_delete(m_ewkContext);
- m_ewkContext = 0;
- }
- ViewLogic::ViewLogic():
- m_ewkContext(0),
- m_currentEwkView(0),
- m_model(0),
- m_emptyView(false),
- m_appsSupport(new ViewModule::AppsSupport()),
- m_vibrationSupport(new ViewModule::VibrationSupport()),
- m_window(NULL),
- m_cbs(new WRT::UserCallbacks),
- m_cbsData(NULL)
- {
- }
- ViewLogic::~ViewLogic ()
- {
- }
- void ViewLogic::ewkClientInit(Evas_Object *wkView) {
- Assert(NULL != wkView && "ewk_view not created at this point");
- ViewModule::GeolocationSupport::Webkit2::
- initialize(m_model->Handle.Get());
- WKPageLoaderClient loaderClient = {
- kWKPageLoaderClientCurrentVersion, /* version */
- static_cast<void*>(this), /* clientinfo */
- didStartProvisionalLoadForFrameCallback, /* didStartProvisionalLoadForFrame */
- 0, /* didReceiveServerRedirectForProvisionalLoadForFrame */
- 0, /* didFailProvisionalLoadWithErrorForFrame */
- 0, /* didCommitLoadForFrame */
- 0, /* didFinishDocumentLoadForFrame */
- didFinishLoadForFrameCallback, /* didFinishLoadForFrame */
- 0, /* didFailLoadWithErrorForFrame */
- 0, /* didSameDocumentNavigationForFrame */
- didReceiveTitleForFrameCallback, /* didReceiveTitleForFrame */
- 0, /* didFirstLayoutForFrame */
- 0, /* didFirstVisuallyNonEmptyLayoutForFrame */
- 0, /* didRemoveFrameFromHierarchy */
- 0, /* didDisplayInsecureContentForFrame */
- 0, /* didRunInsecureContentForFrame */
- 0, /* canAuthenticateAgainstProtectionSpaceInFrame */
- 0, /* didReceiveAuthenticationChallengeInFrame */
- didStartProgressCallback, /* didStartProgressCallback */
- didChangeProgressCallback, /* didChangeProgress */
- didFinishProgressCallback, /* didFinishProgress */
- 0, /* processDidBecomeUnresponsive */
- 0, /* processDidBecomeResponsive */
- processDidCrashCallback, /* processDidCrash */
- 0, /* didChangeBackForwardList */
- 0, /* shouldGoToBackForwardListItem */
- 0, /* didFailToInitializePlugin */
- 0, /* didDetectXSSForFrame */
- 0, /* didNewFirstVisuallyNonEmptyLayout */
- 0, /* willGoToBackForwardListItem */
- 0, /* interactionOccurredWhileProcessUnresponsive */
- 0, /* pluginDidFail */
- };
- WKPageSetPageLoaderClient(ewk_view_WKPage_get(wkView), &loaderClient);
- //WKPageUIClient uiClient = {
- // kWKPageUIClientCurrentVersion, /* version */
- // static_cast<void*>(this), /* clientInfo */
- // 0, /* createNewPage_deprecatedForUseWithV0 */
- // 0, /* showPage*/
- // closeCallback, /* close */
- // 0, /* takeFocus */
- // 0, /* focus */
- // 0, /* unfocus */
- // 0, /* runJavaScriptAlert */
- // 0, /* runJavaScriptConfirm */
- // 0, /* runJavaScriptPrompt */
- // 0, /* setStatusText */
- // 0, /* mouseDidMoveOverElement */
- // 0, /* missingPluginButtonClicked */
- // 0, /* didNotHandleKeyEvent */
- // 0, /* didNotHandleWheelEvent */
- // 0, /* toolbarsAreVisible */
- // 0, /* setToolbarsAreVisible */
- // 0, /* menuBarIsVisible */
- // 0, /* setMenuBarIsVisible */
- // 0, /* statusBarIsVisible */
- // 0, /* setStatusBarIsVisible */
- // 0, /* isResizable */
- // 0, /* setIsResizable */
- // 0, /* getWindowFrame */
- // 0, /* setWindowFrame */
- // 0, /* runBeforeUnloadConfirmPanel */
- // 0, /* didDraw */
- // 0, /* pageDidScroll */
- // 0, /* exceededDatabaseQuota */
- // 0, /* runOpenPanel */
- // decidePolicyForGeolocationPermissionRequestCallback, /* decidePolicyForGeolocationPermissionRequest */
- // 0, /* headerHeight */
- // 0, /* footerHeight */
- // 0, /* drawHeader */
- // 0, /* drawFooter */
- // 0, /* printFrame */
- // 0, /* runModal */
- // 0, /* didCompleteRubberBandForMainFrame */
- // 0, /* saveDataToFileInDownloadsFolder */
- // 0, /* shouldInterruptJavaScript */
- // createNewPageCallback, /* createNewPage */
- // 0, /* mouseDidMoveOverElement */
- // decidePolicyForNotificationPermissionRequestCallback, /* decidePolicyForNotificationPermissionRequest */
- //};
- //WKPageSetPageUIClient(ewk_view_page_get(wkView), &uiClient);
- evas_object_smart_callback_add(
- wkView,
- EWK_CREATE_WINDOW,
- createWindowCallback,
- this);
- evas_object_smart_callback_add(
- wkView,
- EWK_CLOSE_WINDOW,
- closeWindowCallback,
- this);
- WKPagePolicyClient policyClient = {
- kWKPagePolicyClientCurrentVersion, /* version */
- static_cast<void*>(this), /* clientInfo */
- pageDecidePolicyForNavigationActionCallback, /* decidePolicyForNavigationAction */
- pageDecidePolicyForNewWindowActionCallback, /* decidePolicyForNewWindowAction */
- pageDecidePolicyForResponseCallback,
- 0, /* unableToImplementPolicy */
- };
- WKPageSetPagePolicyClient(ewk_view_WKPage_get(wkView),
- &policyClient);
- // EWK ContextMenu Callback
- //WKPageContextMenuClient contextMenuClient = {
- // kWKPageContextMenuClientCurrentVersion, /* version */
- // static_cast<void*>(this), /* clientInfo */
- // 0, /* getContextMenuFromProposedMenu_deprecatedForUseWithV0 */
- // 0, /* customContextMenuItemSelected */
- // 0, /* contextMenuDismissed */
- // pageContextMenuForGetMenuCallback /* getContextMenuFromProposedMenu */
- //};
- //WKPageSetPageContextMenuClient(ewk_view_page_get(wkView),
- // &contextMenuClient);
- evas_object_smart_callback_add(
- wkView,
- EWK_CONTEXTMENU_CUSTOMIZE,
- contextmenuCustomizeCallback,
- this);
- // WKPageFormClient formClient = {
- // kWKPageFormClientCurrentVersion, /* version */
- // static_cast<void*>(this), /* clientInfo */
- // willSubmitFormCallback, /* willSubmitForm */
- // };
- // WKPageSetPageFormClient(ewk_view_page_get(wkView), &formClient);
- evas_object_smart_callback_add(
- wkView,
- EWK_FORM_SUBMIT,
- formSubmitCallback,
- this);
- // EWK Geolocation Callback
- //WKGeolocationProvider geolocation_provider = {
- // kWKGeolocationProviderCurrentVersion,
- // this,
- // startUpdatingCallback,
- // stopUpdatingCallback
- //};
- //WKGeolocationManagerRef geolocation_manager_ref
- // = WKContextGetGeolocationManager(m_wkctx);
- //WKGeolocationManagerSetProvider(geolocation_manager_ref,
- // &geolocation_provider);
- evas_object_smart_callback_add(
- wkView,
- EWK_REQUEST_GEOLOCATION_PERMISSION,
- geolocationPermissionRequestCallback,
- this);
- // EWK Notification Callback
- //WKNotificationProvider notificationProvider = {
- // kWKNotificationProviderCurrentVersion, /* version */
- // static_cast<void*>(this), /* clientinfo */
- // showNotificationCallback, /* show */
- // 0, /* cancel */
- // 0, /* didDestroyNotification */
- // 0, /* addNotificationManager */
- // 0, /* removeNotificationManager */
- // 0, /* notificationPermissions */
- // 0, /* clearNotifications */
- //};
- //WKNotificationManagerSetProvider(WKContextGetNotificationManager(m_wkctx),
- // ¬ificationProvider);
- evas_object_smart_callback_add(
- wkView,
- EWK_NOTIFICATION_SHOW,
- notificationShowCallback,
- this);
- evas_object_smart_callback_add(
- wkView,
- EWK_NOTIFICATION_CANCEL,
- notificationCancelCallback,
- this);
- evas_object_smart_callback_add(
- wkView,
- EWK_NOTIFICATION_PERMISSION_REQUEST,
- notificationPermissionRequestCallback,
- this);
- evas_object_smart_callback_add(
- wkView,
- EWK_VIBRATION_VIBRATE,
- vibrationVibrateCallback,
- this);
- evas_object_smart_callback_add(
- wkView,
- EWK_VIBRATION_CANCEL,
- vibrationCancelCallback,
- this);
- // EWK Orientation Callback
- ewk_view_orientation_lock_callback_set(
- wkView,
- orientationLockCallback,
- this);
- }
- void ViewLogic::ewkClientDeinit(Evas_Object *wkView) {
- LogDebug("ewkClientDeinit");
- Assert(NULL != wkView && "ewk_view not created at this point");
- // deinit WKPageLoaderClient
- WKPageLoaderClient loaderClient = {
- 0, /* version */
- 0, /* clientinfo */
- 0, /* didStartProvisionalLoadForFrame */
- 0, /* didReceiveServerRedirectForProvisionalLoadForFrame */
- 0, /* didFailProvisionalLoadWithErrorForFrame */
- 0, /* didCommitLoadForFrame */
- 0, /* didFinishDocumentLoadForFrame */
- 0, /* didFinishLoadForFrame */
- 0, /* didFailLoadWithErrorForFrame */
- 0, /* didSameDocumentNavigationForFrame */
- 0, /* didReceiveTitleForFrame */
- 0, /* didFirstLayoutForFrame */
- 0, /* didFirstVisuallyNonEmptyLayoutForFrame */
- 0, /* didRemoveFrameFromHierarchy */
- 0, /* didDisplayInsecureContentForFrame */
- 0, /* didRunInsecureContentForFrame */
- 0, /* canAuthenticateAgainstProtectionSpaceInFrame */
- 0, /* didReceiveAuthenticationChallengeInFrame */
- 0, /* didStartProgressCallback */
- 0, /* didChangeProgress */
- 0, /* didFinishProgress */
- 0, /* processDidBecomeUnresponsive */
- 0, /* processDidBecomeResponsive */
- 0, /* processDidCrash */
- 0, /* didChangeBackForwardList */
- 0, /* shouldGoToBackForwardListItem */
- 0, /* didFailToInitializePlugin */
- 0, /* didDetectXSSForFrame */
- 0, /* didNewFirstVisuallyNonEmptyLayout */
- 0, /* willGoToBackForwardListItem */
- 0, /* interactionOccurredWhileProcessUnresponsive */
- 0, /* pluginDidFail */
- };
- WKPageSetPageLoaderClient(ewk_view_WKPage_get(wkView),
- &loaderClient);
- // deinit WKPageUIClient
- //WKPageUIClient uiClient = {
- // 0, /* version */
- // 0, /* clientInfo */
- // 0, /* createNewPage_deprecatedForUseWithV0 */
- // 0, /* showPage*/
- // 0, /* close */
- // 0, /* takeFocus */
- // 0, /* focus */
- // 0, /* unfocus */
- // 0, /* runJavaScriptAlert */
- // 0, /* runJavaScriptConfirm */
- // 0, /* runJavaScriptPrompt */
- // 0, /* setStatusText */
- // 0, /* mouseDidMoveOverElement */
- // 0, /* missingPluginButtonClicked */
- // 0, /* didNotHandleKeyEvent */
- // 0, /* didNotHandleWheelEvent */
- // 0, /* toolbarsAreVisible */
- // 0, /* setToolbarsAreVisible */
- // 0, /* menuBarIsVisible */
- // 0, /* setMenuBarIsVisible */
- // 0, /* statusBarIsVisible */
- // 0, /* setStatusBarIsVisible */
- // 0, /* isResizable */
- // 0, /* setIsResizable */
- // 0, /* getWindowFrame */
- // 0, /* setWindowFrame */
- // 0, /* runBeforeUnloadConfirmPanel */
- // 0, /* didDraw */
- // 0, /* pageDidScroll */
- // 0, /* exceededDatabaseQuota */
- // 0, /* runOpenPanel */
- // 0, /* decidePolicyForGeolocationPermissionRequest */
- // 0, /* headerHeight */
- // 0, /* footerHeight */
- // 0, /* drawHeader */
- // 0, /* drawFooter */
- // 0, /* printFrame */
- // 0, /* runModal */
- // 0, /* didCompleteRubberBandForMainFrame */
- // 0, /* saveDataToFileInDownloadsFolder */
- // 0, /* shouldInterruptJavaScript */
- // 0, /* createNewPage */
- // 0, /* mouseDidMoveOverElement */
- // 0, /* decidePolicyForNotificationPermissionRequest */
- //};
- //WKPageSetPageUIClient(ewk_view_page_get(wkView), &uiClient);
- evas_object_smart_callback_del(
- wkView,
- EWK_CREATE_WINDOW,
- createWindowCallback);
- evas_object_smart_callback_del(
- wkView,
- EWK_CLOSE_WINDOW,
- closeWindowCallback);
- // deinit WKPagePolicyClient
- WKPagePolicyClient policyClient = {
- 0, /* version */
- 0, /* clientInfo */
- 0, /* decidePolicyForNavigationAction */
- 0, /* decidePolicyForNewWindowAction */
- 0, /* decidePolicyForResponse */
- 0, /* unableToImplementPolicy */
- };
- WKPageSetPagePolicyClient(ewk_view_WKPage_get(wkView),
- &policyClient);
- // EWK ContextMenu Callback
- evas_object_smart_callback_del(
- wkView,
- EWK_CONTEXTMENU_CUSTOMIZE,
- contextmenuCustomizeCallback);
- // deinit WKPageFormClient
- // WKPageFormClient formClient = {
- // 0, /* version */
- // 0, /* clientInfo */
- // 0, /* willSubmitForm */
- // };
- // WKPageSetPageFormClient(ewk_view_page_get(wkView), &formClient);
- evas_object_smart_callback_del(
- wkView,
- EWK_FORM_SUBMIT,
- formSubmitCallback);
- // EWK Geolocation Callback
- evas_object_smart_callback_del(
- wkView,
- EWK_REQUEST_GEOLOCATION_PERMISSION,
- geolocationPermissionRequestCallback);
- // EWK Notification Callback
- evas_object_smart_callback_del(
- wkView,
- EWK_NOTIFICATION_SHOW,
- notificationShowCallback);
- evas_object_smart_callback_del(
- wkView,
- EWK_NOTIFICATION_CANCEL,
- notificationCancelCallback);
- evas_object_smart_callback_del(
- wkView,
- EWK_NOTIFICATION_PERMISSION_REQUEST,
- notificationPermissionRequestCallback);
- evas_object_smart_callback_del(
- wkView,
- EWK_VIBRATION_VIBRATE,
- vibrationVibrateCallback);
- evas_object_smart_callback_del(
- wkView,
- EWK_VIBRATION_CANCEL,
- vibrationCancelCallback);
- // EWK Orientation Callback
- ewk_view_orientation_lock_callback_set(
- wkView,
- NULL,
- NULL);
- }
- void ViewLogic::createEwkView()
- {
- LogDebug("createEwkVeiw");
- Evas_Object* newEwkView = ewk_view_add_with_context(
- evas_object_evas_get(m_window),
- m_ewkContext);
- if (!newEwkView) {
- LogError("WKView creation failed");
- Assert(false);
- }
- // set cookie policy
- // even arguments pass the ewkContext, this API should be called
- // after webkit Evas_Object is created
- ewk_context_cookies_policy_set(m_ewkContext, EWK_COOKIE_JAR_ACCEPT_ALWAYS);
- m_ewkViewList.push_back(newEwkView);
- m_currentEwkView = newEwkView;
- m_emptyView = true;
- }
- void ViewLogic::setStartPage()
- {
- //TODO: actually this localization should be done in requestWillSend
- // callback, but Webkit2 denies access to local files if it detects
- // that first loaded file is not 'local' so it wan't work
- DPL::OptionalString localizedUri = ViewModule::UriSupport::localizeURI(
- DPL::FromUTF8String(m_startUrl.c_str()),
- m_model);
- m_currentUri = DPL::ToUTF8String(*localizedUri);
- }
- void ViewLogic::prepareEwkView(Evas_Object *wkView)
- {
- LogDebug("prepareEwkView called");
- Assert(wkView);
- Ewk_Setting* setting = ewk_view_setting_get(wkView);
- // set user agent
- auto userAgentString =
- ViewModule::UserAgentSupport::getUserAgentFromVconf();
- if (!userAgentString.empty()) {
- LogDebug("Setting custom user agent as: " << userAgentString);
- ewk_view_user_agent_set(wkView, userAgentString.c_str());
- }
- // set custom header : language
- using namespace ViewModule::CustomHeaderSupport;
- std::string customHeaderString = getValueByField(ACCEPT_LANGUAGE);
- if (!customHeaderString.empty()) {
- LogDebug("custom field=[" << ACCEPT_LANGUAGE << "]");
- LogDebug("custom value=[" << customHeaderString << "]");
- ewk_view_custom_header_add(wkView,
- ACCEPT_LANGUAGE.c_str(),
- customHeaderString.c_str());
- }
- // enable webkit plugins
- WrtDB::WidgetDAOReadOnly dao(m_model->Handle.Get());
- if (dao.getWebkitPluginsRequired()) {
- ewk_setting_enable_plugins_set(setting, EINA_TRUE);
- } else {
- ewk_setting_enable_plugins_set(setting, EINA_FALSE);
- }
- // The followings are not implemeted yet by webkit2
- // ewk_view_setting_accelerated_compositing_enable_set(EINA_TRUE);
- // ewk_view_mode_set();
- // ewk_view_setting_enable_specified_plugin_set(EINA_TRUE, FLASH_MIME_TYPE);
- // ewk_view_setting_html5video_external_player_enable_set(EINA_FALSE);
- // ewk_view_show_ime_on_autofocus_set(EINA_TRUE);
- // elm_webview_show_magnifier_set(EINA_FALSE);
- ewk_setting_enable_scripts_set(setting, EINA_TRUE);
- ewk_setting_auto_load_images_set(setting, EINA_TRUE);
- ewk_setting_auto_fitting_set(setting, EINA_FALSE);
- // disable zoom option when user click the input field
- // this option is useful with the normal website
- // for the make user friendly, disable auto zoom in the webapp
- // The followings are not implemeted yet by webkit2
- // elm_webview_input_field_zoom_set(EINA_FALSE);
- // set cookie database path
- // The followings are not implemeted yet by webkit2
- // ewk_cookies_file_set(dao.getCookieDatabasePath().c_str()));
- // set visibility to WebCore. This value will be used for html5.
- // also, this value will be changed in the suspend, resume
- // or create window, close window.
- ewk_view_page_visibility_state_set(wkView,
- EWK_PAGE_VISIBILITY_STATE_VISIBLE,
- EINA_TRUE);
- }
- void ViewLogic::removeEwkView(Evas_Object *wkView)
- {
- LogInfo("removeEwkView called");
- Assert(wkView);
- Assert(0 != m_ewkViewList.size());
- // unregister webview callbacks
- ewkClientDeinit(wkView);
- // suspend NPAPI plugin - Not implemented by Webkit2
- // ewk_view_pause_or_resume_plugins();
- m_ewkViewList.remove(wkView);
- evas_object_del(wkView);
- }
- void ViewLogic::resumeEwkView(Evas_Object *wkView)
- {
- LogInfo("resumeEwkView called");
- Assert(wkView);
- // register webview callback
- ewkClientInit(wkView);
- // resume webkit
- resumeWebkit(wkView);
- return;
- }
- void ViewLogic::suspendEwkView(Evas_Object *wkView)
- {
- LogInfo("suspendEwkView called");
- Assert(wkView);
- // suspend webkit
- suspendWebkit(wkView);
- // unregister webview callbacks
- ewkClientDeinit(wkView);
- return;
- }
- void ViewLogic::resumeWebkit(Evas_Object *wkView)
- {
- LogDebug("resumeWebkit");
- Assert(wkView);
- // resume NPAPI plugin
- // The followings are not implemeted yet by webkit2
- // ewk_view_pause_or_resume_plugins(false);
- // ewk_view_pause_or_resume_video_audio(false);
- // ewk_view_javascript_resume();
- // ewk_view_enable_render();
- // ewk_view_reduce_plugins_frame_rate(false);
- ewk_view_resume(wkView);
- ewk_view_visibility_set(wkView, EINA_TRUE);
- ewk_view_page_visibility_state_set(wkView,
- EWK_PAGE_VISIBILITY_STATE_VISIBLE,
- EINA_FALSE);
- return;
- }
- void ViewLogic::suspendWebkit(Evas_Object *wkView)
- {
- LogDebug("suspendWebkit");
- Assert(wkView);
- // suspend the followings
- // The followings are not implemeted yet by webkit2
- // ewk_view_pause_or_resume_plugins(true);
- // ewk_view_pause_or_resume_video_audio(true);
- // send visibility event to webpage
- ewk_view_page_visibility_state_set(wkView,
- EWK_PAGE_VISIBILITY_STATE_HIDDEN,
- EINA_FALSE);
- ewk_view_suspend(wkView);
- ewk_view_visibility_set(wkView, EINA_FALSE);
- return;
- }
- void ViewLogic::contextMessageFromInjectedBundleCallback(
- const char* name,
- const char* body,
- char** returnData,
- void* clientInfo)
- {
- LogDebug("contextMessageFromInjectedBundleCallback called");
- Assert(clientInfo);
- ViewLogic* This = static_cast<ViewLogic*>(clientInfo);
- // didRecieveMessageFromInjectedBundleCallback - returnData is null
- // didReceiveSynchronousMessageCallback - returnData isn't null
- // WKContextInjectedBundleClient bundleClient = {
- // kWKContextInjectedBundleClientCurrentVersion,
- // static_cast<void*>(this),
- // &didRecieveMessageFromInjectedBundleCallback,
- // &didReceiveSynchronousMessageCallback
- // };
- if (NULL == returnData) {
- This->didRecieveMessageFromInjectedBundle(name, body);
- } else {
- This->didReceiveSynchronousMessage(name, body, returnData);
- }
- }
- void ViewLogic::didStartDownloadCallback(
- const char* downloadUrl,
- void* data)
- {
- LogDebug("didStartDownloadCallback called");
- Assert(data);
- ViewLogic* This = static_cast<ViewLogic*>(data);
- Assert(downloadUrl);
- LogDebug("download url = " << downloadUrl);
- This->m_appsSupport->downloadRequest(
- downloadUrl,
- NULL,
- NULL);
- }
- void ViewLogic::didStartProvisionalLoadForFrameCallback(
- WKPageRef /*page*/,
- WKFrameRef /*frame*/,
- WKTypeRef /*userData*/,
- const void *clientInfo)
- {
- LogDebug("didStartProvisionalLoadForFrameCallback called");
- Assert(clientInfo);
- ViewLogic* This = static_cast<ViewLogic*>(const_cast<void*>(clientInfo));
- evas_object_focus_set(This->m_currentEwkView, EINA_TRUE);
- }
- void ViewLogic::didFinishLoadForFrameCallback(
- WKPageRef /*page*/,
- WKFrameRef frame,
- WKTypeRef /*userData*/,
- const void *clientInfo)
- {
- LogDebug("didFinishLoadForFrameCallback called");
- Assert(clientInfo);
- ViewLogic* This = static_cast<ViewLogic*>(const_cast<void*>(clientInfo));
- // Fill id/password
- DPL::OptionalString urlOptionalString = ViewModule::Utils::toString(frame);
- if (urlOptionalString.IsNull()) {
- LogError("url is empty");
- } else {
- std::string urlStr = DPL::ToUTF8String(*urlOptionalString).c_str();
- DPL::OptionalString jsOptionalString =
- ViewModule::PasswordSupport::jsForAutoFillData(urlStr.c_str());
- if (jsOptionalString.IsNull()) {
- LogError("Fail to get JS String");
- } else {
- std::string jsStr = DPL::ToUTF8String(*jsOptionalString).c_str();
- ewk_view_script_execute(
- This->m_currentEwkView,
- jsStr.c_str(),
- didRunJavaScriptCallback,
- This);
- }
- }
- // call loadFinish callback to wrt-client
- if (This->m_cbs->loadFinish) {
- This->m_cbs->loadFinish(true, This->m_cbsData);
- }
- // check if 'appsevice' event is registed at the current frames.
- // If so, dispatch the event to frames.
- PluginModuleSupport::dispatchJavaScriptEvent(
- This->m_ewkContext,
- WrtPlugins::W3C::ServiceCustomEvent);
- }
- void ViewLogic::didReceiveTitleForFrameCallback(
- WKPageRef page,
- WKStringRef title,
- WKFrameRef /*frame*/,
- WKTypeRef /*userData*/,
- const void* clientInfo)
- {
- LogDebug("didReceiveTitleForFrameCallback called");
- Assert(clientInfo);
- ViewLogic* This = static_cast<ViewLogic*>(const_cast<void*>(clientInfo));
- DPL::OptionalString titleOptionalString =
- ViewModule::Utils::toString(title);
- if (titleOptionalString.IsNull()) {
- LogDebug("title data is empty");
- return;
- }
- std::string titleStr = DPL::ToUTF8String(*titleOptionalString);
- LogDebug("Title = [" << titleStr << "]");
- This->m_schemeSupport->HandleTizenScheme(titleStr.c_str(),
- This->m_window,
- page);
- }
- void ViewLogic::didStartProgressCallback(WKPageRef /*page*/,
- const void* clientinfo)
- {
- LogDebug("didStartProgressCallback");
- Assert(clientinfo);
- // TODO : Progress control
- }
- void ViewLogic::didChangeProgressCallback(WKPageRef page,
- const void* /*clientinfo*/)
- {
- double progress = WKPageGetEstimatedProgress(page);
- LogDebug("didChangeProgressCallback progress = " << progress);
- }
- void ViewLogic::didFinishProgressCallback(WKPageRef /*page*/,
- const void* clientinfo)
- {
- LogDebug("didFinishProgressCallback");
- ViewLogic const * const view = static_cast<ViewLogic const * const>(clientinfo);
- if (view->m_cbs->progressFinish)
- view->m_cbs->progressFinish(view->m_cbsData);
- }
- void ViewLogic::createWindowCallback(
- void* data,
- Evas_Object* ,
- void* eventInfo)
- {
- LogDebug("createWindowCallback");
- Assert(data);
- ViewLogic* This = static_cast<ViewLogic*>(data);
- Evas_Object* currentEwkView = This->m_currentEwkView;
- // suspend current ewkview
- /* In case we support many pages in parallel
- then view should not be suspended*/
- //This->suspendEwkView(currentEwkView);
- if (This->m_cbs->bufferUnset) {
- This->m_cbs->bufferUnset(currentEwkView, This->m_cbsData);
- }
- // create new ewkview
- This->createEwkView();
- Evas_Object* newEwkView = This->m_currentEwkView;
- // initialize new ewkview
- This->setStartPage();
- This->ewkClientInit(newEwkView);
- This->prepareEwkView(newEwkView);
- // show new ewkview
- if (This->m_cbs->bufferUnset) {
- This->m_cbs->bufferSet(newEwkView, This->m_cbsData);
- }
- *(static_cast<Evas_Object **>(eventInfo)) = newEwkView;
- }
- void ViewLogic::closeWindowCallback(
- void* data,
- Evas_Object* /*obj*/,
- void* /*eventInfo*/)
- {
- LogDebug("closeWindowCallback");
- ecore_idler_add(windowCloseIdlerCallback, data);
- }
- void ViewLogic::pageDecidePolicyForResponseCallback(
- WKPageRef /*page*/,
- WKFrameRef frame,
- WKURLResponseRef response,
- WKURLRequestRef request,
- WKFramePolicyListenerRef listener,
- WKTypeRef /*userData*/,
- const void* clientInfo)
- {
- Assert(clientInfo);
- ViewLogic* This = static_cast<ViewLogic*>(const_cast<void*>(clientInfo));
- Assert(response);
- WKStringRef contentTypeRef = WKURLResponseEflCopyContentType(response);
- Assert(contentTypeRef);
- if (WKFrameCanShowMIMEType(frame, contentTypeRef)) {
- LogDebug("Accepting this content type to be used by WK2");
- WKFramePolicyListenerUse(listener);
- WKRelease(contentTypeRef);
- return;
- }
- Assert(request);
- // get uri information
- DPL::OptionalString requestOptionalStr =
- ViewModule::Utils::toString(request);
- if (requestOptionalStr.IsNull()) {
- LogDebug("uri data is empty");
- return;
- }
- std::string uriStr = DPL::ToUTF8String(*requestOptionalStr).c_str();
- const char* uri = uriStr.c_str();
- LogDebug("uri = [" << uri << "]");
- // get content information
- DPL::OptionalString contentOptionalStr =
- ViewModule::Utils::toString(contentTypeRef);
- std::string contentStr;
- if (contentOptionalStr.IsNull()) {
- LogDebug("content data is empty");
- } else {
- contentStr = DPL::ToUTF8String(*contentOptionalStr).c_str();
- }
- LogDebug("content type = [" << contentStr << "]");
- // get cookie information
- WKStringRef cookiesRef = WKURLRequestEflCopyCookies(request);
- Assert(cookiesRef);
- DPL::OptionalString cookiesOptionalStr =
- ViewModule::Utils::toString(cookiesRef);
- std::string cookieStr;
- if (cookiesOptionalStr.IsNull()) {
- LogDebug("cookies are empty");
- } else {
- cookieStr = DPL::ToUTF8String(*cookiesOptionalStr).c_str();
- }
- LogDebug("cookie = [" << cookieStr << "]");
- LogDebug("Content not supported, will be opened in external app");
- WKFramePolicyListenerIgnore(listener);
- This->m_appsSupport->downloadRequest(
- uri,
- contentStr.empty() ? NULL : contentStr.c_str(),
- cookieStr.empty() ? NULL : cookieStr.c_str());
- WKRelease(contentTypeRef);
- WKRelease(cookiesRef);
- }
- void ViewLogic::pageDecidePolicyForNavigationActionCallback(
- WKPageRef page,
- WKFrameRef frame,
- WKFrameNavigationType /*navigationType*/,
- WKEventModifiers /*modifiers*/,
- WKEventMouseButton /*mouseButton*/,
- WKURLRequestRef request,
- WKFramePolicyListenerRef listener,
- WKTypeRef /*userData*/,
- const void* clientInfo)
- {
- LogDebug("Accepting URL: " << ViewModule::Utils::toString(request));
- Assert(clientInfo);
- ViewLogic* This = static_cast<ViewLogic*>(const_cast<void*>(clientInfo));
- if (This->m_schemeSupport->filterURIByScheme(page,
- frame,
- request,
- false,
- This->m_model,
- This->m_window))
- {
- LogDebug("use");
- WKFramePolicyListenerUse(listener);
- }
- else
- {
- if(This->m_emptyView)
- {
- /*
- * The view is empty and scheme has been handled externally. When
- * user gets back from the external application he'd see blank page
- * and won't be able to navigate back. This happens when window.open
- * is used to handle schemes like sms/mms/mailto (for example in
- * WAC web standards tests: WS-15XX).
- *
- * To solve the problem, the empty view is removed from the stack
- * and the previous one is shown. This is not an elegant solution
- * but we don't have a better one.
- */
- LogInfo("Scheme has been handled externally. Removing empty view.");
- if (ewk_view_back_possible(This->m_currentEwkView)) {
- // go back to previous WKPage
- ewk_view_back(This->m_currentEwkView);
- } else {
- // stop current WKPage
- ewk_view_stop(This->m_currentEwkView);
- ecore_idler_add(windowCloseIdlerCallback, This);
- }
- }
- LogDebug("ignore");
- WKFramePolicyListenerIgnore(listener);
- }
- }
- void ViewLogic::pageDecidePolicyForNewWindowActionCallback(
- WKPageRef page,
- WKFrameRef frame,
- WKFrameNavigationType /*navigationType*/,
- WKEventModifiers /*modifiers*/,
- WKEventMouseButton /*mouseButton*/,
- WKURLRequestRef request,
- WKStringRef /*frameName*/,
- WKFramePolicyListenerRef listener,
- WKTypeRef /*userData*/,
- const void* clientInfo)
- {
- LogDebug("Accepting URL: " << ViewModule::Utils::toString(request));
- Assert(clientInfo);
- ViewLogic* This = static_cast<ViewLogic*>(const_cast<void*>(clientInfo));
- if (This->m_schemeSupport->filterURIByScheme(page,
- frame,
- request,
- true,
- This->m_model,
- This->m_window))
- {
- WKFramePolicyListenerUse(listener);
- }
- else
- {
- // scheme handled
- WKFramePolicyListenerIgnore(listener);
- }
- }
- void ViewLogic::contextmenuCustomizeCallback(
- void* data,
- Evas_Object* /*obj*/,
- void* eventInfo)
- {
- LogDebug("contextmenuCustomizeCallback called");
- Assert(data);
- Assert(eventInfo);
- ViewLogic* This = static_cast<ViewLogic*>(const_cast<void*>(data));
- Ewk_Context_Menu* menu = static_cast<Ewk_Context_Menu*>(eventInfo);
- if ((This->m_model->Type.Get().appType == WrtDB::APP_TYPE_TIZENWEBAPP) &&
- (This->m_model->SettingList.Get().getContextMenu()
- == ContextMenu_Disable))
- {
- LogDebug("ContextMenu Disable!!");
- for (unsigned int idx = 0; idx < ewk_context_menu_item_count(menu);) {
- Ewk_Context_Menu_Item* item = ewk_context_menu_nth_item_get(menu, idx);
- Assert(item);
- ewk_context_menu_item_remove(menu, item);
- }
- } else {
- LogDebug("ContextMenu Enable!!");
- for (unsigned int idx = 0; idx < ewk_context_menu_item_count(menu);) {
- Ewk_Context_Menu_Item* item = ewk_context_menu_nth_item_get(menu, idx);
- Assert(item);
- Ewk_Context_Menu_Item_Tag tag = ewk_context_menu_item_tag_get(item);
- switch (tag) {
- case kWKContextMenuItemTagOpenImageInNewWindow:
- ewk_context_menu_item_remove(menu, item);
- break;
- default:
- idx++;
- break;
- }
- }
- }
- }
- void ViewLogic::formSubmitCallback(
- void* /*data*/,
- Evas_Object* /*obj*/,
- void* eventInfo)
- {
- LogDebug("formSubmitCallback called");
- Assert(eventInfo);
- Ewk_Form_Data* formData = static_cast<Ewk_Form_Data*>(eventInfo);
- const char* uri = ewk_form_data_url_get(formData);
- if (!uri) {
- LogError("URL is empty");
- return;
- }
- Eina_Hash* userData = ewk_form_data_values_get(formData);
- ViewModule::PasswordSupport::submitClicked(uri, userData);
- }
- void ViewLogic::geolocationPermissionRequestCallback(
- void* /*data*/,
- Evas_Object* /*obj*/,
- void* eventInfo)
- {
- LogDebug("geolocationPermissionRequestCallback called");
- Assert(eventInfo);
- ViewModule::GeolocationSupport::Webkit2::
- geolocationPermissionRequest(eventInfo);
- return;
- }
- void ViewLogic::notificationShowCallback(
- void* data,
- Evas_Object* /*obj*/,
- void* eventInfo)
- {
- LogDebug("notificationShowCallback called");
- Assert(data);
- ViewLogic* This = static_cast<ViewLogic*>(data);
- Assert(eventInfo);
- Ewk_Notification* noti = static_cast<Ewk_Notification*>(eventInfo);
- using namespace ViewModule::WebNotification;
- WebNotificationDataPtr notiData(
- new WebNotificationData(
- This->m_model,
- ewk_notification_id_get(noti)));
- DPL::OptionalString string =
- DPL::FromUTF8String(ewk_notification_icon_url_get(noti));
- if (!string.IsNull()) {
- notiData->m_iconURL = DPL::ToUTF8String(*string);
- }
- string = DPL::FromUTF8String(ewk_notification_title_get(noti));
- if (!string.IsNull()) {
- notiData->m_title = DPL::ToUTF8String(*string);
- }
- string = DPL::FromUTF8String(ewk_notification_body_get(noti));
- if (!string.IsNull()) {
- notiData->m_body = DPL::ToUTF8String(*string);
- }
- LogInfo("notification id : " << notiData->m_id);
- LogInfo("notification iconURL : " << notiData->m_iconURL);
- LogInfo("notification title : " << notiData->m_title);
- LogInfo("notification body : " << notiData->m_body);
- showWebNotification(notiData);
- ewk_notification_showed(This->m_ewkContext, ewk_notification_id_get(noti));
- }
- void ViewLogic::notificationCancelCallback(
- void* /*data*/,
- Evas_Object* /*obj*/,
- void* /*eventInfo*/)
- {
- LogDebug("notificationCancelCallback called");
- }
- void ViewLogic::notificationPermissionRequestCallback(
- void* data,
- Evas_Object* /*obj*/,
- void* eventInfo)
- {
- LogDebug("notificationPermissionRequestCallback called");
- Assert(data);
- ViewLogic* This = static_cast<ViewLogic*>(data);
- Assert(eventInfo);
- Ewk_Notification_Permission_Request* request =
- static_cast<Ewk_Notification_Permission_Request*>(eventInfo);
- ewk_notification_permission_request_response(
- This->m_ewkContext,
- request,
- EINA_TRUE);
- return;
- }
- void ViewLogic::vibrationVibrateCallback(
- void* data,
- Evas_Object* /*obj*/,
- void* eventInfo)
- {
- LogDebug("vibrationVibrateCallback called");
- Assert(data);
- ViewLogic* This = static_cast<ViewLogic*>(data);
- Assert(eventInfo);
- const long vibrationTime = *(static_cast<const long*>(eventInfo));
- This->m_vibrationSupport->startVibration(vibrationTime);
- return;
- }
- void ViewLogic::vibrationCancelCallback(
- void* data,
- Evas_Object* /*obj*/,
- void* /*eventInfo*/)
- {
- LogDebug("vibrationCancelCallback called");
- Assert(data);
- ViewLogic* This = static_cast<ViewLogic*>(data);
- This->m_vibrationSupport->stopVibration();
- return;
- }
- // EWK Orientation Callback
- Eina_Bool ViewLogic::orientationLockCallback(
- Evas_Object* obj,
- Eina_Bool needLock,
- int orientation,
- void* data)
- {
- LogDebug("orientationLockCallback called");
- Assert(data);
- ViewLogic* This = static_cast<ViewLogic*>(data);
- // current implementation doesn't use lock value
- needLock;
- if (orientation & EWK_SCREEN_ORIENTATION_PORTRAIT_PRIMARY) {
- LogDebug("orientation is portrait-primary");
- elm_win_rotation_with_resize_set(This->m_window, 0);
- ewk_view_orientation_send(obj, 0);
- } else if(orientation & EWK_SCREEN_ORIENTATION_LANDSCAPE_PRIMARY) {
- LogDebug("orientation is landscape-primary");
- elm_win_rotation_with_resize_set(This->m_window, 270);
- ewk_view_orientation_send(obj, 90);
- } else if(orientation & EWK_SCREEN_ORIENTATION_PORTRAIT_SECONDARY) {
- LogDebug("orientation is portrait-secondary");
- elm_win_rotation_with_resize_set(This->m_window, 180);
- ewk_view_orientation_send(obj, 180);
- } else if(orientation & EWK_SCREEN_ORIENTATION_LANDSCAPE_SECONDARY) {
- LogDebug("orientation is landscape-secondary");
- elm_win_rotation_with_resize_set(This->m_window, 90);
- ewk_view_orientation_send(obj, -90);
- } else {
- LogDebug("Wrong orientation is set");
- return EINA_FALSE;
- }
- return EINA_TRUE;
- }
- void ViewLogic::didRunJavaScriptCallback(
- Evas_Object* /*obj*/,
- const char* result,
- void* /*userData*/)
- {
- LogInfo("didRunJavaScriptCallback called");
- LogInfo("result = " << result);
- }
- void ViewLogic::backButtonCallback(void* data,
- Evas_Object * /*obj*/,
- void * /*event_info*/)
- {
- LogInfo("BackButtonCallback");
- Assert(data);
- ViewLogic* This = static_cast<ViewLogic*>(data);
- if (WKPageCanGoBack(ewk_view_WKPage_get(This->m_currentEwkView))) {
- WKPageGoBack(ewk_view_WKPage_get(This->m_currentEwkView));
- } else {
- if (1 >= This->m_ewkViewList.size()) {
- // If there is no previous page, widget move to backgroud.
- LogInfo("Widget move to backgroud");
- elm_win_lower(This->m_window);
- } else {
- // Back to previous webview
- LogInfo("Widget move to previous webview");
- ecore_idler_add(windowCloseIdlerCallback, This);
- }
- }
- }
- Eina_Bool ViewLogic::windowCloseIdlerCallback(void* data)
- {
- LogDebug("closeIdlerCallback");
- ViewLogic* This = static_cast<ViewLogic*>(data);
- This->windowClose();
- return ECORE_CALLBACK_CANCEL;
- }
- void ViewLogic::processDidCrashCallback(WKPageRef /*page*/,
- const void* clientInfo)
- {
- LogInfo("processDidCrashCallback");
- ViewLogic const * const view =
- static_cast<ViewLogic const * const>(clientInfo);
- if (view->m_cbs->webCrash) {
- view->m_cbs->webCrash(view->m_cbsData);
- }
- }
- int ViewLogic::appcoreLowMemoryCallback(void *data)
- {
- LogInfo("appcoreLowMemoryCallback");
- Assert(data);
- ViewLogic* This = static_cast<ViewLogic*>(data);
- if (NULL == This->m_ewkContext) {
- LogInfo("ewk isn't initialize at this moment");
- } else {
- ewk_context_cache_clear(This->m_ewkContext);
- ewk_context_notify_low_memory(This->m_ewkContext);
- }
- return 0;
- }
- void ViewLogic::didRecieveMessageFromInjectedBundle(
- const char* name,
- const char* /*body*/)
- {
- LogDebug("did recive message " << name);
- }
- void ViewLogic::didReceiveSynchronousMessage(
- const char* name,
- const char* body,
- char** returnData)
- {
- LogDebug("didReceiveSynchronousMessage called");
- Assert(name);
- Assert(returnData);
- if (!body) {
- LogDebug("body is empty");
- *returnData = NULL;
- return;
- }
- if (!strcmp(name, willSendMessageName)) {
- LogDebug("received : " << willSendMessageName);
- bool is_xhr = true; //Webkit2 should inform if it is xhr
- DPL::OptionalString ret =
- requestWillSend(DPL::FromUTF8String(body), is_xhr);
- if (ret.IsNull()) {
- LogError("Wrong type received");
- *returnData = NULL;
- } else {
- LogDebug("returning uri: " << ret);
- *returnData = strdup(DPL::ToUTF8String(*ret).c_str());
- }
- } else if (!strcmp(name, uriChangedMessageName)) {
- LogDebug("received : " << uriChangedMessageName);
- std::string ret = requestUriChanged(DPL::FromUTF8String(body));
- *returnData = strdup(ret.c_str());
- }
- }
- DPL::Optional<DPL::String> ViewLogic::requestWillSend(
- const DPL::String& inputURI,
- bool is_xhr)
- {
- DPL::Optional<DPL::String> uri =
- ViewModule::UriSupport::localizeURI(inputURI, m_model);
- if (uri.IsNull())
- {
- LogDebug("uri is empty");
- return uri;
- }
- // check ACE, WARP
- if (!ViewModule::SecuritySupport::filterURIBySecurity(uri, is_xhr, m_model))
- {
- // set blocked uri to open browser later
- m_blockedUri = DPL::ToUTF8String(*uri);
- LogInfo("set blocked uri to open browser later : " << m_blockedUri);
- return DPL::Optional<DPL::String>::Null;
- }
- // check roaming state for external scheme
- if (m_model->Type.Get().appType == WrtDB::APP_TYPE_TIZENWEBAPP)
- {
- LogInfo("TizenWebApp does not need to check roaming status!");
- }
- else if (!ViewModule::SecuritySupport::filterURIByRoaming(uri))
- {
- LogDebug("Request was blocked by roaming settings: " << uri);
- return DPL::Optional<DPL::String>::Null;
- }
- return uri;
- }
- std::string ViewLogic::requestUriChanged(const DPL::String& changedURL)
- {
- using namespace ViewModule::SecuritySupport;
- std::string url = DPL::ToUTF8String(changedURL);
- LogInfo("URL = [" << url << "]");
- m_emptyView = false;
- // check WARP
- // If url is same to URICHANGE_BLOCKED_URL,
- // this url has been already blocked by willsend.
- // So current page should be moved to previous page
- if (url == URICHANGE_BLOCKED_URL)
- {
- if (m_model->Type.Get().appType == WrtDB::APP_TYPE_TIZENWEBAPP)
- {
- // block this page and open it in browser
- LogDebug("Request was blocked by WARP: " << url.c_str());
- if (!m_blockedUri.empty()) {
- LogDebug("open browser : " << m_blockedUri);
- bundle* bundleData = bundle_create();
- appsvc_set_operation(bundleData, APPSVC_OPERATION_VIEW);
- appsvc_set_uri(bundleData, m_blockedUri.c_str());
- CONTROLLER_POST_EVENT(
- ApplicationLauncher,
- ApplicationLauncherEvents::LaunchApplicationByAppService(
- bundleData,
- NULL,
- NULL));
- m_blockedUri = std::string();
- }
- }
- if (ewk_view_back_possible(m_currentEwkView)) {
- // go back to previous WKPage
- ewk_view_back(m_currentEwkView);
- } else {
- // stop current WKPage
- ewk_view_stop(m_currentEwkView);
- ecore_idler_add(windowCloseIdlerCallback, this);
- }
- // This is used in case of returning previous page
- m_currentUri = url;
- return URICHANGE_PLUGIN_NO_CHANGE;
- }
- m_currentUri = url;
- // Check if this url with 'http' or 'https' is included in whitelist,
- // which has lists of accessible external documents and
- // used for ONLY Tizen app
- std::string matchedScheme;
- std::string matchedUri;
- pcrecpp::RE(PATTERN_URI_CHANGE).PartialMatch(url.c_str(),
- &matchedUri,
- &matchedScheme);
- ViewModule::Scheme scheme(matchedScheme);
- if (scheme.GetType() == ViewModule::Scheme::HTTP ||
- scheme.GetType() == ViewModule::Scheme::HTTPS)
- {
- if (m_model->Type.Get().appType == WrtDB::APP_TYPE_TIZENWEBAPP) {
- if (!checkWhitelist(url.c_str())) {
- LogInfo("This uri is not included in white document list");
- return URICHANGE_PLUGIN_STOP_ONLY;
- }
- LogInfo("This url is included in WhiteList");
- } else {
- // For WAC app, WRT should block access of device api
- // for external documents
- return URICHANGE_PLUGIN_STOP_ONLY;
- }
- }
- // register javascript object for plugins to be used
- LogInfo("Register Plugin Objects");
- return URICHANGE_PLUGIN_RESTART;
- }
- void ViewLogic::disconnectNetworkConnectionsFunction() {
- if (m_ewkContext) {
- LogDebug("disconnection network connections");
- // API needs Ewk_context
- // Re-open after merged below commit
- // http://slp-info.sec.samsung.net/gerrit/#change,48358
- // ewk_context_network_session_requests_cancel(m_ewkContext);
- }
- }
- void ViewLogic::windowClose()
- {
- LogDebug("windowClose");
- if (1 >= m_ewkViewList.size()) {
- if (m_cbs->windowClose) {
- m_cbs->windowClose(m_cbsData);
- }
- } else {
- // hide current ewkView
- if (m_cbs->bufferUnset) {
- m_cbs->bufferUnset(m_currentEwkView, m_cbsData);
- }
- removeEwkView(m_currentEwkView);
- // get latest ewkView
- m_currentEwkView = m_ewkViewList.back();
- WKPageRef page = ewk_view_WKPage_get(m_currentEwkView);
- WKFrameRef frame = WKPageGetMainFrame(page);
- DPL::OptionalString frameURL = ViewModule::Utils::toString(frame);
- if (frameURL.IsNull()) {
- m_currentUri.clear();
- m_emptyView = true;
- } else {
- m_currentUri = DPL::ToUTF8String(*frameURL);
- m_emptyView = false;
- }
- // resume ewkView
- /* In case we support many pages in parallel
- then view is not suspended*/
- //resumeEwkView(m_currentEwkView);
- // show ewkView
- if (m_cbs->bufferSet) {
- m_cbs->bufferSet(m_currentEwkView, m_cbsData);
- }
- }
- }