Skip to content

Commit

Permalink
Merge pull request #14 from mer-packages/offline
Browse files Browse the repository at this point in the history
[qtwebkit] Introduce experimental.offline property
  • Loading branch information
VDVsx committed May 8, 2014
2 parents 81e87d4 + 7307a74 commit e2aaca3
Show file tree
Hide file tree
Showing 17 changed files with 128 additions and 7 deletions.
33 changes: 33 additions & 0 deletions qtwebkit/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp
Expand Up @@ -814,6 +814,18 @@ bool QQuickWebViewPrivate::handleCertificateVerificationRequest(const QString& h
return dialogRunner.wasAccepted();
}

void QQuickWebViewPrivate::handleNetworkRequestIgnored()
{
Q_Q(QQuickWebView);
emit q->experimental()->networkRequestIgnored();
}

void QQuickWebViewPrivate::handleOfflineChanged(bool state)
{
Q_Q(QQuickWebView);
q->experimental()->handleOfflineChanged(state);
}

void QQuickWebViewPrivate::chooseFiles(WKOpenPanelResultListenerRef listenerRef, const QStringList& selectedFileNames, QtWebPageUIClient::FileChooserType type)
{
Q_Q(QQuickWebView);
Expand Down Expand Up @@ -1152,6 +1164,7 @@ QQuickWebViewExperimental::QQuickWebViewExperimental(QQuickWebView *webView, QQu
, d_ptr(webViewPrivate)
, schemeParent(new QObject(this))
, m_test(new QWebKitTest(webViewPrivate, this))
, m_offline(0)
{
}

Expand Down Expand Up @@ -1267,6 +1280,26 @@ void QQuickWebViewExperimental::setTemporaryCookies(bool enable)
emit temporaryCookiesChanged();
}

bool QQuickWebViewExperimental::offline() const
{
return m_offline;
}

void QQuickWebViewExperimental::setOffline(bool state)
{
Q_D(const QQuickWebView);
d->webPageProxy->setOffline(state);
}

void QQuickWebViewExperimental::handleOfflineChanged(bool state)
{
if (state == m_offline)
return;

m_offline = state;
emit offlineChanged();
}

void QQuickWebViewExperimental::setFlickableViewportEnabled(bool enable)
{
s_flickableViewportEnabled = enable;
Expand Down
8 changes: 8 additions & 0 deletions qtwebkit/Source/WebKit2/UIProcess/API/qt/qquickwebview_p.h
Expand Up @@ -265,6 +265,7 @@ class QWEBKIT_EXPORT QQuickWebViewExperimental : public QObject {

Q_PROPERTY(bool autoCorrect WRITE setAutoCorrect READ autoCorrect NOTIFY autoCorrectChanged)
Q_PROPERTY(bool temporaryCookies WRITE setTemporaryCookies READ temporaryCookies NOTIFY temporaryCookiesChanged FINAL)
Q_PROPERTY(bool offline WRITE setOffline READ offline NOTIFY offlineChanged FINAL)

Q_PROPERTY(QWebNavigationHistory* navigationHistory READ navigationHistory CONSTANT FINAL)

Expand Down Expand Up @@ -373,7 +374,11 @@ class QWEBKIT_EXPORT QQuickWebViewExperimental : public QObject {
bool temporaryCookies() const;
void setTemporaryCookies(bool enable);

bool offline() const;
void setOffline(bool state);

// C++ only
void handleOfflineChanged(bool state);
bool renderToOffscreenBuffer() const;
void setRenderToOffscreenBuffer(bool enable);
static void setFlickableViewportEnabled(bool enable);
Expand Down Expand Up @@ -420,18 +425,21 @@ public Q_SLOTS:
void overviewChanged();
void temporaryCookiesChanged();
void textFound(int matchCount);
void offlineChanged();

void processDidCrash();
void didRelaunchProcess();
void processDidBecomeUnresponsive();
void processDidBecomeResponsive();
void networkRequestIgnored();

private:
QQuickWebViewExperimental(QQuickWebView* webView, QQuickWebViewPrivate* webViewPrivate);
QQuickWebView* q_ptr;
QQuickWebViewPrivate* d_ptr;
QObject* schemeParent;
QWebKitTest* m_test;
bool m_offline;

friend class WebKit::QtWebPageUIClient;

Expand Down
2 changes: 2 additions & 0 deletions qtwebkit/Source/WebKit2/UIProcess/API/qt/qquickwebview_p_p.h
Expand Up @@ -114,6 +114,8 @@ class QQuickWebViewPrivate {
void handleAuthenticationRequiredRequest(const QString& hostname, const QString& realm, const QString& prefilledUsername, QString& username, QString& password);
bool handleCertificateVerificationRequest(const QString& hostname);
void handleProxyAuthenticationRequiredRequest(const QString& hostname, uint16_t port, const QString& prefilledUsername, QString& username, QString& password);
void handleNetworkRequestIgnored();
void handleOfflineChanged(bool state);

void setRenderToOffscreenBuffer(bool enable) { m_renderToOffscreenBuffer = enable; }
void setTransparentBackground(bool);
Expand Down
10 changes: 10 additions & 0 deletions qtwebkit/Source/WebKit2/UIProcess/API/qt/raw/qrawwebview.cpp
Expand Up @@ -62,6 +62,16 @@ void QRawWebViewPrivate::handleProxyAuthenticationRequiredRequest(const String&
notImplemented();
}

void QRawWebViewPrivate::handleNetworkRequestIgnored()
{
notImplemented();
}

void QRawWebViewPrivate::handleOfflineChanged(bool state)
{
notImplemented();
}

void QRawWebViewPrivate::registerEditCommand(PassRefPtr<WebKit::WebEditCommandProxy>, WebKit::WebPageProxy::UndoOrRedo)
{
notImplemented();
Expand Down
Expand Up @@ -48,6 +48,8 @@ class QRawWebViewPrivate : public WebKit::PageClient {
virtual void handleAuthenticationRequiredRequest(const String& hostname, const String& realm, const String& prefilledUsername, String& username, String& password);
virtual void handleCertificateVerificationRequest(const String& hostname, bool& ignoreErrors);
virtual void handleProxyAuthenticationRequiredRequest(const String& hostname, uint16_t port, const String& prefilledUsername, String& username, String& password);
virtual void handleNetworkRequestIgnored();
virtual void handleOfflineChanged(bool state);

virtual void registerEditCommand(PassRefPtr<WebKit::WebEditCommandProxy>, WebKit::WebPageProxy::UndoOrRedo);
virtual bool canUndoRedo(WebKit::WebPageProxy::UndoOrRedo undoOrRedo);
Expand Down
2 changes: 2 additions & 0 deletions qtwebkit/Source/WebKit2/UIProcess/PageClient.h
Expand Up @@ -129,6 +129,8 @@ class PageClient {
virtual void handleCertificateVerificationRequest(const String& hostname, bool& ignoreErrors) = 0;
virtual void handleProxyAuthenticationRequiredRequest(const String& hostname, uint16_t port, const String& prefilledUsername, String& username, String& password) = 0;
virtual void handleWillSetInputMethodState() = 0;
virtual void handleNetworkRequestIgnored() = 0;
virtual void handleOfflineChanged(bool state) = 0;
#endif // PLATFORM(QT).

#if PLATFORM(QT) || PLATFORM(EFL) || PLATFORM(GTK)
Expand Down
3 changes: 3 additions & 0 deletions qtwebkit/Source/WebKit2/UIProcess/WebPageProxy.h
Expand Up @@ -365,11 +365,14 @@ class WebPageProxy
#endif
#if PLATFORM(QT)
void registerApplicationScheme(const String& scheme);
void setOffline(bool state);
void resolveApplicationSchemeRequest(QtNetworkRequestData);
void sendApplicationSchemeReply(const QQuickNetworkReply*);
void authenticationRequiredRequest(const String& hostname, const String& realm, const String& prefilledUsername, String& username, String& password);
void certificateVerificationRequest(const String& hostname, bool& ignoreErrors);
void proxyAuthenticationRequiredRequest(const String& hostname, uint16_t port, const String& prefilledUsername, String& username, String& password);
void networkRequestIgnored();
void offlineChanged(bool value);
#endif // PLATFORM(QT).
#if PLATFORM(EFL)
void setThemePath(const String&);
Expand Down
2 changes: 2 additions & 0 deletions qtwebkit/Source/WebKit2/UIProcess/WebPageProxy.messages.in
Expand Up @@ -84,6 +84,8 @@ messages -> WebPageProxy {
AuthenticationRequiredRequest(WTF::String hostname, WTF::String realm, WTF::String prefilledUsername) -> (WTF::String username, WTF::String password)
CertificateVerificationRequest(WTF::String hostname) -> (bool ignoreErrors)
ProxyAuthenticationRequiredRequest(WTF::String hostname, uint16_t port, WTF::String prefilledUsername) -> (WTF::String username, WTF::String password)
NetworkRequestIgnored()
OfflineChanged(bool state)
#endif

#if PLATFORM(QT) || PLATFORM(EFL)
Expand Down
10 changes: 10 additions & 0 deletions qtwebkit/Source/WebKit2/UIProcess/qt/QtPageClient.cpp
Expand Up @@ -154,6 +154,16 @@ void QtPageClient::handleProxyAuthenticationRequiredRequest(const String& hostna
password = qPassword;
}

void QtPageClient::handleNetworkRequestIgnored()
{
QQuickWebViewPrivate::get(m_webView)->handleNetworkRequestIgnored();
}

void QtPageClient::handleOfflineChanged(bool state)
{
QQuickWebViewPrivate::get(m_webView)->handleOfflineChanged(state);
}

void QtPageClient::setCursor(const WebCore::Cursor& cursor)
{
// FIXME: This is a temporary fix until we get cursor support in QML items.
Expand Down
2 changes: 2 additions & 0 deletions qtwebkit/Source/WebKit2/UIProcess/qt/QtPageClient.h
Expand Up @@ -58,6 +58,8 @@ class QtPageClient : public PageClient {
virtual void handleAuthenticationRequiredRequest(const String& hostname, const String& realm, const String& prefilledUsername, String& username, String& password);
virtual void handleCertificateVerificationRequest(const String& hostname, bool& ignoreErrors);
virtual void handleProxyAuthenticationRequiredRequest(const String& hostname, uint16_t port, const String& prefilledUsername, String& username, String& password);
virtual void handleNetworkRequestIgnored();
virtual void handleOfflineChanged(bool state);

virtual void displayView();
virtual bool canScrollView() { return false; }
Expand Down
15 changes: 15 additions & 0 deletions qtwebkit/Source/WebKit2/UIProcess/qt/WebPageProxyQt.cpp
Expand Up @@ -65,6 +65,11 @@ void WebPageProxy::registerApplicationScheme(const String& scheme)
process()->send(Messages::WebPage::RegisterApplicationScheme(scheme), m_pageID);
}

void WebPageProxy::setOffline(bool state)
{
process()->send(Messages::WebPage::SetOffline(state), m_pageID);
}

void WebPageProxy::resolveApplicationSchemeRequest(QtNetworkRequestData request)
{
#if HAVE(QTQUICK)
Expand Down Expand Up @@ -101,6 +106,16 @@ void WebPageProxy::certificateVerificationRequest(const String& hostname, bool&
m_pageClient->handleCertificateVerificationRequest(hostname, ignoreErrors);
}

void WebPageProxy::networkRequestIgnored()
{
m_pageClient->handleNetworkRequestIgnored();
}

void WebPageProxy::offlineChanged(bool state)
{
m_pageClient->handleOfflineChanged(state);
}

#if PLUGIN_ARCHITECTURE(X11)
void WebPageProxy::createPluginContainer(uint64_t& windowID)
{
Expand Down
1 change: 1 addition & 0 deletions qtwebkit/Source/WebKit2/WebProcess/WebPage/WebPage.h
Expand Up @@ -586,6 +586,7 @@ class WebPage : public TypedAPIObject<APIObject::TypeBundlePage>, public CoreIPC

#if PLATFORM(QT)
void registerApplicationScheme(const String& scheme);
void setOffline(bool state);
void applicationSchemeReply(const QtNetworkReplyData&);
void receivedApplicationSchemeRequest(const QNetworkRequest&, QtNetworkReply*);
void setUserScripts(const Vector<String>&);
Expand Down
Expand Up @@ -79,6 +79,7 @@ messages -> WebPage LegacyReceiver {

#if PLATFORM(QT)
ApplicationSchemeReply(WebKit::QtNetworkReplyData reply)
SetOffline(bool value)
RegisterApplicationScheme(WTF::String scheme)
#endif

Expand Down
8 changes: 8 additions & 0 deletions qtwebkit/Source/WebKit2/WebProcess/WebPage/qt/WebPageQt.cpp
Expand Up @@ -306,6 +306,14 @@ void WebPage::registerApplicationScheme(const String& scheme)
qnam->registerApplicationScheme(this, QString(scheme));
}

void WebPage::setOffline(bool state)
{
QtNetworkAccessManager* qnam = qobject_cast<QtNetworkAccessManager*>(WebProcess::shared().networkAccessManager());
if (!qnam)
return;
qnam->setOffline(state, m_pageID);
}

void WebPage::receivedApplicationSchemeRequest(const QNetworkRequest& request, QtNetworkReply* reply)
{
QtNetworkRequestData requestData(request, reply);
Expand Down
32 changes: 26 additions & 6 deletions qtwebkit/Source/WebKit2/WebProcess/qt/QtNetworkAccessManager.cpp
Expand Up @@ -42,6 +42,7 @@ namespace WebKit {
QtNetworkAccessManager::QtNetworkAccessManager(WebProcess* webProcess)
: QNetworkAccessManager()
, m_webProcess(webProcess)
, m_offline(0)
{
connect(this, SIGNAL(authenticationRequired(QNetworkReply*, QAuthenticator*)), SLOT(onAuthenticationRequired(QNetworkReply*, QAuthenticator*)));
connect(this, SIGNAL(proxyAuthenticationRequired(const QNetworkProxy&, QAuthenticator*)), SLOT(onProxyAuthenticationRequired(const QNetworkProxy&, QAuthenticator*)));
Expand All @@ -63,20 +64,39 @@ WebPage* QtNetworkAccessManager::obtainOriginatingWebPage(const QNetworkRequest&
QNetworkReply* QtNetworkAccessManager::createRequest(Operation operation, const QNetworkRequest& request, QIODevice* outData)
{
WebPage* webPage = obtainOriginatingWebPage(request);
if (webPage && m_applicationSchemes.contains(webPage, request.url().scheme().toLower())) {
QtNetworkReply* reply = new QtNetworkReply(request, this);
webPage->receivedApplicationSchemeRequest(request, reply);
return reply;
if (!m_offline) {
if (webPage && m_applicationSchemes.contains(webPage, request.url().scheme().toLower())) {
QtNetworkReply* reply = new QtNetworkReply(request, this);
webPage->receivedApplicationSchemeRequest(request, reply);
return reply;
}
return QNetworkAccessManager::createRequest(operation, request, outData);
} else {
if (webPage) {
webPage->send(Messages::WebPageProxy::NetworkRequestIgnored());
}
// Return empty reply if offline mode is enabled
QtNetworkReply* reply = new QtNetworkReply(QNetworkRequest(QUrl(QLatin1String(""))),this);
return reply;
}

return QNetworkAccessManager::createRequest(operation, request, outData);
}

void QtNetworkAccessManager::registerApplicationScheme(const WebPage* page, const QString& scheme)
{
m_applicationSchemes.insert(page, scheme.toLower());
}

void QtNetworkAccessManager::setOffline(bool state, qulonglong pageId)
{
WebPage* webPage = m_webProcess->webPage(pageId);

if (!webPage)
return;

m_offline = state;
webPage->send(Messages::WebPageProxy::OfflineChanged(m_offline));
}

void QtNetworkAccessManager::onProxyAuthenticationRequired(const QNetworkProxy& proxy, QAuthenticator* authenticator)
{
// FIXME: Check if there is a better way to get a reference to the page.
Expand Down
Expand Up @@ -42,6 +42,7 @@ class QtNetworkAccessManager : public QNetworkAccessManager {
public:
QtNetworkAccessManager(WebProcess*);
void registerApplicationScheme(const WebPage*, const QString& scheme);
void setOffline(bool state, qulonglong pageId);

protected:
virtual QNetworkReply* createRequest(Operation, const QNetworkRequest&, QIODevice* outgoingData = 0) OVERRIDE;
Expand All @@ -56,6 +57,7 @@ private Q_SLOTS:

QMultiHash<const WebPage*, QString> m_applicationSchemes;
WebProcess* m_webProcess;
bool m_offline;

};

Expand Down
2 changes: 1 addition & 1 deletion rpm/qtwebkit5.spec
Expand Up @@ -3,7 +3,7 @@

Name: qt5-qtwebkit
Summary: Web content engine library for Qt
Version: 5.1.0
Version: 5.1.0+git13
Release: 1%{?dist}
Group: Qt/Qt
License: BSD and LGPLv2+
Expand Down

0 comments on commit e2aaca3

Please sign in to comment.