⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 183992 in webkit


Ignore:
Timestamp:
May 8, 2015, 4:53:56 AM (11 years ago)
Author:
Carlos Garcia Campos
Message:

[GTK] Expose allowFileAccessFromFileURLs setting to WebKit2 GTK+ API
https://bugs.webkit.org/show_bug.cgi?id=144748

Reviewed by Sergio Villar Senin.

Source/WebKit2:

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:

Tools:

  • 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.

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r183988 r183992  
     12015-05-08  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] Expose allowFileAccessFromFileURLs setting to WebKit2 GTK+ API
     4        https://bugs.webkit.org/show_bug.cgi?id=144748
     5
     6        Reviewed by Sergio Villar Senin.
     7
     8        This is needed by local applications loaded as a file URI that do XMLHttpRequests.
     9
     10        * UIProcess/API/gtk/WebKitSettings.cpp:
     11        (webKitSettingsSetProperty):
     12        (webKitSettingsGetProperty):
     13        (webkit_settings_class_init):
     14        (webkit_settings_get_allow_file_access_from_file_urls):
     15        (webkit_settings_set_allow_file_access_from_file_urls):
     16        * UIProcess/API/gtk/WebKitSettings.h:
     17        * UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt:
     18        * UIProcess/API/gtk/docs/webkit2gtk-docs.sgml:
     19
    1202015-05-08  Andreas Kling  <akling@apple.com>
    221
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitSettings.cpp

    r178095 r183992  
    144144    PROP_ENABLE_MEDIA_STREAM,
    145145    PROP_ENABLE_SPATIAL_NAVIGATION,
    146     PROP_ENABLE_MEDIASOURCE
     146    PROP_ENABLE_MEDIASOURCE,
     147    PROP_ALLOW_FILE_ACCESS_FROM_FILE_URLS
    147148};
    148149
     
    310311        webkit_settings_set_enable_mediasource(settings, g_value_get_boolean(value));
    311312        break;
     313    case PROP_ALLOW_FILE_ACCESS_FROM_FILE_URLS:
     314        webkit_settings_set_allow_file_access_from_file_urls(settings, g_value_get_boolean(value));
     315        break;
    312316    default:
    313317        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec);
     
    465469        g_value_set_boolean(value, webkit_settings_get_enable_mediasource(settings));
    466470        break;
    467 
     471    case PROP_ALLOW_FILE_ACCESS_FROM_FILE_URLS:
     472        g_value_set_boolean(value, webkit_settings_get_allow_file_access_from_file_urls(settings));
     473        break;
    468474    default:
    469475        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec);
     
    12181224            FALSE,
    12191225            readWriteConstructParamFlags));
     1226
     1227    /**
     1228     * WebKitSettings:allow-file-access-from-file-urls:
     1229     *
     1230     * Whether file access is allowed from file URLs. By default, when
     1231     * something is loaded in a #WebKitWebView using a file URI, cross
     1232     * origin requests to other file resources are not allowed. This
     1233     * setting allows you to change that behaviour, so that it would be
     1234     * possible to do a XMLHttpRequest of a local file, for example.
     1235     *
     1236     * Since: 2.10
     1237     */
     1238    g_object_class_install_property(gObjectClass,
     1239        PROP_ALLOW_FILE_ACCESS_FROM_FILE_URLS,
     1240        g_param_spec_boolean("allow-file-access-from-file-urls",
     1241            _("Allow file access from file URLs"),
     1242            _("Whether file access is allowed from file URLs."),
     1243            FALSE,
     1244            readWriteConstructParamFlags));
    12201245}
    12211246
     
    30003025    g_object_notify(G_OBJECT(settings), "enable-mediasource");
    30013026}
     3027
     3028/**
     3029 * webkit_settings_get_allow_file_access_from_file_urls:
     3030 * @settings: a #WebKitSettings
     3031 *
     3032 * Get the #WebKitSettings:allow-file-access-from-file-urls property.
     3033 *
     3034 * Returns: %TRUE If file access from file URLs is allowed or %FALSE otherwise.
     3035 *
     3036 * Since: 2.10
     3037 */
     3038gboolean webkit_settings_get_allow_file_access_from_file_urls(WebKitSettings* settings)
     3039{
     3040    g_return_val_if_fail(WEBKIT_IS_SETTINGS(settings), FALSE);
     3041
     3042    return settings->priv->preferences->allowFileAccessFromFileURLs();
     3043}
     3044
     3045/**
     3046 * webkit_settings_set_allow_file_access_from_file_urls:
     3047 * @settings: a #WebKitSettings
     3048 * @allowed: Value to be set
     3049 *
     3050 * Set the #WebKitSettings:allow-file-access-from-file-urls property.
     3051 *
     3052 * Since: 2.10
     3053 */
     3054void webkit_settings_set_allow_file_access_from_file_urls(WebKitSettings* settings, gboolean allowed)
     3055{
     3056    g_return_if_fail(WEBKIT_IS_SETTINGS(settings));
     3057
     3058    WebKitSettingsPrivate* priv = settings->priv;
     3059    if (priv->preferences->allowFileAccessFromFileURLs() == allowed)
     3060        return;
     3061
     3062    priv->preferences->setAllowFileAccessFromFileURLs(allowed);
     3063    g_object_notify(G_OBJECT(settings), "allow-file-access-from-file-urls");
     3064}
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitSettings.h

    r160434 r183992  
    415415                                                                gboolean        enabled);
    416416
     417WEBKIT_API gboolean
     418webkit_settings_get_allow_file_access_from_file_urls           (WebKitSettings *settings);
     419
     420WEBKIT_API void
     421webkit_settings_set_allow_file_access_from_file_urls           (WebKitSettings *settings,
     422                                                                gboolean        allowed);
     423
    417424G_END_DECLS
    418425
  • trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt

    r179984 r183992  
    432432webkit_settings_get_enable_mediasource
    433433webkit_settings_set_enable_mediasource
     434webkit_settings_get_allow_file_access_from_file_urls
     435webkit_settings_set_allow_file_access_from_file_urls
    434436
    435437<SUBSECTION Standard>
  • trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-docs.sgml

    r181555 r183992  
    9090  </index>
    9191
     92  <index id="api-index-2-10" role="2.10">
     93    <title>Index of new symbols in 2.10</title>
     94    <xi:include href="xml/api-index-2.10.xml"><xi:fallback /></xi:include>
     95  </index>
     96
    9297  <xi:include href="xml/annotation-glossary.xml"><xi:fallback /></xi:include>
    9398</book>
  • trunk/Tools/ChangeLog

    r183986 r183992  
     12015-05-08  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] Expose allowFileAccessFromFileURLs setting to WebKit2 GTK+ API
     4        https://bugs.webkit.org/show_bug.cgi?id=144748
     5
     6        Reviewed by Sergio Villar Senin.
     7
     8        * TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitSettings.cpp:
     9        (testWebKitSettings): Check the new setting is correctly
     10        initialized and updated.
     11        * TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitWebContext.cpp:
     12        (testWebContextSecurityFileXHR): Check XHR to local files is
     13        allowed from file URLs after changing the setting.
     14        (beforeAll): Add new test.
     15
    1162015-05-08  Commit Queue  <commit-queue@webkit.org>
    217
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitSettings.cpp

    r169892 r183992  
    274274    g_assert(webkit_settings_get_enable_mediasource(settings));
    275275
     276    // File access from file URLs is not allowed by default.
     277    g_assert(!webkit_settings_get_allow_file_access_from_file_urls(settings));
     278    webkit_settings_set_allow_file_access_from_file_urls(settings, TRUE);
     279    g_assert(webkit_settings_get_allow_file_access_from_file_urls(settings));
     280
    276281    g_object_unref(G_OBJECT(settings));
    277282}
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitWebContext.cpp

    r176512 r183992  
    412412}
    413413
     414static void testWebContextSecurityFileXHR(WebViewTest* test, gconstpointer)
     415{
     416    GUniquePtr<char> fileURL(g_strdup_printf("file://%s/simple.html", Test::getResourcesDir(Test::WebKit2Resources).data()));
     417    test->loadURI(fileURL.get());
     418    test->waitUntilLoadFinished();
     419
     420    GUniquePtr<char> jsonURL(g_strdup_printf("file://%s/simple.json", Test::getResourcesDir().data()));
     421    GUniquePtr<char> xhr(g_strdup_printf("var xhr = new XMLHttpRequest; xhr.open(\"GET\", \"%s\"); xhr.send();", jsonURL.get()));
     422
     423    // By default file access is not allowed, this will fail with a cross-origin error.
     424    GUniqueOutPtr<GError> error;
     425    WebKitJavascriptResult* javascriptResult = test->runJavaScriptAndWaitUntilFinished(xhr.get(), &error.outPtr());
     426    g_assert(!javascriptResult);
     427    g_assert_error(error.get(), WEBKIT_JAVASCRIPT_ERROR, WEBKIT_JAVASCRIPT_ERROR_SCRIPT_FAILED);
     428
     429    // Allow file access from file URLs.
     430    webkit_settings_set_allow_file_access_from_file_urls(webkit_web_view_get_settings(test->m_webView), TRUE);
     431    test->loadURI(fileURL.get());
     432    test->waitUntilLoadFinished();
     433    javascriptResult = test->runJavaScriptAndWaitUntilFinished(xhr.get(), &error.outPtr());
     434    g_assert(javascriptResult);
     435    g_assert(!error);
     436
     437    // It isn't still possible to load file from an HTTP URL.
     438    test->loadURI(kServer->getURIForPath("/").data());
     439    test->waitUntilLoadFinished();
     440    javascriptResult = test->runJavaScriptAndWaitUntilFinished(xhr.get(), &error.outPtr());
     441    g_assert(!javascriptResult);
     442    g_assert_error(error.get(), WEBKIT_JAVASCRIPT_ERROR, WEBKIT_JAVASCRIPT_ERROR_SCRIPT_FAILED);
     443
     444    webkit_settings_set_allow_file_access_from_file_urls(webkit_web_view_get_settings(test->m_webView), FALSE);
     445}
     446
    414447void beforeAll()
    415448{
     
    424457    WebViewTest::add("WebKitWebContext", "languages", testWebContextLanguages);
    425458    SecurityPolicyTest::add("WebKitSecurityManager", "security-policy", testWebContextSecurityPolicy);
     459    WebViewTest::add("WebKitSecurityManager", "file-xhr", testWebContextSecurityFileXHR);
    426460}
    427461
Note: See TracChangeset for help on using the changeset viewer.