[GTK][SOUP] Implement WebCore::PublicSuffix for soup and enable PUBLIC_SUFFIX_LIST...
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 27 Jun 2015 07:45:31 +0000 (07:45 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 27 Jun 2015 07:45:31 +0000 (07:45 +0000)
https://bugs.webkit.org/show_bug.cgi?id=146318

Reviewed by Sergio Villar Senin.

.:

Enable PUBLIC_SUFFIX_LIST for GTK+.

* Source/cmake/OptionsGTK.cmake:

Source/WebCore:

This is covered by unit tests.

* PlatformGTK.cmake:
* platform/soup/PublicSuffixSoup.cpp: Added.
(WebCore::isPublicSuffix):
(WebCore::topPrivatelyControlledDomain):

Tools:

Copy mac PublicSuffix test to the common directory and add it to
the GTK+ build.

* TestWebKitAPI/PlatformGTK.cmake:
* TestWebKitAPI/Tests/WebCore/PublicSuffix.cpp: Added.
(TestWebKitAPI::TEST_F):

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

ChangeLog
Source/WebCore/ChangeLog
Source/WebCore/PlatformGTK.cmake
Source/WebCore/platform/soup/PublicSuffixSoup.cpp [new file with mode: 0644]
Source/cmake/OptionsGTK.cmake
Tools/ChangeLog
Tools/TestWebKitAPI/PlatformGTK.cmake
Tools/TestWebKitAPI/Tests/WebCore/PublicSuffix.cpp [new file with mode: 0644]

index 5f4b3ef..f997fec 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2015-06-27  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK][SOUP] Implement WebCore::PublicSuffix for soup and enable PUBLIC_SUFFIX_LIST for GTK+
+        https://bugs.webkit.org/show_bug.cgi?id=146318
+
+        Reviewed by Sergio Villar Senin.
+
+        Enable PUBLIC_SUFFIX_LIST for GTK+.
+
+        * Source/cmake/OptionsGTK.cmake:
+
 2015-06-22  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         Unreviewed. Update OptionsGTK.cmake and NEWS for 2.9.3 release.
index 08c963f..f82623d 100644 (file)
@@ -1,3 +1,17 @@
+2015-06-27  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK][SOUP] Implement WebCore::PublicSuffix for soup and enable PUBLIC_SUFFIX_LIST for GTK+
+        https://bugs.webkit.org/show_bug.cgi?id=146318
+
+        Reviewed by Sergio Villar Senin.
+
+        This is covered by unit tests.
+
+        * PlatformGTK.cmake:
+        * platform/soup/PublicSuffixSoup.cpp: Added.
+        (WebCore::isPublicSuffix):
+        (WebCore::topPrivatelyControlledDomain):
+
 2015-06-26  Myles C. Maxfield  <mmaxfield@apple.com>
 
         [iOS] AppleGothic has been superseded by Apple SD Gothic Neo
index e150f98..ebe9290 100644 (file)
@@ -185,6 +185,7 @@ list(APPEND WebCore_SOURCES
     platform/network/soup/SynchronousLoaderClientSoup.cpp
     platform/network/soup/WebKitSoupRequestGeneric.cpp
 
+    platform/soup/PublicSuffixSoup.cpp
     platform/soup/SharedBufferSoup.cpp
     platform/soup/URLSoup.cpp
 
diff --git a/Source/WebCore/platform/soup/PublicSuffixSoup.cpp b/Source/WebCore/platform/soup/PublicSuffixSoup.cpp
new file mode 100644 (file)
index 0000000..16232c7
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2015 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. ``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
+ * 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 "PublicSuffix.h"
+
+#if ENABLE(PUBLIC_SUFFIX_LIST)
+
+#include <libsoup/soup.h>
+#include <wtf/glib/GUniquePtr.h>
+
+namespace WebCore {
+
+bool isPublicSuffix(const String& domain)
+{
+    if (domain.isEmpty())
+        return false;
+
+    return soup_tld_domain_is_public_suffix(domain.utf8().data());
+}
+
+String topPrivatelyControlledDomain(const String& domain)
+{
+    if (domain.isEmpty())
+        return String();
+
+    GUniqueOutPtr<GError> error;
+    if (const char* baseDomain = soup_tld_get_base_domain(domain.utf8().data(), &error.outPtr()))
+        return String::fromUTF8(baseDomain);
+
+    if (g_error_matches(error.get(), SOUP_TLD_ERROR, SOUP_TLD_ERROR_NO_BASE_DOMAIN) || g_error_matches(error.get(), SOUP_TLD_ERROR, SOUP_TLD_ERROR_NOT_ENOUGH_DOMAINS))
+        return String();
+
+    if (g_error_matches(error.get(), SOUP_TLD_ERROR, SOUP_TLD_ERROR_IS_IP_ADDRESS) || g_error_matches(error.get(), SOUP_TLD_ERROR, SOUP_TLD_ERROR_INVALID_HOSTNAME))
+        return domain;
+
+    ASSERT_NOT_REACHED();
+    return String();
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(PUBLIC_SUFFIX_LIST)
index 0587c86..e23e153 100644 (file)
@@ -176,6 +176,7 @@ WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_NAVIGATOR_HWCONCURRENCY PRIVATE ON)
 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_NETSCAPE_PLUGIN_API PRIVATE ON)
 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_NOTIFICATIONS PRIVATE ON)
 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_PICTURE_SIZES PRIVATE ON)
+WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_PUBLIC_SUFFIX_LIST PRIVATE ON)
 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_QUOTA PRIVATE OFF)
 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_RESOLUTION_MEDIA_QUERY PRIVATE OFF)
 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_REQUEST_ANIMATION_FRAME PRIVATE ON)
index 1971048..82ec7bc 100644 (file)
@@ -1,3 +1,17 @@
+2015-06-27  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK][SOUP] Implement WebCore::PublicSuffix for soup and enable PUBLIC_SUFFIX_LIST for GTK+
+        https://bugs.webkit.org/show_bug.cgi?id=146318
+
+        Reviewed by Sergio Villar Senin.
+
+        Copy mac PublicSuffix test to the common directory and add it to
+        the GTK+ build.
+
+        * TestWebKitAPI/PlatformGTK.cmake:
+        * TestWebKitAPI/Tests/WebCore/PublicSuffix.cpp: Added.
+        (TestWebKitAPI::TEST_F):
+
 2015-06-26  Per Arne Vollan  <peavo@outlook.com>
 
         WinLauncher fails to download files.
index d641b89..747379b 100644 (file)
@@ -130,6 +130,7 @@ add_executable(TestWebCore
     ${TESTWEBKITAPI_DIR}/Tests/WebCore/URL.cpp
     ${TESTWEBKITAPI_DIR}/Tests/WebCore/SharedBuffer.cpp
     ${TESTWEBKITAPI_DIR}/Tests/WebCore/FileSystem.cpp
+    ${TESTWEBKITAPI_DIR}/Tests/WebCore/PublicSuffix.cpp
 )
 
 target_link_libraries(TestWebCore ${test_webcore_LIBRARIES})
diff --git a/Tools/TestWebKitAPI/Tests/WebCore/PublicSuffix.cpp b/Tools/TestWebKitAPI/Tests/WebCore/PublicSuffix.cpp
new file mode 100644 (file)
index 0000000..f87ba63
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2012 Apple Inc. All rights reserved.
+ *
+ * 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"
+
+#if ENABLE(PUBLIC_SUFFIX_LIST)
+
+#include "WTFStringUtilities.h"
+#include <WebCore/PublicSuffix.h>
+#include <wtf/MainThread.h>
+
+using namespace WebCore;
+
+namespace TestWebKitAPI {
+
+class PublicSuffix: public testing::Test {
+public:
+    virtual void SetUp()
+    {
+        WTF::initializeMainThread();
+    }
+};
+
+TEST_F(PublicSuffix, IsPublicSuffix)
+{
+    EXPECT_TRUE(isPublicSuffix("com"));
+    EXPECT_FALSE(isPublicSuffix("test.com"));
+    EXPECT_FALSE(isPublicSuffix("com.com"));
+    EXPECT_TRUE(isPublicSuffix("net"));
+    EXPECT_TRUE(isPublicSuffix("org"));
+    EXPECT_TRUE(isPublicSuffix("co.uk"));
+    EXPECT_FALSE(isPublicSuffix("bl.uk"));
+    EXPECT_FALSE(isPublicSuffix("test.co.uk"));
+    EXPECT_TRUE(isPublicSuffix("xn--zf0ao64a.tw"));
+}
+
+TEST_F(PublicSuffix, TopPrivatelyControlledDomain)
+{
+    EXPECT_EQ(String("test.com"), topPrivatelyControlledDomain("test.com"));
+    EXPECT_EQ(String("test.com"), topPrivatelyControlledDomain("com.test.com"));
+    EXPECT_EQ(String("test.com"), topPrivatelyControlledDomain("subdomain.test.com"));
+    EXPECT_EQ(String("com.com"), topPrivatelyControlledDomain("www.com.com"));
+    EXPECT_EQ(String("test.co.uk"), topPrivatelyControlledDomain("test.co.uk"));
+    EXPECT_EQ(String("test.co.uk"), topPrivatelyControlledDomain("subdomain.test.co.uk"));
+    EXPECT_EQ(String("bl.uk"), topPrivatelyControlledDomain("bl.uk"));
+    EXPECT_EQ(String("bl.uk"), topPrivatelyControlledDomain("subdomain.bl.uk"));
+    EXPECT_EQ(String("test.xn--zf0ao64a.tw"), topPrivatelyControlledDomain("test.xn--zf0ao64a.tw"));
+    EXPECT_EQ(String("test.xn--zf0ao64a.tw"), topPrivatelyControlledDomain("www.test.xn--zf0ao64a.tw"));
+    EXPECT_EQ(String("127.0.0.1"), topPrivatelyControlledDomain("127.0.0.1"));
+    EXPECT_EQ(String(), topPrivatelyControlledDomain("1"));
+    EXPECT_EQ(String(), topPrivatelyControlledDomain("com"));
+}
+
+}
+
+#endif // ENABLE(PUBLIC_SUFFIX_LIST)