The previous iteration of this API was somewhat odd and rough in random
places, which degraded usability and made less than perfect sense.
This commit reworks the API to be a little closer to more
conventional promise APIs (a la javascript promises).
Also adds a test to ensure the class even works.
Previously it was possible to have following sequence of calls
while destroying a session:
1. `WebContentConnection::die()` calls `Client::close_session()`
2. `Client::close_session()` removes a session from active sessions
map which causes session destructor call.
3. Session destructor calls `Client::close_session()` to remove a
session from active sessions.
With `stop()` method inlined into destructor `close_session()` need
to be called just once while destroying a session.
These steps now have more than one caller; specifically, they may be
called from the Delete Session and Close Window endpoints. The session
was only removed from the active session map for the former endpoint.
Instead, let's more accurately handle removing the session where the
spec tells us to, so that all callers properly perform this step.
WebDriver::Session::close_window may invoke Session::stop, which needs
the WebContent connection to still exist. Do not remove the window's
handle (thus destroying the connection) until it is no longer needed.
With current architecture every window has its own WebContent process
and there is one WebDriver process that is responsible for talking to
all opened windows. It thus make sense to manage open windows from
WebDriver process instead of WebContent process that is not supposed
to know about all other opened WebContent processes.
This mostly reverts 826d5f8f9a but also
adds `web_content_connection` to window structure and window id
generation (currently out of spec).
With these changes `get_window_handles`, `switch_to_window` and
`close_window` start to actually switch, close and returned handles
of currently opened windows.
This moves the actual launching of browser windows to the WebDriver main
file. This will allow Ladybird to specify its own callback and re-use
Serenity's Session class.
We have a new, improved string type coming up in AK (OOM aware, no null
state), and while it's going to use UTF-8, the name UTF8String is a
mouthful - so let's free up the String name by renaming the existing
class.
Making the old one have an annoying name will hopefully also help with
quick adoption :^)
These lambdas were marked mutable as they captured a Ptr wrapper
class by value, which then only returned const-qualified references
to the value they point from the previous const pointer operators.
Nothing is actually mutating in the lambdas state here, and now
that the Ptr operators don't add extra const qualifiers these
can be removed.
This moves Get Window Handle, Close Window, and Get Window Handles over
to WebContent so they may be implemented closer to the spec and be used
by Ladybird.
We are expected to return the list of open handles after closing the
current handle. Also just return a WebDriver::Response instead of a
wrapped Error variant.
WebDriver now only has an IPC connection to WebContent. WebDriver still
launches the browser, but now when the session ends, we simply send a
SIGTERM signal to the browser.
There are a couple changes here from the existing Get All Cookies
implementation.
1. Previously, WebDriver actually returned *all* cookies in the cookie
jar. The spec dictates that we only return cookies that match the
document's URL. Specifically, it calls out that we must run just the
first step of RFC 6265 section 5.4 to perform domain matching.
This change adds a special mode to our implementation of that section
to skip the remaining steps.
2. We now fill in the SameSite cookie attribute when serializing the
cookie to JSON (this was a trival FIXME that didn't get picked up
when SameSite was implemented).