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 (#30985)
- Loading branch information
Showing
5 changed files
with
82 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
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,42 @@ | ||
// 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 "base/task/post_task.h" | ||
#include "chrome/browser/browser_process.h" | ||
#include "content/public/browser/browser_task_traits.h" | ||
#include "content/public/browser/font_access_chooser.h" | ||
#include "content/public/browser/render_frame_host.h" | ||
|
||
class ElectronFontAccessChooser : public content::FontAccessChooser { | ||
public: | ||
explicit ElectronFontAccessChooser(base::OnceClosure close_callback) { | ||
base::PostTask( | ||
FROM_HERE, {content::BrowserThread::UI}, | ||
base::BindOnce( | ||
[](base::OnceClosure closure) { std::move(closure).Run(); }, | ||
std::move(close_callback))); | ||
} | ||
~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_ |