fix: prevent navigator.fonts.query() from crashing (#30930)
* fix: prevent navigator.fonts.query() from crashing * refactor: use base::PostTask instead
This commit is contained in:
parent
9eaa9de3b4
commit
c8e4cc29c0
5 changed files with 82 additions and 0 deletions
|
@ -383,6 +383,8 @@ filenames = {
|
|||
"shell/browser/file_select_helper.cc",
|
||||
"shell/browser/file_select_helper.h",
|
||||
"shell/browser/file_select_helper_mac.mm",
|
||||
"shell/browser/font/electron_font_access_delegate.cc",
|
||||
"shell/browser/font/electron_font_access_delegate.h",
|
||||
"shell/browser/font_defaults.cc",
|
||||
"shell/browser/font_defaults.h",
|
||||
"shell/browser/javascript_environment.cc",
|
||||
|
|
|
@ -1670,6 +1670,12 @@ content::BluetoothDelegate* ElectronBrowserClient::GetBluetoothDelegate() {
|
|||
return bluetooth_delegate_.get();
|
||||
}
|
||||
|
||||
content::FontAccessDelegate* ElectronBrowserClient::GetFontAccessDelegate() {
|
||||
if (!font_access_delegate_)
|
||||
font_access_delegate_ = std::make_unique<ElectronFontAccessDelegate>();
|
||||
return font_access_delegate_.get();
|
||||
}
|
||||
|
||||
void BindBadgeServiceForServiceWorker(
|
||||
const content::ServiceWorkerVersionBaseInfo& info,
|
||||
mojo::PendingReceiver<blink::mojom::BadgeService> receiver) {
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "net/ssl/client_cert_identity.h"
|
||||
#include "services/metrics/public/cpp/ukm_source_id.h"
|
||||
#include "shell/browser/bluetooth/electron_bluetooth_delegate.h"
|
||||
#include "shell/browser/font/electron_font_access_delegate.h"
|
||||
#include "shell/browser/serial/electron_serial_delegate.h"
|
||||
#include "third_party/blink/public/mojom/badging/badging.mojom-forward.h"
|
||||
|
||||
|
@ -91,6 +92,8 @@ class ElectronBrowserClient : public content::ContentBrowserClient,
|
|||
|
||||
content::SerialDelegate* GetSerialDelegate() override;
|
||||
|
||||
content::FontAccessDelegate* GetFontAccessDelegate() override;
|
||||
|
||||
content::BluetoothDelegate* GetBluetoothDelegate() override;
|
||||
|
||||
device::GeolocationManager* GetGeolocationManager() override;
|
||||
|
@ -305,6 +308,7 @@ class ElectronBrowserClient : public content::ContentBrowserClient,
|
|||
|
||||
std::unique_ptr<ElectronSerialDelegate> serial_delegate_;
|
||||
std::unique_ptr<ElectronBluetoothDelegate> bluetooth_delegate_;
|
||||
std::unique_ptr<ElectronFontAccessDelegate> font_access_delegate_;
|
||||
|
||||
#if defined(OS_MAC)
|
||||
ElectronBrowserMainParts* browser_main_parts_ = nullptr;
|
||||
|
|
42
shell/browser/font/electron_font_access_delegate.cc
Normal file
42
shell/browser/font/electron_font_access_delegate.cc
Normal file
|
@ -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)));
|
||||
}
|
28
shell/browser/font/electron_font_access_delegate.h
Normal file
28
shell/browser/font/electron_font_access_delegate.h
Normal file
|
@ -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_
|
Loading…
Reference in a new issue