1 #ifndef DALI_WEB_ENGINE_PLUGIN_H
2 #define DALI_WEB_ENGINE_PLUGIN_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/images/native-image-interface.h>
23 #include <dali/public-api/math/rect.h>
24 #include <dali/public-api/signals/dali-signal.h>
32 class WebEngineBackForwardList;
33 class WebEngineContext;
34 class WebEngineCookieManager;
35 class WebEngineSettings;
40 * @brief WebEnginePlugin is an abstract interface, used by dali-adaptor to access WebEngine plugin.
41 * A concrete implementation must be created for each platform and provided as dynamic library.
47 * @brief WebEngine signal type related with page loading.
49 using WebEnginePageLoadSignalType = Signal<void(const std::string&)>;
52 * @brief WebView signal type related with page loading error.
54 using WebEnginePageLoadErrorSignalType = Signal<void(const std::string&, int)>;
56 // forward declaration.
57 enum class ScrollEdge;
60 * @brief WebView signal type related with scroll edge reached.
62 using WebEngineScrollEdgeReachedSignalType = Signal<void(const ScrollEdge)>;
65 * @brief WebView signal type related with page url changed.
67 using WebEngineUrlChangedSignalType = Signal<void(const std::string&)>;
70 * @brief Alert callback when JavaScript alert is called with a message.
71 * It returns true if a pop-up is created successfully, false otherwise.
73 using JavaScriptAlertCallback = std::function<bool(const std::string&)>;
76 * @brief Confirm callback when JavaScript confirm is called with a message.
77 * It returns true if a pop-up is created successfully, false otherwise.
79 using JavaScriptConfirmCallback = std::function<bool(const std::string&)>;
82 * @brief Prompt callback when JavaScript prompt is called with a message
83 * and an optional value that is the default value for the input field.
84 * It returns true if a pop-up is created successfully, false otherwise.
86 using JavaScriptPromptCallback = std::function<bool(const std::string&, const std::string&)>;
89 * @brief Enumeration for the scroll edge.
93 LEFT, ///< Left edge reached.
94 RIGHT, ///< Right edge reached.
95 TOP, ///< Top edge reached.
96 BOTTOM, ///< Bottom edge reached.
100 * @brief Constructor.
102 WebEnginePlugin() = default;
107 virtual ~WebEnginePlugin() = default;
110 * @brief Creates WebEngine instance.
112 * @param [in] width The width of Web
113 * @param [in] height The height of Web
114 * @param [in] locale The locale of Web
115 * @param [in] timezoneId The timezoneID of Web
117 virtual void Create(int width, int height, const std::string& locale, const std::string& timezoneId) = 0;
120 * @brief Creates WebEngine instance.
122 * @param [in] width The width of Web
123 * @param [in] height The height of Web
124 * @param [in] argc The count of application arguments
125 * @param [in] argv The string array of application arguments
127 virtual void Create(int width, int height, int argc, char** argv) = 0;
130 * @brief Destroys WebEngine instance.
132 virtual void Destroy() = 0;
135 * @brief Get settings of WebEngine.
137 virtual WebEngineSettings& GetSettings() const = 0;
140 * @brief Get context of WebEngine.
142 virtual WebEngineContext& GetContext() const = 0;
145 * @brief Get cookie manager of WebEngine.
147 virtual WebEngineCookieManager& GetCookieManager() const = 0;
150 * @brief Get back-forward list of WebEngine.
152 virtual WebEngineBackForwardList& GetBackForwardList() const = 0;
155 * @brief Loads a web page based on a given URL.
157 * @param [in] url The URL of the resource to load
159 virtual void LoadUrl(const std::string& url) = 0;
162 * @brief Returns the title of the Web.
164 * @return The title of web page
166 virtual std::string GetTitle() const = 0;
169 * @brief Returns the Favicon of the Web.
171 * @return Favicon of Dali::PixelData& type
173 virtual Dali::PixelData GetFavicon() const = 0;
176 * @brief Gets image to render.
178 virtual NativeImageInterfacePtr GetNativeImageSource() = 0;
181 * @brief Returns the URL of the Web.
183 * @return Url of string type
185 virtual const std::string& GetUrl() = 0;
188 * @brief Loads a given string as web contents.
190 * @param [in] htmlString The string to use as the contents of the web page
192 virtual void LoadHtmlString(const std::string& htmlString) = 0;
195 * @brief Reloads the Web.
197 virtual void Reload() = 0;
200 * @brief Stops loading web contents on the current page.
202 virtual void StopLoading() = 0;
205 * @brief Suspends the operation associated with the view.
207 virtual void Suspend() = 0;
210 * @brief Resumes the operation associated with the view object after calling Suspend().
212 virtual void Resume() = 0;
215 * @brief Scrolls the webpage of view by deltaX and deltaY.
217 virtual void ScrollBy(int deltaX, int deltaY) = 0;
220 * @brief Scroll to the specified position of the given view.
222 virtual void SetScrollPosition(int x, int y) = 0;
225 * @brief Gets the current scroll position of the given view.
227 virtual Dali::Vector2 GetScrollPosition() const = 0;
230 * @brief Gets the possible scroll size of the given view.
232 virtual Dali::Vector2 GetScrollSize() const = 0;
235 * @brief Gets the last known content's size.
237 virtual Dali::Vector2 GetContentSize() const = 0;
240 * @brief Returns whether forward is possible.
242 * @return True if forward is possible, false otherwise
244 virtual bool CanGoForward() = 0;
247 * @brief Goes to forward.
249 virtual void GoForward() = 0;
252 * @brief Returns whether backward is possible.
254 * @return True if backward is possible, false otherwise
256 virtual bool CanGoBack() = 0;
259 * @brief Goes to back.
261 virtual void GoBack() = 0;
264 * @brief Evaluates JavaScript code represented as a string.
266 * @param[in] script The JavaScript code
267 * @param[in] resultHandler The callback function to be called by the JavaScript runtime. This carries evaluation result.
269 virtual void EvaluateJavaScript(const std::string& script, std::function<void(const std::string&)> resultHandler) = 0;
272 * @brief Add a message handler into JavaScript.
274 * @param[in] exposedObjectName The name of exposed object
275 * @param[in] handler The callback function
277 virtual void AddJavaScriptMessageHandler(const std::string& exposedObjectName, std::function<void(const std::string&)> handler) = 0;
280 * @brief Register a callback for JavaScript alert.
282 * @param[in] callback The callback function
284 virtual void RegisterJavaScriptAlertCallback(JavaScriptAlertCallback callback) = 0;
287 * @brief Reply for JavaScript alert.
289 virtual void JavaScriptAlertReply() = 0;
292 * @brief Register a callback for JavaScript confirm.
294 * @param[in] callback The callback function
296 virtual void RegisterJavaScriptConfirmCallback(JavaScriptConfirmCallback callback) = 0;
299 * @brief Reply for JavaScript confirm.
301 virtual void JavaScriptConfirmReply( bool confirmed ) = 0;
304 * @brief Register a callback for JavaScript prompt.
306 * @param[in] callback The callback function
308 virtual void RegisterJavaScriptPromptCallback( JavaScriptPromptCallback callback ) = 0;
311 * @brief Reply for JavaScript prompt.
313 virtual void JavaScriptPromptReply( const std::string& result ) = 0;
316 * @brief Clears the history of Web.
318 virtual void ClearHistory() = 0;
321 * @brief Clears all tiles resources of Web.
323 virtual void ClearAllTilesResources() = 0;
326 * @brief Get user agent string.
328 * @return The string value of user agent
330 virtual const std::string& GetUserAgent() const = 0;
333 * @brief Set user agent string.
335 * @param[in] userAgent The string value of user agent
337 virtual void SetUserAgent(const std::string& userAgent) = 0;
340 * @brief Sets size of Web Page.
342 virtual void SetSize(int width, int height) = 0;
345 * @brief Sends Touch Events.
347 virtual bool SendTouchEvent(const TouchEvent& touch) = 0;
350 * @brief Sends Key Events.
352 virtual bool SendKeyEvent(const KeyEvent& event) = 0;
355 * @brief Support mouse events or not.
356 * @param[in] enabled True if enabled, false othewise.
358 virtual void EnableMouseEvents( bool enabled ) = 0;
361 * @brief Support key events or not.
362 * @param[in] enabled True if enabled, false othewise.
364 virtual void EnableKeyEvents( bool enabled ) = 0;
368 * @param[in] focused True if focus is gained, false lost.
370 virtual void SetFocus(bool focused) = 0;
373 * @brief Update display area.
374 * @param[in] displayArea The display area need be updated.
376 virtual void UpdateDisplayArea(Dali::Rect<int> displayArea) = 0;
379 * @brief Enable video hole.
380 * @param[in] enabled True if enabled, false othewise.
382 virtual void EnableVideoHole(bool enabled) = 0;
385 * @brief Sends Hover Events.
386 * @param[in] event The hover event would be sent.
388 virtual bool SendHoverEvent( const HoverEvent& event ) = 0;
391 * @brief Sends Wheel Events.
392 * @param[in] event The wheel event would be sent.
394 virtual bool SendWheelEvent( const WheelEvent& event ) = 0;
397 * @brief Connects to this signal to be notified when page loading is started.
399 * @return A signal object to connect with.
401 virtual WebEnginePageLoadSignalType& PageLoadStartedSignal() = 0;
404 * @brief Connects to this signal to be notified when page loading is in progress.
406 * @return A signal object to connect with.
408 virtual WebEnginePageLoadSignalType& PageLoadInProgressSignal() = 0;
411 * @brief Connects to this signal to be notified when page loading is finished.
413 * @return A signal object to connect with.
415 virtual WebEnginePageLoadSignalType& PageLoadFinishedSignal() = 0;
418 * @brief Connects to this signal to be notified when an error occurs in page loading.
420 * @return A signal object to connect with.
422 virtual WebEnginePageLoadErrorSignalType& PageLoadErrorSignal() = 0;
425 * @brief Connects to this signal to be notified when scroll edge is reached.
427 * @return A signal object to connect with.
429 virtual WebEngineScrollEdgeReachedSignalType& ScrollEdgeReachedSignal() = 0;
432 * @brief Connects to this signal to be notified when url is changed.
434 * @return A signal object to connect with.
436 virtual WebEngineUrlChangedSignalType& UrlChangedSignal() = 0;