Bug TT-71 Remove private ewk_auth_* and ewk_ceritifcate_* API calls
[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 void WebView::setPrivateMode(bool state)
287 {
288     BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
289     M_ASSERT(m_ewkView);
290
291 #if defined(USE_EWEBKIT)
292 #if PLATFORM(TIZEN)
293     Ewk_Settings * settings = ewk_view_settings_get(m_ewkView);
294 #else
295     Ewk_Settings * settings = ewk_page_group_settings_get(ewk_view_page_group_get(m_ewkView));
296 #endif
297     ewk_settings_private_browsing_enabled_set(settings, state);
298     if(state){
299          ewk_cookie_manager_accept_policy_set(ewk_context_cookie_manager_get(ewk_context_default_get()), EWK_COOKIE_ACCEPT_POLICY_NEVER);
300     }
301     else{
302          ewk_cookie_manager_accept_policy_set(ewk_context_cookie_manager_get(ewk_context_default_get()), EWK_COOKIE_ACCEPT_POLICY_ALWAYS);
303     }
304 #endif
305 }
306
307 void WebView::confirmationResult(WebConfirmationPtr confirmation)
308 {
309     BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
310
311 #if defined(USE_EWEBKIT)
312 #if PLATFORM(TIZEN)
313     switch(confirmation->getConfirmationType()) {
314     case WebConfirmation::ConfirmationType::Geolocation: {
315         Ewk_Geolocation_Permission_Request *request = m_confirmationGeolocationMap[confirmation];
316         Eina_Bool result;
317         if (confirmation->getResult() == WebConfirmation::ConfirmationResult::Confirmed)
318             result = EINA_TRUE;
319         else if (confirmation->getResult() == WebConfirmation::ConfirmationResult::Rejected)
320             result = EINA_FALSE;
321         else {
322             BROWSER_LOGE("Wrong ConfirmationResult");
323             break;
324         }
325         // set geolocation permission
326         ewk_geolocation_permission_reply(request, result);
327         ewk_view_resume(m_ewkView);
328
329         // remove from map
330         m_confirmationGeolocationMap.erase(confirmation);
331         break;
332     }
333     case WebConfirmation::ConfirmationType::UserMedia: {
334         Ewk_User_Media_Permission_Request *request = m_confirmationUserMediaMap[confirmation];
335         Eina_Bool result;
336         if (confirmation->getResult() == WebConfirmation::ConfirmationResult::Confirmed)
337             result = EINA_TRUE;
338         else if (confirmation->getResult() == WebConfirmation::ConfirmationResult::Rejected)
339             result = EINA_FALSE;
340         else {
341             BROWSER_LOGE("Wrong ConfirmationResult");
342             break;
343         };
344
345         // set usermedia permission
346         ewk_user_media_permission_reply(request, result);
347         ewk_view_resume(m_ewkView);
348
349         // remove from map
350         m_confirmationUserMediaMap.erase(confirmation);
351         break;
352     }
353     case WebConfirmation::ConfirmationType::Notification: {
354         Ewk_Notification_Permission_Request *request = m_confirmationNotificationMap[confirmation];
355         Eina_Bool result;
356         if (confirmation->getResult() == WebConfirmation::ConfirmationResult::Confirmed)
357             result = EINA_TRUE;
358         else if (confirmation->getResult() == WebConfirmation::ConfirmationResult::Rejected)
359             result = EINA_FALSE;
360         else {
361             BROWSER_LOGE("Wrong ConfirmationResult");
362             break;
363         }
364
365         // set notification permission
366         ewk_notification_permission_reply(request, result);
367         ewk_view_resume(m_ewkView);
368
369         // remove from map
370         m_confirmationNotificationMap.erase(confirmation);
371         break;
372     }
373     case WebConfirmation::ConfirmationType::CertificateConfirmation: {
374         CertificateConfirmationPtr cert = std::dynamic_pointer_cast<CertificateConfirmation, WebConfirmation>(confirmation);
375         Ewk_Certificate_Policy_Decision *request = m_confirmationCertificatenMap[cert];
376         Eina_Bool result;
377         if (cert->getResult() == WebConfirmation::ConfirmationResult::Confirmed)
378             result = EINA_TRUE;
379         else if (cert->getResult() == WebConfirmation::ConfirmationResult::Rejected)
380             result = EINA_FALSE;
381         else {
382             BROWSER_LOGE("Wrong ConfirmationResult");
383             break;
384         }
385
386         // set certificate confirmation
387         BROWSER_LOGE("NOT IMPLEMENTED: Certificate Confirmation handling!");
388
389         // remove from map
390         m_confirmationCertificatenMap.erase(cert);
391         break;
392     }
393     case WebConfirmation::ConfirmationType::Authentication: {
394         AuthenticationConfirmationPtr auth = std::dynamic_pointer_cast<AuthenticationConfirmation, WebConfirmation>(confirmation);
395         Ewk_Auth_Request *request = m_confirmationAuthenticationMap[auth];
396         if (auth->getResult() == WebConfirmation::ConfirmationResult::Confirmed) {
397             BROWSER_LOGE("NOT IMPLEMENTED: Autenthication Request Confirmation handling!");
398         } else if (auth->getResult() == WebConfirmation::ConfirmationResult::Rejected) {
399             BROWSER_LOGE("NOT IMPLEMENTED: Autenthication Request Rejection handling!");
400         } else {
401             BROWSER_LOGE("Wrong ConfirmationResult");
402             break;
403         }
404
405         // remove from map
406         m_confirmationAuthenticationMap.erase(auth);
407         break;
408     }
409     default:
410         break;
411     }
412 #else
413    (void)confirmation;
414 #endif
415 #endif
416 }
417
418 std::shared_ptr<tizen_browser::tools::BrowserImage> WebView::captureSnapshot(int targetWidth, int targetHeight)
419 {
420     BROWSER_LOGD("%s:%d %s NOT IMPLEMENTED, returning empty BrowserImage object", __FILE__, __LINE__, __func__);
421     M_ASSERT(m_ewkView);
422     M_ASSERT(targetWidth);
423     M_ASSERT(targetHeight);
424     Evas_Coord vw, vh;
425     std::shared_ptr<tizen_browser::tools::BrowserImage> noImage = std::make_shared<tizen_browser::tools::BrowserImage>();
426     evas_object_geometry_get(m_ewkView, NULL, NULL, &vw, &vh);
427     if (vw == 0 || vh == 0)
428         return noImage;
429
430     Eina_Rectangle area;
431     double snapshotProportions = (double)(targetWidth) /(double)(targetHeight);
432     double webkitProportions = (double)(vw) /(double)(vh);
433     if (webkitProportions >= snapshotProportions) {
434         // centring position of screenshot
435         area.x = (vw*getZoomFactor()/2) - (vh*getZoomFactor()*snapshotProportions/2);
436         area.y = 0;
437         area.w = vh*getZoomFactor()*snapshotProportions;
438         area.h = vh*getZoomFactor();
439     }
440     else {
441         area.x = 0;
442         area.y = 0;
443         area.w = vw*getZoomFactor();
444         area.h = vw*getZoomFactor()/snapshotProportions;
445     }
446     if (area.w == 0 || area.h == 0)
447         return noImage;
448
449     double scaleW = (double)targetWidth / (double)(area.w);
450     double scaleH = (double)targetHeight / (double)(area.h);
451
452 #if defined(USE_EWEBKIT)
453 #if PLATFORM(TIZEN)
454     Evas_Object *snapshot = nullptr;
455     // TODO use ewk_view_screenshot_contents_get_async API here
456     if (snapshot)
457         return tizen_browser::tools::EflTools::getBrowserImage(snapshot);
458 #endif
459 #endif
460
461     return noImage;
462 }
463
464 #if defined(USE_EWEBKIT)
465 void WebView::__setFocusToEwkView(void * data, Evas * /* e */, Evas_Object * /* obj */, void * /* event_info */)
466 {
467     BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
468
469     WebView * self = reinterpret_cast<WebView *>(data);
470
471     if(!self->hasFocus())
472         self->ewkViewClicked();
473 }
474
475 void WebView::__newWindowRequest(void *data, Evas_Object *, void *out)
476 {
477     BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
478
479     WebView * self = reinterpret_cast<WebView *>(data);
480     BROWSER_LOGD("%s:%d %s self=%p", __FILE__, __LINE__, __func__, self);
481     BROWSER_LOGD("Window creating in tab: %s", self->getTabId().toString().c_str());
482     std::shared_ptr<basic_webengine::AbstractWebEngine<Evas_Object>>  m_webEngine;
483     m_webEngine = std::dynamic_pointer_cast
484     <
485         basic_webengine::AbstractWebEngine<Evas_Object>,tizen_browser::core::AbstractService
486     >
487     (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.webkitengineservice"));
488     M_ASSERT(m_webEngine);
489
490     /// \todo: Choose newly created tab.
491     TabId id = m_webEngine->addTab(std::string(), &self->getTabId());
492     BROWSER_LOGD("Created tab: %s", id.toString().c_str());
493
494     Evas_Object* tab_ewk_view = m_webEngine->getTabView(id);
495     *static_cast<Evas_Object**>(out) = tab_ewk_view;
496 }
497
498 void WebView::__closeWindowRequest(void *data, Evas_Object *, void *)
499 {
500     BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
501     WebView * self = reinterpret_cast<WebView *>(data);
502     std::shared_ptr<AbstractWebEngine<Evas_Object>> m_webEngine =
503                 std::dynamic_pointer_cast
504                 <basic_webengine::AbstractWebEngine<Evas_Object>,tizen_browser::core::AbstractService>
505                 (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.webkitengineservice"));
506     m_webEngine->closeTab(self->getTabId());
507 }
508
509 void WebView::__loadStarted(void * data, Evas_Object * /* obj */, void * /* event_info */)
510 {
511     WebView * self = reinterpret_cast<WebView *>(data);
512
513     BROWSER_LOGD("%s:%d\n\t %s", __func__, __LINE__, ewk_view_url_get(self->m_ewkView));
514
515     self->m_isLoading = true;
516     self->loadStarted();
517     tizen_browser::services::TabThumbCache* cache = tizen_browser::services::TabThumbCache::getInstance();
518     cache->clearThumb(self->m_tabId);
519 }
520
521 void WebView::__loadStop(void * data, Evas_Object * /* obj */, void * /* event_info */)
522 {
523     BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
524
525     WebView * self = reinterpret_cast<WebView *>(data);
526     self->m_isLoading = false;
527
528     self->loadStop();
529 }
530
531 void WebView::__loadFinished(void * data, Evas_Object * /* obj */, void * /* event_info */)
532 {
533     BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
534
535     WebView * self = reinterpret_cast<WebView *>(data);
536     self->m_isLoading = false;
537     self->m_loadProgress = 1;
538
539     self->loadFinished();
540     self->loadProgress(self->m_loadProgress);
541     tizen_browser::services::TabThumbCache* cache = tizen_browser::services::TabThumbCache::getInstance();
542     cache->updateThumb(self->m_tabId);
543 }
544
545 void WebView::__loadProgress(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     self->m_loadProgress = *(double *)event_info;
551
552     self->loadProgress(self->m_loadProgress);
553 }
554
555 void WebView::__loadError(void* data, Evas_Object * obj, void* ewkError)
556 {
557     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
558
559     WebView *self = reinterpret_cast<WebView*>(data);
560     Ewk_Error *error = reinterpret_cast<Ewk_Error*>(ewkError);
561     Ewk_Error_Type errorType = ewk_error_type_get(error);
562
563     BROWSER_LOGD("[%s:%d] ewk_error_type: %d ",
564                  __PRETTY_FUNCTION__, __LINE__, errorType);
565
566     BROWSER_LOGD("[%s:%d] emiting signal ", __PRETTY_FUNCTION__, __LINE__);
567     int errorCode = ewk_error_code_get(error);
568     if(errorCode == EWK_ERROR_NETWORK_STATUS_CANCELLED)
569     {
570         BROWSER_LOGD("Stop signal emitted");
571         BROWSER_LOGD("Error description: %s", ewk_error_description_get(error));
572         evas_object_smart_callback_call(obj, "load,stop", NULL);
573     }
574     else
575     {
576         self->loadError();
577         self->m_loadError=true;
578     }
579 }
580
581 void WebView::__titleChanged(void * data, Evas_Object * obj, void * /* event_info */)
582 {
583     BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
584
585     WebView * self = reinterpret_cast<WebView *>(data);
586     self->m_title = tizen_browser::tools::fromChar(ewk_view_title_get(obj));
587
588     self->titleChanged(self->m_title);
589 }
590
591 void WebView::__urlChanged(void * data, Evas_Object * /* obj */, void * event_info)
592 {
593     BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
594
595     WebView * self = reinterpret_cast<WebView *>(data);
596     BROWSER_LOGD("URL changed for tab: %s", self->getTabId().toString().c_str());
597     std::shared_ptr<basic_webengine::AbstractWebEngine<Evas_Object>> m_webEngine;
598     m_webEngine = std::dynamic_pointer_cast<basic_webengine::AbstractWebEngine<Evas_Object>, tizen_browser::core::AbstractService>(
599             tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.webkitengineservice"));
600     M_ASSERT(m_webEngine);
601     self->uriChanged(tizen_browser::tools::fromChar(reinterpret_cast<const char *>(event_info)));
602     self->tabIdChecker(self->m_tabId);
603 }
604
605 void WebView::__backForwardListChanged(void * data, Evas_Object * /* obj */, void * /* event_info */)
606 {
607     BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
608
609     WebView * self = reinterpret_cast<WebView *>(data);
610     self->backwardEnableChanged(self->isBackEnabled());
611     self->forwardEnableChanged(self->isForwardEnabled());
612 }
613
614 void WebView::__faviconChanged(void* data, Evas_Object*, void*)
615 {
616     if(data)
617     {
618         WebView * self = static_cast<WebView *>(data);
619         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));
620         if (favicon) {
621             BROWSER_LOGD("[%s:%d] Favicon received", __PRETTY_FUNCTION__, __LINE__);
622             self->faviconImage = tizen_browser::tools::EflTools::getBrowserImage(favicon);
623             evas_object_unref(favicon);
624             self->favIconChanged(self->faviconImage);
625         }
626     }
627 }
628
629 void WebView::__IMEClosed(void* data, Evas_Object*, void*)
630 {
631     BROWSER_LOGD("%s", __func__);
632     WebView * self = reinterpret_cast<WebView *>(data);
633     self->IMEStateChanged(false);
634 }
635
636 void WebView::__IMEOpened(void* data, Evas_Object*, void*)
637 {
638     BROWSER_LOGD("%s", __func__);
639     WebView * self = reinterpret_cast<WebView *>(data);
640     self->IMEStateChanged(true);
641 }
642
643 std::string WebView::securityOriginToUri(const Ewk_Security_Origin *origin)
644 {
645     std::string protocol = tizen_browser::tools::fromChar(ewk_security_origin_protocol_get(origin));
646     std::string uri = tizen_browser::tools::fromChar(ewk_security_origin_host_get(origin));
647     std::string url = (boost::format("%1%://%2%") % protocol % uri).str();
648     return url;
649 }
650
651 void WebView::__geolocationPermissionRequest(void * data, Evas_Object * /* obj */, void * event_info)
652 {
653     BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
654 #if PLATFORM(TIZEN)
655     WebView * self = reinterpret_cast<WebView *>(data);
656
657     Ewk_Geolocation_Permission_Request *request = reinterpret_cast<Ewk_Geolocation_Permission_Request *>(event_info);
658     if (!request)
659         return;
660
661     // suspend webview
662     ewk_view_suspend(self->m_ewkView);
663
664     std::string url = WebView::securityOriginToUri(ewk_geolocation_permission_request_origin_get(request));
665
666     ///\todo add translations
667     std::string message = (boost::format("%1% Requests your location") % url).str();
668
669     WebConfirmationPtr c = std::make_shared<WebConfirmation>(WebConfirmation::ConfirmationType::Geolocation, self->m_tabId, url, message);
670
671     // store
672     self->m_confirmationGeolocationMap[c] = request;
673
674     self->cofirmationRequest(c);
675 #endif
676 }
677
678 void WebView::__usermediaPermissionRequest(void * data, Evas_Object * /* obj */, void * event_info)
679 {
680     BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
681 #if PLATFORM(TIZEN)
682     WebView * self = reinterpret_cast<WebView *>(data);
683
684     Ewk_User_Media_Permission_Request *request = reinterpret_cast<Ewk_User_Media_Permission_Request *>(event_info);
685     if (!request)
686         return;
687
688     // suspend webview
689     ewk_view_suspend(self->m_ewkView);
690
691     ///\todo add translations
692     std::string message = "User media permission request";
693
694     WebConfirmationPtr c = std::make_shared<WebConfirmation>(WebConfirmation::ConfirmationType::UserMedia, self->m_tabId, std::string(), message);
695
696     // store
697     self->m_confirmationUserMediaMap[c] = request;
698
699     self->cofirmationRequest(c);
700 #endif
701 }
702
703 void WebView::__notificationPermissionRequest(void * data, Evas_Object * /* obj */, void * event_info)
704 {
705     BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
706 #if PLATFORM(TIZEN)
707     WebView * self = reinterpret_cast<WebView *>(data);
708
709     Ewk_Notification_Permission_Request *request = reinterpret_cast<Ewk_Notification_Permission_Request *>(event_info);
710     if (!request)
711         return;
712
713     // suspend webview
714     ewk_view_suspend(self->m_ewkView);
715
716     ///\todo add translations
717     std::string message = (boost::format("%1% wants to display notifications") % self->getURI()).str();
718
719     WebConfirmationPtr c = std::make_shared<WebConfirmation>(WebConfirmation::ConfirmationType::Notification, self->m_tabId, self->getURI(), message);
720
721     // store
722     self->m_confirmationNotificationMap[c] = request;
723
724     self->cofirmationRequest(c);
725 #endif
726 }
727
728 void WebView::__authenticationRequest(void * data, Evas_Object * /* obj */, void * event_info)
729 {
730     BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
731 #if PLATFORM(TIZEN)
732     WebView * self = reinterpret_cast<WebView *>(data);
733
734     Ewk_Auth_Request *request = reinterpret_cast<Ewk_Auth_Request *>(event_info);
735     EINA_SAFETY_ON_NULL_RETURN(request);
736
737     std::string url = self->getURI();
738     std::string message = (boost::format("A username and password are being requested by %1%.") % url).str();
739
740     AuthenticationConfirmationPtr c = std::make_shared<AuthenticationConfirmation>(self->m_tabId, url, message);
741
742     self->m_confirmationAuthenticationMap[c] = request;
743
744     self->cofirmationRequest(c);
745 #endif
746 }
747
748 void WebView::__requestCertificationConfirm(void * data , Evas_Object * /* obj */, void * event_info)
749 {
750     BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
751 #if PLATFORM(TIZEN)
752     WebView * self = reinterpret_cast<WebView *>(data);
753
754     Ewk_Certificate_Policy_Decision *request = reinterpret_cast<Ewk_Certificate_Policy_Decision *>(event_info);
755     if (!request)
756         return;
757
758     // suspend webview
759     ewk_view_suspend(self->m_ewkView);
760
761     std::string url = self->getURI();
762
763     ///\todo add translations
764     std::string message = (boost::format("There are problems with the security certificate for this site.<br>%1%") % url).str();
765
766     CertificateConfirmationPtr c = std::make_shared<CertificateConfirmation>(self->m_tabId, url, message);
767
768     c->setResult(tizen_browser::basic_webengine::WebConfirmation::ConfirmationResult::Confirmed);
769
770     // store
771     self->m_confirmationCertificatenMap[c] = request;
772
773     self->cofirmationRequest(c);
774 #endif
775 }
776 #endif
777
778 void WebView::setFocus()
779 {
780     elm_object_focus_set(m_ewkView, EINA_TRUE);
781 }
782
783 void WebView::clearFocus()
784 {
785     elm_object_focus_set(m_ewkView, EINA_FALSE);
786 }
787
788 bool WebView::hasFocus() const
789 {
790     return elm_object_focus_get(m_ewkView) == EINA_TRUE ? true : false;
791 }
792
793 double WebView::getZoomFactor() const
794 {
795     if(EINA_UNLIKELY(m_ewkView == NULL)){
796         return 1.0;
797     }
798
799 #if defined(USE_EWEBKIT)
800     return ewk_view_page_zoom_get(m_ewkView);
801 #else
802     return 1.0;
803 #endif
804 }
805
806 void WebView::setZoomFactor(double zoomFactor)
807 {
808 #if defined(USE_EWEBKIT)
809     if(m_ewkView){
810         //using zoomFactor = 0 sets zoom "fit to screen"
811
812         ewk_view_page_zoom_set(m_ewkView, zoomFactor);
813     }
814 #endif
815 }
816
817
818 const TabId& WebView::getTabId(){
819     return m_tabId;
820 }
821
822
823 std::shared_ptr<tizen_browser::tools::BrowserImage> WebView::getFavicon() {
824     BROWSER_LOGD("%s:%d, TabId: %s", __PRETTY_FUNCTION__, __LINE__, m_tabId.toString().c_str());
825     M_ASSERT(m_ewkView);
826
827 #if defined(USE_EWEBKIT)
828     if (faviconImage.get() == NULL) {
829
830 #if PLATFORM(TIZEN)
831 //    Evas_Object * favicon = ewk_view_favicon_get(m_ewkView);
832     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));
833 #else
834     Ewk_Favicon_Database * database = ewk_context_favicon_database_get(ewk_view_context_get(m_ewkView));
835     Evas_Object * favicon = ewk_favicon_database_icon_get(database, ewk_view_url_get(m_ewkView), evas_object_evas_get(m_ewkView));
836 #endif
837
838 #ifndef NDEBUG
839         int w = 0, h = 0;
840         evas_object_image_size_get(favicon, &w, &h);
841         BROWSER_LOGD("[%s]: Info about favicon: w:%d h:%d, type: %s", __func__, w, h, evas_object_type_get(favicon));
842 #endif
843         if (favicon) {
844             std::shared_ptr<tizen_browser::tools::BrowserImage>
845                 image = tizen_browser::tools::EflTools::getBrowserImage(favicon);
846
847             evas_object_unref(favicon);
848
849             return image;
850         }
851     } else {
852         return faviconImage;
853     }
854 #endif
855
856     BROWSER_LOGE("[%s:%d]: Returned favicon is empty!", __PRETTY_FUNCTION__, __LINE__);
857     return std::make_shared<tizen_browser::tools::BrowserImage>();
858 }
859
860 void WebView::clearPrivateData()
861 {
862     BROWSER_LOGD("Clearing private data");
863 #if defined(USE_EWEBKIT)
864     Ewk_Context * context = ewk_context_default_get();
865     ewk_context_web_storage_delete_all(context);
866     ewk_cookie_manager_cookies_clear(ewk_context_cookie_manager_get(context));
867 #endif
868 }
869
870 void WebView::searchOnWebsite(const std::string & searchString, int flags)
871 {
872     ///\todo: it should be "0" instead of "1024" for unlimited match count but it doesn't work properly in WebKit
873     Eina_Bool result = ewk_view_text_find(m_ewkView, searchString.c_str(), static_cast<Ewk_Find_Options>(flags), 1024);
874     BROWSER_LOGD("Ewk search; word: %s, result: %d", searchString.c_str(), result);
875 }
876
877 } /* namespace webkitengine_service */
878 } /* end of basic_webengine */
879 } /* end of tizen_browser */
880