PageRenderTime 56ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/wrt/src/view/webkit/view_logic.cpp

https://review.tizen.org/git/
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

Large files files are truncated, but you can click here to view the full file

  1. /*
  2. * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
  3. *
  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
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  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.
  15. */
  16. /**
  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
  22. */
  23. #include "view_logic.h"
  24. #include <cstring>
  25. #include <string>
  26. #include <dpl/assert.h>
  27. #include <dpl/log/log.h>
  28. #include <dpl/optional.h>
  29. #include <dpl/string.h>
  30. #include <appcore-common.h>
  31. #include <pcrecpp.h>
  32. #include <widget_model.h>
  33. #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
  34. #include <common/application_data.h>
  35. #include <common/application_launcher.h>
  36. #include <common/scheme.h>
  37. #include <common/roaming_agent.h>
  38. #include <common/view_logic_apps_support.h>
  39. #include <common/view_logic_custom_header_support.h>
  40. #include <common/view_logic_password_support.h>
  41. #include <common/view_logic_security_support.h>
  42. #include <common/view_logic_storage_support.h>
  43. #include <common/view_logic_uri_support.h>
  44. #include <common/view_logic_user_agent_support.h>
  45. #include <common/view_logic_vibration_support.h>
  46. #include <common/view_logic_web_notification_support.h>
  47. #include <view_logic_scheme_support.h>
  48. #include "view_logic_geolocation_support_webkit2.h"
  49. #include "view_logic_utils.h"
  50. #include "bundles/plugin_module_support.h"
  51. #include <ewk_context.h>
  52. #include <ewk_context_menu.h>
  53. #include <ewk_form_data.h>
  54. #include <ewk_network.h>
  55. #include <ewk_notification.h>
  56. #include <ewk_view.h>
  57. #include <ewk_setting.h>
  58. #include <WebKit2.h>
  59. #include <WKPage.h>
  60. #include <WKContextMenuItem.h>
  61. #include <WKURLResponseEfl.h>
  62. #include <WKURLRequestEfl.h>
  63. #include <js_overlay_types.h>
  64. #include <i_runnable_widget_object.h>
  65. namespace {
  66. const char * const bundlePath = "/usr/lib/wrt-wk2-bundles/libwrt-wk2-bundle.so";
  67. const char * const willSendMessageName = "will_send_msg";
  68. const char * const uriChangedMessageName = "uri_changed_msg";
  69. const char * const URICHANGE_PLUGIN_STOP_ONLY = "plugin_stop_only";
  70. const char * const URICHANGE_PLUGIN_RESTART = "plugin_restart";
  71. const char * const URICHANGE_PLUGIN_NO_CHANGE = "plugin_no_change";
  72. const char * const URICHANGE_BLOCKED_URL = "null";
  73. const char* PATTERN_URI_CHANGE = "^(([^:/\\?#]+)://[^\\?#]*)";
  74. const int MAX_NUM_CONTEXT_MENU_ITEMS = 10;
  75. // ewk callback
  76. const char * const EWK_CREATE_WINDOW = "create,window";
  77. const char * const EWK_CLOSE_WINDOW = "close,window";
  78. const char * const EWK_CONTEXTMENU_CUSTOMIZE = "contextmenu,customize";
  79. const char * const EWK_FORM_SUBMIT = "form,submit";
  80. const char * const EWK_REQUEST_GEOLOCATION_PERMISSION =
  81. "request,geolocation,permission";
  82. const char * const EWK_NOTIFICATION_SHOW = "notification,show";
  83. const char * const EWK_NOTIFICATION_CANCEL = "notification,cancel";
  84. const char * const EWK_NOTIFICATION_PERMISSION_REQUEST =
  85. "notification,permission,request";
  86. const char * const EWK_VIBRATION_VIBRATE = "vibration,vibrate";
  87. const char * const EWK_VIBRATION_CANCEL = "vibration,cancel";
  88. }
  89. void ViewLogic::createWebView(Ewk_Context* context,
  90. Evas_Object* window)
  91. {
  92. LogDebug("");
  93. initializeEwkContext(context);
  94. Assert(NULL != m_ewkContext);
  95. Assert(window);
  96. m_window = window;
  97. createEwkView();
  98. }
  99. void ViewLogic::destroyWebView()
  100. {
  101. if (m_ewkContext) {
  102. finalizeEwkContext();
  103. }
  104. }
  105. void ViewLogic::initialize()
  106. {
  107. LogDebug("Initializing");
  108. ApplicationLauncherSingleton::Instance().Touch();
  109. appcore_set_event_callback(
  110. APPCORE_EVENT_LOW_MEMORY,
  111. &appcoreLowMemoryCallback,
  112. this);
  113. }
  114. void ViewLogic::terminate()
  115. {
  116. LogDebug("terminating view logic");
  117. if (m_model) {
  118. hideWidget();
  119. } else {
  120. LogError("Widget model not created");
  121. }
  122. LogDebug("done");
  123. }
  124. void ViewLogic::prepareView(WidgetModel* m, const std::string &startUrl)
  125. {
  126. LogDebug("View prepare");
  127. Assert(m);
  128. m_model = m;
  129. m_startUrl = ViewModule::UriSupport::getUri(m_model, startUrl);
  130. Assert(NULL != m_ewkContext);
  131. Assert(m_window);
  132. initializeSupport();
  133. setStartPage();
  134. ewkClientInit(m_currentEwkView);
  135. prepareEwkView(m_currentEwkView);
  136. initializePluginLoading();
  137. }
  138. void ViewLogic::initializePluginLoading()
  139. {
  140. // inform wrt information for plugin loading to web process
  141. PluginModuleSupport::start(
  142. m_ewkContext,
  143. m_model->Handle.Get(),
  144. elm_config_scale_get(),
  145. ApplicationDataSingleton::Instance().getEncodedBundle(),
  146. m_theme.c_str(),
  147. m_model->SettingList.Get().isEncrypted());
  148. }
  149. void ViewLogic::initializeSupport()
  150. {
  151. // set local stroage database path
  152. WrtDB::WidgetDAOReadOnly dao(m_model->Handle.Get());
  153. ewk_context_web_storage_path_set(m_ewkContext,
  154. dao.getPrivateLocalStoragePath().c_str());
  155. m_schemeSupport.reset(new SchemeSupport(m_model->Type.Get().appType));
  156. ViewModule::StorageSupport::initializeStorage(m_model);
  157. m_appsSupport->initialize(m_model);
  158. m_vibrationSupport->initialize();
  159. ViewModule::GeolocationSupport::Webkit2::initialize(m_model->Handle.Get());
  160. ViewModule::GeolocationSupport::Webkit2::
  161. adjustGeolocationModuleState(m_currentEwkView);
  162. }
  163. void ViewLogic::showWidget()
  164. {
  165. LogDebug("showing widget");
  166. Assert(NULL != m_currentEwkView && "ewk_view not created at this point");
  167. if (m_currentUri.empty()) {
  168. LogError("Localized current URI doesn't exist");
  169. return;
  170. }
  171. LogInfo("m_currentUri: " << m_currentUri);
  172. RoamingAgentSingleton::Instance().setDisconnectCallback(
  173. DPL::MakeDelegate(this,
  174. &ViewLogic::disconnectNetworkConnectionsFunction));
  175. // load page
  176. WKURLRef baseUrl = WKURLCreateWithUTF8CString(
  177. m_currentUri.c_str());
  178. if (!baseUrl) {
  179. LogError("URL creation failed");
  180. return;
  181. }
  182. WKPageLoadURL(ewk_view_WKPage_get(m_currentEwkView), baseUrl);
  183. WKRelease(baseUrl);
  184. if (m_cbs->bufferSet) {
  185. m_cbs->bufferSet(m_currentEwkView, m_cbsData);
  186. }
  187. }
  188. void ViewLogic::hideWidget()
  189. {
  190. LogDebug("hiding widget");
  191. RoamingAgentSingleton::Instance().unsetDisconnectCallback();
  192. ViewModule::StorageSupport::deinitializeStorage(m_model);
  193. m_appsSupport->deinitialize();
  194. m_vibrationSupport->deinitialize();
  195. // almost terminate time spends for terminate webkit.
  196. // after block this evas_object_del code, webkit will be destoryed
  197. // with parent evas_object(~WindowData())
  198. //FOREACH(it, m_ewkViewList) {
  199. // evas_object_del(*it);
  200. //}
  201. m_ewkViewList.clear();
  202. }
  203. void ViewLogic::suspendWidget()
  204. {
  205. LogInfo("Pausing widget");
  206. Assert(m_model);
  207. if (!m_currentEwkView) {
  208. LogWarning("Cannot suspend widget without view");
  209. } else {
  210. suspendWebkit(m_currentEwkView);
  211. }
  212. // call user callback
  213. if (m_cbs->suspend) {
  214. m_cbs->suspend(true, m_cbsData);
  215. }
  216. };
  217. void ViewLogic::resumeWidget()
  218. {
  219. LogInfo("Resume widget");
  220. Assert(m_model);
  221. if (m_currentEwkView) {
  222. resumeWebkit(m_currentEwkView);
  223. }
  224. if (m_window) {
  225. elm_win_activate(m_window);
  226. }
  227. evas_object_focus_set(m_currentEwkView, EINA_TRUE);
  228. // call user callback
  229. if (m_cbs->resume) {
  230. m_cbs->resume(true, m_cbsData);
  231. }
  232. };
  233. void ViewLogic::resetWidget()
  234. {
  235. LogInfo("Resetting Widget");
  236. // check if already created webview exists
  237. if (!m_ewkViewList.size()) {
  238. // create new webview
  239. createEwkView();
  240. setStartPage();
  241. ewkClientInit(m_currentEwkView);
  242. prepareEwkView(m_currentEwkView);
  243. } else {
  244. bundle *bundle = ApplicationDataSingleton::Instance().getBundle();
  245. const char *operation = appsvc_get_operation(bundle);
  246. LogInfo("operation : " << operation);
  247. if (operation &&
  248. !strcmp(operation, APPSVC_OPERATION_DEFAULT)) {
  249. // ignore default operation that is reserved by system
  250. // just activate current window
  251. LogInfo("raise window");
  252. elm_win_raise(m_window);
  253. resumeWebkit(m_currentEwkView);
  254. return;
  255. }
  256. // check if current url is service url for this tizen service
  257. std::string requestedUri =
  258. ViewModule::UriSupport::getUri(m_model, m_startUrl);
  259. DPL::OptionalString servicedUri = ViewModule::UriSupport::localizeURI(
  260. DPL::FromUTF8String(requestedUri.c_str()),
  261. m_model);
  262. if (m_currentUri == DPL::ToUTF8String(*servicedUri)) {
  263. // set only encoded bundle
  264. double scale = elm_config_scale_get();
  265. PluginModuleSupport::setCustomProperties(
  266. m_ewkContext,
  267. &scale,
  268. ApplicationDataSingleton::Instance().getEncodedBundle());
  269. // dispatch 'appservice' js event
  270. PluginModuleSupport::dispatchJavaScriptEvent(
  271. m_ewkContext,
  272. WrtPlugins::W3C::ServiceCustomEvent);
  273. // window activate
  274. if (m_window) {
  275. elm_win_raise(m_window);
  276. }
  277. resumeWebkit(m_currentEwkView);
  278. return;
  279. } else {
  280. m_currentUri = DPL::ToUTF8String(*servicedUri);
  281. }
  282. }
  283. // inform wrt information for plugin loading to web process
  284. PluginModuleSupport::start(
  285. m_ewkContext,
  286. m_model->Handle.Get(),
  287. elm_config_scale_get(),
  288. ApplicationDataSingleton::Instance().getEncodedBundle(),
  289. m_theme.c_str(),
  290. m_model->SettingList.Get().isEncrypted());
  291. // load page
  292. WKURLRef baseUrl = WKURLCreateWithUTF8CString(
  293. m_currentUri.c_str());
  294. if (!baseUrl) {
  295. LogError("URL creation failed");
  296. return;
  297. }
  298. WKPageLoadURL(ewk_view_WKPage_get(m_currentEwkView), baseUrl);
  299. WKRelease(baseUrl);
  300. resumeWebkit(m_currentEwkView);
  301. // call user callback
  302. if (m_cbs->reset) {
  303. m_cbs->reset(true, m_cbsData);
  304. }
  305. if (m_cbs->bufferSet) {
  306. m_cbs->bufferSet(m_currentEwkView, m_cbsData);
  307. }
  308. }
  309. void ViewLogic::goBack()
  310. {
  311. if (WKPageCanGoBack(ewk_view_WKPage_get(m_currentEwkView))) {
  312. WKPageGoBack(ewk_view_WKPage_get(m_currentEwkView));
  313. } else {
  314. if (1 >= m_ewkViewList.size()) {
  315. // If there is no previous page, widget move to backgroud.
  316. LogInfo("Widget move to backgroud");
  317. elm_win_lower(m_window);
  318. } else {
  319. // Back to previous webview
  320. LogInfo("Widget move to previous webview");
  321. ecore_idler_add(windowCloseIdlerCallback, this);
  322. }
  323. }
  324. }
  325. Evas_Object* ViewLogic::getCurrentWebview()
  326. {
  327. LogInfo("get current webview");
  328. return m_currentEwkView;
  329. }
  330. void ViewLogic::setUserCallbacks(WRT::UserCallbacksPtr cbs, void *data)
  331. {
  332. m_cbs = cbs;
  333. m_cbsData = data;
  334. }
  335. void ViewLogic::initializeEwkContext(Ewk_Context* newEwkContext)
  336. {
  337. LogInfo("initializeEwkContext called");
  338. Assert(newEwkContext && "Ewk_Context provided can not be null");
  339. // bundle callback setting
  340. ewk_context_message_from_injected_bundle_callback_set(
  341. newEwkContext,
  342. contextMessageFromInjectedBundleCallback,
  343. static_cast<void*>(this));
  344. // proxy server setting
  345. char *proxyAddress = vconf_get_str(VCONFKEY_NETWORK_PROXY);
  346. if ((!proxyAddress) || (strlen(proxyAddress) == 0)
  347. || (strstr(proxyAddress, "0.0.0.0")))
  348. {
  349. LogInfo("proxy address is empty");
  350. ewk_context_proxy_uri_set(newEwkContext, NULL);
  351. } else {
  352. LogInfo("proxy address [" << proxyAddress << "]");
  353. ewk_context_proxy_uri_set(newEwkContext, proxyAddress);
  354. }
  355. if (proxyAddress) {
  356. free(proxyAddress);
  357. proxyAddress = NULL;
  358. }
  359. // theme setting
  360. const char *theme = elm_theme_get(NULL);
  361. if (theme) {
  362. m_theme = theme;
  363. LogInfo("theme is " << m_theme);
  364. }
  365. // set download callback
  366. //WKContextDownloadClient downloadClient = {
  367. // kWKContextDownloadClientCurrentVersion,
  368. // ewkContext,
  369. // didStartDownload,
  370. // 0, // didReceiveAuthenticationChallenge
  371. // 0, // didReceiveResponse
  372. // 0, // didReceiveData
  373. // 0, // shouldDecodeSourceDataOfMIMEType
  374. // 0, // decideDestinationWithSuggestedFilename
  375. // 0, // didCreateDestination
  376. // 0, // didFinish
  377. // 0, // didFail
  378. // 0, // didCancel
  379. // 0 // processDidCrash
  380. // };
  381. // WKContextSetDownloadClient(newEwkContext, &downloadClient);
  382. ewk_context_did_start_download_callback_set(
  383. newEwkContext,
  384. didStartDownloadCallback,
  385. this);
  386. // set to member value
  387. m_ewkContext = newEwkContext;
  388. }
  389. void ViewLogic::finalizeEwkContext()
  390. {
  391. LogInfo("finalizeEwkContext called");
  392. ewk_context_delete(m_ewkContext);
  393. m_ewkContext = 0;
  394. }
  395. ViewLogic::ViewLogic():
  396. m_ewkContext(0),
  397. m_currentEwkView(0),
  398. m_model(0),
  399. m_emptyView(false),
  400. m_appsSupport(new ViewModule::AppsSupport()),
  401. m_vibrationSupport(new ViewModule::VibrationSupport()),
  402. m_window(NULL),
  403. m_cbs(new WRT::UserCallbacks),
  404. m_cbsData(NULL)
  405. {
  406. }
  407. ViewLogic::~ViewLogic ()
  408. {
  409. }
  410. void ViewLogic::ewkClientInit(Evas_Object *wkView) {
  411. Assert(NULL != wkView && "ewk_view not created at this point");
  412. ViewModule::GeolocationSupport::Webkit2::
  413. initialize(m_model->Handle.Get());
  414. WKPageLoaderClient loaderClient = {
  415. kWKPageLoaderClientCurrentVersion, /* version */
  416. static_cast<void*>(this), /* clientinfo */
  417. didStartProvisionalLoadForFrameCallback, /* didStartProvisionalLoadForFrame */
  418. 0, /* didReceiveServerRedirectForProvisionalLoadForFrame */
  419. 0, /* didFailProvisionalLoadWithErrorForFrame */
  420. 0, /* didCommitLoadForFrame */
  421. 0, /* didFinishDocumentLoadForFrame */
  422. didFinishLoadForFrameCallback, /* didFinishLoadForFrame */
  423. 0, /* didFailLoadWithErrorForFrame */
  424. 0, /* didSameDocumentNavigationForFrame */
  425. didReceiveTitleForFrameCallback, /* didReceiveTitleForFrame */
  426. 0, /* didFirstLayoutForFrame */
  427. 0, /* didFirstVisuallyNonEmptyLayoutForFrame */
  428. 0, /* didRemoveFrameFromHierarchy */
  429. 0, /* didDisplayInsecureContentForFrame */
  430. 0, /* didRunInsecureContentForFrame */
  431. 0, /* canAuthenticateAgainstProtectionSpaceInFrame */
  432. 0, /* didReceiveAuthenticationChallengeInFrame */
  433. didStartProgressCallback, /* didStartProgressCallback */
  434. didChangeProgressCallback, /* didChangeProgress */
  435. didFinishProgressCallback, /* didFinishProgress */
  436. 0, /* processDidBecomeUnresponsive */
  437. 0, /* processDidBecomeResponsive */
  438. processDidCrashCallback, /* processDidCrash */
  439. 0, /* didChangeBackForwardList */
  440. 0, /* shouldGoToBackForwardListItem */
  441. 0, /* didFailToInitializePlugin */
  442. 0, /* didDetectXSSForFrame */
  443. 0, /* didNewFirstVisuallyNonEmptyLayout */
  444. 0, /* willGoToBackForwardListItem */
  445. 0, /* interactionOccurredWhileProcessUnresponsive */
  446. 0, /* pluginDidFail */
  447. };
  448. WKPageSetPageLoaderClient(ewk_view_WKPage_get(wkView), &loaderClient);
  449. //WKPageUIClient uiClient = {
  450. // kWKPageUIClientCurrentVersion, /* version */
  451. // static_cast<void*>(this), /* clientInfo */
  452. // 0, /* createNewPage_deprecatedForUseWithV0 */
  453. // 0, /* showPage*/
  454. // closeCallback, /* close */
  455. // 0, /* takeFocus */
  456. // 0, /* focus */
  457. // 0, /* unfocus */
  458. // 0, /* runJavaScriptAlert */
  459. // 0, /* runJavaScriptConfirm */
  460. // 0, /* runJavaScriptPrompt */
  461. // 0, /* setStatusText */
  462. // 0, /* mouseDidMoveOverElement */
  463. // 0, /* missingPluginButtonClicked */
  464. // 0, /* didNotHandleKeyEvent */
  465. // 0, /* didNotHandleWheelEvent */
  466. // 0, /* toolbarsAreVisible */
  467. // 0, /* setToolbarsAreVisible */
  468. // 0, /* menuBarIsVisible */
  469. // 0, /* setMenuBarIsVisible */
  470. // 0, /* statusBarIsVisible */
  471. // 0, /* setStatusBarIsVisible */
  472. // 0, /* isResizable */
  473. // 0, /* setIsResizable */
  474. // 0, /* getWindowFrame */
  475. // 0, /* setWindowFrame */
  476. // 0, /* runBeforeUnloadConfirmPanel */
  477. // 0, /* didDraw */
  478. // 0, /* pageDidScroll */
  479. // 0, /* exceededDatabaseQuota */
  480. // 0, /* runOpenPanel */
  481. // decidePolicyForGeolocationPermissionRequestCallback, /* decidePolicyForGeolocationPermissionRequest */
  482. // 0, /* headerHeight */
  483. // 0, /* footerHeight */
  484. // 0, /* drawHeader */
  485. // 0, /* drawFooter */
  486. // 0, /* printFrame */
  487. // 0, /* runModal */
  488. // 0, /* didCompleteRubberBandForMainFrame */
  489. // 0, /* saveDataToFileInDownloadsFolder */
  490. // 0, /* shouldInterruptJavaScript */
  491. // createNewPageCallback, /* createNewPage */
  492. // 0, /* mouseDidMoveOverElement */
  493. // decidePolicyForNotificationPermissionRequestCallback, /* decidePolicyForNotificationPermissionRequest */
  494. //};
  495. //WKPageSetPageUIClient(ewk_view_page_get(wkView), &uiClient);
  496. evas_object_smart_callback_add(
  497. wkView,
  498. EWK_CREATE_WINDOW,
  499. createWindowCallback,
  500. this);
  501. evas_object_smart_callback_add(
  502. wkView,
  503. EWK_CLOSE_WINDOW,
  504. closeWindowCallback,
  505. this);
  506. WKPagePolicyClient policyClient = {
  507. kWKPagePolicyClientCurrentVersion, /* version */
  508. static_cast<void*>(this), /* clientInfo */
  509. pageDecidePolicyForNavigationActionCallback, /* decidePolicyForNavigationAction */
  510. pageDecidePolicyForNewWindowActionCallback, /* decidePolicyForNewWindowAction */
  511. pageDecidePolicyForResponseCallback,
  512. 0, /* unableToImplementPolicy */
  513. };
  514. WKPageSetPagePolicyClient(ewk_view_WKPage_get(wkView),
  515. &policyClient);
  516. // EWK ContextMenu Callback
  517. //WKPageContextMenuClient contextMenuClient = {
  518. // kWKPageContextMenuClientCurrentVersion, /* version */
  519. // static_cast<void*>(this), /* clientInfo */
  520. // 0, /* getContextMenuFromProposedMenu_deprecatedForUseWithV0 */
  521. // 0, /* customContextMenuItemSelected */
  522. // 0, /* contextMenuDismissed */
  523. // pageContextMenuForGetMenuCallback /* getContextMenuFromProposedMenu */
  524. //};
  525. //WKPageSetPageContextMenuClient(ewk_view_page_get(wkView),
  526. // &contextMenuClient);
  527. evas_object_smart_callback_add(
  528. wkView,
  529. EWK_CONTEXTMENU_CUSTOMIZE,
  530. contextmenuCustomizeCallback,
  531. this);
  532. // WKPageFormClient formClient = {
  533. // kWKPageFormClientCurrentVersion, /* version */
  534. // static_cast<void*>(this), /* clientInfo */
  535. // willSubmitFormCallback, /* willSubmitForm */
  536. // };
  537. // WKPageSetPageFormClient(ewk_view_page_get(wkView), &formClient);
  538. evas_object_smart_callback_add(
  539. wkView,
  540. EWK_FORM_SUBMIT,
  541. formSubmitCallback,
  542. this);
  543. // EWK Geolocation Callback
  544. //WKGeolocationProvider geolocation_provider = {
  545. // kWKGeolocationProviderCurrentVersion,
  546. // this,
  547. // startUpdatingCallback,
  548. // stopUpdatingCallback
  549. //};
  550. //WKGeolocationManagerRef geolocation_manager_ref
  551. // = WKContextGetGeolocationManager(m_wkctx);
  552. //WKGeolocationManagerSetProvider(geolocation_manager_ref,
  553. // &geolocation_provider);
  554. evas_object_smart_callback_add(
  555. wkView,
  556. EWK_REQUEST_GEOLOCATION_PERMISSION,
  557. geolocationPermissionRequestCallback,
  558. this);
  559. // EWK Notification Callback
  560. //WKNotificationProvider notificationProvider = {
  561. // kWKNotificationProviderCurrentVersion, /* version */
  562. // static_cast<void*>(this), /* clientinfo */
  563. // showNotificationCallback, /* show */
  564. // 0, /* cancel */
  565. // 0, /* didDestroyNotification */
  566. // 0, /* addNotificationManager */
  567. // 0, /* removeNotificationManager */
  568. // 0, /* notificationPermissions */
  569. // 0, /* clearNotifications */
  570. //};
  571. //WKNotificationManagerSetProvider(WKContextGetNotificationManager(m_wkctx),
  572. // &notificationProvider);
  573. evas_object_smart_callback_add(
  574. wkView,
  575. EWK_NOTIFICATION_SHOW,
  576. notificationShowCallback,
  577. this);
  578. evas_object_smart_callback_add(
  579. wkView,
  580. EWK_NOTIFICATION_CANCEL,
  581. notificationCancelCallback,
  582. this);
  583. evas_object_smart_callback_add(
  584. wkView,
  585. EWK_NOTIFICATION_PERMISSION_REQUEST,
  586. notificationPermissionRequestCallback,
  587. this);
  588. evas_object_smart_callback_add(
  589. wkView,
  590. EWK_VIBRATION_VIBRATE,
  591. vibrationVibrateCallback,
  592. this);
  593. evas_object_smart_callback_add(
  594. wkView,
  595. EWK_VIBRATION_CANCEL,
  596. vibrationCancelCallback,
  597. this);
  598. // EWK Orientation Callback
  599. ewk_view_orientation_lock_callback_set(
  600. wkView,
  601. orientationLockCallback,
  602. this);
  603. }
  604. void ViewLogic::ewkClientDeinit(Evas_Object *wkView) {
  605. LogDebug("ewkClientDeinit");
  606. Assert(NULL != wkView && "ewk_view not created at this point");
  607. // deinit WKPageLoaderClient
  608. WKPageLoaderClient loaderClient = {
  609. 0, /* version */
  610. 0, /* clientinfo */
  611. 0, /* didStartProvisionalLoadForFrame */
  612. 0, /* didReceiveServerRedirectForProvisionalLoadForFrame */
  613. 0, /* didFailProvisionalLoadWithErrorForFrame */
  614. 0, /* didCommitLoadForFrame */
  615. 0, /* didFinishDocumentLoadForFrame */
  616. 0, /* didFinishLoadForFrame */
  617. 0, /* didFailLoadWithErrorForFrame */
  618. 0, /* didSameDocumentNavigationForFrame */
  619. 0, /* didReceiveTitleForFrame */
  620. 0, /* didFirstLayoutForFrame */
  621. 0, /* didFirstVisuallyNonEmptyLayoutForFrame */
  622. 0, /* didRemoveFrameFromHierarchy */
  623. 0, /* didDisplayInsecureContentForFrame */
  624. 0, /* didRunInsecureContentForFrame */
  625. 0, /* canAuthenticateAgainstProtectionSpaceInFrame */
  626. 0, /* didReceiveAuthenticationChallengeInFrame */
  627. 0, /* didStartProgressCallback */
  628. 0, /* didChangeProgress */
  629. 0, /* didFinishProgress */
  630. 0, /* processDidBecomeUnresponsive */
  631. 0, /* processDidBecomeResponsive */
  632. 0, /* processDidCrash */
  633. 0, /* didChangeBackForwardList */
  634. 0, /* shouldGoToBackForwardListItem */
  635. 0, /* didFailToInitializePlugin */
  636. 0, /* didDetectXSSForFrame */
  637. 0, /* didNewFirstVisuallyNonEmptyLayout */
  638. 0, /* willGoToBackForwardListItem */
  639. 0, /* interactionOccurredWhileProcessUnresponsive */
  640. 0, /* pluginDidFail */
  641. };
  642. WKPageSetPageLoaderClient(ewk_view_WKPage_get(wkView),
  643. &loaderClient);
  644. // deinit WKPageUIClient
  645. //WKPageUIClient uiClient = {
  646. // 0, /* version */
  647. // 0, /* clientInfo */
  648. // 0, /* createNewPage_deprecatedForUseWithV0 */
  649. // 0, /* showPage*/
  650. // 0, /* close */
  651. // 0, /* takeFocus */
  652. // 0, /* focus */
  653. // 0, /* unfocus */
  654. // 0, /* runJavaScriptAlert */
  655. // 0, /* runJavaScriptConfirm */
  656. // 0, /* runJavaScriptPrompt */
  657. // 0, /* setStatusText */
  658. // 0, /* mouseDidMoveOverElement */
  659. // 0, /* missingPluginButtonClicked */
  660. // 0, /* didNotHandleKeyEvent */
  661. // 0, /* didNotHandleWheelEvent */
  662. // 0, /* toolbarsAreVisible */
  663. // 0, /* setToolbarsAreVisible */
  664. // 0, /* menuBarIsVisible */
  665. // 0, /* setMenuBarIsVisible */
  666. // 0, /* statusBarIsVisible */
  667. // 0, /* setStatusBarIsVisible */
  668. // 0, /* isResizable */
  669. // 0, /* setIsResizable */
  670. // 0, /* getWindowFrame */
  671. // 0, /* setWindowFrame */
  672. // 0, /* runBeforeUnloadConfirmPanel */
  673. // 0, /* didDraw */
  674. // 0, /* pageDidScroll */
  675. // 0, /* exceededDatabaseQuota */
  676. // 0, /* runOpenPanel */
  677. // 0, /* decidePolicyForGeolocationPermissionRequest */
  678. // 0, /* headerHeight */
  679. // 0, /* footerHeight */
  680. // 0, /* drawHeader */
  681. // 0, /* drawFooter */
  682. // 0, /* printFrame */
  683. // 0, /* runModal */
  684. // 0, /* didCompleteRubberBandForMainFrame */
  685. // 0, /* saveDataToFileInDownloadsFolder */
  686. // 0, /* shouldInterruptJavaScript */
  687. // 0, /* createNewPage */
  688. // 0, /* mouseDidMoveOverElement */
  689. // 0, /* decidePolicyForNotificationPermissionRequest */
  690. //};
  691. //WKPageSetPageUIClient(ewk_view_page_get(wkView), &uiClient);
  692. evas_object_smart_callback_del(
  693. wkView,
  694. EWK_CREATE_WINDOW,
  695. createWindowCallback);
  696. evas_object_smart_callback_del(
  697. wkView,
  698. EWK_CLOSE_WINDOW,
  699. closeWindowCallback);
  700. // deinit WKPagePolicyClient
  701. WKPagePolicyClient policyClient = {
  702. 0, /* version */
  703. 0, /* clientInfo */
  704. 0, /* decidePolicyForNavigationAction */
  705. 0, /* decidePolicyForNewWindowAction */
  706. 0, /* decidePolicyForResponse */
  707. 0, /* unableToImplementPolicy */
  708. };
  709. WKPageSetPagePolicyClient(ewk_view_WKPage_get(wkView),
  710. &policyClient);
  711. // EWK ContextMenu Callback
  712. evas_object_smart_callback_del(
  713. wkView,
  714. EWK_CONTEXTMENU_CUSTOMIZE,
  715. contextmenuCustomizeCallback);
  716. // deinit WKPageFormClient
  717. // WKPageFormClient formClient = {
  718. // 0, /* version */
  719. // 0, /* clientInfo */
  720. // 0, /* willSubmitForm */
  721. // };
  722. // WKPageSetPageFormClient(ewk_view_page_get(wkView), &formClient);
  723. evas_object_smart_callback_del(
  724. wkView,
  725. EWK_FORM_SUBMIT,
  726. formSubmitCallback);
  727. // EWK Geolocation Callback
  728. evas_object_smart_callback_del(
  729. wkView,
  730. EWK_REQUEST_GEOLOCATION_PERMISSION,
  731. geolocationPermissionRequestCallback);
  732. // EWK Notification Callback
  733. evas_object_smart_callback_del(
  734. wkView,
  735. EWK_NOTIFICATION_SHOW,
  736. notificationShowCallback);
  737. evas_object_smart_callback_del(
  738. wkView,
  739. EWK_NOTIFICATION_CANCEL,
  740. notificationCancelCallback);
  741. evas_object_smart_callback_del(
  742. wkView,
  743. EWK_NOTIFICATION_PERMISSION_REQUEST,
  744. notificationPermissionRequestCallback);
  745. evas_object_smart_callback_del(
  746. wkView,
  747. EWK_VIBRATION_VIBRATE,
  748. vibrationVibrateCallback);
  749. evas_object_smart_callback_del(
  750. wkView,
  751. EWK_VIBRATION_CANCEL,
  752. vibrationCancelCallback);
  753. // EWK Orientation Callback
  754. ewk_view_orientation_lock_callback_set(
  755. wkView,
  756. NULL,
  757. NULL);
  758. }
  759. void ViewLogic::createEwkView()
  760. {
  761. LogDebug("createEwkVeiw");
  762. Evas_Object* newEwkView = ewk_view_add_with_context(
  763. evas_object_evas_get(m_window),
  764. m_ewkContext);
  765. if (!newEwkView) {
  766. LogError("WKView creation failed");
  767. Assert(false);
  768. }
  769. // set cookie policy
  770. // even arguments pass the ewkContext, this API should be called
  771. // after webkit Evas_Object is created
  772. ewk_context_cookies_policy_set(m_ewkContext, EWK_COOKIE_JAR_ACCEPT_ALWAYS);
  773. m_ewkViewList.push_back(newEwkView);
  774. m_currentEwkView = newEwkView;
  775. m_emptyView = true;
  776. }
  777. void ViewLogic::setStartPage()
  778. {
  779. //TODO: actually this localization should be done in requestWillSend
  780. // callback, but Webkit2 denies access to local files if it detects
  781. // that first loaded file is not 'local' so it wan't work
  782. DPL::OptionalString localizedUri = ViewModule::UriSupport::localizeURI(
  783. DPL::FromUTF8String(m_startUrl.c_str()),
  784. m_model);
  785. m_currentUri = DPL::ToUTF8String(*localizedUri);
  786. }
  787. void ViewLogic::prepareEwkView(Evas_Object *wkView)
  788. {
  789. LogDebug("prepareEwkView called");
  790. Assert(wkView);
  791. Ewk_Setting* setting = ewk_view_setting_get(wkView);
  792. // set user agent
  793. auto userAgentString =
  794. ViewModule::UserAgentSupport::getUserAgentFromVconf();
  795. if (!userAgentString.empty()) {
  796. LogDebug("Setting custom user agent as: " << userAgentString);
  797. ewk_view_user_agent_set(wkView, userAgentString.c_str());
  798. }
  799. // set custom header : language
  800. using namespace ViewModule::CustomHeaderSupport;
  801. std::string customHeaderString = getValueByField(ACCEPT_LANGUAGE);
  802. if (!customHeaderString.empty()) {
  803. LogDebug("custom field=[" << ACCEPT_LANGUAGE << "]");
  804. LogDebug("custom value=[" << customHeaderString << "]");
  805. ewk_view_custom_header_add(wkView,
  806. ACCEPT_LANGUAGE.c_str(),
  807. customHeaderString.c_str());
  808. }
  809. // enable webkit plugins
  810. WrtDB::WidgetDAOReadOnly dao(m_model->Handle.Get());
  811. if (dao.getWebkitPluginsRequired()) {
  812. ewk_setting_enable_plugins_set(setting, EINA_TRUE);
  813. } else {
  814. ewk_setting_enable_plugins_set(setting, EINA_FALSE);
  815. }
  816. // The followings are not implemeted yet by webkit2
  817. // ewk_view_setting_accelerated_compositing_enable_set(EINA_TRUE);
  818. // ewk_view_mode_set();
  819. // ewk_view_setting_enable_specified_plugin_set(EINA_TRUE, FLASH_MIME_TYPE);
  820. // ewk_view_setting_html5video_external_player_enable_set(EINA_FALSE);
  821. // ewk_view_show_ime_on_autofocus_set(EINA_TRUE);
  822. // elm_webview_show_magnifier_set(EINA_FALSE);
  823. ewk_setting_enable_scripts_set(setting, EINA_TRUE);
  824. ewk_setting_auto_load_images_set(setting, EINA_TRUE);
  825. ewk_setting_auto_fitting_set(setting, EINA_FALSE);
  826. // disable zoom option when user click the input field
  827. // this option is useful with the normal website
  828. // for the make user friendly, disable auto zoom in the webapp
  829. // The followings are not implemeted yet by webkit2
  830. // elm_webview_input_field_zoom_set(EINA_FALSE);
  831. // set cookie database path
  832. // The followings are not implemeted yet by webkit2
  833. // ewk_cookies_file_set(dao.getCookieDatabasePath().c_str()));
  834. // set visibility to WebCore. This value will be used for html5.
  835. // also, this value will be changed in the suspend, resume
  836. // or create window, close window.
  837. ewk_view_page_visibility_state_set(wkView,
  838. EWK_PAGE_VISIBILITY_STATE_VISIBLE,
  839. EINA_TRUE);
  840. }
  841. void ViewLogic::removeEwkView(Evas_Object *wkView)
  842. {
  843. LogInfo("removeEwkView called");
  844. Assert(wkView);
  845. Assert(0 != m_ewkViewList.size());
  846. // unregister webview callbacks
  847. ewkClientDeinit(wkView);
  848. // suspend NPAPI plugin - Not implemented by Webkit2
  849. // ewk_view_pause_or_resume_plugins();
  850. m_ewkViewList.remove(wkView);
  851. evas_object_del(wkView);
  852. }
  853. void ViewLogic::resumeEwkView(Evas_Object *wkView)
  854. {
  855. LogInfo("resumeEwkView called");
  856. Assert(wkView);
  857. // register webview callback
  858. ewkClientInit(wkView);
  859. // resume webkit
  860. resumeWebkit(wkView);
  861. return;
  862. }
  863. void ViewLogic::suspendEwkView(Evas_Object *wkView)
  864. {
  865. LogInfo("suspendEwkView called");
  866. Assert(wkView);
  867. // suspend webkit
  868. suspendWebkit(wkView);
  869. // unregister webview callbacks
  870. ewkClientDeinit(wkView);
  871. return;
  872. }
  873. void ViewLogic::resumeWebkit(Evas_Object *wkView)
  874. {
  875. LogDebug("resumeWebkit");
  876. Assert(wkView);
  877. // resume NPAPI plugin
  878. // The followings are not implemeted yet by webkit2
  879. // ewk_view_pause_or_resume_plugins(false);
  880. // ewk_view_pause_or_resume_video_audio(false);
  881. // ewk_view_javascript_resume();
  882. // ewk_view_enable_render();
  883. // ewk_view_reduce_plugins_frame_rate(false);
  884. ewk_view_resume(wkView);
  885. ewk_view_visibility_set(wkView, EINA_TRUE);
  886. ewk_view_page_visibility_state_set(wkView,
  887. EWK_PAGE_VISIBILITY_STATE_VISIBLE,
  888. EINA_FALSE);
  889. return;
  890. }
  891. void ViewLogic::suspendWebkit(Evas_Object *wkView)
  892. {
  893. LogDebug("suspendWebkit");
  894. Assert(wkView);
  895. // suspend the followings
  896. // The followings are not implemeted yet by webkit2
  897. // ewk_view_pause_or_resume_plugins(true);
  898. // ewk_view_pause_or_resume_video_audio(true);
  899. // send visibility event to webpage
  900. ewk_view_page_visibility_state_set(wkView,
  901. EWK_PAGE_VISIBILITY_STATE_HIDDEN,
  902. EINA_FALSE);
  903. ewk_view_suspend(wkView);
  904. ewk_view_visibility_set(wkView, EINA_FALSE);
  905. return;
  906. }
  907. void ViewLogic::contextMessageFromInjectedBundleCallback(
  908. const char* name,
  909. const char* body,
  910. char** returnData,
  911. void* clientInfo)
  912. {
  913. LogDebug("contextMessageFromInjectedBundleCallback called");
  914. Assert(clientInfo);
  915. ViewLogic* This = static_cast<ViewLogic*>(clientInfo);
  916. // didRecieveMessageFromInjectedBundleCallback - returnData is null
  917. // didReceiveSynchronousMessageCallback - returnData isn't null
  918. // WKContextInjectedBundleClient bundleClient = {
  919. // kWKContextInjectedBundleClientCurrentVersion,
  920. // static_cast<void*>(this),
  921. // &didRecieveMessageFromInjectedBundleCallback,
  922. // &didReceiveSynchronousMessageCallback
  923. // };
  924. if (NULL == returnData) {
  925. This->didRecieveMessageFromInjectedBundle(name, body);
  926. } else {
  927. This->didReceiveSynchronousMessage(name, body, returnData);
  928. }
  929. }
  930. void ViewLogic::didStartDownloadCallback(
  931. const char* downloadUrl,
  932. void* data)
  933. {
  934. LogDebug("didStartDownloadCallback called");
  935. Assert(data);
  936. ViewLogic* This = static_cast<ViewLogic*>(data);
  937. Assert(downloadUrl);
  938. LogDebug("download url = " << downloadUrl);
  939. This->m_appsSupport->downloadRequest(
  940. downloadUrl,
  941. NULL,
  942. NULL);
  943. }
  944. void ViewLogic::didStartProvisionalLoadForFrameCallback(
  945. WKPageRef /*page*/,
  946. WKFrameRef /*frame*/,
  947. WKTypeRef /*userData*/,
  948. const void *clientInfo)
  949. {
  950. LogDebug("didStartProvisionalLoadForFrameCallback called");
  951. Assert(clientInfo);
  952. ViewLogic* This = static_cast<ViewLogic*>(const_cast<void*>(clientInfo));
  953. evas_object_focus_set(This->m_currentEwkView, EINA_TRUE);
  954. }
  955. void ViewLogic::didFinishLoadForFrameCallback(
  956. WKPageRef /*page*/,
  957. WKFrameRef frame,
  958. WKTypeRef /*userData*/,
  959. const void *clientInfo)
  960. {
  961. LogDebug("didFinishLoadForFrameCallback called");
  962. Assert(clientInfo);
  963. ViewLogic* This = static_cast<ViewLogic*>(const_cast<void*>(clientInfo));
  964. // Fill id/password
  965. DPL::OptionalString urlOptionalString = ViewModule::Utils::toString(frame);
  966. if (urlOptionalString.IsNull()) {
  967. LogError("url is empty");
  968. } else {
  969. std::string urlStr = DPL::ToUTF8String(*urlOptionalString).c_str();
  970. DPL::OptionalString jsOptionalString =
  971. ViewModule::PasswordSupport::jsForAutoFillData(urlStr.c_str());
  972. if (jsOptionalString.IsNull()) {
  973. LogError("Fail to get JS String");
  974. } else {
  975. std::string jsStr = DPL::ToUTF8String(*jsOptionalString).c_str();
  976. ewk_view_script_execute(
  977. This->m_currentEwkView,
  978. jsStr.c_str(),
  979. didRunJavaScriptCallback,
  980. This);
  981. }
  982. }
  983. // call loadFinish callback to wrt-client
  984. if (This->m_cbs->loadFinish) {
  985. This->m_cbs->loadFinish(true, This->m_cbsData);
  986. }
  987. // check if 'appsevice' event is registed at the current frames.
  988. // If so, dispatch the event to frames.
  989. PluginModuleSupport::dispatchJavaScriptEvent(
  990. This->m_ewkContext,
  991. WrtPlugins::W3C::ServiceCustomEvent);
  992. }
  993. void ViewLogic::didReceiveTitleForFrameCallback(
  994. WKPageRef page,
  995. WKStringRef title,
  996. WKFrameRef /*frame*/,
  997. WKTypeRef /*userData*/,
  998. const void* clientInfo)
  999. {
  1000. LogDebug("didReceiveTitleForFrameCallback called");
  1001. Assert(clientInfo);
  1002. ViewLogic* This = static_cast<ViewLogic*>(const_cast<void*>(clientInfo));
  1003. DPL::OptionalString titleOptionalString =
  1004. ViewModule::Utils::toString(title);
  1005. if (titleOptionalString.IsNull()) {
  1006. LogDebug("title data is empty");
  1007. return;
  1008. }
  1009. std::string titleStr = DPL::ToUTF8String(*titleOptionalString);
  1010. LogDebug("Title = [" << titleStr << "]");
  1011. This->m_schemeSupport->HandleTizenScheme(titleStr.c_str(),
  1012. This->m_window,
  1013. page);
  1014. }
  1015. void ViewLogic::didStartProgressCallback(WKPageRef /*page*/,
  1016. const void* clientinfo)
  1017. {
  1018. LogDebug("didStartProgressCallback");
  1019. Assert(clientinfo);
  1020. // TODO : Progress control
  1021. }
  1022. void ViewLogic::didChangeProgressCallback(WKPageRef page,
  1023. const void* /*clientinfo*/)
  1024. {
  1025. double progress = WKPageGetEstimatedProgress(page);
  1026. LogDebug("didChangeProgressCallback progress = " << progress);
  1027. }
  1028. void ViewLogic::didFinishProgressCallback(WKPageRef /*page*/,
  1029. const void* clientinfo)
  1030. {
  1031. LogDebug("didFinishProgressCallback");
  1032. ViewLogic const * const view = static_cast<ViewLogic const * const>(clientinfo);
  1033. if (view->m_cbs->progressFinish)
  1034. view->m_cbs->progressFinish(view->m_cbsData);
  1035. }
  1036. void ViewLogic::createWindowCallback(
  1037. void* data,
  1038. Evas_Object* ,
  1039. void* eventInfo)
  1040. {
  1041. LogDebug("createWindowCallback");
  1042. Assert(data);
  1043. ViewLogic* This = static_cast<ViewLogic*>(data);
  1044. Evas_Object* currentEwkView = This->m_currentEwkView;
  1045. // suspend current ewkview
  1046. /* In case we support many pages in parallel
  1047. then view should not be suspended*/
  1048. //This->suspendEwkView(currentEwkView);
  1049. if (This->m_cbs->bufferUnset) {
  1050. This->m_cbs->bufferUnset(currentEwkView, This->m_cbsData);
  1051. }
  1052. // create new ewkview
  1053. This->createEwkView();
  1054. Evas_Object* newEwkView = This->m_currentEwkView;
  1055. // initialize new ewkview
  1056. This->setStartPage();
  1057. This->ewkClientInit(newEwkView);
  1058. This->prepareEwkView(newEwkView);
  1059. // show new ewkview
  1060. if (This->m_cbs->bufferUnset) {
  1061. This->m_cbs->bufferSet(newEwkView, This->m_cbsData);
  1062. }
  1063. *(static_cast<Evas_Object **>(eventInfo)) = newEwkView;
  1064. }
  1065. void ViewLogic::closeWindowCallback(
  1066. void* data,
  1067. Evas_Object* /*obj*/,
  1068. void* /*eventInfo*/)
  1069. {
  1070. LogDebug("closeWindowCallback");
  1071. ecore_idler_add(windowCloseIdlerCallback, data);
  1072. }
  1073. void ViewLogic::pageDecidePolicyForResponseCallback(
  1074. WKPageRef /*page*/,
  1075. WKFrameRef frame,
  1076. WKURLResponseRef response,
  1077. WKURLRequestRef request,
  1078. WKFramePolicyListenerRef listener,
  1079. WKTypeRef /*userData*/,
  1080. const void* clientInfo)
  1081. {
  1082. Assert(clientInfo);
  1083. ViewLogic* This = static_cast<ViewLogic*>(const_cast<void*>(clientInfo));
  1084. Assert(response);
  1085. WKStringRef contentTypeRef = WKURLResponseEflCopyContentType(response);
  1086. Assert(contentTypeRef);
  1087. if (WKFrameCanShowMIMEType(frame, contentTypeRef)) {
  1088. LogDebug("Accepting this content type to be used by WK2");
  1089. WKFramePolicyListenerUse(listener);
  1090. WKRelease(contentTypeRef);
  1091. return;
  1092. }
  1093. Assert(request);
  1094. // get uri information
  1095. DPL::OptionalString requestOptionalStr =
  1096. ViewModule::Utils::toString(request);
  1097. if (requestOptionalStr.IsNull()) {
  1098. LogDebug("uri data is empty");
  1099. return;
  1100. }
  1101. std::string uriStr = DPL::ToUTF8String(*requestOptionalStr).c_str();
  1102. const char* uri = uriStr.c_str();
  1103. LogDebug("uri = [" << uri << "]");
  1104. // get content information
  1105. DPL::OptionalString contentOptionalStr =
  1106. ViewModule::Utils::toString(contentTypeRef);
  1107. std::string contentStr;
  1108. if (contentOptionalStr.IsNull()) {
  1109. LogDebug("content data is empty");
  1110. } else {
  1111. contentStr = DPL::ToUTF8String(*contentOptionalStr).c_str();
  1112. }
  1113. LogDebug("content type = [" << contentStr << "]");
  1114. // get cookie information
  1115. WKStringRef cookiesRef = WKURLRequestEflCopyCookies(request);
  1116. Assert(cookiesRef);
  1117. DPL::OptionalString cookiesOptionalStr =
  1118. ViewModule::Utils::toString(cookiesRef);
  1119. std::string cookieStr;
  1120. if (cookiesOptionalStr.IsNull()) {
  1121. LogDebug("cookies are empty");
  1122. } else {
  1123. cookieStr = DPL::ToUTF8String(*cookiesOptionalStr).c_str();
  1124. }
  1125. LogDebug("cookie = [" << cookieStr << "]");
  1126. LogDebug("Content not supported, will be opened in external app");
  1127. WKFramePolicyListenerIgnore(listener);
  1128. This->m_appsSupport->downloadRequest(
  1129. uri,
  1130. contentStr.empty() ? NULL : contentStr.c_str(),
  1131. cookieStr.empty() ? NULL : cookieStr.c_str());
  1132. WKRelease(contentTypeRef);
  1133. WKRelease(cookiesRef);
  1134. }
  1135. void ViewLogic::pageDecidePolicyForNavigationActionCallback(
  1136. WKPageRef page,
  1137. WKFrameRef frame,
  1138. WKFrameNavigationType /*navigationType*/,
  1139. WKEventModifiers /*modifiers*/,
  1140. WKEventMouseButton /*mouseButton*/,
  1141. WKURLRequestRef request,
  1142. WKFramePolicyListenerRef listener,
  1143. WKTypeRef /*userData*/,
  1144. const void* clientInfo)
  1145. {
  1146. LogDebug("Accepting URL: " << ViewModule::Utils::toString(request));
  1147. Assert(clientInfo);
  1148. ViewLogic* This = static_cast<ViewLogic*>(const_cast<void*>(clientInfo));
  1149. if (This->m_schemeSupport->filterURIByScheme(page,
  1150. frame,
  1151. request,
  1152. false,
  1153. This->m_model,
  1154. This->m_window))
  1155. {
  1156. LogDebug("use");
  1157. WKFramePolicyListenerUse(listener);
  1158. }
  1159. else
  1160. {
  1161. if(This->m_emptyView)
  1162. {
  1163. /*
  1164. * The view is empty and scheme has been handled externally. When
  1165. * user gets back from the external application he'd see blank page
  1166. * and won't be able to navigate back. This happens when window.open
  1167. * is used to handle schemes like sms/mms/mailto (for example in
  1168. * WAC web standards tests: WS-15XX).
  1169. *
  1170. * To solve the problem, the empty view is removed from the stack
  1171. * and the previous one is shown. This is not an elegant solution
  1172. * but we don't have a better one.
  1173. */
  1174. LogInfo("Scheme has been handled externally. Removing empty view.");
  1175. if (ewk_view_back_possible(This->m_currentEwkView)) {
  1176. // go back to previous WKPage
  1177. ewk_view_back(This->m_currentEwkView);
  1178. } else {
  1179. // stop current WKPage
  1180. ewk_view_stop(This->m_currentEwkView);
  1181. ecore_idler_add(windowCloseIdlerCallback, This);
  1182. }
  1183. }
  1184. LogDebug("ignore");
  1185. WKFramePolicyListenerIgnore(listener);
  1186. }
  1187. }
  1188. void ViewLogic::pageDecidePolicyForNewWindowActionCallback(
  1189. WKPageRef page,
  1190. WKFrameRef frame,
  1191. WKFrameNavigationType /*navigationType*/,
  1192. WKEventModifiers /*modifiers*/,
  1193. WKEventMouseButton /*mouseButton*/,
  1194. WKURLRequestRef request,
  1195. WKStringRef /*frameName*/,
  1196. WKFramePolicyListenerRef listener,
  1197. WKTypeRef /*userData*/,
  1198. const void* clientInfo)
  1199. {
  1200. LogDebug("Accepting URL: " << ViewModule::Utils::toString(request));
  1201. Assert(clientInfo);
  1202. ViewLogic* This = static_cast<ViewLogic*>(const_cast<void*>(clientInfo));
  1203. if (This->m_schemeSupport->filterURIByScheme(page,
  1204. frame,
  1205. request,
  1206. true,
  1207. This->m_model,
  1208. This->m_window))
  1209. {
  1210. WKFramePolicyListenerUse(listener);
  1211. }
  1212. else
  1213. {
  1214. // scheme handled
  1215. WKFramePolicyListenerIgnore(listener);
  1216. }
  1217. }
  1218. void ViewLogic::contextmenuCustomizeCallback(
  1219. void* data,
  1220. Evas_Object* /*obj*/,
  1221. void* eventInfo)
  1222. {
  1223. LogDebug("contextmenuCustomizeCallback called");
  1224. Assert(data);
  1225. Assert(eventInfo);
  1226. ViewLogic* This = static_cast<ViewLogic*>(const_cast<void*>(data));
  1227. Ewk_Context_Menu* menu = static_cast<Ewk_Context_Menu*>(eventInfo);
  1228. if ((This->m_model->Type.Get().appType == WrtDB::APP_TYPE_TIZENWEBAPP) &&
  1229. (This->m_model->SettingList.Get().getContextMenu()
  1230. == ContextMenu_Disable))
  1231. {
  1232. LogDebug("ContextMenu Disable!!");
  1233. for (unsigned int idx = 0; idx < ewk_context_menu_item_count(menu);) {
  1234. Ewk_Context_Menu_Item* item = ewk_context_menu_nth_item_get(menu, idx);
  1235. Assert(item);
  1236. ewk_context_menu_item_remove(menu, item);
  1237. }
  1238. } else {
  1239. LogDebug("ContextMenu Enable!!");
  1240. for (unsigned int idx = 0; idx < ewk_context_menu_item_count(menu);) {
  1241. Ewk_Context_Menu_Item* item = ewk_context_menu_nth_item_get(menu, idx);
  1242. Assert(item);
  1243. Ewk_Context_Menu_Item_Tag tag = ewk_context_menu_item_tag_get(item);
  1244. switch (tag) {
  1245. case kWKContextMenuItemTagOpenImageInNewWindow:
  1246. ewk_context_menu_item_remove(menu, item);
  1247. break;
  1248. default:
  1249. idx++;
  1250. break;
  1251. }
  1252. }
  1253. }
  1254. }
  1255. void ViewLogic::formSubmitCallback(
  1256. void* /*data*/,
  1257. Evas_Object* /*obj*/,
  1258. void* eventInfo)
  1259. {
  1260. LogDebug("formSubmitCallback called");
  1261. Assert(eventInfo);
  1262. Ewk_Form_Data* formData = static_cast<Ewk_Form_Data*>(eventInfo);
  1263. const char* uri = ewk_form_data_url_get(formData);
  1264. if (!uri) {
  1265. LogError("URL is empty");
  1266. return;
  1267. }
  1268. Eina_Hash* userData = ewk_form_data_values_get(formData);
  1269. ViewModule::PasswordSupport::submitClicked(uri, userData);
  1270. }
  1271. void ViewLogic::geolocationPermissionRequestCallback(
  1272. void* /*data*/,
  1273. Evas_Object* /*obj*/,
  1274. void* eventInfo)
  1275. {
  1276. LogDebug("geolocationPermissionRequestCallback called");
  1277. Assert(eventInfo);
  1278. ViewModule::GeolocationSupport::Webkit2::
  1279. geolocationPermissionRequest(eventInfo);
  1280. return;
  1281. }
  1282. void ViewLogic::notificationShowCallback(
  1283. void* data,
  1284. Evas_Object* /*obj*/,
  1285. void* eventInfo)
  1286. {
  1287. LogDebug("notificationShowCallback called");
  1288. Assert(data);
  1289. ViewLogic* This = static_cast<ViewLogic*>(data);
  1290. Assert(eventInfo);
  1291. Ewk_Notification* noti = static_cast<Ewk_Notification*>(eventInfo);
  1292. using namespace ViewModule::WebNotification;
  1293. WebNotificationDataPtr notiData(
  1294. new WebNotificationData(
  1295. This->m_model,
  1296. ewk_notification_id_get(noti)));
  1297. DPL::OptionalString string =
  1298. DPL::FromUTF8String(ewk_notification_icon_url_get(noti));
  1299. if (!string.IsNull()) {
  1300. notiData->m_iconURL = DPL::ToUTF8String(*string);
  1301. }
  1302. string = DPL::FromUTF8String(ewk_notification_title_get(noti));
  1303. if (!string.IsNull()) {
  1304. notiData->m_title = DPL::ToUTF8String(*string);
  1305. }
  1306. string = DPL::FromUTF8String(ewk_notification_body_get(noti));
  1307. if (!string.IsNull()) {
  1308. notiData->m_body = DPL::ToUTF8String(*string);
  1309. }
  1310. LogInfo("notification id : " << notiData->m_id);
  1311. LogInfo("notification iconURL : " << notiData->m_iconURL);
  1312. LogInfo("notification title : " << notiData->m_title);
  1313. LogInfo("notification body : " << notiData->m_body);
  1314. showWebNotification(notiData);
  1315. ewk_notification_showed(This->m_ewkContext, ewk_notification_id_get(noti));
  1316. }
  1317. void ViewLogic::notificationCancelCallback(
  1318. void* /*data*/,
  1319. Evas_Object* /*obj*/,
  1320. void* /*eventInfo*/)
  1321. {
  1322. LogDebug("notificationCancelCallback called");
  1323. }
  1324. void ViewLogic::notificationPermissionRequestCallback(
  1325. void* data,
  1326. Evas_Object* /*obj*/,
  1327. void* eventInfo)
  1328. {
  1329. LogDebug("notificationPermissionRequestCallback called");
  1330. Assert(data);
  1331. ViewLogic* This = static_cast<ViewLogic*>(data);
  1332. Assert(eventInfo);
  1333. Ewk_Notification_Permission_Request* request =
  1334. static_cast<Ewk_Notification_Permission_Request*>(eventInfo);
  1335. ewk_notification_permission_request_response(
  1336. This->m_ewkContext,
  1337. request,
  1338. EINA_TRUE);
  1339. return;
  1340. }
  1341. void ViewLogic::vibrationVibrateCallback(
  1342. void* data,
  1343. Evas_Object* /*obj*/,
  1344. void* eventInfo)
  1345. {
  1346. LogDebug("vibrationVibrateCallback called");
  1347. Assert(data);
  1348. ViewLogic* This = static_cast<ViewLogic*>(data);
  1349. Assert(eventInfo);
  1350. const long vibrationTime = *(static_cast<const long*>(eventInfo));
  1351. This->m_vibrationSupport->startVibration(vibrationTime);
  1352. return;
  1353. }
  1354. void ViewLogic::vibrationCancelCallback(
  1355. void* data,
  1356. Evas_Object* /*obj*/

Large files files are truncated, but you can click here to view the full file