diff --git a/Userland/Libraries/LibWeb/CSS/MediaQuery.cpp b/Userland/Libraries/LibWeb/CSS/MediaQuery.cpp index 29f6a2b288..f5800d7657 100644 --- a/Userland/Libraries/LibWeb/CSS/MediaQuery.cpp +++ b/Userland/Libraries/LibWeb/CSS/MediaQuery.cpp @@ -165,7 +165,7 @@ bool MediaFeature::compare(HTML::Window const& window, MediaFeatureValue left, C left_px = left.length().absolute_length_to_px(); right_px = right.length().absolute_length_to_px(); } else { - auto viewport_rect = window.page()->web_exposed_screen_area(); + auto viewport_rect = window.page().web_exposed_screen_area(); auto const& initial_font = window.associated_document().style_computer().initial_font(); Gfx::FontPixelMetrics const& initial_font_metrics = initial_font.pixel_metrics(); diff --git a/Userland/Libraries/LibWeb/CSS/Screen.cpp b/Userland/Libraries/LibWeb/CSS/Screen.cpp index 0bc2435367..8f8d3f4814 100644 --- a/Userland/Libraries/LibWeb/CSS/Screen.cpp +++ b/Userland/Libraries/LibWeb/CSS/Screen.cpp @@ -40,7 +40,7 @@ void Screen::visit_edges(Cell::Visitor& visitor) Gfx::IntRect Screen::screen_rect() const { - auto screen_rect_in_css_pixels = window().page()->web_exposed_screen_area(); + auto screen_rect_in_css_pixels = window().page().web_exposed_screen_area(); return { screen_rect_in_css_pixels.x().to_int(), screen_rect_in_css_pixels.y().to_int(), diff --git a/Userland/Libraries/LibWeb/Clipboard/Clipboard.cpp b/Userland/Libraries/LibWeb/Clipboard/Clipboard.cpp index de8cc4e819..55da3cb9a4 100644 --- a/Userland/Libraries/LibWeb/Clipboard/Clipboard.cpp +++ b/Userland/Libraries/LibWeb/Clipboard/Clipboard.cpp @@ -113,8 +113,7 @@ static void write_blobs_and_option_to_clipboard(JS::Realm& realm, ReadonlySpanbytes())); // 4. Insert payload and presentationStyle into the system clipboard using formatString as the native clipboard format. - if (auto* page = window.page()) - page->client().page_did_insert_clipboard_entry(move(payload), move(presentation_style), move(format_string)); + window.page().client().page_did_insert_clipboard_entry(move(payload), move(presentation_style), move(format_string)); } // FIXME: 3. Write web custom formats given webCustomFormats. diff --git a/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp b/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp index 6decedc4a6..1628f6666b 100644 --- a/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp +++ b/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp @@ -1722,19 +1722,13 @@ WebIDL::ExceptionOr> nonstandard_resource_load auto request = fetch_params.request(); - Page* page = nullptr; - auto& global_object = realm.global_object(); - if (is(global_object)) - page = static_cast(global_object).page(); - else if (is(global_object)) - page = static_cast(global_object).page(); + auto& page = Bindings::host_defined_page(realm); // NOTE: Using LoadRequest::create_for_url_on_page here will unconditionally add cookies as long as there's a page available. // However, it is up to http_network_or_cache_fetch to determine if cookies should be added to the request. LoadRequest load_request; load_request.set_url(request->current_url()); - if (page) - load_request.set_page(*page); + load_request.set_page(page); load_request.set_method(DeprecatedString::copy(request->method())); for (auto const& header : *request->header_list()) load_request.set_header(DeprecatedString::copy(header.name), DeprecatedString::copy(header.value)); diff --git a/Userland/Libraries/LibWeb/HTML/MimeTypeArray.cpp b/Userland/Libraries/LibWeb/HTML/MimeTypeArray.cpp index d99b9442d6..c76a1b8f18 100644 --- a/Userland/Libraries/LibWeb/HTML/MimeTypeArray.cpp +++ b/Userland/Libraries/LibWeb/HTML/MimeTypeArray.cpp @@ -32,8 +32,7 @@ Vector MimeTypeArray::supported_property_names() const { // The MimeTypeArray interface supports named properties. If the user agent's PDF viewer supported is true, then they are the PDF viewer mime types. Otherwise, they are the empty list. auto const& window = verify_cast(HTML::relevant_global_object(*this)); - VERIFY(window.page()); - if (!window.page()->pdf_viewer_supported()) + if (!window.page().pdf_viewer_supported()) return {}; // https://html.spec.whatwg.org/multipage/system-state.html#pdf-viewer-mime-types diff --git a/Userland/Libraries/LibWeb/HTML/Navigator.cpp b/Userland/Libraries/LibWeb/HTML/Navigator.cpp index 701007f96c..d60a919f44 100644 --- a/Userland/Libraries/LibWeb/HTML/Navigator.cpp +++ b/Userland/Libraries/LibWeb/HTML/Navigator.cpp @@ -42,7 +42,7 @@ bool Navigator::pdf_viewer_enabled() const // The NavigatorPlugins mixin's pdfViewerEnabled getter steps are to return the user agent's PDF viewer supported. // NOTE: The NavigatorPlugins mixin should only be exposed on the Window object. auto const& window = verify_cast(HTML::current_global_object()); - return window.page()->pdf_viewer_supported(); + return window.page().pdf_viewer_supported(); } // https://w3c.github.io/webdriver/#dfn-webdriver @@ -52,7 +52,7 @@ bool Navigator::webdriver() const // NOTE: The NavigatorAutomationInformation interface should not be exposed on WorkerNavigator. auto const& window = verify_cast(HTML::current_global_object()); - return window.page()->is_webdriver_active(); + return window.page().is_webdriver_active(); } void Navigator::visit_edges(Cell::Visitor& visitor) diff --git a/Userland/Libraries/LibWeb/HTML/Plugin.cpp b/Userland/Libraries/LibWeb/HTML/Plugin.cpp index b2187f1711..5d459965e0 100644 --- a/Userland/Libraries/LibWeb/HTML/Plugin.cpp +++ b/Userland/Libraries/LibWeb/HTML/Plugin.cpp @@ -56,8 +56,7 @@ Vector Plugin::supported_property_names() const { // The Plugin interface supports named properties. If the user agent's PDF viewer supported is true, then they are the PDF viewer mime types. Otherwise, they are the empty list. auto const& window = verify_cast(HTML::relevant_global_object(*this)); - VERIFY(window.page()); - if (!window.page()->pdf_viewer_supported()) + if (!window.page().pdf_viewer_supported()) return {}; // https://html.spec.whatwg.org/multipage/system-state.html#pdf-viewer-mime-types diff --git a/Userland/Libraries/LibWeb/HTML/PluginArray.cpp b/Userland/Libraries/LibWeb/HTML/PluginArray.cpp index cb5e036361..fd086a7bc1 100644 --- a/Userland/Libraries/LibWeb/HTML/PluginArray.cpp +++ b/Userland/Libraries/LibWeb/HTML/PluginArray.cpp @@ -38,8 +38,7 @@ Vector PluginArray::supported_property_names() const { // The PluginArray interface supports named properties. If the user agent's PDF viewer supported is true, then they are the PDF viewer plugin names. Otherwise, they are the empty list. auto const& window = verify_cast(HTML::relevant_global_object(*this)); - VERIFY(window.page()); - if (!window.page()->pdf_viewer_supported()) + if (!window.page().pdf_viewer_supported()) return {}; // https://html.spec.whatwg.org/multipage/system-state.html#pdf-viewer-plugin-names diff --git a/Userland/Libraries/LibWeb/HTML/Window.cpp b/Userland/Libraries/LibWeb/HTML/Window.cpp index f7523f6bab..9cc191ad9b 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.cpp +++ b/Userland/Libraries/LibWeb/HTML/Window.cpp @@ -427,14 +427,14 @@ bool Window::dispatch_event(DOM::Event& event) return DOM::EventDispatcher::dispatch(*this, event, true); } -Page* Window::page() +Page& Window::page() { - return &associated_document().page(); + return associated_document().page(); } -Page const* Window::page() const +Page const& Window::page() const { - return &associated_document().page(); + return associated_document().page(); } Optional Window::query_media_feature(CSS::MediaFeatureID media_feature) const @@ -457,15 +457,9 @@ Optional Window::query_media_feature(CSS::MediaFeatureID return CSS::MediaFeatureValue(0); // FIXME: device-aspect-ratio case CSS::MediaFeatureID::DeviceHeight: - if (auto* page = this->page()) { - return CSS::MediaFeatureValue(CSS::Length::make_px(page->web_exposed_screen_area().height())); - } - return CSS::MediaFeatureValue(0); + return CSS::MediaFeatureValue(CSS::Length::make_px(page().web_exposed_screen_area().height())); case CSS::MediaFeatureID::DeviceWidth: - if (auto* page = this->page()) { - return CSS::MediaFeatureValue(CSS::Length::make_px(page->web_exposed_screen_area().width())); - } - return CSS::MediaFeatureValue(0); + return CSS::MediaFeatureValue(CSS::Length::make_px(page().web_exposed_screen_area().width())); case CSS::MediaFeatureID::DisplayMode: // FIXME: Detect if window is fullscreen return CSS::MediaFeatureValue(CSS::ValueID::Browser); @@ -498,18 +492,15 @@ Optional Window::query_media_feature(CSS::MediaFeatureID case CSS::MediaFeatureID::Pointer: return CSS::MediaFeatureValue(CSS::ValueID::Fine); case CSS::MediaFeatureID::PrefersColorScheme: { - if (auto* page = this->page()) { - switch (page->preferred_color_scheme()) { - case CSS::PreferredColorScheme::Light: - return CSS::MediaFeatureValue(CSS::ValueID::Light); - case CSS::PreferredColorScheme::Dark: - return CSS::MediaFeatureValue(CSS::ValueID::Dark); - case CSS::PreferredColorScheme::Auto: - default: - return CSS::MediaFeatureValue(page->palette().is_dark() ? CSS::ValueID::Dark : CSS::ValueID::Light); - } + switch (page().preferred_color_scheme()) { + case CSS::PreferredColorScheme::Light: + return CSS::MediaFeatureValue(CSS::ValueID::Light); + case CSS::PreferredColorScheme::Dark: + return CSS::MediaFeatureValue(CSS::ValueID::Dark); + case CSS::PreferredColorScheme::Auto: + default: + return CSS::MediaFeatureValue(page().palette().is_dark() ? CSS::ValueID::Dark : CSS::ValueID::Light); } - return CSS::MediaFeatureValue(CSS::ValueID::Light); } case CSS::MediaFeatureID::PrefersContrast: // FIXME: Make this a preference @@ -701,8 +692,7 @@ Vector> Window::pdf_viewer_plugin_objects() // 3. "Microsoft Edge PDF Viewer" // 4. "WebKit built-in PDF" // The values of the above list form the PDF viewer plugin names list. https://html.spec.whatwg.org/multipage/system-state.html#pdf-viewer-plugin-names - VERIFY(page()); - if (!page()->pdf_viewer_supported()) + if (!page().pdf_viewer_supported()) return {}; if (m_pdf_viewer_plugin_objects.is_empty()) { @@ -725,8 +715,7 @@ Vector> Window::pdf_viewer_mime_type_objects() // 0. "application/pdf" // 1. "text/pdf" // The values of the above list form the PDF viewer mime types list. https://html.spec.whatwg.org/multipage/system-state.html#pdf-viewer-mime-types - VERIFY(page()); - if (!page()->pdf_viewer_supported()) + if (!page().pdf_viewer_supported()) return {}; if (m_pdf_viewer_mime_type_objects.is_empty()) { @@ -1010,8 +999,7 @@ void Window::alert(String const& message) // for historical reasons. The practical impact of this is that alert(undefined) is // treated as alert("undefined"), but alert() is treated as alert(""). // FIXME: Make this fully spec compliant. - if (auto* page = this->page()) - page->did_request_alert(message); + page().did_request_alert(message); } // https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#dom-confirm @@ -1019,18 +1007,14 @@ bool Window::confirm(Optional const& message) { // FIXME: Make this fully spec compliant. // NOTE: `message` has an IDL-provided default value and is never empty. - if (auto* page = this->page()) - return page->did_request_confirm(*message); - return false; + return page().did_request_confirm(*message); } // https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#dom-prompt Optional Window::prompt(Optional const& message, Optional const& default_) { // FIXME: Make this fully spec compliant. - if (auto* page = this->page()) - return page->did_request_prompt(*message, *default_); - return {}; + return page().did_request_prompt(*message, *default_); } // https://html.spec.whatwg.org/multipage/web-messaging.html#window-post-message-steps @@ -1222,9 +1206,7 @@ double Window::scroll_x() const { // The scrollX attribute must return the x-coordinate, relative to the initial containing block origin, // of the left of the viewport, or zero if there is no viewport. - if (auto* page = this->page()) - return page->top_level_traversable()->viewport_scroll_offset().x().to_double(); - return 0; + return page().top_level_traversable()->viewport_scroll_offset().x().to_double(); } // https://w3c.github.io/csswg-drafts/cssom-view/#dom-window-scrolly @@ -1232,9 +1214,7 @@ double Window::scroll_y() const { // The scrollY attribute must return the y-coordinate, relative to the initial containing block origin, // of the top of the viewport, or zero if there is no viewport. - if (auto* page = this->page()) - return page->top_level_traversable()->viewport_scroll_offset().y().to_double(); - return 0; + return page().top_level_traversable()->viewport_scroll_offset().y().to_double(); } // https://w3c.github.io/csswg-drafts/cssom-view/#perform-a-scroll @@ -1256,10 +1236,7 @@ static void perform_a_scroll(Page& page, double x, double y, JS::GCPtrpage(); - if (!page) - return; - auto top_level_traversable = page->top_level_traversable(); + auto top_level_traversable = page().top_level_traversable(); // 1. If invoked with one argument, follow these substeps: @@ -1312,7 +1289,7 @@ void Window::scroll(ScrollToOptions const& options) // 12. Perform a scroll of the viewport to position, document’s root element as the associated element, if there is // one, or null otherwise, and the scroll behavior being the value of the behavior dictionary member of options. auto element = JS::GCPtr { document ? &document->root() : nullptr }; - perform_a_scroll(*page, x, y, element, options.behavior); + perform_a_scroll(page(), x, y, element, options.behavior); } // https://w3c.github.io/csswg-drafts/cssom-view/#dom-window-scroll @@ -1374,9 +1351,7 @@ i32 Window::screen_x() const { // The screenX and screenLeft attributes must return the x-coordinate, relative to the origin of the Web-exposed // screen area, of the left of the client window as number of CSS pixels, or zero if there is no such thing. - if (auto* page = this->page()) - return page->window_position().x().value(); - return 0; + return page().window_position().x().value(); } // https://w3c.github.io/csswg-drafts/cssom-view/#dom-window-screeny @@ -1384,9 +1359,7 @@ i32 Window::screen_y() const { // The screenY and screenTop attributes must return the y-coordinate, relative to the origin of the screen of the // Web-exposed screen area, of the top of the client window as number of CSS pixels, or zero if there is no such thing. - if (auto* page = this->page()) - return page->window_position().y().value(); - return 0; + return page().window_position().y().value(); } // https://w3c.github.io/csswg-drafts/cssom-view/#dom-window-outerwidth @@ -1394,9 +1367,7 @@ i32 Window::outer_width() const { // The outerWidth attribute must return the width of the client window. If there is no client window this // attribute must return zero. - if (auto* page = this->page()) - return page->window_size().width().value(); - return 0; + return page().window_size().width().value(); } // https://w3c.github.io/csswg-drafts/cssom-view/#dom-window-outerheight @@ -1404,9 +1375,7 @@ i32 Window::outer_height() const { // The outerHeight attribute must return the height of the client window. If there is no client window this // attribute must return zero. - if (auto* page = this->page()) - return page->window_size().height().value(); - return 0; + return page().window_size().height().value(); } // https://w3c.github.io/csswg-drafts/cssom-view/#dom-window-devicepixelratio @@ -1416,9 +1385,7 @@ double Window::device_pixel_ratio() const // 2. Let CSS pixel size be the size of a CSS pixel at the current page zoom and using a scale factor of 1.0. // 3. Let device pixel size be the vertical size of a device pixel of the output device. // 4. Return the result of dividing CSS pixel size by device pixel size. - if (auto* page = this->page()) - return page->client().device_pixels_per_css_pixel(); - return 1; + return page().client().device_pixels_per_css_pixel(); } // https://html.spec.whatwg.org/multipage/imagebitmap-and-animations.html#dom-animationframeprovider-requestanimationframe diff --git a/Userland/Libraries/LibWeb/HTML/Window.h b/Userland/Libraries/LibWeb/HTML/Window.h index d568643f0e..2358c2bf30 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.h +++ b/Userland/Libraries/LibWeb/HTML/Window.h @@ -77,8 +77,8 @@ public: // ^JS::Object virtual JS::ThrowCompletionOr internal_set_prototype_of(JS::Object* prototype) override; - Page* page(); - Page const* page() const; + Page& page(); + Page const& page() const; // https://html.spec.whatwg.org/multipage/window-object.html#concept-document-window DOM::Document const& associated_document() const { return *m_associated_document; }