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