fix: NSImageName string conversion (#23467)
This commit is contained in:
parent
392ea320cf
commit
6114518463
4 changed files with 19 additions and 8 deletions
|
@ -2363,7 +2363,7 @@ void WebContents::StartDrag(const gin_helper::Dictionary& item,
|
|||
}
|
||||
|
||||
gin::Handle<NativeImage> icon;
|
||||
if (!item.Get("icon", &icon)) {
|
||||
if (!item.Get("icon", &icon) || icon->image().IsEmpty()) {
|
||||
args->ThrowError("Must specify non-empty 'icon' option");
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -490,9 +490,8 @@ gin::Handle<NativeImage> NativeImage::CreateFromDataURL(v8::Isolate* isolate,
|
|||
}
|
||||
|
||||
#if !defined(OS_MACOSX)
|
||||
gin::Handle<NativeImage> NativeImage::CreateFromNamedImage(
|
||||
gin::Arguments* args,
|
||||
const std::string& name) {
|
||||
gin::Handle<NativeImage> NativeImage::CreateFromNamedImage(gin::Arguments* args,
|
||||
std::string name) {
|
||||
return CreateEmpty(args->isolate());
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -62,7 +62,7 @@ class NativeImage : public gin_helper::Wrappable<NativeImage> {
|
|||
static gin::Handle<NativeImage> CreateFromDataURL(v8::Isolate* isolate,
|
||||
const GURL& url);
|
||||
static gin::Handle<NativeImage> CreateFromNamedImage(gin::Arguments* args,
|
||||
const std::string& name);
|
||||
std::string name);
|
||||
|
||||
static void BuildPrototype(v8::Isolate* isolate,
|
||||
v8::Local<v8::FunctionTemplate> prototype);
|
||||
|
|
|
@ -33,12 +33,24 @@ double safeShift(double in, double def) {
|
|||
return def;
|
||||
}
|
||||
|
||||
gin::Handle<NativeImage> NativeImage::CreateFromNamedImage(
|
||||
gin::Arguments* args,
|
||||
const std::string& name) {
|
||||
gin::Handle<NativeImage> NativeImage::CreateFromNamedImage(gin::Arguments* args,
|
||||
std::string name) {
|
||||
@autoreleasepool {
|
||||
std::vector<double> hsl_shift;
|
||||
|
||||
// The string representations of NSImageNames don't match the strings
|
||||
// themselves; they instead follow the following pattern:
|
||||
// * NSImageNameActionTemplate -> "NSActionTemplate"
|
||||
// * NSImageNameMultipleDocuments -> "NSMultipleDocuments"
|
||||
// To account for this, we strip out "ImageName" from the passed string.
|
||||
std::string to_remove("ImageName");
|
||||
size_t pos = name.find(to_remove);
|
||||
if (pos != std::string::npos) {
|
||||
name.erase(pos, to_remove.length());
|
||||
}
|
||||
|
||||
NSImage* image = [NSImage imageNamed:base::SysUTF8ToNSString(name)];
|
||||
|
||||
if (!image.valid) {
|
||||
return CreateEmpty(args->isolate());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue