зеркало из https://github.com/electron/electron.git
fix: use nested run loop in clipboard.readImage (#39466)
This commit is contained in:
Родитель
08bbff5361
Коммит
cf658b700d
|
@ -9,6 +9,7 @@
|
|||
#include "base/containers/contains.h"
|
||||
#include "base/run_loop.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "shell/browser/browser.h"
|
||||
#include "shell/common/gin_converters/image_converter.h"
|
||||
#include "shell/common/gin_helper/dictionary.h"
|
||||
#include "shell/common/node_includes.h"
|
||||
|
@ -220,10 +221,18 @@ void Clipboard::WriteBookmark(const std::u16string& title,
|
|||
}
|
||||
|
||||
gfx::Image Clipboard::ReadImage(gin_helper::Arguments* args) {
|
||||
// The ReadPng uses thread pool which requires app ready.
|
||||
if (IsBrowserProcess() && !Browser::Get()->is_ready()) {
|
||||
args->ThrowError(
|
||||
"clipboard.readImage is available only after app ready in the main "
|
||||
"process");
|
||||
return gfx::Image();
|
||||
}
|
||||
|
||||
ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
|
||||
absl::optional<gfx::Image> image;
|
||||
|
||||
base::RunLoop run_loop;
|
||||
base::RunLoop run_loop(base::RunLoop::Type::kNestableTasksAllowed);
|
||||
base::RepeatingClosure callback = run_loop.QuitClosure();
|
||||
clipboard->ReadPng(
|
||||
GetClipboardBuffer(args),
|
||||
|
|
|
@ -16,6 +16,11 @@ ifdescribe(process.platform !== 'win32' || process.arch !== 'arm64')('clipboard
|
|||
const readImage = clipboard.readImage();
|
||||
expect(readImage.toDataURL()).to.equal(i.toDataURL());
|
||||
});
|
||||
|
||||
it('works for empty image', () => {
|
||||
clipboard.writeText('Not an Image');
|
||||
expect(clipboard.readImage().isEmpty()).to.be.true();
|
||||
});
|
||||
});
|
||||
|
||||
describe('clipboard.readText()', () => {
|
||||
|
|
Загрузка…
Ссылка в новой задаче