chore: bump chromium to 131.0.6776.0 (main) (#44137)
* chore: bump chromium in DEPS to 131.0.6763.0 * chore: bump chromium in DEPS to 131.0.6764.0 * update patches * chore: bump chromium in DEPS to 131.0.6766.0 * chore: update patches * Use PathInfo in FileSystemAccess code Refs5872329
* Modernize image utilities. Refs5905226
* [DevTools] move feature flags to the devtools directory Refs5913878
* chore: bump chromium in DEPS to 131.0.6768.0 * chore: update patches * Remove experimental credshelper flags Refs4017a6c8b4
* Change gfx::[PNG|JPEG]Codec::Decode to return a SkBitmap Refs5917286
Refs5905621
* chore: script/gen-libc++-filenames.js * chore: bump chromium in DEPS to 131.0.6770.0 * chore: update patches * chore: bump chromium in DEPS to 131.0.6772.0 * chore: update patches * [UI] Add alias for mojo version of `MenuSourceType` Refs5803393
* Update Background Color for Task Manager Refresh Refs5875259
* chore: bump chromium in DEPS to 131.0.6774.0 * chore: bump chromium in DEPS to 131.0.6776.0 * chore: update patches * chore: update filenames.libcxx.gni * esm: remove --no-import-harmony-assertions https://github.com/nodejs/node/pull/54890 * 5507047: [import-attributes] Remove support for import assertions |5507047
* fixup: Change gfx::[PNG|JPEG]Codec::Decode to return a SkBitmap * chore: bump chromium in DEPS to 131.0.6778.0 * Revert "chore: bump chromium in DEPS to 131.0.6778.0" This reverts commit fb9092fc51700651aa4a245931f71ec1ca55a274. --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: Jeremy Rose <nornagon@electronjs.org> Co-authored-by: deepak1556 <hop2deep@gmail.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>
This commit is contained in:
parent
72802c374b
commit
36b7cf341e
59 changed files with 395 additions and 325 deletions
|
@ -92,6 +92,7 @@ const char kDefaultLastPickedDirectoryKey[] = "default-id";
|
|||
const char kCustomLastPickedDirectoryKey[] = "custom-id";
|
||||
const char kPathKey[] = "path";
|
||||
const char kPathTypeKey[] = "path-type";
|
||||
const char kDisplayNameKey[] = "display-name";
|
||||
const char kTimestampKey[] = "timestamp";
|
||||
|
||||
constexpr base::TimeDelta kPermissionRevocationTimeout = base::Seconds(5);
|
||||
|
@ -210,6 +211,10 @@ std::string GenerateLastPickedDirectoryKey(const std::string& id) {
|
|||
: base::StrCat({kCustomLastPickedDirectoryKey, "-", id});
|
||||
}
|
||||
|
||||
std::string StringOrEmpty(const std::string* s) {
|
||||
return s ? *s : std::string();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace electron {
|
||||
|
@ -219,7 +224,7 @@ class FileSystemAccessPermissionContext::PermissionGrantImpl
|
|||
public:
|
||||
PermissionGrantImpl(base::WeakPtr<FileSystemAccessPermissionContext> context,
|
||||
const url::Origin& origin,
|
||||
const base::FilePath& path,
|
||||
const content::PathInfo& path_info,
|
||||
HandleType handle_type,
|
||||
GrantType type,
|
||||
UserAction user_action)
|
||||
|
@ -227,7 +232,7 @@ class FileSystemAccessPermissionContext::PermissionGrantImpl
|
|||
origin_{origin},
|
||||
handle_type_{handle_type},
|
||||
type_{type},
|
||||
path_{path} {}
|
||||
path_info_{path_info} {}
|
||||
|
||||
// FileSystemAccessPermissionGrant:
|
||||
PermissionStatus GetStatus() override {
|
||||
|
@ -237,7 +242,12 @@ class FileSystemAccessPermissionContext::PermissionGrantImpl
|
|||
|
||||
base::FilePath GetPath() override {
|
||||
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
|
||||
return path_;
|
||||
return path_info_.path;
|
||||
}
|
||||
|
||||
std::string GetDisplayName() override {
|
||||
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
|
||||
return path_info_.display_name;
|
||||
}
|
||||
|
||||
void RequestPermission(
|
||||
|
@ -311,7 +321,7 @@ class FileSystemAccessPermissionContext::PermissionGrantImpl
|
|||
electron::WebContentsPermissionHelper::PermissionType::FILE_SYSTEM);
|
||||
|
||||
base::Value::Dict details;
|
||||
details.Set("filePath", base::FilePathToValue(path_));
|
||||
details.Set("filePath", base::FilePathToValue(path_info_.path));
|
||||
details.Set("isDirectory", handle_type_ == HandleType::kDirectory);
|
||||
details.Set("fileAccessType",
|
||||
type_ == GrantType::kWrite ? "writable" : "readable");
|
||||
|
@ -350,12 +360,13 @@ class FileSystemAccessPermissionContext::PermissionGrantImpl
|
|||
|
||||
static void UpdateGrantPath(
|
||||
std::map<base::FilePath, PermissionGrantImpl*>& grants,
|
||||
const base::FilePath& old_path,
|
||||
const base::FilePath& new_path) {
|
||||
const content::PathInfo& old_path,
|
||||
const content::PathInfo& new_path) {
|
||||
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
||||
auto entry_it = std::ranges::find_if(
|
||||
grants,
|
||||
[&old_path](const auto& entry) { return entry.first == old_path; });
|
||||
auto entry_it =
|
||||
std::ranges::find_if(grants, [&old_path](const auto& entry) {
|
||||
return entry.first == old_path.path;
|
||||
});
|
||||
|
||||
if (entry_it == grants.end()) {
|
||||
// There must be an entry for an ancestor of this entry. Nothing to do
|
||||
|
@ -370,7 +381,7 @@ class FileSystemAccessPermissionContext::PermissionGrantImpl
|
|||
|
||||
// Update the permission grant's key in the map of active permissions.
|
||||
grants.erase(entry_it);
|
||||
grants.emplace(new_path, grant_impl);
|
||||
grants.emplace(new_path.path, grant_impl);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
@ -396,13 +407,13 @@ class FileSystemAccessPermissionContext::PermissionGrantImpl
|
|||
}
|
||||
}
|
||||
|
||||
void SetPath(const base::FilePath& new_path) {
|
||||
void SetPath(const content::PathInfo& new_path) {
|
||||
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
|
||||
|
||||
if (path_ == new_path)
|
||||
if (path_info_ == new_path)
|
||||
return;
|
||||
|
||||
path_ = new_path;
|
||||
path_info_ = new_path;
|
||||
NotifyPermissionStatusChanged();
|
||||
}
|
||||
|
||||
|
@ -412,7 +423,7 @@ class FileSystemAccessPermissionContext::PermissionGrantImpl
|
|||
const url::Origin origin_;
|
||||
const HandleType handle_type_;
|
||||
const GrantType type_;
|
||||
base::FilePath path_;
|
||||
content::PathInfo path_info_;
|
||||
|
||||
// This member should only be updated via SetStatus().
|
||||
PermissionStatus status_ = PermissionStatus::ASK;
|
||||
|
@ -440,14 +451,14 @@ FileSystemAccessPermissionContext::~FileSystemAccessPermissionContext() =
|
|||
scoped_refptr<content::FileSystemAccessPermissionGrant>
|
||||
FileSystemAccessPermissionContext::GetReadPermissionGrant(
|
||||
const url::Origin& origin,
|
||||
const base::FilePath& path,
|
||||
const content::PathInfo& path_info,
|
||||
HandleType handle_type,
|
||||
UserAction user_action) {
|
||||
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
|
||||
// operator[] might insert a new OriginState in |active_permissions_map_|,
|
||||
// but that is exactly what we want.
|
||||
auto& origin_state = active_permissions_map_[origin];
|
||||
auto*& existing_grant = origin_state.read_grants[path];
|
||||
auto*& existing_grant = origin_state.read_grants[path_info.path];
|
||||
scoped_refptr<PermissionGrantImpl> new_grant;
|
||||
|
||||
if (existing_grant && existing_grant->handle_type() != handle_type) {
|
||||
|
@ -460,15 +471,15 @@ FileSystemAccessPermissionContext::GetReadPermissionGrant(
|
|||
|
||||
if (!existing_grant) {
|
||||
new_grant = base::MakeRefCounted<PermissionGrantImpl>(
|
||||
weak_factory_.GetWeakPtr(), origin, path, handle_type, GrantType::kRead,
|
||||
user_action);
|
||||
weak_factory_.GetWeakPtr(), origin, path_info, handle_type,
|
||||
GrantType::kRead, user_action);
|
||||
existing_grant = new_grant.get();
|
||||
}
|
||||
|
||||
// If a parent directory is already readable this new grant should also be
|
||||
// readable.
|
||||
if (new_grant &&
|
||||
AncestorHasActivePermission(origin, path, GrantType::kRead)) {
|
||||
AncestorHasActivePermission(origin, path_info.path, GrantType::kRead)) {
|
||||
existing_grant->SetStatus(PermissionStatus::GRANTED);
|
||||
} else {
|
||||
switch (user_action) {
|
||||
|
@ -495,14 +506,14 @@ FileSystemAccessPermissionContext::GetReadPermissionGrant(
|
|||
scoped_refptr<content::FileSystemAccessPermissionGrant>
|
||||
FileSystemAccessPermissionContext::GetWritePermissionGrant(
|
||||
const url::Origin& origin,
|
||||
const base::FilePath& path,
|
||||
const content::PathInfo& path_info,
|
||||
HandleType handle_type,
|
||||
UserAction user_action) {
|
||||
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
|
||||
// operator[] might insert a new OriginState in |active_permissions_map_|,
|
||||
// but that is exactly what we want.
|
||||
auto& origin_state = active_permissions_map_[origin];
|
||||
auto*& existing_grant = origin_state.write_grants[path];
|
||||
auto*& existing_grant = origin_state.write_grants[path_info.path];
|
||||
scoped_refptr<PermissionGrantImpl> new_grant;
|
||||
|
||||
if (existing_grant && existing_grant->handle_type() != handle_type) {
|
||||
|
@ -515,7 +526,7 @@ FileSystemAccessPermissionContext::GetWritePermissionGrant(
|
|||
|
||||
if (!existing_grant) {
|
||||
new_grant = base::MakeRefCounted<PermissionGrantImpl>(
|
||||
weak_factory_.GetWeakPtr(), origin, path, handle_type,
|
||||
weak_factory_.GetWeakPtr(), origin, path_info, handle_type,
|
||||
GrantType::kWrite, user_action);
|
||||
existing_grant = new_grant.get();
|
||||
}
|
||||
|
@ -523,7 +534,7 @@ FileSystemAccessPermissionContext::GetWritePermissionGrant(
|
|||
// If a parent directory is already writable this new grant should also be
|
||||
// writable.
|
||||
if (new_grant &&
|
||||
AncestorHasActivePermission(origin, path, GrantType::kWrite)) {
|
||||
AncestorHasActivePermission(origin, path_info.path, GrantType::kWrite)) {
|
||||
existing_grant->SetStatus(PermissionStatus::GRANTED);
|
||||
} else {
|
||||
switch (user_action) {
|
||||
|
@ -563,8 +574,7 @@ bool FileSystemAccessPermissionContext::CanObtainWritePermission(
|
|||
|
||||
void FileSystemAccessPermissionContext::ConfirmSensitiveEntryAccess(
|
||||
const url::Origin& origin,
|
||||
PathType path_type,
|
||||
const base::FilePath& path,
|
||||
const content::PathInfo& path_info,
|
||||
HandleType handle_type,
|
||||
UserAction user_action,
|
||||
content::GlobalRenderFrameHostId frame_id,
|
||||
|
@ -574,14 +584,13 @@ void FileSystemAccessPermissionContext::ConfirmSensitiveEntryAccess(
|
|||
|
||||
auto after_blocklist_check_callback = base::BindOnce(
|
||||
&FileSystemAccessPermissionContext::DidCheckPathAgainstBlocklist,
|
||||
GetWeakPtr(), origin, path, handle_type, user_action, frame_id);
|
||||
CheckPathAgainstBlocklist(path_type, path, handle_type,
|
||||
GetWeakPtr(), origin, path_info, handle_type, user_action, frame_id);
|
||||
CheckPathAgainstBlocklist(path_info, handle_type,
|
||||
std::move(after_blocklist_check_callback));
|
||||
}
|
||||
|
||||
void FileSystemAccessPermissionContext::CheckPathAgainstBlocklist(
|
||||
PathType path_type,
|
||||
const base::FilePath& path,
|
||||
const content::PathInfo& path_info,
|
||||
HandleType handle_type,
|
||||
base::OnceCallback<void(bool)> callback) {
|
||||
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
|
||||
|
@ -590,7 +599,7 @@ void FileSystemAccessPermissionContext::CheckPathAgainstBlocklist(
|
|||
// blocked directories based on that, but that doesn't work well. Instead we
|
||||
// should have a separate Chrome OS only code path to block for example the
|
||||
// root of certain external file systems.
|
||||
if (path_type == PathType::kExternal) {
|
||||
if (path_info.type == content::PathType::kExternal) {
|
||||
std::move(callback).Run(/*should_block=*/false);
|
||||
return;
|
||||
}
|
||||
|
@ -601,7 +610,8 @@ void FileSystemAccessPermissionContext::CheckPathAgainstBlocklist(
|
|||
|
||||
base::ThreadPool::PostTaskAndReplyWithResult(
|
||||
FROM_HERE, {base::MayBlock(), base::TaskPriority::USER_VISIBLE},
|
||||
base::BindOnce(&ShouldBlockAccessToPath, path, handle_type, extra_rules),
|
||||
base::BindOnce(&ShouldBlockAccessToPath, path_info.path, handle_type,
|
||||
extra_rules),
|
||||
std::move(callback));
|
||||
}
|
||||
|
||||
|
@ -628,7 +638,7 @@ void FileSystemAccessPermissionContext::OnRestrictedPathResult(
|
|||
|
||||
void FileSystemAccessPermissionContext::DidCheckPathAgainstBlocklist(
|
||||
const url::Origin& origin,
|
||||
const base::FilePath& path,
|
||||
const content::PathInfo& path_info,
|
||||
HandleType handle_type,
|
||||
UserAction user_action,
|
||||
content::GlobalRenderFrameHostId frame_id,
|
||||
|
@ -650,7 +660,7 @@ void FileSystemAccessPermissionContext::DidCheckPathAgainstBlocklist(
|
|||
gin::DataObjectBuilder(isolate)
|
||||
.Set("origin", origin.GetURL().spec())
|
||||
.Set("isDirectory", handle_type == HandleType::kDirectory)
|
||||
.Set("path", path)
|
||||
.Set("path", path_info.path)
|
||||
.Build();
|
||||
session->Emit(
|
||||
"file-system-access-restricted", details,
|
||||
|
@ -699,14 +709,14 @@ void FileSystemAccessPermissionContext::MaybeEvictEntries(
|
|||
void FileSystemAccessPermissionContext::SetLastPickedDirectory(
|
||||
const url::Origin& origin,
|
||||
const std::string& id,
|
||||
const base::FilePath& path,
|
||||
const PathType type) {
|
||||
const content::PathInfo& path_info) {
|
||||
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
|
||||
|
||||
// Create an entry into the nested dictionary.
|
||||
base::Value::Dict entry;
|
||||
entry.Set(kPathKey, base::FilePathToValue(path));
|
||||
entry.Set(kPathTypeKey, static_cast<int>(type));
|
||||
entry.Set(kPathKey, base::FilePathToValue(path_info.path));
|
||||
entry.Set(kPathTypeKey, static_cast<int>(path_info.type));
|
||||
entry.Set(kDisplayNameKey, path_info.display_name);
|
||||
entry.Set(kTimestampKey, base::TimeToValue(clock_->Now()));
|
||||
|
||||
auto it = id_pathinfo_map_.find(origin);
|
||||
|
@ -722,15 +732,14 @@ void FileSystemAccessPermissionContext::SetLastPickedDirectory(
|
|||
}
|
||||
}
|
||||
|
||||
FileSystemAccessPermissionContext::PathInfo
|
||||
FileSystemAccessPermissionContext::GetLastPickedDirectory(
|
||||
content::PathInfo FileSystemAccessPermissionContext::GetLastPickedDirectory(
|
||||
const url::Origin& origin,
|
||||
const std::string& id) {
|
||||
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
|
||||
|
||||
auto it = id_pathinfo_map_.find(origin);
|
||||
|
||||
PathInfo path_info;
|
||||
content::PathInfo path_info;
|
||||
if (it == id_pathinfo_map_.end()) {
|
||||
return path_info;
|
||||
}
|
||||
|
@ -740,13 +749,14 @@ FileSystemAccessPermissionContext::GetLastPickedDirectory(
|
|||
return path_info;
|
||||
}
|
||||
|
||||
auto type_int =
|
||||
entry->FindInt(kPathTypeKey).value_or(static_cast<int>(PathType::kLocal));
|
||||
path_info.type = type_int == static_cast<int>(PathType::kExternal)
|
||||
? PathType::kExternal
|
||||
: PathType::kLocal;
|
||||
auto type_int = entry->FindInt(kPathTypeKey)
|
||||
.value_or(static_cast<int>(content::PathType::kLocal));
|
||||
path_info.type = type_int == static_cast<int>(content::PathType::kExternal)
|
||||
? content::PathType::kExternal
|
||||
: content::PathType::kLocal;
|
||||
path_info.path =
|
||||
base::ValueToFilePath(entry->Find(kPathKey)).value_or(base::FilePath());
|
||||
path_info.display_name = StringOrEmpty(entry->FindString(kDisplayNameKey));
|
||||
return path_info;
|
||||
}
|
||||
|
||||
|
@ -812,8 +822,8 @@ std::u16string FileSystemAccessPermissionContext::GetPickerTitle(
|
|||
|
||||
void FileSystemAccessPermissionContext::NotifyEntryMoved(
|
||||
const url::Origin& origin,
|
||||
const base::FilePath& old_path,
|
||||
const base::FilePath& new_path) {
|
||||
const content::PathInfo& old_path,
|
||||
const content::PathInfo& new_path) {
|
||||
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
|
||||
|
||||
if (old_path == new_path) {
|
||||
|
@ -834,7 +844,7 @@ void FileSystemAccessPermissionContext::OnFileCreatedFromShowSaveFilePicker(
|
|||
const storage::FileSystemURL& url) {}
|
||||
|
||||
void FileSystemAccessPermissionContext::CheckPathsAgainstEnterprisePolicy(
|
||||
std::vector<PathInfo> entries,
|
||||
std::vector<content::PathInfo> entries,
|
||||
content::GlobalRenderFrameHostId frame_id,
|
||||
EntriesAllowedByEnterprisePolicyCallback callback) {
|
||||
std::move(callback).Run(std::move(entries));
|
||||
|
|
|
@ -53,20 +53,19 @@ class FileSystemAccessPermissionContext
|
|||
// content::FileSystemAccessPermissionContext:
|
||||
scoped_refptr<content::FileSystemAccessPermissionGrant>
|
||||
GetReadPermissionGrant(const url::Origin& origin,
|
||||
const base::FilePath& path,
|
||||
const content::PathInfo& path,
|
||||
HandleType handle_type,
|
||||
UserAction user_action) override;
|
||||
|
||||
scoped_refptr<content::FileSystemAccessPermissionGrant>
|
||||
GetWritePermissionGrant(const url::Origin& origin,
|
||||
const base::FilePath& path,
|
||||
const content::PathInfo& path,
|
||||
HandleType handle_type,
|
||||
UserAction user_action) override;
|
||||
|
||||
void ConfirmSensitiveEntryAccess(
|
||||
const url::Origin& origin,
|
||||
PathType path_type,
|
||||
const base::FilePath& path,
|
||||
const content::PathInfo& path,
|
||||
HandleType handle_type,
|
||||
UserAction user_action,
|
||||
content::GlobalRenderFrameHostId frame_id,
|
||||
|
@ -85,11 +84,10 @@ class FileSystemAccessPermissionContext
|
|||
|
||||
void SetLastPickedDirectory(const url::Origin& origin,
|
||||
const std::string& id,
|
||||
const base::FilePath& path,
|
||||
const PathType type) override;
|
||||
const content::PathInfo& path) override;
|
||||
|
||||
PathInfo GetLastPickedDirectory(const url::Origin& origin,
|
||||
const std::string& id) override;
|
||||
content::PathInfo GetLastPickedDirectory(const url::Origin& origin,
|
||||
const std::string& id) override;
|
||||
|
||||
base::FilePath GetWellKnownDirectoryPath(
|
||||
blink::mojom::WellKnownDirectory directory,
|
||||
|
@ -99,15 +97,15 @@ class FileSystemAccessPermissionContext
|
|||
const blink::mojom::FilePickerOptionsPtr& options) override;
|
||||
|
||||
void NotifyEntryMoved(const url::Origin& origin,
|
||||
const base::FilePath& old_path,
|
||||
const base::FilePath& new_path) override;
|
||||
const content::PathInfo& old_path,
|
||||
const content::PathInfo& new_path) override;
|
||||
|
||||
void OnFileCreatedFromShowSaveFilePicker(
|
||||
const GURL& file_picker_binding_context,
|
||||
const storage::FileSystemURL& url) override;
|
||||
|
||||
void CheckPathsAgainstEnterprisePolicy(
|
||||
std::vector<PathInfo> entries,
|
||||
std::vector<content::PathInfo> entries,
|
||||
content::GlobalRenderFrameHostId frame_id,
|
||||
EntriesAllowedByEnterprisePolicyCallback callback) override;
|
||||
|
||||
|
@ -135,12 +133,11 @@ class FileSystemAccessPermissionContext
|
|||
|
||||
void PermissionGrantDestroyed(PermissionGrantImpl* grant);
|
||||
|
||||
void CheckPathAgainstBlocklist(PathType path_type,
|
||||
const base::FilePath& path,
|
||||
void CheckPathAgainstBlocklist(const content::PathInfo& path,
|
||||
HandleType handle_type,
|
||||
base::OnceCallback<void(bool)> callback);
|
||||
void DidCheckPathAgainstBlocklist(const url::Origin& origin,
|
||||
const base::FilePath& path,
|
||||
const content::PathInfo& path,
|
||||
HandleType handle_type,
|
||||
UserAction user_action,
|
||||
content::GlobalRenderFrameHostId frame_id,
|
||||
|
|
|
@ -32,11 +32,12 @@ bool IsDebuggingNotifications() {
|
|||
}
|
||||
|
||||
bool SaveIconToPath(const SkBitmap& bitmap, const base::FilePath& path) {
|
||||
std::vector<unsigned char> png_data;
|
||||
if (!gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, &png_data))
|
||||
std::optional<std::vector<uint8_t>> png_data =
|
||||
gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false);
|
||||
if (!png_data.has_value())
|
||||
return false;
|
||||
|
||||
return base::WriteFile(path, png_data);
|
||||
return base::WriteFile(path, png_data.value());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -244,8 +244,7 @@ gfx::Image Clipboard::ReadImage(gin_helper::Arguments* args) {
|
|||
base::BindOnce(
|
||||
[](std::optional<gfx::Image>* image, base::RepeatingClosure cb,
|
||||
const std::vector<uint8_t>& result) {
|
||||
SkBitmap bitmap;
|
||||
gfx::PNGCodec::Decode(result.data(), result.size(), &bitmap);
|
||||
SkBitmap bitmap = gfx::PNGCodec::Decode(result);
|
||||
image->emplace(gfx::Image::CreateFrom1xBitmap(bitmap));
|
||||
std::move(cb).Run();
|
||||
},
|
||||
|
|
|
@ -238,10 +238,12 @@ v8::Local<v8::Value> NativeImage::ToPNG(gin::Arguments* args) {
|
|||
|
||||
const SkBitmap bitmap =
|
||||
image_.AsImageSkia().GetRepresentation(scale_factor).GetBitmap();
|
||||
std::vector<unsigned char> encoded;
|
||||
gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, &encoded);
|
||||
const char* data = reinterpret_cast<char*>(encoded.data());
|
||||
size_t size = encoded.size();
|
||||
std::optional<std::vector<uint8_t>> encoded =
|
||||
gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false);
|
||||
if (!encoded.has_value())
|
||||
return node::Buffer::New(args->isolate(), 0).ToLocalChecked();
|
||||
const char* data = reinterpret_cast<char*>(encoded->data());
|
||||
size_t size = encoded->size();
|
||||
return node::Buffer::Copy(args->isolate(), data, size).ToLocalChecked();
|
||||
}
|
||||
|
||||
|
@ -265,13 +267,13 @@ v8::Local<v8::Value> NativeImage::ToBitmap(gin::Arguments* args) {
|
|||
}
|
||||
|
||||
v8::Local<v8::Value> NativeImage::ToJPEG(v8::Isolate* isolate, int quality) {
|
||||
std::vector<unsigned char> output;
|
||||
gfx::JPEG1xEncodedDataFromImage(image_, quality, &output);
|
||||
if (output.empty())
|
||||
std::optional<std::vector<uint8_t>> encoded_image =
|
||||
gfx::JPEG1xEncodedDataFromImage(image_, quality);
|
||||
if (!encoded_image.has_value())
|
||||
return node::Buffer::New(isolate, 0).ToLocalChecked();
|
||||
return node::Buffer::Copy(isolate,
|
||||
reinterpret_cast<const char*>(&output.front()),
|
||||
output.size())
|
||||
return node::Buffer::Copy(
|
||||
isolate, reinterpret_cast<const char*>(&encoded_image->front()),
|
||||
encoded_image->size())
|
||||
.ToLocalChecked();
|
||||
}
|
||||
|
||||
|
|
|
@ -21,28 +21,31 @@
|
|||
#include "shell/common/gin_helper/dictionary.h"
|
||||
#include "third_party/blink/public/common/context_menu_data/untrustworthy_context_menu_params.h"
|
||||
#include "third_party/blink/public/mojom/permissions/permission_status.mojom.h"
|
||||
#include "ui/base/mojom/menu_source_type.mojom.h"
|
||||
#include "ui/events/keycodes/dom/keycode_converter.h"
|
||||
#include "ui/events/keycodes/keyboard_code_conversion.h"
|
||||
|
||||
namespace gin {
|
||||
|
||||
static constexpr auto MenuSourceTypes =
|
||||
base::MakeFixedFlatMap<std::string_view, ui::MenuSourceType>({
|
||||
{"adjustSelection", ui::MENU_SOURCE_ADJUST_SELECTION},
|
||||
{"adjustSelectionReset", ui::MENU_SOURCE_ADJUST_SELECTION_RESET},
|
||||
{"keyboard", ui::MENU_SOURCE_KEYBOARD},
|
||||
{"longPress", ui::MENU_SOURCE_LONG_PRESS},
|
||||
{"longTap", ui::MENU_SOURCE_LONG_TAP},
|
||||
{"mouse", ui::MENU_SOURCE_MOUSE},
|
||||
{"none", ui::MENU_SOURCE_NONE},
|
||||
{"stylus", ui::MENU_SOURCE_STYLUS},
|
||||
{"touch", ui::MENU_SOURCE_TOUCH},
|
||||
{"touchHandle", ui::MENU_SOURCE_TOUCH_HANDLE},
|
||||
{"touchMenu", ui::MENU_SOURCE_TOUCH_EDIT_MENU},
|
||||
base::MakeFixedFlatMap<std::string_view, ui::mojom::MenuSourceType>({
|
||||
{"adjustSelection", ui::mojom::MenuSourceType::kAdjustSelection},
|
||||
{"adjustSelectionReset",
|
||||
ui::mojom::MenuSourceType::kAdjustSelectionReset},
|
||||
{"keyboard", ui::mojom::MenuSourceType::kKeyboard},
|
||||
{"longPress", ui::mojom::MenuSourceType::kLongPress},
|
||||
{"longTap", ui::mojom::MenuSourceType::kLongTap},
|
||||
{"mouse", ui::mojom::MenuSourceType::kMouse},
|
||||
{"none", ui::mojom::MenuSourceType::kNone},
|
||||
{"stylus", ui::mojom::MenuSourceType::kStylus},
|
||||
{"touch", ui::mojom::MenuSourceType::kTouch},
|
||||
{"touchHandle", ui::mojom::MenuSourceType::kTouchHandle},
|
||||
{"touchMenu", ui::mojom::MenuSourceType::kTouchEditMenu},
|
||||
});
|
||||
|
||||
// let us know when upstream changes & we need to update MenuSourceTypes
|
||||
static_assert(std::size(MenuSourceTypes) == ui::MENU_SOURCE_TYPE_LAST + 1U);
|
||||
static_assert(std::size(MenuSourceTypes) ==
|
||||
static_cast<int32_t>(ui::mojom::MenuSourceType::kMaxValue) + 1);
|
||||
|
||||
// static
|
||||
v8::Local<v8::Value> Converter<ui::MenuSourceType>::ToV8(
|
||||
|
|
|
@ -58,8 +58,8 @@ float GetScaleFactorFromPath(const base::FilePath& path) {
|
|||
bool AddImageSkiaRepFromPNG(gfx::ImageSkia* image,
|
||||
const base::span<const uint8_t> data,
|
||||
double scale_factor) {
|
||||
SkBitmap bitmap;
|
||||
if (!gfx::PNGCodec::Decode(data.data(), data.size(), &bitmap))
|
||||
SkBitmap bitmap = gfx::PNGCodec::Decode(data);
|
||||
if (bitmap.isNull())
|
||||
return false;
|
||||
|
||||
image->AddRepresentation(gfx::ImageSkiaRep(bitmap, scale_factor));
|
||||
|
@ -69,8 +69,8 @@ bool AddImageSkiaRepFromPNG(gfx::ImageSkia* image,
|
|||
bool AddImageSkiaRepFromJPEG(gfx::ImageSkia* image,
|
||||
const base::span<const uint8_t> data,
|
||||
double scale_factor) {
|
||||
auto bitmap = gfx::JPEGCodec::Decode(data.data(), data.size());
|
||||
if (!bitmap)
|
||||
auto bitmap = gfx::JPEGCodec::Decode(data);
|
||||
if (bitmap.isNull())
|
||||
return false;
|
||||
|
||||
// `JPEGCodec::Decode()` doesn't tell `SkBitmap` instance it creates
|
||||
|
@ -80,9 +80,9 @@ bool AddImageSkiaRepFromJPEG(gfx::ImageSkia* image,
|
|||
// TODO(alexeykuzmin): This workaround should be removed
|
||||
// when the `JPEGCodec::Decode()` code is fixed.
|
||||
// See https://github.com/electron/electron/issues/11294.
|
||||
bitmap->setAlphaType(SkAlphaType::kOpaque_SkAlphaType);
|
||||
bitmap.setAlphaType(SkAlphaType::kOpaque_SkAlphaType);
|
||||
|
||||
image->AddRepresentation(gfx::ImageSkiaRep(*bitmap, scale_factor));
|
||||
image->AddRepresentation(gfx::ImageSkiaRep(bitmap, scale_factor));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue