Diff
Modified: trunk/Source/WebKit2/ChangeLog (183991 => 183992)
--- trunk/Source/WebKit2/ChangeLog 2015-05-08 10:44:06 UTC (rev 183991)
+++ trunk/Source/WebKit2/ChangeLog 2015-05-08 11:53:56 UTC (rev 183992)
@@ -1,3 +1,22 @@
+2015-05-08 Carlos Garcia Campos <[email protected]>
+
+ [GTK] Expose allowFileAccessFromFileURLs setting to WebKit2 GTK+ API
+ https://bugs.webkit.org/show_bug.cgi?id=144748
+
+ Reviewed by Sergio Villar Senin.
+
+ This is needed by local applications loaded as a file URI that do XMLHttpRequests.
+
+ * UIProcess/API/gtk/WebKitSettings.cpp:
+ (webKitSettingsSetProperty):
+ (webKitSettingsGetProperty):
+ (webkit_settings_class_init):
+ (webkit_settings_get_allow_file_access_from_file_urls):
+ (webkit_settings_set_allow_file_access_from_file_urls):
+ * UIProcess/API/gtk/WebKitSettings.h:
+ * UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt:
+ * UIProcess/API/gtk/docs/webkit2gtk-docs.sgml:
+
2015-05-08 Andreas Kling <[email protected]>
Optimize serialization of quoted JSON strings.
Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitSettings.cpp (183991 => 183992)
--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitSettings.cpp 2015-05-08 10:44:06 UTC (rev 183991)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitSettings.cpp 2015-05-08 11:53:56 UTC (rev 183992)
@@ -143,7 +143,8 @@
PROP_ENABLE_WRITE_CONSOLE_MESSAGES_TO_STDOUT,
PROP_ENABLE_MEDIA_STREAM,
PROP_ENABLE_SPATIAL_NAVIGATION,
- PROP_ENABLE_MEDIASOURCE
+ PROP_ENABLE_MEDIASOURCE,
+ PROP_ALLOW_FILE_ACCESS_FROM_FILE_URLS
};
static void webKitSettingsConstructed(GObject* object)
@@ -309,6 +310,9 @@
case PROP_ENABLE_MEDIASOURCE:
webkit_settings_set_enable_mediasource(settings, g_value_get_boolean(value));
break;
+ case PROP_ALLOW_FILE_ACCESS_FROM_FILE_URLS:
+ webkit_settings_set_allow_file_access_from_file_urls(settings, g_value_get_boolean(value));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec);
break;
@@ -464,7 +468,9 @@
case PROP_ENABLE_MEDIASOURCE:
g_value_set_boolean(value, webkit_settings_get_enable_mediasource(settings));
break;
-
+ case PROP_ALLOW_FILE_ACCESS_FROM_FILE_URLS:
+ g_value_set_boolean(value, webkit_settings_get_allow_file_access_from_file_urls(settings));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec);
break;
@@ -1217,6 +1223,25 @@
_("Whether MediaSource should be enabled."),
FALSE,
readWriteConstructParamFlags));
+
+ /**
+ * WebKitSettings:allow-file-access-from-file-urls:
+ *
+ * Whether file access is allowed from file URLs. By default, when
+ * something is loaded in a #WebKitWebView using a file URI, cross
+ * origin requests to other file resources are not allowed. This
+ * setting allows you to change that behaviour, so that it would be
+ * possible to do a XMLHttpRequest of a local file, for example.
+ *
+ * Since: 2.10
+ */
+ g_object_class_install_property(gObjectClass,
+ PROP_ALLOW_FILE_ACCESS_FROM_FILE_URLS,
+ g_param_spec_boolean("allow-file-access-from-file-urls",
+ _("Allow file access from file URLs"),
+ _("Whether file access is allowed from file URLs."),
+ FALSE,
+ readWriteConstructParamFlags));
}
WebPreferences* webkitSettingsGetPreferences(WebKitSettings* settings)
@@ -2999,3 +3024,41 @@
priv->preferences->setMediaSourceEnabled(enabled);
g_object_notify(G_OBJECT(settings), "enable-mediasource");
}
+
+/**
+ * webkit_settings_get_allow_file_access_from_file_urls:
+ * @settings: a #WebKitSettings
+ *
+ * Get the #WebKitSettings:allow-file-access-from-file-urls property.
+ *
+ * Returns: %TRUE If file access from file URLs is allowed or %FALSE otherwise.
+ *
+ * Since: 2.10
+ */
+gboolean webkit_settings_get_allow_file_access_from_file_urls(WebKitSettings* settings)
+{
+ g_return_val_if_fail(WEBKIT_IS_SETTINGS(settings), FALSE);
+
+ return settings->priv->preferences->allowFileAccessFromFileURLs();
+}
+
+/**
+ * webkit_settings_set_allow_file_access_from_file_urls:
+ * @settings: a #WebKitSettings
+ * @allowed: Value to be set
+ *
+ * Set the #WebKitSettings:allow-file-access-from-file-urls property.
+ *
+ * Since: 2.10
+ */
+void webkit_settings_set_allow_file_access_from_file_urls(WebKitSettings* settings, gboolean allowed)
+{
+ g_return_if_fail(WEBKIT_IS_SETTINGS(settings));
+
+ WebKitSettingsPrivate* priv = settings->priv;
+ if (priv->preferences->allowFileAccessFromFileURLs() == allowed)
+ return;
+
+ priv->preferences->setAllowFileAccessFromFileURLs(allowed);
+ g_object_notify(G_OBJECT(settings), "allow-file-access-from-file-urls");
+}
Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitSettings.h (183991 => 183992)
--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitSettings.h 2015-05-08 10:44:06 UTC (rev 183991)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitSettings.h 2015-05-08 11:53:56 UTC (rev 183992)
@@ -414,6 +414,13 @@
webkit_settings_set_enable_mediasource (WebKitSettings *settings,
gboolean enabled);
+WEBKIT_API gboolean
+webkit_settings_get_allow_file_access_from_file_urls (WebKitSettings *settings);
+
+WEBKIT_API void
+webkit_settings_set_allow_file_access_from_file_urls (WebKitSettings *settings,
+ gboolean allowed);
+
G_END_DECLS
#endif /* WebKitSettings_h */
Modified: trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt (183991 => 183992)
--- trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt 2015-05-08 10:44:06 UTC (rev 183991)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt 2015-05-08 11:53:56 UTC (rev 183992)
@@ -431,6 +431,8 @@
webkit_settings_set_enable_spatial_navigation
webkit_settings_get_enable_mediasource
webkit_settings_set_enable_mediasource
+webkit_settings_get_allow_file_access_from_file_urls
+webkit_settings_set_allow_file_access_from_file_urls
<SUBSECTION Standard>
WebKitSettingsClass
Modified: trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-docs.sgml (183991 => 183992)
--- trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-docs.sgml 2015-05-08 10:44:06 UTC (rev 183991)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-docs.sgml 2015-05-08 11:53:56 UTC (rev 183992)
@@ -89,5 +89,10 @@
<xi:include href="" /></xi:include>
</index>
+ <index id="api-index-2-10" role="2.10">
+ <title>Index of new symbols in 2.10</title>
+ <xi:include href="" /></xi:include>
+ </index>
+
<xi:include href="" /></xi:include>
</book>
Modified: trunk/Tools/ChangeLog (183991 => 183992)
--- trunk/Tools/ChangeLog 2015-05-08 10:44:06 UTC (rev 183991)
+++ trunk/Tools/ChangeLog 2015-05-08 11:53:56 UTC (rev 183992)
@@ -1,3 +1,18 @@
+2015-05-08 Carlos Garcia Campos <[email protected]>
+
+ [GTK] Expose allowFileAccessFromFileURLs setting to WebKit2 GTK+ API
+ https://bugs.webkit.org/show_bug.cgi?id=144748
+
+ Reviewed by Sergio Villar Senin.
+
+ * TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitSettings.cpp:
+ (testWebKitSettings): Check the new setting is correctly
+ initialized and updated.
+ * TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitWebContext.cpp:
+ (testWebContextSecurityFileXHR): Check XHR to local files is
+ allowed from file URLs after changing the setting.
+ (beforeAll): Add new test.
+
2015-05-08 Commit Queue <[email protected]>
Unreviewed, rolling out r183945.
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitSettings.cpp (183991 => 183992)
--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitSettings.cpp 2015-05-08 10:44:06 UTC (rev 183991)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitSettings.cpp 2015-05-08 11:53:56 UTC (rev 183992)
@@ -273,6 +273,11 @@
webkit_settings_set_enable_mediasource(settings, TRUE);
g_assert(webkit_settings_get_enable_mediasource(settings));
+ // File access from file URLs is not allowed by default.
+ g_assert(!webkit_settings_get_allow_file_access_from_file_urls(settings));
+ webkit_settings_set_allow_file_access_from_file_urls(settings, TRUE);
+ g_assert(webkit_settings_get_allow_file_access_from_file_urls(settings));
+
g_object_unref(G_OBJECT(settings));
}
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitWebContext.cpp (183991 => 183992)
--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitWebContext.cpp 2015-05-08 10:44:06 UTC (rev 183991)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitWebContext.cpp 2015-05-08 11:53:56 UTC (rev 183992)
@@ -411,6 +411,39 @@
| SecurityPolicyTest::CORSEnabled | SecurityPolicyTest::EmptyDocument);
}
+static void testWebContextSecurityFileXHR(WebViewTest* test, gconstpointer)
+{
+ GUniquePtr<char> fileURL(g_strdup_printf("file://%s/simple.html", Test::getResourcesDir(Test::WebKit2Resources).data()));
+ test->loadURI(fileURL.get());
+ test->waitUntilLoadFinished();
+
+ GUniquePtr<char> jsonURL(g_strdup_printf("file://%s/simple.json", Test::getResourcesDir().data()));
+ GUniquePtr<char> xhr(g_strdup_printf("var xhr = new XMLHttpRequest; xhr.open(\"GET\", \"%s\"); xhr.send();", jsonURL.get()));
+
+ // By default file access is not allowed, this will fail with a cross-origin error.
+ GUniqueOutPtr<GError> error;
+ WebKitJavascriptResult* _javascript_Result = test->runJavaScriptAndWaitUntilFinished(xhr.get(), &error.outPtr());
+ g_assert(!_javascript_Result);
+ g_assert_error(error.get(), WEBKIT_JAVASCRIPT_ERROR, WEBKIT_JAVASCRIPT_ERROR_SCRIPT_FAILED);
+
+ // Allow file access from file URLs.
+ webkit_settings_set_allow_file_access_from_file_urls(webkit_web_view_get_settings(test->m_webView), TRUE);
+ test->loadURI(fileURL.get());
+ test->waitUntilLoadFinished();
+ _javascript_Result = test->runJavaScriptAndWaitUntilFinished(xhr.get(), &error.outPtr());
+ g_assert(_javascript_Result);
+ g_assert(!error);
+
+ // It isn't still possible to load file from an HTTP URL.
+ test->loadURI(kServer->getURIForPath("/").data());
+ test->waitUntilLoadFinished();
+ _javascript_Result = test->runJavaScriptAndWaitUntilFinished(xhr.get(), &error.outPtr());
+ g_assert(!_javascript_Result);
+ g_assert_error(error.get(), WEBKIT_JAVASCRIPT_ERROR, WEBKIT_JAVASCRIPT_ERROR_SCRIPT_FAILED);
+
+ webkit_settings_set_allow_file_access_from_file_urls(webkit_web_view_get_settings(test->m_webView), FALSE);
+}
+
void beforeAll()
{
kServer = new WebKitTestServer();
@@ -423,6 +456,7 @@
Test::add("WebKitWebContext", "spell-checker", testWebContextSpellChecker);
WebViewTest::add("WebKitWebContext", "languages", testWebContextLanguages);
SecurityPolicyTest::add("WebKitSecurityManager", "security-policy", testWebContextSecurityPolicy);
+ WebViewTest::add("WebKitSecurityManager", "file-xhr", testWebContextSecurityFileXHR);
}
void afterAll()