1 #ifndef DALI_WEB_ENGINE_H
2 #define DALI_WEB_ENGINE_H
5 * Copyright (c) 2018 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-handle.h>
25 #include <dali/devel-api/adaptor-framework/web-engine-plugin.h>
26 #include <dali/public-api/dali-adaptor-common.h>
37 } // namespace Adaptor
39 } // namespace Internal
42 * @brief Proxy class to dynamically load, use and unload web engine plugin.
44 * The purpose of this class is to dynamically load the web engine plugin if and when its needed.
45 * So we don't slow down every application startup if they never need web engine.
47 class DALI_ADAPTOR_API WebEngine : public BaseHandle
62 * @brief Creates a new instance of a WebEngine.
64 static WebEngine New();
67 * @brief Copy constructor.
69 * @param[in] WebEngine WebEngine to copy. The copied WebEngine will point at the same implementation
71 WebEngine( const WebEngine& WebEngine );
74 * @brief Assignment operator.
76 * @param[in] WebEngine The WebEngine to assign from.
77 * @return The updated WebEngine.
79 WebEngine& operator=( const WebEngine& WebEngine );
82 * @brief Downcast a handle to WebEngine handle.
84 * If handle points to a WebEngine the downcast produces valid
85 * handle. If not the returned handle is left uninitialized.
87 * @param[in] handle Handle to an object
88 * @return Handle to a WebEngine or an uninitialized handle
90 static WebEngine DownCast( BaseHandle handle );
93 * @brief Creates WebEngine instance.
95 * @param [in] width The width of Web
96 * @param [in] height The height of Web
97 * @param [in] locale The locale of Web
98 * @param [in] timezoneId The timezoneID of Web
100 void Create( int width, int height, const std::string& locale, const std::string& timezoneId );
103 * @brief Destroys WebEngine instance.
108 * @brief Gets native image source to render.
110 NativeImageInterfacePtr GetNativeImageSource();
113 * @brief Loads a web page based on a given URL.
115 * @param [in] url The URL of the resource to load
117 void LoadUrl( const std::string& url );
120 * @brief Gets the url.
122 const std::string& GetUrl();
125 * @brief Loads a given string as web contents.
127 * @param [in] htmlString The string to use as the contents of the web page
129 void LoadHTMLString( const std::string& htmlString );
132 * @brief Reloads the Web.
137 * @brief Stops loading web contents on the current page.
142 * @brief Suspends the operation associated with the view.
147 * @brief Resumes the operation associated with the view object after calling Suspend().
152 * @brief Returns whether forward is possible.
154 * @return True if forward is possible, false otherwise
159 * @brief Goes to forward.
164 * @brief Returns whether backward is possible.
166 * @return True if backward is possible, false otherwise
171 * @brief Goes to back.
176 * @brief Evaluates JavaScript code represented as a string.
178 * @param[in] script The JavaScript code
179 * @param[in] resultHandler The callback function to be called by the JavaScript runtime. This carries evaluation result.
181 void EvaluateJavaScript( const std::string& script, std::function< void( const std::string& ) > resultHandler );
184 * @brief Add a message handler into JavaScript.
186 * @param[in] exposedObjectName The name of exposed object
187 * @param[in] handler The callback function
189 void AddJavaScriptMessageHandler( const std::string& exposedObjectName, std::function< void( const std::string& ) > handler );
192 * @brief Clears the history of Web.
197 * @brief Clears the cache of Web.
202 * @brief Clears all the cookies of Web.
207 * @brief Get cache model option. The default is DOCUMENT_VIEWER.
209 * @return The cache model option
211 Dali::WebEnginePlugin::CacheModel GetCacheModel() const;
214 * @brief Set cache model option. The default is DOCUMENT_VIEWER.
216 * @param[in] cacheModel The cache model option
218 void SetCacheModel( Dali::WebEnginePlugin::CacheModel cacheModel );
221 * @brief Gets the cookie acceptance policy. The default is NO_THIRD_PARTY.
223 * @return The cookie acceptance policy
225 Dali::WebEnginePlugin::CookieAcceptPolicy GetCookieAcceptPolicy() const;
228 * @brief Sets the cookie acceptance policy. The default is NO_THIRD_PARTY.
230 * @param[in] policy The cookie acceptance policy
232 void SetCookieAcceptPolicy( Dali::WebEnginePlugin::CookieAcceptPolicy policy );
235 * @brief Get user agent string.
237 * @return The string value of user agent
239 const std::string& GetUserAgent() const;
242 * @brief Set user agent string.
244 * @param[in] userAgent The string value of user agent
246 void SetUserAgent( const std::string& userAgent );
249 * @brief Returns whether JavaScript can be executable. The default is true.
251 * @return true if JavaScript executing is enabled, false otherwise
253 bool IsJavaScriptEnabled() const;
256 * @brief Enables/disables JavaScript executing. The default is enabled.
258 * @param[in] enabled True if JavaScript executing is enabled, false otherwise
260 void EnableJavaScript( bool enabled );
263 * @brief Returns whether JavaScript can be executable. The default is true.
265 * @return true if images are loaded automatically, false otherwise
267 bool AreImagesAutomaticallyLoaded() const;
270 * @brief Enables/disables auto loading of images. The default is enabled.
272 * @param[in] automatic True if images are loaded automatically, false otherwise
274 void LoadImagesAutomatically( bool automatic );
277 * @brief Gets the default text encoding name.
279 * @return The default text encoding name
281 const std::string& GetDefaultTextEncodingName() const;
284 * @brief Sets the default text encoding name.
286 * @param[in] defaultTextEncodingName The default text encoding name
288 void SetDefaultTextEncodingName( const std::string& defaultTextEncodingName );
291 * @brief Returns the default font size in pixel. The default value is 16.
293 * @return The default font size
295 int GetDefaultFontSize() const;
298 * @brief Sets the default font size in pixel. The default value is 16.
300 * @param[in] defaultFontSize A new default font size to set
302 void SetDefaultFontSize( int defaultFontSize );
305 * @brief Sets the size of Web Pages.
307 void SetSize( int width, int height );
310 * @brief Sends Touch Events.
312 bool SendTouchEvent( const TouchData& touch );
315 * @brief Sends key Events.
317 bool SendKeyEvent( const KeyEvent& event );
320 * @brief Connects to this signal to be notified when page loading is started.
322 * @return A signal object to connect with.
324 Dali::WebEnginePlugin::WebEnginePageLoadSignalType& PageLoadStartedSignal();
327 * @brief Connects to this signal to be notified when page loading is finished.
329 * @return A signal object to connect with.
331 Dali::WebEnginePlugin::WebEnginePageLoadSignalType& PageLoadFinishedSignal();
334 * @brief Connects to this signal to be notified when an error occurs in page loading.
336 * @return A signal object to connect with.
338 Dali::WebEnginePlugin::WebEnginePageLoadErrorSignalType& PageLoadErrorSignal();
340 private: // Not intended for application developers
343 * @brief Internal constructor
345 explicit DALI_INTERNAL WebEngine( Internal::Adaptor::WebEngine* internal );
350 #endif // DALI_WEB_ENGINE_H