2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
20 * @brief This is the header file for the %Web class.
22 * This header file contains the declarations of the %Web class.
24 #ifndef _FWEB_CTRL_WEB_H_
25 #define _FWEB_CTRL_WEB_H_
27 #include <FBaseBuffer.h>
28 #include <FBaseResult.h>
29 #include <FBaseString.h>
30 #include <FUiContainer.h>
32 namespace Tizen { namespace Graphics
39 namespace Tizen { namespace Net { namespace Http
42 }}} // Tizen::Net::Http
44 namespace Tizen { namespace Web { namespace Controls
46 class IJavaScriptBridge;
47 class ILoadingListener;
48 class ITextSearchListener;
49 class IWebDownloadListener;
50 class IWebKeypadEventListener;
51 class IWebUiEventListener;
52 class IWebUiEventListenerF;
54 class HitElementResult;
55 class PageNavigationList;
58 }}} // Tizen::Web::Controls
60 namespace Tizen { namespace Web { namespace Controls
65 * @brief This class provides methods for embedding a browser in an application.
69 * The %Web class provides methods for embedding a browser in an application to load and render various types of %Web content. Similar to adding UI controls, the %Web content can be added to the application by adding a %Web control.
71 * For more information on the class features and %Web browser feature limitations, see <a href="../org.tizen.native.appprogramming/html/guide/web/controls_namespace.htm">Web Controls Guide</a> and <a href="../org.tizen.native.appprogramming/html/guide/web/supported_web_features.htm">Supported Features in the Web Control</a>.
73 * The following example demonstrates how to use the %Web class.
75 // Sample code for WebSample.h
80 public Tizen::Ui::Controls::Form
84 virtual ~WebSample(void) {};
90 Tizen::Web::Controls::Web *__pWeb;
93 virtual result OnInitializing(void);
96 // Sample code for WebSample.cpp
97 #include "WebSample.h"
99 using namespace Tizen::Ui;
100 using namespace Tizen::Ui::Controls;
101 using namespace Tizen::Web::Controls;
104 WebSample::OnInitializing(void)
106 result r = E_SUCCESS;
109 __pWeb->Construct(GetClientAreaBounds());
116 // Calls LoadUrl() with the URL of the Web content to display it on the Web control
118 WebSample::LoadUrl(void)
120 Tizen::Base::String url(L"http://www.tizen.org");
122 __pWeb->LoadUrl(url);
127 class _OSP_EXPORT_ Web
128 : public Tizen::Ui::Container
132 * The object is not fully constructed after this constructor is called. For full construction, the Construct() method must be called right after calling this constructor.
139 * This destructor overrides Tizen::Base::Object::~Object().
146 * Initializes this instance of the %Web control with the specified parameters.
151 * @privilege %http://tizen.org/privilege/web.service
153 * @return An error code
154 * @param[in] rect The rectangle size of the control
155 * @exception E_SUCCESS The method is successful.
156 * @exception E_SYSTEM The method has failed.
157 * @exception E_INVALID_ARG The specified @c rect is invalid.
158 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
160 result Construct(const Tizen::Graphics::Rectangle& rect);
163 * Initializes this instance of the %Web control with the specified parameters.
168 * @privilege %http://tizen.org/privilege/web.service
170 * @return An error code
171 * @param[in] rect The rectangle size of the control
172 * @exception E_SUCCESS The method is successful.
173 * @exception E_SYSTEM The method has failed.
174 * @exception E_INVALID_ARG The specified @c rect is invalid.
175 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
177 result Construct(const Tizen::Graphics::FloatRectangle& rect);
180 * Loads the resource specified by the URL.
185 * @privilege %http://tizen.org/privilege/web.service
187 * @param[in] url The resource to load
188 * @exception E_SUCCESS The method is successful.
189 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
190 * @remarks The specific error code can be accessed using the GetLastResult() method.
192 void LoadUrl(const Tizen::Base::String& url);
195 * Loads the resource specified by the URL with the given header of HTTP request.
200 * @privilege %http://tizen.org/privilege/web.service
202 * @return An error code
203 * @param[in] url The resource to load
204 * @param[in] header The header of the HTTP request
205 * @exception E_SUCCESS The method is successful.
206 * @exception E_INVALID_HEADER The header object does not contain any header fields.
207 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
209 result LoadUrl(const Tizen::Base::String& url, const Tizen::Net::Http::HttpHeader& header);
212 * Load the resource specified by the URL with the given header and body of HTTP request. @n
213 * The header must include content-type entity-header field that is needed to check mime-type of the message body.
218 * @privilege %http://tizen.org/privilege/web.service
220 * @return An error code
221 * @param[in] url The resource to load
222 * @param[in] header The header of the HTTP request
223 * @param[in] body The message body of the HTTP request
224 * @exception E_SUCCESS The method is successful.
225 * @exception E_INVALID_HEADER The header object does not contain any header fields.
226 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
228 result LoadUrlWithPostRequest(const Tizen::Base::String& url, const Tizen::Net::Http::HttpHeader& header, const Tizen::Base::ByteBuffer& body);
231 * Loads the content of the specified buffer.
236 * @privilege %http://tizen.org/privilege/web.service
238 * @param[in] baseUrl The uniform resource locator (URL) of the content
239 * @param[in] content The content
240 * @param[in] mime The MIME type of the content
241 * @param[in] encoding The <a href= "../org.tizen.native.appprogramming/html/guide/web/supported_web_features.htm">text encoding</a> of the content
242 * @exception E_SUCCESS The method is successful.
243 * @exception E_INVALID_ARG The content buffer is empty @b Since: @b 2.1
244 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
245 * @remarks The specific error code can be accessed using the GetLastResult() method.
247 void LoadData(const Tizen::Base::String& baseUrl, const Tizen::Base::ByteBuffer& content, const Tizen::Base::String& mime, const Tizen::Base::String& encoding = "UTF-8");
250 * Stops the current loading operation.
255 * @privilege %http://tizen.org/privilege/web.service
257 * @exception E_SUCCESS The method is successful.
258 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
259 * @remarks The specific error code can be accessed using the GetLastResult() method.
261 void StopLoading(void);
264 * Reloads the current page.
269 * @privilege %http://tizen.org/privilege/web.service
271 * @exception E_SUCCESS The method is successful.
272 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
273 * @remarks The specific error code can be accessed using the GetLastResult() method.
278 * Checks whether the page is loading.
282 * @return @c true if a page is loading, @n
285 bool IsLoading(void) const;
288 * Checks whether the current %Web control has a back history item.
292 * @return @c true if a back history item exists, @n
295 bool CanGoBack(void) const;
298 * Checks whether the current %Web control has a forward history item.
302 * @return @c true if a forward history item exists, @n
305 bool CanGoForward(void) const;
308 * Goes to the back history of the current %Web control.
313 * @privilege %http://tizen.org/privilege/web.service
315 * @exception E_SUCCESS The method is successful.
316 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
317 * @remarks The specific error code can be accessed using the GetLastResult() method.
322 * Goes to the forward history of the current %Web control.
327 * @privilege %http://tizen.org/privilege/web.service
329 * @exception E_SUCCESS The method is successful.
330 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
331 * @remarks The specific error code can be accessed using the GetLastResult() method.
333 void GoForward(void);
336 * Gets the backward and forward navigation list of the %Web control.
340 * @return A pointer to PageNavigationList containing the history items of the %Web control
341 * @exception E_SUCCESS The method is successful.
342 * @exception E_SYSTEM The method cannot proceed due to a severe system error.
343 * @remarks The specific error code can be accessed using the GetLastResult() method.
345 Tizen::Web::Controls::PageNavigationList* GetBackForwardListN(void) const;
348 * Searches for a word on the current page. @n
349 * When called again, it searches for the next instance of the word on the page. Set @c searchForward to @c false to search for the word in the backward
354 * @return @c true if the specified @c word is found, @n
356 * @param[in] word The string to search for
357 * @param[in] searchForward Set to @c true to search for the word in the forward direction from the current position, @n
358 * else @c false to search for the word in the backward direction from the current position
360 bool SearchText(const Tizen::Base::String& word, bool searchForward = true);
363 * Sets the new values for the default setting. @n
364 * It fails to change the setting during data load.
369 * @privilege %http://tizen.org/privilege/web.service
371 * @return An error code
372 * @param[in] setting The setting to update
373 * @exception E_SUCCESS The method is successful.
374 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
376 result SetSetting(const Tizen::Web::Controls::WebSetting& setting);
379 * Gets the setting of the %Web control.
383 * @return An instance of WebSetting
385 Tizen::Web::Controls::WebSetting GetSetting(void) const;
389 * Gets the information of the element pointed by the specified coordinates.
393 * @return A HitElementResult of the pointed element
394 * @param[in] point The x and y coordinates
395 * @exception E_SUCCESS The method is successful.
396 * @exception E_INVALID_ARG The specified @c point is invalid.
397 * @exception E_UNSUPPORTED_FORMAT The image format is not supported.
398 * @exception E_SYSTEM The method cannot proceed due to a severe system error.
399 * @remarks The specific error code can be accessed using the GetLastResult() method.
401 Tizen::Web::Controls::HitElementResult* GetElementByPointN(const Tizen::Graphics::Point& point) const;
404 * Gets the information of the element pointed by the specified coordinates.
408 * @return A HitElementResult of the pointed element
409 * @param[in] point The x and y coordinates
410 * @exception E_SUCCESS The method is successful.
411 * @exception E_INVALID_ARG The specified @c point is invalid.
412 * @exception E_UNSUPPORTED_FORMAT The image format is not supported.
413 * @exception E_SYSTEM The method cannot proceed due to a severe system error.
414 * @remarks The specific error code can be accessed using the GetLastResult() method.
416 Tizen::Web::Controls::HitElementResult* GetElementByPointN(const Tizen::Graphics::FloatPoint& point) const;
419 * Evaluates the JavaScript string and returns the result.
424 * @privilege %http://tizen.org/privilege/web.service
426 * @return The result of the evaluated JavaScript, @n
427 * else an empty string if an error occurs
428 * @param[in] scriptCode The JavaScript code as string
429 * @exception E_SUCCESS The method is successful.
430 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
431 * @remarks The specific error code can be accessed using the GetLastResult() method.
433 Tizen::Base::String* EvaluateJavascriptN(const Tizen::Base::String& scriptCode);
436 * Sets the zoom-out level as a ratio.
440 * @return An error code
441 * @param[in] level The zoom-out level @n
442 * The value ranges between @c 0.3 and @c 2.0. When the page view is at its original size, the level is @c 1.0. @n If the
443 * specified level is less than @c 1.0, the page view is reduced. @n If the specified level is greater than @c 1.0, the page view is
445 * @exception E_SUCCESS The method is successful.
446 * @exception E_OUT_OF_RANGE The specified @c level is less than @c 0.3 or greater than @c 2.0.
448 result SetZoomLevel(float level);
451 * Gets the zoom level of a page as a percentage.
455 * @return The value ranges between @c 0.3 and @c 2.0
457 float GetZoomLevel(void) const;
460 * Gets the title of the current page.
464 * @return The title of the current page
466 Tizen::Base::String GetTitle(void) const;
469 * Gets the URL of the current page.
473 * @return The URL of the current page
475 Tizen::Base::String GetUrl(void) const;
478 * Checks whether the specified multipurpose internet mail extensions (MIME) type is supported by %Tizen.
482 * @return @c true if the specified MIME type is supported, @n
484 * @param[in] mime The MIME type
486 bool IsMimeSupported(const Tizen::Base::String& mime) const;
489 * Sets a load event listener.
494 * @privilege %http://tizen.org/privilege/web.service
496 * @param[in] pLoadingListener The listener receives the events that occurs while loading the data
497 * @exception E_SUCCESS The method is successful.
498 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
499 * @remarks The specific error code can be accessed using the GetLastResult() method.
501 void SetLoadingListener(Tizen::Web::Controls::ILoadingListener* pLoadingListener);
504 * Sets a download event listener.
509 * @privilege %http://tizen.org/privilege/web.service
511 * @param[in] pDownLoadListener The listener to receive the data from a network incrementally
512 * @exception E_SUCCESS The method is successful.
513 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
514 * @remarks The specific error code can be accessed using the GetLastResult() method.
516 void SetDownloadListener(Tizen::Web::Controls::IWebDownloadListener* pDownLoadListener);
519 * Sets the starting point for the text selection block. @n
520 * It sets the selection block around the nearest word bound.
524 * @return An error code
525 * @param[in] startPoint The starting point for the text selection block
526 * @exception E_SUCCESS The method is successful.
527 * @exception E_INVALID_ARG There is nothing to select from the starting point specified.
529 result SetBlockSelectionPosition(const Tizen::Graphics::Point& startPoint);
532 * Sets the starting point for the text selection block. @n
533 * It sets the selection block around the nearest word bound.
537 * @return An error code
538 * @param[in] startPoint The starting point for the text selection block
539 * @exception E_SUCCESS The method is successful.
540 * @exception E_INVALID_ARG There is nothing to select from the starting point specified.
542 result SetBlockSelectionPosition(const Tizen::Graphics::FloatPoint& startPoint);
545 * Releases the currently selected block.
549 * @return An error code
550 * @exception E_SUCCESS The method is successful.
553 result ReleaseBlock(void);
556 * Gets the starting point and the ending point of the selected text block. @n
557 * When the %GetBlockRange() method is called without the selection block, the @c startPoint and @c endPoint have (0,0) values for the x and y coordinates.
561 * @return An error code
562 * @param[out] startPoint The starting point of the selected text block
563 * @param[out] endPoint The ending point of the selected text block
564 * @exception E_SUCCESS The method is successful.
566 result GetBlockRange(Tizen::Graphics::Point& startPoint, Tizen::Graphics::Point& endPoint) const;
569 * Gets the starting point and the ending point of the selected text block. @n
570 * When this method is called without the selection block, the startPoint and endPoint have (0.0,0.0) values for the x and y coordinates.
574 * @return An error code
575 * @param[out] startPoint The starting point of the selected text block
576 * @param[out] endPoint The ending point of the selected text block
577 * @exception E_SUCCESS The method is successful.
579 result GetBlockRange(Tizen::Graphics::FloatPoint& startPoint, Tizen::Graphics::FloatPoint& endPoint) const;
583 * Gets the text of the selected text block.
587 * @return The selected text, @n
588 * else an empty string if there is no selection block
590 Tizen::Base::String GetTextFromBlock(void) const;
593 * Enables or disables the vertical and horizontal scrolls.
597 * @param[in] enable Set to @c true to enable the scrolling of the web page, @n
599 * @exception E_SUCCESS The method is successful.
601 result SetScrollEnabled(bool enable);
605 * Checks whether the web page scroll is enabled.
609 * @return @c true if the web page scroll is enabled, @n
612 bool IsScrollEnabled(void) const;
615 * Registers a user interface (UI) event listener.
619 * @param[in] pUiEventListener The listener to receive the user interface (UI) related events
621 void SetWebUiEventListener(Tizen::Web::Controls::IWebUiEventListener* pUiEventListener);
624 * Registers a user interface (UI) event listener.
628 * @param[in] pUiEventListener The listener to receive the user interface (UI) related events
630 void SetWebUiEventListenerF(Tizen::Web::Controls::IWebUiEventListenerF* pUiEventListener);
633 * Checks whether the %Web control uses private browsing.
637 * @return @c true if private browsing is enabled, @n
640 bool IsPrivateBrowsingEnabled(void) const;
643 * Sets the private browsing and returns the result.
648 * @privilege %http://tizen.org/privilege/web.service
650 * @return The result of setting the private browsing
651 * @param[in] enable Set to @c true to enable private browsing, @n
653 * @exception E_SUCCESS The method is successful.
654 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
656 result SetPrivateBrowsingEnabled(bool enable);
659 * Clears the back and forward navigation list.
664 * @privilege %http://tizen.org/privilege/web.service
666 * @return An error code
667 * @exception E_SUCCESS The method is successful.
668 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
670 * @see CanGoForward()
674 result ClearHistory(void);
677 * Clears the application's cache.
682 * @privilege %http://tizen.org/privilege/web.service
684 * @return An error code
685 * @exception E_SUCCESS The method is successful.
686 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
688 result ClearCache(void);
691 * Clears the application's cookie.
696 * @privilege %http://tizen.org/privilege/web.service
698 * @return An error code
699 * @exception E_SUCCESS The method is successful.
700 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
702 result ClearCookie(void);
705 * Clears the application's all stored form datas.
710 * @privilege %http://tizen.org/privilege/web.service
712 * @return An error code
713 * @exception E_SUCCESS The method is successful.
714 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
716 result ClearFormData(void);
719 * Clears the application's all stored id/password datas.
724 * @privilege %http://tizen.org/privilege/web.service
726 * @return An error code
727 * @exception E_SUCCESS The method is successful.
728 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
730 result ClearLoginFormData(void);
733 * Checks whether the %Web control allows cookie. @n
734 * Returns @c true if cookie is enabled.
738 * @return @c true if cookie is allowed, @n
741 bool IsCookieEnabled(void) const;
744 * Enables or disables a cookie.
749 * @privilege %http://tizen.org/privilege/web.service
751 * @return The result of enabling or disabling cookie
752 * @param[in] enable Set to @c true if the web control allows a cookie, @n
754 * @exception E_SUCCESS The method is successful.
755 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
757 result SetCookieEnabled(bool enable);
760 * Saves the current web page as a pdf file. @n The size parameter is used to set size of the pdf file using millimeter.
764 * @return An error code
765 * @param[in] filePath The path of the pdf file that is created
766 * @param[in] pSize The width and height of the pdf file in millimeter. The width and height must be greater than @c 0. @n
767 * If the parameter contains @c null, the method uses the default size of the web page that is shown on the screen.
768 * @exception E_SUCCESS The method is successful.
769 * @exception E_INVALID_ARG Either of the following conditions has occurred: @n
770 * - The specified path is invalid.
771 * - The specified size is invalid.
772 * @exception E_INACCESSIBLE_PATH The file path is not allowed for the application to write.
774 result SavePageAsPdf(const Tizen::Base::String& filePath, const Tizen::Graphics::Dimension* pSize = null);
777 * Adds a JavaScript bridge instance.
781 * @return An error code
782 * @param[in] jsBridge The JavaScript bridge to add
783 * @exception E_SUCCESS The method is successful.
784 * @exception E_OBJ_ALREADY_EXIST A JavaScript bridge with the same name already exists.
786 result AddJavaScriptBridge(const IJavaScriptBridge& jsBridge);
789 * Removes a JavaScript bridge instance.
793 * @return An error code
794 * @param[in] jsBridge The JavaScript bridge to remove
795 * @exception E_SUCCESS The method is successful.
796 * @exception E_OBJ_NOT_FOUND The specified element is not found.
798 result RemoveJavaScriptBridge(const IJavaScriptBridge& jsBridge);
801 * Registers a keypad event listener. @n
802 * The registered listener is notified when the keypad associated with @c <input> tag or with @c <textarea> tag is opened or closed.
806 * @param[in] pKeypadEventListener The event listener to set
807 * @remarks The interfaces of IWebKeypadEventListener are called only when the input style of the keypad is @c INPUT_STYLE_OVERLAY.
808 * @see WebSetting::SetInputStyle()
810 void SetWebKeypadEventListener(IWebKeypadEventListener* pKeypadEventListener);
813 * Searches for all instances of the text on the current page and then highlights them. @n
814 * The current matched block will indicate the first match.
818 * @return An error code
820 * @param[in] text The string to search for
821 * @param[in] caseSensitive Set to @c true to search for the text with case-sensitive mode, @n
822 * else @c false to search for the text in the backward direction from the current position
823 * @exception E_SUCCESS The method is successful.
824 * @exception E_INVALID_ARG The specified @c text is invalid.
825 * @remarks This method operates asynchronously.
826 * @see Tizen::Web::Controls::ITextSearchListener::OnTextFound()
828 result SearchTextAllAsync(const Tizen::Base::String& text, bool caseSensitive);
831 * Scrolls the current matched block to the next text matched by SearchTextAllAsync().
835 * @return An error code
837 * @param[in] searchForward Set to @c true to search for the text in the forward direction from the current position, @n
838 * @exception E_SUCCESS The method is successful.
839 * @exception E_OBJ_NOT_FOUND The next instance is not found.
840 * @exception E_INVALID_OPERATION The SearchTextAllAsync() method is not called.
841 * @remarks This method operates asynchronously.
842 * @see Tizen::Web::Controls::ITextSearchListener::OnTextFound()
844 result SearchNextAsync(bool searchForward = true);
847 * Sets a text search listener.
851 * @param[in] pTextSearchListener The result of the search operation made by asynchronous methods
853 void SetTextSearchListener(ITextSearchListener* pTextSearchListener);
856 * Gets the favicon image from current page.
861 * @see Tizen::Web::Controls::ILoadingListener::OnFaviconReceived()
863 Tizen::Graphics::Bitmap* GetFaviconN(void) const;
866 * Informs the browser engine to stop the screen operations such as updating a screen until %Web calls the Resume() method. @n
867 * It is useful when a %Web control is not visible and does not need to update its screen.
874 * Informs the browser engine to resume the handling of screen operations.
881 * Scrolls the web page with the given coordinates.
885 * @param[in] diff The x and y coordinates
887 void ScrollBy(const Tizen::Graphics::Point& diff);
890 * Sets the scrolled position of the web page.
894 * @param[in] dest The x and y coordinates
896 void ScrollTo(const Tizen::Graphics::Point& dest);
899 * Gets the current scroll position of the web page.
903 * @return The x and y coordinates
905 Tizen::Graphics::Point GetScrollPosition(void) const;
908 * Gets the real size of the current web page.
912 * @return The size of the current web page
913 * @remarks If an application want to get the displayed size, the return value should be multiplied by the zoom factor.
914 * @see GetZoomLevel()
916 Tizen::Graphics::Dimension GetPageSize(void) const;
920 // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
922 // @param[in] item The instance of the %Web class to copy from
923 // @remarks This constructor is hidden.
925 Web(const Web& item);
928 // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
930 // @param[in] item The instance of the %Web class to assign from
931 // @remarks This operator is hidden.
933 Web& operator =(const Web& item);
936 }}} // Tizen::Web::Controls
937 #endif // _FWEB_CTRL_WEB_H_