[GTK] [WK2] Add javascript clipboard functionality settings to WebKit2 GTK+ API.
authormrobinson@webkit.org <mrobinson@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 20 Mar 2012 15:38:40 +0000 (15:38 +0000)
committermrobinson@webkit.org <mrobinson@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 20 Mar 2012 15:38:40 +0000 (15:38 +0000)
https://bugs.webkit.org/show_bug.cgi?id=80981

Patch by Antaryami Pandia <antaryami.pandia@motorola.com> on 2012-03-20
Reviewed by Martin Robinson.

Add WebSettings to enable/disable javascript clipboard functionality.

* UIProcess/API/gtk/WebKitSettings.cpp:
(webKitSettingsSetProperty):
(webKitSettingsGetProperty):
(webkit_settings_class_init):
(webkit_settings_get_javascript_can_access_clipboard):
(webkit_settings_set_javascript_can_access_clipboard):
* UIProcess/API/gtk/WebKitSettings.h:
* UIProcess/API/gtk/docs/webkit2gtk-sections.txt:
* UIProcess/API/gtk/tests/TestWebKitSettings.cpp:
(testWebKitSettings):

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

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/gtk/WebKitSettings.cpp
Source/WebKit2/UIProcess/API/gtk/WebKitSettings.h
Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt
Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitSettings.cpp

index 422c364..9c4abc2 100644 (file)
@@ -1,3 +1,23 @@
+2012-03-20  Antaryami Pandia  <antaryami.pandia@motorola.com>
+
+        [GTK] [WK2] Add javascript clipboard functionality settings to WebKit2 GTK+ API.
+        https://bugs.webkit.org/show_bug.cgi?id=80981
+
+        Reviewed by Martin Robinson.
+
+        Add WebSettings to enable/disable javascript clipboard functionality.
+
+        * UIProcess/API/gtk/WebKitSettings.cpp:
+        (webKitSettingsSetProperty):
+        (webKitSettingsGetProperty):
+        (webkit_settings_class_init):
+        (webkit_settings_get_javascript_can_access_clipboard):
+        (webkit_settings_set_javascript_can_access_clipboard):
+        * UIProcess/API/gtk/WebKitSettings.h:
+        * UIProcess/API/gtk/docs/webkit2gtk-sections.txt:
+        * UIProcess/API/gtk/tests/TestWebKitSettings.cpp:
+        (testWebKitSettings):
+
 2012-03-19  Adam Barth  <abarth@webkit.org>
 
         Remove support for "magic" iframe
index b4b267d..8bec722 100644 (file)
@@ -105,7 +105,8 @@ enum {
     PROP_PRINT_BACKGROUNDS,
     PROP_ENABLE_WEBAUDIO,
     PROP_ENABLE_WEBGL,
-    PROP_ZOOM_TEXT_ONLY
+    PROP_ZOOM_TEXT_ONLY,
+    PROP_JAVASCRIPT_CAN_ACCESS_CLIPBOARD
 };
 
 static void webKitSettingsSetProperty(GObject* object, guint propId, const GValue* value, GParamSpec* paramSpec)
@@ -215,6 +216,9 @@ static void webKitSettingsSetProperty(GObject* object, guint propId, const GValu
     case PROP_ZOOM_TEXT_ONLY:
         webkit_settings_set_zoom_text_only(settings, g_value_get_boolean(value));
         break;
+    case PROP_JAVASCRIPT_CAN_ACCESS_CLIPBOARD:
+        webkit_settings_set_javascript_can_access_clipboard(settings, g_value_get_boolean(value));
+        break;
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec);
         break;
@@ -328,6 +332,9 @@ static void webKitSettingsGetProperty(GObject* object, guint propId, GValue* val
     case PROP_ZOOM_TEXT_ONLY:
         g_value_set_boolean(value, webkit_settings_get_zoom_text_only(settings));
         break;
+    case PROP_JAVASCRIPT_CAN_ACCESS_CLIPBOARD:
+        g_value_set_boolean(value, webkit_settings_get_javascript_can_access_clipboard(settings));
+        break;
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec);
         break;
@@ -840,6 +847,21 @@ static void webkit_settings_class_init(WebKitSettingsClass* klass)
                                                          FALSE,
                                                          readWriteConstructParamFlags));
 
+    /**
+     * WebKitSettings:javascript-can-access-clipboard:
+     *
+     * Whether JavaScript can access the clipboard. The default value is %FALSE. If
+     * set to %TRUE, document.execCommand() allows cut, copy and paste commands.
+     *
+     */
+    g_object_class_install_property(gObjectClass,
+                                    PROP_JAVASCRIPT_CAN_ACCESS_CLIPBOARD,
+                                    g_param_spec_boolean("javascript-can-access-clipboard",
+                                                         _("JavaScript can access clipboard"),
+                                                         _("Whether JavaScript can access Clipboard"),
+                                                         FALSE,
+                                                         readWriteConstructParamFlags));
+
     g_type_class_add_private(klass, sizeof(WebKitSettingsPrivate));
 }
 
@@ -2133,3 +2155,41 @@ gboolean webkit_settings_get_zoom_text_only(WebKitSettings* settings)
     return settings->priv->zoomTextOnly;
 }
 
+/**
+ * webkit_settings_get_javascript_can_access_clipboard:
+ * @settings: a #WebKitSettings
+ *
+ * Get the #WebKitSettings:javascript-can-access-clipboard property.
+ *
+ * Returns: %TRUE If javascript-can-access-clipboard is enabled or %FALSE otherwise.
+ */
+gboolean webkit_settings_get_javascript_can_access_clipboard(WebKitSettings* settings)
+{
+    g_return_val_if_fail(WEBKIT_IS_SETTINGS(settings), FALSE);
+
+    return WKPreferencesGetJavaScriptCanAccessClipboard(settings->priv->preferences.get())
+            && WKPreferencesGetDOMPasteAllowed(settings->priv->preferences.get());
+}
+
+/**
+ * webkit_settings_set_javascript_can_access_clipboard:
+ * @settings: a #WebKitSettings
+ * @enabled: Value to be set
+ *
+ * Set the #WebKitSettings:javascript-can-access-clipboard property.
+ */
+void webkit_settings_set_javascript_can_access_clipboard(WebKitSettings* settings, gboolean enabled)
+{
+    g_return_if_fail(WEBKIT_IS_SETTINGS(settings));
+
+    WebKitSettingsPrivate* priv = settings->priv;
+    bool currentValue = WKPreferencesGetJavaScriptCanAccessClipboard(priv->preferences.get())
+            && WKPreferencesGetDOMPasteAllowed(priv->preferences.get());
+    if (currentValue == enabled)
+        return;
+
+    WKPreferencesSetJavaScriptCanAccessClipboard(priv->preferences.get(), enabled);
+    WKPreferencesSetDOMPasteAllowed(priv->preferences.get(), enabled);
+
+    g_object_notify(G_OBJECT(settings), "javascript-can-access-clipboard");
+}
index 25a78ac..57bf3f1 100644 (file)
@@ -314,6 +314,13 @@ webkit_settings_set_zoom_text_only                             (WebKitSettings *
 WEBKIT_API gboolean
 webkit_settings_get_zoom_text_only                             (WebKitSettings *settings);
 
+WEBKIT_API gboolean
+webkit_settings_get_javascript_can_access_clipboard            (WebKitSettings *settings);
+
+WEBKIT_API void
+webkit_settings_set_javascript_can_access_clipboard            (WebKitSettings *settings,
+                                                                gboolean        enabled);
+
 G_END_DECLS
 
 #endif /* WebKitSettings_h */
index ddacf8d..d33f8ae 100644 (file)
@@ -232,6 +232,8 @@ webkit_settings_get_enable_webgl
 webkit_settings_set_enable_webgl
 webkit_settings_get_zoom_text_only
 webkit_settings_set_zoom_text_only
+webkit_settings_get_javascript_can_access_clipboard
+webkit_settings_set_javascript_can_access_clipboard
 
 <SUBSECTION Standard>
 WebKitSettingsClass
index 03c5f2f..c66a05e 100644 (file)
@@ -204,6 +204,11 @@ static void testWebKitSettings(Test*, gconstpointer)
     webkit_settings_set_zoom_text_only(settings, TRUE);
     g_assert(webkit_settings_get_zoom_text_only(settings));
 
+    // By default, JavaScript cannot access the clipboard.
+    g_assert(!webkit_settings_get_javascript_can_access_clipboard(settings));
+    webkit_settings_set_javascript_can_access_clipboard(settings, TRUE);
+    g_assert(webkit_settings_get_javascript_can_access_clipboard(settings));
+
     g_object_unref(G_OBJECT(settings));
 }