Repository navigation
refactor: remove redundant NativeImage::GetBitmap() - #46696
Conversation
MarshallOfSound
left a comment
There was a problem hiding this comment.
Is deprecating a thing semver/minor? feels like a thing we can just land
|
Bumping back down to |
jkleinsc
left a comment
There was a problem hiding this comment.
Needs an entry added to docs/breaking-changes.md
🪦 Deprecation Checklist🔥 New deprecations in this PR
@electron/wg-releases: Please confirm these deprecation changes conform to our deprecation policies listed in |
dsanders11
left a comment
There was a problem hiding this comment.
There's a few usages we should also change to toBitmap() as part of this PR:
electron/spec/api-browser-window-spec.ts
Line 4602 in 3ad8778
electron/spec/ts-smoke/electron/main.ts
Line 1294 in 3ad8778
electron/docs/api/web-contents.md
Line 890 in 3ad8778
Here's a suggested way to add the deprecation warnings and satisfy the checklist:
diff --git a/shell/common/api/electron_api_native_image.cc b/shell/common/api/electron_api_native_image.cc
index e991c618a3..d16023390d 100644
--- a/shell/common/api/electron_api_native_image.cc
+++ b/shell/common/api/electron_api_native_image.cc
@@ -286,6 +286,19 @@ std::string NativeImage::ToDataURL(gin::Arguments* args) {
image_.AsImageSkia().GetRepresentation(scale_factor).GetBitmap());
}
+v8::Local<v8::Value> NativeImage::GetBitmap(gin::Arguments* args) {
+ static bool deprecated_warning_issued = false;
+
+ if (!deprecated_warning_issued) {
+ deprecated_warning_issued = true;
+ util::EmitWarning(isolate_,
+ "getBitmap() is deprecated, use toBitmap() instead.",
+ "DeprecationWarning");
+ }
+
+ return ToBitmap(args);
+}
+
v8::Local<v8::Value> NativeImage::GetNativeHandle(
gin_helper::ErrorThrower thrower) {
#if BUILDFLAG(IS_MAC)
@@ -582,7 +595,7 @@ gin::ObjectTemplateBuilder NativeImage::GetObjectTemplateBuilder(
.SetMethod("toPNG", &NativeImage::ToPNG)
.SetMethod("toJPEG", &NativeImage::ToJPEG)
.SetMethod("toBitmap", &NativeImage::ToBitmap)
- .SetMethod("getBitmap", &NativeImage::ToBitmap)
+ .SetMethod("getBitmap", &NativeImage::GetBitmap)
.SetMethod("getScaleFactors", &NativeImage::GetScaleFactors)
.SetMethod("getNativeHandle", &NativeImage::GetNativeHandle)
.SetMethod("toDataURL", &NativeImage::ToDataURL)
diff --git a/shell/common/api/electron_api_native_image.h b/shell/common/api/electron_api_native_image.h
index b09269b5ec..60f4acb1a5 100644
--- a/shell/common/api/electron_api_native_image.h
+++ b/shell/common/api/electron_api_native_image.h
@@ -112,6 +112,7 @@ class NativeImage final : public gin::Wrappable<NativeImage> {
v8::Local<v8::Value> ToJPEG(v8::Isolate* isolate, int quality);
v8::Local<v8::Value> ToBitmap(gin::Arguments* args);
std::vector<float> GetScaleFactors();
+ v8::Local<v8::Value> GetBitmap(gin::Arguments* args);
v8::Local<v8::Value> GetNativeHandle(gin_helper::ErrorThrower thrower);
gin::Handle<NativeImage> Resize(gin::Arguments* args,
base::Value::Dict options);
diff --git a/spec/api-native-image-spec.ts b/spec/api-native-image-spec.ts
index bbd30cff7a..72a5ffeaee 100644
--- a/spec/api-native-image-spec.ts
+++ b/spec/api-native-image-spec.ts
@@ -4,6 +4,7 @@ import { expect } from 'chai';
import * as path from 'node:path';
+import { expectDeprecationMessages } from './lib/deprecate-helpers';
import { ifdescribe, ifit, itremote, useRemoteContext } from './lib/spec-helpers';
describe('nativeImage module', () => {
@@ -78,15 +79,20 @@ describe('nativeImage module', () => {
});
describe('createEmpty()', () => {
- it('returns an empty image', () => {
+ it('returns an empty image', async () => {
const empty = nativeImage.createEmpty();
expect(empty.isEmpty()).to.be.true();
expect(empty.getAspectRatio()).to.equal(1);
expect(empty.toDataURL()).to.equal('data:image/png;base64,');
expect(empty.toDataURL({ scaleFactor: 2.0 })).to.equal('data:image/png;base64,');
expect(empty.getSize()).to.deep.equal({ width: 0, height: 0 });
- expect(empty.getBitmap()).to.be.empty();
- expect(empty.getBitmap({ scaleFactor: 2.0 })).to.be.empty();
+ await expectDeprecationMessages(
+ () => {
+ expect(empty.getBitmap()).to.be.empty();
+ expect(empty.getBitmap({ scaleFactor: 2.0 })).to.be.empty();
+ },
+ 'getBitmap() is deprecated, use toBitmap() instead.'
+ );
expect(empty.toBitmap()).to.be.empty();
expect(empty.toBitmap({ scaleFactor: 2.0 })).to.be.empty();
expect(empty.toJPEG(100)).to.be.empty();b14ce6b to
e7379a4
Compare
Needs an entry added to docs/breaking-changes.md
Change request was addressed!
|
Release Notes Persisted
|
|
I have automatically backported this PR to "36-x-y", please check out #46736 |
* refactor: remove redundant NativeImage::GetBitmap() * docs: mark NativeImage.getBitmap() as deprecated * have getBitmap() emit a deprecation warning * docs: update obsolete refefence to getBitmap() * test: update obsolete refefences to getBitmap() --------- Co-authored-by: David Sanders <[email protected]>
Description of Change
Mark
NativeImage.getBitmap()as deprecated and document it as an alias forNativeImage.toBitmap().The documentation says:
...but this hasn't been true since June 2022 f61be57#diff-87426541166a1d650dedb7f3804023ffeb1718899ab7a83814ad538061546d60 because the old behavior of
getBitmap()wasn't sandbox-compatible. For nearly three years, both functions have returned a newly-allocated copy of the bitmap and are functionally equivalent. 😸So this PR:
NativeImage::GetBitmap()NativeImage.getBitmap()to C++NativeImage::ToBitmap()NativeImage.getBitmap()as an alias toNativeImage.toBitmap()NativeImage.getBitmap()as deprecatedItems 1-3 are
semver/patchbugfix. Item 4 is arguablysemver/minor? Labeling the PR accordingly. If @electron/wg-api wants to keep both methods as non-deprecated for some reason, I'm open to the idea.Checklist
npm testpassesRelease Notes
Notes: Deprecated
NativeImage.getBitmap()and fixed incorrect documentation.