d48decce3e91ccaae5b24991a8ad46f55d7bf38a
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / web-view / web-view-impl.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 // CLASS HEADER
19 #include "web-view-impl.h"
20
21 // EXTERNAL INCLUDES
22 #include <cstring>
23 #include <dali/devel-api/scripting/enum-helper.h>
24 #include <dali/devel-api/scripting/scripting.h>
25 #include <dali/devel-api/common/stage.h>
26 #include <dali/public-api/adaptor-framework/native-image-source.h>
27 #include <dali/public-api/object/type-registry.h>
28 #include <dali/public-api/object/type-registry-helper.h>
29
30 // INTERNAL INCLUDES
31 #include <dali-toolkit/devel-api/controls/control-devel.h>
32 #include <dali-toolkit/devel-api/image-loader/texture-manager.h>
33 #include <dali-toolkit/internal/visuals/visual-factory-impl.h>
34 #include <dali-toolkit/public-api/visuals/image-visual-properties.h>
35
36 namespace Dali
37 {
38
39 namespace Toolkit
40 {
41
42 namespace Internal
43 {
44
45 namespace
46 {
47
48 BaseHandle Create()
49 {
50   return Toolkit::WebView::New();
51 }
52
53 DALI_ENUM_TO_STRING_TABLE_BEGIN( CacheModel )
54 DALI_ENUM_TO_STRING_WITH_SCOPE( Toolkit::WebView::CacheModel, DOCUMENT_VIEWER )
55 DALI_ENUM_TO_STRING_WITH_SCOPE( Toolkit::WebView::CacheModel, DOCUMENT_BROWSER )
56 DALI_ENUM_TO_STRING_WITH_SCOPE( Toolkit::WebView::CacheModel, PRIMARY_WEB_BROWSER )
57 DALI_ENUM_TO_STRING_TABLE_END( CacheModel )
58
59 DALI_ENUM_TO_STRING_TABLE_BEGIN( CookieAcceptPolicy )
60 DALI_ENUM_TO_STRING_WITH_SCOPE( Toolkit::WebView::CookieAcceptPolicy, ALWAYS )
61 DALI_ENUM_TO_STRING_WITH_SCOPE( Toolkit::WebView::CookieAcceptPolicy, NEVER )
62 DALI_ENUM_TO_STRING_WITH_SCOPE( Toolkit::WebView::CookieAcceptPolicy, NO_THIRD_PARTY )
63 DALI_ENUM_TO_STRING_TABLE_END( CookieAcceptPolicy )
64
65 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::WebView, Toolkit::Control, Create )
66
67 DALI_PROPERTY_REGISTRATION( Toolkit, WebView, "url",                     STRING,  URL                        )
68 DALI_PROPERTY_REGISTRATION( Toolkit, WebView, "cacheModel",              STRING,  CACHE_MODEL                )
69 DALI_PROPERTY_REGISTRATION( Toolkit, WebView, "cookieAcceptPolicy",      STRING,  COOKIE_ACCEPT_POLICY       )
70 DALI_PROPERTY_REGISTRATION( Toolkit, WebView, "userAgent",               STRING,  USER_AGENT                 )
71 DALI_PROPERTY_REGISTRATION( Toolkit, WebView, "enableJavaScript",        BOOLEAN, ENABLE_JAVASCRIPT          )
72 DALI_PROPERTY_REGISTRATION( Toolkit, WebView, "loadImagesAutomatically", BOOLEAN, LOAD_IMAGES_AUTOMATICALLY  )
73 DALI_PROPERTY_REGISTRATION( Toolkit, WebView, "defaultTextEncodingName", STRING,  DEFAULT_TEXT_ENCODING_NAME )
74 DALI_PROPERTY_REGISTRATION( Toolkit, WebView, "defaultFontSize",         INTEGER, DEFAULT_FONT_SIZE          )
75 DALI_PROPERTY_REGISTRATION( Toolkit, WebView, "scrollPosition",          VECTOR2, SCROLL_POSITION            )
76 DALI_PROPERTY_REGISTRATION( Toolkit, WebView, "scrollSize",              VECTOR2, SCROLL_SIZE                )
77 DALI_PROPERTY_REGISTRATION( Toolkit, WebView, "contentSize",             VECTOR2, CONTENT_SIZE               )
78
79 DALI_SIGNAL_REGISTRATION(   Toolkit, WebView, "pageLoadStarted",         PAGE_LOAD_STARTED_SIGNAL            )
80 DALI_SIGNAL_REGISTRATION(   Toolkit, WebView, "pageLoadFinished",        PAGE_LOAD_FINISHED_SIGNAL           )
81 DALI_SIGNAL_REGISTRATION(   Toolkit, WebView, "pageLoadError",           PAGE_LOAD_ERROR_SIGNAL              )
82 DALI_SIGNAL_REGISTRATION(   Toolkit, WebView, "scrollEdgeReached",       SCROLL_EDGE_REACHED_SIGNAL          )
83
84 DALI_TYPE_REGISTRATION_END()
85
86 const std::string kEmptyString;
87
88 const char* DEFAULT_SAMPLER_TYPENAME = "sampler2D";
89
90 const char* FRAGMENT_SHADER_TEXTURE = DALI_COMPOSE_SHADER(
91   varying mediump vec2 vTexCoord;\n
92   uniform sampler2D sTexture;\n
93   uniform lowp vec4 uColor;\n
94   uniform lowp vec3 mixColor;\n
95   uniform lowp float preMultipliedAlpha;\n
96   \n
97   void main()\n
98   {\n
99       gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor * vec4( mixColor, 1.0 );\n
100   }\n
101 );
102
103 Dali::Toolkit::Visual::Base CreateNativeImageVisual( NativeImageInterfacePtr nativeImageInterface )
104 {
105   std::string fragmentShader;
106
107   const char* fragmentPrefix = nativeImageInterface->GetCustomFragmentPrefix();
108   if( fragmentPrefix )
109   {
110     fragmentShader = fragmentPrefix;
111     fragmentShader += FRAGMENT_SHADER_TEXTURE;
112   }
113   else
114   {
115     fragmentShader = FRAGMENT_SHADER_TEXTURE;
116   }
117
118   const char* customSamplerTypename = nativeImageInterface->GetCustomSamplerTypename();
119   if( customSamplerTypename )
120   {
121     fragmentShader.replace( fragmentShader.find( DEFAULT_SAMPLER_TYPENAME ), strlen( DEFAULT_SAMPLER_TYPENAME ), customSamplerTypename );
122   }
123
124   Texture texture = Dali::Texture::New( *nativeImageInterface );
125   const std::string nativeImageUrl = Dali::Toolkit::TextureManager::AddTexture( texture );
126
127   return Toolkit::VisualFactory::Get().CreateVisual(
128     { { Toolkit::Visual::Property::TYPE,  Toolkit::Visual::IMAGE } ,
129       { Toolkit::Visual::Property::SHADER, { { Toolkit::Visual::Shader::Property::FRAGMENT_SHADER, fragmentShader } } },
130       { Toolkit::ImageVisual::Property::URL, nativeImageUrl } } );
131 }
132
133 } // anonymous namepsace
134
135 #define GET_ENUM_STRING( structName, inputExp ) \
136   Scripting::GetLinearEnumerationName< Toolkit::WebView::structName::Type >( static_cast< Toolkit::WebView::structName::Type >( inputExp ), structName##_TABLE, structName##_TABLE_COUNT )
137
138 #define GET_ENUM_VALUE( structName, inputExp, outputExp ) \
139   Scripting::GetEnumerationProperty< Toolkit::WebView::structName::Type >( inputExp, structName##_TABLE, structName##_TABLE_COUNT, outputExp )
140
141 WebView::WebView( const std::string& locale, const std::string& timezoneId )
142 : Control( ControlBehaviour( ACTOR_BEHAVIOUR_DEFAULT | DISABLE_STYLE_CHANGE_SIGNALS ) ),
143   mUrl(),
144   mVisual(),
145   mWebViewSize( Stage::GetCurrent().GetSize() ),
146   mWebEngine(),
147   mPageLoadStartedSignal(),
148   mPageLoadFinishedSignal(),
149   mPageLoadErrorSignal()
150 {
151   mWebEngine = Dali::WebEngine::New();
152
153   // WebEngine is empty when it is not properly initialized.
154   if( mWebEngine )
155   {
156     mWebEngine.Create( mWebViewSize.width, mWebViewSize.height, locale, timezoneId );
157   }
158 }
159
160 WebView::WebView()
161 : WebView( "", "" )
162 {
163 }
164
165 WebView::~WebView()
166 {
167 }
168
169 Toolkit::WebView WebView::New()
170 {
171   WebView* impl = new WebView();
172   Toolkit::WebView handle = Toolkit::WebView( *impl );
173
174   impl->Initialize();
175   return handle;
176 }
177
178 Toolkit::WebView WebView::New( const std::string& locale, const std::string& timezoneId )
179 {
180   WebView* impl = new WebView( locale, timezoneId );
181   Toolkit::WebView handle = Toolkit::WebView( *impl );
182
183   impl->Initialize();
184   return handle;
185 }
186
187 void WebView::OnInitialize()
188 {
189   Self().SetProperty( Actor::Property::KEYBOARD_FOCUSABLE, true );
190   Self().TouchedSignal().Connect( this, &WebView::OnTouchEvent );
191
192   if( mWebEngine )
193   {
194     mWebEngine.PageLoadStartedSignal().Connect( this, &WebView::OnPageLoadStarted );
195     mWebEngine.PageLoadFinishedSignal().Connect( this, &WebView::OnPageLoadFinished );
196     mWebEngine.PageLoadErrorSignal().Connect( this, &WebView::OnPageLoadError );
197     mWebEngine.ScrollEdgeReachedSignal().Connect( this, &WebView::OnScrollEdgeReached );
198   }
199 }
200
201 void WebView::LoadUrl( const std::string& url )
202 {
203   mUrl = url;
204   if( mWebEngine )
205   {
206     mVisual = CreateNativeImageVisual( mWebEngine.GetNativeImageSource() );
207
208     if( mVisual )
209     {
210       // Clean up previously registered visual and add new one.
211       DevelControl::RegisterVisual( *this, Toolkit::WebView::Property::URL, mVisual );
212       mWebEngine.LoadUrl( url );
213     }
214   }
215 }
216
217 void WebView::LoadHTMLString( const std::string& htmlString )
218 {
219   if( mWebEngine )
220   {
221     mVisual = CreateNativeImageVisual( mWebEngine.GetNativeImageSource() );
222
223     if( mVisual )
224     {
225       DevelControl::RegisterVisual( *this, Toolkit::WebView::Property::URL, mVisual );
226       mWebEngine.LoadHTMLString( htmlString );
227     }
228   }
229 }
230
231 void WebView::Reload()
232 {
233   if( mWebEngine )
234   {
235     mWebEngine.Reload();
236   }
237 }
238
239 void WebView::StopLoading()
240 {
241   if( mWebEngine )
242   {
243     mWebEngine.StopLoading();
244   }
245 }
246
247 void WebView::Suspend()
248 {
249   if( mWebEngine )
250   {
251     mWebEngine.Suspend();
252   }
253 }
254
255 void WebView::Resume()
256 {
257   if( mWebEngine )
258   {
259     mWebEngine.Resume();
260   }
261 }
262
263 void WebView::ScrollBy( int deltaX, int deltaY )
264 {
265   if ( mWebEngine )
266   {
267     mWebEngine.ScrollBy( deltaX, deltaY );
268   }
269 }
270
271 bool WebView::CanGoForward()
272 {
273   return mWebEngine ? mWebEngine.CanGoForward() : false;
274 }
275
276 void WebView::GoForward()
277 {
278   if( mWebEngine )
279   {
280     mWebEngine.GoForward();
281   }
282 }
283
284 bool WebView::CanGoBack()
285 {
286   return mWebEngine ? mWebEngine.CanGoBack() : false;
287 }
288
289 void WebView::GoBack()
290 {
291   if( mWebEngine )
292   {
293     mWebEngine.GoBack();
294   }
295 }
296
297 void WebView::EvaluateJavaScript( const std::string& script, std::function< void( const std::string& ) > resultHandler )
298 {
299   if( mWebEngine )
300   {
301     mWebEngine.EvaluateJavaScript( script, resultHandler );
302   }
303 }
304
305 void WebView::AddJavaScriptMessageHandler( const std::string& exposedObjectName, std::function< void( const std::string& ) > handler )
306 {
307   if( mWebEngine )
308   {
309     mWebEngine.AddJavaScriptMessageHandler( exposedObjectName, handler );
310   }
311 }
312
313 void WebView::ClearHistory()
314 {
315   if( mWebEngine )
316   {
317     mWebEngine.ClearHistory();
318   }
319 }
320
321 void WebView::ClearCache()
322 {
323   if( mWebEngine )
324   {
325     mWebEngine.ClearCache();
326   }
327 }
328
329 void WebView::ClearCookies()
330 {
331   if( mWebEngine )
332   {
333     mWebEngine.ClearCookies();
334   }
335 }
336
337 Dali::Toolkit::WebView::WebViewPageLoadSignalType& WebView::PageLoadStartedSignal()
338 {
339   return mPageLoadStartedSignal;
340 }
341
342 Dali::Toolkit::WebView::WebViewPageLoadSignalType& WebView::PageLoadFinishedSignal()
343 {
344   return mPageLoadFinishedSignal;
345 }
346
347 Dali::Toolkit::WebView::WebViewPageLoadErrorSignalType& WebView::PageLoadErrorSignal()
348 {
349   return mPageLoadErrorSignal;
350 }
351
352 Dali::Toolkit::WebView::WebViewScrollEdgeReachedSignalType& WebView::ScrollEdgeReachedSignal()
353 {
354   return mScrollEdgeReachedSignal;
355 }
356
357 void WebView::OnPageLoadStarted( const std::string& url )
358 {
359   if( !mPageLoadStartedSignal.Empty() )
360   {
361     Dali::Toolkit::WebView handle( GetOwner() );
362     mPageLoadStartedSignal.Emit( handle, url );
363   }
364 }
365
366 void WebView::OnPageLoadFinished( const std::string& url )
367 {
368   if( !mPageLoadFinishedSignal.Empty() )
369   {
370     Dali::Toolkit::WebView handle( GetOwner() );
371     mPageLoadFinishedSignal.Emit( handle, url );
372   }
373 }
374
375 void WebView::OnPageLoadError( const std::string& url, int errorCode )
376 {
377   if( !mPageLoadErrorSignal.Empty() )
378   {
379     Dali::Toolkit::WebView handle( GetOwner() );
380     mPageLoadErrorSignal.Emit( handle, url, static_cast< Toolkit::WebView::LoadErrorCode >( errorCode ) );
381   }
382 }
383
384 void WebView::OnScrollEdgeReached( Dali::WebEnginePlugin::ScrollEdge edge )
385 {
386   if( !mScrollEdgeReachedSignal.Empty() )
387   {
388     Dali::Toolkit::WebView handle( GetOwner() );
389     mScrollEdgeReachedSignal.Emit( handle, edge );
390   }
391 }
392
393 bool WebView::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
394 {
395   Dali::BaseHandle handle( object );
396
397   bool connected = false;
398   Toolkit::WebView webView = Toolkit::WebView::DownCast( handle );
399
400   if( 0 == strcmp( signalName.c_str(), PAGE_LOAD_STARTED_SIGNAL ) )
401   {
402     webView.PageLoadStartedSignal().Connect( tracker, functor );
403     connected = true;
404   }
405   else if( 0 == strcmp( signalName.c_str(), PAGE_LOAD_FINISHED_SIGNAL ) )
406   {
407     webView.PageLoadFinishedSignal().Connect( tracker, functor );
408     connected = true;
409   }
410   else if( 0 == strcmp( signalName.c_str(), PAGE_LOAD_ERROR_SIGNAL ) )
411   {
412     webView.PageLoadErrorSignal().Connect( tracker, functor );
413     connected = true;
414   }
415   else if( 0 == strcmp( signalName.c_str(), SCROLL_EDGE_REACHED_SIGNAL ) )
416   {
417     webView.ScrollEdgeReachedSignal().Connect( tracker, functor );
418     connected = true;
419   }
420
421   return connected;
422 }
423
424 Vector3 WebView::GetNaturalSize()
425 {
426   if( mVisual )
427   {
428     Vector2 rendererNaturalSize;
429     mVisual.GetNaturalSize( rendererNaturalSize );
430     return Vector3( rendererNaturalSize );
431   }
432
433   return Vector3( mWebViewSize );
434 }
435
436 void WebView::OnRelayout( const Vector2& size, RelayoutContainer& container )
437 {
438   Control::OnRelayout( size, container );
439
440   if( size.width > 0 && size.height > 0 && mWebViewSize != size )
441   {
442     mWebViewSize = size;
443
444     if( mWebEngine )
445     {
446       mWebEngine.SetSize( size.width, size.height );
447     }
448   }
449 }
450
451 void WebView::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
452 {
453   Toolkit::WebView webView = Toolkit::WebView::DownCast( Dali::BaseHandle( object ) );
454
455   if( webView )
456   {
457     WebView& impl = GetImpl( webView );
458     switch( index )
459     {
460       case Toolkit::WebView::Property::URL:
461       {
462         std::string url;
463         if( value.Get( url ) )
464         {
465           impl.LoadUrl( url );
466         }
467         break;
468       }
469       case Toolkit::WebView::Property::CACHE_MODEL:
470       {
471         Toolkit::WebView::CacheModel::Type output = impl.GetCacheModel();
472         GET_ENUM_VALUE( CacheModel, value, output );
473         impl.SetCacheModel( output );
474         break;
475       }
476       case Toolkit::WebView::Property::COOKIE_ACCEPT_POLICY:
477       {
478         Toolkit::WebView::CookieAcceptPolicy::Type output = impl.GetCookieAcceptPolicy();
479         GET_ENUM_VALUE( CookieAcceptPolicy, value, output );
480         impl.SetCookieAcceptPolicy( output );
481         break;
482       }
483       case Toolkit::WebView::Property::USER_AGENT:
484       {
485         std::string input;
486         if( value.Get( input ) )
487         {
488           impl.SetUserAgent( input );
489         }
490         break;
491       }
492       case Toolkit::WebView::Property::ENABLE_JAVASCRIPT:
493       {
494         bool input;
495         if( value.Get( input ) )
496         {
497           impl.EnableJavaScript( input );
498         }
499         break;
500       }
501       case Toolkit::WebView::Property::LOAD_IMAGES_AUTOMATICALLY:
502       {
503         bool input;
504         if( value.Get( input ) )
505         {
506           impl.LoadImagesAutomatically( input );
507         }
508         break;
509       }
510       case Toolkit::WebView::Property::DEFAULT_TEXT_ENCODING_NAME:
511       {
512         std::string input;
513         if( value.Get( input ) )
514         {
515           impl.SetDefaultTextEncodingName( input );
516         }
517         break;
518       }
519       case Toolkit::WebView::Property::DEFAULT_FONT_SIZE:
520       {
521         int input;
522         if( value.Get( input ) )
523         {
524           impl.SetDefaultFontSize( input );
525         }
526         break;
527       }
528       case Toolkit::WebView::Property::SCROLL_POSITION:
529       {
530         Vector2 input;
531         if ( value.Get( input ) )
532         {
533           impl.SetScrollPosition( input.x, input.y );
534         }
535         break;
536       }
537     }
538   }
539 }
540
541 Property::Value WebView::GetProperty( BaseObject* object, Property::Index propertyIndex )
542 {
543   Property::Value value;
544
545   Toolkit::WebView webView = Toolkit::WebView::DownCast( Dali::BaseHandle( object ) );
546
547   if( webView )
548   {
549     WebView& impl = GetImpl( webView );
550     switch( propertyIndex )
551     {
552       case Toolkit::WebView::Property::URL:
553       {
554         value = impl.mUrl;
555         break;
556       }
557       case Toolkit::WebView::Property::CACHE_MODEL:
558       {
559         value = GET_ENUM_STRING( CacheModel, impl.GetCacheModel() );
560         break;
561       }
562       case Toolkit::WebView::Property::COOKIE_ACCEPT_POLICY:
563       {
564         value = GET_ENUM_STRING( CookieAcceptPolicy, impl.GetCookieAcceptPolicy() );
565         break;
566       }
567       case Toolkit::WebView::Property::USER_AGENT:
568       {
569         value = impl.GetUserAgent();
570         break;
571       }
572       case Toolkit::WebView::Property::ENABLE_JAVASCRIPT:
573       {
574         value = impl.IsJavaScriptEnabled();
575         break;
576       }
577       case Toolkit::WebView::Property::LOAD_IMAGES_AUTOMATICALLY:
578       {
579         value = impl.AreImagesAutomaticallyLoaded();
580         break;
581       }
582       case Toolkit::WebView::Property::DEFAULT_TEXT_ENCODING_NAME:
583       {
584         value = impl.GetDefaultTextEncodingName();
585         break;
586       }
587       case Toolkit::WebView::Property::DEFAULT_FONT_SIZE:
588       {
589         value = impl.GetDefaultFontSize();
590         break;
591       }
592       case Toolkit::WebView::Property::SCROLL_POSITION:
593       {
594         int x, y;
595         impl.GetScrollPosition( x, y );
596         value = Vector2( x, y );
597         break;
598       }
599       case Toolkit::WebView::Property::SCROLL_SIZE:
600       {
601         int width, height;
602         impl.GetScrollSize( width, height );
603         value = Vector2( width, height );
604         break;
605       }
606       case Toolkit::WebView::Property::CONTENT_SIZE:
607       {
608         int width, height;
609         impl.GetContentSize( width, height );
610         value = Vector2( width, height );
611         break;
612       }
613       default:
614          break;
615     }
616   }
617
618   return value;
619 }
620
621 bool WebView::OnTouchEvent( Actor actor, const Dali::TouchEvent& touch )
622 {
623   bool result = false;
624
625   if( mWebEngine )
626   {
627     result = mWebEngine.SendTouchEvent( touch );
628   }
629   return result;
630 }
631
632 bool WebView::OnKeyEvent( const Dali::KeyEvent& event )
633 {
634   bool result = false;
635
636   if( mWebEngine )
637   {
638     result = mWebEngine.SendKeyEvent( event );
639   }
640   return result;
641 }
642
643 void WebView::OnKeyInputFocusGained()
644 {
645   if( mWebEngine )
646   {
647     mWebEngine.SetFocus( true );
648   }
649
650   EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
651 }
652
653 void WebView::OnKeyInputFocusLost()
654 {
655   if( mWebEngine )
656   {
657     mWebEngine.SetFocus( false );
658   }
659
660   EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
661 }
662
663 void WebView::SetScrollPosition( int x, int y )
664 {
665   if( mWebEngine )
666   {
667     mWebEngine.SetScrollPosition( x, y );
668   }
669 }
670
671 void WebView::GetScrollPosition( int& x, int& y ) const
672 {
673   if( mWebEngine )
674   {
675     mWebEngine.GetScrollPosition( x, y );
676   }
677 }
678
679 void WebView::GetScrollSize( int& width, int& height ) const
680 {
681   if( mWebEngine )
682   {
683     mWebEngine.GetScrollSize( width, height );
684   }
685 }
686
687 void WebView::GetContentSize( int& width, int& height ) const
688 {
689   if( mWebEngine )
690   {
691     mWebEngine.GetContentSize( width, height );
692   }
693 }
694
695 Toolkit::WebView::CacheModel::Type WebView::GetCacheModel() const
696 {
697   return mWebEngine ? static_cast< Toolkit::WebView::CacheModel::Type >( mWebEngine.GetCacheModel() ) : Toolkit::WebView::CacheModel::DOCUMENT_VIEWER;
698 }
699
700 void WebView::SetCacheModel( Toolkit::WebView::CacheModel::Type cacheModel )
701 {
702   if( mWebEngine )
703   {
704     mWebEngine.SetCacheModel( static_cast< WebEnginePlugin::CacheModel >( cacheModel ) );
705   }
706 }
707
708 Toolkit::WebView::CookieAcceptPolicy::Type WebView::GetCookieAcceptPolicy() const
709 {
710   return mWebEngine ? static_cast< Toolkit::WebView::CookieAcceptPolicy::Type >( mWebEngine.GetCookieAcceptPolicy() ) : Toolkit::WebView::CookieAcceptPolicy::NO_THIRD_PARTY;
711 }
712
713 void WebView::SetCookieAcceptPolicy( Toolkit::WebView::CookieAcceptPolicy::Type policy )
714 {
715   if( mWebEngine )
716   {
717     mWebEngine.SetCookieAcceptPolicy( static_cast< WebEnginePlugin::CookieAcceptPolicy >( policy ) );
718   }
719 }
720
721 const std::string& WebView::GetUserAgent() const
722 {
723   return mWebEngine ? mWebEngine.GetUserAgent() : kEmptyString;
724 }
725
726 void WebView::SetUserAgent( const std::string& userAgent )
727 {
728   if( mWebEngine )
729   {
730     mWebEngine.SetUserAgent( userAgent );
731   }
732 }
733
734 bool WebView::IsJavaScriptEnabled() const
735 {
736   return mWebEngine ? mWebEngine.IsJavaScriptEnabled() : true;
737 }
738
739 void WebView::EnableJavaScript( bool enabled )
740 {
741   if( mWebEngine )
742   {
743     mWebEngine.EnableJavaScript( enabled );
744   }
745 }
746
747 bool WebView::AreImagesAutomaticallyLoaded() const
748 {
749   return mWebEngine ? mWebEngine.AreImagesAutomaticallyLoaded() : true;
750 }
751
752 void WebView::LoadImagesAutomatically( bool automatic )
753 {
754   if( mWebEngine )
755   {
756     mWebEngine.LoadImagesAutomatically( automatic );
757   }
758 }
759
760 const std::string& WebView::GetDefaultTextEncodingName() const
761 {
762   return mWebEngine ? mWebEngine.GetDefaultTextEncodingName() : kEmptyString;
763 }
764
765 void WebView::SetDefaultTextEncodingName( const std::string& defaultTextEncodingName )
766 {
767   if( mWebEngine )
768   {
769     mWebEngine.SetDefaultTextEncodingName( defaultTextEncodingName );
770   }
771 }
772
773 int WebView::GetDefaultFontSize() const
774 {
775   return mWebEngine ? mWebEngine.GetDefaultFontSize() : 0;
776 }
777
778 void WebView::SetDefaultFontSize( int defaultFontSize )
779 {
780   if( mWebEngine )
781   {
782     mWebEngine.SetDefaultFontSize( defaultFontSize );
783   }
784 }
785
786 #undef GET_ENUM_STRING
787 #undef GET_ENUM_VALUE
788
789 } // namespace Internal
790
791 } // namespace Toolkit
792
793 } // namespace Dali