QCefView
Loading...
Searching...
No Matches
QCefView

Represents the CEF browser view. More...

#include <QCefView.h>

Public Types

enum  CefWindowOpenDisposition
 Represents the CEF pop-up windows open disposition. More...
 

Public Slots

void setFocus ()
 

Signals

void loadingStateChanged (const int &browserId, bool isLoading, bool canGoBack, bool canGoForward)
 Gets called on loading state changed.
 
void loadStart (const int &browserId, const QString &frameId, bool isMainFrame, int transitionType)
 Gets called on loading starts.
 
void loadEnd (const int &browserId, const QString &frameId, bool isMainFrame, int httpStatusCode)
 Gets called on loading ends.
 
void loadError (const int &browserId, const QString &frameId, bool isMainFrame, int errorCode, const QString &errorMsg, const QString &failedUrl)
 Gets called on loading failed due to error.
 
void draggableRegionChanged (const QRegion &draggableRegion, const QRegion &nonDraggableRegion)
 Gets called on draggable region changed.
 
void addressChanged (const QString &frameId, const QString &url)
 Gets called on the address changed.
 
void titleChanged (const QString &title)
 Gets called on title changed.
 
void faviconURLChanged (const QStringList &urls)
 Gets called on favicon url changed.
 
void fullscreenModeChanged (bool fullscreen)
 Gets called on fullscreen mode changed.
 
void statusMessage (const QString &message)
 Gets called on status message changed.
 
void consoleMessage (const QString &message, int level)
 Gets called on console message from the web content.
 
void loadingProgressChanged (double progress)
 Gets called on loading progress changed.
 
void cefUrlRequest (const int &browserId, const QString &frameId, const QString &url)
 Gets called on built-in scheme URL access.
 
void cefQueryRequest (const int &browserId, const QString &frameId, const QCefQuery &query)
 Gets called on new QCefQuery request.
 
void invokeMethod (const int &browserId, const QString &frameId, const QString &method, const QVariantList &arguments)
 Gets called on invoking method request from web content(Javascript)
 
void reportJavascriptResult (const int &browserId, const QString &frameId, const QString &context, const QVariant &result)
 Gets called on the result of the javascript executed with executeJavascriptWithResult returned.
 
void nativeBrowserCreated (QWindow *window)
 Gets called after the native browser window created. This slot does not work for OSR mode.
 

Public Member Functions

 QCefView (const QString &url, const QCefSetting *setting, QWidget *parent=nullptr, Qt::WindowFlags f=Qt::WindowFlags())
 Constructs a QCefView instance.
 
 QCefView (QWidget *parent=nullptr, Qt::WindowFlags f=Qt::WindowFlags())
 Constructs a QCefView instance.
 
 ~QCefView ()
 Destructs the QCefView instance.
 
void addLocalFolderResource (const QString &path, const QString &url, int priority=0)
 Adds a url mapping item with local web resource directory.
 
void addArchiveResource (const QString &path, const QString &url, const QString &password="", int priority=0)
 Adds a url mapping item with local archive (.zip) file which contains the web resource.
 
int browserId ()
 Gets the browser id.
 
void navigateToString (const QString &content)
 Navigates to the content.
 
void navigateToUrl (const QString &url)
 Navigates to the URL.
 
bool browserCanGoBack ()
 Checks whether the browser can go back.
 
bool browserCanGoForward ()
 Checks whether the browser can go forward.
 
void browserGoBack ()
 Requires the browser to go back.
 
void browserGoForward ()
 Requires the browser to go forward.
 
bool browserIsLoading ()
 Checks whether the browser is loading.
 
void browserReload ()
 Requires the browser to reload.
 
void browserStopLoad ()
 Requires the browser to stop load.
 
bool triggerEvent (const QCefEvent &event)
 Triggers the event for main frame.
 
bool triggerEvent (const QCefEvent &event, const QString &frameId)
 Triggers the event for specified frame.
 
bool broadcastEvent (const QCefEvent &event)
 Broad cast the event for all frames.
 
bool responseQCefQuery (const QCefQuery &query)
 Response the QCefQuery request.
 
bool executeJavascript (const QString &frameId, const QString &code, const QString &url)
 Executes javascript code in specified frame, this method does not report the result of the javascript. To get the result of the javascript execution use executeJavascriptWithResult
 
bool executeJavascriptWithResult (const QString &frameId, const QString &code, const QString &url, const QString &context)
 Executes javascript code in specified frame and the result will be reported through reportJavascriptResult signal.
 
bool setPreference (const QString &name, const QVariant &value, const QString &error)
 Sets the preference for this browser.
 
void setOSRFrameRate (int fps)
 Sets the frame rate for OSR (Off-Screen Rendering).
 
bool hasDevTools ()
 Detects whether this browser has a devtools opened.
 
void showDevTools ()
 Opens the devtools dialog.
 
void closeDevTools ()
 Closes the devtools dialog.
 
void setAllowDrag (bool allow)
 Sets whether dragging is allowed.
 
bool allowDrag () const
 Indicates whether drag operations are allowed.
 
void setFocus (Qt::FocusReason reason)
 Please refer to QWidget::setFocus.
 
QVariant inputMethodQuery (Qt::InputMethodQuery query) const override
 Please refer to QWidget::inputMethodQuery.
 

Static Public Attributes

static const QString MainFrameID
 The main frame identity.
 
static const QString AllFrameID
 The identifier for all frames.
 

Protected Member Functions

virtual QCefViewonNewBrowser (const QString &sourceFrameId, const QString &url, const QString &name, QCefView::CefWindowOpenDisposition targetDisposition, QRect &rect, QCefSetting &settings)
 Gets called before a new browser created (only for browser created by non-JavaScript)
 
virtual bool onNewPopup (const QString &frameId, const QString &targetUrl, QString &targetFrameName, QCefView::CefWindowOpenDisposition targetDisposition, QRect &rect, QCefSetting &settings, bool &disableJavascriptAccess)
 Gets called before the popup browser created (only for browser created by JavaScript)
 
virtual void onNewDownloadItem (const QSharedPointer< QCefDownloadItem > &item, const QString &suggestedName)
 Gets called on new download item was required. Keep reference to the download item and call QCefDownloadItem::start method to allow and start the download, Ignore the download item to disallow the download.
 
virtual void onUpdateDownloadItem (const QSharedPointer< QCefDownloadItem > &item)
 Gets called on download item updated. To get this method called QCefDownloadItem::start method must be called in newDownloadItem method.
 
virtual bool onRequestCloseFromWeb ()
 Gets called on close request from web.
 
QPaintEngine * paintEngine () const override
 Please refer to QWidget::paintEngine.
 
bool event (QEvent *event) override
 

Detailed Description

Represents the CEF browser view.

Member Enumeration Documentation

◆ CefWindowOpenDisposition

Represents the CEF pop-up windows open disposition.

Enumerator
CefWindowOpenDispositionUnknown 
CefWindowOpenDispositionCurrentTab 
CefWindowOpenDispositionSingletonTab 
CefWindowOpenDispositionNewForeGroundTab 
CefWindowOpenDispositionNewBackgroundTab 
CefWindowOpenDispositionNewPopup 
CefWindowOpenDispositionNewWindow 
CefWindowOpenDispositionSaveToDisk 
CefWindowOpenDispositionOffTheRecord 
CefWindowOpenDispositionIgnoreAction 

Constructor & Destructor Documentation

◆ QCefView() [1/2]

QCefView::QCefView ( const QString & url,
const QCefSetting * setting,
QWidget * parent = nullptr,
Qt::WindowFlags f = Qt::WindowFlags() )

Constructs a QCefView instance.

Parameters
urlThe target url
settingThe QCefSetting instance
parentThe parent
fThe Qt WindowFlags

◆ QCefView() [2/2]

QCefView::QCefView ( QWidget * parent = nullptr,
Qt::WindowFlags f = Qt::WindowFlags() )

Constructs a QCefView instance.

Parameters
parentThe parent
fThe Qt WindowFlags

◆ ~QCefView()

QCefView::~QCefView ( )

Destructs the QCefView instance.

Member Function Documentation

◆ addLocalFolderResource()

void QCefView::addLocalFolderResource ( const QString & path,
const QString & url,
int priority = 0 )

Adds a url mapping item with local web resource directory.

Parameters
pathThe path to the local resource directory
urlThe url to be mapped to
priorityThe priority

◆ addArchiveResource()

void QCefView::addArchiveResource ( const QString & path,
const QString & url,
const QString & password = "",
int priority = 0 )

Adds a url mapping item with local archive (.zip) file which contains the web resource.

Parameters
pathThe path to the local archive file
urlThe url to be mapped to
passwordThe password of the archive
priorityThe priority

◆ browserId()

int QCefView::browserId ( )

Gets the browser id.

Returns
The browser id

◆ navigateToString()

void QCefView::navigateToString ( const QString & content)

Navigates to the content.

Parameters
contentThe content

◆ navigateToUrl()

void QCefView::navigateToUrl ( const QString & url)

Navigates to the URL.

Parameters
urlThe url

◆ browserCanGoBack()

bool QCefView::browserCanGoBack ( )

Checks whether the browser can go back.

Returns
True if can; otherwise false

◆ browserCanGoForward()

bool QCefView::browserCanGoForward ( )

Checks whether the browser can go forward.

Returns
True if can; otherwise false

◆ browserGoBack()

void QCefView::browserGoBack ( )

Requires the browser to go back.

◆ browserGoForward()

void QCefView::browserGoForward ( )

Requires the browser to go forward.

◆ browserIsLoading()

bool QCefView::browserIsLoading ( )

Checks whether the browser is loading.

Returns
True if it is loading; otherwise false

◆ browserReload()

void QCefView::browserReload ( )

Requires the browser to reload.

◆ browserStopLoad()

void QCefView::browserStopLoad ( )

Requires the browser to stop load.

◆ triggerEvent() [1/2]

bool QCefView::triggerEvent ( const QCefEvent & event)

Triggers the event for main frame.

Parameters
eventThe QCefEvent instance
Returns
True on successful; otherwise false

◆ triggerEvent() [2/2]

bool QCefView::triggerEvent ( const QCefEvent & event,
const QString & frameId )

Triggers the event for specified frame.

Parameters
eventThe QCefEvent instance
frameIdThe frame id
Returns
True on successful; otherwise false

◆ broadcastEvent()

bool QCefView::broadcastEvent ( const QCefEvent & event)

Broad cast the event for all frames.

Parameters
eventThe QCefEvent instance
Returns
True on successful; otherwise false

◆ responseQCefQuery()

bool QCefView::responseQCefQuery ( const QCefQuery & query)

Response the QCefQuery request.

Parameters
queryThe query instance
Returns
True on successful; otherwise false

◆ executeJavascript()

bool QCefView::executeJavascript ( const QString & frameId,
const QString & code,
const QString & url )

Executes javascript code in specified frame, this method does not report the result of the javascript. To get the result of the javascript execution use executeJavascriptWithResult

Parameters
frameIdThe frame id
codeThe javascript code
urlThe URL where the script in question can be found, if any. The renderer may request this URL to show the developer the source of the error
Returns
True on successful; otherwise false

◆ executeJavascriptWithResult()

bool QCefView::executeJavascriptWithResult ( const QString & frameId,
const QString & code,
const QString & url,
const QString & context )

Executes javascript code in specified frame and the result will be reported through reportJavascriptResult signal.

Parameters
frameIdThe frame id
codeThe javascript code
urlThe URL where the script in question can be found, if any. The renderer may request this URL to show the developer the source of the error
contextThe context used to identify the one execution
Returns
True on successful; otherwise false

◆ setPreference()

bool QCefView::setPreference ( const QString & name,
const QVariant & value,
const QString & error )

Sets the preference for this browser.

Parameters
nameThe preference name
valueThe preference value, if this value is QVariant::UnknownType or QVariant::Invalid, the preference will be restored to default value
errorThe error message populated on failure
Returns
True on successful; otherwise false

◆ setOSRFrameRate()

void QCefView::setOSRFrameRate ( int fps)

Sets the frame rate for OSR (Off-Screen Rendering).

Parameters
fpsThe desired frame rate in frames per second.

◆ hasDevTools()

bool QCefView::hasDevTools ( )

Detects whether this browser has a devtools opened.

Returns
True if opend already; otherwise false

◆ showDevTools()

void QCefView::showDevTools ( )

Opens the devtools dialog.

◆ closeDevTools()

void QCefView::closeDevTools ( )

Closes the devtools dialog.

◆ setAllowDrag()

void QCefView::setAllowDrag ( bool allow)

Sets whether dragging is allowed.

Parameters
allowTrue to allow dragging; false to disable it.

◆ allowDrag()

bool QCefView::allowDrag ( ) const

Indicates whether drag operations are allowed.

Returns
true if drag operations are permitted; otherwise, false.

◆ loadingStateChanged

void QCefView::loadingStateChanged ( const int & browserId,
bool isLoading,
bool canGoBack,
bool canGoForward )
signal

Gets called on loading state changed.

Parameters
browserIdIndicates the browser id
isLoadingIndicates the browser is loading
canGoBackIndicates the browser can go back
canGoForwardIndicates the browser can go forward

◆ loadStart

void QCefView::loadStart ( const int & browserId,
const QString & frameId,
bool isMainFrame,
int transitionType )
signal

Gets called on loading starts.

Parameters
browserIdIndicates the browser id
frameIdIndicates the frame id
isMainFrameIndicates the whether this is the main frame
transitionTypetransition type

◆ loadEnd

void QCefView::loadEnd ( const int & browserId,
const QString & frameId,
bool isMainFrame,
int httpStatusCode )
signal

Gets called on loading ends.

Parameters
browserIdIndicates the browser id
frameIdIndicates the frame id
isMainFrameIndicates the whether this is the main frame
httpStatusCodeThe HTTP status code

◆ loadError

void QCefView::loadError ( const int & browserId,
const QString & frameId,
bool isMainFrame,
int errorCode,
const QString & errorMsg,
const QString & failedUrl )
signal

Gets called on loading failed due to error.

Parameters
browserIdIndicates the browser id
frameIdIndicates the frame id
isMainFrameIndicates the whether this is the main frame
errorCodeThe error code
errorMsgThe error message
failedUrlThe url caused the failure

◆ draggableRegionChanged

void QCefView::draggableRegionChanged ( const QRegion & draggableRegion,
const QRegion & nonDraggableRegion )
signal

Gets called on draggable region changed.

Parameters
draggableRegionThe new draggable region
nonDraggableRegionThe new non-draggable region

◆ addressChanged

void QCefView::addressChanged ( const QString & frameId,
const QString & url )
signal

Gets called on the address changed.

Parameters
frameIdThe frame id
urlThe address

◆ titleChanged

void QCefView::titleChanged ( const QString & title)
signal

Gets called on title changed.

Parameters
titleThe title

◆ faviconURLChanged

void QCefView::faviconURLChanged ( const QStringList & urls)
signal

Gets called on favicon url changed.

Parameters
urlsThe urls

◆ fullscreenModeChanged

void QCefView::fullscreenModeChanged ( bool fullscreen)
signal

Gets called on fullscreen mode changed.

Parameters
fullscreenThe current fullscreen mode

◆ statusMessage

void QCefView::statusMessage ( const QString & message)
signal

Gets called on status message changed.

Parameters
messageThe status message

◆ consoleMessage

void QCefView::consoleMessage ( const QString & message,
int level )
signal

Gets called on console message from the web content.

Parameters
messageThe message
levelThe level

◆ loadingProgressChanged

void QCefView::loadingProgressChanged ( double progress)
signal

Gets called on loading progress changed.

Parameters
progressCurrent progress

◆ cefUrlRequest

void QCefView::cefUrlRequest ( const int & browserId,
const QString & frameId,
const QString & url )
signal

Gets called on built-in scheme URL access.

Parameters
browserIdThe browser id
frameIdThe frame id
urlThe full url

◆ cefQueryRequest

void QCefView::cefQueryRequest ( const int & browserId,
const QString & frameId,
const QCefQuery & query )
signal

Gets called on new QCefQuery request.

Parameters
browserIdThe browser id
frameIdThe frame id
queryThe query request

◆ invokeMethod

void QCefView::invokeMethod ( const int & browserId,
const QString & frameId,
const QString & method,
const QVariantList & arguments )
signal

Gets called on invoking method request from web content(Javascript)

Parameters
browserIdThe browser id
frameIdThe frame id
methodThe method name
argumentsThe arguments list

◆ reportJavascriptResult

void QCefView::reportJavascriptResult ( const int & browserId,
const QString & frameId,
const QString & context,
const QVariant & result )
signal

Gets called on the result of the javascript executed with executeJavascriptWithResult returned.

Parameters
browserIdThe browser id
frameIdThe frame id
contextThe context
resultThe result

◆ nativeBrowserCreated

void QCefView::nativeBrowserCreated ( QWindow * window)
signal

Gets called after the native browser window created. This slot does not work for OSR mode.

Parameters
windowThe native browser windows

◆ onNewBrowser()

virtual QCefView * QCefView::onNewBrowser ( const QString & sourceFrameId,
const QString & url,
const QString & name,
QCefView::CefWindowOpenDisposition targetDisposition,
QRect & rect,
QCefSetting & settings )
protectedvirtual

Gets called before a new browser created (only for browser created by non-JavaScript)

Parameters
sourceFrameIdThe source frame id
urlThe target URL
nameThe target name
targetDispositionTarget window open method
rectRect to be used for the popup
settingsSettings to be used for the popup
Returns

True to cancel the popup; false to allow

◆ onNewPopup()

virtual bool QCefView::onNewPopup ( const QString & frameId,
const QString & targetUrl,
QString & targetFrameName,
QCefView::CefWindowOpenDisposition targetDisposition,
QRect & rect,
QCefSetting & settings,
bool & disableJavascriptAccess )
protectedvirtual

Gets called before the popup browser created (only for browser created by JavaScript)

Parameters
frameIdThe source frame id
targetUrlThe target URL
targetFrameNameThe target name
targetDispositionTarget window open method
rectRect to be used for the popup
settingsSettings to be used for the popup
disableJavascriptAccessThe output value to receive the Javascript access switch
Returns
True to cancel the popup; false to allow

◆ onNewDownloadItem()

virtual void QCefView::onNewDownloadItem ( const QSharedPointer< QCefDownloadItem > & item,
const QString & suggestedName )
protectedvirtual

Gets called on new download item was required. Keep reference to the download item and call QCefDownloadItem::start method to allow and start the download, Ignore the download item to disallow the download.

Parameters
itemThe new download item
suggestedNameThe new suggested name

◆ onUpdateDownloadItem()

virtual void QCefView::onUpdateDownloadItem ( const QSharedPointer< QCefDownloadItem > & item)
protectedvirtual

Gets called on download item updated. To get this method called QCefDownloadItem::start method must be called in newDownloadItem method.

Parameters
itemThe download item

◆ onRequestCloseFromWeb()

virtual bool QCefView::onRequestCloseFromWeb ( )
protectedvirtual

Gets called on close request from web.

Returns
True to allow the close, false to cancel the close

◆ setFocus() [1/2]

void QCefView::setFocus ( Qt::FocusReason reason)

Please refer to QWidget::setFocus.

◆ inputMethodQuery()

QVariant QCefView::inputMethodQuery ( Qt::InputMethodQuery query) const
override

Please refer to QWidget::inputMethodQuery.

◆ setFocus [2/2]

void QCefView::setFocus ( )
inlineslot

◆ paintEngine()

QPaintEngine * QCefView::paintEngine ( ) const
overrideprotected

Please refer to QWidget::paintEngine.

◆ event()

bool QCefView::event ( QEvent * event)
overrideprotected
Parameters
event
Returns

Member Data Documentation

◆ MainFrameID

const QString QCefView::MainFrameID
static

The main frame identity.

◆ AllFrameID

const QString QCefView::AllFrameID
static

The identifier for all frames.