Limit number of opened tabs in brower
[profile/tv/apps/web/browser.git] / services / WebKitEngineService / WebView.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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 /*
18  * WebView.cpp
19  *
20  *  Created on: Apr 1, 2014
21  *      Author: p.rafalski
22  */
23
24 #include "WebView.h"
25
26 #if defined(USE_EWEBKIT)
27 #include <ewk_chromium.h>
28 #endif
29
30 #include <boost/format.hpp>
31 #include <boost/regex.hpp>
32 #include <boost/algorithm/string/regex.hpp>
33 #include <boost/algorithm/string/classification.hpp>
34 #include <boost/algorithm/string/split.hpp>
35 #include <Elementary.h>
36 #include <Evas.h>
37
38 #include "AbstractWebEngine/AbstractWebEngine.h"
39 #include "AbstractWebEngine/TabThumbCache.h"
40 #include "app_common.h"
41 #include "BrowserAssert.h"
42 #include "BrowserLogger.h"
43 #include "EflTools.h"
44 #include "GeneralTools.h"
45 #include "Tools/WorkQueue.h"
46 #include "ServiceManager.h"
47
48 #define certificate_crt_path CERTS_DIR
49 #if MERGE_ME
50 #define APPLICATION_NAME_FOR_USER_AGENT "SamsungBrowser/1.0"
51 #else
52 #define APPLICATION_NAME_FOR_USER_AGENT "Mozilla/5.0 (X11; SMART-TV; Linux) AppleWebkit/538.1 (KHTML, like Gecko) Safari/538.1"
53 #endif
54
55 //TODO: temporary user agent for mobile display, change to proper one
56 #define APPLICATION_NAME_FOR_USER_AGENT_MOBILE "Mozilla/5.0 (Linux; Tizen 3.0; SAMSUNG SM-Z130H) AppleWebKit/538.1 (KHTML, like Gecko) SamsungBrowser/1.0 Mobile Safari/538.1"
57
58 using namespace tizen_browser::tools;
59
60 namespace tizen_browser {
61 namespace basic_webengine {
62 namespace webkitengine_service {
63
64 const std::string WebView::COOKIES_PATH = "cookies";
65
66 WebView::WebView(Evas_Object * obj, TabId tabId)
67     : m_parent(obj)
68     , m_tabId(tabId)
69     , m_ewkContext(ewk_context_new())
70     , m_title(std::string())
71     , m_ewkView(nullptr)
72     , m_isLoading(false)
73     , m_loadError(false)
74 {
75     config.load("whatever");
76 }
77
78 WebView::~WebView()
79 {
80     BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
81
82     if (m_ewkView) {
83         unregisterCallbacks();
84     }
85
86     ewk_context_delete(m_ewkContext);
87 }
88
89 void WebView::init(bool desktopMode, Evas_Object * opener)
90 {
91 #if defined(USE_EWEBKIT)
92     M_ASSERT(m_ewkContext);
93     m_ewkView = ewk_view_add_with_context(evas_object_evas_get(m_parent), m_ewkContext);
94
95     evas_object_data_set(m_ewkView, "_container", this);
96     BROWSER_LOGD("%s:%d %s self=%p", __FILE__, __LINE__, __func__, this);
97
98     evas_object_color_set(m_ewkView, 255, 255, 255, 255);
99     evas_object_size_hint_weight_set(m_ewkView, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
100     evas_object_size_hint_align_set(m_ewkView, EVAS_HINT_FILL, EVAS_HINT_FILL);
101     if (desktopMode) {
102         switchToDesktopMode();
103     } else {
104         switchToMobileMode();
105     }
106     //\todo: when value is other than 1.0, scroller is located improperly
107 //    ewk_view_device_pixel_ratio_set(m_ewkView, 1.0f);
108
109 #if PLATFORM(TIZEN)
110     ewk_view_resume(m_ewkView);
111 #endif
112
113     ewk_context_cache_model_set(m_ewkContext, EWK_CACHE_MODEL_PRIMARY_WEBBROWSER);
114     std::string path = app_get_data_path() + COOKIES_PATH;
115     ewk_cookie_manager_persistent_storage_set(ewk_context_cookie_manager_get(m_ewkContext),  path.c_str(), EWK_COOKIE_PERSISTENT_STORAGE_SQLITE);
116
117     setupEwkSettings();
118     registerCallbacks();
119 #else
120     m_ewkView = evas_object_rectangle_add(evas_object_evas_get(m_parent));
121 #endif
122 }
123
124 void WebView::registerCallbacks()
125 {
126 #if defined(USE_EWEBKIT)
127     evas_object_smart_callback_add(m_ewkView, "load,started", __loadStarted, this);
128     evas_object_smart_callback_add(m_ewkView, "load,stop", __loadStop, this);
129     evas_object_smart_callback_add(m_ewkView, "load,finished", __loadFinished, this);
130     evas_object_smart_callback_add(m_ewkView, "load,progress", __loadProgress, this);
131     evas_object_smart_callback_add(m_ewkView, "load,error", __loadError, this);
132
133     evas_object_smart_callback_add(m_ewkView, "title,changed", __titleChanged, this);
134     evas_object_smart_callback_add(m_ewkView, "url,changed", __urlChanged, this);
135
136     evas_object_smart_callback_add(m_ewkView, "back,forward,list,changed", __backForwardListChanged, this);
137
138     evas_object_smart_callback_add(m_ewkView, "create,window", __newWindowRequest, this);
139     evas_object_smart_callback_add(m_ewkView, "close,window", __closeWindowRequest, this);
140
141     evas_object_smart_callback_add(m_ewkView, "geolocation,permission,request", __geolocationPermissionRequest, this);
142     evas_object_smart_callback_add(m_ewkView, "usermedia,permission,request", __usermediaPermissionRequest, this);
143     evas_object_smart_callback_add(m_ewkView, "notification,permission,request", __notificationPermissionRequest, this);
144     evas_object_smart_callback_add(m_ewkView, "authentication,request", __authenticationRequest, this);
145     evas_object_smart_callback_add(m_ewkView, "request,certificate,confirm", __requestCertificationConfirm, this);
146
147     evas_object_event_callback_add(m_ewkView, EVAS_CALLBACK_MOUSE_DOWN, __setFocusToEwkView, this);
148     evas_object_smart_callback_add(m_ewkView, "icon,received", __faviconChanged, this);
149
150     evas_object_smart_callback_add(m_ewkView, "editorclient,ime,closed", __IMEClosed, this);
151     evas_object_smart_callback_add(m_ewkView, "editorclient,ime,opened", __IMEOpened, this);
152 #endif
153 }
154
155 void WebView::unregisterCallbacks()
156 {
157 #if defined(USE_EWEBKIT)
158     evas_object_smart_callback_del_full(m_ewkView, "load,started", __loadStarted, this);
159     evas_object_smart_callback_del_full(m_ewkView, "load,stop", __loadStop, this);
160     evas_object_smart_callback_del_full(m_ewkView, "load,finished", __loadFinished, this);
161     evas_object_smart_callback_del_full(m_ewkView, "load,progress", __loadProgress, this);
162     evas_object_smart_callback_del_full(m_ewkView, "load,error", __loadError, this);
163
164     evas_object_smart_callback_del_full(m_ewkView, "title,changed", __titleChanged, this);
165     evas_object_smart_callback_del_full(m_ewkView, "url,changed", __urlChanged, this);
166
167     evas_object_smart_callback_del_full(m_ewkView, "back,forward,list,changed", __backForwardListChanged, this);
168
169     evas_object_smart_callback_del_full(m_ewkView, "create,window", __newWindowRequest, this);
170     evas_object_smart_callback_del_full(m_ewkView, "close,window", __closeWindowRequest, this);
171
172     evas_object_smart_callback_del_full(m_ewkView, "geolocation,permission,request", __geolocationPermissionRequest, this);
173     evas_object_smart_callback_del_full(m_ewkView, "usermedia,permission,request", __usermediaPermissionRequest, this);
174     evas_object_smart_callback_del_full(m_ewkView, "notification,permission,request", __notificationPermissionRequest, this);
175     evas_object_smart_callback_del_full(m_ewkView, "authentication,request", __authenticationRequest, this);
176     evas_object_smart_callback_del_full(m_ewkView, "request,certificate,confirm", __requestCertificationConfirm, this);
177
178     evas_object_event_callback_del(m_ewkView, EVAS_CALLBACK_MOUSE_DOWN, __setFocusToEwkView);
179     evas_object_smart_callback_del_full(m_ewkView, "icon,received", __faviconChanged, this);
180
181     evas_object_smart_callback_del_full(m_ewkView, "editorclient,ime,closed", __IMEClosed, this);
182     evas_object_smart_callback_del_full(m_ewkView, "editorclient,ime,opened", __IMEOpened, this);
183 #endif
184 }
185
186 void WebView::setupEwkSettings()
187 {
188 #if defined(USE_EWEBKIT)
189 #if PLATFORM(TIZEN)
190     Ewk_Settings * settings = ewk_view_settings_get(m_ewkView);
191     ewk_settings_uses_keypad_without_user_action_set(settings, EINA_FALSE);
192 #endif
193 #endif
194 }
195
196 Evas_Object * WebView::getLayout()
197 {
198     return m_ewkView;
199 }
200
201 void WebView::setURI(const std::string & uri)
202 {
203     BROWSER_LOGD("%s:%d %s uri=%s", __FILE__, __LINE__, __func__, uri.c_str());
204 #if defined(USE_EWEBKIT)
205     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
206     ewk_view_url_set(m_ewkView, uri.c_str());
207     m_loadError = false;
208 #endif
209 }
210
211 std::string WebView::getURI(void)
212 {
213 #if defined(USE_EWEBKIT)
214     BROWSER_LOGD("%s:%d %s uri=%s", __FILE__, __LINE__, __func__, ewk_view_url_get(m_ewkView));
215     return fromChar(ewk_view_url_get(m_ewkView));
216 #else
217     return std::string();
218 #endif
219 }
220
221 std::string WebView::getTitle(void)
222 {
223     return m_title;
224 }
225
226 void WebView::stopLoading(void)
227 {
228 #if defined(USE_EWEBKIT)
229     ewk_view_stop(m_ewkView);
230 #endif
231     loadStop();
232 }
233
234 void WebView::reload(void)
235 {
236 #if defined(USE_EWEBKIT)
237     if(m_loadError)
238     {
239         m_loadError = false;
240         ewk_view_url_set(m_ewkView, ewk_view_url_get(m_ewkView));
241     }
242     else
243         ewk_view_reload(m_ewkView);
244 #endif
245 }
246
247 void WebView::back(void)
248 {
249 #if defined(USE_EWEBKIT)
250     m_loadError = false;
251     ewk_view_back(m_ewkView);
252 #endif
253 }
254
255 void WebView::forward(void)
256 {
257 #if defined(USE_EWEBKIT)
258     m_loadError = false;
259     ewk_view_forward(m_ewkView);
260 #endif
261 }
262
263 bool WebView::isBackEnabled(void)
264 {
265 #if defined(USE_EWEBKIT)
266     return ewk_view_back_possible(m_ewkView);
267 #else
268     return false;
269 #endif
270 }
271
272 bool WebView::isForwardEnabled(void)
273 {
274 #if defined(USE_EWEBKIT)
275     return ewk_view_forward_possible(m_ewkView);
276 #else
277     return false;
278 #endif
279 }
280
281 bool WebView::isLoading()
282 {
283     return m_isLoading;
284 }
285
286 bool WebView::isLoadError() const
287 {
288     return m_loadError;
289 }
290
291 void WebView::setPrivateMode(bool state)
292 {
293     BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
294     M_ASSERT(m_ewkView);
295
296 #if defined(USE_EWEBKIT)
297 #if PLATFORM(TIZEN)
298     Ewk_Settings * settings = ewk_view_settings_get(m_ewkView);
299 #else
300     Ewk_Settings * settings = ewk_page_group_settings_get(ewk_view_page_group_get(m_ewkView));
301 #endif
302     ewk_settings_private_browsing_enabled_set(settings, state);
303     if (m_ewkView)
304     {
305         Ewk_Context *context = ewk_view_context_get(m_ewkView);
306         if (context)
307         {
308             if(state)
309             {
310                  ewk_cookie_manager_accept_policy_set(ewk_context_cookie_manager_get(context), EWK_COOKIE_ACCEPT_POLICY_NEVER);
311             }
312             else
313             {
314                  ewk_cookie_manager_accept_policy_set(ewk_context_cookie_manager_get(context), EWK_COOKIE_ACCEPT_POLICY_ALWAYS);
315             }
316         }
317     }
318 #endif
319 }
320
321 void WebView::confirmationResult(WebConfirmationPtr confirmation)
322 {
323     BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
324
325 #if defined(USE_EWEBKIT)
326 #if PLATFORM(TIZEN)
327     switch(confirmation->getConfirmationType()) {
328     case WebConfirmation::ConfirmationType::Geolocation: {
329         Ewk_Geolocation_Permission_Request *request = m_confirmationGeolocationMap[confirmation];
330         Eina_Bool result;
331         if (confirmation->getResult() == WebConfirmation::ConfirmationResult::Confirmed)
332             result = EINA_TRUE;
333         else if (confirmation->getResult() == WebConfirmation::ConfirmationResult::Rejected)
334             result = EINA_FALSE;
335         else {
336             BROWSER_LOGE("Wrong ConfirmationResult");
337             break;
338         }
339         // set geolocation permission
340         ewk_geolocation_permission_reply(request, result);
341         ewk_view_resume(m_ewkView);
342
343         // remove from map
344         m_confirmationGeolocationMap.erase(confirmation);
345         break;
346     }
347     case WebConfirmation::ConfirmationType::UserMedia: {
348         Ewk_User_Media_Permission_Request *request = m_confirmationUserMediaMap[confirmation];
349         Eina_Bool result;
350         if (confirmation->getResult() == WebConfirmation::ConfirmationResult::Confirmed)
351             result = EINA_TRUE;
352         else if (confirmation->getResult() == WebConfirmation::ConfirmationResult::Rejected)
353             result = EINA_FALSE;
354         else {
355             BROWSER_LOGE("Wrong ConfirmationResult");
356             break;
357         };
358
359         // set usermedia permission
360         ewk_user_media_permission_reply(request, result);
361         ewk_view_resume(m_ewkView);
362
363         // remove from map
364         m_confirmationUserMediaMap.erase(confirmation);
365         break;
366     }
367     case WebConfirmation::ConfirmationType::Notification: {
368         Ewk_Notification_Permission_Request *request = m_confirmationNotificationMap[confirmation];
369         Eina_Bool result;
370         if (confirmation->getResult() == WebConfirmation::ConfirmationResult::Confirmed)
371             result = EINA_TRUE;
372         else if (confirmation->getResult() == WebConfirmation::ConfirmationResult::Rejected)
373             result = EINA_FALSE;
374         else {
375             BROWSER_LOGE("Wrong ConfirmationResult");
376             break;
377         }
378
379         // set notification permission
380         ewk_notification_permission_reply(request, result);
381         ewk_view_resume(m_ewkView);
382
383         // remove from map
384         m_confirmationNotificationMap.erase(confirmation);
385         break;
386     }
387     case WebConfirmation::ConfirmationType::CertificateConfirmation: {
388         CertificateConfirmationPtr cert = std::dynamic_pointer_cast<CertificateConfirmation, WebConfirmation>(confirmation);
389         Ewk_Certificate_Policy_Decision *request = m_confirmationCertificatenMap[cert];
390         Eina_Bool result;
391         if (cert->getResult() == WebConfirmation::ConfirmationResult::Confirmed)
392             result = EINA_TRUE;
393         else if (cert->getResult() == WebConfirmation::ConfirmationResult::Rejected)
394             result = EINA_FALSE;
395         else {
396             BROWSER_LOGE("Wrong ConfirmationResult");
397             break;
398         }
399
400         // set certificate confirmation
401         BROWSER_LOGE("NOT IMPLEMENTED: Certificate Confirmation handling!");
402
403         // remove from map
404         m_confirmationCertificatenMap.erase(cert);
405         break;
406     }
407     case WebConfirmation::ConfirmationType::Authentication: {
408         AuthenticationConfirmationPtr auth = std::dynamic_pointer_cast<AuthenticationConfirmation, WebConfirmation>(confirmation);
409         Ewk_Auth_Request *request = m_confirmationAuthenticationMap[auth];
410         if (auth->getResult() == WebConfirmation::ConfirmationResult::Confirmed) {
411             BROWSER_LOGE("NOT IMPLEMENTED: Autenthication Request Confirmation handling!");
412         } else if (auth->getResult() == WebConfirmation::ConfirmationResult::Rejected) {
413             BROWSER_LOGE("NOT IMPLEMENTED: Autenthication Request Rejection handling!");
414         } else {
415             BROWSER_LOGE("Wrong ConfirmationResult");
416             break;
417         }
418
419         // remove from map
420         m_confirmationAuthenticationMap.erase(auth);
421         break;
422     }
423     default:
424         break;
425     }
426 #else
427    (void)confirmation;
428 #endif
429 #endif
430 }
431
432 std::shared_ptr<BrowserImage> WebView::captureSnapshot(int targetWidth, int targetHeight)
433 {
434     BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
435     M_ASSERT(m_ewkView);
436     M_ASSERT(targetWidth);
437     M_ASSERT(targetHeight);
438     Evas_Coord vw, vh;
439     std::shared_ptr<BrowserImage> noImage = std::make_shared<BrowserImage>();
440     evas_object_geometry_get(m_ewkView, nullptr, nullptr, &vw, &vh);
441     if (vw == 0 || vh == 0)
442         return noImage;
443
444     Eina_Rectangle area;
445     double snapshotProportions = (double)(targetWidth) /(double)(targetHeight);
446     double webkitProportions = (double)(vw) /(double)(vh);
447     if (webkitProportions >= snapshotProportions) {
448         // centring position of screenshot
449         area.x = (vw*getZoomFactor()/2) - (vh*getZoomFactor()*snapshotProportions/2);
450         area.y = 0;
451         area.w = vh*getZoomFactor()*snapshotProportions;
452         area.h = vh*getZoomFactor();
453     }
454     else {
455         area.x = 0;
456         area.y = 0;
457         area.w = vw*getZoomFactor();
458         area.h = vw*getZoomFactor()/snapshotProportions;
459     }
460     if (area.w == 0 || area.h == 0)
461         return noImage;
462
463
464     BROWSER_LOGD("[%s:%d] Before snapshot (screenshot) - look at the time of taking snapshot below",__func__, __LINE__);
465 #if defined(USE_EWEBKIT)
466 #if PLATFORM(TIZEN)
467     Evas_Object *snapshot = ewk_view_screenshot_contents_get( m_ewkView, area, 1.0, evas_object_evas_get(m_ewkView));
468     BROWSER_LOGD("[%s:%d] Snapshot (screenshot) catched, evas pointer: %p",__func__, __LINE__, snapshot);
469     if (snapshot)
470         return EflTools::getBrowserImage(snapshot);
471 #endif
472 #endif
473
474     return noImage;
475 }
476
477 #if defined(USE_EWEBKIT)
478 void WebView::__setFocusToEwkView(void * data, Evas * /* e */, Evas_Object * /* obj */, void * /* event_info */)
479 {
480     BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
481
482     WebView * self = reinterpret_cast<WebView *>(data);
483
484     if(!self->hasFocus())
485         self->ewkViewClicked();
486 }
487
488 void WebView::__newWindowRequest(void *data, Evas_Object *, void *out)
489 {
490     BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
491
492     WebView * self = reinterpret_cast<WebView *>(data);
493     BROWSER_LOGD("%s:%d %s self=%p", __FILE__, __LINE__, __func__, self);
494     BROWSER_LOGD("Window creating in tab: %s", self->getTabId().toString().c_str());
495     std::shared_ptr<basic_webengine::AbstractWebEngine<Evas_Object>>  m_webEngine;
496     m_webEngine = std::dynamic_pointer_cast
497     <
498         basic_webengine::AbstractWebEngine<Evas_Object>,tizen_browser::core::AbstractService
499     >
500     (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.webkitengineservice"));
501     M_ASSERT(m_webEngine);
502
503     /// \todo: Choose newly created tab.
504     TabId id;
505     if (m_webEngine->currentTabId() != (id = m_webEngine->addTab(std::string(), &self->getTabId()))) {
506         BROWSER_LOGD("Created tab: %s", id.toString().c_str());
507         Evas_Object* tab_ewk_view = m_webEngine->getTabView(id);
508         *static_cast<Evas_Object**>(out) = tab_ewk_view;
509     }
510 }
511
512 void WebView::__closeWindowRequest(void *data, Evas_Object *, void *)
513 {
514     BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
515     WebView * self = reinterpret_cast<WebView *>(data);
516     std::shared_ptr<AbstractWebEngine<Evas_Object>> m_webEngine =
517                 std::dynamic_pointer_cast
518                 <basic_webengine::AbstractWebEngine<Evas_Object>,tizen_browser::core::AbstractService>
519                 (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.webkitengineservice"));
520     m_webEngine->closeTab(self->getTabId());
521 }
522
523 void WebView::__loadStarted(void * data, Evas_Object * /* obj */, void * /* event_info */)
524 {
525     WebView * self = reinterpret_cast<WebView *>(data);
526
527     BROWSER_LOGD("%s:%d\n\t %s", __func__, __LINE__, ewk_view_url_get(self->m_ewkView));
528
529     self->m_isLoading = true;
530     self->loadStarted();
531     tizen_browser::services::TabThumbCache* cache = tizen_browser::services::TabThumbCache::getInstance();
532     cache->clearThumb(self->m_tabId);
533 }
534
535 void WebView::__loadStop(void * data, Evas_Object * /* obj */, void * /* event_info */)
536 {
537     BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
538
539     WebView * self = reinterpret_cast<WebView *>(data);
540     self->m_isLoading = false;
541
542     self->loadStop();
543 }
544
545 void WebView::__loadFinished(void * data, Evas_Object * /* obj */, void * /* event_info */)
546 {
547     BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
548
549     WebView * self = reinterpret_cast<WebView *>(data);
550
551     self->m_isLoading = false;
552     self->m_loadProgress = 1;
553
554     self->loadFinished();
555     self->loadProgress(self->m_loadProgress);
556     tizen_browser::services::TabThumbCache* cache = tizen_browser::services::TabThumbCache::getInstance();
557     cache->updateThumb(self->m_tabId);
558 }
559
560 void WebView::__loadProgress(void * data, Evas_Object * /* obj */, void * event_info)
561 {
562     BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
563
564     WebView * self = reinterpret_cast<WebView *>(data);
565     self->m_loadProgress = *(double *)event_info;
566     self->loadProgress(self->m_loadProgress);
567 }
568
569 void WebView::__loadError(void* data, Evas_Object * obj, void* ewkError)
570 {
571     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
572
573     WebView *self = reinterpret_cast<WebView*>(data);
574     Ewk_Error *error = reinterpret_cast<Ewk_Error*>(ewkError);
575     Ewk_Error_Type errorType = ewk_error_type_get(error);
576
577     BROWSER_LOGD("[%s:%d] ewk_error_type: %d ",
578                  __PRETTY_FUNCTION__, __LINE__, errorType);
579
580     BROWSER_LOGD("[%s:%d] emiting signal ", __PRETTY_FUNCTION__, __LINE__);
581     int errorCode = ewk_error_code_get(error);
582     if(errorCode == EWK_ERROR_NETWORK_STATUS_CANCELLED)
583     {
584         BROWSER_LOGD("Stop signal emitted");
585         BROWSER_LOGD("Error description: %s", ewk_error_description_get(error));
586         evas_object_smart_callback_call(obj, "load,stop", nullptr);
587     }
588     else
589     {
590         self->loadError();
591         self->m_loadError=true;
592     }
593 }
594
595 void WebView::__titleChanged(void * data, Evas_Object * obj, void * /* event_info */)
596 {
597     BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
598
599     WebView * self = reinterpret_cast<WebView *>(data);
600     self->m_title = fromChar(ewk_view_title_get(obj));
601     self->titleChanged(self->m_title);
602 }
603
604 void WebView::__urlChanged(void * data, Evas_Object * /* obj */, void * event_info)
605 {
606     BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
607
608     WebView * self = reinterpret_cast<WebView *>(data);
609     BROWSER_LOGD("URL changed for tab: %s", self->getTabId().toString().c_str());
610     self->uriChanged(self->getURI());
611     self->tabIdChecker(self->m_tabId);
612 }
613
614 void WebView::__backForwardListChanged(void * data, Evas_Object * /* obj */, void * /* event_info */)
615 {
616     BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
617
618     WebView * self = reinterpret_cast<WebView *>(data);
619     self->backwardEnableChanged(self->isBackEnabled());
620     self->forwardEnableChanged(self->isForwardEnabled());
621 }
622
623 void WebView::__faviconChanged(void* data, Evas_Object*, void*)
624 {
625     if(data)
626     {
627         WebView * self = static_cast<WebView *>(data);
628         Evas_Object * favicon = ewk_context_icon_database_icon_object_add(ewk_view_context_get(self->m_ewkView), ewk_view_url_get(self->m_ewkView),evas_object_evas_get(self->m_ewkView));
629         if (favicon) {
630             BROWSER_LOGD("[%s:%d] Favicon received", __PRETTY_FUNCTION__, __LINE__);
631             self->faviconImage = EflTools::getBrowserImage(favicon);
632             evas_object_unref(favicon);
633             self->favIconChanged(self->faviconImage);
634         }
635     }
636 }
637
638 void WebView::__IMEClosed(void* data, Evas_Object*, void*)
639 {
640     BROWSER_LOGD("%s", __func__);
641     WebView * self = reinterpret_cast<WebView *>(data);
642     self->IMEStateChanged(false);
643 }
644
645 void WebView::__IMEOpened(void* data, Evas_Object*, void*)
646 {
647     BROWSER_LOGD("%s", __func__);
648     WebView * self = reinterpret_cast<WebView *>(data);
649     self->IMEStateChanged(true);
650 }
651
652 std::string WebView::securityOriginToUri(const Ewk_Security_Origin *origin)
653 {
654     std::string protocol = fromChar(ewk_security_origin_protocol_get(origin));
655     std::string uri = fromChar(ewk_security_origin_host_get(origin));
656     std::string url = (boost::format("%1%://%2%") % protocol % uri).str();
657     return url;
658 }
659
660 void WebView::__geolocationPermissionRequest(void * data, Evas_Object * /* obj */, void * event_info)
661 {
662     BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
663 #if PLATFORM(TIZEN)
664     WebView * self = reinterpret_cast<WebView *>(data);
665
666     Ewk_Geolocation_Permission_Request *request = reinterpret_cast<Ewk_Geolocation_Permission_Request *>(event_info);
667     if (!request)
668         return;
669
670     // suspend webview
671     ewk_view_suspend(self->m_ewkView);
672
673     std::string url = WebView::securityOriginToUri(ewk_geolocation_permission_request_origin_get(request));
674
675     ///\todo add translations
676     std::string message = (boost::format("%1% Requests your location") % url).str();
677
678     WebConfirmationPtr c = std::make_shared<WebConfirmation>(WebConfirmation::ConfirmationType::Geolocation, self->m_tabId, url, message);
679
680     // store
681     self->m_confirmationGeolocationMap[c] = request;
682
683     self->cofirmationRequest(c);
684 #endif
685 }
686
687 void WebView::__usermediaPermissionRequest(void * data, Evas_Object * /* obj */, void * event_info)
688 {
689     BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
690 #if PLATFORM(TIZEN)
691     WebView * self = reinterpret_cast<WebView *>(data);
692
693     Ewk_User_Media_Permission_Request *request = reinterpret_cast<Ewk_User_Media_Permission_Request *>(event_info);
694     if (!request)
695         return;
696
697     // suspend webview
698     ewk_view_suspend(self->m_ewkView);
699
700     ///\todo add translations
701     std::string message = "User media permission request";
702
703     WebConfirmationPtr c = std::make_shared<WebConfirmation>(WebConfirmation::ConfirmationType::UserMedia, self->m_tabId, std::string(), message);
704
705     // store
706     self->m_confirmationUserMediaMap[c] = request;
707
708     self->cofirmationRequest(c);
709 #endif
710 }
711
712 void WebView::__notificationPermissionRequest(void * data, Evas_Object * /* obj */, void * event_info)
713 {
714     BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
715 #if PLATFORM(TIZEN)
716     WebView * self = reinterpret_cast<WebView *>(data);
717
718     Ewk_Notification_Permission_Request *request = reinterpret_cast<Ewk_Notification_Permission_Request *>(event_info);
719     if (!request)
720         return;
721
722     // suspend webview
723     ewk_view_suspend(self->m_ewkView);
724
725     ///\todo add translations
726     std::string message = (boost::format("%1% wants to display notifications") % self->getURI()).str();
727
728     WebConfirmationPtr c = std::make_shared<WebConfirmation>(WebConfirmation::ConfirmationType::Notification, self->m_tabId, self->getURI(), message);
729
730     // store
731     self->m_confirmationNotificationMap[c] = request;
732
733     self->cofirmationRequest(c);
734 #endif
735 }
736
737 void WebView::__authenticationRequest(void * data, Evas_Object * /* obj */, void * event_info)
738 {
739     BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
740 #if PLATFORM(TIZEN)
741     WebView * self = reinterpret_cast<WebView *>(data);
742
743     Ewk_Auth_Request *request = reinterpret_cast<Ewk_Auth_Request *>(event_info);
744     EINA_SAFETY_ON_NULL_RETURN(request);
745
746     std::string url = self->getURI();
747     std::string message = (boost::format("A username and password are being requested by %1%.") % url).str();
748
749     AuthenticationConfirmationPtr c = std::make_shared<AuthenticationConfirmation>(self->m_tabId, url, message);
750
751     self->m_confirmationAuthenticationMap[c] = request;
752
753     self->cofirmationRequest(c);
754 #endif
755 }
756
757 void WebView::__requestCertificationConfirm(void * data , Evas_Object * /* obj */, void * event_info)
758 {
759     BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
760 #if PLATFORM(TIZEN)
761     WebView * self = reinterpret_cast<WebView *>(data);
762
763     Ewk_Certificate_Policy_Decision *request = reinterpret_cast<Ewk_Certificate_Policy_Decision *>(event_info);
764     if (!request)
765         return;
766
767     // suspend webview
768     ewk_view_suspend(self->m_ewkView);
769
770     std::string url = self->getURI();
771
772     ///\todo add translations
773     std::string message = (boost::format("There are problems with the security certificate for this site.<br>%1%") % url).str();
774
775     CertificateConfirmationPtr c = std::make_shared<CertificateConfirmation>(self->m_tabId, url, message);
776
777     c->setResult(tizen_browser::basic_webengine::WebConfirmation::ConfirmationResult::Confirmed);
778
779     // store
780     self->m_confirmationCertificatenMap[c] = request;
781
782     self->cofirmationRequest(c);
783 #endif
784 }
785 #endif
786
787 void WebView::setFocus()
788 {
789     elm_object_focus_set(m_ewkView, EINA_TRUE);
790 }
791
792 void WebView::clearFocus()
793 {
794     elm_object_focus_set(m_ewkView, EINA_FALSE);
795 }
796
797 bool WebView::hasFocus() const
798 {
799     return elm_object_focus_get(m_ewkView) == EINA_TRUE ? true : false;
800 }
801
802 double WebView::getZoomFactor() const
803 {
804     if(EINA_UNLIKELY(m_ewkView == nullptr)) {
805         return 1.0;
806     }
807
808 #if defined(USE_EWEBKIT)
809     return ewk_view_page_zoom_get(m_ewkView);
810 #else
811     return 1.0;
812 #endif
813 }
814
815 void WebView::setZoomFactor(double zoomFactor)
816 {
817 #if defined(USE_EWEBKIT)
818     if(m_ewkView) {
819         //using zoomFactor = 0 sets zoom "fit to screen"
820
821         if(zoomFactor != getZoomFactor()) 
822             ewk_view_page_zoom_set(m_ewkView, zoomFactor);
823     }
824 #endif
825 }
826
827 void WebView::scrollView(const int& dx, const int& dy)
828 {
829     ewk_view_scroll_by(m_ewkView, dx, dy);
830 }
831
832 const TabId& WebView::getTabId() {
833     return m_tabId;
834 }
835
836
837 std::shared_ptr<BrowserImage> WebView::getFavicon()
838 {
839     BROWSER_LOGD("%s:%d, TabId: %s", __PRETTY_FUNCTION__, __LINE__, m_tabId.toString().c_str());
840
841     Evas_Object * favicon = ewk_context_icon_database_icon_object_add(ewk_view_context_get(m_ewkView), ewk_view_url_get(m_ewkView),evas_object_evas_get(m_ewkView));
842     faviconImage = EflTools::getBrowserImage(favicon);
843     evas_object_unref(favicon);
844
845     if(faviconImage.get())
846         return faviconImage;
847
848     BROWSER_LOGD("[%s:%d] Returned favicon is empty!",  __PRETTY_FUNCTION__, __LINE__);
849     return std::make_shared<BrowserImage>();
850 }
851
852 void WebView::clearPrivateData()
853 {
854     BROWSER_LOGD("Clearing private data");
855 #if defined(USE_EWEBKIT)
856     if (m_ewkView)
857     {
858         Ewk_Context *context = ewk_view_context_get(m_ewkView);
859         if (context)
860         {
861             ewk_context_web_storage_delete_all(context);
862             ewk_cookie_manager_cookies_clear(ewk_context_cookie_manager_get(context));
863         }
864     }
865 #endif
866 }
867
868 void WebView::searchOnWebsite(const std::string & searchString, int flags)
869 {
870     ///\todo: it should be "0" instead of "1024" for unlimited match count but it doesn't work properly in WebKit
871     Eina_Bool result = ewk_view_text_find(m_ewkView, searchString.c_str(), static_cast<Ewk_Find_Options>(flags), 1024);
872     BROWSER_LOGD("Ewk search; word: %s, result: %d", searchString.c_str(), result);
873 }
874
875 void WebView::switchToDesktopMode() {
876     BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
877     int res = ewk_view_user_agent_set(m_ewkView, APPLICATION_NAME_FOR_USER_AGENT);
878     m_desktopMode = true;
879 }
880
881 void WebView::switchToMobileMode() {
882     BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
883     int res = ewk_view_user_agent_set(m_ewkView, APPLICATION_NAME_FOR_USER_AGENT_MOBILE);
884     m_desktopMode = false;
885 }
886
887 bool WebView::isDesktopMode() const {
888     return m_desktopMode;
889 }
890
891 } /* namespace webkitengine_service */
892 } /* end of basic_webengine */
893 } /* end of tizen_browser */
894