[GTK] Expose WebKitSecurityOrigin API
authormcatanzaro@igalia.com <mcatanzaro@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 3 Jan 2017 11:59:28 +0000 (11:59 +0000)
committermcatanzaro@igalia.com <mcatanzaro@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 3 Jan 2017 11:59:28 +0000 (11:59 +0000)
https://bugs.webkit.org/show_bug.cgi?id=166632

Source/WebKit2:

Patch by Michael Catanzaro  <mcatanzaro@igalia.com> and Carlos Garcia Campos <cgarcia@igalia.com> on 2017-01-03
Reviewed by Carlos Garcia Campos.

This API will be useful to have for various purposes, such as setting initial notification
permissions.

* PlatformGTK.cmake:
* UIProcess/API/gtk/WebKitAutocleanups.h:
* UIProcess/API/gtk/WebKitSecurityOrigin.cpp: Added.
(_WebKitSecurityOrigin::_WebKitSecurityOrigin):
(webkitSecurityOriginCreate):
(webkit_security_origin_new):
(webkit_security_origin_new_for_uri):
(webkit_security_origin_ref):
(webkit_security_origin_unref):
(webkit_security_origin_get_protocol):
(webkit_security_origin_get_host):
(webkit_security_origin_get_port):
(webkit_security_origin_is_opaque):
(webkit_security_origin_to_string):
* UIProcess/API/gtk/WebKitSecurityOrigin.h: Added.
* UIProcess/API/gtk/WebKitSecurityOriginPrivate.h: Added.
* UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt:
* UIProcess/API/gtk/docs/webkit2gtk-docs.sgml:
* UIProcess/API/gtk/webkit2.h:

Tools:

Reviewed by Carlos Garcia Campos.

* TestWebKitAPI/Tests/WebKit2Gtk/CMakeLists.txt:
* TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitSecurityOrigin.cpp: Added.
(testSecurityOriginBasicConstructor):
(testSecurityOriginURIConstructor):
(testSecurityOriginDefaultPort):
(testSecurityOriginFileURI):
(testSecurityOriginDataURI):
(beforeAll):
(afterAll):

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

12 files changed:
Source/WebKit2/ChangeLog
Source/WebKit2/PlatformGTK.cmake
Source/WebKit2/UIProcess/API/gtk/WebKitAutocleanups.h
Source/WebKit2/UIProcess/API/gtk/WebKitSecurityOrigin.cpp [new file with mode: 0644]
Source/WebKit2/UIProcess/API/gtk/WebKitSecurityOrigin.h [new file with mode: 0644]
Source/WebKit2/UIProcess/API/gtk/WebKitSecurityOriginPrivate.h [new file with mode: 0644]
Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt
Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-docs.sgml
Source/WebKit2/UIProcess/API/gtk/webkit2.h
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKit2Gtk/CMakeLists.txt
Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitSecurityOrigin.cpp [new file with mode: 0644]

index 620c2ea..9d172b9 100644 (file)
@@ -1,3 +1,33 @@
+2017-01-03  Michael Catanzaro  <mcatanzaro@igalia.com> and Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] Expose WebKitSecurityOrigin API
+        https://bugs.webkit.org/show_bug.cgi?id=166632
+
+        Reviewed by Carlos Garcia Campos.
+
+        This API will be useful to have for various purposes, such as setting initial notification
+        permissions.
+
+        * PlatformGTK.cmake:
+        * UIProcess/API/gtk/WebKitAutocleanups.h:
+        * UIProcess/API/gtk/WebKitSecurityOrigin.cpp: Added.
+        (_WebKitSecurityOrigin::_WebKitSecurityOrigin):
+        (webkitSecurityOriginCreate):
+        (webkit_security_origin_new):
+        (webkit_security_origin_new_for_uri):
+        (webkit_security_origin_ref):
+        (webkit_security_origin_unref):
+        (webkit_security_origin_get_protocol):
+        (webkit_security_origin_get_host):
+        (webkit_security_origin_get_port):
+        (webkit_security_origin_is_opaque):
+        (webkit_security_origin_to_string):
+        * UIProcess/API/gtk/WebKitSecurityOrigin.h: Added.
+        * UIProcess/API/gtk/WebKitSecurityOriginPrivate.h: Added.
+        * UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt:
+        * UIProcess/API/gtk/docs/webkit2gtk-docs.sgml:
+        * UIProcess/API/gtk/webkit2.h:
+
 2017-01-03  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         [SOUP] Load options allowStoredCredentials = DoNotAllowStoredCredentials with clientCredentialPolicy = MayAskClientForCredentials doesn't work
index 0a5e4d4..4838478 100644 (file)
@@ -220,6 +220,9 @@ list(APPEND WebKit2_SOURCES
     UIProcess/API/gtk/WebKitSecurityManager.cpp
     UIProcess/API/gtk/WebKitSecurityManager.h
     UIProcess/API/gtk/WebKitSecurityManagerPrivate.h
+    UIProcess/API/gtk/WebKitSecurityOrigin.cpp
+    UIProcess/API/gtk/WebKitSecurityOrigin.h
+    UIProcess/API/gtk/WebKitSecurityOriginPrivate.h
     UIProcess/API/gtk/WebKitSettings.cpp
     UIProcess/API/gtk/WebKitSettings.h
     UIProcess/API/gtk/WebKitSettingsPrivate.h
@@ -534,6 +537,7 @@ set(WebKit2GTK_INSTALLED_HEADERS
     ${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitResponsePolicyDecision.h
     ${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitScriptDialog.h
     ${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitSecurityManager.h
+    ${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitSecurityOrigin.h
     ${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitSettings.h
     ${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitURIRequest.h
     ${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitURIResponse.h
index f872f30..7b07e89 100644 (file)
@@ -75,6 +75,7 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitCredential, webkit_credential_free)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitJavascriptResult, webkit_javascript_result_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitMimeInfo, webkit_mime_info_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitNavigationAction, webkit_navigation_action_free)
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitSecurityOrigin, webkit_security_origin_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitUserScript, webkit_user_script_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitUserStyleSheet, webkit_user_style_sheet_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitWebViewSessionState, webkit_web_view_session_state_unref)
diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitSecurityOrigin.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitSecurityOrigin.cpp
new file mode 100644 (file)
index 0000000..2334ccc
--- /dev/null
@@ -0,0 +1,261 @@
+/*
+ * Copyright (C) 2017 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebKitSecurityOrigin.h"
+
+#include "WebKitSecurityOriginPrivate.h"
+#include <WebCore/URL.h>
+#include <wtf/text/CString.h>
+
+using namespace WebKit;
+
+/**
+ * SECTION: WebKitSecurityOrigin
+ * @Short_description: A security boundary for websites
+ * @Title: WebKitSecurityOrigin
+ *
+ * #WebKitSecurityOrigin is a representation of a security domain
+ * defined by websites. A security origin normally consists of a
+ * protocol, a hostname, and a port number. It is also possible for a
+ * security origin to be opaque, as defined by the HTML standard, in
+ * which case it has no associated protocol, host, or port.
+ *
+ * Websites with the same security origin can access each other's
+ * resources for client-side scripting or database access.
+ *
+ * Since: 2.16
+ */
+
+struct _WebKitSecurityOrigin {
+    _WebKitSecurityOrigin(Ref<WebCore::SecurityOrigin>&& coreSecurityOrigin)
+        : securityOrigin(WTFMove(coreSecurityOrigin))
+    {
+    }
+
+    Ref<WebCore::SecurityOrigin> securityOrigin;
+    CString protocol;
+    CString host;
+    int referenceCount { 1 };
+};
+
+G_DEFINE_BOXED_TYPE(WebKitSecurityOrigin, webkit_security_origin, webkit_security_origin_ref, webkit_security_origin_unref)
+
+WebKitSecurityOrigin* webkitSecurityOriginCreate(Ref<WebCore::SecurityOrigin>&& coreSecurityOrigin)
+{
+    WebKitSecurityOrigin* origin = static_cast<WebKitSecurityOrigin*>(fastMalloc(sizeof(WebKitSecurityOrigin)));
+    new (origin) WebKitSecurityOrigin(WTFMove(coreSecurityOrigin));
+    return origin;
+}
+
+/**
+ * webkit_security_origin_new:
+ * @protocol: The protocol for the new origin
+ * @host: The host for the new origin
+ * @port: The port number for the new origin, or 0 to indicate the
+ *        default port for @protocol
+ *
+ * Create a new security origin from the provided protocol, host and
+ * port.
+ *
+ * Returns: (transfer full): A #WebKitSecurityOrigin.
+ *
+ * Since: 2.16
+ */
+WebKitSecurityOrigin* webkit_security_origin_new(const gchar* protocol, const gchar* host, guint16 port)
+{
+    g_return_val_if_fail(protocol, nullptr);
+    g_return_val_if_fail(host, nullptr);
+
+    std::optional<uint16_t> optionalPort;
+    if (port)
+        optionalPort = port;
+
+    return webkitSecurityOriginCreate(WebCore::SecurityOrigin::create(String::fromUTF8(protocol), String::fromUTF8(host), optionalPort));
+}
+
+/**
+ * webkit_security_origin_new_for_uri:
+ * @uri: The URI for the new origin
+ *
+ * Create a new security origin from the provided URI. Components of
+ * @uri other than protocol, host, and port do not affect the created
+ * #WebKitSecurityOrigin.
+ *
+ * Returns: (transfer full): A #WebKitSecurityOrigin.
+ *
+ * Since: 2.16
+ */
+WebKitSecurityOrigin* webkit_security_origin_new_for_uri(const gchar* uri)
+{
+    g_return_val_if_fail(uri, nullptr);
+
+    return webkitSecurityOriginCreate(WebCore::SecurityOrigin::create(WebCore::URL(WebCore::URL(), String::fromUTF8(uri))));
+}
+
+/**
+ * webkit_security_origin_ref:
+ * @origin: a #WebKitSecurityOrigin
+ *
+ * Atomically increments the reference count of @origin by one.
+ * This function is MT-safe and may be called from any thread.
+ *
+ * Returns: The passed #WebKitSecurityOrigin
+ *
+ * Since: 2.16
+ */
+WebKitSecurityOrigin* webkit_security_origin_ref(WebKitSecurityOrigin* origin)
+{
+    g_return_val_if_fail(origin, nullptr);
+
+    g_atomic_int_inc(&origin->referenceCount);
+    return origin;
+}
+
+/**
+ * webkit_security_origin_unref:
+ * @origin: A #WebKitSecurityOrigin
+ *
+ * Atomically decrements the reference count of @origin by one.
+ * If the reference count drops to 0, all memory allocated by
+ * #WebKitSecurityOrigin is released. This function is MT-safe and may be
+ * called from any thread.
+ *
+ * Since: 2.16
+ */
+void webkit_security_origin_unref(WebKitSecurityOrigin* origin)
+{
+    g_return_if_fail(origin);
+
+    if (g_atomic_int_dec_and_test(&origin->referenceCount)) {
+        origin->~WebKitSecurityOrigin();
+        fastFree(origin);
+    }
+}
+
+/**
+ * webkit_security_origin_get_protocol:
+ * @origin: a #WebKitSecurityOrigin
+ *
+ * Gets the protocol of @origin, or %NULL if @origin is opaque.
+ *
+ * Returns (allow-none): The protocol of the #WebKitSecurityOrigin
+ *
+ * Since: 2.16
+ */
+const gchar* webkit_security_origin_get_protocol(WebKitSecurityOrigin* origin)
+{
+    g_return_val_if_fail(origin, nullptr);
+
+    if (origin->securityOrigin->protocol().isEmpty())
+        return nullptr;
+
+    if (origin->protocol.isNull())
+        origin->protocol = origin->securityOrigin->protocol().utf8();
+    return origin->protocol.data();
+}
+
+/**
+ * webkit_security_origin_get_host:
+ * @origin: a #WebKitSecurityOrigin
+ *
+ * Gets the hostname of @origin, or %NULL if @origin is opaque or if its
+ * protocol does not require a host component.
+ *
+ * Returns: (allow-none): The host of the #WebKitSecurityOrigin
+ *
+ * Since: 2.16
+ */
+const gchar* webkit_security_origin_get_host(WebKitSecurityOrigin* origin)
+{
+    g_return_val_if_fail(origin, nullptr);
+
+    if (origin->securityOrigin->host().isEmpty())
+        return nullptr;
+
+    if (origin->host.isNull())
+        origin->host = origin->securityOrigin->host().utf8();
+    return origin->host.data();
+}
+
+/**
+ * webkit_security_origin_get_port:
+ * @origin: a #WebKitSecurityOrigin
+ *
+ * Gets the port of @origin. This function will always return 0 if the
+ * port is the default port for the given protocol. For example,
+ * http://example.com has the same security origin as
+ * http://example.com:80, and this function will return 0 for a
+ * #WebKitSecurityOrigin constructed from either URI. It will also
+ * return 0 if @origin is opaque.
+ *
+ * Returns: The port of the #WebKitSecurityOrigin.
+ *
+ * Since: 2.16
+ */
+guint16 webkit_security_origin_get_port(WebKitSecurityOrigin* origin)
+{
+    g_return_val_if_fail(origin, 0);
+
+    return origin->securityOrigin->port().value_or(0);
+}
+
+/**
+ * webkit_security_origin_is_opaque:
+ * @origin: a #WebKitSecurityOrigin
+ *
+ * Gets whether @origin is an opaque security origin, which does not
+ * possess an associated protocol, host, or port.
+ *
+ * Returns: %TRUE if @origin is opaque.
+ *
+ * Since: 2.16
+ */
+gboolean webkit_security_origin_is_opaque(WebKitSecurityOrigin* origin)
+{
+    g_return_val_if_fail(origin, TRUE);
+
+    return origin->securityOrigin->isUnique();
+}
+
+/**
+ * webkit_security_origin_to_string:
+ * @origin: a #WebKitSecurityOrigin
+ *
+ * Gets a string representation of @origin. The string representation
+ * is a valid URI with only protocol, host, and port components. It may
+ * be %NULL, but usually only if @origin is opaque.
+ *
+ * Returns: (allow-none) (transfer full): a URI representing @origin.
+ *
+ * Since: 2.16
+ */
+gchar* webkit_security_origin_to_string(WebKitSecurityOrigin* origin)
+{
+    g_return_val_if_fail(origin, nullptr);
+
+    CString cstring = origin->securityOrigin->toString().utf8();
+    return cstring == "null" ? nullptr : g_strdup (cstring.data());
+}
diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitSecurityOrigin.h b/Source/WebKit2/UIProcess/API/gtk/WebKitSecurityOrigin.h
new file mode 100644 (file)
index 0000000..450723e
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2017 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if !defined(__WEBKIT2_H_INSIDE__) && !defined(WEBKIT2_COMPILATION)
+#error "Only <webkit2/webkit2.h> can be included directly."
+#endif
+
+#ifndef WebKitSecurityOrigin_h
+#define WebKitSecurityOrigin_h
+
+#include <glib-object.h>
+#include <webkit2/WebKitDefines.h>
+
+G_BEGIN_DECLS
+
+#define WEBKIT_TYPE_SECURITY_ORIGIN (webkit_security_origin_get_type())
+
+typedef struct _WebKitSecurityOrigin WebKitSecurityOrigin;
+
+WEBKIT_API GType
+webkit_security_origin_get_type     (void);
+
+WEBKIT_API WebKitSecurityOrigin *
+webkit_security_origin_new          (const gchar          *protocol,
+                                     const gchar          *host,
+                                     guint16               port);
+
+WEBKIT_API WebKitSecurityOrigin *
+webkit_security_origin_new_for_uri  (const gchar          *uri);
+
+WEBKIT_API WebKitSecurityOrigin *
+webkit_security_origin_ref          (WebKitSecurityOrigin *origin);
+
+WEBKIT_API void
+webkit_security_origin_unref        (WebKitSecurityOrigin *origin);
+
+WEBKIT_API const gchar *
+webkit_security_origin_get_protocol (WebKitSecurityOrigin *origin);
+
+WEBKIT_API const gchar *
+webkit_security_origin_get_host     (WebKitSecurityOrigin *origin);
+
+WEBKIT_API guint16
+webkit_security_origin_get_port     (WebKitSecurityOrigin *origin);
+
+WEBKIT_API gboolean
+webkit_security_origin_is_opaque    (WebKitSecurityOrigin *origin);
+
+WEBKIT_API gchar *
+webkit_security_origin_to_string    (WebKitSecurityOrigin *origin);
+
+G_END_DECLS
+
+#endif /* WebKitSecurityOrigin_h */
diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitSecurityOriginPrivate.h b/Source/WebKit2/UIProcess/API/gtk/WebKitSecurityOriginPrivate.h
new file mode 100644 (file)
index 0000000..1db3e37
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2017 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "WebKitPrivate.h"
+#include "WebKitSecurityOrigin.h"
+#include <WebCore/SecurityOrigin.h>
+
+WebKitSecurityOrigin* webkitSecurityOriginCreate(Ref<WebCore::SecurityOrigin>&&);
index 01303f6..ee3afbb 100644 (file)
@@ -1211,6 +1211,26 @@ webkit_security_manager_get_type
 </SECTION>
 
 <SECTION>
+<FILE>WebKitSecurityOrigin</FILE>
+WebKitSecurityOrigin
+webkit_security_origin_new
+webkit_security_origin_new_for_uri
+webkit_security_origin_ref
+webkit_security_origin_unref
+webkit_security_origin_get_protocol
+webkit_security_origin_get_host
+webkit_security_origin_get_port
+webkit_security_origin_is_opaque
+webkit_security_origin_to_string
+
+<SUBSECTION Standard>
+WEBKIT_TYPE_SECURITY_ORIGIN
+
+<SUBSECTION Private>
+webkit_security_origin_get_type
+</SECTION>
+
+<SECTION>
 <FILE>WebKitWebsiteDataManager</FILE>
 WebKitWebsiteDataManager
 webkit_website_data_manager_new
index f8f42dc..024e9b8 100644 (file)
@@ -51,6 +51,7 @@
     <xi:include href="xml/WebKitUserContent.xml"/>
     <xi:include href="xml/WebKitNotification.xml"/>
     <xi:include href="xml/WebKitNotificationPermissionRequest.xml"/>
+    <xi:include href="xml/WebKitSecurityOrigin.xml"/>
     <xi:include href="xml/WebKitWebsiteDataManager.xml"/>
   </chapter>
 
index 3e44d60..fc0fa4e 100644 (file)
@@ -61,6 +61,7 @@
 #include <webkit2/WebKitResponsePolicyDecision.h>
 #include <webkit2/WebKitScriptDialog.h>
 #include <webkit2/WebKitSecurityManager.h>
+#include <webkit2/WebKitSecurityOrigin.h>
 #include <webkit2/WebKitSettings.h>
 #include <webkit2/WebKitURIRequest.h>
 #include <webkit2/WebKitURIResponse.h>
index 9dfeca0..ea2b8b7 100644 (file)
@@ -1,3 +1,20 @@
+2017-01-03  Michael Catanzaro  <mcatanzaro@igalia.com>
+
+        [GTK] Expose WebKitSecurityOrigin API
+        https://bugs.webkit.org/show_bug.cgi?id=166632
+
+        Reviewed by Carlos Garcia Campos.
+
+        * TestWebKitAPI/Tests/WebKit2Gtk/CMakeLists.txt:
+        * TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitSecurityOrigin.cpp: Added.
+        (testSecurityOriginBasicConstructor):
+        (testSecurityOriginURIConstructor):
+        (testSecurityOriginDefaultPort):
+        (testSecurityOriginFileURI):
+        (testSecurityOriginDataURI):
+        (beforeAll):
+        (afterAll):
+
 2017-01-03  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         [GTK] HTTP auth layout tests are flaky
index 946774e..2584df2 100644 (file)
@@ -118,6 +118,7 @@ ADD_WK2_TEST(TestSSL TestSSL.cpp)
 ADD_WK2_TEST(TestUIClient TestUIClient.cpp)
 ADD_WK2_TEST(TestWebExtensions TestWebExtensions.cpp)
 ADD_WK2_TEST(TestWebKitPolicyClient TestWebKitPolicyClient.cpp)
+ADD_WK2_TEST(TestWebKitSecurityOrigin TestWebKitSecurityOrigin.cpp)
 ADD_WK2_TEST(TestWebKitSettings TestWebKitSettings.cpp)
 ADD_WK2_TEST(TestWebKitVersion TestWebKitVersion.cpp)
 ADD_WK2_TEST(TestWebViewEditor TestWebViewEditor.cpp)
diff --git a/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitSecurityOrigin.cpp b/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitSecurityOrigin.cpp
new file mode 100644 (file)
index 0000000..1cc9e77
--- /dev/null
@@ -0,0 +1,142 @@
+/*
+ * Copyright (C) 2017 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2,1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+
+#include "TestMain.h"
+#include <webkit2/webkit2.h>
+#include <wtf/glib/GUniquePtr.h>
+
+static void testSecurityOriginBasicConstructor(Test*, gconstpointer)
+{
+    WebKitSecurityOrigin* origin = webkit_security_origin_new("http", "127.0.0.1", 1234);
+    g_assert(origin);
+    GUniquePtr<char> asString(webkit_security_origin_to_string(origin));
+    g_assert_cmpstr(asString.get(), ==, "http://127.0.0.1:1234");
+    g_assert_cmpstr(webkit_security_origin_get_protocol(origin), ==, "http");
+    g_assert_cmpstr(webkit_security_origin_get_host(origin), ==, "127.0.0.1");
+    g_assert_cmpint(webkit_security_origin_get_port(origin), ==, 1234);
+    g_assert(!webkit_security_origin_is_opaque(origin));
+    webkit_security_origin_unref(origin);
+}
+
+static void testSecurityOriginURIConstructor(Test*, gconstpointer)
+{
+    WebKitSecurityOrigin* origin = webkit_security_origin_new_for_uri("http://127.0.0.1:1234");
+    g_assert(origin);
+    GUniquePtr<char> asString(webkit_security_origin_to_string(origin));
+    g_assert_cmpstr(asString.get(), ==, "http://127.0.0.1:1234");
+    g_assert_cmpstr(webkit_security_origin_get_protocol(origin), ==, "http");
+    g_assert_cmpstr(webkit_security_origin_get_host(origin), ==, "127.0.0.1");
+    g_assert_cmpint(webkit_security_origin_get_port(origin), ==, 1234);
+    g_assert(!webkit_security_origin_is_opaque(origin));
+    webkit_security_origin_unref(origin);
+
+    origin = webkit_security_origin_new_for_uri("http://127.0.0.1:1234/this/path/?should=be#ignored");
+    g_assert(origin);
+    asString.reset(webkit_security_origin_to_string(origin));
+    g_assert_cmpstr(asString.get(), ==, "http://127.0.0.1:1234");
+    g_assert_cmpstr(webkit_security_origin_get_protocol(origin), ==, "http");
+    g_assert_cmpstr(webkit_security_origin_get_host(origin), ==, "127.0.0.1");
+    g_assert_cmpint(webkit_security_origin_get_port(origin), ==, 1234);
+    g_assert(!webkit_security_origin_is_opaque(origin));
+    webkit_security_origin_unref(origin);
+}
+
+static void testSecurityOriginDefaultPort(Test*, gconstpointer)
+{
+    WebKitSecurityOrigin* origin = webkit_security_origin_new("http", "127.0.0.1", 0);
+    g_assert(origin);
+    GUniquePtr<char> asString(webkit_security_origin_to_string(origin));
+    g_assert_cmpstr(asString.get(), ==, "http://127.0.0.1");
+    g_assert_cmpstr(webkit_security_origin_get_protocol(origin), ==, "http");
+    g_assert_cmpstr(webkit_security_origin_get_host(origin), ==, "127.0.0.1");
+    g_assert_cmpint(webkit_security_origin_get_port(origin), ==, 0);
+    g_assert(!webkit_security_origin_is_opaque(origin));
+    webkit_security_origin_unref(origin);
+
+    origin = webkit_security_origin_new("http", "127.0.0.1", 80);
+    g_assert(origin);
+    asString.reset(webkit_security_origin_to_string(origin));
+    g_assert_cmpstr(asString.get(), ==, "http://127.0.0.1");
+    g_assert_cmpstr(webkit_security_origin_get_protocol(origin), ==, "http");
+    g_assert_cmpstr(webkit_security_origin_get_host(origin), ==, "127.0.0.1");
+    g_assert_cmpint(webkit_security_origin_get_port(origin), ==, 0);
+    g_assert(!webkit_security_origin_is_opaque(origin));
+    webkit_security_origin_unref(origin);
+
+    origin = webkit_security_origin_new_for_uri("http://127.0.0.1");
+    g_assert(origin);
+    asString.reset(webkit_security_origin_to_string(origin));
+    g_assert_cmpstr(asString.get(), ==, "http://127.0.0.1");
+    g_assert_cmpstr(webkit_security_origin_get_protocol(origin), ==, "http");
+    g_assert_cmpstr(webkit_security_origin_get_host(origin), ==, "127.0.0.1");
+    g_assert_cmpint(webkit_security_origin_get_port(origin), ==, 0);
+    g_assert(!webkit_security_origin_is_opaque(origin));
+    webkit_security_origin_unref(origin);
+
+    origin = webkit_security_origin_new_for_uri("http://127.0.0.1:80");
+    g_assert(origin);
+    asString.reset(webkit_security_origin_to_string(origin));
+    g_assert_cmpstr(asString.get(), ==, "http://127.0.0.1");
+    g_assert_cmpstr(webkit_security_origin_get_protocol(origin), ==, "http");
+    g_assert_cmpstr(webkit_security_origin_get_host(origin), ==, "127.0.0.1");
+    g_assert_cmpint(webkit_security_origin_get_port(origin), ==, 0);
+    g_assert(!webkit_security_origin_is_opaque(origin));
+    webkit_security_origin_unref(origin);
+}
+
+static void testSecurityOriginFileURI(Test*, gconstpointer)
+{
+    WebKitSecurityOrigin* origin = webkit_security_origin_new_for_uri("file:///abcdefg");
+    g_assert(origin);
+    GUniquePtr<char> asString(webkit_security_origin_to_string(origin));
+    g_assert_cmpstr(asString.get(), ==, "file://");
+    g_assert_cmpstr(webkit_security_origin_get_protocol(origin), ==, "file");
+    g_assert(!webkit_security_origin_get_host(origin));
+    g_assert_cmpint(webkit_security_origin_get_port(origin), ==, 0);
+    g_assert(!webkit_security_origin_is_opaque(origin));
+    webkit_security_origin_unref(origin);
+}
+
+static void testOpaqueSecurityOrigin(Test*, gconstpointer)
+{
+    WebKitSecurityOrigin* origin = webkit_security_origin_new_for_uri("data:Lali ho!");
+    g_assert(origin);
+    GUniquePtr<char> asString(webkit_security_origin_to_string(origin));
+    g_assert(!asString);
+    g_assert(!webkit_security_origin_get_protocol(origin));
+    g_assert(!webkit_security_origin_get_host(origin));
+    g_assert_cmpint(webkit_security_origin_get_port(origin), ==, 0);
+    g_assert(webkit_security_origin_is_opaque(origin));
+    webkit_security_origin_unref(origin);
+}
+
+void beforeAll()
+{
+    Test::add("WebKitSecurityOrigin", "basic-constructor", testSecurityOriginBasicConstructor);
+    Test::add("WebKitSecurityOrigin", "uri-constructor", testSecurityOriginURIConstructor);
+    Test::add("WebKitSecruityOrigin", "default-port", testSecurityOriginDefaultPort);
+    Test::add("WebKitSecurityOrigin", "file-uri", testSecurityOriginFileURI);
+    Test::add("WebKitSecruityOrigin", "opaque-origin", testOpaqueSecurityOrigin);
+}
+
+void afterAll()
+{
+}