1 #ifndef DALI_WEB_ENGINE_PLUGIN_H
2 #define DALI_WEB_ENGINE_PLUGIN_H
5 * Copyright (c) 2020 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/signals/dali-signal.h>
32 * @brief WebEnginePlugin is an abstract interface, used by dali-adaptor to access WebEngine plugin.
33 * A concrete implementation must be created for each platform and provided as dynamic library.
39 * @brief WebEngine signal type related with page loading.
41 typedef Signal<void(const std::string&)> WebEnginePageLoadSignalType;
44 * @brief WebView signal type related with page loading error.
46 typedef Signal<void(const std::string&, int)> WebEnginePageLoadErrorSignalType;
48 // forward declaration.
49 enum class ScrollEdge;
52 * @brief WebView signal type related with scroll edge reached.
54 typedef Signal< void( const ScrollEdge )> WebEngineScrollEdgeReachedSignalType;
57 * @brief Enumeration for cache model options.
62 * @brief Use the smallest cache capacity.
67 * @brief Use the bigger cache capacity than DocumentBrowser.
72 * @brief Use the biggest cache capacity.
78 * @brief Enumeration for the cookies accept policies.
80 enum class CookieAcceptPolicy
83 * @brief Accepts every cookie sent from any page.
88 * @brief Rejects all the cookies.
93 * @brief Accepts only cookies set by the main document that is loaded.
99 * @brief Enumeration for the scroll edge.
101 enum class ScrollEdge
103 LEFT, ///< Left edge reached.
104 RIGHT, ///< Right edge reached.
105 TOP, ///< Top edge reached.
106 BOTTOM, ///< Bottom edge reached.
110 * @brief Constructor.
112 WebEnginePlugin() = default;
117 virtual ~WebEnginePlugin() = default;
120 * @brief Creates WebEngine instance.
122 * @param [in] width The width of Web
123 * @param [in] height The height of Web
124 * @param [in] locale The locale of Web
125 * @param [in] timezoneId The timezoneID of Web
127 virtual void Create(int width, int height, const std::string& locale, const std::string& timezoneId) = 0;
130 * @brief Destroys WebEngine instance.
132 virtual void Destroy() = 0;
135 * @brief Loads a web page based on a given URL.
137 * @param [in] url The URL of the resource to load
139 virtual void LoadUrl(const std::string& url) = 0;
142 * @brief Gets image to render.
144 virtual NativeImageInterfacePtr GetNativeImageSource() = 0;
147 * @brief Returns the URL of the Web.
149 * @return Url of string type
151 virtual const std::string& GetUrl() = 0;
154 * @brief Loads a given string as web contents.
156 * @param [in] htmlString The string to use as the contents of the web page
158 virtual void LoadHTMLString(const std::string& htmlString) = 0;
161 * @brief Reloads the Web.
163 virtual void Reload() = 0;
166 * @brief Stops loading web contents on the current page.
168 virtual void StopLoading() = 0;
171 * @brief Suspends the operation associated with the view.
173 virtual void Suspend() = 0;
176 * @brief Resumes the operation associated with the view object after calling Suspend().
178 virtual void Resume() = 0;
181 * @brief Scrolls the webpage of view by deltaX and deltaY.
183 virtual void ScrollBy( int deltaX, int deltaY ) = 0;
186 * @brief Scroll to the specified position of the given view.
188 virtual void SetScrollPosition( int x, int y ) = 0;
191 * @brief Gets the current scroll position of the given view.
193 virtual void GetScrollPosition( int& x, int& y ) const = 0;
196 * @brief Gets the possible scroll size of the given view.
198 virtual void GetScrollSize( int& width, int& height ) const = 0;
201 * @brief Gets the last known content's size.
203 virtual void GetContentSize( int& width, int& height ) const = 0;
206 * @brief Returns whether forward is possible.
208 * @return True if forward is possible, false otherwise
210 virtual bool CanGoForward() = 0;
213 * @brief Goes to forward.
215 virtual void GoForward() = 0;
218 * @brief Returns whether backward is possible.
220 * @return True if backward is possible, false otherwise
222 virtual bool CanGoBack() = 0;
225 * @brief Goes to back.
227 virtual void GoBack() = 0;
230 * @brief Evaluates JavaScript code represented as a string.
232 * @param[in] script The JavaScript code
233 * @param[in] resultHandler The callback function to be called by the JavaScript runtime. This carries evaluation result.
235 virtual void EvaluateJavaScript(const std::string& script, std::function<void(const std::string&)> resultHandler) = 0;
238 * @brief Add a message handler into JavaScript.
240 * @param[in] exposedObjectName The name of exposed object
241 * @param[in] handler The callback function
243 virtual void AddJavaScriptMessageHandler(const std::string& exposedObjectName, std::function<void(const std::string&)> handler) = 0;
246 * @brief Clears the history of Web.
248 virtual void ClearHistory() = 0;
251 * @brief Clears the cache of Web.
253 virtual void ClearCache() = 0;
256 * @brief Clears all the cookies of Web.
258 virtual void ClearCookies() = 0;
261 * @brief Get cache model option. The default is DOCUMENT_VIEWER.
263 * @return The cache model option
265 virtual CacheModel GetCacheModel() const = 0;
268 * @brief Set cache model option. The default is DOCUMENT_VIEWER.
270 * @param[in] cacheModel The cache model option
272 virtual void SetCacheModel(CacheModel cacheModel) = 0;
275 * @brief Gets the cookie acceptance policy. The default is NO_THIRD_PARTY.
277 * @return The cookie acceptance policy
279 virtual CookieAcceptPolicy GetCookieAcceptPolicy() const = 0;
282 * @brief Sets the cookie acceptance policy. The default is NO_THIRD_PARTY.
284 * @param[in] policy The cookie acceptance policy
286 virtual void SetCookieAcceptPolicy(CookieAcceptPolicy policy) = 0;
289 * @brief Get user agent string.
291 * @return The string value of user agent
293 virtual const std::string& GetUserAgent() const = 0;
296 * @brief Set user agent string.
298 * @param[in] userAgent The string value of user agent
300 virtual void SetUserAgent(const std::string& userAgent) = 0;
303 * @brief Returns whether JavaScript can be executable. The default is true.
305 * @return true if JavaScript executing is enabled, false otherwise
307 virtual bool IsJavaScriptEnabled() const = 0;
310 * @brief Enables/disables JavaScript executing. The default is enabled.
312 * @param[in] enabled True if JavaScript executing is enabled, false otherwise
314 virtual void EnableJavaScript(bool enabled) = 0;
317 * @brief Returns whether images can be loaded automatically. The default is true.
319 * @return true if images are loaded automatically, false otherwise
321 virtual bool AreImagesAutomaticallyLoaded() const = 0;
324 * @brief Enables/disables auto loading of images. The default is enabled.
326 * @param[in] automatic True if images are loaded automatically, false otherwise
328 virtual void LoadImagesAutomatically(bool automatic) = 0;
331 * @brief Gets the default text encoding name (e.g. UTF-8).
333 * @return The default text encoding name
335 virtual const std::string& GetDefaultTextEncodingName() const = 0;
338 * @brief Sets the default text encoding name (e.g. UTF-8).
340 * @param[in] defaultTextEncodingName The default text encoding name
342 virtual void SetDefaultTextEncodingName(const std::string& defaultTextEncodingName) = 0;
345 * @brief Returns the default font size in pixel. The default value is 16.
347 * @return The default font size
349 virtual int GetDefaultFontSize() const = 0;
352 * @brief Sets the default font size in pixel. The default value is 16.
354 * @param[in] defaultFontSize A new default font size to set
356 virtual void SetDefaultFontSize(int defaultFontSize) = 0;
359 * @brief Sets size of Web Page.
361 virtual void SetSize(int width, int height) = 0;
364 * @brief Sends Touch Events.
366 virtual bool SendTouchEvent(const TouchEvent& touch) = 0;
369 * @brief Sends Key Events.
371 virtual bool SendKeyEvent(const KeyEvent& event) = 0;
376 virtual void SetFocus( bool focused ) = 0;
379 * @brief Connects to this signal to be notified when page loading is started.
381 * @return A signal object to connect with.
383 virtual WebEnginePageLoadSignalType& PageLoadStartedSignal() = 0;
386 * @brief Connects to this signal to be notified when page loading is finished.
388 * @return A signal object to connect with.
390 virtual WebEnginePageLoadSignalType& PageLoadFinishedSignal() = 0;
393 * @brief Connects to this signal to be notified when an error occurs in page loading.
395 * @return A signal object to connect with.
397 virtual WebEnginePageLoadErrorSignalType& PageLoadErrorSignal() = 0;
400 * @brief Connects to this signal to be notified when scroll edge is reached.
402 * @return A signal object to connect with.
404 virtual WebEngineScrollEdgeReachedSignalType& ScrollEdgeReachedSignal() = 0;