Skip to content

Commit

Permalink
LibWeb: Implement Navigator.doNotTrack
Browse files Browse the repository at this point in the history
  • Loading branch information
jamierocks authored and awesomekling committed Jul 4, 2024
1 parent e342542 commit 61e616c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Userland/Libraries/LibWeb/HTML/Navigator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <LibWeb/HTML/Navigator.h>
#include <LibWeb/HTML/Scripting/Environments.h>
#include <LibWeb/HTML/Window.h>
#include <LibWeb/Loader/ResourceLoader.h>
#include <LibWeb/Page/Page.h>

namespace Web::HTML {
Expand Down Expand Up @@ -100,4 +101,16 @@ WebIDL::Long Navigator::max_touch_points()
return 0;
}

// https://www.w3.org/TR/tracking-dnt/#dom-navigator-donottrack
Optional<FlyString> Navigator::do_not_track() const
{
// The value is null if no DNT header field would be sent (e.g., because a tracking preference is not
// enabled and no user-granted exception is applicable); otherwise, the value is a string beginning with
// "0" or "1", possibly followed by DNT-extension characters.
if (ResourceLoader::the().enable_do_not_track())
return "1"_fly_string;

return {};
}

}
2 changes: 2 additions & 0 deletions Userland/Libraries/LibWeb/HTML/Navigator.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class Navigator : public Bindings::PlatformObject
[[nodiscard]] JS::NonnullGCPtr<Clipboard::Clipboard> clipboard();
[[nodiscard]] JS::NonnullGCPtr<UserActivation> user_activation();

Optional<FlyString> do_not_track() const;

static WebIDL::Long max_touch_points();

virtual ~Navigator() override;
Expand Down
3 changes: 3 additions & 0 deletions Userland/Libraries/LibWeb/HTML/Navigator.idl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ interface Navigator {

// https://html.spec.whatwg.org/multipage/interaction.html#useractivation
[SameObject] readonly attribute UserActivation userActivation;

// https://www.w3.org/TR/tracking-dnt/#dom-navigator-donottrack
readonly attribute DOMString? doNotTrack;
};

// NOTE: As NavigatorContentUtils, NavigatorCookies, NavigatorPlugins, and NavigatorAutomationInformation
Expand Down

0 comments on commit 61e616c

Please sign in to comment.