Merge "Replace Signal with std::function." into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / web-view / web-view-impl.cpp
1 /*
2  * Copyright (c) 2021 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 <dali/devel-api/adaptor-framework/web-engine-back-forward-list.h>
23 #include <dali/devel-api/adaptor-framework/web-engine-certificate.h>
24 #include <dali/devel-api/adaptor-framework/web-engine-console-message.h>
25 #include <dali/devel-api/adaptor-framework/web-engine-context-menu-item.h>
26 #include <dali/devel-api/adaptor-framework/web-engine-context-menu.h>
27 #include <dali/devel-api/adaptor-framework/web-engine-context.h>
28 #include <dali/devel-api/adaptor-framework/web-engine-cookie-manager.h>
29 #include <dali/devel-api/adaptor-framework/web-engine-form-repost-decision.h>
30 #include <dali/devel-api/adaptor-framework/web-engine-hit-test.h>
31 #include <dali/devel-api/adaptor-framework/web-engine-http-auth-handler.h>
32 #include <dali/devel-api/adaptor-framework/web-engine-load-error.h>
33 #include <dali/devel-api/adaptor-framework/web-engine-policy-decision.h>
34 #include <dali/devel-api/adaptor-framework/web-engine-request-interceptor.h>
35 #include <dali/devel-api/adaptor-framework/web-engine-settings.h>
36 #include <dali/devel-api/common/stage.h>
37 #include <dali/devel-api/scripting/enum-helper.h>
38 #include <dali/devel-api/scripting/scripting.h>
39 #include <dali/public-api/adaptor-framework/native-image-source.h>
40 #include <dali/public-api/object/type-registry-helper.h>
41 #include <dali/public-api/object/type-registry.h>
42 #include <cstring>
43 #include <memory>
44
45 // INTERNAL INCLUDES
46 #include <dali-toolkit/devel-api/controls/control-devel.h>
47 #include <dali-toolkit/devel-api/controls/web-view/web-back-forward-list.h>
48 #include <dali-toolkit/devel-api/controls/web-view/web-context.h>
49 #include <dali-toolkit/devel-api/controls/web-view/web-cookie-manager.h>
50 #include <dali-toolkit/devel-api/controls/web-view/web-settings.h>
51 #include <dali-toolkit/devel-api/image-loader/texture-manager.h>
52 #include <dali-toolkit/internal/visuals/visual-factory-impl.h>
53 #include <dali-toolkit/public-api/image-loader/image.h>
54 #include <dali-toolkit/public-api/visuals/image-visual-properties.h>
55
56 namespace Dali
57 {
58 namespace Toolkit
59 {
60 namespace Internal
61 {
62 namespace
63 {
64 BaseHandle Create()
65 {
66   return Toolkit::WebView::New();
67 }
68
69 // clang-format off
70 DALI_TYPE_REGISTRATION_BEGIN(Toolkit::WebView, Toolkit::Control, Create)
71
72 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "url",                     STRING,  URL                       )
73 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "userAgent",               STRING,  USER_AGENT                )
74 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "scrollPosition",          VECTOR2, SCROLL_POSITION           )
75 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "scrollSize",              VECTOR2, SCROLL_SIZE               )
76 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "contentSize",             VECTOR2, CONTENT_SIZE              )
77 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "title",                   STRING,  TITLE                     )
78 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "videoHoleEnabled",        BOOLEAN, VIDEO_HOLE_ENABLED        )
79 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "mouseEventsEnabled",      BOOLEAN, MOUSE_EVENTS_ENABLED      )
80 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "keyEventsEnabled",        BOOLEAN, KEY_EVENTS_ENABLED        )
81 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "documentBackgroundColor", VECTOR4, DOCUMENT_BACKGROUND_COLOR )
82 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "tilesClearedWhenHidden",  BOOLEAN, TILES_CLEARED_WHEN_HIDDEN )
83 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "tileCoverAreaMultiplier", FLOAT,   TILE_COVER_AREA_MULTIPLIER)
84 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "cursorEnabledByClient",   BOOLEAN, CURSOR_ENABLED_BY_CLIENT  )
85 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "selectedText",            STRING,  SELECTED_TEXT             )
86 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "pageZoomFactor",          FLOAT,   PAGE_ZOOM_FACTOR          )
87 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "textZoomFactor",          FLOAT,   TEXT_ZOOM_FACTOR          )
88 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "loadProgressPercentage",  FLOAT,   LOAD_PROGRESS_PERCENTAGE  )
89
90 DALI_TYPE_REGISTRATION_END()
91 // clang-format on
92
93 } // namespace
94
95 #define GET_ENUM_STRING(structName, inputExp) \
96   Scripting::GetLinearEnumerationName<Toolkit::WebView::structName::Type>(static_cast<Toolkit::WebView::structName::Type>(inputExp), structName##_TABLE, structName##_TABLE_COUNT)
97
98 #define GET_ENUM_VALUE(structName, inputExp, outputExp) \
99   Scripting::GetEnumerationProperty<Toolkit::WebView::structName::Type>(inputExp, structName##_TABLE, structName##_TABLE_COUNT, outputExp)
100
101 WebView::WebView(const std::string& locale, const std::string& timezoneId)
102 : Control(ControlBehaviour(ACTOR_BEHAVIOUR_DEFAULT | DISABLE_STYLE_CHANGE_SIGNALS)),
103   mVisual(),
104   mWebViewSize(Stage::GetCurrent().GetSize()),
105   mWebEngine(),
106   mWebViewArea(0, 0, mWebViewSize.width, mWebViewSize.height),
107   mVideoHoleEnabled(false),
108   mMouseEventsEnabled(true),
109   mKeyEventsEnabled(true),
110   mScreenshotCapturedCallback(nullptr)
111 {
112   mWebEngine = Dali::WebEngine::New();
113
114   // WebEngine is empty when it is not properly initialized.
115   if(mWebEngine)
116   {
117     mWebEngine.Create(mWebViewSize.width, mWebViewSize.height, locale, timezoneId);
118   }
119 }
120
121 WebView::WebView(uint32_t argc, char** argv)
122 : Control(ControlBehaviour(ACTOR_BEHAVIOUR_DEFAULT | DISABLE_STYLE_CHANGE_SIGNALS)),
123   mVisual(),
124   mWebViewSize(Stage::GetCurrent().GetSize()),
125   mWebEngine(),
126   mWebViewArea(0, 0, mWebViewSize.width, mWebViewSize.height),
127   mVideoHoleEnabled(false),
128   mMouseEventsEnabled(true),
129   mKeyEventsEnabled(true),
130   mScreenshotCapturedCallback(nullptr)
131 {
132   mWebEngine = Dali::WebEngine::New();
133
134   // WebEngine is empty when it is not properly initialized.
135   if(mWebEngine)
136   {
137     mWebEngine.Create(mWebViewSize.width, mWebViewSize.height, argc, argv);
138   }
139 }
140
141 WebView::WebView()
142 : WebView("", "")
143 {
144 }
145
146 WebView::~WebView()
147 {
148   if(mWebEngine)
149   {
150     mWebEngine.FrameRenderedSignal().Disconnect(this, &WebView::OnFrameRendered);
151     mWebEngine.Destroy();
152   }
153 }
154
155 Toolkit::WebView WebView::New()
156 {
157   WebView*         impl   = new WebView();
158   Toolkit::WebView handle = Toolkit::WebView(*impl);
159
160   impl->Initialize();
161   return handle;
162 }
163
164 Toolkit::WebView WebView::New(const std::string& locale, const std::string& timezoneId)
165 {
166   WebView*         impl   = new WebView(locale, timezoneId);
167   Toolkit::WebView handle = Toolkit::WebView(*impl);
168
169   impl->Initialize();
170   return handle;
171 }
172
173 Toolkit::WebView WebView::New(uint32_t argc, char** argv)
174 {
175   WebView*         impl   = new WebView(argc, argv);
176   Toolkit::WebView handle = Toolkit::WebView(*impl);
177
178   impl->Initialize();
179   return handle;
180 }
181
182 void WebView::OnInitialize()
183 {
184   Actor self = Self();
185
186   self.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
187   self.TouchedSignal().Connect(this, &WebView::OnTouchEvent);
188   self.HoveredSignal().Connect(this, &WebView::OnHoverEvent);
189   self.WheelEventSignal().Connect(this, &WebView::OnWheelEvent);
190   Dali::DevelActor::VisibilityChangedSignal(self).Connect(this, &WebView::OnVisibilityChanged);
191
192   mPositionUpdateNotification = self.AddPropertyNotification(Actor::Property::WORLD_POSITION, StepCondition(1.0f, 1.0f));
193   mSizeUpdateNotification     = self.AddPropertyNotification(Actor::Property::SIZE, StepCondition(1.0f, 1.0f));
194   mScaleUpdateNotification    = self.AddPropertyNotification(Actor::Property::WORLD_SCALE, StepCondition(0.1f, 1.0f));
195   mPositionUpdateNotification.NotifySignal().Connect(this, &WebView::UpdateDisplayArea);
196   mSizeUpdateNotification.NotifySignal().Connect(this, &WebView::UpdateDisplayArea);
197   mScaleUpdateNotification.NotifySignal().Connect(this, &WebView::UpdateDisplayArea);
198
199   if(mWebEngine)
200   {
201     mWebEngine.FrameRenderedSignal().Connect(this, &WebView::OnFrameRendered);
202     mWebContext         = std::unique_ptr<Dali::Toolkit::WebContext>(new WebContext(mWebEngine.GetContext()));
203     mWebCookieManager   = std::unique_ptr<Dali::Toolkit::WebCookieManager>(new WebCookieManager(mWebEngine.GetCookieManager()));
204     mWebSettings        = std::unique_ptr<Dali::Toolkit::WebSettings>(new WebSettings(mWebEngine.GetSettings()));
205     mWebBackForwardList = std::unique_ptr<Dali::Toolkit::WebBackForwardList>(new WebBackForwardList(mWebEngine.GetBackForwardList()));
206   }
207 }
208
209 Dali::Toolkit::WebSettings* WebView::GetSettings() const
210 {
211   return mWebSettings.get();
212 }
213
214 Dali::Toolkit::WebContext* WebView::GetContext() const
215 {
216   return mWebContext.get();
217 }
218
219 Dali::Toolkit::WebCookieManager* WebView::GetCookieManager() const
220 {
221   return mWebCookieManager.get();
222 }
223
224 Dali::Toolkit::WebBackForwardList* WebView::GetBackForwardList() const
225 {
226   return mWebBackForwardList.get();
227 }
228
229 Dali::Toolkit::ImageView WebView::GetFavicon() const
230 {
231   Dali::Toolkit::ImageView faviconView;
232   if(mWebEngine)
233   {
234     Dali::PixelData pixelData = mWebEngine.GetFavicon();
235     faviconView               = CreateImageView(pixelData);
236   }
237   return faviconView;
238 }
239
240 void WebView::LoadUrl(const std::string& url)
241 {
242   if(mWebEngine)
243   {
244     if(!mVisual)
245     {
246       mWebEngine.FrameRenderedSignal().Connect(this, &WebView::OnInitialFrameRendered);
247     }
248
249     mWebEngine.LoadUrl(url);
250   }
251 }
252
253 void WebView::LoadHtmlString(const std::string& htmlString)
254 {
255   if(mWebEngine)
256   {
257     if(!mVisual)
258     {
259       mWebEngine.FrameRenderedSignal().Connect(this, &WebView::OnInitialFrameRendered);
260     }
261
262     mWebEngine.LoadHtmlString(htmlString);
263   }
264 }
265
266 bool WebView::LoadHtmlStringOverrideCurrentEntry(const std::string& html, const std::string& basicUri, const std::string& unreachableUrl)
267 {
268   if(!mWebEngine)
269     return false;
270
271   if(!mVisual)
272   {
273     mWebEngine.FrameRenderedSignal().Connect(this, &WebView::OnInitialFrameRendered);
274   }
275
276   return mWebEngine.LoadHtmlStringOverrideCurrentEntry(html, basicUri, unreachableUrl);
277 }
278
279 bool WebView::LoadContents(const std::string& contents, uint32_t contentSize, const std::string& mimeType, const std::string& encoding, const std::string& baseUri)
280 {
281   if(!mWebEngine)
282     return false;
283
284   if(!mVisual)
285   {
286     mWebEngine.FrameRenderedSignal().Connect(this, &WebView::OnInitialFrameRendered);
287   }
288
289   return mWebEngine.LoadContents(contents, contentSize, mimeType, encoding, baseUri);
290 }
291
292 void WebView::Reload()
293 {
294   if(mWebEngine)
295   {
296     mWebEngine.Reload();
297   }
298 }
299
300 bool WebView::ReloadWithoutCache()
301 {
302   return mWebEngine ? mWebEngine.ReloadWithoutCache() : false;
303 }
304
305 void WebView::StopLoading()
306 {
307   if(mWebEngine)
308   {
309     mWebEngine.StopLoading();
310   }
311 }
312
313 void WebView::Suspend()
314 {
315   if(mWebEngine)
316   {
317     mWebEngine.Suspend();
318   }
319 }
320
321 void WebView::Resume()
322 {
323   if(mWebEngine)
324   {
325     mWebEngine.Resume();
326   }
327 }
328
329 void WebView::SuspendNetworkLoading()
330 {
331   if(mWebEngine)
332   {
333     mWebEngine.SuspendNetworkLoading();
334   }
335 }
336
337 void WebView::ResumeNetworkLoading()
338 {
339   if(mWebEngine)
340   {
341     mWebEngine.ResumeNetworkLoading();
342   }
343 }
344
345 bool WebView::AddCustomHeader(const std::string& name, const std::string& value)
346 {
347   return mWebEngine ? mWebEngine.AddCustomHeader(name, value) : false;
348 }
349
350 bool WebView::RemoveCustomHeader(const std::string& name)
351 {
352   return mWebEngine ? mWebEngine.RemoveCustomHeader(name) : false;
353 }
354
355 uint32_t WebView::StartInspectorServer(uint32_t port)
356 {
357   return mWebEngine ? mWebEngine.StartInspectorServer(port) : false;
358 }
359
360 bool WebView::StopInspectorServer()
361 {
362   return mWebEngine ? mWebEngine.StopInspectorServer() : false;
363 }
364
365 void WebView::ScrollBy(int32_t deltaX, int32_t deltaY)
366 {
367   if(mWebEngine)
368   {
369     mWebEngine.ScrollBy(deltaX, deltaY);
370   }
371 }
372
373 bool WebView::ScrollEdgeBy(int32_t deltaX, int32_t deltaY)
374 {
375   return mWebEngine ? mWebEngine.ScrollEdgeBy(deltaX, deltaY) : false;
376 }
377
378 bool WebView::CanGoForward()
379 {
380   return mWebEngine ? mWebEngine.CanGoForward() : false;
381 }
382
383 void WebView::GoForward()
384 {
385   if(mWebEngine)
386   {
387     mWebEngine.GoForward();
388   }
389 }
390
391 bool WebView::CanGoBack()
392 {
393   return mWebEngine ? mWebEngine.CanGoBack() : false;
394 }
395
396 void WebView::GoBack()
397 {
398   if(mWebEngine)
399   {
400     mWebEngine.GoBack();
401   }
402 }
403
404 void WebView::EvaluateJavaScript(const std::string& script, std::function<void(const std::string&)> resultHandler)
405 {
406   if(mWebEngine)
407   {
408     mWebEngine.EvaluateJavaScript(script, resultHandler);
409   }
410 }
411
412 void WebView::AddJavaScriptMessageHandler(const std::string& exposedObjectName, std::function<void(const std::string&)> handler)
413 {
414   if(mWebEngine)
415   {
416     mWebEngine.AddJavaScriptMessageHandler(exposedObjectName, handler);
417   }
418 }
419
420 void WebView::RegisterJavaScriptAlertCallback(Dali::WebEnginePlugin::JavaScriptAlertCallback callback)
421 {
422   if(mWebEngine)
423   {
424     mWebEngine.RegisterJavaScriptAlertCallback(callback);
425   }
426 }
427
428 void WebView::JavaScriptAlertReply()
429 {
430   if(mWebEngine)
431   {
432     mWebEngine.JavaScriptAlertReply();
433   }
434 }
435
436 void WebView::RegisterJavaScriptConfirmCallback(Dali::WebEnginePlugin::JavaScriptConfirmCallback callback)
437 {
438   if(mWebEngine)
439   {
440     mWebEngine.RegisterJavaScriptConfirmCallback(callback);
441   }
442 }
443
444 void WebView::JavaScriptConfirmReply(bool confirmed)
445 {
446   if(mWebEngine)
447   {
448     mWebEngine.JavaScriptConfirmReply(confirmed);
449   }
450 }
451
452 void WebView::RegisterJavaScriptPromptCallback(Dali::WebEnginePlugin::JavaScriptPromptCallback callback)
453 {
454   if(mWebEngine)
455   {
456     mWebEngine.RegisterJavaScriptPromptCallback(callback);
457   }
458 }
459
460 void WebView::JavaScriptPromptReply(const std::string& result)
461 {
462   if(mWebEngine)
463   {
464     mWebEngine.JavaScriptPromptReply(result);
465   }
466 }
467
468 std::unique_ptr<Dali::WebEngineHitTest> WebView::CreateHitTest(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode)
469 {
470   std::unique_ptr<Dali::WebEngineHitTest> webHitTest;
471   if(!mWebEngine)
472   {
473     return webHitTest;
474   }
475
476   return mWebEngine.CreateHitTest(x, y, mode);
477 }
478
479 bool WebView::CreateHitTestAsynchronously(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode, Dali::WebEnginePlugin::WebEngineHitTestCreatedCallback callback)
480 {
481   bool result = false;
482   if(mWebEngine)
483   {
484     result = mWebEngine.CreateHitTestAsynchronously(x, y, mode, callback);
485   }
486   return result;
487 }
488
489 void WebView::ClearHistory()
490 {
491   if(mWebEngine)
492   {
493     mWebEngine.ClearHistory();
494   }
495 }
496
497 void WebView::ClearAllTilesResources()
498 {
499   if(mWebEngine)
500   {
501     mWebEngine.ClearAllTilesResources();
502   }
503 }
504
505 void WebView::SetScaleFactor(float scaleFactor, Dali::Vector2 point)
506 {
507   if(mWebEngine)
508   {
509     mWebEngine.SetScaleFactor(scaleFactor, point);
510   }
511 }
512
513 float WebView::GetScaleFactor() const
514 {
515   return mWebEngine ? mWebEngine.GetScaleFactor() : 0.0f;
516 }
517
518 void WebView::ActivateAccessibility(bool activated)
519 {
520   if(mWebEngine)
521   {
522     mWebEngine.ActivateAccessibility(activated);
523   }
524 }
525
526 bool WebView::HighlightText(const std::string& text, Dali::WebEnginePlugin::FindOption options, uint32_t maxMatchCount)
527 {
528   return mWebEngine ? mWebEngine.HighlightText(text, options, maxMatchCount) : false;
529 }
530
531 void WebView::AddDynamicCertificatePath(const std::string& host, const std::string& certPath)
532 {
533   if(mWebEngine)
534   {
535     mWebEngine.AddDynamicCertificatePath(host, certPath);
536   }
537 }
538
539 Dali::Toolkit::ImageView WebView::GetScreenshot(Dali::Rect<int32_t> viewArea, float scaleFactor)
540 {
541   Dali::Toolkit::ImageView imageView;
542   if(mWebEngine)
543   {
544     Dali::PixelData pixelData = mWebEngine.GetScreenshot(viewArea, scaleFactor);
545     imageView                 = CreateImageView(pixelData);
546   }
547   return imageView;
548 }
549
550 bool WebView::GetScreenshotAsynchronously(Dali::Rect<int32_t> viewArea, float scaleFactor, Dali::Toolkit::WebView::WebViewScreenshotCapturedCallback callback)
551 {
552   mScreenshotCapturedCallback = callback;
553   return mWebEngine ? mWebEngine.GetScreenshotAsynchronously(viewArea, scaleFactor, std::bind(&WebView::OnScreenshotCaptured, this, std::placeholders::_1)) : false;
554 }
555
556 bool WebView::CheckVideoPlayingAsynchronously(Dali::WebEnginePlugin::VideoPlayingCallback callback)
557 {
558   return mWebEngine ? mWebEngine.CheckVideoPlayingAsynchronously(callback) : false;
559 }
560
561 void WebView::RegisterGeolocationPermissionCallback(Dali::WebEnginePlugin::GeolocationPermissionCallback callback)
562 {
563   if(mWebEngine)
564   {
565     mWebEngine.RegisterGeolocationPermissionCallback(callback);
566   }
567 }
568
569 void WebView::SetTtsFocus(bool focused)
570 {
571   if(mWebEngine && !HasKeyInputFocus())
572   {
573     mWebEngine.SetFocus(focused);
574   }
575 }
576
577 void WebView::UpdateDisplayArea(Dali::PropertyNotification& /*source*/)
578 {
579   if(!mWebEngine)
580     return;
581
582   Actor self(Self());
583
584   bool    positionUsesAnchorPoint = self.GetProperty<bool>(Actor::Property::POSITION_USES_ANCHOR_POINT);
585   Vector3 actorSize               = self.GetCurrentProperty<Vector3>(Actor::Property::SIZE) * self.GetCurrentProperty<Vector3>(Actor::Property::SCALE);
586   Vector3 anchorPointOffSet       = actorSize * (positionUsesAnchorPoint ? self.GetCurrentProperty<Vector3>(Actor::Property::ANCHOR_POINT) : AnchorPoint::TOP_LEFT);
587   Vector2 screenPosition          = self.GetProperty<Vector2>(Actor::Property::SCREEN_POSITION);
588
589   Dali::Rect<int32_t> displayArea;
590   displayArea.x      = screenPosition.x - anchorPointOffSet.x;
591   displayArea.y      = screenPosition.y - anchorPointOffSet.y;
592   displayArea.width  = actorSize.x;
593   displayArea.height = actorSize.y;
594
595   Size displaySize = Size(displayArea.width, displayArea.height);
596   if(mWebViewSize != displaySize)
597   {
598     mWebViewSize = displaySize;
599   }
600
601   if(mWebViewArea != displayArea)
602   {
603     mWebViewArea = displayArea;
604     mWebEngine.UpdateDisplayArea(mWebViewArea);
605   }
606 }
607
608 void WebView::EnableVideoHole(bool enabled)
609 {
610   mVideoHoleEnabled = enabled;
611
612   EnableBlendMode(!mVideoHoleEnabled);
613
614   if(mWebEngine)
615   {
616     mWebEngine.EnableVideoHole(mVideoHoleEnabled);
617   }
618 }
619
620 void WebView::EnableBlendMode(bool blendEnabled)
621 {
622   Actor self = Self();
623   for(uint32_t i = 0; i < self.GetRendererCount(); i++)
624   {
625     Dali::Renderer render = self.GetRendererAt(i);
626     render.SetProperty(Renderer::Property::BLEND_MODE, blendEnabled ? BlendMode::ON : BlendMode::OFF);
627   }
628 }
629
630 Dali::Toolkit::ImageView WebView::CreateImageView(Dali::PixelData pixel) const
631 {
632   if(!pixel)
633   {
634     return Dali::Toolkit::ImageView();
635   }
636
637   std::string              url       = Dali::Toolkit::Image::GenerateUrl(pixel);
638   Dali::Toolkit::ImageView imageView = Dali::Toolkit::ImageView::New(url);
639   imageView.SetProperty(Dali::Actor::Property::SIZE, Vector2(pixel.GetWidth(), pixel.GetHeight()));
640   return imageView;
641 }
642
643 void WebView::RegisterPageLoadStartedCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback)
644 {
645   if(mWebEngine)
646   {
647     mWebEngine.RegisterPageLoadStartedCallback(callback);
648   }
649 }
650
651 void WebView::RegisterPageLoadInProgressCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback)
652 {
653   if(mWebEngine)
654   {
655     mWebEngine.RegisterPageLoadInProgressCallback(callback);
656   }
657 }
658
659 void WebView::RegisterPageLoadFinishedCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback)
660 {
661   if(mWebEngine)
662   {
663     mWebEngine.RegisterPageLoadFinishedCallback(callback);
664   }
665 }
666
667 void WebView::RegisterPageLoadErrorCallback(Dali::WebEnginePlugin::WebEnginePageLoadErrorCallback callback)
668 {
669   if(mWebEngine)
670   {
671     mWebEngine.RegisterPageLoadErrorCallback(callback);
672   }
673 }
674
675 void WebView::RegisterScrollEdgeReachedCallback(Dali::WebEnginePlugin::WebEngineScrollEdgeReachedCallback callback)
676 {
677   if(mWebEngine)
678   {
679     mWebEngine.RegisterScrollEdgeReachedCallback(callback);
680   }
681 }
682
683 void WebView::RegisterUrlChangedCallback(Dali::WebEnginePlugin::WebEngineUrlChangedCallback callback)
684 {
685   if(mWebEngine)
686   {
687     mWebEngine.RegisterUrlChangedCallback(callback);
688   }
689 }
690
691 void WebView::RegisterFormRepostDecidedCallback(Dali::WebEnginePlugin::WebEngineFormRepostDecidedCallback callback)
692 {
693   if(mWebEngine)
694   {
695     mWebEngine.RegisterFormRepostDecidedCallback(callback);
696   }
697 }
698
699 void WebView::RegisterFrameRenderedCallback(Dali::WebEnginePlugin::WebEngineFrameRenderedCallback callback)
700 {
701   mFrameRenderedCallback = callback;
702 }
703
704 void WebView::RegisterRequestInterceptorCallback(Dali::WebEnginePlugin::WebEngineRequestInterceptorCallback callback)
705 {
706   if(mWebEngine)
707   {
708     mWebEngine.RegisterRequestInterceptorCallback(callback);
709   }
710 }
711
712 void WebView::RegisterConsoleMessageReceivedCallback(Dali::WebEnginePlugin::WebEngineConsoleMessageReceivedCallback callback)
713 {
714   if(mWebEngine)
715   {
716     mWebEngine.RegisterConsoleMessageReceivedCallback(callback);
717   }
718 }
719
720 void WebView::RegisterResponsePolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineResponsePolicyDecidedCallback callback)
721 {
722   if(mWebEngine)
723   {
724     mWebEngine.RegisterResponsePolicyDecidedCallback(callback);
725   }
726 }
727
728 void WebView::RegisterCertificateConfirmedCallback(Dali::WebEnginePlugin::WebEngineCertificateCallback callback)
729 {
730   if(mWebEngine)
731   {
732     mWebEngine.RegisterCertificateConfirmedCallback(callback);
733   }
734 }
735
736 void WebView::RegisterSslCertificateChangedCallback(Dali::WebEnginePlugin::WebEngineCertificateCallback callback)
737 {
738   if(mWebEngine)
739   {
740     mWebEngine.RegisterSslCertificateChangedCallback(callback);
741   }
742 }
743
744 void WebView::RegisterHttpAuthHandlerCallback(Dali::WebEnginePlugin::WebEngineHttpAuthHandlerCallback callback)
745 {
746   if(mWebEngine)
747   {
748     mWebEngine.RegisterHttpAuthHandlerCallback(callback);
749   }
750 }
751
752 void WebView::RegisterContextMenuShownCallback(Dali::WebEnginePlugin::WebEngineContextMenuShownCallback callback)
753 {
754   if(mWebEngine)
755   {
756     mWebEngine.RegisterContextMenuShownCallback(callback);
757   }
758 }
759
760 void WebView::RegisterContextMenuHiddenCallback(Dali::WebEnginePlugin::WebEngineContextMenuHiddenCallback callback)
761 {
762   if(mWebEngine)
763   {
764     mWebEngine.RegisterContextMenuHiddenCallback(callback);
765   }
766 }
767
768 void WebView::OnFrameRendered()
769 {
770   if(mFrameRenderedCallback)
771   {
772     mFrameRenderedCallback();
773   }
774 }
775
776 void WebView::OnInitialFrameRendered()
777 {
778   mWebEngine.FrameRenderedSignal().Disconnect(this, &WebView::OnInitialFrameRendered);
779
780   Texture           texture        = Dali::Texture::New(*mWebEngine.GetNativeImageSource());
781   const std::string nativeImageUrl = Dali::Toolkit::TextureManager::AddTexture(texture);
782   mVisual                          = Toolkit::VisualFactory::Get().CreateVisual({{Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE}, {Toolkit::ImageVisual::Property::URL, nativeImageUrl}});
783
784   if(mVisual)
785   {
786     DevelControl::RegisterVisual(*this, Toolkit::WebView::Property::URL, mVisual);
787     EnableBlendMode(!mVideoHoleEnabled);
788   }
789 }
790
791 void WebView::OnVisibilityChanged(Actor actor, bool isVisible, Dali::DevelActor::VisibilityChange::Type type)
792 {
793   if(type == Dali::DevelActor::VisibilityChange::Type::SELF)
794   {
795     SetVisibility(isVisible);
796   }
797 }
798
799 void WebView::OnScreenshotCaptured(Dali::PixelData pixel)
800 {
801   if(mScreenshotCapturedCallback)
802   {
803     Dali::Toolkit::ImageView imageView = CreateImageView(pixel);
804     mScreenshotCapturedCallback(imageView);
805   }
806 }
807
808 void WebView::OnSceneConnection(int depth)
809 {
810   Control::OnSceneConnection(depth);
811   EnableBlendMode(!mVideoHoleEnabled);
812 }
813
814 bool WebView::OnTouchEvent(Actor actor, const Dali::TouchEvent& touch)
815 {
816   bool result = false;
817
818   if(mWebEngine)
819   {
820     result = mWebEngine.SendTouchEvent(touch);
821   }
822   return result;
823 }
824
825 bool WebView::OnKeyEvent(const Dali::KeyEvent& event)
826 {
827   bool result = false;
828
829   if(mWebEngine)
830   {
831     result = mWebEngine.SendKeyEvent(event);
832   }
833   return result;
834 }
835
836 bool WebView::OnHoverEvent(Actor actor, const Dali::HoverEvent& hover)
837 {
838   bool result = false;
839   if(mWebEngine && mMouseEventsEnabled)
840   {
841     result = mWebEngine.SendHoverEvent(hover);
842   }
843   return result;
844 }
845
846 bool WebView::OnWheelEvent(Actor actor, const Dali::WheelEvent& wheel)
847 {
848   bool result = false;
849   if(mWebEngine && mMouseEventsEnabled)
850   {
851     result = mWebEngine.SendWheelEvent(wheel);
852   }
853   return result;
854 }
855
856 void WebView::OnKeyInputFocusGained()
857 {
858   if(mWebEngine)
859   {
860     mWebEngine.SetFocus(true);
861   }
862
863   EmitKeyInputFocusSignal(true); // Calls back into the Control hence done last.
864 }
865
866 void WebView::OnKeyInputFocusLost()
867 {
868   if(mWebEngine)
869   {
870     mWebEngine.SetFocus(false);
871   }
872
873   EmitKeyInputFocusSignal(false); // Calls back into the Control hence done last.
874 }
875
876 Vector3 WebView::GetNaturalSize()
877 {
878   if(mVisual)
879   {
880     Vector2 rendererNaturalSize;
881     mVisual.GetNaturalSize(rendererNaturalSize);
882     return Vector3(rendererNaturalSize);
883   }
884
885   return Vector3(mWebViewSize);
886 }
887
888 void WebView::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value)
889 {
890   Toolkit::WebView webView = Toolkit::WebView::DownCast(Dali::BaseHandle(object));
891
892   if(webView)
893   {
894     WebView& impl = GetImpl(webView);
895     switch(index)
896     {
897       case Toolkit::WebView::Property::URL:
898       {
899         std::string url;
900         if(value.Get(url))
901         {
902           impl.LoadUrl(url);
903         }
904         break;
905       }
906       case Toolkit::WebView::Property::USER_AGENT:
907       {
908         std::string input;
909         if(value.Get(input))
910         {
911           impl.SetUserAgent(input);
912         }
913         break;
914       }
915       case Toolkit::WebView::Property::SCROLL_POSITION:
916       {
917         Vector2 input;
918         if(value.Get(input))
919         {
920           impl.SetScrollPosition(input.x, input.y);
921         }
922         break;
923       }
924       case Toolkit::WebView::Property::VIDEO_HOLE_ENABLED:
925       {
926         bool input;
927         if(value.Get(input))
928         {
929           impl.EnableVideoHole(input);
930         }
931         break;
932       }
933       case Toolkit::WebView::Property::MOUSE_EVENTS_ENABLED:
934       {
935         bool input;
936         if(value.Get(input))
937         {
938           impl.EnableMouseEvents(input);
939         }
940         break;
941       }
942       case Toolkit::WebView::Property::KEY_EVENTS_ENABLED:
943       {
944         bool input;
945         if(value.Get(input))
946         {
947           impl.EnableKeyEvents(input);
948         }
949         break;
950       }
951       case Toolkit::WebView::Property::DOCUMENT_BACKGROUND_COLOR:
952       {
953         Vector4 input;
954         if(value.Get(input))
955         {
956           impl.SetDocumentBackgroundColor(input);
957         }
958         break;
959       }
960       case Toolkit::WebView::Property::TILES_CLEARED_WHEN_HIDDEN:
961       {
962         bool input;
963         if(value.Get(input))
964         {
965           impl.ClearTilesWhenHidden(input);
966         }
967         break;
968       }
969       case Toolkit::WebView::Property::TILE_COVER_AREA_MULTIPLIER:
970       {
971         float input;
972         if(value.Get(input))
973         {
974           impl.SetTileCoverAreaMultiplier(input);
975         }
976         break;
977       }
978       case Toolkit::WebView::Property::CURSOR_ENABLED_BY_CLIENT:
979       {
980         bool input;
981         if(value.Get(input))
982         {
983           impl.EnableCursorByClient(input);
984         }
985         break;
986       }
987       case Toolkit::WebView::Property::PAGE_ZOOM_FACTOR:
988       {
989         float input;
990         if(value.Get(input))
991         {
992           impl.SetPageZoomFactor(input);
993         }
994         break;
995       }
996       case Toolkit::WebView::Property::TEXT_ZOOM_FACTOR:
997       {
998         float input;
999         if(value.Get(input))
1000         {
1001           impl.SetTextZoomFactor(input);
1002         }
1003         break;
1004       }
1005       default:
1006         break;
1007     }
1008   }
1009 }
1010
1011 Property::Value WebView::GetProperty(BaseObject* object, Property::Index propertyIndex)
1012 {
1013   Property::Value value;
1014
1015   Toolkit::WebView webView = Toolkit::WebView::DownCast(Dali::BaseHandle(object));
1016
1017   if(webView)
1018   {
1019     WebView& impl = GetImpl(webView);
1020     switch(propertyIndex)
1021     {
1022       case Toolkit::WebView::Property::URL:
1023       {
1024         value = impl.GetUrl();
1025         break;
1026       }
1027       case Toolkit::WebView::Property::USER_AGENT:
1028       {
1029         value = impl.GetUserAgent();
1030         break;
1031       }
1032       case Toolkit::WebView::Property::SCROLL_POSITION:
1033       {
1034         value = impl.GetScrollPosition();
1035         break;
1036       }
1037       case Toolkit::WebView::Property::SCROLL_SIZE:
1038       {
1039         value = impl.GetScrollSize();
1040         break;
1041       }
1042       case Toolkit::WebView::Property::CONTENT_SIZE:
1043       {
1044         value = impl.GetContentSize();
1045         break;
1046       }
1047       case Toolkit::WebView::Property::TITLE:
1048       {
1049         value = impl.GetTitle();
1050         break;
1051       }
1052       case Toolkit::WebView::Property::VIDEO_HOLE_ENABLED:
1053       {
1054         value = impl.mVideoHoleEnabled;
1055         break;
1056       }
1057       case Toolkit::WebView::Property::MOUSE_EVENTS_ENABLED:
1058       {
1059         value = impl.mMouseEventsEnabled;
1060         break;
1061       }
1062       case Toolkit::WebView::Property::KEY_EVENTS_ENABLED:
1063       {
1064         value = impl.mKeyEventsEnabled;
1065         break;
1066       }
1067       case Toolkit::WebView::Property::SELECTED_TEXT:
1068       {
1069         value = impl.GetSelectedText();
1070         break;
1071       }
1072       case Toolkit::WebView::Property::PAGE_ZOOM_FACTOR:
1073       {
1074         value = impl.GetPageZoomFactor();
1075         break;
1076       }
1077       case Toolkit::WebView::Property::TEXT_ZOOM_FACTOR:
1078       {
1079         value = impl.GetTextZoomFactor();
1080         break;
1081       }
1082       case Toolkit::WebView::Property::LOAD_PROGRESS_PERCENTAGE:
1083       {
1084         value = impl.GetLoadProgressPercentage();
1085         break;
1086       }
1087       default:
1088         break;
1089     }
1090   }
1091
1092   return value;
1093 }
1094
1095 void WebView::SetScrollPosition(int32_t x, int32_t y)
1096 {
1097   if(mWebEngine)
1098   {
1099     mWebEngine.SetScrollPosition(x, y);
1100   }
1101 }
1102
1103 Dali::Vector2 WebView::GetScrollPosition() const
1104 {
1105   return mWebEngine ? mWebEngine.GetScrollPosition() : Dali::Vector2::ZERO;
1106 }
1107
1108 Dali::Vector2 WebView::GetScrollSize() const
1109 {
1110   return mWebEngine ? mWebEngine.GetScrollSize() : Dali::Vector2::ZERO;
1111 }
1112
1113 Dali::Vector2 WebView::GetContentSize() const
1114 {
1115   return mWebEngine ? mWebEngine.GetContentSize() : Dali::Vector2::ZERO;
1116 }
1117
1118 std::string WebView::GetTitle() const
1119 {
1120   return mWebEngine ? mWebEngine.GetTitle() : std::string();
1121 }
1122
1123 void WebView::SetDocumentBackgroundColor(Dali::Vector4 color)
1124 {
1125   if(mWebEngine)
1126   {
1127     mWebEngine.SetDocumentBackgroundColor(color);
1128   }
1129 }
1130
1131 void WebView::ClearTilesWhenHidden(bool cleared)
1132 {
1133   if(mWebEngine)
1134   {
1135     mWebEngine.ClearTilesWhenHidden(cleared);
1136   }
1137 }
1138
1139 void WebView::SetTileCoverAreaMultiplier(float multiplier)
1140 {
1141   if(mWebEngine)
1142   {
1143     mWebEngine.SetTileCoverAreaMultiplier(multiplier);
1144   }
1145 }
1146
1147 void WebView::EnableCursorByClient(bool enabled)
1148 {
1149   if(mWebEngine)
1150   {
1151     mWebEngine.EnableCursorByClient(enabled);
1152   }
1153 }
1154
1155 std::string WebView::GetSelectedText() const
1156 {
1157   return mWebEngine ? mWebEngine.GetSelectedText() : std::string();
1158 }
1159
1160 std::string WebView::GetUrl() const
1161 {
1162   return mWebEngine ? mWebEngine.GetUrl() : std::string();
1163 }
1164
1165 std::string WebView::GetUserAgent() const
1166 {
1167   return mWebEngine ? mWebEngine.GetUserAgent() : std::string();
1168 }
1169
1170 void WebView::SetUserAgent(const std::string& userAgent)
1171 {
1172   if(mWebEngine)
1173   {
1174     mWebEngine.SetUserAgent(userAgent);
1175   }
1176 }
1177
1178 void WebView::EnableMouseEvents(bool enabled)
1179 {
1180   if(mWebEngine)
1181   {
1182     mMouseEventsEnabled = enabled;
1183     mWebEngine.EnableMouseEvents(enabled);
1184   }
1185 }
1186
1187 void WebView::EnableKeyEvents(bool enabled)
1188 {
1189   if(mWebEngine)
1190   {
1191     mKeyEventsEnabled = enabled;
1192     mWebEngine.EnableKeyEvents(enabled);
1193   }
1194 }
1195
1196 void WebView::SetPageZoomFactor(float zoomFactor)
1197 {
1198   if(mWebEngine)
1199   {
1200     mWebEngine.SetPageZoomFactor(zoomFactor);
1201   }
1202 }
1203
1204 float WebView::GetPageZoomFactor() const
1205 {
1206   return mWebEngine ? mWebEngine.GetPageZoomFactor() : 0.0f;
1207 }
1208
1209 void WebView::SetTextZoomFactor(float zoomFactor)
1210 {
1211   if(mWebEngine)
1212   {
1213     mWebEngine.SetTextZoomFactor(zoomFactor);
1214   }
1215 }
1216
1217 float WebView::GetTextZoomFactor() const
1218 {
1219   return mWebEngine ? mWebEngine.GetTextZoomFactor() : 0.0f;
1220 }
1221
1222 float WebView::GetLoadProgressPercentage() const
1223 {
1224   return mWebEngine ? mWebEngine.GetLoadProgressPercentage() : 0.0f;
1225 }
1226
1227 bool WebView::SetVisibility(bool visible)
1228 {
1229   return mWebEngine ? mWebEngine.SetVisibility(visible) : false;
1230 }
1231
1232 #undef GET_ENUM_STRING
1233 #undef GET_ENUM_VALUE
1234
1235 } // namespace Internal
1236
1237 } // namespace Toolkit
1238
1239 } // namespace Dali