Skip to content

Commit

Permalink
blink: print ots parsing message to console for ArrayBuffer font face
Browse files Browse the repository at this point in the history
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 <ericwilligers@chromium.org>
Reviewed-by: Eric Willigers <ericwilligers@chromium.org>
Cr-Commit-Position: refs/heads/master@{#901348}
  • Loading branch information
ele828 authored and Chromium LUCI CQ committed Jul 14, 2021
1 parent aabf005 commit e2be8ad
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 7 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ Ehsan Akhgari <ehsan.akhgari@gmail.com>
Elan Ruusamäe <elan.ruusamae@gmail.com>
Ergun Erdogmus <erdogmusergun@gmail.com>
Eric Ahn <byungwook.ahn@gmail.com>
Eric Huang <ele828@gmail.com>
Eric Rescorla <ekr@rtfm.com>
Erik Hill <erikghill@gmail.com>
Erik Kurzinger <ekurzinger@gmail.com>
Expand Down
16 changes: 13 additions & 3 deletions third_party/blink/renderer/core/css/font_face.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -171,7 +172,8 @@ FontFace* FontFace::Create(ExecutionContext* context,
const FontFaceDescriptors* descriptors) {
FontFace* font_face =
MakeGarbageCollected<FontFace>(context, family, descriptors);
font_face->InitCSSFontFace(static_cast<const unsigned char*>(source->Data()),
font_face->InitCSSFontFace(context,
static_cast<const unsigned char*>(source->Data()),
source->ByteLength());
return font_face;
}
Expand All @@ -183,7 +185,7 @@ FontFace* FontFace::Create(ExecutionContext* context,
FontFace* font_face =
MakeGarbageCollected<FontFace>(context, family, descriptors);
font_face->InitCSSFontFace(
static_cast<const unsigned char*>(source->BaseAddress()),
context, static_cast<const unsigned char*>(source->BaseAddress()),
source->byteLength());
return font_face;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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<ConsoleMessage>(
mojom::blink::ConsoleMessageSource::kOther,
mojom::blink::ConsoleMessageLevel::kWarning,
"OTS parsing error: " + ots_parse_message_));
}
SetError(MakeGarbageCollected<DOMException>(
DOMExceptionCode::kSyntaxError, "Invalid font data in ArrayBuffer."));
}
Expand Down
6 changes: 3 additions & 3 deletions third_party/blink/renderer/core/css/font_face.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -179,8 +179,8 @@ class CORE_EXPORT FontFace : public ScriptWrappable,
ScriptPromise FontStatusPromise(ScriptState*);
void RunCallbacks();

using LoadedProperty = ScriptPromiseProperty<Member<FontFace>,
Member<DOMException>>;
using LoadedProperty =
ScriptPromiseProperty<Member<FontFace>, Member<DOMException>>;

AtomicString family_;
String ots_parse_message_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ConsoleMessage>(
mojom::ConsoleMessageSource::kOther,
mojom::ConsoleMessageLevel::kWarning,
Expand Down
Original file line number Diff line number Diff line change
@@ -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".
Expand Down
Original file line number Diff line number Diff line change
@@ -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".
Expand Down
Original file line number Diff line number Diff line change
@@ -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".
Expand Down

0 comments on commit e2be8ad

Please sign in to comment.