WebView
PUBLISHED
You can access web pages and web content in your application using the WebView functionality. You can also use various other features for Web browsing, such as loading and displaying web pages, and navigating through the browsing history.
The main features of WebView are as follows:
- Initializing and Creating WebView
You can initialize a WebView and create a WebView object.
- Managing Web Page Loading
You can load a web page with requested URL and register event handlers for loading events.
- Managing Cookie
You can set the cookie policy and the storage for the cookie.
- Finalizing WebView
You can shut down the WebView and clean up the resources.
Prerequisites
To enable your application to use WebView functionality:
- To use the Tizen.WebView namespace, create the
ElmSharp-Beta
project using the Project Wizard of Visual Studio. - To use the class of the
Tizen.WebView
namespace, the application has to request permission by adding the following privileges to thetizen-manifest.xml
file:<privileges> <!--To use the Internet connection--> <privilege>http://tizen.org/privilege/internet</privilege> <!--To access media storage--> <privilege>http://tizen.org/privilege/mediastorage</privilege> <!--To access, read, and write to the external storage--> <privilege>http://tizen.org/privilege/externalstorage</privilege> </privileges>
- To use the methods and properties of the
Tizen.WebView
namespace, include it in your application:using Tizen.WebView;
Initializing and Creating WebView
To Initialize WebView and create a WebView object, follow these steps:- To use the
Tizen.WebView
namespace in your application, call theTizen.WebView.Chromium.Initialize
method before the start of the main loop:Elementary.Initialize(); Elementary.ThemeOverlay(); Chromium.Initialize(); App app = new App(); app.Run(args);
- To create a WebView object, use the constructor of Tizen.WebView.WebView with
ElmSharp.Window
:var webView = new WebView(window) { AlignmentX = -1, AlignmentY = -1, WeightX = 1, WeightY = 1 }; webView.Show();
Managing Web Page Loading
To load a web page and add an event handler to loading events:- To load a web page, use the
Tizen.WebView.WebView.LoadUrl
method with an appropriate URL:webView.LoadUrl("https://www.tizen.org/");
- The following table lists the loading events provided by the
Tizen.WebView.WebView
class:Table: Loading Events
Event Description Argument LoadStarted
This event occurs when the page loading has started. – LoadFinished
This event occurs when the page loading has completed. – LoadError
This event occurs when the page loading has failed with an error. Tizen.WebView.SmartCallbackLoadErrorArgs - Add an event handler to handle each loading event:
webView.LoadStarted += (s, e) => { /* Handle LoadStarted event here */ }; webView.LoadFinished += (s, e) => { /* Handle LoadFinished event here */ }; webView.LoadError += (s, e) => { /* Handle LoadError event here */ // error code var code = e.Code; // description var desc = e.Description; // URL var url = e.Url; };
Managing Cookie
To manage and set the cookie options, use the Tizen.WebView.CookieManager class.
- To get the
Tizen.WebView.CookieManager
object from WebView, useTizen.WebView.WebView.GetContext
andTizen.WebView.Context.GetCookieManager
:CookieManager cookieManager = webView.GetContext().GetCookieManager();
- To set the cookie acceptance policy, use the
Tizen.WebView.CookieManager.SetCookieAcceptPolicy
method:/* Accepts every cookie sent from any page */ cookieManager.SetCookieAcceptPolicy(CookieAcceptPolicy.Always); /* Rejects all the cookies */ cookieManager.SetCookieAcceptPolicy(CookieAcceptPolicy.Never); /* Accepts only cookies set by the main document that is loaded */ cookieManager.SetCookieAcceptPolicy(CookieAcceptPolicy.NoThirdParty);
- To set the persistent storage for the cookie, use the
Tizen.WebView.CookieManager.SetPersistentStorage
method:cookieManager.SetPersistentStorage(DirectoryInfo.Data, CookiePersistentStorage.SqlLite);
Finalizing WebView
To clean up the allocated resources, call the Tizen.WebView.Chromium.Shutdown
method after the end of the main loop:
App app = new App(); app.Run(args); Chromium.Shutdown();
Was this document helpful?
We value your feedback. Please let us know what you think.