mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 01:17:34 +00:00
LibWebView+LibPublicSuffix: Merge LibPublicSuffix into LibWebView
After d2c7e1ea7d
, there is now only one
user of LibPublicSuffix - the URL sanitation utility within LibWebView.
Rather than having an entire library for the small Public Suffix data
accessor, merge it into LibWebView.
This commit is contained in:
parent
a1cce69db0
commit
a8f0fa5dd4
11 changed files with 57 additions and 87 deletions
|
@ -1,3 +1,5 @@
|
|||
include(${SerenityOS_SOURCE_DIR}/Meta/CMake/public_suffix.cmake)
|
||||
|
||||
set(SOURCES
|
||||
AccessibilityTreeModel.cpp
|
||||
AriaPropertiesStateModel.cpp
|
||||
|
@ -14,8 +16,11 @@ set(SOURCES
|
|||
ViewImplementation.cpp
|
||||
WebContentClient.cpp
|
||||
WebSocketClientAdapter.cpp
|
||||
${PUBLIC_SUFFIX_SOURCES}
|
||||
)
|
||||
|
||||
set(GENERATED_SOURCES ${CURRENT_LIB_GENERATED})
|
||||
|
||||
if (SERENITYOS)
|
||||
list(APPEND SOURCES OutOfProcessWebView.cpp)
|
||||
endif()
|
||||
|
@ -41,7 +46,8 @@ set(GENERATED_SOURCES
|
|||
)
|
||||
|
||||
serenity_lib(LibWebView webview)
|
||||
target_link_libraries(LibWebView PRIVATE LibCore LibFileSystem LibGfx LibGUI LibIPC LibProtocol LibPublicSuffix LibJS LibWeb LibSQL)
|
||||
target_link_libraries(LibWebView PRIVATE LibCore LibFileSystem LibGfx LibGUI LibIPC LibProtocol LibJS LibWeb LibSQL)
|
||||
target_compile_definitions(LibWebView PRIVATE ENABLE_PUBLIC_SUFFIX=$<BOOL:${ENABLE_PUBLIC_SUFFIX_DOWNLOAD}>)
|
||||
|
||||
if (SERENITYOS)
|
||||
target_link_libraries(LibWebView PRIVATE LibFileSystemAccessClient)
|
||||
|
|
|
@ -1,16 +1,54 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
|
||||
* Copyright (c) 2023, Cameron Youell <cameronyouell@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/String.h>
|
||||
#include <LibCore/System.h>
|
||||
#include <LibFileSystem/FileSystem.h>
|
||||
#include <LibPublicSuffix/URL.h>
|
||||
#include <LibWebView/URL.h>
|
||||
|
||||
#if defined(ENABLE_PUBLIC_SUFFIX)
|
||||
# include <LibWebView/PublicSuffixData.h>
|
||||
#endif
|
||||
|
||||
namespace WebView {
|
||||
|
||||
static Optional<URL> query_public_suffix_list(StringView url_string)
|
||||
{
|
||||
auto out = MUST(String::from_utf8(url_string));
|
||||
if (!out.contains("://"sv))
|
||||
out = MUST(String::formatted("https://{}"sv, out));
|
||||
|
||||
auto url = URL::create_with_url_or_path(out.to_deprecated_string());
|
||||
if (!url.is_valid())
|
||||
return {};
|
||||
|
||||
#if defined(ENABLE_PUBLIC_SUFFIX)
|
||||
if (url.host().has<URL::IPv4Address>() || url.host().has<URL::IPv6Address>())
|
||||
return url;
|
||||
|
||||
if (url.scheme() != "http"sv && url.scheme() != "https"sv)
|
||||
return url;
|
||||
|
||||
if (url.host().has<String>()) {
|
||||
auto const& host = url.host().get<String>();
|
||||
|
||||
if (auto public_suffix = MUST(PublicSuffixData::the()->get_public_suffix(host)); public_suffix.has_value())
|
||||
return url;
|
||||
|
||||
if (host.ends_with_bytes(".local"sv) || host.ends_with_bytes("localhost"sv))
|
||||
return url;
|
||||
}
|
||||
|
||||
return {};
|
||||
#else
|
||||
return url;
|
||||
#endif
|
||||
}
|
||||
|
||||
Optional<URL> sanitize_url(StringView url, Optional<StringView> search_engine, AppendTLD append_tld)
|
||||
{
|
||||
if (FileSystem::exists(url)) {
|
||||
|
@ -38,8 +76,8 @@ Optional<URL> sanitize_url(StringView url, Optional<StringView> search_engine, A
|
|||
}
|
||||
}
|
||||
|
||||
auto result = PublicSuffix::absolute_url(url);
|
||||
if (result.is_error())
|
||||
auto result = query_public_suffix_list(url);
|
||||
if (!result.has_value())
|
||||
return format_search_engine();
|
||||
|
||||
return result.release_value();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue