mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
LibWeb: Add an Internals API to trigger a user-activated (trusted) event
Some DOM APIs are restricted to user-activated events. For example, you can't just invoke `navigator.clipboard.writeText` from JS - it has to be accompanied by a user gesture, such as a mouse-down event. This adds an Internals API to simulate such a gesture.
This commit is contained in:
parent
6761791c9a
commit
78d455e231
Notes:
sideshowbarker
2024-07-17 03:14:39 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/78d455e231 Pull-request: https://github.com/SerenityOS/serenity/pull/21878
3 changed files with 13 additions and 0 deletions
|
@ -8,6 +8,8 @@
|
|||
#include <LibWeb/Bindings/InternalsPrototype.h>
|
||||
#include <LibWeb/Bindings/Intrinsics.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/DOM/Event.h>
|
||||
#include <LibWeb/DOM/EventTarget.h>
|
||||
#include <LibWeb/HTML/BrowsingContext.h>
|
||||
#include <LibWeb/HTML/Window.h>
|
||||
#include <LibWeb/Internals/Internals.h>
|
||||
|
@ -58,4 +60,10 @@ JS::Object* Internals::hit_test(double x, double y)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<bool> Internals::dispatch_user_activated_event(DOM::EventTarget& target, DOM::Event& event)
|
||||
{
|
||||
event.set_is_trusted(true);
|
||||
return target.dispatch_event(event);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -21,6 +21,8 @@ public:
|
|||
void gc();
|
||||
JS::Object* hit_test(double x, double y);
|
||||
|
||||
WebIDL::ExceptionOr<bool> dispatch_user_activated_event(DOM::EventTarget&, DOM::Event& event);
|
||||
|
||||
private:
|
||||
explicit Internals(JS::Realm&);
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
#import <DOM/EventTarget.idl>
|
||||
|
||||
[Exposed=Nobody] interface Internals {
|
||||
|
||||
undefined signalTextTestIsDone();
|
||||
undefined gc();
|
||||
object hitTest(double x, double y);
|
||||
boolean dispatchUserActivatedEvent(EventTarget target, Event event);
|
||||
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue