1 #ifndef DALI_WEB_ENGINE_IMPL_H
2 #define DALI_WEB_ENGINE_IMPL_H
5 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/public-api/object/base-object.h>
25 #include <dali/devel-api/adaptor-framework/web-engine-plugin.h>
26 #include <dali/devel-api/adaptor-framework/web-engine.h>
30 // forward declaration
31 class WebEngineBackForwardList;
32 class WebEngineContext;
33 class WebEngineCookieManager;
34 class WebEngineSettings;
42 typedef IntrusivePtr<WebEngine> WebEnginePtr;
45 * @brief WebEngine class is used for Web.
47 class WebEngine : public Dali::BaseObject
51 * @brief Creates a new WebEngine handle
53 * @return WebEngine pointer
55 static WebEnginePtr New();
58 * @copydoc Dali::WebEngine::Create()
60 void Create(int width, int height, const std::string& locale, const std::string& timezoneId);
63 * @copydoc Dali::WebEngine::Create()
65 void Create(int width, int height, int argc, char** argv);
68 * @copydoc Dali::WebEngine::Destroy()
73 * @copydoc Dali::WebEngine::GetNativeImageSource()
75 Dali::NativeImageInterfacePtr GetNativeImageSource();
78 * @copydoc Dali::WebEngine::GetSettings()
80 Dali::WebEngineSettings& GetSettings() const;
83 * @copydoc Dali::WebEngine::GetContext()
85 Dali::WebEngineContext& GetContext() const;
88 * @copydoc Dali::WebEngine::GetCookieManager()
90 Dali::WebEngineCookieManager& GetCookieManager() const;
93 * @copydoc Dali::WebEngine::GetBackForwardList()
95 Dali::WebEngineBackForwardList& GetBackForwardList() const;
98 * @copydoc Dali::WebEngine::LoadUrl()
100 void LoadUrl(const std::string& url);
103 * @copydoc Dali::WebEngine::GetTitle()
105 std::string GetTitle() const;
108 * @copydoc Dali::WebEngine::GetFavicon()
110 Dali::PixelData GetFavicon() const;
113 * @copydoc Dali::WebEngine::GetUrl()
115 const std::string& GetUrl();
118 * @copydoc Dali::WebEngine::GetUserAgent()
120 const std::string& GetUserAgent() const;
123 * @copydoc Dali::WebEngine::SetUserAgent()
125 void SetUserAgent(const std::string& userAgent);
128 * @copydoc Dali::WebEngine::LoadHtmlString()
130 void LoadHtmlString(const std::string& htmlString);
133 * @copydoc Dali::WebEngine::LoadHtmlStringOverrideCurrentEntry()
135 bool LoadHtmlStringOverrideCurrentEntry(const std::string& html, const std::string& basicUri, const std::string& unreachableUrl);
138 * @copydoc Dali::WebEngine::LoadContents()
140 bool LoadContents(const std::string& contents, uint32_t contentSize, const std::string& mimeType, const std::string& encoding, const std::string& baseUri);
143 * @copydoc Dali::WebEngine::Reload()
148 * @copydoc Dali::WebEngine::ReloadWithoutCache()
150 bool ReloadWithoutCache();
153 * @copydoc Dali::WebEngine::StopLoading()
158 * @copydoc Dali::WebEngine::Suspend()
163 * @copydoc Dali::WebEngine::Resume()
168 * @copydoc Dali::WebEngine::SuspendNetworkLoading()
170 void SuspendNetworkLoading();
173 * @copydoc Dali::WebEngine::ResumeNetworkLoading()
175 void ResumeNetworkLoading();
178 * @copydoc Dali::WebEngine::AddCustomHeader()
180 bool AddCustomHeader(const std::string& name, const std::string& value);
183 * @copydoc Dali::WebEngine::RemoveCustomHeader()
185 bool RemoveCustomHeader(const std::string& name);
188 * @copydoc Dali::WebEngine::StartInspectorServer()
190 uint32_t StartInspectorServer(uint32_t port);
193 * @copydoc Dali::WebEngine::StopInspectorServer()
195 bool StopInspectorServer();
198 * @copydoc Dali::WebEngine::ScrollBy()
200 void ScrollBy(int deltaX, int deltaY);
203 * @copydoc Dali::WebEngine::ScrollEdgeBy()
205 bool ScrollEdgeBy(int deltaX, int deltaY);
208 * @copydoc Dali::WebEngine::SetScrollPosition()
210 void SetScrollPosition(int x, int y);
213 * @copydoc Dali::WebEngine::GetScrollPosition()
215 Dali::Vector2 GetScrollPosition() const;
218 * @copydoc Dali::WebEngine::GetScrollSize()
220 Dali::Vector2 GetScrollSize() const;
223 * @copydoc Dali::WebEngine::GetContentSize()
225 Dali::Vector2 GetContentSize() const;
228 * @copydoc Dali::WebEngine::RegisterJavaScriptAlertCallback()
230 void RegisterJavaScriptAlertCallback(Dali::WebEnginePlugin::JavaScriptAlertCallback callback);
233 * @copydoc Dali::WebEngine::JavaScriptAlertReply()
235 void JavaScriptAlertReply();
238 * @copydoc Dali::WebEngine::RegisterJavaScriptConfirmCallback()
240 void RegisterJavaScriptConfirmCallback(Dali::WebEnginePlugin::JavaScriptConfirmCallback callback);
243 * @copydoc Dali::WebEngine::JavaScriptConfirmReply()
245 void JavaScriptConfirmReply(bool confirmed);
248 * @copydoc Dali::WebEngine::RegisterJavaScriptPromptCallback()
250 void RegisterJavaScriptPromptCallback(Dali::WebEnginePlugin::JavaScriptPromptCallback callback);
253 * @copydoc Dali::WebEngine::JavaScriptPromptReply()
255 void JavaScriptPromptReply(const std::string& result);
258 * @copydoc Dali::WebEngine::CanGoForward()
263 * @copydoc Dali::WebEngine::GoForward()
268 * @copydoc Dali::WebEngine::CanGoBack()
273 * @copydoc Dali::WebEngine::GoBack()
278 * @copydoc Dali::WebEngine::EvaluateJavaScript()
280 void EvaluateJavaScript(const std::string& script, std::function<void(const std::string&)> resultHandler);
283 * @copydoc Dali::WebEngine::AddJavaScriptMessageHandler()
285 void AddJavaScriptMessageHandler(const std::string& exposedObjectName, std::function<void(const std::string&)> handler);
288 * @copydoc Dali::WebEngine::ClearAllTilesResources()
290 void ClearAllTilesResources();
293 * @copydoc Dali::WebEngine::ClearHistory()
298 * @copydoc Dali::WebEngine::SetSize()
300 void SetSize(int width, int height);
303 * @copydoc Dali::WebEngine::EnableMouseEvents()
305 void EnableMouseEvents(bool enabled);
308 * @copydoc Dali::WebEngine::EnableKeyEvents()
310 void EnableKeyEvents(bool enabled);
313 * @copydoc Dali::WebEngine::SetDocumentBackgroundColor()
315 void SetDocumentBackgroundColor(Dali::Vector4 color);
318 * @copydoc Dali::WebEngine::ClearTilesWhenHidden()
320 void ClearTilesWhenHidden(bool cleared);
323 * @copydoc Dali::WebEngine::SetTileCoverAreaMultiplier()
325 void SetTileCoverAreaMultiplier(float multiplier);
328 * @copydoc Dali::WebEngine::EnableCursorByClient()
330 void EnableCursorByClient(bool enabled);
333 * @copydoc Dali::WebEngine::GetSelectedText()
335 std::string GetSelectedText() const;
338 * @copydoc Dali::WebEngine::SendTouchEvent()
340 bool SendTouchEvent(const Dali::TouchEvent& touch);
343 * @copydoc Dali::WebEngine::SendKeyEvent()
345 bool SendKeyEvent(const Dali::KeyEvent& event);
348 * @copydoc Dali::WebEngine::SetFocus()
350 void SetFocus(bool focused);
353 * @copydoc Dali::WebEngine::SetPageZoomFactor()
355 void SetPageZoomFactor(float zoomFactor);
358 * @copydoc Dali::WebEngine::GetPageZoomFactor()
360 float GetPageZoomFactor() const;
363 * @copydoc Dali::WebEngine::SetTextZoomFactor()
365 void SetTextZoomFactor(float zoomFactor);
368 * @copydoc Dali::WebEngine::GetTextZoomFactor()
370 float GetTextZoomFactor() const;
373 * @copydoc Dali::WebEngine::GetLoadProgressPercentage()
375 float GetLoadProgressPercentage() const;
378 * @copydoc Dali::WebEngine::SetScaleFactor()
380 void SetScaleFactor(float scaleFactor, Dali::Vector2 point);
383 * @copydoc Dali::WebEngine::GetScaleFactor()
385 float GetScaleFactor() const;
388 * @copydoc Dali::WebEngine::ActivateAccessibility()
390 void ActivateAccessibility(bool activated);
393 * @copydoc Dali::WebEngine::SetVisibility()
395 bool SetVisibility(bool visible);
398 * @copydoc Dali::WebEngine::HighlightText()
400 bool HighlightText(const std::string& text, Dali::WebEnginePlugin::FindOption options, uint32_t maxMatchCount);
403 * @copydoc Dali::WebEngine::AddDynamicCertificatePath()
405 void AddDynamicCertificatePath(const std::string& host, const std::string& certPath);
408 * @copydoc Dali::WebEngine::GetScreenshot()
410 Dali::PixelData GetScreenshot(Dali::Rect<int> viewArea, float scaleFactor);
413 * @copydoc Dali::WebEngine::GetScreenshotAsync()
415 bool GetScreenshotAsynchronously(Dali::Rect<int> viewArea, float scaleFactor, Dali::WebEnginePlugin::ScreenshotCapturedCallback callback);
418 * @copydoc Dali::WebEngine::IsVideoPlaying()
420 bool CheckVideoPlayingAsynchronously(Dali::WebEnginePlugin::VideoPlayingCallback callback);
423 * @copydoc Dali::WebEngine::RegisterGeolocationPermissionCallback()
425 void RegisterGeolocationPermissionCallback(Dali::WebEnginePlugin::GeolocationPermissionCallback callback);
428 * @copydoc Dali::WebEngine::UpdateDisplayArea()
430 void UpdateDisplayArea(Dali::Rect<int> displayArea);
433 * @copydoc Dali::WebEngine::EnableVideoHole()
435 void EnableVideoHole(bool enabled);
438 * @copydoc Dali::WebEngine::SendHoverEvent()
440 bool SendHoverEvent(const Dali::HoverEvent& event);
443 * @copydoc Dali::WebEngine::SendWheelEvent()
445 bool SendWheelEvent(const Dali::WheelEvent& event);
448 * @copydoc Dali::WebEngine::PageLoadStartedSignal()
450 Dali::WebEnginePlugin::WebEnginePageLoadSignalType& PageLoadStartedSignal();
453 * @copydoc Dali::WebEngine::PageLoadProgressSignal()
455 Dali::WebEnginePlugin::WebEnginePageLoadSignalType& PageLoadInProgressSignal();
458 * @copydoc Dali::WebEngine::PageLoadFinishedSignal()
460 Dali::WebEnginePlugin::WebEnginePageLoadSignalType& PageLoadFinishedSignal();
463 * @copydoc Dali::WebEngine::PageLoadErrorSignal()
465 Dali::WebEnginePlugin::WebEnginePageLoadErrorSignalType& PageLoadErrorSignal();
468 * @copydoc Dali::WebEngine::ScrollEdgeReachedSignal()
470 Dali::WebEnginePlugin::WebEngineScrollEdgeReachedSignalType& ScrollEdgeReachedSignal();
473 * @copydoc Dali::WebEngine::UrlChangedSignal()
475 Dali::WebEnginePlugin::WebEngineUrlChangedSignalType& UrlChangedSignal();
478 * @copydoc Dali::WebEngine::FormRepostDecisionSignal()
480 Dali::WebEnginePlugin::WebEngineFormRepostDecisionSignalType& FormRepostDecisionSignal();
483 * @copydoc Dali::WebEngine::FrameRenderedSignal()
485 Dali::WebEnginePlugin::WebEngineFrameRenderedSignalType& FrameRenderedSignal();
489 * @brief Constructor.
496 virtual ~WebEngine();
498 // Undefined copy constructor
499 WebEngine(const WebEngine& WebEngine);
501 // Undefined assignment operator
502 WebEngine& operator=(const WebEngine& WebEngine);
505 * @brief Initializes member data.
507 * @return Whether the initialization succeed or not.
512 * @brief Initializes library handle by loading web engine plugin.
514 * @return Whether the initialization succeed or not.
516 bool InitializePluginHandle();
519 typedef Dali::WebEnginePlugin* (*CreateWebEngineFunction)();
520 typedef void (*DestroyWebEngineFunction)(Dali::WebEnginePlugin* plugin);
522 Dali::WebEnginePlugin* mPlugin; ///< WebEnginePlugin instance
523 void* mHandle; ///< Handle for the loaded library
524 CreateWebEngineFunction mCreateWebEnginePtr; ///< Function to create plugin instance
525 DestroyWebEngineFunction mDestroyWebEnginePtr; ///< Function to destroy plugin instance
528 } // namespace Adaptor
529 } // namespace Internal
531 inline static Internal::Adaptor::WebEngine& GetImplementation(Dali::WebEngine& webEngine)
533 DALI_ASSERT_ALWAYS(webEngine && "WebEngine handle is empty.");
535 BaseObject& handle = webEngine.GetBaseObject();
537 return static_cast<Internal::Adaptor::WebEngine&>(handle);
540 inline static const Internal::Adaptor::WebEngine& GetImplementation(const Dali::WebEngine& webEngine)
542 DALI_ASSERT_ALWAYS(webEngine && "WebEngine handle is empty.");
544 const BaseObject& handle = webEngine.GetBaseObject();
546 return static_cast<const Internal::Adaptor::WebEngine&>(handle);