Commit graph

70 commits

Author SHA1 Message Date
MacDue
35612c6a7f AK+Everywhere: Change URL::path() to serialize_path()
This now defaults to serializing the path with percent decoded segments
(which is what all callers expect), but has an option not to. This fixes
`file://` URLs with spaces in their paths.

The name has been changed to serialize_path() path to make it more clear
that this method will generate a new string each call (except for the
cannot_be_a_base_url() case). A few callers have then been updated to
avoid repeatedly calling this function.
2023-04-15 06:37:04 +02:00
Timothy Flynn
69e8216f2c LibWeb: Do not use OS error codes in the error callback for file:// URLs
The error code passed here is expected to be an HTTP error code. Passing
errno codes does not make sense in that context.
2023-04-04 22:41:20 +01:00
Andreas Kling
652676fdc1 LibWeb: Make ResourceLoader insert a Content-Type header for file://
We make a guess using the MIME type guessing API in LibCore. This frees
clients of this code from having to do the guessing.
2023-03-22 23:34:32 +00:00
Andreas Kling
20132da88d LibWeb: Don't treat erroring subresource loads as success
If a subresource fails to load, we don't care that we got some custom
404 page. The subresource should still be considered failed.

This is an ad-hoc solution that unbreaks Acid2. This code will
eventually be replaced by fetch mechanisms.
2023-03-15 23:29:00 +01:00
Andreas Kling
3435820e1f LibWeb: Render HTML content if present for HTTP error pages
If an HTTP response fails with an error code (e.g 403) but still has
body content, we now render the content.

We only fall back to our own built-in error page if there's no body.
2023-02-24 19:15:49 +01:00
Tim Schumacher
606a3982f3 LibCore: Move Stream-based file into the Core namespace 2023-02-13 00:50:07 +00:00
Tim Schumacher
d43a7eae54 LibCore: Rename File to DeprecatedFile
As usual, this removes many unused includes and moves used includes
further down the chain.
2023-02-13 00:50:07 +00:00
Timothy Flynn
4a916cd379 Everywhere: Remove needless copies of Error / ErrorOr instances
Either take the underlying objects with release_* methods or move() the
instances around.
2023-02-10 09:08:52 +00:00
Timothy Flynn
96f409ec1e LibWeb+WebContent: Do not reference-count file request objects
There is currently a memory leak with these file request objects due to
the callback on_file_request_finish referencing itself in its capture
list. This object does not need to be reference counted or allocated on
the heap. It is only ever stored in a HashMap until a response is
received from the browser, and it is not shared.
2023-02-01 14:04:44 +00:00
Luke Wilde
6d188d72c0 LibWeb: Store cookies for every HTTP response
As per Fetch, we are supposed to store cookies from Set-Cookie as soon
as we receive response headers for any HTTP response, even in error
cases.

Required by Twitter to login, as it sets cookies via XHR.
2022-12-30 21:56:54 -05:00
Tim Schumacher
ed4c2f2f8e LibCore: Rename Stream::read_all to read_until_eof
This generally seems like a better name, especially if we somehow also
need a better name for "read the entire buffer, but not the entire file"
somewhere down the line.
2022-12-12 14:16:42 +01:00
Linus Groh
57dc179b1f Everywhere: Rename to_{string => deprecated_string}() where applicable
This will make it easier to support both string types at the same time
while we convert code, and tracking down remaining uses.

One big exception is Value::to_string() in LibJS, where the name is
dictated by the ToString AO.
2022-12-06 08:54:33 +01:00
Linus Groh
6e19ab2bbc AK+Everywhere: Rename String to DeprecatedString
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 :^)
2022-12-06 08:54:33 +01:00
MacDue
8a5d2be617 Everywhere: Remove unnecessary mutable attributes from lambdas
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.
2022-11-19 14:37:31 +00:00
Andrew Kaster
828441852f Everywhere: Replace uses of __serenity__ with AK_OS_SERENITY
Now that we have OS macros for essentially every supported OS, let's try
to use them everywhere.
2022-10-10 12:23:12 +02:00
Linus Groh
398e44b27b LibWeb: Pass status code to ResourceLoader error callback when available 2022-10-05 09:12:59 +01:00
networkException
4230dbbb21 AK+Everywhere: Replace "protocol" with "scheme" url helpers
URL had properly named replacements for protocol(), set_protocol() and
create_with_file_protocol() already. This patch removes these function
and updates all call sites to use the functions named according to the
specification.

See https://url.spec.whatwg.org/#concept-url-scheme
2022-09-29 09:39:04 +01:00
Andreas Kling
9567e211e7 LibWeb+WebContent: Add abstraction layer for event loop and timers
Instead of using Core::EventLoop and Core::Timer directly, LibWeb now
goes through a Web::Platform abstraction layer instead.

This will allow us to plug in Qt's event loop (and QTimer) over in
Ladybird, to avoid having to deal with multiple event loops.
2022-09-07 20:30:31 +02:00
Andreas Kling
c964a6b548 LibWeb: Paper over a VERIFY() crash in ResourceLoader for now 2022-07-17 14:11:36 +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
92a3803066 LibWeb: Add timeout_callback to ResourceLoader::load() 2022-07-03 13:26:32 +02:00
Kenneth Myhra
07b6c7114b LibWeb: Use a single shot timer instead of an ordinary repetitive timer 2022-07-03 13:26:32 +02:00
Lucas CHOLLET
662711fa26 Browser+LibWeb+WebContent: Allow Browser to load local files
To achieve this goal:
 - The Browser unveils "/tmp/portal/filesystemaccess"
 - Pass the page through LoadRequest => ResourceLoader
 - ResourceLoader requests a file to the FileSystemAccessServer via IPC
 - OutOfProcessWebView handles it and sends a file descriptor back to
 the Page.
2022-06-27 20:22:15 +01:00
Andreas Kling
c03a0e7260 LibWeb: Fix unsafe capture of ref-to-local when setting up load timeout
We were capturing a reference to a stack local and then persisting the
closure, causing it to dereference a long-gone object when invoked.
2022-06-23 20:37:29 +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
Luke Wilde
210c3795f9 LibWeb: Apply content filter to DNS prefetch and pre-connect
Performing DNS prefetch or pre-connect on filtered URLs is wasteful,
as we would block any actual use further down the line.

A bunch of websites perform DNS prefetch and/or pre-connect to trackers
as well, for example:
```
prefetch DNS for 'https://adserver-us.adtech.advertising.com/'
prefetch DNS for 'https://secure.adnxs.com/'
prefetch DNS for 'https://bidder.criteo.com/'
prefetch DNS for 'https://static.criteo.net/'
prefetch DNS for 'https://cdn.krxd.net/'
prefetch DNS for 'https://widgets.outbrain.com/'
prefetch DNS for 'https://images.outbrain.com/'
prefetch DNS for 'https://log.outbrain.com/
prefetch DNS for 'https://amplifypixel.outbrain.com/'
prefetch DNS for 'https://odb.outbrain.com/'
prefetch DNS for 'https://js-sec.indexww.com/'
prefetch DNS for 'https://as-sec.casalemedia.com/'
prefetch DNS for 'https://as.casalemedia.com/'
prefetch DNS for 'https://sofia.trustx.org/'
prefetch DNS for 'https://c.amazon-adsystem.com/'
prefetch DNS for 'https://s.amazon-adsystem.com/'
prefetch DNS for 'https://aax.amazon-adsystem.com/'
prefetch DNS for 'https://t.teads.tv/'
prefetch DNS for 'https://beacon.krxd.net/'
pre-connect to 'https://www.google-analytics.com/'
pre-connect to 'https://www.googletagmanager.com/'
```
2022-06-10 12:15:37 +01:00
Michiel Visser
7278ad761e LibHTTP+LibWeb: Accept Brotli encoded responses 2022-05-21 22:41:40 +02:00
DexesTTP
c00ae53b66 LibWeb: Abstract the LibProtocol ResourceLoader connection
This is the final component that required LibProtocol as a dependency
of LibWeb. With this, we can now remove the dependency, and LibWeb no
longer requires IPC to work :^)
2022-05-15 12:17:36 +02:00
Sam Atkins
1f82beded3 LibWeb: Make about:blank load correctly
- Don't treat an empty `about:blank` resource as an error.
- Give `about:` urls a content-type so `FrameLoader::parse_document()`
  won't reject them.
2022-05-13 16:25:33 +02:00
DexesTTP
6027ab9e12 LibWeb: Only generate ResourceLoader signposts while on Serenity 2022-05-06 14:11:03 +02:00
Andreas Kling
9ed5a14af2 LibWeb: Remove unused ResourceLoader::load_sync()
There are no remaining users of this API, everyone has been migrated
to asynchronous resource loading.
2022-04-10 01:37:45 +02:00
Andreas Kling
f21eb90294 LibWeb: Remove debug spam about proxy configuration lookups 2022-04-09 14:50:05 +02:00
Ali Mohammad Pur
a42e03b01a Browser+LibWeb+WebContent: Implement per-URL-pattern proxies
...at least for SOCKS5.
2022-04-09 12:21:43 +02:00
Idan Horowitz
086969277e Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
Simon Wanner
3d80d38954 LibWeb: Emit signposts for resource loads 2022-03-24 14:35:47 +01:00
Timothy Flynn
20eb441cba LibWeb: Evict replaced Resource objects from cache
When a Resource is converted to an ImageResource, evict the original
resource from cache. The original resource's data has been moved, so on
a warm reload of a page, when that resource is loaded from cache, it
would not have any data to actually show.
2022-03-23 21:26:35 +01:00
Andreas Kling
252ed8ad18 LibWeb: Fail resource loads on HTTP 4xx or 5xx error
This fixes an issue on ACID3 where failing image loads with body content
would still get displayed.
2022-03-09 16:43:00 +01:00
Andreas Kling
378bca8b0c LibWeb: Make debug logging of resource load errors red instead of green
Red is a bit more suspicious than green, after all. :^)
2022-02-04 00:16:25 +01:00
Sam Atkins
c388a879d7 AK+Userland: Make AK::decode_base64 return ErrorOr 2022-01-24 22:36:09 +01:00
sin-ack
2e1bbcb0fa LibCore+LibIPC+Everywhere: Return Stream::LocalSocket from LocalServer
This change unfortunately cannot be atomically made without a single
commit changing everything.

Most of the important changes are in LibIPC/Connection.cpp,
LibIPC/ServerConnection.cpp and LibCore/LocalServer.cpp.

The notable changes are:
- IPCCompiler now generates the decode and decode_message functions such
  that they take a Core::Stream::LocalSocket instead of the socket fd.
- IPC::Decoder now uses the receive_fd method of LocalSocket instead of
  doing system calls directly on the fd.
- IPC::ConnectionBase and related classes now use the Stream API
  functions.
- IPC::ServerConnection no longer constructs the socket itself; instead,
  a convenience macro, IPC_CLIENT_CONNECTION, is used in place of
  C_OBJECT and will generate a static try_create factory function for
  the ServerConnection subclass. The subclass is now responsible for
  passing the socket constructed in this function to its
  ServerConnection base; the socket is passed as the first argument to
  the constructor (as a NonnullOwnPtr<Core::Stream::LocalServer>) before
  any other arguments.
- The functionality regarding taking over sockets from SystemServer has
  been moved to LibIPC/SystemServerTakeover.cpp. The Core::LocalSocket
  implementation of this functionality hasn't been deleted due to my
  intention of removing this class in the near future and to reduce
  noise on this (already quite noisy) PR.
2022-01-15 13:29:48 +03:30
Andreas Kling
a7f1f1c34b LibCore: Use ErrorOr<T> for Core::File::open() 2021-11-08 00:35:27 +01:00
Ben Wiederhake
cb868cfa41 AK+Everywhere: Make Base64 decoding fallible 2021-10-23 19:16:40 +01:00
Ali Mohammad Pur
f0e2c517fc LibWeb: Implement the dns-prefetch and preconnect link relationships 2021-09-28 22:32:31 +02:00
Andreas Kling
fccf0a466b LibWeb: Log resource load success before invoking success callback
The success callback may trigger JavaScript execution, causing resource
load times to appear much longer than they actually are. :^)
2021-09-22 14:35:13 +02:00
Ali Mohammad Pur
e780ee2832 LibWeb: Avoid introducing a reference cycle in ResourceLoader::load()
Previously we were kinda sorta resolving the reference cycle, but let's
just keep the requests in a hashtable instead of relying on hard to
track refcount tricks.
Fixes #7314.
2021-09-19 21:10:23 +04:30
Andreas Kling
d69e4f9ca7 LibWeb: Don't dump full data URLs in ResourceLoader logging
Some pages use *really* large data URLs. :^)
2021-09-16 01:39:47 +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
Brian Gianforcaro
189066d91d LibWeb: Log resource loading success, failure, and duration
When debugging why your website isn't loading in LibWeb the
resource loader is a blind spot as we don't have much logging
except on certain error paths. This can lead to confusing situations
where the browser just appears to hang.

This changes attempts to fix that by adding common success and
failure logging handlers so all resource loading outcomes can
are logged.
2021-09-12 16:39:23 +02:00
Brian Gianforcaro
bca8707e15 LibWeb: Start tracking elapsed time when a resource is loaded 2021-09-12 16:39:23 +02:00