Skip to content

Commit

Permalink
[qtwebkit] Add support for user specified style sheets
Browse files Browse the repository at this point in the history
  • Loading branch information
Raine Makelainen committed Jun 3, 2014
1 parent 7be4f11 commit 06511c8
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
35 changes: 35 additions & 0 deletions qtwebkit/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp
Expand Up @@ -643,6 +643,7 @@ void QQuickWebViewPrivate::didRelaunchProcess()

updateViewportSize();
updateUserScripts();
updateUserStyleSheet();
updateSchemeDelegates();
}

Expand Down Expand Up @@ -953,6 +954,24 @@ void QQuickWebViewPrivate::updateUserScripts()
}
}

void QQuickWebViewPrivate::updateUserStyleSheet()
{
// This feature works per-WebView because we keep an unique page group for
// each Page/WebView pair we create.
WKPageGroupRemoveAllUserStyleSheets(pageGroup.get());

if (!userStyleSheet.isValid()) {
qWarning("QQuickWebView: Couldn't open '%s' as user style sheet because URL is invalid.", qPrintable(userStyleSheet.toString()));
return;
}

// Name of readUserScript is bad but it is suitable for reading style sheet as well.
WKRetainPtr<WKStringRef> contents = readUserScript(userStyleSheet);
if (contents && !WKStringIsEmpty(contents.get())) {
WKPageGroupAddUserStyleSheet(pageGroup.get(), contents.get(), /*baseURL*/ 0, /*whitelistedURLPatterns*/ 0, /*blacklistedURLPatterns*/ 0, kWKInjectInTopFrameOnly);
}
}

void QQuickWebViewPrivate::updateSchemeDelegates()
{
webPageProxy->registerApplicationScheme(ASCIILiteral("qrc"));
Expand Down Expand Up @@ -1695,6 +1714,22 @@ void QQuickWebViewExperimental::setUserScripts(const QList<QUrl>& userScripts)
emit userScriptsChanged();
}

QUrl QQuickWebViewExperimental::userStyleSheet() const
{
Q_D(const QQuickWebView);
return d->userStyleSheet;
}

void QQuickWebViewExperimental::setUserStyleSheet(const QUrl &userStyleSheet)
{
Q_D(QQuickWebView);
if (d->userStyleSheet == userStyleSheet)
return;
d->userStyleSheet = userStyleSheet;
d->updateUserStyleSheet();
emit userStyleSheetChanged();
}

QUrl QQuickWebViewExperimental::remoteInspectorUrl() const
{
#if ENABLE(INSPECTOR_SERVER)
Expand Down
4 changes: 4 additions & 0 deletions qtwebkit/Source/WebKit2/UIProcess/API/qt/qquickwebview_p.h
Expand Up @@ -287,6 +287,7 @@ class QWEBKIT_EXPORT QQuickWebViewExperimental : public QObject {
Q_PROPERTY(QQmlListProperty<QQuickUrlSchemeDelegate> urlSchemeDelegates READ schemeDelegates)
Q_PROPERTY(QString userAgent READ userAgent WRITE setUserAgent NOTIFY userAgentChanged)
Q_PROPERTY(QList<QUrl> userScripts READ userScripts WRITE setUserScripts NOTIFY userScriptsChanged)
Q_PROPERTY(QUrl userStyleSheet READ userStyleSheet WRITE setUserStyleSheet NOTIFY userStyleSheetChanged)
Q_PROPERTY(QUrl remoteInspectorUrl READ remoteInspectorUrl NOTIFY remoteInspectorUrlChanged FINAL)
Q_ENUMS(NavigationRequestActionExperimental)
Q_FLAGS(FindFlags)
Expand Down Expand Up @@ -338,6 +339,8 @@ class QWEBKIT_EXPORT QQuickWebViewExperimental : public QObject {
void setDeviceHeight(int);
QList<QUrl> userScripts() const;
void setUserScripts(const QList<QUrl>& userScripts);
QUrl userStyleSheet() const;
void setUserStyleSheet(const QUrl& userStyleSheet);
QUrl remoteInspectorUrl() const;

QWebKitTest* test();
Expand Down Expand Up @@ -418,6 +421,7 @@ public Q_SLOTS:
void enterFullScreenRequested();
void exitFullScreenRequested();
void userScriptsChanged();
void userStyleSheetChanged();
void preferredMinimumContentsWidthChanged();
void remoteInspectorUrlChanged();
void autoCorrectChanged();
Expand Down
2 changes: 2 additions & 0 deletions qtwebkit/Source/WebKit2/UIProcess/API/qt/qquickwebview_p_p.h
Expand Up @@ -126,6 +126,7 @@ class QQuickWebViewPrivate {
bool transparentBackground() const;
void setNavigatorQtObjectEnabled(bool);
void updateUserScripts();
void updateUserStyleSheet();
void updateSchemeDelegates();

void setAutoCorrect(bool autoCorrect) { m_autoCorrect = autoCorrect; }
Expand Down Expand Up @@ -223,6 +224,7 @@ class QQuickWebViewPrivate {
QQmlComponent* headerComponent;

QList<QUrl> userScripts;
QUrl userStyleSheet;

bool m_firstFrameRendered;
bool m_betweenLoadCommitAndFirstFrame;
Expand Down

0 comments on commit 06511c8

Please sign in to comment.