[Qt][WK2] Replace use of WebPreferences with use of WKPrefences C API
authormichael.bruning@digia.com <michael.bruning@digia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 27 Feb 2013 11:40:36 +0000 (11:40 +0000)
committermichael.bruning@digia.com <michael.bruning@digia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 27 Feb 2013 11:40:36 +0000 (11:40 +0000)
https://bugs.webkit.org/show_bug.cgi?id=108952

Reviewed by Simon Hausmann.

Signed off for WebKit2 by Benjamin Poulain.

This patch moves the view classes and preferences in the Qt API
to use the C API for accessing and manipulating preferences as
part of the cleanup and move towards using the C API as base for
the Qt WebKit2 API.

Adds the function WebKit::adoptToQString for convenience when
dealing with QString and copied String objects.

Removes the ScrollAnimatorEnabled options from QWebPreferences.

* UIProcess/API/cpp/qt/WKStringQt.cpp:
(WebKit::adoptToQString):
* UIProcess/API/cpp/qt/WKStringQt.h:
(WebKit):
* UIProcess/API/qt/qquickwebview.cpp:
(QQuickWebViewPrivate::initialize):
* UIProcess/API/qt/qwebpreferences.cpp:
(QWebPreferencesPrivate::testAttribute):
(QWebPreferencesPrivate::setAttribute):
(QWebPreferencesPrivate::setFontFamily):
(QWebPreferencesPrivate::fontFamily):
(QWebPreferencesPrivate::setFontSize):
(QWebPreferencesPrivate::fontSize):
* UIProcess/API/qt/qwebpreferences_p.h:
* UIProcess/API/qt/qwebpreferences_p_p.h:

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

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/cpp/qt/WKStringQt.cpp
Source/WebKit2/UIProcess/API/cpp/qt/WKStringQt.h
Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp
Source/WebKit2/UIProcess/API/qt/qwebpreferences.cpp
Source/WebKit2/UIProcess/API/qt/qwebpreferences_p.h
Source/WebKit2/UIProcess/API/qt/qwebpreferences_p_p.h

index ff4c42b..4539d7a 100644 (file)
@@ -1,3 +1,38 @@
+2013-02-27  Michael BrĂ¼ning  <michael.bruning@digia.com>
+
+        [Qt][WK2] Replace use of WebPreferences with use of WKPrefences C API
+        https://bugs.webkit.org/show_bug.cgi?id=108952
+
+        Reviewed by Simon Hausmann.
+
+        Signed off for WebKit2 by Benjamin Poulain.
+
+        This patch moves the view classes and preferences in the Qt API
+        to use the C API for accessing and manipulating preferences as
+        part of the cleanup and move towards using the C API as base for
+        the Qt WebKit2 API.
+
+        Adds the function WebKit::adoptToQString for convenience when
+        dealing with QString and copied String objects.
+
+        Removes the ScrollAnimatorEnabled options from QWebPreferences.
+
+        * UIProcess/API/cpp/qt/WKStringQt.cpp:
+        (WebKit::adoptToQString):
+        * UIProcess/API/cpp/qt/WKStringQt.h:
+        (WebKit):
+        * UIProcess/API/qt/qquickwebview.cpp:
+        (QQuickWebViewPrivate::initialize):
+        * UIProcess/API/qt/qwebpreferences.cpp:
+        (QWebPreferencesPrivate::testAttribute):
+        (QWebPreferencesPrivate::setAttribute):
+        (QWebPreferencesPrivate::setFontFamily):
+        (QWebPreferencesPrivate::fontFamily):
+        (QWebPreferencesPrivate::setFontSize):
+        (QWebPreferencesPrivate::fontSize):
+        * UIProcess/API/qt/qwebpreferences_p.h:
+        * UIProcess/API/qt/qwebpreferences_p_p.h:
+
 2013-02-26  Anders Carlsson  <andersca@apple.com>
 
         Implement StorageAreaProxy::getItem and StorageAreaProxy::setItem
index f2f1883..4ae448e 100644 (file)
@@ -22,6 +22,7 @@
 #include "WKStringQt.h"
 
 #include "WKAPICast.h"
+#include "WKRetainPtr.h"
 #include <QString>
 #include <wtf/RefPtr.h>
 #include <wtf/text/WTFString.h>
@@ -41,3 +42,10 @@ QString WKStringCopyQString(WKStringRef stringRef)
     const WTF::String& string = toImpl(stringRef)->string();
     return QString(reinterpret_cast<const QChar*>(string.characters()), string.length());
 }
+
+namespace WebKit {
+QString adoptToQString(WKStringRef stringRef)
+{
+    return WKStringCopyQString(adoptWK(stringRef).get());
+}
+} /* namespace WebKit */
index cc46e42..ff2cfa8 100644 (file)
@@ -27,4 +27,9 @@
 WK_EXPORT WKStringRef WKStringCreateWithQString(const QString& string);
 WK_EXPORT QString WKStringCopyQString(WKStringRef string);
 
+namespace WebKit {
+QString adoptToQString(WKStringRef);
+} /* namespace WebKit */
+
+using WebKit::adoptToQString;
 #endif /* WKStringQt_h */
index 7973f98..66cb83c 100644 (file)
@@ -65,6 +65,7 @@
 #include <QtQuick/QQuickView>
 #include <WKOpenPanelResultListener.h>
 #include <WKPageGroup.h>
+#include <WKPreferences.h>
 #include <WKSerializedScriptValue.h>
 #include <WKString.h>
 #include <WKStringQt.h>
@@ -357,13 +358,14 @@ void QQuickWebViewPrivate::initialize(WKContextRef contextRef, WKPageGroupRef pa
     QObject::connect(iconDatabase, SIGNAL(iconChangedForPageURL(QString)), q_ptr, SLOT(_q_onIconChangedForPageURL(QString)));
 
     // Any page setting should preferrable be set before creating the page.
-    webPageProxy->pageGroup()->preferences()->setAcceleratedCompositingEnabled(true);
-    webPageProxy->pageGroup()->preferences()->setForceCompositingMode(true);
+    WKPreferencesRef preferencesRef = WKPageGroupGetPreferences(pageGroup.get());
+    WKPreferencesSetAcceleratedCompositingEnabled(preferencesRef, true);
     bool showDebugVisuals = qgetenv("WEBKIT_SHOW_COMPOSITING_DEBUG_VISUALS") == "1";
-    webPageProxy->pageGroup()->preferences()->setCompositingBordersVisible(showDebugVisuals);
-    webPageProxy->pageGroup()->preferences()->setCompositingRepaintCountersVisible(showDebugVisuals);
-    webPageProxy->pageGroup()->preferences()->setFrameFlatteningEnabled(true);
-    webPageProxy->pageGroup()->preferences()->setWebGLEnabled(true);
+    WKPreferencesSetCompositingBordersVisible(preferencesRef, showDebugVisuals);
+    WKPreferencesSetCompositingRepaintCountersVisible(preferencesRef, showDebugVisuals);
+    WKPreferencesSetFrameFlatteningEnabled(preferencesRef, true);
+    WKPreferencesSetWebGLEnabled(preferencesRef, true);
+    webPageProxy->pageGroup()->preferences()->setForceCompositingMode(true);
 
     pageClient.initialize(q_ptr, pageViewPrivate->eventHandler.data(), &undoController);
     webPageProxy->initializeWebPage();
index 7ddfd92..6d2cac1 100644 (file)
 #include "config.h"
 #include "qwebpreferences_p.h"
 
-#include "WebPageGroup.h"
-#include "WebPageProxy.h"
 #include "qquickwebview_p_p.h"
 #include "qwebpreferences_p_p.h"
+#include <WKPageGroup.h>
+#include <WKPreferences.h>
+#include <WKRetainPtr.h>
+#include <WKStringQt.h>
 
 QWebPreferences* QWebPreferencesPrivate::createPreferences(QQuickWebViewPrivate* webViewPrivate)
 {
@@ -35,51 +37,48 @@ QWebPreferences* QWebPreferencesPrivate::createPreferences(QQuickWebViewPrivate*
 
 bool QWebPreferencesPrivate::testAttribute(QWebPreferencesPrivate::WebAttribute attr) const
 {
+    WKPreferencesRef preferencesRef = WKPageGroupGetPreferences(webViewPrivate->pageGroup.get());
     switch (attr) {
     case AutoLoadImages:
-        return preferences()->loadsImagesAutomatically();
+        return WKPreferencesGetLoadsImagesAutomatically(preferencesRef);
 #if ENABLE(FULLSCREEN_API)
     case FullScreenEnabled:
-        return preferences()->fullScreenEnabled();
+        return WKPreferencesGetFullScreenEnabled(preferencesRef);
 #endif
     case JavascriptEnabled:
-        return preferences()->javaScriptEnabled();
+        return WKPreferencesGetJavaScriptEnabled(preferencesRef);
     case PluginsEnabled:
-        return preferences()->pluginsEnabled();
+        return WKPreferencesGetPluginsEnabled(preferencesRef);
     case OfflineWebApplicationCacheEnabled:
-        return preferences()->offlineWebApplicationCacheEnabled();
+        return WKPreferencesGetOfflineWebApplicationCacheEnabled(preferencesRef);
     case LocalStorageEnabled:
-        return preferences()->localStorageEnabled();
+        return WKPreferencesGetLocalStorageEnabled(preferencesRef);
     case XSSAuditingEnabled:
-        return preferences()->xssAuditorEnabled();
+        return WKPreferencesGetXSSAuditorEnabled(preferencesRef);
     case PrivateBrowsingEnabled:
-        return preferences()->privateBrowsingEnabled();
+        return WKPreferencesGetPrivateBrowsingEnabled(preferencesRef);
     case DnsPrefetchEnabled:
-        return preferences()->dnsPrefetchingEnabled();
+        return WKPreferencesGetDNSPrefetchingEnabled(preferencesRef);
     case FrameFlatteningEnabled:
-        return preferences()->frameFlatteningEnabled();
+        return WKPreferencesGetFrameFlatteningEnabled(preferencesRef);
     case DeveloperExtrasEnabled:
-        return preferences()->developerExtrasEnabled();
+        return WKPreferencesGetDeveloperExtrasEnabled(preferencesRef);
 #if ENABLE(WEBGL)
     case WebGLEnabled:
-        return preferences()->webGLEnabled();
+        return WKPreferencesGetWebGLEnabled(preferencesRef);
 #if ENABLE(CSS_SHADERS)
     case CSSCustomFilterEnabled:
-        return preferences()->cssCustomFilterEnabled();
+        return WKPreferencesGetCSSCustomFilterEnabled(preferencesRef);
 #endif
 #endif
 #if ENABLE(WEB_AUDIO)
     case WebAudioEnabled:
-        return preferences()->webAudioEnabled();
-#endif
-#if ENABLE(SMOOTH_SCROLLING)
-    case ScrollAnimatorEnabled:
-        return preferences()->scrollAnimatorEnabled();
+        return WKPreferencesGetWebAudioEnabled(preferencesRef);
 #endif
     case CaretBrowsingEnabled:
-        return preferences()->caretBrowsingEnabled();
+        return WKPreferencesGetCaretBrowsingEnabled(preferencesRef);
     case NotificationsEnabled:
-        return preferences()->notificationsEnabled();
+        return WKPreferencesGetNotificationsEnabled(preferencesRef);
     default:
         ASSERT_NOT_REACHED();
         return false;
@@ -88,67 +87,63 @@ bool QWebPreferencesPrivate::testAttribute(QWebPreferencesPrivate::WebAttribute
 
 void QWebPreferencesPrivate::setAttribute(QWebPreferencesPrivate::WebAttribute attr, bool enable)
 {
+    WKPreferencesRef preferencesRef = WKPageGroupGetPreferences(webViewPrivate->pageGroup.get());
     switch (attr) {
     case AutoLoadImages:
-        preferences()->setLoadsImagesAutomatically(enable);
+        WKPreferencesSetLoadsImagesAutomatically(preferencesRef, enable);
         break;
 #if ENABLE(FULLSCREEN_API)
     case FullScreenEnabled:
-        preferences()->setFullScreenEnabled(enable);
+        WKPreferencesSetFullScreenEnabled(preferencesRef, enable);
         break;
 #endif
     case JavascriptEnabled:
-        preferences()->setJavaScriptEnabled(enable);
+        WKPreferencesSetJavaScriptEnabled(preferencesRef, enable);
         break;
     case PluginsEnabled:
-        preferences()->setPluginsEnabled(enable);
+        WKPreferencesSetPluginsEnabled(preferencesRef, enable);
         break;
     case OfflineWebApplicationCacheEnabled:
-        preferences()->setOfflineWebApplicationCacheEnabled(enable);
+        WKPreferencesSetOfflineWebApplicationCacheEnabled(preferencesRef, enable);
         break;
     case LocalStorageEnabled:
-        preferences()->setLocalStorageEnabled(enable);
+        WKPreferencesSetLocalStorageEnabled(preferencesRef, enable);
         break;
     case XSSAuditingEnabled:
-        preferences()->setXSSAuditorEnabled(enable);
+        WKPreferencesSetXSSAuditorEnabled(preferencesRef, enable);
         break;
     case PrivateBrowsingEnabled:
-        preferences()->setPrivateBrowsingEnabled(enable);
+        WKPreferencesSetPrivateBrowsingEnabled(preferencesRef, enable);
         break;
     case DnsPrefetchEnabled:
-        preferences()->setDNSPrefetchingEnabled(enable);
+        WKPreferencesSetDNSPrefetchingEnabled(preferencesRef, enable);
         break;
     case FrameFlatteningEnabled:
-        preferences()->setFrameFlatteningEnabled(enable);
+        WKPreferencesSetFrameFlatteningEnabled(preferencesRef, enable);
     case DeveloperExtrasEnabled:
-        preferences()->setDeveloperExtrasEnabled(enable);
+        WKPreferencesSetDeveloperExtrasEnabled(preferencesRef, enable);
         break;
 #if ENABLE(WEBGL)
     case WebGLEnabled:
-        preferences()->setWebGLEnabled(enable);
+        WKPreferencesSetWebGLEnabled(preferencesRef, enable);
         break;
 #if ENABLE(CSS_SHADERS)
     case CSSCustomFilterEnabled:
-        preferences()->setCSSCustomFilterEnabled(enable);
+        WKPreferencesSetCSSCustomFilterEnabled(preferencesRef, enable);
         break;
 #endif
 #endif
 #if ENABLE(WEB_AUDIO)
     case WebAudioEnabled:
-        preferences()->setWebAudioEnabled(enable);
-        break;
-#endif
-#if ENABLE(SMOOTH_SCROLLING)
-    case ScrollAnimatorEnabled:
-        preferences()->setScrollAnimatorEnabled(enable);
+        WKPreferencesSetWebAudioEnabled(preferencesRef, enable);
         break;
 #endif
     case CaretBrowsingEnabled:
         // FIXME: Caret browsing doesn't make much sense in touch mode.
-        preferences()->setCaretBrowsingEnabled(enable);
+        WKPreferencesSetCaretBrowsingEnabled(preferencesRef, enable);
         break;
     case NotificationsEnabled:
-        preferences()->setNotificationsEnabled(enable);
+        WKPreferencesSetNotificationsEnabled(preferencesRef, enable);
         break;
     default:
         ASSERT_NOT_REACHED();
@@ -181,24 +176,26 @@ void QWebPreferencesPrivate::initializeDefaultFontSettings()
 
 void QWebPreferencesPrivate::setFontFamily(QWebPreferencesPrivate::FontFamily which, const QString& family)
 {
+    WKPreferencesRef preferencesRef = WKPageGroupGetPreferences(webViewPrivate->pageGroup.get());
+    WKRetainPtr<WKStringRef> familyRef = adoptWK(WKStringCreateWithQString(family));
     switch (which) {
     case StandardFont:
-        preferences()->setStandardFontFamily(family);
+        WKPreferencesSetStandardFontFamily(preferencesRef, familyRef.get());
         break;
     case FixedFont:
-        preferences()->setFixedFontFamily(family);
+        WKPreferencesSetFixedFontFamily(preferencesRef, familyRef.get());
         break;
     case SerifFont:
-        preferences()->setSerifFontFamily(family);
+        WKPreferencesSetSerifFontFamily(preferencesRef, familyRef.get());
         break;
     case SansSerifFont:
-        preferences()->setSansSerifFontFamily(family);
+        WKPreferencesSetSansSerifFontFamily(preferencesRef, familyRef.get());
         break;
     case CursiveFont:
-        preferences()->setCursiveFontFamily(family);
+        WKPreferencesSetCursiveFontFamily(preferencesRef, familyRef.get());
         break;
     case FantasyFont:
-        preferences()->setFantasyFontFamily(family);
+        WKPreferencesSetFantasyFontFamily(preferencesRef, familyRef.get());
         break;
     default:
         break;
@@ -207,35 +204,37 @@ void QWebPreferencesPrivate::setFontFamily(QWebPreferencesPrivate::FontFamily wh
 
 QString QWebPreferencesPrivate::fontFamily(QWebPreferencesPrivate::FontFamily which) const
 {
+    WKPreferencesRef preferencesRef = WKPageGroupGetPreferences(webViewPrivate->pageGroup.get());
     switch (which) {
     case StandardFont:
-        return preferences()->standardFontFamily();
+        return adoptToQString(WKPreferencesCopyStandardFontFamily(preferencesRef));
     case FixedFont:
-        return preferences()->fixedFontFamily();
+        return adoptToQString(WKPreferencesCopyFixedFontFamily(preferencesRef));
     case SerifFont:
-        return preferences()->serifFontFamily();
+        return adoptToQString(WKPreferencesCopySerifFontFamily(preferencesRef));
     case SansSerifFont:
-        return preferences()->sansSerifFontFamily();
+        return adoptToQString(WKPreferencesCopySansSerifFontFamily(preferencesRef));
     case CursiveFont:
-        return preferences()->cursiveFontFamily();
+        return adoptToQString(WKPreferencesCopyCursiveFontFamily(preferencesRef));
     case FantasyFont:
-        return preferences()->fantasyFontFamily();
+        return adoptToQString(WKPreferencesCopyFantasyFontFamily(preferencesRef));
     default:
         return QString();
     }
 }
 
 void QWebPreferencesPrivate::setFontSize(QWebPreferencesPrivate::FontSizeType type, unsigned size)
-{
+{    
+    WKPreferencesRef preferencesRef = WKPageGroupGetPreferences(webViewPrivate->pageGroup.get());
     switch (type) {
     case MinimumFontSize:
-        preferences()->setMinimumFontSize(size);
+        WKPreferencesSetMinimumFontSize(preferencesRef, static_cast<uint32_t>(size));
         break;
     case DefaultFontSize:
-        preferences()->setDefaultFontSize(size);
+        WKPreferencesSetDefaultFontSize(preferencesRef, static_cast<uint32_t>(size));
         break;
     case DefaultFixedFontSize:
-        preferences()->setDefaultFixedFontSize(size);
+        WKPreferencesSetDefaultFixedFontSize(preferencesRef, static_cast<uint32_t>(size));
         break;
     default:
         ASSERT_NOT_REACHED();
@@ -244,13 +243,14 @@ void QWebPreferencesPrivate::setFontSize(QWebPreferencesPrivate::FontSizeType ty
 
 unsigned QWebPreferencesPrivate::fontSize(QWebPreferencesPrivate::FontSizeType type) const
 {
+    WKPreferencesRef preferencesRef = WKPageGroupGetPreferences(webViewPrivate->pageGroup.get());
     switch (type) {
     case MinimumFontSize:
-        return preferences()->minimumFontSize();
+        return static_cast<unsigned>(WKPreferencesGetMinimumFontSize(preferencesRef));
     case DefaultFontSize:
-        return preferences()->defaultFontSize();
+        return static_cast<unsigned>(WKPreferencesGetDefaultFontSize(preferencesRef));
     case DefaultFixedFontSize:
-        return preferences()->defaultFixedFontSize();
+        return static_cast<unsigned>(WKPreferencesGetDefaultFixedFontSize(preferencesRef));
     default:
         ASSERT_NOT_REACHED();
         return false;
@@ -546,25 +546,6 @@ void QWebPreferences::setWebAudioEnabled(bool enable)
 #endif
 }
 
-bool QWebPreferences::scrollAnimatorEnabled() const
-{
-#if ENABLE(SMOOTH_SCROLLING)
-    return d->testAttribute(QWebPreferencesPrivate::ScrollAnimatorEnabled);
-#else
-    return false;
-#endif
-}
-
-void QWebPreferences::setScrollAnimatorEnabled(bool enable)
-{
-#if ENABLE(SMOOTH_SCROLLING)
-    d->setAttribute(QWebPreferencesPrivate::ScrollAnimatorEnabled, enable);
-    emit scrollAnimatorEnabledChanged();
-#else
-    UNUSED_PARAM(enable);
-#endif
-}
-
 bool QWebPreferences::caretBrowsingEnabled() const
 {
     return d->testAttribute(QWebPreferencesPrivate::CaretBrowsingEnabled);
@@ -587,11 +568,6 @@ void QWebPreferences::setNotificationsEnabled(bool enable)
     emit notificationsEnabledChanged();
 }
 
-WebKit::WebPreferences* QWebPreferencesPrivate::preferences() const
-{
-    return webViewPrivate->webPageProxy->pageGroup()->preferences();
-}
-
 QWebPreferencesPrivate* QWebPreferencesPrivate::get(QWebPreferences* preferences)
 {
     return preferences->d;
index e3fab79..7fc5220 100644 (file)
@@ -45,7 +45,6 @@ public:
     Q_PROPERTY(bool developerExtrasEnabled READ developerExtrasEnabled WRITE setDeveloperExtrasEnabled NOTIFY developerExtrasEnabledChanged FINAL)
     Q_PROPERTY(bool webGLEnabled READ webGLEnabled WRITE setWebGLEnabled NOTIFY webGLEnabledChanged FINAL)
     Q_PROPERTY(bool webAudioEnabled READ webAudioEnabled WRITE setWebAudioEnabled NOTIFY webAudioEnabledChanged FINAL)
-    Q_PROPERTY(bool scrollAnimatorEnabled READ scrollAnimatorEnabled WRITE setScrollAnimatorEnabled NOTIFY scrollAnimatorEnabledChanged FINAL)
     Q_PROPERTY(bool caretBrowsingEnabled READ caretBrowsingEnabled WRITE setCaretBrowsingEnabled NOTIFY caretBrowsingEnabledChanged FINAL)
     Q_PROPERTY(bool notificationsEnabled READ notificationsEnabled WRITE setNotificationsEnabled NOTIFY notificationsEnabledChanged FINAL)
 
@@ -102,9 +101,6 @@ public:
     bool webAudioEnabled() const;
     void setWebAudioEnabled(bool enable);
 
-    bool scrollAnimatorEnabled() const;
-    void setScrollAnimatorEnabled(bool enable);
-
     bool caretBrowsingEnabled() const;
     void setCaretBrowsingEnabled(bool enable);
 
@@ -153,7 +149,6 @@ Q_SIGNALS:
     void developerExtrasEnabledChanged();
     void webGLEnabledChanged();
     void webAudioEnabledChanged();
-    void scrollAnimatorEnabledChanged();
     void caretBrowsingEnabledChanged();
     void notificationsEnabledChanged();
 
index c8098b5..6ee692c 100644 (file)
@@ -20,8 +20,6 @@
 #ifndef qwebpreferences_p_p_h
 #define qwebpreferences_p_p_h
 
-#include "WebPreferences.h"
-
 class QQuickWebViewPrivate;
 
 class QWebPreferencesPrivate {
@@ -42,7 +40,6 @@ public:
         WebGLEnabled,
         CSSCustomFilterEnabled,
         WebAudioEnabled,
-        ScrollAnimatorEnabled,
         CaretBrowsingEnabled,
         NotificationsEnabled
     };
@@ -74,8 +71,6 @@ public:
     void setFontSize(FontSizeType type, unsigned size);
     unsigned fontSize(FontSizeType type) const;
 
-    WebKit::WebPreferences* preferences() const;
-
     QQuickWebViewPrivate* webViewPrivate;
 
     static QWebPreferencesPrivate* get(QWebPreferences*);