[WK2][Qt] Replace WebPageGroup usage for user scripts with WKPageGroupRef
authorhausmann@webkit.org <hausmann@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 4 Feb 2013 12:21:32 +0000 (12:21 +0000)
committerhausmann@webkit.org <hausmann@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 4 Feb 2013 12:21:32 +0000 (12:21 +0000)
https://bugs.webkit.org/show_bug.cgi?id=108651

Reviewed by Sam Weinig.

It's straight-forward port towards the C API.

* UIProcess/API/qt/qquickwebview.cpp:
(QQuickWebViewPrivate::initialize):
(readUserScript):
(QQuickWebViewPrivate::updateUserScripts):
* UIProcess/API/qt/qquickwebview_p_p.h:
(QQuickWebViewPrivate):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@141756 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp
Source/WebKit2/UIProcess/API/qt/qquickwebview_p_p.h

index ee3a9a8..c4854aa 100644 (file)
@@ -1,3 +1,19 @@
+2013-02-04  Simon Hausmann  <simon.hausmann@digia.com>
+
+        [WK2][Qt] Replace WebPageGroup usage for user scripts with WKPageGroupRef
+        https://bugs.webkit.org/show_bug.cgi?id=108651
+
+        Reviewed by Sam Weinig.
+
+        It's straight-forward port towards the C API.
+
+        * UIProcess/API/qt/qquickwebview.cpp:
+        (QQuickWebViewPrivate::initialize):
+        (readUserScript):
+        (QQuickWebViewPrivate::updateUserScripts):
+        * UIProcess/API/qt/qquickwebview_p_p.h:
+        (QQuickWebViewPrivate):
+
 2013-02-04  Balazs Kelemen  <kbalazs@webkit.org>
 
         [Soup] Wrap SoupSession by NetworkStorageSession
index 6f532c2..a6a9d64 100644 (file)
@@ -65,7 +65,9 @@
 #include <QtQml/QJSValue>
 #include <QtQuick/QQuickView>
 #include <WKOpenPanelResultListener.h>
+#include <WKPageGroup.h>
 #include <WKSerializedScriptValue.h>
+#include <WKString.h>
 #include <WebCore/IntPoint.h>
 #include <WebCore/IntRect.h>
 #include <limits>
@@ -295,14 +297,12 @@ QQuickWebViewPrivate::~QQuickWebViewPrivate()
 // Note: we delay this initialization to make sure that QQuickWebView has its d-ptr in-place.
 void QQuickWebViewPrivate::initialize(WKContextRef contextRef, WKPageGroupRef pageGroupRef)
 {
-    RefPtr<WebPageGroup> pageGroup;
-    if (pageGroupRef)
-        pageGroup = toImpl(pageGroupRef);
-    else
-        pageGroup = WebPageGroup::create();
+    pageGroup = pageGroupRef;
+    if (!pageGroup)
+        pageGroup = adoptWK(WKPageGroupCreateWithIdentifier(0));
 
     context = contextRef ? QtWebContext::create(toImpl(contextRef)) : QtWebContext::defaultContext();
-    webPageProxy = context->createWebPage(&pageClient, pageGroup.get());
+    webPageProxy = context->createWebPage(&pageClient, toImpl(pageGroup.get()));
     webPageProxy->setUseFixedLayout(s_flickableViewportEnabled);
 #if ENABLE(FULLSCREEN_API)
     webPageProxy->fullScreenManager()->setWebView(q_ptr);
@@ -737,7 +737,7 @@ void QQuickWebViewPrivate::setNavigatorQtObjectEnabled(bool enabled)
     webPageProxy->postMessageToInjectedBundle(messageName, webEnabled.get());
 }
 
-static QString readUserScript(const QUrl& url)
+static WKRetainPtr<WKStringRef> readUserScript(const QUrl& url)
 {
     QString path;
     if (url.isLocalFile())
@@ -746,28 +746,27 @@ static QString readUserScript(const QUrl& url)
         path = QStringLiteral(":") + url.path();
     else {
         qWarning("QQuickWebView: Couldn't open '%s' as user script because only file:/// and qrc:/// URLs are supported.", qPrintable(url.toString()));
-        return QString();
+        return 0;
     }
 
     QFile file(path);
     if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
         qWarning("QQuickWebView: Couldn't open '%s' as user script due to error '%s'.", qPrintable(url.toString()), qPrintable(file.errorString()));
-        return QString();
+        return 0;
     }
 
-    QString contents = QString::fromUtf8(file.readAll());
+    QByteArray contents = file.readAll();
     if (contents.isEmpty())
         qWarning("QQuickWebView: Ignoring '%s' as user script because file is empty.", qPrintable(url.toString()));
 
-    return contents;
+    return adoptWK(WKStringCreateWithUTF8CString(contents.constData()));
 }
 
 void QQuickWebViewPrivate::updateUserScripts()
 {
     // This feature works per-WebView because we keep an unique page group for
     // each Page/WebView pair we create.
-    WebPageGroup* pageGroup = webPageProxy->pageGroup();
-    pageGroup->removeAllUserScripts();
+    WKPageGroupRemoveAllUserScripts(pageGroup.get());
 
     for (unsigned i = 0; i < userScripts.size(); ++i) {
         const QUrl& url = userScripts.at(i);
@@ -776,10 +775,10 @@ void QQuickWebViewPrivate::updateUserScripts()
             continue;
         }
 
-        QString contents = readUserScript(url);
-        if (contents.isEmpty())
+        WKRetainPtr<WKStringRef> contents = readUserScript(url);
+        if (!contents || WKStringIsEmpty(contents.get()))
             continue;
-        pageGroup->addUserScript(String(contents), emptyString(), 0, 0, InjectInTopFrameOnly, InjectAtDocumentEnd);
+        WKPageGroupAddUserScript(pageGroup.get(), contents.get(), /*baseURL*/ 0, /*whitelistedURLPatterns*/ 0, /*blacklistedURLPatterns*/ 0, kWKInjectInTopFrameOnly, kWKInjectAtDocumentEnd);
     }
 }
 
index a0ca69a..88b28c4 100644 (file)
@@ -33,6 +33,7 @@
 #include <QtCore/QObject>
 #include <QtCore/QScopedPointer>
 #include <WebCore/ViewportArguments.h>
+#include <WebKit2/WKRetainPtr.h>
 #include <wtf/OwnPtr.h>
 #include <wtf/RefPtr.h>
 
@@ -161,6 +162,7 @@ protected:
     QQuickWebViewPrivate(QQuickWebView* viewport);
     RefPtr<WebKit::QtWebContext> context;
     RefPtr<WebKit::WebPageProxy> webPageProxy;
+    WKRetainPtr<WKPageGroupRef> pageGroup;
 
     WebKit::QtPageClient pageClient;
     WebKit::DefaultUndoController undoController;