Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: prevent navigator.fonts.query() from crashing
- Loading branch information
1 parent
eb955af
commit 13a052b
Showing
7 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: Shelley Vohr <shelley.vohr@gmail.com> | ||
Date: Mon, 13 Sep 2021 16:06:52 +0200 | ||
Subject: Fix: font access chooser DCHECK | ||
|
||
This patch is necessary to prevent a crash when navigator.fonts.query() | ||
in the intermediary period prior to Electron actually implementing the | ||
feature. Chromium relies on a user choice via a UI they pop up to run | ||
the callback, and in contrast we don't really have a way to run the | ||
closure post-construction of the FontAccessChooser and therefore must | ||
run it in the constructor, which makes it such that | ||
FontAccessManagerImpl::DidChooseLocalFonts runs before the FontAccessChooser | ||
is assigned in the choosers_ map and DCHECKS. | ||
|
||
As we don't yet have a standardized permissions model | ||
for this and similar APIs, this just mediates the crash and adds | ||
appropriate simple scaffolding for a proper implementation. | ||
|
||
diff --git a/content/browser/font_access/font_access_manager_impl.cc b/content/browser/font_access/font_access_manager_impl.cc | ||
index 518854d5370cdb5dc5131ad47442ac2bc748eae5..8b2b6ab23d1d12a0bb202dd1227ba5a28236a934 100644 | ||
--- a/content/browser/font_access/font_access_manager_impl.cc | ||
+++ b/content/browser/font_access/font_access_manager_impl.cc | ||
@@ -262,8 +262,8 @@ void FontAccessManagerImpl::DidChooseLocalFonts( | ||
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); | ||
|
||
// The chooser has fulfilled its purpose. It's safe to dispose of it. | ||
- size_t erased = choosers_.erase(frame_id); | ||
- DCHECK_EQ(erased, 1u); | ||
+ // size_t erased = choosers_.erase(frame_id); | ||
+ // DCHECK_EQ(erased, 1u); | ||
|
||
std::move(callback).Run(std::move(status), std::move(fonts)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (c) 2021 Microsoft, Inc. | ||
// Use of this source code is governed by the MIT license that can be | ||
// found in the LICENSE file. | ||
|
||
#include <utility> | ||
|
||
#include "shell/browser/font/electron_font_access_delegate.h" | ||
|
||
#include "content/public/browser/font_access_chooser.h" | ||
#include "content/public/browser/render_frame_host.h" | ||
|
||
// #include <memory> | ||
// #include <string> | ||
|
||
class ElectronFontAccessChooser : public content::FontAccessChooser { | ||
public: | ||
explicit ElectronFontAccessChooser(base::OnceClosure close_callback) { | ||
std::move(close_callback).Run(); | ||
} | ||
~ElectronFontAccessChooser() override = default; | ||
}; | ||
|
||
ElectronFontAccessDelegate::ElectronFontAccessDelegate() = default; | ||
ElectronFontAccessDelegate::~ElectronFontAccessDelegate() = default; | ||
|
||
std::unique_ptr<content::FontAccessChooser> | ||
ElectronFontAccessDelegate::RunChooser( | ||
content::RenderFrameHost* frame, | ||
const std::vector<std::string>& selection, | ||
content::FontAccessChooser::Callback callback) { | ||
// TODO(codebytere) : implement with proper permissions model. | ||
return std::make_unique<ElectronFontAccessChooser>(base::BindOnce( | ||
[](content::FontAccessChooser::Callback callback) { | ||
std::move(callback).Run( | ||
blink::mojom::FontEnumerationStatus::kUnimplemented, {}); | ||
}, | ||
std::move(callback))); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (c) 2021 Microsoft, Inc. | ||
// Use of this source code is governed by the MIT license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef SHELL_BROWSER_FONT_ELECTRON_FONT_ACCESS_DELEGATE_H_ | ||
#define SHELL_BROWSER_FONT_ELECTRON_FONT_ACCESS_DELEGATE_H_ | ||
|
||
#include <memory> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "content/public/browser/font_access_chooser.h" | ||
#include "content/public/browser/font_access_delegate.h" | ||
|
||
class ElectronFontAccessDelegate : public content::FontAccessDelegate { | ||
public: | ||
ElectronFontAccessDelegate(); | ||
~ElectronFontAccessDelegate() override; | ||
|
||
std::unique_ptr<content::FontAccessChooser> RunChooser( | ||
content::RenderFrameHost* frame, | ||
const std::vector<std::string>& selection, | ||
content::FontAccessChooser::Callback callback) override; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(ElectronFontAccessDelegate); | ||
}; | ||
|
||
#endif // SHELL_BROWSER_FONT_ELECTRON_FONT_ACCESS_DELEGATE_H_ |