QWebEngineUrlScheme 类

QWebEngineUrlScheme 类能配置自定义 URL 方案。 更多...

头: #include <QWebEngineUrlScheme>
CMake: find_package(Qt6 REQUIRED COMPONENTS WebEngineCore)
target_link_libraries(mytarget PRIVATE Qt6::WebEngineCore)
qmake: QT += webenginecore

公共类型

enum Flag { SecureScheme, LocalScheme, LocalAccessAllowed, NoAccessAllowed, ServiceWorkersAllowed, …, FetchApiAllowed }
flags Flags
enum SpecialPort { PortUnspecified }
enum class 句法 { HostPortAndUserInformation, HostAndPort, Host, Path }

公共函数

QWebEngineUrlScheme ()
QWebEngineUrlScheme (const QByteArray & name )
QWebEngineUrlScheme (const QWebEngineUrlScheme & that )
QWebEngineUrlScheme (QWebEngineUrlScheme && that )
~QWebEngineUrlScheme ()
int defaultPort () const
QWebEngineUrlScheme::Flags flags () const
QByteArray name () const
void setDefaultPort (int newValue )
void setFlags (QWebEngineUrlScheme::Flags newValue )
void setName (const QByteArray & newValue )
void setSyntax (QWebEngineUrlScheme::Syntax newValue )
QWebEngineUrlScheme::Syntax syntax () const
bool operator!= (const QWebEngineUrlScheme & that ) const
QWebEngineUrlScheme & operator= (const QWebEngineUrlScheme & that )
QWebEngineUrlScheme & operator= (QWebEngineUrlScheme && that )
bool operator== (const QWebEngineUrlScheme & that ) const

静态公共成员

void registerScheme (const QWebEngineUrlScheme & scheme )
QWebEngineUrlScheme schemeByName (const QByteArray & name )

详细描述

A web engine URL scheme describes a URL scheme from the web engine's perspective, specifying how URLs of this scheme should be parsed, and which security restrictions should be placed on resources originating from such URLs.

Custom URL schemes must be configured early at application startup, before creating any Qt WebEngine classes. In general this means the schemes need to be configured before a QGuiApplication or QApplication 实例被创建。

Every registered scheme configuration applies globally to all profiles.

int main(int argc, char **argv)
{
    QWebEngineUrlScheme scheme("myscheme");
    scheme.setSyntax(QWebEngineUrlScheme::Syntax::HostAndPort);
    scheme.setDefaultPort(2345);
    scheme.setFlags(QWebEngineUrlScheme::SecureScheme);
    QWebEngineUrlScheme::registerScheme(scheme);
    ...
}
					

To actually make use of the custom URL scheme, a QWebEngineUrlSchemeHandler must be created and registered in a profile.

另请参阅 QWebEngineUrlSchemeHandler .

成员类型文档编制

enum QWebEngineUrlScheme:: Flag
flags QWebEngineUrlScheme:: Flags

This enum type specifies security options that should apply to a URL scheme.

常量 描述
QWebEngineUrlScheme::SecureScheme 0x1 Indicates that the URL scheme is potentially trustworthy . This flag should only be applied to URL schemes which ensure data authenticity, confidentiality, and integrity, either through encryption or other means. Examples of secure builtin schemes include https (authenticated and encrypted) and qrc (local resources only), whereas http is an example of an insecure scheme.
QWebEngineUrlScheme::LocalScheme 0x2 Indicates that the URL scheme provides access to local resources. The purpose of this flag is to prevent network content from accessing local resources. Only schemes with the LocalAccessAllowed flag may load resources from a scheme with the LocalScheme flag. The only builtin scheme with this flag is file .
QWebEngineUrlScheme::LocalAccessAllowed 0x4 Indicates that content from this scheme should be allowed to load resources from schemes with the LocalScheme 标志。
QWebEngineUrlScheme::NoAccessAllowed 0x8 Indicates that all content from this scheme should be forced to have unique opaque origins: no two resources will have the same origin.
QWebEngineUrlScheme::ServiceWorkersAllowed 0x10 Indicates that the Service Workers API should be enabled.
QWebEngineUrlScheme::ViewSourceAllowed 0x20 Indicates that the View Source feature should be enabled.
QWebEngineUrlScheme::ContentSecurityPolicyIgnored 0x40 Indicates that accesses to this scheme should bypass all Content-Security-Policy checks.
QWebEngineUrlScheme::CorsEnabled 0x80 Enables cross-origin resource sharing (CORS) for this scheme. This flag is required in order for content to be loaded by documents of a different origin, this includes access from other schemes. The appropriate CORS headers are generated automatically by the QWebEngineUrlRequestJob class. By default only http and https are CORS enabled. (Added in Qt 5.14)
QWebEngineUrlScheme::FetchApiAllowed (since Qt 6.6) 0x100 Enables a URL scheme to be used by the HTML5 fetch API and XMLHttpRequest.send with a body. By default only http and https can be send to using the Fetch API or with an XMLHttpRequest with a body.

Flags 类型是 typedef 对于 QFlags <Flag>。它存储 Flag 值的 OR 组合。

enum QWebEngineUrlScheme:: SpecialPort

This enum type defines special values for defaultPort .

常量 描述
QWebEngineUrlScheme::PortUnspecified -1 Indicates that the URL scheme does not have a port element.

enum class QWebEngineUrlScheme:: 句法

This enum type lists types of URL syntax.

To apply the same-origin policy to a custom URL scheme, WebEngine must be able to compute the origin (host and port combination) of a URL. The Host... options indicate that the URL scheme conforms to the standard URL syntax (like http ) and automatically enable the same-origin policy. The 路径 option indicates that the URL scheme uses a non-standard syntax and that the same-origin policy cannot be applied.

常量 描述
QWebEngineUrlScheme::Syntax::HostPortAndUserInformation 0 The authority component of a URL of this type has all of the standard elements: host, port, user name, and password. A URL without a port will use the defaultPort (which must not be PortUnspecified ).
QWebEngineUrlScheme::Syntax::HostAndPort 1 The authority component of a URL of this type has only the host and port elements. A URL without a port will use the defaultPort (which must not be PortUnspecified ).
QWebEngineUrlScheme::Syntax::Host 2 The authority component of a URL of this type has only the host part and no port. The defaultPort must be set to PortUnspecified .
QWebEngineUrlScheme::Syntax::Path 3 A URL of this type has no authority component at all. Everything after scheme name and separator character (:) will be preserved as is without validation or canonicalization. All URLs of such a scheme will be considered as having the same origin (unless the NoAccessAllowed flag is used).

成员函数文档编制

QWebEngineUrlScheme:: QWebEngineUrlScheme ()

Constructs a web engine URL scheme with default values.

[explicit] QWebEngineUrlScheme:: QWebEngineUrlScheme (const QByteArray & name )

Constructs a web engine URL scheme with given name .

QWebEngineUrlScheme:: QWebEngineUrlScheme (const QWebEngineUrlScheme & that )

拷贝 that .

QWebEngineUrlScheme:: QWebEngineUrlScheme ( QWebEngineUrlScheme && that )

移动 that .

[noexcept] QWebEngineUrlScheme:: ~QWebEngineUrlScheme ()

Destructs this object.

int QWebEngineUrlScheme:: defaultPort () const

Returns the default port of this URL scheme.

默认值为 PortUnspecified .

另请参阅 setDefaultPort ().

QWebEngineUrlScheme::Flags QWebEngineUrlScheme:: flags () const

Returns the flags for this URL scheme.

The default value is an empty set of flags.

另请参阅 Flags and setFlags ().

QByteArray QWebEngineUrlScheme:: name () const

返回此 URL 方案的名称。

默认值为空字符串。

另请参阅 setName ().

[static] void QWebEngineUrlScheme:: registerScheme (const QWebEngineUrlScheme & scheme )

注册 scheme with the web engine's URL parser and security model.

It is recommended that all custom URL schemes are first registered with this function at application startup, even if the default options are to be used.

警告: This function must be called early at application startup, before creating any WebEngine classes. Late calls will be ignored.

另请参阅 schemeByName ().

[static] QWebEngineUrlScheme QWebEngineUrlScheme:: schemeByName (const QByteArray & name )

Returns the web engine URL scheme with the given name or the default-constructed scheme.

另请参阅 registerScheme ().

void QWebEngineUrlScheme:: setDefaultPort ( int newValue )

Sets the default port of this URL scheme to newValue .

另请参阅 defaultPort ().

void QWebEngineUrlScheme:: setFlags ( QWebEngineUrlScheme::Flags newValue )

Sets the flags for this URL scheme to newValue .

另请参阅 Flags and flags ().

void QWebEngineUrlScheme:: setName (const QByteArray & newValue )

Sets the name of this URL scheme to newValue .

注意: The name is automatically converted to lower case.

另请参阅 name ().

void QWebEngineUrlScheme:: setSyntax ( QWebEngineUrlScheme::Syntax newValue )

Sets the syntax type of this URL scheme to newValue .

另请参阅 句法 and syntax ().

QWebEngineUrlScheme::Syntax QWebEngineUrlScheme:: syntax () const

Returns the syntax type of this URL scheme.

默认值为 路径 .

另请参阅 句法 and setSyntax ().

bool QWebEngineUrlScheme:: operator!= (const QWebEngineUrlScheme & that ) const

返回 true if this and that object are not equal.

QWebEngineUrlScheme &QWebEngineUrlScheme:: operator= (const QWebEngineUrlScheme & that )

拷贝 that .

QWebEngineUrlScheme &QWebEngineUrlScheme:: operator= ( QWebEngineUrlScheme && that )

移动 that .

bool QWebEngineUrlScheme:: operator== (const QWebEngineUrlScheme & that ) const

返回 true if this and that object are equal.