diff --git a/Userland/Libraries/LibWeb/Loader/FrameLoader.h b/Userland/Libraries/LibWeb/Loader/FrameLoader.h index 650d6f2364..e9fd575905 100644 --- a/Userland/Libraries/LibWeb/Loader/FrameLoader.h +++ b/Userland/Libraries/LibWeb/Loader/FrameLoader.h @@ -35,6 +35,8 @@ public: void load_html(StringView, const AK::URL&); + bool is_pending() const { return resource()->is_pending(); } + HTML::BrowsingContext& browsing_context() { return m_browsing_context; } HTML::BrowsingContext const& browsing_context() const { return m_browsing_context; } diff --git a/Userland/Libraries/LibWeb/Loader/Resource.cpp b/Userland/Libraries/LibWeb/Loader/Resource.cpp index 49ab1cc918..86601c4c22 100644 --- a/Userland/Libraries/LibWeb/Loader/Resource.cpp +++ b/Userland/Libraries/LibWeb/Loader/Resource.cpp @@ -33,8 +33,7 @@ Resource::Resource(Type type, Resource& resource) : m_request(resource.m_request) , m_encoded_data(move(resource.m_encoded_data)) , m_type(type) - , m_loaded(resource.m_loaded) - , m_failed(resource.m_failed) + , m_state(resource.m_state) , m_error(move(resource.m_error)) , m_encoding(move(resource.m_encoding)) , m_mime_type(move(resource.m_mime_type)) @@ -89,12 +88,12 @@ static bool is_valid_encoding(StringView encoding) void Resource::did_load(Badge, ReadonlyBytes data, HashMap const& headers, Optional status_code) { - VERIFY(!m_loaded); + VERIFY(m_state == State::Pending); // FIXME: Handle OOM failure. m_encoded_data = ByteBuffer::copy(data).release_value_but_fixme_should_propagate_errors(); m_response_headers = headers.clone().release_value_but_fixme_should_propagate_errors(); m_status_code = move(status_code); - m_loaded = true; + m_state = State::Loaded; auto content_type = headers.get("Content-Type"); @@ -136,7 +135,7 @@ void Resource::did_fail(Badge, DeprecatedString const& error, Op { m_error = error; m_status_code = move(status_code); - m_failed = true; + m_state = State::Failed; for_each_client([](auto& client) { client.resource_did_fail(); diff --git a/Userland/Libraries/LibWeb/Loader/Resource.h b/Userland/Libraries/LibWeb/Loader/Resource.h index b37175a86d..2e3dda2370 100644 --- a/Userland/Libraries/LibWeb/Loader/Resource.h +++ b/Userland/Libraries/LibWeb/Loader/Resource.h @@ -37,9 +37,16 @@ public: Type type() const { return m_type; } - bool is_loaded() const { return m_loaded; } + enum class State { + Pending, + Loaded, + Failed, + }; + + bool is_pending() const { return m_state == State::Pending; } + bool is_loaded() const { return m_state == State::Loaded; } + bool is_failed() const { return m_state == State::Failed; } - bool is_failed() const { return m_failed; } DeprecatedString const& error() const { return m_error; } bool has_encoded_data() const { return !m_encoded_data.is_empty(); } @@ -71,8 +78,7 @@ private: LoadRequest m_request; ByteBuffer m_encoded_data; Type m_type { Type::Generic }; - bool m_loaded { false }; - bool m_failed { false }; + State m_state { State::Pending }; DeprecatedString m_error; Optional m_encoding; diff --git a/Userland/Libraries/LibWeb/Page/Page.cpp b/Userland/Libraries/LibWeb/Page/Page.cpp index b30f3c62f9..cd4d5bc05e 100644 --- a/Userland/Libraries/LibWeb/Page/Page.cpp +++ b/Userland/Libraries/LibWeb/Page/Page.cpp @@ -52,6 +52,11 @@ void Page::load_html(StringView html, const AK::URL& url) top_level_browsing_context().loader().load_html(html, url); } +bool Page::has_ongoing_navigation() const +{ + return top_level_browsing_context().loader().is_pending(); +} + Gfx::Palette Page::palette() const { return m_client.palette(); diff --git a/Userland/Libraries/LibWeb/Page/Page.h b/Userland/Libraries/LibWeb/Page/Page.h index fa8368cfd4..d41492f58e 100644 --- a/Userland/Libraries/LibWeb/Page/Page.h +++ b/Userland/Libraries/LibWeb/Page/Page.h @@ -60,6 +60,8 @@ public: void load_html(StringView, const AK::URL&); + bool has_ongoing_navigation() const; + CSSPixelPoint device_to_css_point(DevicePixelPoint) const; DevicePixelPoint css_to_device_point(CSSPixelPoint) const; CSSPixelRect device_to_css_rect(DevicePixelRect) const;