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;
38 * @brief WebEnginePlugin is an abstract interface, used by dali-adaptor to access WebEngine plugin.
39 * A concrete implementation must be created for each platform and provided as dynamic library.
45 * @brief WebEngine signal type related with page loading.
47 using WebEnginePageLoadSignalType = Signal<void(const std::string&)>;
50 * @brief WebView signal type related with page loading error.
52 using WebEnginePageLoadErrorSignalType = Signal<void(const std::string&, int)>;
54 // forward declaration.
55 enum class ScrollEdge;
58 * @brief WebView signal type related with scroll edge reached.
60 using WebEngineScrollEdgeReachedSignalType = Signal<void(const ScrollEdge)>;
63 * @brief WebView signal type related with page url changed.
65 using WebEngineUrlChangedSignalType = Signal<void(const std::string&)>;
68 * @brief Alert callback when JavaScript alert is called with a message.
69 * It returns true if a pop-up is created successfully, false otherwise.
71 using JavaScriptAlertCallback = std::function<bool(const std::string&)>;
74 * @brief Confirm callback when JavaScript confirm is called with a message.
75 * It returns true if a pop-up is created successfully, false otherwise.
77 using JavaScriptConfirmCallback = std::function<bool(const std::string&)>;
80 * @brief Prompt callback when JavaScript prompt is called with a message
81 * and an optional value that is the default value for the input field.
82 * It returns true if a pop-up is created successfully, false otherwise.
84 using JavaScriptPromptCallback = std::function<bool(const std::string&, const std::string&)>;
87 * @brief Enumeration for the scroll edge.
91 LEFT, ///< Left edge reached.
92 RIGHT, ///< Right edge reached.
93 TOP, ///< Top edge reached.
94 BOTTOM, ///< Bottom edge reached.
100 WebEnginePlugin() = default;
105 virtual ~WebEnginePlugin() = default;
108 * @brief Creates WebEngine instance.
110 * @param [in] width The width of Web
111 * @param [in] height The height of Web
112 * @param [in] locale The locale of Web
113 * @param [in] timezoneId The timezoneID of Web
115 virtual void Create(int width, int height, const std::string& locale, const std::string& timezoneId) = 0;
118 * @brief Creates WebEngine instance.
120 * @param [in] width The width of Web
121 * @param [in] height The height of Web
122 * @param [in] argc The count of application arguments
123 * @param [in] argv The string array of application arguments
125 virtual void Create(int width, int height, int argc, char** argv) = 0;
128 * @brief Destroys WebEngine instance.
130 virtual void Destroy() = 0;
133 * @brief Get settings of WebEngine.
135 virtual WebEngineSettings& GetSettings() const = 0;
138 * @brief Get context of WebEngine.
140 virtual WebEngineContext& GetContext() const = 0;
143 * @brief Get cookie manager of WebEngine.
145 virtual WebEngineCookieManager& GetCookieManager() const = 0;
148 * @brief Get back-forward list of WebEngine.
150 virtual WebEngineBackForwardList& GetBackForwardList() const = 0;
153 * @brief Loads a web page based on a given URL.
155 * @param [in] url The URL of the resource to load
157 virtual void LoadUrl(const std::string& url) = 0;
160 * @brief Returns the title of the Web.
162 * @return The title of web page
164 virtual std::string GetTitle() const = 0;
167 * @brief Returns the Favicon of the Web.
169 * @return Favicon of Dali::PixelData& type
171 virtual Dali::PixelData GetFavicon() const = 0;
174 * @brief Gets image to render.
176 virtual NativeImageInterfacePtr GetNativeImageSource() = 0;
179 * @brief Returns the URL of the Web.
181 * @return Url of string type
183 virtual const std::string& GetUrl() = 0;
186 * @brief Loads a given string as web contents.
188 * @param [in] htmlString The string to use as the contents of the web page
190 virtual void LoadHtmlString(const std::string& htmlString) = 0;
193 * @brief Reloads the Web.
195 virtual void Reload() = 0;
198 * @brief Stops loading web contents on the current page.
200 virtual void StopLoading() = 0;
203 * @brief Suspends the operation associated with the view.
205 virtual void Suspend() = 0;
208 * @brief Resumes the operation associated with the view object after calling Suspend().
210 virtual void Resume() = 0;
213 * @brief Scrolls the webpage of view by deltaX and deltaY.
215 virtual void ScrollBy(int deltaX, int deltaY) = 0;
218 * @brief Scroll to the specified position of the given view.
220 virtual void SetScrollPosition(int x, int y) = 0;
223 * @brief Gets the current scroll position of the given view.
225 virtual Dali::Vector2 GetScrollPosition() const = 0;
228 * @brief Gets the possible scroll size of the given view.
230 virtual Dali::Vector2 GetScrollSize() const = 0;
233 * @brief Gets the last known content's size.
235 virtual Dali::Vector2 GetContentSize() const = 0;
238 * @brief Returns whether forward is possible.
240 * @return True if forward is possible, false otherwise
242 virtual bool CanGoForward() = 0;
245 * @brief Goes to forward.
247 virtual void GoForward() = 0;
250 * @brief Returns whether backward is possible.
252 * @return True if backward is possible, false otherwise
254 virtual bool CanGoBack() = 0;
257 * @brief Goes to back.
259 virtual void GoBack() = 0;
262 * @brief Evaluates JavaScript code represented as a string.
264 * @param[in] script The JavaScript code
265 * @param[in] resultHandler The callback function to be called by the JavaScript runtime. This carries evaluation result.
267 virtual void EvaluateJavaScript(const std::string& script, std::function<void(const std::string&)> resultHandler) = 0;
270 * @brief Add a message handler into JavaScript.
272 * @param[in] exposedObjectName The name of exposed object
273 * @param[in] handler The callback function
275 virtual void AddJavaScriptMessageHandler(const std::string& exposedObjectName, std::function<void(const std::string&)> handler) = 0;
278 * @brief Register a callback for JavaScript alert.
280 * @param[in] callback The callback function
282 virtual void RegisterJavaScriptAlertCallback(JavaScriptAlertCallback callback) = 0;
285 * @brief Reply for JavaScript alert.
287 virtual void JavaScriptAlertReply() = 0;
290 * @brief Register a callback for JavaScript confirm.
292 * @param[in] callback The callback function
294 virtual void RegisterJavaScriptConfirmCallback(JavaScriptConfirmCallback callback) = 0;
297 * @brief Reply for JavaScript confirm.
299 virtual void JavaScriptConfirmReply( bool confirmed ) = 0;
302 * @brief Register a callback for JavaScript prompt.
304 * @param[in] callback The callback function
306 virtual void RegisterJavaScriptPromptCallback( JavaScriptPromptCallback callback ) = 0;
309 * @brief Reply for JavaScript prompt.
311 virtual void JavaScriptPromptReply( const std::string& result ) = 0;
314 * @brief Clears the history of Web.
316 virtual void ClearHistory() = 0;
319 * @brief Clears all tiles resources of Web.
321 virtual void ClearAllTilesResources() = 0;
324 * @brief Get user agent string.
326 * @return The string value of user agent
328 virtual const std::string& GetUserAgent() const = 0;
331 * @brief Set user agent string.
333 * @param[in] userAgent The string value of user agent
335 virtual void SetUserAgent(const std::string& userAgent) = 0;
338 * @brief Sets size of Web Page.
340 virtual void SetSize(int width, int height) = 0;
343 * @brief Sends Touch Events.
345 virtual bool SendTouchEvent(const TouchEvent& touch) = 0;
348 * @brief Sends Key Events.
350 virtual bool SendKeyEvent(const KeyEvent& event) = 0;
355 virtual void SetFocus(bool focused) = 0;
358 * @brief Update display area.
359 * @param[in] displayArea The display area need be updated.
361 virtual void UpdateDisplayArea(Dali::Rect<int> displayArea) = 0;
364 * @brief Enable video hole.
365 * @param[in] enabled True if enabled, false othewise.
367 virtual void EnableVideoHole(bool enabled) = 0;
370 * @brief Connects to this signal to be notified when page loading is started.
372 * @return A signal object to connect with.
374 virtual WebEnginePageLoadSignalType& PageLoadStartedSignal() = 0;
377 * @brief Connects to this signal to be notified when page loading is in progress.
379 * @return A signal object to connect with.
381 virtual WebEnginePageLoadSignalType& PageLoadInProgressSignal() = 0;
384 * @brief Connects to this signal to be notified when page loading is finished.
386 * @return A signal object to connect with.
388 virtual WebEnginePageLoadSignalType& PageLoadFinishedSignal() = 0;
391 * @brief Connects to this signal to be notified when an error occurs in page loading.
393 * @return A signal object to connect with.
395 virtual WebEnginePageLoadErrorSignalType& PageLoadErrorSignal() = 0;
398 * @brief Connects to this signal to be notified when scroll edge is reached.
400 * @return A signal object to connect with.
402 virtual WebEngineScrollEdgeReachedSignalType& ScrollEdgeReachedSignal() = 0;
405 * @brief Connects to this signal to be notified when url is changed.
407 * @return A signal object to connect with.
409 virtual WebEngineUrlChangedSignalType& UrlChangedSignal() = 0;