Skip to content

Commit 6aff55d

Browse files
shannonboothawesomekling
authored andcommitted
LibWeb: Port NavigatorID from DeprecatedString to String
1 parent 0a4586d commit 6aff55d

File tree

5 files changed

+24
-24
lines changed

5 files changed

+24
-24
lines changed

Userland/Libraries/LibWeb/HTML/NavigatorID.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
namespace Web::HTML {
1212

1313
// https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator-appversion
14-
DeprecatedString NavigatorIDMixin::app_version() const
14+
String NavigatorIDMixin::app_version() const
1515
{
1616
// Must return the appropriate string that starts with "5.0 (", as follows:
1717

1818
// Let trail be the substring of default `User-Agent` value that follows the "Mozilla/" prefix.
1919
auto user_agent_string = ResourceLoader::the().user_agent();
2020

21-
auto trail = user_agent_string.substring_view(strlen("Mozilla/"), user_agent_string.length() - strlen("Mozilla/"));
21+
auto trail = MUST(user_agent_string.substring_from_byte_offset(strlen("Mozilla/"), user_agent_string.bytes().size() - strlen("Mozilla/")));
2222

2323
// If the navigator compatibility mode is Chrome or WebKit
2424
// 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
3333
}
3434

3535
// https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator-platform
36-
DeprecatedString NavigatorIDMixin::platform() const
36+
String NavigatorIDMixin::platform() const
3737
{
3838
// Must return a string representing the platform on which the browser is executing (e.g. "MacIntel", "Win32",
3939
// "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
4444
}
4545

4646
// https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator-useragent
47-
DeprecatedString NavigatorIDMixin::user_agent() const
47+
String NavigatorIDMixin::user_agent() const
4848
{
4949
// Must return the default `User-Agent` value.
5050
return ResourceLoader::the().user_agent();

Userland/Libraries/LibWeb/HTML/NavigatorID.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#pragma once
88

9-
#include <AK/DeprecatedString.h>
9+
#include <AK/String.h>
1010

1111
namespace Web::HTML {
1212

@@ -17,31 +17,31 @@ class NavigatorIDMixin {
1717
// implementers are strongly urged to include as little information in this API as possible.
1818

1919
// https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator-appcodename
20-
DeprecatedString app_code_name() const { return "Mozilla"sv; }
20+
String app_code_name() const { return "Mozilla"_string; }
2121

2222
// https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator-appcodename
23-
DeprecatedString app_name() const { return "Netscape"sv; }
23+
String app_name() const { return "Netscape"_string; }
2424

2525
// https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator-appversion
26-
DeprecatedString app_version() const;
26+
String app_version() const;
2727

2828
// https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator-platform
29-
DeprecatedString platform() const;
29+
String platform() const;
3030

3131
// https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator-product
32-
DeprecatedString product() const { return "Gecko"sv; }
32+
String product() const { return "Gecko"_string; }
3333

3434
// https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator-productsub
35-
DeprecatedString product_sub() const { return "20030107"sv; } // Compatibility mode "Chrome"
35+
String product_sub() const { return "20030107"_string; } // Compatibility mode "Chrome"
3636

3737
// https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator-useragent
38-
DeprecatedString user_agent() const;
38+
String user_agent() const;
3939

4040
// https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator-vendor
41-
DeprecatedString vendor() const { return "Google Inc."sv; } // Compatibility mode "Chrome"
41+
String vendor() const { return "Google Inc."_string; } // Compatibility mode "Chrome"
4242

4343
// https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator-vendorsub
44-
DeprecatedString vendor_sub() const { return ""sv; }
44+
String vendor_sub() const { return String {}; }
4545

4646
// NOTE: If the navigator compatibility mode is Gecko, then the user agent must also support the following partial interface:
4747
// bool taint_enabled()

Userland/Libraries/LibWeb/Loader/ResourceLoader.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ ErrorOr<NonnullRefPtr<ResourceLoader>> ResourceLoader::try_create(NonnullRefPtr<
5959

6060
ResourceLoader::ResourceLoader(NonnullRefPtr<ResourceLoaderConnector> connector)
6161
: m_connector(move(connector))
62-
, m_user_agent(default_user_agent)
63-
, m_platform(default_platform)
62+
, m_user_agent(MUST(String::from_utf8(default_user_agent)))
63+
, m_platform(MUST(String::from_utf8(default_platform)))
6464
{
6565
}
6666

@@ -315,7 +315,7 @@ void ResourceLoader::load(LoadRequest& request, SuccessCallback success_callback
315315
auto proxy = ProxyMappings::the().proxy_for_url(url);
316316

317317
HashMap<DeprecatedString, DeprecatedString> headers;
318-
headers.set("User-Agent", m_user_agent);
318+
headers.set("User-Agent", m_user_agent.to_deprecated_string());
319319
headers.set("Accept-Encoding", "gzip, deflate, br");
320320

321321
for (auto& it : request.headers()) {

Userland/Libraries/LibWeb/Loader/ResourceLoader.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,11 @@ class ResourceLoader : public Core::EventReceiver {
123123

124124
int pending_loads() const { return m_pending_loads; }
125125

126-
DeprecatedString const& user_agent() const { return m_user_agent; }
127-
void set_user_agent(DeprecatedString const& user_agent) { m_user_agent = user_agent; }
126+
String const& user_agent() const { return m_user_agent; }
127+
void set_user_agent(String user_agent) { m_user_agent = move(user_agent); }
128128

129-
DeprecatedString const& platform() const { return m_platform; }
130-
void set_platform(DeprecatedString const& platform) { m_platform = platform; }
129+
String const& platform() const { return m_platform; }
130+
void set_platform(String platform) { m_platform = move(platform); }
131131

132132
void clear_cache();
133133
void evict_from_cache(LoadRequest const&);
@@ -142,8 +142,8 @@ class ResourceLoader : public Core::EventReceiver {
142142

143143
HashTable<NonnullRefPtr<ResourceLoaderConnectorRequest>> m_active_requests;
144144
NonnullRefPtr<ResourceLoaderConnector> m_connector;
145-
DeprecatedString m_user_agent;
146-
DeprecatedString m_platform;
145+
String m_user_agent;
146+
String m_platform;
147147
Optional<Page&> m_page {};
148148
};
149149

Userland/Services/WebContent/ConnectionFromClient.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ void ConnectionFromClient::debug_request(DeprecatedString const& request, Deprec
451451
}
452452

453453
if (request == "spoof-user-agent") {
454-
Web::ResourceLoader::the().set_user_agent(argument);
454+
Web::ResourceLoader::the().set_user_agent(MUST(String::from_deprecated_string(argument)));
455455
return;
456456
}
457457

0 commit comments

Comments
 (0)