Revert "Renamed KeyEvent enum values to comply with coding standards."
[platform/core/uifw/dali-extension.git] / dali-extension / web-engine-chromium / tizen-web-engine-chromium.cpp
1 /*
2  * Copyright (c) 2020 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 #include <tizen-web-engine-chromium.h>
19
20 #include <Ecore.h>
21 #include <Ecore_Evas.h>
22 #include <Evas.h>
23 #include <Elementary.h>
24
25 #include <EWebKit_internal.h>
26 #include <EWebKit_product.h>
27
28 #include <dali/devel-api/common/stage.h>
29 #include <dali/integration-api/debug.h>
30 #include <dali/integration-api/adaptor-framework/adaptor.h>
31
32 using namespace Dali;
33
34 namespace Dali
35 {
36 namespace Plugin
37 {
38
39 class WebViewContainerClientPair {
40 public:
41   WebViewContainerClientPair( WebViewContainerClient* client, Evas_Object* webView )
42   {
43     mClient = client;
44     mWebView = webView;
45   }
46
47   WebViewContainerClient* mClient;
48   Evas_Object* mWebView;
49 };
50
51 class WebEngineManager {
52   //
53   // A class for managing multiple WebViews
54   //
55 public:
56   static WebEngineManager& Get()
57   {
58     static WebEngineManager instance;
59
60     return instance;
61   }
62
63   WebEngineManager(WebEngineManager const&) = delete;
64
65   void operator=(WebEngineManager const&) = delete;
66
67   Ecore_Evas* GetWindow()
68   {
69     return mWindow;
70   }
71
72   void AddContainerClient( WebViewContainerClient* client, Evas_Object* webView )
73   {
74     mContainerClients.push_back( WebViewContainerClientPair( client, webView ) );
75   }
76
77   void RemoveContainerClient( Evas_Object* webView )
78   {
79     for( auto it = mContainerClients.begin(); it != mContainerClients.end(); )
80     {
81       if( (*it).mWebView == webView )
82       {
83         mContainerClients.erase( it );
84         break;
85       }
86     }
87   }
88
89   WebViewContainerClient* FindContainerClient( Evas_Object* o )
90   {
91     for( auto& webViewClient :  mContainerClients )
92     {
93       if( webViewClient.mWebView == o )
94       {
95         return webViewClient.mClient;
96       }
97     }
98     return 0;
99   }
100
101 private:
102   WebEngineManager()
103   {
104     elm_init( 0, 0 );
105     ewk_init();
106     mWindow = ecore_evas_new( "wayland_egl", 0, 0, 1, 1, 0 );
107   }
108
109   Ecore_Evas* mWindow;
110   std::vector< WebViewContainerClientPair > mContainerClients;
111 };
112
113 class WebViewContainerForDali
114 {
115 public:
116   WebViewContainerForDali( WebViewContainerClient& client, int width, int height )
117     : mClient( client ),
118       mWidth( width ),
119       mHeight( height ),
120       mCookieAcceptancePolicy( EWK_COOKIE_ACCEPT_POLICY_NO_THIRD_PARTY )
121   {
122     InitWebView();
123
124     WebEngineManager::Get().AddContainerClient( &mClient, mWebView );
125   }
126
127   ~WebViewContainerForDali()
128   {
129     WebEngineManager::Get().RemoveContainerClient( mWebView );
130
131     evas_object_del( mWebView );
132   }
133
134   void InitWebView()
135   {
136     Ecore_Wl2_Window* win = AnyCast< Ecore_Wl2_Window* >( Adaptor::Get().GetNativeWindowHandle() );
137     Ewk_Context* context = ewk_context_default_get();
138     ewk_context_max_refresh_rate_set( context, 60 );
139     mWebView = ewk_view_add( ecore_evas_get( WebEngineManager::Get().GetWindow() ) );
140     ewk_view_offscreen_rendering_enabled_set( mWebView, true );
141     ewk_view_ime_window_set( mWebView, win );
142
143     evas_object_smart_callback_add( mWebView, "offscreen,frame,rendered",
144                                     &WebViewContainerForDali::OnFrameRendered,
145                                     &mClient );
146     evas_object_smart_callback_add( mWebView, "load,started",
147                                     &WebViewContainerForDali::OnLoadStarted,
148                                     &mClient );
149     evas_object_smart_callback_add( mWebView, "load,finished",
150                                     &WebViewContainerForDali::OnLoadFinished,
151                                     &mClient );
152     evas_object_smart_callback_add( mWebView, "load,error",
153                                     &WebViewContainerForDali::OnLoadError,
154                                     &mClient );
155     evas_object_smart_callback_add( mWebView, "console,message",
156                                     &WebViewContainerForDali::OnConsoleMessage,
157                                     this );
158
159     evas_object_resize( mWebView, mWidth, mHeight );
160     evas_object_show( mWebView );
161   }
162
163   void LoadUrl( const std::string& url )
164   {
165     ewk_view_url_set( mWebView, url.c_str() );
166     ewk_view_focus_set( mWebView, true );
167   }
168
169   void LoadHtml( const std::string& html )
170   {
171     ewk_view_html_string_load( mWebView, html.c_str(), 0, 0 );
172   }
173
174   std::string GetUrl()
175   {
176     return std::string( ewk_view_url_get( mWebView ) );
177   }
178
179   void Reload()
180   {
181     ewk_view_reload( mWebView );
182   }
183
184   void StopLoading()
185   {
186     ewk_view_stop( mWebView );
187   }
188
189   void Suspend()
190   {
191     ewk_view_suspend( mWebView );
192   }
193
194   void Resume()
195   {
196     ewk_view_resume( mWebView );
197   }
198
199   void GoBack()
200   {
201     ewk_view_back( mWebView );
202   }
203
204   void GoForward()
205   {
206     ewk_view_forward( mWebView );
207   }
208
209   bool CanGoBack()
210   {
211     return ewk_view_back_possible( mWebView );
212   }
213
214   bool CanGoForward()
215   {
216     return ewk_view_forward_possible( mWebView );
217   }
218
219   void EvaluateJavaScript( size_t key, const std::string& script )
220   {
221     ewk_view_script_execute( mWebView, script.c_str(), OnEvaluateJavaScript, (void*)key );
222   }
223
224   void AddJavaScriptMessageHandler( const std::string& exposedObjectName )
225   {
226     // |jsFunctionName| is fixed as "postMessage" so we don't use this.
227     ewk_view_javascript_message_handler_add( mWebView, &WebViewContainerForDali::OnJavaScriptMessage, exposedObjectName.c_str() );
228   }
229
230   void ClearHistory()
231   {
232     ewk_view_back_forward_list_clear( mWebView );
233   }
234
235   void ClearCache()
236   {
237     ewk_context_cache_clear( ewk_view_context_get( mWebView ) );
238   }
239
240   void ClearCookies()
241   {
242     ewk_cookie_manager_cookies_clear( ewk_context_cookie_manager_get( ewk_view_context_get( mWebView ) ) );
243   }
244
245   Ewk_Cache_Model GetCacheModel()
246   {
247     return ewk_context_cache_model_get( ewk_view_context_get( mWebView ) );
248   }
249
250   void SetCacheModel( Ewk_Cache_Model cacheModel )
251   {
252     ewk_context_cache_model_set( ewk_view_context_get( mWebView ), cacheModel );
253   }
254
255   Ewk_Cookie_Accept_Policy GetCookieAcceptPolicy()
256   {
257     return mCookieAcceptancePolicy;
258   }
259
260   void SetCookieAcceptPolicy( Ewk_Cookie_Accept_Policy policy )
261   {
262     ewk_cookie_manager_accept_policy_set( ewk_context_cookie_manager_get( ewk_view_context_get( mWebView ) ), policy );
263     mCookieAcceptancePolicy = policy;
264   }
265
266   const std::string& GetUserAgent()
267   {
268     mUserAgent = std::string( ewk_view_user_agent_get( mWebView ) );
269     return mUserAgent;
270   }
271
272   void SetUserAgent( const std::string& userAgent )
273   {
274     ewk_view_user_agent_set( mWebView, userAgent.c_str() );
275   }
276
277   bool IsJavaScriptEnabled()
278   {
279     return ewk_settings_javascript_enabled_get( ewk_view_settings_get( mWebView ) );
280   }
281
282   void EnableJavaScript( bool enabled )
283   {
284     ewk_settings_javascript_enabled_set( ewk_view_settings_get( mWebView ), enabled );
285   }
286
287   bool AreImagesAutomaticallyLoaded()
288   {
289     return ewk_settings_loads_images_automatically_get( ewk_view_settings_get( mWebView ) );
290   }
291
292   void LoadImagesAutomatically( bool automatic )
293   {
294     ewk_settings_loads_images_automatically_set( ewk_view_settings_get( mWebView ), automatic );
295   }
296
297   const std::string& GetDefaultTextEncodingName()
298   {
299     mDefaultTextEncodingName = std::string( ewk_settings_default_text_encoding_name_get( ewk_view_settings_get( mWebView ) ) );
300     return mDefaultTextEncodingName;
301   }
302
303   void SetDefaultTextEncodingName( const std::string& defaultTextEncodingName )
304   {
305     ewk_settings_default_text_encoding_name_set( ewk_view_settings_get( mWebView ), defaultTextEncodingName.c_str() );
306   }
307
308   int GetDefaultFontSize()
309   {
310     return ewk_settings_default_font_size_get( ewk_view_settings_get( mWebView ) );
311   }
312
313   void SetDefaultFontSize( int defaultFontSize )
314   {
315     ewk_settings_default_font_size_set( ewk_view_settings_get( mWebView ), defaultFontSize );
316   }
317
318   void SetSize( int width, int height )
319   {
320     mWidth = width;
321     mHeight = height;
322     evas_object_resize( mWebView, mWidth, mHeight );
323   }
324
325   bool SendTouchEvent( const TouchEvent& touch )
326   {
327     Ewk_Touch_Event_Type type = EWK_TOUCH_START;
328     Evas_Touch_Point_State state = EVAS_TOUCH_POINT_DOWN;
329     switch ( touch.GetState( 0 ) )
330     {
331       case PointState::DOWN:
332       {
333         type = EWK_TOUCH_START;
334         state = EVAS_TOUCH_POINT_DOWN;
335         break;
336       }
337       case PointState::UP:
338       {
339         type = EWK_TOUCH_END;
340         state = EVAS_TOUCH_POINT_UP;
341         break;
342       }
343       case PointState::MOTION:
344       {
345         type = EWK_TOUCH_MOVE;
346         state = EVAS_TOUCH_POINT_MOVE;
347         break;
348       }
349       case PointState::INTERRUPTED:
350       {
351         type = EWK_TOUCH_CANCEL;
352         state = EVAS_TOUCH_POINT_CANCEL;
353         break;
354       }
355       default:
356       {
357         break;
358       }
359     }
360
361     Eina_List* pointList = 0;
362     Ewk_Touch_Point* point = new Ewk_Touch_Point;
363     point->id = 0;
364     point->x = touch.GetLocalPosition( 0 ).x;
365     point->y = touch.GetLocalPosition( 0 ).y;
366     point->state = state;
367     pointList = eina_list_append( pointList, point );
368
369     ewk_view_feed_touch_event( mWebView, type, pointList, 0 );
370     eina_list_free( pointList );
371     return false;
372   }
373
374   bool SendKeyEvent( const Dali::KeyEvent& keyEvent )
375   {
376     void* evasKeyEvent = 0;
377     if( keyEvent.GetState() == Dali::KeyEvent::Down )
378     {
379       Evas_Event_Key_Down downEvent;
380       memset( &downEvent, 0, sizeof(Evas_Event_Key_Down) );
381       downEvent.key = keyEvent.GetKeyName().c_str();
382       downEvent.string = keyEvent.GetKeyString().c_str();
383       evasKeyEvent = static_cast<void*>(&downEvent);
384       ewk_view_send_key_event( mWebView, evasKeyEvent, true );
385     }
386     else
387     {
388       Evas_Event_Key_Up upEvent;
389       memset(&upEvent, 0, sizeof(Evas_Event_Key_Up));
390       upEvent.key = keyEvent.GetKeyName().c_str();
391       upEvent.string = keyEvent.GetKeyString().c_str();
392       evasKeyEvent = static_cast<void*>(&upEvent);
393       ewk_view_send_key_event( mWebView, evasKeyEvent, false );
394      }
395      return false;
396   }
397
398 private:
399   static void OnFrameRendered( void* data, Evas_Object*, void* buffer )
400   {
401     auto client = static_cast<WebViewContainerClient*>(data);
402     client->UpdateImage( static_cast<tbm_surface_h>(buffer) );
403   }
404
405   static void OnLoadStarted( void* data, Evas_Object*, void* )
406   {
407     auto client = static_cast<WebViewContainerClient*>(data);
408     client->LoadStarted();
409   }
410
411   static void OnLoadFinished( void* data, Evas_Object*, void* )
412   {
413     auto client = static_cast<WebViewContainerClient*>(data);
414     client->LoadFinished();
415   }
416
417   static void OnLoadError( void* data, Evas_Object*, void* rawError )
418   {
419     auto client = static_cast<WebViewContainerClient*>(data);
420     Ewk_Error* error = static_cast< Ewk_Error* >( rawError );
421
422     client->LoadError( ewk_error_url_get( error ), ewk_error_code_get( error ) );
423   }
424
425   static void OnConsoleMessage( void*, Evas_Object*, void* eventInfo )
426   {
427     Ewk_Console_Message* message = (Ewk_Console_Message*)eventInfo;
428     DALI_LOG_RELEASE_INFO( "console message:%s: %d: %d: %s",
429         ewk_console_message_source_get( message ),
430         ewk_console_message_line_get( message ),
431         ewk_console_message_level_get( message ),
432         ewk_console_message_text_get( message ) );
433   }
434
435   static void OnEvaluateJavaScript( Evas_Object* o, const char* result, void* data )
436   {
437     auto client = WebEngineManager::Get().FindContainerClient( o );
438     if( client )
439     {
440       client->RunJavaScriptEvaluationResultHandler( (size_t)data, result );
441     }
442   }
443
444   static void OnJavaScriptMessage( Evas_Object* o, Ewk_Script_Message message )
445   {
446     auto client = WebEngineManager::Get().FindContainerClient( o );
447     if( client )
448     {
449       client->RunJavaScriptMessageHandler( message.name, static_cast<char*>( message.body ) );
450     }
451   }
452
453 private:
454   Evas_Object* mWebView;
455   WebViewContainerClient& mClient;
456
457   int mWidth;
458   int mHeight;
459
460   Ewk_Cookie_Accept_Policy mCookieAcceptancePolicy;
461   std::string mUserAgent;
462   std::string mDefaultTextEncodingName;
463 };
464
465 class TBMSurfaceSourceInitializer
466 {
467 public:
468   explicit TBMSurfaceSourceInitializer( NativeImageSourcePtr& imageSrc,
469                                         int width, int height )
470   {
471     mSurface = tbm_surface_create( width, height, TBM_FORMAT_ARGB8888 );
472     if( !mSurface )
473     {
474       DALI_LOG_ERROR( "Failed to create tbm surface." );
475     }
476
477     Any tbmSource( mSurface );
478     imageSrc = NativeImageSource::New( tbmSource );
479     Any emptySource( 0 );
480     imageSrc->SetSource( emptySource );
481   }
482
483   ~TBMSurfaceSourceInitializer()
484   {
485     if( mSurface )
486     {
487       if( tbm_surface_destroy( mSurface ) != TBM_SURFACE_ERROR_NONE )
488       {
489         DALI_LOG_ERROR( "Failed to destroy tbm surface." );
490       }
491     }
492   }
493 private:
494   tbm_surface_h mSurface;
495 };
496
497 TizenWebEngineChromium::TizenWebEngineChromium()
498   : mWebViewContainer( 0 )
499   , mJavaScriptEvaluationCount( 0 )
500 {
501 }
502
503 TizenWebEngineChromium::~TizenWebEngineChromium()
504 {
505   Destroy();
506 }
507
508 void TizenWebEngineChromium::Create( int width, int height,
509                                      const std::string& locale,
510                                      const std::string& timezoneID )
511 {
512   mWebViewContainer =
513       new WebViewContainerForDali( *this, width, height );
514   TBMSurfaceSourceInitializer initializer( mDaliImageSrc, width, height );
515 }
516
517 void TizenWebEngineChromium::Destroy()
518 {
519   if (mWebViewContainer)
520   {
521     mJavaScriptEvaluationResultHandlers.clear();
522     mJavaScriptMessageHandlers.clear();
523
524     delete mWebViewContainer;
525     mWebViewContainer = 0;
526   }
527 }
528
529 void TizenWebEngineChromium::LoadUrl( const std::string& path )
530 {
531   if( mWebViewContainer )
532   {
533     mWebViewContainer->LoadUrl( path );
534   }
535 }
536
537 NativeImageInterfacePtr TizenWebEngineChromium::GetNativeImageSource()
538 {
539   return mDaliImageSrc;
540 }
541
542 const std::string& TizenWebEngineChromium::GetUrl()
543 {
544   if( mWebViewContainer )
545   {
546     mUrl =  mWebViewContainer->GetUrl();
547   }
548   return mUrl;
549 }
550
551 void TizenWebEngineChromium::LoadHTMLString( const std::string& string )
552 {
553   if( mWebViewContainer )
554   {
555     mWebViewContainer->LoadHtml( string );
556   }
557 }
558
559 void TizenWebEngineChromium::Reload()
560 {
561   if( mWebViewContainer )
562   {
563     mWebViewContainer->Reload();
564   }
565 }
566
567 void TizenWebEngineChromium::StopLoading()
568 {
569   if( mWebViewContainer )
570   {
571     mWebViewContainer->StopLoading();
572   }
573 }
574
575 void TizenWebEngineChromium::Suspend()
576 {
577   if( mWebViewContainer )
578   {
579     mWebViewContainer->Suspend();
580   }
581 }
582
583 void TizenWebEngineChromium::Resume()
584 {
585   if( mWebViewContainer )
586   {
587     mWebViewContainer->Resume();
588   }
589 }
590
591 bool TizenWebEngineChromium::CanGoForward()
592 {
593   if( mWebViewContainer )
594   {
595     return mWebViewContainer->CanGoForward();
596   }
597   return false;
598 }
599
600 void TizenWebEngineChromium::GoForward()
601 {
602   if( mWebViewContainer )
603   {
604     mWebViewContainer->GoForward();
605   }
606 }
607
608 bool TizenWebEngineChromium::CanGoBack()
609 {
610   if( mWebViewContainer )
611   {
612     return mWebViewContainer->CanGoBack();
613   }
614   return false;
615 }
616
617 void TizenWebEngineChromium::GoBack()
618 {
619   if( mWebViewContainer )
620   {
621     mWebViewContainer->GoBack();
622   }
623 }
624
625 void TizenWebEngineChromium::EvaluateJavaScript( const std::string& script, std::function< void( const std::string& ) > resultHandler )
626 {
627   if( mWebViewContainer )
628   {
629     bool badAlloc = false;
630
631     try
632     {
633       mJavaScriptEvaluationResultHandlers.emplace( mJavaScriptEvaluationCount, resultHandler );
634     }
635     catch( std::bad_alloc &e )
636     {
637       badAlloc = true;
638       DALI_LOG_ERROR( "Too many ongoing JavaScript evaluations." );
639     }
640
641     if( !badAlloc )
642     {
643       mWebViewContainer->EvaluateJavaScript( mJavaScriptEvaluationCount++, script );
644     }
645   }
646 }
647
648 void TizenWebEngineChromium::AddJavaScriptMessageHandler( const std::string& exposedObjectName, std::function< void( const std::string& ) > handler )
649 {
650   if( mWebViewContainer )
651   {
652     if( mJavaScriptMessageHandlers.emplace( exposedObjectName, handler ).second )
653     {
654       mWebViewContainer->AddJavaScriptMessageHandler( exposedObjectName );
655     }
656     else
657     {
658       DALI_LOG_ERROR( "Callback for (%s) already exists.", exposedObjectName.c_str() );
659     }
660   }
661 }
662
663 void TizenWebEngineChromium::ClearHistory()
664 {
665   if( mWebViewContainer )
666   {
667     mWebViewContainer->ClearHistory();
668   }
669 }
670
671 void TizenWebEngineChromium::ClearCache()
672 {
673   if( mWebViewContainer )
674   {
675     mWebViewContainer->ClearCache();
676   }
677 }
678
679 void TizenWebEngineChromium::ClearCookies()
680 {
681   if( mWebViewContainer )
682   {
683     mWebViewContainer->ClearCookies();
684   }
685 }
686
687 Dali::WebEnginePlugin::CacheModel TizenWebEngineChromium::GetCacheModel() const
688 {
689   if( mWebViewContainer )
690   {
691     return static_cast< Dali::WebEnginePlugin::CacheModel >( mWebViewContainer->GetCacheModel() );
692   }
693   return Dali::WebEnginePlugin::CacheModel::DOCUMENT_VIEWER;
694 }
695
696 void TizenWebEngineChromium::SetCacheModel( Dali::WebEnginePlugin::CacheModel cacheModel )
697 {
698   if( mWebViewContainer )
699   {
700     return mWebViewContainer->SetCacheModel( static_cast< Ewk_Cache_Model >( cacheModel ) );
701   }
702 }
703
704 Dali::WebEnginePlugin::CookieAcceptPolicy TizenWebEngineChromium::GetCookieAcceptPolicy() const
705 {
706   if( mWebViewContainer )
707   {
708     return static_cast< Dali::WebEnginePlugin::CookieAcceptPolicy >( mWebViewContainer->GetCookieAcceptPolicy() );
709   }
710   return Dali::WebEnginePlugin::CookieAcceptPolicy::NO_THIRD_PARTY;
711 }
712
713 void TizenWebEngineChromium::SetCookieAcceptPolicy( Dali::WebEnginePlugin::CookieAcceptPolicy policy )
714 {
715   if( mWebViewContainer )
716   {
717     mWebViewContainer->SetCookieAcceptPolicy( static_cast< Ewk_Cookie_Accept_Policy >( policy ) );
718   }
719 }
720
721 const std::string kEmpty;
722
723 const std::string& TizenWebEngineChromium::GetUserAgent() const
724 {
725   if( mWebViewContainer )
726   {
727     return mWebViewContainer->GetUserAgent();
728   }
729   return kEmpty;
730 }
731
732 void TizenWebEngineChromium::SetUserAgent( const std::string& userAgent )
733 {
734   if( mWebViewContainer )
735   {
736     mWebViewContainer->SetUserAgent( userAgent );
737   }
738 }
739
740 bool TizenWebEngineChromium::IsJavaScriptEnabled() const
741 {
742   if( mWebViewContainer )
743   {
744     return mWebViewContainer->IsJavaScriptEnabled();
745   }
746   return false;
747 }
748
749 void TizenWebEngineChromium::EnableJavaScript( bool enabled )
750 {
751   if( mWebViewContainer )
752   {
753     mWebViewContainer->EnableJavaScript( enabled );
754   }
755 }
756
757 bool TizenWebEngineChromium::AreImagesAutomaticallyLoaded() const
758 {
759   if( mWebViewContainer )
760   {
761     return mWebViewContainer->AreImagesAutomaticallyLoaded();
762   }
763   return false;
764 }
765
766 void TizenWebEngineChromium::LoadImagesAutomatically( bool automatic )
767 {
768   if( mWebViewContainer )
769   {
770     mWebViewContainer->LoadImagesAutomatically( automatic );
771   }
772 }
773
774 const std::string& TizenWebEngineChromium::GetDefaultTextEncodingName() const
775 {
776   if( mWebViewContainer )
777   {
778     return mWebViewContainer->GetDefaultTextEncodingName();
779   }
780   return kEmpty;
781 }
782
783 void TizenWebEngineChromium::SetDefaultTextEncodingName( const std::string& defaultTextEncodingName )
784 {
785   if( mWebViewContainer )
786   {
787     mWebViewContainer->SetDefaultTextEncodingName( defaultTextEncodingName );
788   }
789 }
790
791 int TizenWebEngineChromium::GetDefaultFontSize() const
792 {
793   if( mWebViewContainer )
794   {
795     return mWebViewContainer->AreImagesAutomaticallyLoaded();
796   }
797   return 0;
798 }
799
800 void TizenWebEngineChromium::SetDefaultFontSize( int defaultFontSize )
801 {
802   if( mWebViewContainer )
803   {
804     mWebViewContainer->SetDefaultFontSize( defaultFontSize );
805   }
806 }
807
808 void TizenWebEngineChromium::SetSize( int width, int height )
809 {
810   if( mWebViewContainer )
811   {
812     mWebViewContainer->SetSize( width, height );
813   }
814 }
815
816 bool TizenWebEngineChromium::SendTouchEvent( const Dali::TouchEvent& touch )
817 {
818   if( mWebViewContainer )
819   {
820     return mWebViewContainer->SendTouchEvent( touch );
821   }
822   return false;
823 }
824
825 bool TizenWebEngineChromium::SendKeyEvent( const Dali::KeyEvent& event )
826 {
827   if( mWebViewContainer )
828   {
829     return mWebViewContainer->SendKeyEvent( event );
830   }
831   return false;
832 }
833
834 Dali::WebEnginePlugin::WebEnginePageLoadSignalType& TizenWebEngineChromium::PageLoadStartedSignal()
835 {
836   return mLoadStartedSignal;
837 }
838
839 Dali::WebEnginePlugin::WebEnginePageLoadSignalType& TizenWebEngineChromium::PageLoadFinishedSignal()
840 {
841   return mLoadFinishedSignal;
842 }
843
844 Dali::WebEnginePlugin::WebEnginePageLoadErrorSignalType& TizenWebEngineChromium::PageLoadErrorSignal()
845 {
846   return mLoadErrorSignal;
847 }
848
849 // WebViewContainerClient Interface
850 void TizenWebEngineChromium::UpdateImage( tbm_surface_h buffer )
851 {
852   if( !buffer )
853   {
854     return;
855   }
856
857   Any source( buffer );
858   mDaliImageSrc->SetSource( source );
859   Dali::Stage::GetCurrent().KeepRendering( 0.0f );
860 }
861
862 void TizenWebEngineChromium::LoadStarted()
863 {
864   DALI_LOG_RELEASE_INFO( "#LoadStarted : %s\n", GetUrl().c_str() );
865   mLoadStartedSignal.Emit( GetUrl() );
866 }
867
868 void TizenWebEngineChromium::LoadFinished()
869 {
870   DALI_LOG_RELEASE_INFO( "#LoadFinished : %s\n", GetUrl().c_str() );
871   mLoadFinishedSignal.Emit( GetUrl() );
872 }
873
874 void TizenWebEngineChromium::LoadError( const char* url, int errorCode )
875 {
876   std::string stdUrl( url );
877   mLoadErrorSignal.Emit( stdUrl, errorCode );
878 }
879
880 void TizenWebEngineChromium::RunJavaScriptEvaluationResultHandler( size_t key, const char* result )
881 {
882   auto handler = mJavaScriptEvaluationResultHandlers.find( key );
883   if( handler == mJavaScriptEvaluationResultHandlers.end() )
884   {
885     return;
886   }
887
888   if( handler->second )
889   {
890     std::string stored( result );
891     handler->second( stored );
892   }
893
894   mJavaScriptEvaluationResultHandlers.erase( handler );
895 }
896
897 void TizenWebEngineChromium::RunJavaScriptMessageHandler( const std::string& objectName, const std::string& message )
898 {
899   auto handler = mJavaScriptMessageHandlers.find( objectName );
900   if( handler == mJavaScriptMessageHandlers.end() )
901   {
902     return;
903   }
904
905   handler->second( message );
906 }
907 } // namespace Plugin
908 } // namespace Dali
909
910
911 extern "C" DALI_EXPORT_API Dali::WebEnginePlugin* CreateWebEnginePlugin()
912 {
913   return new Dali::Plugin::TizenWebEngineChromium();
914 }
915
916 extern "C" DALI_EXPORT_API void DestroyWebEnginePlugin( Dali::WebEnginePlugin* plugin )
917 {
918   if( plugin )
919   {
920     delete plugin;
921   }
922 }