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