1 #ifndef DALI_WEB_ENGINE_PLUGIN_H
2 #define DALI_WEB_ENGINE_PLUGIN_H
5 * Copyright (c) 2022 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/images/native-image-interface.h>
23 #include <dali/public-api/math/rect.h>
24 #include <dali/public-api/signals/dali-signal.h>
34 class WebEngineBackForwardList;
35 class WebEngineContext;
36 class WebEngineCookieManager;
37 class WebEnginePolicyDecision;
38 class WebEngineSettings;
41 * @brief WebEnginePlugin is an abstract interface, used by dali-adaptor to access WebEngine plugin.
42 * A concrete implementation must be created for each platform and provided as dynamic library.
48 * @brief WebEngine callback related with page loading.
50 using WebEnginePageLoadCallback = std::function<void(const std::string&)>;
53 * @brief WebView callback related with page loading error.
55 using WebEnginePageLoadErrorCallback = std::function<void(const std::string&, int)>;
57 // forward declaration.
58 enum class ScrollEdge;
61 * @brief WebView callback related with scroll edge reached.
63 using WebEngineScrollEdgeReachedCallback = std::function<void(const ScrollEdge)>;
66 * @brief The callback to be called when the web engine received a plain text of current web page.
68 using PlainTextReceivedCallback = std::function<void(const std::string&)>;
71 * @brief Message result callback when JavaScript is executed with a message.
73 using JavaScriptMessageHandlerCallback = std::function<void(const std::string&)>;
76 * @brief WebView callback related with navigation policy would be decided.
78 using WebEngineNavigationPolicyDecidedCallback = std::function<void(std::unique_ptr<Dali::WebEnginePolicyDecision>)>;
81 * @brief Enumeration for the scroll edge.
85 LEFT, ///< Left edge reached.
86 RIGHT, ///< Right edge reached.
87 TOP, ///< Top edge reached.
88 BOTTOM, ///< Bottom edge reached.
94 WebEnginePlugin() = default;
99 virtual ~WebEnginePlugin() = default;
102 * @brief Creates WebEngine instance.
104 * @param [in] width The width of Web
105 * @param [in] height The height of Web
106 * @param [in] locale The locale of Web
107 * @param [in] timezoneId The timezoneID of Web
109 virtual void Create(int width, int height, const std::string& locale, const std::string& timezoneId) = 0;
112 * @brief Creates WebEngine instance.
114 * @param [in] width The width of Web
115 * @param [in] height The height of Web
116 * @param [in] argc The count of application arguments
117 * @param [in] argv The string array of application arguments
119 virtual void Create(int width, int height, int argc, char** argv) = 0;
122 * @brief Destroys WebEngine instance.
124 virtual void Destroy() = 0;
127 * @brief Get settings of WebEngine.
129 virtual WebEngineSettings& GetSettings() const = 0;
132 * @brief Get context of WebEngine.
134 virtual WebEngineContext& GetContext() const = 0;
137 * @brief Get cookie manager of WebEngine.
139 virtual WebEngineCookieManager& GetCookieManager() const = 0;
142 * @brief Get back-forward list of WebEngine.
144 virtual WebEngineBackForwardList& GetBackForwardList() const = 0;
147 * @brief Loads a web page based on a given URL.
149 * @param [in] url The URL of the resource to load
151 virtual void LoadUrl(const std::string& url) = 0;
154 * @brief Returns the title of the Web.
156 * @return The title of web page
158 virtual std::string GetTitle() const = 0;
161 * @brief Returns the Favicon of the Web.
163 * @return Favicon of Dali::PixelData& type
165 virtual Dali::PixelData GetFavicon() const = 0;
168 * @brief Gets image to render.
170 virtual NativeImageInterfacePtr GetNativeImageSource() = 0;
173 * @brief Returns the URL of the Web.
175 * @return Url of string type
177 virtual const std::string& GetUrl() = 0;
180 * @brief Loads a given string as web contents.
182 * @param [in] htmlString The string to use as the contents of the web page
184 virtual void LoadHtmlString(const std::string& htmlString) = 0;
187 * @brief Reloads the Web.
189 virtual void Reload() = 0;
192 * @brief Stops loading web contents on the current page.
194 virtual void StopLoading() = 0;
197 * @brief Suspends the operation associated with the view.
199 virtual void Suspend() = 0;
202 * @brief Resumes the operation associated with the view object after calling Suspend().
204 virtual void Resume() = 0;
207 * @brief Scrolls the webpage of view by deltaX and deltaY.
209 virtual void ScrollBy(int deltaX, int deltaY) = 0;
212 * @brief Scroll to the specified position of the given view.
214 virtual void SetScrollPosition(int x, int y) = 0;
217 * @brief Gets the current scroll position of the given view.
219 virtual void GetScrollPosition(int& x, int& y) const = 0;
222 * @brief Gets the possible scroll size of the given view.
224 virtual void GetScrollSize(int& width, int& height) const = 0;
227 * @brief Gets the last known content's size.
229 virtual void GetContentSize(int& width, int& height) const = 0;
232 * @brief Returns whether forward is possible.
234 * @return True if forward is possible, false otherwise
236 virtual bool CanGoForward() = 0;
239 * @brief Goes to forward.
241 virtual void GoForward() = 0;
244 * @brief Returns whether backward is possible.
246 * @return True if backward is possible, false otherwise
248 virtual bool CanGoBack() = 0;
251 * @brief Goes to back.
253 virtual void GoBack() = 0;
256 * @brief Evaluates JavaScript code represented as a string.
258 * @param[in] script The JavaScript code
259 * @param[in] resultHandler The callback function to be called by the JavaScript runtime. This carries evaluation result.
261 virtual void EvaluateJavaScript(const std::string& script, JavaScriptMessageHandlerCallback resultHandler) = 0;
264 * @brief Add a message handler into JavaScript.
266 * @param[in] exposedObjectName The name of exposed object
267 * @param[in] handler The callback function
269 virtual void AddJavaScriptMessageHandler(const std::string& exposedObjectName, JavaScriptMessageHandlerCallback handler) = 0;
272 * @brief Clears all tiles resources of Web.
274 virtual void ClearAllTilesResources() = 0;
277 * @brief Clears the history of Web.
279 virtual void ClearHistory() = 0;
282 * @brief Get user agent string.
284 * @return The string value of user agent
286 virtual const std::string& GetUserAgent() const = 0;
289 * @brief Set user agent string.
291 * @param[in] userAgent The string value of user agent
293 virtual void SetUserAgent(const std::string& userAgent) = 0;
296 * @brief Sets size of Web Page.
298 virtual void SetSize(int width, int height) = 0;
301 * @brief Sends Touch Events.
303 virtual bool SendTouchEvent(const TouchEvent& touch) = 0;
306 * @brief Sends Key Events.
308 virtual bool SendKeyEvent(const KeyEvent& event) = 0;
313 virtual void SetFocus(bool focused) = 0;
316 * @brief Update display area.
317 * @param[in] displayArea The display area need be updated.
319 virtual void UpdateDisplayArea(Dali::Rect<int> displayArea) = 0;
322 * @brief Enable video hole.
323 * @param[in] enabled True if enabled, false othewise.
325 virtual void EnableVideoHole(bool enabled) = 0;
328 * @brief Callback to be called when page loading is started.
330 * @param[in] callback
332 virtual void RegisterPageLoadStartedCallback(WebEnginePageLoadCallback callback) = 0;
335 * @brief Callback to be called when page loading is finished.
337 * @param[in] callback
339 virtual void RegisterPageLoadFinishedCallback(WebEnginePageLoadCallback callback) = 0;
342 * @brief Callback to be called when an error occurs in page loading.
344 * @param[in] callback
346 virtual void RegisterPageLoadErrorCallback(WebEnginePageLoadErrorCallback callback) = 0;
349 * @brief Callback to be called when scroll edge is reached.
351 * @param[in] callback
353 virtual void RegisterScrollEdgeReachedCallback(WebEngineScrollEdgeReachedCallback callback) = 0;
356 * @brief Callback to be called when navigation policy would be decided.
358 * @param[in] callback
360 virtual void RegisterNavigationPolicyDecidedCallback(WebEngineNavigationPolicyDecidedCallback callback) = 0;
363 * @brief Get a plain text of current web page asynchronously.
365 * @param[in] callback The callback function called asynchronously.
367 virtual void GetPlainTextAsynchronously(PlainTextReceivedCallback callback) = 0;