You.i Engine
CYIWebViewController Class Referenceabstract

Detailed Description

Provides an interface to a platform web view, if available.

CYIWebViewController is used to control a platform native web view.

For the web view to appear in the application, CYIWebView must be used. A CYIWebViewController is automatically constructed when a CYIWebView is created, and it can be retrieved using CYIWebView::GetWebViewController(). The web view controller can also be used without a visual representation.

This example shows how to retrieve the CYIWebViewController from a CYIWebView.

CYIWebView *pWebView = pSceneViewMain->GetNode<CYIWebView>("ViewName");
CYIWebViewController *pWebViewController = pWebView->GetWebViewController();
if (pWebViewController)
{
pWebViewController->LoadUrl(CYIUrl("http://www.youi.tv"));
}

This is an example of using the webview without a visual representation for an authentication flow.

class WebViewAuthentication : public CYISignalHandler
{
public:
WebViewAuthentication()
{
}
void InitWebView()
{
m_pWebViewController = CYIWebViewController::CreateIfSupported();
if (m_pWebViewController)
{
m_pWebViewController->AuthenticationRequired.Connect(*this, &WebViewAuthentication::OnAuthenticationRequired);
}
}
void OnAuthenticationRequired(CYIString host, CYIString realm)
{
YI_UNUSED(host);
YI_UNUSED(realm);
m_pWebViewController->Authenticate("username", "password");
}
private:
std::unique_ptr<CYIWebViewController> m_pWebViewController;
};
Note
This class is only available on supported mobile touch platforms: Android and iOS. Android TV and Fire TV are not supported.
As of iOS 9, App Transport Security prevents insecure communication by default.
See also
CYIWebView
CYIPlatformView
CYIPlatformViewProxy

#include <platform/YiWebViewController.h>

Inheritance diagram for CYIWebViewController:

Classes

struct  Resource
 Represents a resource that has been loaded. More...
 

Public Types

enum  RESOURCE_TYPE {
  WEB_VIEW_HTTP_URL,
  WEB_VIEW_FILE_URL,
  WEB_VIEW_HTML_DOC
}
 Supported resource types. More...
 

Public Member Functions

virtual ~CYIWebViewController ()
 
void LoadUrl (const CYIUrl &url)
 
void LoadFile (const CYIString &pathToDocument)
 
void LoadHTML (const CYIString &htmlString)
 
virtual void NavigateBack ()=0
 
virtual void NavigateForward ()=0
 
virtual bool CanNavigateBack ()=0
 
virtual bool CanNavigateForward ()=0
 
virtual void ClearCache ()=0
 
const ResourceGetLastLoadedResource () const
 
virtual void Authenticate (const CYIString &username, const CYIString &password)=0
 
virtual void CancelAuthentication ()=0
 
virtual void SetOverpullEnabled (bool bEnabled)=0
 
CYIPlatformViewProxyGetPlatformViewProxy () const
 
- Public Member Functions inherited from CYISignalHandler
 CYISignalHandler ()
 
 CYISignalHandler (const CYISignalHandler &rSignalHandler)
 
virtual ~CYISignalHandler ()
 
CYISignalHandleroperator= (const CYISignalHandler &rSignalHandler)
 
void MoveToThread (CYIThread *pThread)
 This function allows the user to override the default thread affinity to any CYIThread that may or may not be running. More...
 
CYIThreadHandle GetThreadAffinity () const
 
void SetThreadAffinity (const CYIThreadHandle &rThreadAffinity)
 
virtual bool IsConnected () const
 
virtual bool IsConnected (const CYISignalBase &rSignal) const
 
void Disconnect (CYISignalBase &rSignal)
 
void DisconnectFromAllSignals ()
 
- Public Member Functions inherited from CYIThread::Listener
 Listener ()
 
virtual ~Listener ()
 
virtual void OnThreadStarted (CYIThread *)
 
virtual void OnThreadTerminated (CYIThread *)
 
virtual void OnThreadFinished (CYIThread *)
 

Static Public Member Functions

static std::unique_ptr< CYIWebViewControllerCreateIfSupported ()
 

Public Attributes

CYISignal< CYIString, CYIStringAuthenticationRequired
 
CYISignal< ResourceLoadingCancelled
 
CYISignal< ResourceLoadingStarted
 
CYISignal< ResourceLoadingFinished
 
CYISignal< Resource, CYIStringLoadingErrorOccurred
 
CYISignal< ResourceRedirectOccurred
 

Protected Member Functions

 CYIWebViewController ()
 
void NotifyLoadingStarted (const CYIString &webRequest)
 
void NotifyLoadingFinished ()
 
void NotifyLoadingErrorOccurred (const CYIString &errorMessage)
 
void NotifyAuthenticationRequired (const CYIString &realm, const CYIString &host)
 
void NotifyLoadingCancelled ()
 
virtual void Load (const Resource &webViewResource)=0
 

Member Enumeration Documentation

Supported resource types.

Enumerator
WEB_VIEW_HTTP_URL 

Indicates a remote url.

WEB_VIEW_FILE_URL 

Indicates a local file path to a document.

WEB_VIEW_HTML_DOC 

Indicates an in-memory HTML document.

Constructor & Destructor Documentation

virtual CYIWebViewController::~CYIWebViewController ( )
virtual
CYIWebViewController::CYIWebViewController ( )
protected

Member Function Documentation

virtual void CYIWebViewController::Authenticate ( const CYIString username,
const CYIString password 
)
pure virtual

Authenticates with username and password in response to an authentication request. Calling this function is only valid if there is an ongoing authentication request. It will have no effect otherwise.

Invalid credentials will result in AuthenticationRequired being emitted again.

See also
AuthenticationRequired
virtual void CYIWebViewController::CancelAuthentication ( )
pure virtual

Cancels an ongoing authentication and releases resources being used for the authentication. Calling this function is only valid if there is an ongoing authentication request. It will have no effect otherwise.

See also
AuthenticationRequired
virtual bool CYIWebViewController::CanNavigateBack ( )
pure virtual

Indicates if it is possible to navigate back.

virtual bool CYIWebViewController::CanNavigateForward ( )
pure virtual

Indicates if it is possible to navigate forward.

virtual void CYIWebViewController::ClearCache ( )
pure virtual

Clears all cached data, including cookies. Affects all web view instances.

static std::unique_ptr<CYIWebViewController> CYIWebViewController::CreateIfSupported ( )
static

Returns a new instance of CYIWebViewController, or nullptr if unsupported on the platform.

const Resource& CYIWebViewController::GetLastLoadedResource ( ) const

Returns the last resource successfully loaded by this web view.

See also
LoadingFinished
CYIPlatformViewProxy* CYIWebViewController::GetPlatformViewProxy ( ) const

Returns the platform view proxy representation of the platform native web view.

From the returned CYIPlatfromViewProxy a CYIPlatformViewHandle may be obtained. This allows access to the platform native web view which this controller controls. This is useful for advanced configuration of the native web view such as enabling or disabling platform specific features of the web view.

Note
On Android the native platform web view is an instance of android.webkit.WebView.
On iOS the native platform web view is an instance of WebKit.WKWebView.
CYIPlatformViewHandle may not be set on the CYIPlatformViewProxy directly after creation of the CYIWebViewController. Use CYIPlatformViewProxy::PlatformViewHandleSet to obtain the platform native web view handle after it has been set.
See also
CYIPlatformView::SetViewProxy
CYIPlatformViewProxy::GetPlatformViewHandle
virtual void CYIWebViewController::Load ( const Resource webViewResource)
protectedpure virtual

Loads webViewResource.

void CYIWebViewController::LoadFile ( const CYIString pathToDocument)

Loads the local resource located at absolute path pathToDocument. The resource can be located in the assets directory, in which case the path can be constructed using CYIApp::GetAssetsPath. The resource may also be stored in the data or external directory, and the path can be constructed using CYIApp::GetDataPath or CYIApp::GetExternalPath, respectively.

void CYIWebViewController::LoadHTML ( const CYIString htmlString)

Loads htmlString as a document.

void CYIWebViewController::LoadUrl ( const CYIUrl url)

Loads the remote resource located at url.

virtual void CYIWebViewController::NavigateBack ( )
pure virtual

Navigates back in the web view history. Has no effect if it is not possible to navigate back.

See also
CanNavigateBack
virtual void CYIWebViewController::NavigateForward ( )
pure virtual

Navigates forward in the web view history. Has no effect if it is not possible to navigate forward.

See also
CanNavigateForward
void CYIWebViewController::NotifyAuthenticationRequired ( const CYIString realm,
const CYIString host 
)
protected

Implementations must call this function when authentication is required.

void CYIWebViewController::NotifyLoadingCancelled ( )
protected

Implementaitons must call this function when authentication request is cancelled.

void CYIWebViewController::NotifyLoadingErrorOccurred ( const CYIString errorMessage)
protected

Implementations must call this function when an error is encountered when loading.

void CYIWebViewController::NotifyLoadingFinished ( )
protected

Implementations must call this function when the web view has completed loading the resource.

void CYIWebViewController::NotifyLoadingStarted ( const CYIString webRequest)
protected

Implementations must call this function when the web view begins loading the resource.

virtual void CYIWebViewController::SetOverpullEnabled ( bool  bEnabled)
pure virtual

Enables or disables a visual indication when the user scrolls beyond the bounds of the scrolling limits.

Note
This indication may differ between platforms.

Member Data Documentation

CYISignal<CYIString , CYIString > CYIWebViewController::AuthenticationRequired

Emitted when the resource being loaded requires authentication to view. Users should respond to this signal by calling either Authenticate or CancelAuthentication.

The first signal parameter represents the host, and the second parameter represents the realm.

See also
Authenticate
CancelAuthentication
CYISignal<Resource> CYIWebViewController::LoadingCancelled

Emitted when an authentication request has been cancelled for the specified resource.

See also
CancelAuthentication
CYISignal<Resource, CYIString > CYIWebViewController::LoadingErrorOccurred

Emitted when the web view has encountered an error while loading the specified resource. The error message is provided as the second signal parameter.

CYISignal<Resource> CYIWebViewController::LoadingFinished

Emitted when the web view has finished loading the specified resource.

CYISignal<Resource> CYIWebViewController::LoadingStarted

Emitted when the web view begins loading the specified resource.

CYISignal<Resource> CYIWebViewController::RedirectOccurred

Emitted when the web view has encountered a redirect while loading the specified resource. The resource with the new path is provided as the signal parameter.


The documentation for this class was generated from the following file: