mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-30 00:31:14 +00:00
LibWeb: Port NavigatorID from DeprecatedString to String
This commit is contained in:
parent
0a4586d510
commit
6aff55d655
Notes:
sideshowbarker
2024-07-17 07:20:49 +09:00
Author: https://github.com/shannonbooth Commit: https://github.com/SerenityOS/serenity/commit/6aff55d655 Pull-request: https://github.com/SerenityOS/serenity/pull/21997 Reviewed-by: https://github.com/AtkinsSJ ✅
|
@ -11,14 +11,14 @@
|
||||||
namespace Web::HTML {
|
namespace Web::HTML {
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator-appversion
|
// https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator-appversion
|
||||||
DeprecatedString NavigatorIDMixin::app_version() const
|
String NavigatorIDMixin::app_version() const
|
||||||
{
|
{
|
||||||
// Must return the appropriate string that starts with "5.0 (", as follows:
|
// Must return the appropriate string that starts with "5.0 (", as follows:
|
||||||
|
|
||||||
// Let trail be the substring of default `User-Agent` value that follows the "Mozilla/" prefix.
|
// Let trail be the substring of default `User-Agent` value that follows the "Mozilla/" prefix.
|
||||||
auto user_agent_string = ResourceLoader::the().user_agent();
|
auto user_agent_string = ResourceLoader::the().user_agent();
|
||||||
|
|
||||||
auto trail = user_agent_string.substring_view(strlen("Mozilla/"), user_agent_string.length() - strlen("Mozilla/"));
|
auto trail = MUST(user_agent_string.substring_from_byte_offset(strlen("Mozilla/"), user_agent_string.bytes().size() - strlen("Mozilla/")));
|
||||||
|
|
||||||
// If the navigator compatibility mode is Chrome or WebKit
|
// If the navigator compatibility mode is Chrome or WebKit
|
||||||
// NOTE: We are using Chrome for now. Make sure to update all APIs if you add a toggle for this.
|
// NOTE: We are using Chrome for now. Make sure to update all APIs if you add a toggle for this.
|
||||||
|
@ -33,7 +33,7 @@ DeprecatedString NavigatorIDMixin::app_version() const
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator-platform
|
// https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator-platform
|
||||||
DeprecatedString NavigatorIDMixin::platform() const
|
String NavigatorIDMixin::platform() const
|
||||||
{
|
{
|
||||||
// Must return a string representing the platform on which the browser is executing (e.g. "MacIntel", "Win32",
|
// Must return a string representing the platform on which the browser is executing (e.g. "MacIntel", "Win32",
|
||||||
// "Linux x86_64", "Linux armv81") or, for privacy and compatibility, a string that is commonly returned on another
|
// "Linux x86_64", "Linux armv81") or, for privacy and compatibility, a string that is commonly returned on another
|
||||||
|
@ -44,7 +44,7 @@ DeprecatedString NavigatorIDMixin::platform() const
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator-useragent
|
// https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator-useragent
|
||||||
DeprecatedString NavigatorIDMixin::user_agent() const
|
String NavigatorIDMixin::user_agent() const
|
||||||
{
|
{
|
||||||
// Must return the default `User-Agent` value.
|
// Must return the default `User-Agent` value.
|
||||||
return ResourceLoader::the().user_agent();
|
return ResourceLoader::the().user_agent();
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/DeprecatedString.h>
|
#include <AK/String.h>
|
||||||
|
|
||||||
namespace Web::HTML {
|
namespace Web::HTML {
|
||||||
|
|
||||||
|
@ -17,31 +17,31 @@ public:
|
||||||
// implementers are strongly urged to include as little information in this API as possible.
|
// implementers are strongly urged to include as little information in this API as possible.
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator-appcodename
|
// https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator-appcodename
|
||||||
DeprecatedString app_code_name() const { return "Mozilla"sv; }
|
String app_code_name() const { return "Mozilla"_string; }
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator-appcodename
|
// https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator-appcodename
|
||||||
DeprecatedString app_name() const { return "Netscape"sv; }
|
String app_name() const { return "Netscape"_string; }
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator-appversion
|
// https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator-appversion
|
||||||
DeprecatedString app_version() const;
|
String app_version() const;
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator-platform
|
// https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator-platform
|
||||||
DeprecatedString platform() const;
|
String platform() const;
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator-product
|
// https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator-product
|
||||||
DeprecatedString product() const { return "Gecko"sv; }
|
String product() const { return "Gecko"_string; }
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator-productsub
|
// https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator-productsub
|
||||||
DeprecatedString product_sub() const { return "20030107"sv; } // Compatibility mode "Chrome"
|
String product_sub() const { return "20030107"_string; } // Compatibility mode "Chrome"
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator-useragent
|
// https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator-useragent
|
||||||
DeprecatedString user_agent() const;
|
String user_agent() const;
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator-vendor
|
// https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator-vendor
|
||||||
DeprecatedString vendor() const { return "Google Inc."sv; } // Compatibility mode "Chrome"
|
String vendor() const { return "Google Inc."_string; } // Compatibility mode "Chrome"
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator-vendorsub
|
// https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator-vendorsub
|
||||||
DeprecatedString vendor_sub() const { return ""sv; }
|
String vendor_sub() const { return String {}; }
|
||||||
|
|
||||||
// NOTE: If the navigator compatibility mode is Gecko, then the user agent must also support the following partial interface:
|
// NOTE: If the navigator compatibility mode is Gecko, then the user agent must also support the following partial interface:
|
||||||
// bool taint_enabled()
|
// bool taint_enabled()
|
||||||
|
|
|
@ -59,8 +59,8 @@ ErrorOr<NonnullRefPtr<ResourceLoader>> ResourceLoader::try_create(NonnullRefPtr<
|
||||||
|
|
||||||
ResourceLoader::ResourceLoader(NonnullRefPtr<ResourceLoaderConnector> connector)
|
ResourceLoader::ResourceLoader(NonnullRefPtr<ResourceLoaderConnector> connector)
|
||||||
: m_connector(move(connector))
|
: m_connector(move(connector))
|
||||||
, m_user_agent(default_user_agent)
|
, m_user_agent(MUST(String::from_utf8(default_user_agent)))
|
||||||
, m_platform(default_platform)
|
, m_platform(MUST(String::from_utf8(default_platform)))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -315,7 +315,7 @@ void ResourceLoader::load(LoadRequest& request, SuccessCallback success_callback
|
||||||
auto proxy = ProxyMappings::the().proxy_for_url(url);
|
auto proxy = ProxyMappings::the().proxy_for_url(url);
|
||||||
|
|
||||||
HashMap<DeprecatedString, DeprecatedString> headers;
|
HashMap<DeprecatedString, DeprecatedString> headers;
|
||||||
headers.set("User-Agent", m_user_agent);
|
headers.set("User-Agent", m_user_agent.to_deprecated_string());
|
||||||
headers.set("Accept-Encoding", "gzip, deflate, br");
|
headers.set("Accept-Encoding", "gzip, deflate, br");
|
||||||
|
|
||||||
for (auto& it : request.headers()) {
|
for (auto& it : request.headers()) {
|
||||||
|
|
|
@ -123,11 +123,11 @@ public:
|
||||||
|
|
||||||
int pending_loads() const { return m_pending_loads; }
|
int pending_loads() const { return m_pending_loads; }
|
||||||
|
|
||||||
DeprecatedString const& user_agent() const { return m_user_agent; }
|
String const& user_agent() const { return m_user_agent; }
|
||||||
void set_user_agent(DeprecatedString const& user_agent) { m_user_agent = user_agent; }
|
void set_user_agent(String user_agent) { m_user_agent = move(user_agent); }
|
||||||
|
|
||||||
DeprecatedString const& platform() const { return m_platform; }
|
String const& platform() const { return m_platform; }
|
||||||
void set_platform(DeprecatedString const& platform) { m_platform = platform; }
|
void set_platform(String platform) { m_platform = move(platform); }
|
||||||
|
|
||||||
void clear_cache();
|
void clear_cache();
|
||||||
void evict_from_cache(LoadRequest const&);
|
void evict_from_cache(LoadRequest const&);
|
||||||
|
@ -142,8 +142,8 @@ private:
|
||||||
|
|
||||||
HashTable<NonnullRefPtr<ResourceLoaderConnectorRequest>> m_active_requests;
|
HashTable<NonnullRefPtr<ResourceLoaderConnectorRequest>> m_active_requests;
|
||||||
NonnullRefPtr<ResourceLoaderConnector> m_connector;
|
NonnullRefPtr<ResourceLoaderConnector> m_connector;
|
||||||
DeprecatedString m_user_agent;
|
String m_user_agent;
|
||||||
DeprecatedString m_platform;
|
String m_platform;
|
||||||
Optional<Page&> m_page {};
|
Optional<Page&> m_page {};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -451,7 +451,7 @@ void ConnectionFromClient::debug_request(DeprecatedString const& request, Deprec
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request == "spoof-user-agent") {
|
if (request == "spoof-user-agent") {
|
||||||
Web::ResourceLoader::the().set_user_agent(argument);
|
Web::ResourceLoader::the().set_user_agent(MUST(String::from_deprecated_string(argument)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue