mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 10:47:35 +00:00
LibWeb: Make Document::page() return a Page&
Now that Document always has a Page, and always keeps it alive, we can make this return a Page&, exposing various unnecessary null checks.
This commit is contained in:
parent
70193c0009
commit
7c95ebc302
17 changed files with 43 additions and 78 deletions
|
@ -57,7 +57,7 @@ void HTMLImageElement::initialize(JS::Realm& realm)
|
|||
Base::initialize(realm);
|
||||
set_prototype(&Bindings::ensure_web_prototype<Bindings::HTMLImageElementPrototype>(realm, "HTMLImageElement"_fly_string));
|
||||
|
||||
m_current_request = ImageRequest::create(realm, *document().page());
|
||||
m_current_request = ImageRequest::create(realm, document().page());
|
||||
}
|
||||
|
||||
void HTMLImageElement::adopted_from(DOM::Document& old_document)
|
||||
|
@ -385,7 +385,7 @@ ErrorOr<void> HTMLImageElement::update_the_image_data(bool restart_animations, b
|
|||
m_pending_request = nullptr;
|
||||
|
||||
// 4. Let current request be a new image request whose image data is that of the entry and whose state is completely available.
|
||||
m_current_request = ImageRequest::create(realm(), *document().page());
|
||||
m_current_request = ImageRequest::create(realm(), document().page());
|
||||
m_current_request->set_image_data(entry->image_data);
|
||||
m_current_request->set_state(ImageRequest::State::CompletelyAvailable);
|
||||
|
||||
|
@ -512,7 +512,7 @@ after_step_7:
|
|||
// multiple image elements (as well as CSS background-images, etc.)
|
||||
|
||||
// 16. Set image request to a new image request whose current URL is urlString.
|
||||
auto image_request = ImageRequest::create(realm(), *document().page());
|
||||
auto image_request = ImageRequest::create(realm(), document().page());
|
||||
image_request->set_current_url(realm(), url_string);
|
||||
|
||||
// 17. If current request's state is unavailable or broken, then set the current request to image request.
|
||||
|
@ -707,7 +707,7 @@ void HTMLImageElement::react_to_changes_in_the_environment()
|
|||
key.origin = document().origin();
|
||||
|
||||
// 11. ⌛ Let image request be a new image request whose current URL is urlString
|
||||
auto image_request = ImageRequest::create(realm(), *document().page());
|
||||
auto image_request = ImageRequest::create(realm(), document().page());
|
||||
image_request->set_current_url(realm(), url_string);
|
||||
|
||||
// 12. ⌛ Let the element's pending request be image request.
|
||||
|
|
|
@ -70,7 +70,7 @@ void HTMLLinkElement::inserted()
|
|||
ResourceLoader::the().preconnect(document().parse_url(deprecated_attribute(HTML::AttributeNames::href)));
|
||||
} else if (m_relationship & Relationship::Icon) {
|
||||
auto favicon_url = document().parse_url(href());
|
||||
auto favicon_request = LoadRequest::create_for_url_on_page(favicon_url, document().page());
|
||||
auto favicon_request = LoadRequest::create_for_url_on_page(favicon_url, &document().page());
|
||||
set_resource(ResourceLoader::the().load_resource(Resource::Type::Generic, favicon_request));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,9 +57,6 @@ void HTMLMetaElement::inserted()
|
|||
auto name = attribute(AttributeNames::name);
|
||||
auto content = attribute(AttributeNames::content);
|
||||
if (name.has_value() && name->bytes_as_string_view().equals_ignoring_ascii_case("theme-color"sv) && content.has_value()) {
|
||||
auto* page = document().page();
|
||||
if (!page)
|
||||
return;
|
||||
auto context = CSS::Parser::ParsingContext { document() };
|
||||
|
||||
// 2. For each element in candidate elements:
|
||||
|
@ -82,7 +79,7 @@ void HTMLMetaElement::inserted()
|
|||
auto color = css_value->as_color().color();
|
||||
|
||||
// 4. If color is not failure, then return color.
|
||||
page->client().page_did_change_theme_color(color);
|
||||
document().page().client().page_did_change_theme_color(color);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -138,7 +138,7 @@ void HTMLObjectElement::queue_element_task_to_run_object_representation_steps()
|
|||
}
|
||||
|
||||
// 4. Let request be a new request whose URL is the resulting URL record, client is the element's node document's relevant settings object, destination is "object", credentials mode is "include", mode is "navigate", and whose use-URL-credentials flag is set.
|
||||
auto request = LoadRequest::create_for_url_on_page(url, document().page());
|
||||
auto request = LoadRequest::create_for_url_on_page(url, &document().page());
|
||||
|
||||
// 5. Fetch request, with processResponseEndOfBody given response res set to finalize and report timing with res, the element's node document's relevant global object, and "object".
|
||||
// Fetching the resource must delay the load event of the element's node document until the task that is queued by the networking task source once the resource has been fetched (defined next) has been run.
|
||||
|
@ -316,7 +316,7 @@ void HTMLObjectElement::load_image()
|
|||
// NOTE: This currently reloads the image instead of reusing the resource we've already downloaded.
|
||||
auto data = deprecated_attribute(HTML::AttributeNames::data);
|
||||
auto url = document().parse_url(data);
|
||||
m_image_request = HTML::SharedImageRequest::get_or_create(realm(), *document().page(), url);
|
||||
m_image_request = HTML::SharedImageRequest::get_or_create(realm(), document().page(), url);
|
||||
m_image_request->add_callbacks(
|
||||
[this] {
|
||||
run_object_representation_completed_steps(Representation::Image);
|
||||
|
|
|
@ -69,9 +69,8 @@ WebIDL::ExceptionOr<void> NavigableContainer::create_new_child_navigable()
|
|||
VERIFY(group);
|
||||
|
||||
// 3. Let browsingContext and document be the result of creating a new browsing context and document given element's node document, element, and group.
|
||||
auto* page = document().page();
|
||||
VERIFY(page);
|
||||
auto [browsing_context, document] = TRY(BrowsingContext::create_a_new_browsing_context_and_document(*page, this->document(), *this, *group));
|
||||
auto& page = document().page();
|
||||
auto [browsing_context, document] = TRY(BrowsingContext::create_a_new_browsing_context_and_document(page, this->document(), *this, *group));
|
||||
|
||||
// 4. Let targetName be null.
|
||||
Optional<String> target_name;
|
||||
|
|
|
@ -292,7 +292,7 @@ bool EnvironmentSettingsObject::is_scripting_enabled() const
|
|||
// The user has not disabled scripting for settings at this time. (User agents may provide users with the option to disable scripting globally, or in a finer-grained manner, e.g., on a per-origin basis, down to the level of individual environment settings objects.)
|
||||
auto document = const_cast<EnvironmentSettingsObject&>(*this).responsible_document();
|
||||
VERIFY(document);
|
||||
if (!document->page() || !document->page()->is_scripting_enabled())
|
||||
if (!document->page().is_scripting_enabled())
|
||||
return false;
|
||||
|
||||
// FIXME: Either settings's global object is not a Window object, or settings's global object's associated Document's active sandboxing flag set does not have its sandboxed scripts browsing context flag set.
|
||||
|
|
|
@ -429,12 +429,12 @@ bool Window::dispatch_event(DOM::Event& event)
|
|||
|
||||
Page* Window::page()
|
||||
{
|
||||
return associated_document().page();
|
||||
return &associated_document().page();
|
||||
}
|
||||
|
||||
Page const* Window::page() const
|
||||
{
|
||||
return associated_document().page();
|
||||
return &associated_document().page();
|
||||
}
|
||||
|
||||
Optional<CSS::MediaFeatureValue> Window::query_media_feature(CSS::MediaFeatureID media_feature) const
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue