|
@@ -10,6 +10,7 @@
|
|
|
#include <vector>
|
|
|
|
|
|
#include "base/files/file_util.h"
|
|
|
+#include "base/logging.h"
|
|
|
#include "base/strings/pattern.h"
|
|
|
#include "base/strings/string_util.h"
|
|
|
#include "base/strings/utf_string_conversions.h"
|
|
@@ -146,7 +147,10 @@ NativeImage::~NativeImage() {
|
|
|
// static
|
|
|
bool NativeImage::TryConvertNativeImage(v8::Isolate* isolate,
|
|
|
v8::Local<v8::Value> image,
|
|
|
- NativeImage** native_image) {
|
|
|
+ NativeImage** native_image,
|
|
|
+ OnConvertError on_error) {
|
|
|
+ std::string error_message;
|
|
|
+
|
|
|
base::FilePath icon_path;
|
|
|
if (gin::ConvertFromV8(isolate, image, &icon_path)) {
|
|
|
*native_image = NativeImage::CreateFromPath(isolate, icon_path).get();
|
|
@@ -156,17 +160,27 @@ bool NativeImage::TryConvertNativeImage(v8::Isolate* isolate,
|
|
|
#else
|
|
|
const auto img_path = icon_path.value();
|
|
|
#endif
|
|
|
- isolate->ThrowException(v8::Exception::Error(gin::StringToV8(
|
|
|
- isolate, "Failed to load image from path '" + img_path + "'")));
|
|
|
- return false;
|
|
|
+ error_message = "Failed to load image from path '" + img_path + "'";
|
|
|
}
|
|
|
} else {
|
|
|
if (!gin::ConvertFromV8(isolate, image, native_image)) {
|
|
|
- isolate->ThrowException(v8::Exception::Error(gin::StringToV8(
|
|
|
- isolate, "Argument must be a file path or a NativeImage")));
|
|
|
- return false;
|
|
|
+ error_message = "Argument must be a file path or a NativeImage";
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ if (!error_message.empty()) {
|
|
|
+ switch (on_error) {
|
|
|
+ case OnConvertError::kThrow:
|
|
|
+ isolate->ThrowException(
|
|
|
+ v8::Exception::Error(gin::StringToV8(isolate, error_message)));
|
|
|
+ break;
|
|
|
+ case OnConvertError::kWarn:
|
|
|
+ LOG(WARNING) << error_message;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
return true;
|
|
|
}
|
|
|
|