mac: Don't rely on NSImage to read file

It doesn't work with asar.
This commit is contained in:
Cheng Zhao 2015-02-12 12:24:18 +08:00
parent 903ff0b61a
commit 509ce0d5cb
3 changed files with 20 additions and 29 deletions

View file

@ -6,35 +6,13 @@
#import <Cocoa/Cocoa.h>
#include "base/files/file_path.h"
#include "base/mac/foundation_util.h"
#include "base/mac/scoped_nsobject.h"
#include "base/strings/string_util.h"
#include "base/strings/sys_string_conversions.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/image/image_skia.h"
namespace atom {
namespace api {
namespace {
bool IsTemplateImage(const base::FilePath& path) {
return (MatchPattern(path.value(), "*Template.*") ||
MatchPattern(path.value(), "*Template@*x.*"));
}
} // namespace
// static
mate::Handle<NativeImage> NativeImage::CreateFromPath(
v8::Isolate* isolate, const base::FilePath& path) {
base::scoped_nsobject<NSImage> image([[NSImage alloc]
initByReferencingFile:base::mac::FilePathToNSString(path)]);
if (IsTemplateImage(path))
[image setTemplate:YES];
return Create(isolate, gfx::Image(image.release()));
void NativeImage::MakeTemplateImage(gfx::Image* image) {
[image->AsNSImage() setTemplate:YES];
}
} // namespace api