Commit graph

56 commits

Author SHA1 Message Date
Linus Groh
22a627fc1a LibWeb: Move Origin into the HTML namespace
Origin is defined in the HTML Standard, and therefore belongs into the
HTML directory and namespace in LibWeb.
https://html.spec.whatwg.org/multipage/origin.html#origin
2022-07-14 00:42:26 +01:00
Ankur Sundara
400ef9913e LibWeb: Fix regexes for XHR
Regexes for is_method and is_header_name did not escape the "-"
and unintentionally allowed for "," to be part of a
method/header name, not following the spec.
This commit escapes the "-" character to follow the spec.
2022-07-13 22:52:10 +02:00
sin-ack
3f3f45580a Everywhere: Add sv suffix to strings relying on StringView(char const*)
Each of these strings would previously rely on StringView's char const*
constructor overload, which would call __builtin_strlen on the string.
Since we now have operator ""sv, we can replace these with much simpler
versions. This opens the door to being able to remove
StringView(char const*).

No functional changes.
2022-07-12 23:11:35 +02:00
Kenneth Myhra
247951e09c LibWeb: Add URLSearchParams as part of union type for XHR::send()
This patch adds support for URLSearchParams to XHR::send() and
introduces the union type XMLHttpRequestBodyInit.

XHR::send() now has support for String and URLSearchParams.
2022-07-08 12:37:01 +02:00
Kenneth Myhra
445c3050d4 LibWeb: Wire up XHR::ontimeout event 2022-07-03 13:26:32 +02:00
Kenneth Myhra
c805987329 LibWeb: Add timeout functionality to ResourceLoader
Add timeout functionality to ResourceLoader and use it from
XMLHttpRequest.
2022-06-21 10:29:14 +01:00
Kenneth Myhra
8b42c05648 LibWeb: Add XMLHttpRequest::timeout setter and getter 2022-06-21 10:29:14 +01:00
Luke Wilde
1f820f8840 LibWeb: Add support for the <base> element changing the base URL
Used by Google seemingly almost all around account sign in and
management. The modern sign in page has this near the beginning:
```html
<base href="https://accounts.google.com">
```
All of the XHRs performed by sign in are relative URLs to this
base URL. Previously we ignored this and did it relative to the
current URL, causing the XHRs to 404 and sign in to fall apart.

I presume they do this because you can access the sign in page
from multiple endpoints, such as `/ServiceLogin` and
`/o/oauth2/auth/identifier`
2022-06-19 16:35:43 +01:00
Kenneth Myhra
a5514fece9 LibWeb: Move XHR::open() towards more spec compliance
Following FIXMEs have been addressed:
- 1. Let settingsObject be this’s relevant settings object.
- 2. If settingsObject has a responsible document and it is not fully
     active, then throw an "InvalidStateError" DOMException.
- 6. Let parsedURL be the result of parsing url with settingsObject's
     API base URL and settingsObject’s API URL character encoding.
- 8. If the async argument is omitted, set async to true, and set
     username and password to null.
2022-04-23 18:05:55 +02:00
Kenneth Myhra
01194053b7 LibWeb: XHR set_request_header() validate header name and value 2022-04-23 18:05:55 +02:00
Kenneth Myhra
1ca1a73d67 LibWeb: Trim leading and trailing HTTP whitespace bytes
The XMLHttpRequest specification specifices that header values should be
normalized by trimming leading and trailing HTTP whitespace bytes.
2022-04-23 18:05:55 +02:00
Kenneth Myhra
fccea8888e LibWeb: Use a more restrictive regex for method token production
This changes the regular expression for is_method() to a more
restrictive pattern.
2022-04-23 18:05:55 +02:00
Kenneth Myhra
053bcd4859 LibWeb: Combine headers in XMLHttpRequest::set_request_header
This patch adds support for combining header values, in addtion it adds
spec comments for readability.
2022-04-23 18:05:55 +02:00
Kenneth Myhra
69f05a66fc LibWeb: Add XMLHttpRequest::open() overload
This adds the XMLHttpRequest::open(String, String, bool, String, String)
overload.

The following FIXMEs has been implemented:
- If method is not a method, then throw a "SyntaxError" DOMException.
- If the username argument is not null, set the username given parsedURL
  and username.
- If the password argument is not null, set the password given parsedURL
  and password.
- Set this’s synchronous flag if async is false; otherwise unset this’s
  synchronous flag.

Spec comments has also been updated.
2022-04-05 22:33:44 +02:00
Idan Horowitz
086969277e Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
Hendiadyoin1
6a95df2526 LibTextCodec: Don't allocate Strings on encoding normalisation
This ripples down to LibWeb's HTML and XHR decoders, which therefore
become less allocation heavy.
2022-03-21 10:48:17 +01:00
Lenny Maiorani
c37820b898 Libraries: Use default constructors/destructors in LibWeb
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#cother-other-default-operation-rules

"The compiler is more likely to get the default semantics right and
you cannot implement these functions better than the compiler."
2022-03-17 17:23:49 +00:00
Linus Groh
1422bd45eb LibWeb: Move Window from DOM directory & namespace to HTML
The Window object is part of the HTML spec. :^)
https://html.spec.whatwg.org/multipage/window-object.html
2022-03-08 00:30:30 +01:00
Andreas Kling
e76e8e22b5 LibWeb: Separate "event listener" from "EventListener"
I can't imagine how this happened, but it seems we've managed to
conflate the "event listener" and "EventListener" concepts from the DOM
specification in some parts of the code.

We previously had two things:

    - DOM::EventListener
    - DOM::EventTarget::EventListenerRegistration

DOM::EventListener was roughly the "EventListener" IDL type,
and DOM::EventTarget::EventListenerRegistration was roughly the "event
listener" concept. However, they were used interchangeably (and
incorrectly!) in many places.

After this patch, we now have:

    - DOM::IDLEventListener
    - DOM::DOMEventListener

DOM::IDLEventListener is the "EventListener" IDL type,
and DOM::DOMEventListener is the "event listener" concept.

This patch also updates the addEventListener() and removeEventListener()
functions to follow the spec more closely, along with the "inner invoke"
function in our EventDispatcher.
2022-02-16 22:21:45 +01:00
Ali Mohammad Pur
385b07dcda LibWeb: Implement responseType and response for XHR
This makes us capable of loading non-utf8 content via XHR.
2022-02-16 22:48:32 +03:30
Linus Groh
6d0e6e3811 LibWeb: Rename Origin::is_same() to Origin::is_same_origin()
The HTML Origin spec has two similar but slightly different concepts of
origin equality: "same origin" and "same origin-domain". Let's be
explicit with the naming here :^)
Also add spec comments.
2022-02-15 01:31:03 +01:00
Luke Wilde
28f0193d9b LibWeb: Decode XHR text with the specified charset in the MIME type
The MIME type can come from either the Content-Type header in the
response header list, or the overridden MIME type passed into
overrideMimeType()

This is required by Google Maps, which downloads blobs encoded
in x-user-defined format.
2022-02-12 12:53:28 +01:00
Luke Wilde
4ccade42b7 LibWeb: Implement XMLHttpRequest.overrideMimeType
This allows you to ignore the Content-Type returned by the server and
always parse the content as if it's the given MIME type.

This will currently be used for allowing you to override the charset
of text responses.
2022-02-12 12:53:28 +01:00
Luke Wilde
5aacec65ab LibWeb: Rewrite EventTarget to more closely match the spec
This isn't perfect (especially the global object situation in
activate_event_handler), but I believe it's in a much more complete
state now :^)

This fixes the issue of crashing in prepare_for_ordinary_call with the
`i < m_size` crash, as it now uses the IDL callback functions which
requires the Environment Settings Object. The environment settings
object for the callback is fetched at the time the callback is created,
for example, WrapperGenerator gets the incumbent settings object for
the callback at the time of wrapping. This allows us to remove passing
in ScriptExecutionContext into EventTarget's constructor.

With this, we can now drop ScriptExecutionContext.
2022-02-08 17:47:44 +00:00
Sam Atkins
45cf40653a Everywhere: Convert ByteBuffer factory methods from Optional -> ErrorOr
Apologies for the enormous commit, but I don't see a way to split this
up nicely. In the vast majority of cases it's a simple change. A few
extra places can use TRY instead of manual error checking though. :^)
2022-01-24 22:36:09 +01:00
Andreas Kling
a7b1c7eb16 LibWeb: Don't send a request body in XMLHttpRequest GET or HEAD 2021-10-04 00:06:48 +02:00
Idan Horowitz
4d71f22673 LibWeb: Add the missing ProgressEvent IDL constructor 2021-10-01 20:14:45 +02:00
Andreas Kling
ed5c807c99 LibWeb: Allow passing a (String) body to XMLHttpRequest.send()
This patch implements the simplest form of send(body): strings.
2021-09-27 01:56:08 +02:00
Andreas Kling
0ee457dfdf LibWeb: Provide a default DOM::EventTarget::dispatch_event()
All EventTarget subclasses except Window do the same exact thing in
their overrides, so let's just share an implementation in the base.
2021-09-25 23:36:43 +02:00
Andreas Kling
7ef4d75716 LibWeb: Implement XMLHttpRequest.getAllResponseHeaders() 2021-09-19 22:34:44 +02:00
Andreas Kling
ee8a1a9b3f LibWeb: Keep XMLHttpRequest alive while handling load/error events
A weakly held XHR object is not guaranteed to remain alive after
running arbitrary JavaScript, so let's make sure we take a strong
reference in the ResourceLoader callbacks here.
2021-09-19 15:02:27 +02:00
Andreas Kling
398a95c3c9 LibWeb: Remove unnecessary WeakPtr creation in XMLHttpRequest::send() 2021-09-19 14:59:02 +02:00
Andreas Kling
dc8707527f LibWeb: Implement XMLHttpRequest.onreadystatechange 2021-09-19 01:43:27 +02:00
Idan Horowitz
d6cfa34667 AK: Make URL::m_port an Optional<u16>, Expose raw port getter
Our current way of signalling a missing port with m_port == 0 was
lacking, as 0 is a valid port number in URLs.
2021-09-14 00:14:45 +02:00
Idan Horowitz
4629f2e4ad LibWeb: Add the Web::URL namespace and move URLEncoder to it
This namespace will be used for all interfaces defined in the URL
specification, like URL and URLSearchParams.

This has the unfortunate side-effect of requiring us to use the fully
qualified AK::URL name whenever we want to refer to the AK class, so
this commit also fixes all such references.
2021-09-13 01:43:10 +02:00
Andreas Kling
19de6bb1cc LibWeb+Browser: Add Debug menu action for toggling Same-Origin Policy
Sometimes it's useful to turn off the SOP for testing purposes.
Let's make that easy by having a Debug menu item for it. :^)
2021-09-12 02:13:28 +02:00
Andreas Kling
e1fb8bef09 LibWeb: Rename Document::complete_url() => parse_url()
This better matches the spec nomenclature.
2021-09-09 21:25:10 +02:00
Andreas Kling
90cdeebfb3 LibWeb: Rename DOM::Window::document() => associated_document()
Match the spec nomenclature.
2021-09-09 21:25:10 +02:00
Andreas Kling
d392349b6e LibWeb: Add DOM::Window::page()
This helps us to get from a Window to the containing Page, without
clients having to go through Document.
2021-09-09 21:25:10 +02:00
Ali Mohammad Pur
97e97bccab Everywhere: Make ByteBuffer::{create_*,copy}() OOM-safe 2021-09-06 01:53:26 +02:00
Andreas Kling
ba9d5c4d54 LibJS: Rename Function => FunctionObject 2021-06-27 22:36:04 +02:00
Gunnar Beutner
53d0150827 AK+Userland: Remove nullability feature for the ByteBuffer type
Nobody seems to use this particular feature, in fact there were some
bugs which were uncovered by removing operator bool.
2021-05-16 17:49:42 +02:00
Linus Groh
ebdeed087c Everywhere: Use linusg@serenityos.org for my copyright headers 2021-04-22 22:51:19 +02:00
Brian Gianforcaro
1682f0b760 Everything: Move to SPDX license identifiers in all files.
SPDX License Identifiers are a more compact / standardized
way of representing file license information.

See: https://spdx.dev/resources/use/#identifiers

This was done with the `ambr` search and replace tool.

 ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-22 11:22:27 +02:00
Timothy Flynn
0f47a23e8e LibWeb: Set Cookie header on remaining resource requests 2021-04-15 09:46:49 +02:00
Linus Groh
57ead17d54 LibWeb: Implement XMLHttpRequest.getResponseHeader()
This lets jQuery's AJAX functionality progress further :^)
2021-04-03 16:34:34 +02:00
Linus Groh
288b90a297 LibWeb: Implement XMLHttpRequest.status
This lets jQuery's AJAX functionality progress further :^)
2021-04-03 16:34:34 +02:00
Linus Groh
e02270c5cc LibWeb: Make XMLHttpRequest.open() work with relative URLs 2021-04-03 16:34:34 +02:00
Linus Groh
000ef96613 LibWeb: Pass optional status code to ResourceLoader callbacks
This is needed for XMLHttpRequest, and will certainly be useful for
other things, too.
2021-04-03 16:34:34 +02:00
Linus Groh
14058b6858 LibWeb: Use DOMException in XMLHttpRequest::send() 2021-02-20 09:14:19 +01:00