From 76af9d434c6e240799f7214cb5187b4bd6d77202 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Sun, 3 Sep 2023 15:58:55 +1200 Subject: [PATCH] LibWeb: Port HTMLCanvasElement interface from DeprecatedString to String --- .../Libraries/LibWeb/HTML/HTMLCanvasElement.cpp | 14 +++++++------- Userland/Libraries/LibWeb/HTML/HTMLCanvasElement.h | 6 +++--- .../Libraries/LibWeb/HTML/HTMLCanvasElement.idl | 2 +- Userland/Libraries/LibWeb/WebDriver/Screenshot.cpp | 4 ++-- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Userland/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp index 67bcd99e67..0969ca77ff 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp @@ -153,7 +153,7 @@ JS::ThrowCompletionOr HTMLCanvasElement: } // https://html.spec.whatwg.org/multipage/canvas.html#dom-canvas-getcontext -JS::ThrowCompletionOr HTMLCanvasElement::get_context(DeprecatedString const& type, JS::Value options) +JS::ThrowCompletionOr HTMLCanvasElement::get_context(String const& type, JS::Value options) { // 1. If options is not an object, then set options to null. if (!options.is_object()) @@ -246,14 +246,14 @@ static ErrorOr serialize_bitmap(Gfx::Bitmap const& bitmap } // https://html.spec.whatwg.org/multipage/canvas.html#dom-canvas-todataurl -DeprecatedString HTMLCanvasElement::to_data_url(DeprecatedString const& type, Optional quality) const +String HTMLCanvasElement::to_data_url(StringView type, Optional quality) const { // FIXME: 1. If this canvas element's bitmap's origin-clean flag is set to false, then throw a "SecurityError" DOMException. // 2. If this canvas element's bitmap has no pixels (i.e. either its horizontal dimension or its vertical dimension is zero) // then return the string "data:,". (This is the shortest data: URL; it represents the empty string in a text/plain resource.) if (!m_bitmap) - return "data:,"; + return "data:,"_string; // 3. Let file be a serialization of this canvas element's bitmap as a file, passing type and quality if given. auto file = serialize_bitmap(*m_bitmap, type, move(quality)); @@ -261,19 +261,19 @@ DeprecatedString HTMLCanvasElement::to_data_url(DeprecatedString const& type, Op // 4. If file is null then return "data:,". if (file.is_error()) { dbgln("HTMLCanvasElement: Failed to encode canvas bitmap to {}: {}", type, file.error()); - return "data:,"; + return "data:,"_string; } // 5. Return a data: URL representing file. [RFC2397] auto base64_encoded_or_error = encode_base64(file.value().buffer); if (base64_encoded_or_error.is_error()) { - return "data:,"; + return "data:,"_string; } - return AK::URL::create_with_data(file.value().mime_type, base64_encoded_or_error.release_value(), true).to_deprecated_string(); + return MUST(AK::URL::create_with_data(file.value().mime_type, base64_encoded_or_error.release_value(), true).to_string()); } // https://html.spec.whatwg.org/multipage/canvas.html#dom-canvas-toblob -WebIDL::ExceptionOr HTMLCanvasElement::to_blob(JS::NonnullGCPtr callback, DeprecatedString const& type, Optional quality) +WebIDL::ExceptionOr HTMLCanvasElement::to_blob(JS::NonnullGCPtr callback, StringView type, Optional quality) { // FIXME: 1. If this canvas element's bitmap's origin-clean flag is set to false, then throw a "SecurityError" DOMException. diff --git a/Userland/Libraries/LibWeb/HTML/HTMLCanvasElement.h b/Userland/Libraries/LibWeb/HTML/HTMLCanvasElement.h index c8f26c7e31..79d798f13a 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLCanvasElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLCanvasElement.h @@ -25,7 +25,7 @@ public: Gfx::Bitmap* bitmap() { return m_bitmap; } bool create_bitmap(size_t minimum_width = 0, size_t minimum_height = 0); - JS::ThrowCompletionOr get_context(DeprecatedString const& type, JS::Value options); + JS::ThrowCompletionOr get_context(String const& type, JS::Value options); unsigned width() const; unsigned height() const; @@ -33,8 +33,8 @@ public: WebIDL::ExceptionOr set_width(unsigned); WebIDL::ExceptionOr set_height(unsigned); - DeprecatedString to_data_url(DeprecatedString const& type, Optional quality) const; - WebIDL::ExceptionOr to_blob(JS::NonnullGCPtr callback, DeprecatedString const& type, Optional quality); + String to_data_url(StringView type, Optional quality) const; + WebIDL::ExceptionOr to_blob(JS::NonnullGCPtr callback, StringView type, Optional quality); void present(); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLCanvasElement.idl b/Userland/Libraries/LibWeb/HTML/HTMLCanvasElement.idl index 485d778063..6ea01e08fd 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLCanvasElement.idl +++ b/Userland/Libraries/LibWeb/HTML/HTMLCanvasElement.idl @@ -5,7 +5,7 @@ typedef (CanvasRenderingContext2D or WebGLRenderingContext) RenderingContext; // https://html.spec.whatwg.org/multipage/semantics.html#htmlcanvaselement -[Exposed=Window, UseDeprecatedAKString] +[Exposed=Window] interface HTMLCanvasElement : HTMLElement { [HTMLConstructor] constructor(); diff --git a/Userland/Libraries/LibWeb/WebDriver/Screenshot.cpp b/Userland/Libraries/LibWeb/WebDriver/Screenshot.cpp index 3d79916cf3..f2a6405efe 100644 --- a/Userland/Libraries/LibWeb/WebDriver/Screenshot.cpp +++ b/Userland/Libraries/LibWeb/WebDriver/Screenshot.cpp @@ -36,11 +36,11 @@ static Response encode_canvas_element(HTML::HTMLCanvasElement const& canvas) auto data_url = canvas.to_data_url("image/png"sv, {}); // 5. Let index be the index of "," in data url. - auto index = data_url.find(','); + auto index = data_url.find_byte_offset(','); VERIFY(index.has_value()); // 6. Let encoded string be a substring of data url using (index + 1) as the start argument. - auto encoded_string = data_url.substring(*index + 1); + auto encoded_string = MUST(data_url.substring_from_byte_offset(*index + 1)); // 7. Return success with data encoded string. return JsonValue { move(encoded_string) };