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