From e2be8ad132577075cc027c357d1408e893d6bcd4 Mon Sep 17 00:00:00 2001 From: Eric Huang Date: Wed, 14 Jul 2021 03:49:04 +0000 Subject: [PATCH] blink: print ots parsing message to console for ArrayBuffer font face This adds ots parsing message as warning to console when it fails to parse font from FontFace API in ArrayBuffer type. Bug: 1085735 Change-Id: I779d8fbef6d433809e3357e155b4be5307266d1d Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3017909 Commit-Queue: Eric Willigers Reviewed-by: Eric Willigers Cr-Commit-Position: refs/heads/master@{#901348} --- AUTHORS | 1 + third_party/blink/renderer/core/css/font_face.cc | 16 +++++++++++++--- third_party/blink/renderer/core/css/font_face.h | 6 +++--- .../renderer/core/css/remote_font_face_source.cc | 2 +- .../fast/css/fontface-arraybuffer-expected.txt | 1 + .../fast/css/fontface-arraybuffer-expected.txt | 1 + .../fast/css/fontface-arraybuffer-expected.txt | 1 + 7 files changed, 21 insertions(+), 7 deletions(-) diff --git a/AUTHORS b/AUTHORS index 8777d2c3091405..2878092af623e3 100644 --- a/AUTHORS +++ b/AUTHORS @@ -310,6 +310,7 @@ Ehsan Akhgari Elan Ruusamäe Ergun Erdogmus Eric Ahn +Eric Huang Eric Rescorla Erik Hill Erik Kurzinger diff --git a/third_party/blink/renderer/core/css/font_face.cc b/third_party/blink/renderer/core/css/font_face.cc index ea7a535a795d2a..1f06ab34122ab3 100644 --- a/third_party/blink/renderer/core/css/font_face.cc +++ b/third_party/blink/renderer/core/css/font_face.cc @@ -59,6 +59,7 @@ #include "third_party/blink/renderer/core/frame/local_dom_window.h" #include "third_party/blink/renderer/core/frame/local_frame.h" #include "third_party/blink/renderer/core/frame/settings.h" +#include "third_party/blink/renderer/core/inspector/console_message.h" #include "third_party/blink/renderer/core/typed_arrays/dom_array_buffer.h" #include "third_party/blink/renderer/core/typed_arrays/dom_array_buffer_view.h" #include "third_party/blink/renderer/core/workers/worker_global_scope.h" @@ -171,7 +172,8 @@ FontFace* FontFace::Create(ExecutionContext* context, const FontFaceDescriptors* descriptors) { FontFace* font_face = MakeGarbageCollected(context, family, descriptors); - font_face->InitCSSFontFace(static_cast(source->Data()), + font_face->InitCSSFontFace(context, + static_cast(source->Data()), source->ByteLength()); return font_face; } @@ -183,7 +185,7 @@ FontFace* FontFace::Create(ExecutionContext* context, FontFace* font_face = MakeGarbageCollected(context, family, descriptors); font_face->InitCSSFontFace( - static_cast(source->BaseAddress()), + context, static_cast(source->BaseAddress()), source->byteLength()); return font_face; } @@ -862,7 +864,9 @@ void FontFace::InitCSSFontFace(ExecutionContext* context, const CSSValue& src) { } } -void FontFace::InitCSSFontFace(const unsigned char* data, size_t size) { +void FontFace::InitCSSFontFace(ExecutionContext* context, + const unsigned char* data, + size_t size) { css_font_face_ = CreateCSSFontFace(this, unicode_range_.Get()); if (error_) return; @@ -874,6 +878,12 @@ void FontFace::InitCSSFontFace(const unsigned char* data, size_t size) { if (source->IsValid()) { SetLoadStatus(kLoaded); } else { + if (!ots_parse_message_.IsEmpty()) { + context->AddConsoleMessage(MakeGarbageCollected( + mojom::blink::ConsoleMessageSource::kOther, + mojom::blink::ConsoleMessageLevel::kWarning, + "OTS parsing error: " + ots_parse_message_)); + } SetError(MakeGarbageCollected( DOMExceptionCode::kSyntaxError, "Invalid font data in ArrayBuffer.")); } diff --git a/third_party/blink/renderer/core/css/font_face.h b/third_party/blink/renderer/core/css/font_face.h index 939b436e75ee53..2cfde0003fb8c6 100644 --- a/third_party/blink/renderer/core/css/font_face.h +++ b/third_party/blink/renderer/core/css/font_face.h @@ -168,7 +168,7 @@ class CORE_EXPORT FontFace : public ScriptWrappable, const FontFaceDescriptors*); void InitCSSFontFace(ExecutionContext*, const CSSValue& src); - void InitCSSFontFace(const unsigned char* data, size_t); + void InitCSSFontFace(ExecutionContext*, const unsigned char* data, size_t); void SetPropertyFromString(const ExecutionContext*, const String&, AtRuleDescriptorID, @@ -179,8 +179,8 @@ class CORE_EXPORT FontFace : public ScriptWrappable, ScriptPromise FontStatusPromise(ScriptState*); void RunCallbacks(); - using LoadedProperty = ScriptPromiseProperty, - Member>; + using LoadedProperty = + ScriptPromiseProperty, Member>; AtomicString family_; String ots_parse_message_; diff --git a/third_party/blink/renderer/core/css/remote_font_face_source.cc b/third_party/blink/renderer/core/css/remote_font_face_source.cc index 5ec29a3695bba2..c281d1427e7639 100644 --- a/third_party/blink/renderer/core/css/remote_font_face_source.cc +++ b/third_party/blink/renderer/core/css/remote_font_face_source.cc @@ -204,7 +204,7 @@ void RemoteFontFaceSource::NotifyFinished(Resource* resource) { mojom::ConsoleMessageSource::kOther, mojom::ConsoleMessageLevel::kWarning, "Failed to decode downloaded font: " + font->Url().ElidedString())); - if (font->OtsParsingMessage().length() > 1) { + if (!font->OtsParsingMessage().IsEmpty()) { execution_context->AddConsoleMessage(MakeGarbageCollected( mojom::ConsoleMessageSource::kOther, mojom::ConsoleMessageLevel::kWarning, diff --git a/third_party/blink/web_tests/fast/css/fontface-arraybuffer-expected.txt b/third_party/blink/web_tests/fast/css/fontface-arraybuffer-expected.txt index 695fb49e839202..decf114580bcd6 100644 --- a/third_party/blink/web_tests/fast/css/fontface-arraybuffer-expected.txt +++ b/third_party/blink/web_tests/fast/css/fontface-arraybuffer-expected.txt @@ -1,4 +1,5 @@ CONSOLE WARNING: line 4: SharedArrayBuffer will require cross-origin isolation as of M92, around July 2021. See https://developer.chrome.com/blog/enabling-shared-array-buffer/ for more details. +CONSOLE WARNING: line 35: OTS parsing error: file less than 4 bytes Tests ArrayBuffer / ArrayBufferView constructors of FontFace. On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". diff --git a/third_party/blink/web_tests/virtual/shared_array_buffer_on_desktop/fast/css/fontface-arraybuffer-expected.txt b/third_party/blink/web_tests/virtual/shared_array_buffer_on_desktop/fast/css/fontface-arraybuffer-expected.txt index 8dc53ba55ea773..2ac31ba415f14c 100644 --- a/third_party/blink/web_tests/virtual/shared_array_buffer_on_desktop/fast/css/fontface-arraybuffer-expected.txt +++ b/third_party/blink/web_tests/virtual/shared_array_buffer_on_desktop/fast/css/fontface-arraybuffer-expected.txt @@ -1,4 +1,5 @@ CONSOLE WARNING: line 29: SharedArrayBuffer will require cross-origin isolation as of M92, around July 2021. See https://developer.chrome.com/blog/enabling-shared-array-buffer/ for more details. +CONSOLE WARNING: line 35: OTS parsing error: file less than 4 bytes Tests ArrayBuffer / ArrayBufferView constructors of FontFace. On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". diff --git a/third_party/blink/web_tests/virtual/synchronous_html_parser/fast/css/fontface-arraybuffer-expected.txt b/third_party/blink/web_tests/virtual/synchronous_html_parser/fast/css/fontface-arraybuffer-expected.txt index 8dc53ba55ea773..2ac31ba415f14c 100644 --- a/third_party/blink/web_tests/virtual/synchronous_html_parser/fast/css/fontface-arraybuffer-expected.txt +++ b/third_party/blink/web_tests/virtual/synchronous_html_parser/fast/css/fontface-arraybuffer-expected.txt @@ -1,4 +1,5 @@ CONSOLE WARNING: line 29: SharedArrayBuffer will require cross-origin isolation as of M92, around July 2021. See https://developer.chrome.com/blog/enabling-shared-array-buffer/ for more details. +CONSOLE WARNING: line 35: OTS parsing error: file less than 4 bytes Tests ArrayBuffer / ArrayBufferView constructors of FontFace. On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".