diff options
author | Jüri Valdmann <juri.valdmann@qt.io> | 2018-09-03 10:25:04 +0200 |
---|---|---|
committer | Jüri Valdmann <juri.valdmann@qt.io> | 2018-09-12 09:53:53 +0000 |
commit | 5b5b7d9a5f922ef5fa99cfac41da348e23970032 (patch) | |
tree | 52369f7ff008d64a6089a0d8063189f396761b99 /src | |
parent | c91bba7af3215107916a135733dcf428f57a564f (diff) |
Improve QWebEngineUrlScheme API
Following feedback from 5.12 API review:
- Use enum class for Syntax
- Add Q_FLAG for Flags
- Mark constructor from name as explicit
- Rename Secure to SecureScheme
- Rename Local to LocalScheme
- Rename addScheme to registerScheme
- Rename findScheme to schemeByName
Task-number: QTBUG-70247
Change-Id: Iae332c8d9843349506e8a4b07d70f0d234597375
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/core/api/qwebengineurlscheme.cpp | 44 | ||||
-rw-r--r-- | src/core/api/qwebengineurlscheme.h | 23 | ||||
-rw-r--r-- | src/core/web_engine_context.cpp | 4 | ||||
-rw-r--r-- | src/webengine/api/qquickwebengineprofile.cpp | 2 | ||||
-rw-r--r-- | src/webenginewidgets/api/qwebengineprofile.cpp | 2 |
5 files changed, 39 insertions, 36 deletions
diff --git a/src/core/api/qwebengineurlscheme.cpp b/src/core/api/qwebengineurlscheme.cpp index 59899769b..f36f3335b 100644 --- a/src/core/api/qwebengineurlscheme.cpp +++ b/src/core/api/qwebengineurlscheme.cpp @@ -43,16 +43,16 @@ QT_BEGIN_NAMESPACE -ASSERT_ENUMS_MATCH(QWebEngineUrlScheme::PathSyntax, url::SCHEME_WITHOUT_AUTHORITY) -ASSERT_ENUMS_MATCH(QWebEngineUrlScheme::HostSyntax, url::SCHEME_WITH_HOST) -ASSERT_ENUMS_MATCH(QWebEngineUrlScheme::HostAndPortSyntax, url::SCHEME_WITH_HOST_AND_PORT) -ASSERT_ENUMS_MATCH(QWebEngineUrlScheme::HostPortAndUserInformationSyntax, +ASSERT_ENUMS_MATCH(QWebEngineUrlScheme::Syntax::Path, url::SCHEME_WITHOUT_AUTHORITY) +ASSERT_ENUMS_MATCH(QWebEngineUrlScheme::Syntax::Host, url::SCHEME_WITH_HOST) +ASSERT_ENUMS_MATCH(QWebEngineUrlScheme::Syntax::HostAndPort, url::SCHEME_WITH_HOST_AND_PORT) +ASSERT_ENUMS_MATCH(QWebEngineUrlScheme::Syntax::HostPortAndUserInformation, url::SCHEME_WITH_HOST_PORT_AND_USER_INFORMATION) -ASSERT_ENUMS_MATCH(QWebEngineUrlScheme::PortUnspecified, url::PORT_UNSPECIFIED); +ASSERT_ENUMS_MATCH(QWebEngineUrlScheme::PortUnspecified, url::PORT_UNSPECIFIED) -ASSERT_ENUMS_MATCH(QWebEngineUrlScheme::Secure, url::CustomScheme::Secure) -ASSERT_ENUMS_MATCH(QWebEngineUrlScheme::Local, url::CustomScheme::Local) +ASSERT_ENUMS_MATCH(QWebEngineUrlScheme::SecureScheme, url::CustomScheme::Secure) +ASSERT_ENUMS_MATCH(QWebEngineUrlScheme::LocalScheme, url::CustomScheme::Local) ASSERT_ENUMS_MATCH(QWebEngineUrlScheme::LocalAccessAllowed, url::CustomScheme::LocalAccessAllowed) ASSERT_ENUMS_MATCH(QWebEngineUrlScheme::NoAccessAllowed, url::CustomScheme::NoAccessAllowed) ASSERT_ENUMS_MATCH(QWebEngineUrlScheme::ServiceWorkersAllowed, url::CustomScheme::ServiceWorkersAllowed) @@ -91,10 +91,10 @@ public: int main(int argc, char **argv) { QWebEngineUrlScheme scheme("myscheme"); - scheme.setSyntax(QWebEngineUrlScheme::HostAndPortSyntax); + scheme.setSyntax(QWebEngineUrlScheme::Syntax::HostAndPort); scheme.setDefaultPort(2345); - scheme.setFlags(QWebEngineUrlScheme::Secure); - QWebEngineUrlScheme::addScheme(scheme); + scheme.setFlags(QWebEngineUrlScheme::SecureScheme); + QWebEngineUrlScheme::registerScheme(scheme); ... } \endcode @@ -113,25 +113,25 @@ public: 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 \c {Host...} options indicate that the URL scheme conforms to the standard URL syntax (like - \c http) and automatically enable the same-origin policy. The \c {PathSyntax} + \c http) and automatically enable the same-origin policy. The \c {Path} option indicates that the URL scheme uses a non-standard syntax and that the same-origin policy cannot be applied. - \value HostPortAndUserInformationSyntax + \value HostPortAndUserInformation 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 \l defaultPort (which \e must not be \l PortUnspecified). - \value HostAndPortSyntax + \value HostAndPort The authority component of a URL of this type has only the host and port elements. A URL without a port will use the \l defaultPort (which \e must not be \l PortUnspecified). - \value HostSyntax + \value Host The authority component of a URL of this type has only the host part and no port. The \l defaultPort \e must be set to \l PortUnspecified. - \value PathSyntax + \value Path 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 @@ -152,7 +152,7 @@ public: This enum type specifies security options that should apply to a URL scheme. - \value Secure + \value SecureScheme Indicates that the URL scheme is \l{https://www.w3.org/TR/powerful-features/#is-origin-trustworthy}{potentially trustworthy}. This flag should only be applied to URL schemes which ensure @@ -161,7 +161,7 @@ public: (authenticated and encrypted) and \c qrc (local resources only), whereas \c http is an example of an insecure scheme. - \value Local + \value LocalScheme 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 \c LocalAccessAllowed flag may load resources from a @@ -279,7 +279,7 @@ void QWebEngineUrlScheme::setName(const QByteArray &newValue) /*! Returns the syntax type of this URL scheme. - The default value is \c PathSyntax. + The default value is \c Path. \sa Syntax, setSyntax() */ @@ -351,9 +351,9 @@ void QWebEngineUrlScheme::setFlags(Flags newValue) \warning This function must be called early at application startup, before creating any WebEngine classes. Late calls will be ignored. - \sa findScheme() + \sa schemeByName() */ -void QWebEngineUrlScheme::addScheme(const QWebEngineUrlScheme &scheme) +void QWebEngineUrlScheme::registerScheme(const QWebEngineUrlScheme &scheme) { url::CustomScheme::AddScheme(*scheme.d); } @@ -362,9 +362,9 @@ void QWebEngineUrlScheme::addScheme(const QWebEngineUrlScheme &scheme) Returns the web engine URL scheme with the given \a name or the default-constructed scheme. - \sa addScheme() + \sa registerScheme() */ -QWebEngineUrlScheme QWebEngineUrlScheme::findScheme(const QByteArray &name) +QWebEngineUrlScheme QWebEngineUrlScheme::schemeByName(const QByteArray &name) { base::StringPiece namePiece{name.data(), static_cast<size_t>(name.size())}; if (const url::CustomScheme *cs = url::CustomScheme::FindScheme(namePiece)) diff --git a/src/core/api/qwebengineurlscheme.h b/src/core/api/qwebengineurlscheme.h index dd936bd9d..88a8f5065 100644 --- a/src/core/api/qwebengineurlscheme.h +++ b/src/core/api/qwebengineurlscheme.h @@ -43,6 +43,7 @@ #include <QtWebEngineCore/qtwebenginecoreglobal.h> #include <QtCore/qbytearray.h> +#include <QtCore/qobjectdefs.h> #include <QtCore/qshareddata.h> QT_BEGIN_NAMESPACE @@ -50,12 +51,13 @@ QT_BEGIN_NAMESPACE class QWebEngineUrlSchemePrivate; class QWEBENGINECORE_EXPORT QWebEngineUrlScheme { + Q_GADGET public: - enum Syntax { - HostPortAndUserInformationSyntax, - HostAndPortSyntax, - HostSyntax, - PathSyntax, + enum class Syntax { + HostPortAndUserInformation, + HostAndPort, + Host, + Path, }; enum SpecialPort { @@ -63,8 +65,8 @@ public: }; enum Flag { - Secure = 0x1, - Local = 0x2, + SecureScheme = 0x1, + LocalScheme = 0x2, LocalAccessAllowed = 0x4, NoAccessAllowed = 0x8, ServiceWorkersAllowed = 0x10, @@ -72,9 +74,10 @@ public: ContentSecurityPolicyIgnored = 0x40, }; Q_DECLARE_FLAGS(Flags, Flag) + Q_FLAG(Flags) QWebEngineUrlScheme(); - QWebEngineUrlScheme(const QByteArray &name); + explicit QWebEngineUrlScheme(const QByteArray &name); QWebEngineUrlScheme(const QWebEngineUrlScheme &that); QWebEngineUrlScheme &operator=(const QWebEngineUrlScheme &that); @@ -99,8 +102,8 @@ public: Flags flags() const; void setFlags(Flags newValue); - static void addScheme(const QWebEngineUrlScheme &scheme); - static QWebEngineUrlScheme findScheme(const QByteArray &name); + static void registerScheme(const QWebEngineUrlScheme &scheme); + static QWebEngineUrlScheme schemeByName(const QByteArray &name); private: QWebEngineUrlScheme(QWebEngineUrlSchemePrivate *d); diff --git a/src/core/web_engine_context.cpp b/src/core/web_engine_context.cpp index 899e50e16..aba23b622 100644 --- a/src/core/web_engine_context.cpp +++ b/src/core/web_engine_context.cpp @@ -329,10 +329,10 @@ WebEngineContext::WebEngineContext() #endif QWebEngineUrlScheme qrcScheme(QByteArrayLiteral("qrc")); - qrcScheme.setFlags(QWebEngineUrlScheme::Secure + qrcScheme.setFlags(QWebEngineUrlScheme::SecureScheme | QWebEngineUrlScheme::LocalAccessAllowed | QWebEngineUrlScheme::ViewSourceAllowed); - QWebEngineUrlScheme::addScheme(qrcScheme); + QWebEngineUrlScheme::registerScheme(qrcScheme); // Allow us to inject javascript like any webview toolkit. content::RenderFrameHost::AllowInjectingJavaScriptForAndroidWebView(); diff --git a/src/webengine/api/qquickwebengineprofile.cpp b/src/webengine/api/qquickwebengineprofile.cpp index 02e15454b..f536695ef 100644 --- a/src/webengine/api/qquickwebengineprofile.cpp +++ b/src/webengine/api/qquickwebengineprofile.cpp @@ -836,7 +836,7 @@ static bool checkInternalScheme(const QByteArray &scheme) Registers a handler \a handler for custom URL scheme \a scheme in the profile. It is recommended to first register the scheme with \l - QWebEngineUrlScheme::addScheme at application startup. + QWebEngineUrlScheme::registerScheme at application startup. */ void QQuickWebEngineProfile::installUrlSchemeHandler(const QByteArray &scheme, QWebEngineUrlSchemeHandler *handler) { diff --git a/src/webenginewidgets/api/qwebengineprofile.cpp b/src/webenginewidgets/api/qwebengineprofile.cpp index b66a1aa53..b2fe49da3 100644 --- a/src/webenginewidgets/api/qwebengineprofile.cpp +++ b/src/webenginewidgets/api/qwebengineprofile.cpp @@ -682,7 +682,7 @@ static bool checkInternalScheme(const QByteArray &scheme) Registers a handler \a handler for custom URL scheme \a scheme in the profile. It is recommended to first register the scheme with \l - QWebEngineUrlScheme::addScheme at application startup. + QWebEngineUrlScheme::registerScheme at application startup. */ void QWebEngineProfile::installUrlSchemeHandler(const QByteArray &scheme, QWebEngineUrlSchemeHandler *handler) { |