also format missing .cc files
This commit is contained in:
parent
53bdf22c85
commit
c6f4bbd143
181 changed files with 4102 additions and 4254 deletions
|
@ -22,15 +22,15 @@ namespace {
|
|||
class Archive : public mate::Wrappable<Archive> {
|
||||
public:
|
||||
static v8::Local<v8::Value> Create(v8::Isolate* isolate,
|
||||
const base::FilePath& path) {
|
||||
const base::FilePath& path) {
|
||||
std::unique_ptr<asar::Archive> archive(new asar::Archive(path));
|
||||
if (!archive->Init())
|
||||
return v8::False(isolate);
|
||||
return (new Archive(isolate, std::move(archive)))->GetWrapper();
|
||||
}
|
||||
|
||||
static void BuildPrototype(
|
||||
v8::Isolate* isolate, v8::Local<v8::FunctionTemplate> prototype) {
|
||||
static void BuildPrototype(v8::Isolate* isolate,
|
||||
v8::Local<v8::FunctionTemplate> prototype) {
|
||||
prototype->SetClassName(mate::StringToV8(isolate, "Archive"));
|
||||
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
||||
.SetProperty("path", &Archive::GetPath)
|
||||
|
@ -50,13 +50,11 @@ class Archive : public mate::Wrappable<Archive> {
|
|||
}
|
||||
|
||||
// Returns the path of the file.
|
||||
base::FilePath GetPath() {
|
||||
return archive_->path();
|
||||
}
|
||||
base::FilePath GetPath() { return archive_->path(); }
|
||||
|
||||
// Reads the offset and size of file.
|
||||
v8::Local<v8::Value> GetFileInfo(v8::Isolate* isolate,
|
||||
const base::FilePath& path) {
|
||||
const base::FilePath& path) {
|
||||
asar::Archive::FileInfo info;
|
||||
if (!archive_ || !archive_->GetFileInfo(path, &info))
|
||||
return v8::False(isolate);
|
||||
|
@ -68,8 +66,7 @@ class Archive : public mate::Wrappable<Archive> {
|
|||
}
|
||||
|
||||
// Returns a fake result of fs.stat(path).
|
||||
v8::Local<v8::Value> Stat(v8::Isolate* isolate,
|
||||
const base::FilePath& path) {
|
||||
v8::Local<v8::Value> Stat(v8::Isolate* isolate, const base::FilePath& path) {
|
||||
asar::Archive::Stats stats;
|
||||
if (!archive_ || !archive_->Stat(path, &stats))
|
||||
return v8::False(isolate);
|
||||
|
@ -84,7 +81,7 @@ class Archive : public mate::Wrappable<Archive> {
|
|||
|
||||
// Returns all files under a directory.
|
||||
v8::Local<v8::Value> Readdir(v8::Isolate* isolate,
|
||||
const base::FilePath& path) {
|
||||
const base::FilePath& path) {
|
||||
std::vector<base::FilePath> files;
|
||||
if (!archive_ || !archive_->Readdir(path, &files))
|
||||
return v8::False(isolate);
|
||||
|
@ -93,7 +90,7 @@ class Archive : public mate::Wrappable<Archive> {
|
|||
|
||||
// Returns the path of file with symbol link resolved.
|
||||
v8::Local<v8::Value> Realpath(v8::Isolate* isolate,
|
||||
const base::FilePath& path) {
|
||||
const base::FilePath& path) {
|
||||
base::FilePath realpath;
|
||||
if (!archive_ || !archive_->Realpath(path, &realpath))
|
||||
return v8::False(isolate);
|
||||
|
@ -102,7 +99,7 @@ class Archive : public mate::Wrappable<Archive> {
|
|||
|
||||
// Copy the file out into a temporary file and returns the new path.
|
||||
v8::Local<v8::Value> CopyFileOut(v8::Isolate* isolate,
|
||||
const base::FilePath& path) {
|
||||
const base::FilePath& path) {
|
||||
base::FilePath new_path;
|
||||
if (!archive_ || !archive_->CopyFileOut(path, &new_path))
|
||||
return v8::False(isolate);
|
||||
|
@ -117,9 +114,7 @@ class Archive : public mate::Wrappable<Archive> {
|
|||
}
|
||||
|
||||
// Free the resources used by archive.
|
||||
void Destroy() {
|
||||
archive_.reset();
|
||||
}
|
||||
void Destroy() { archive_.reset(); }
|
||||
|
||||
private:
|
||||
std::unique_ptr<asar::Archive> archive_;
|
||||
|
@ -138,14 +133,18 @@ void InitAsarSupport(v8::Isolate* isolate,
|
|||
// Initialize asar support.
|
||||
if (result->IsFunction()) {
|
||||
v8::Local<v8::Value> args[] = {
|
||||
process, require, node::asar_value.ToStringChecked(isolate),
|
||||
process,
|
||||
require,
|
||||
node::asar_value.ToStringChecked(isolate),
|
||||
};
|
||||
result.As<v8::Function>()->Call(result, 3, args);
|
||||
}
|
||||
}
|
||||
|
||||
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
||||
v8::Local<v8::Context> context, void* priv) {
|
||||
void Initialize(v8::Local<v8::Object> exports,
|
||||
v8::Local<v8::Value> unused,
|
||||
v8::Local<v8::Context> context,
|
||||
void* priv) {
|
||||
mate::Dictionary dict(context->GetIsolate(), exports);
|
||||
dict.SetMethod("createArchive", &Archive::Create);
|
||||
dict.SetMethod("initAsarSupport", &InitAsarSupport);
|
||||
|
|
|
@ -16,12 +16,13 @@ using crash_reporter::CrashReporter;
|
|||
|
||||
namespace mate {
|
||||
|
||||
template<>
|
||||
template <>
|
||||
struct Converter<CrashReporter::UploadReportResult> {
|
||||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||
static v8::Local<v8::Value> ToV8(
|
||||
v8::Isolate* isolate,
|
||||
const CrashReporter::UploadReportResult& reports) {
|
||||
mate::Dictionary dict(isolate, v8::Object::New(isolate));
|
||||
dict.Set("date", v8::Date::New(isolate, reports.first*1000.0));
|
||||
dict.Set("date", v8::Date::New(isolate, reports.first * 1000.0));
|
||||
dict.Set("id", reports.second);
|
||||
return dict.GetHandle();
|
||||
}
|
||||
|
@ -43,8 +44,10 @@ std::map<std::string, std::string> GetParameters() {
|
|||
return CrashReporter::GetInstance()->GetParameters();
|
||||
}
|
||||
|
||||
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
||||
v8::Local<v8::Context> context, void* priv) {
|
||||
void Initialize(v8::Local<v8::Object> exports,
|
||||
v8::Local<v8::Value> unused,
|
||||
v8::Local<v8::Context> context,
|
||||
void* priv) {
|
||||
mate::Dictionary dict(context->GetIsolate(), exports);
|
||||
auto reporter = base::Unretained(CrashReporter::GetInstance());
|
||||
dict.SetMethod("start", base::Bind(&CrashReporter::Start, reporter));
|
||||
|
|
|
@ -50,18 +50,10 @@ struct ScaleFactorPair {
|
|||
};
|
||||
|
||||
ScaleFactorPair kScaleFactorPairs[] = {
|
||||
// The "@2x" is put as first one to make scale matching faster.
|
||||
{ "@2x" , 2.0f },
|
||||
{ "@3x" , 3.0f },
|
||||
{ "@1x" , 1.0f },
|
||||
{ "@4x" , 4.0f },
|
||||
{ "@5x" , 5.0f },
|
||||
{ "@1.25x" , 1.25f },
|
||||
{ "@1.33x" , 1.33f },
|
||||
{ "@1.4x" , 1.4f },
|
||||
{ "@1.5x" , 1.5f },
|
||||
{ "@1.8x" , 1.8f },
|
||||
{ "@2.5x" , 2.5f },
|
||||
// The "@2x" is put as first one to make scale matching faster.
|
||||
{"@2x", 2.0f}, {"@3x", 3.0f}, {"@1x", 1.0f}, {"@4x", 4.0f},
|
||||
{"@5x", 5.0f}, {"@1.25x", 1.25f}, {"@1.33x", 1.33f}, {"@1.4x", 1.4f},
|
||||
{"@1.5x", 1.5f}, {"@1.8x", 1.8f}, {"@2.5x", 2.5f},
|
||||
};
|
||||
|
||||
float GetScaleFactorFromPath(const base::FilePath& path) {
|
||||
|
@ -117,7 +109,7 @@ bool AddImageSkiaRep(gfx::ImageSkia* image,
|
|||
decoded.reset(new SkBitmap);
|
||||
decoded->allocN32Pixels(width, height, false);
|
||||
decoded->setPixels(
|
||||
const_cast<void*>(reinterpret_cast<const void*>(data)));
|
||||
const_cast<void*>(reinterpret_cast<const void*>(data)));
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
@ -154,9 +146,8 @@ bool PopulateImageSkiaRepsFromPath(gfx::ImageSkia* image,
|
|||
succeed |= AddImageSkiaRep(image, path, 1.0f);
|
||||
|
||||
for (const ScaleFactorPair& pair : kScaleFactorPairs)
|
||||
succeed |= AddImageSkiaRep(image,
|
||||
path.InsertBeforeExtensionASCII(pair.name),
|
||||
pair.scale);
|
||||
succeed |= AddImageSkiaRep(
|
||||
image, path.InsertBeforeExtensionASCII(pair.name), pair.scale);
|
||||
return succeed;
|
||||
}
|
||||
|
||||
|
@ -195,9 +186,9 @@ base::win::ScopedHICON ReadICOFromPath(int size, const base::FilePath& path) {
|
|||
}
|
||||
|
||||
// Load the icon from file.
|
||||
return base::win::ScopedHICON(static_cast<HICON>(
|
||||
LoadImage(NULL, image_path.value().c_str(), IMAGE_ICON, size, size,
|
||||
LR_LOADFROMFILE)));
|
||||
return base::win::ScopedHICON(
|
||||
static_cast<HICON>(LoadImage(NULL, image_path.value().c_str(), IMAGE_ICON,
|
||||
size, size, LR_LOADFROMFILE)));
|
||||
}
|
||||
|
||||
bool ReadImageSkiaFromICO(gfx::ImageSkia* image, HICON icon) {
|
||||
|
@ -211,8 +202,7 @@ bool ReadImageSkiaFromICO(gfx::ImageSkia* image, HICON icon) {
|
|||
}
|
||||
#endif
|
||||
|
||||
void Noop(char*, void*) {
|
||||
}
|
||||
void Noop(char*, void*) {}
|
||||
|
||||
} // namespace
|
||||
|
||||
|
@ -221,7 +211,7 @@ NativeImage::NativeImage(v8::Isolate* isolate, const gfx::Image& image)
|
|||
Init(isolate);
|
||||
if (image_.HasRepresentation(gfx::Image::kImageRepSkia)) {
|
||||
isolate->AdjustAmountOfExternalAllocatedMemory(
|
||||
image_.ToImageSkia()->bitmap()->computeByteSize());
|
||||
image_.ToImageSkia()->bitmap()->computeByteSize());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -235,15 +225,15 @@ NativeImage::NativeImage(v8::Isolate* isolate, const base::FilePath& hicon_path)
|
|||
Init(isolate);
|
||||
if (image_.HasRepresentation(gfx::Image::kImageRepSkia)) {
|
||||
isolate->AdjustAmountOfExternalAllocatedMemory(
|
||||
image_.ToImageSkia()->bitmap()->computeByteSize());
|
||||
image_.ToImageSkia()->bitmap()->computeByteSize());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
NativeImage::~NativeImage() {
|
||||
if (image_.HasRepresentation(gfx::Image::kImageRepSkia)) {
|
||||
isolate()->AdjustAmountOfExternalAllocatedMemory(
|
||||
-static_cast<int64_t>(image_.ToImageSkia()->bitmap()->computeByteSize()));
|
||||
isolate()->AdjustAmountOfExternalAllocatedMemory(-static_cast<int64_t>(
|
||||
image_.ToImageSkia()->bitmap()->computeByteSize()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -262,8 +252,8 @@ HICON NativeImage::GetHICON(int size) {
|
|||
// Then convert the image to ICO.
|
||||
if (image_.IsEmpty())
|
||||
return NULL;
|
||||
hicons_[size] = std::move(
|
||||
IconUtil::CreateHICONFromSkBitmap(image_.AsBitmap()));
|
||||
hicons_[size] =
|
||||
std::move(IconUtil::CreateHICONFromSkBitmap(image_.AsBitmap()));
|
||||
return hicons_[size].get();
|
||||
}
|
||||
#endif
|
||||
|
@ -300,7 +290,8 @@ v8::Local<v8::Value> NativeImage::ToBitmap(mate::Arguments* args) {
|
|||
return node::Buffer::New(args->isolate(), 0).ToLocalChecked();
|
||||
return node::Buffer::Copy(args->isolate(),
|
||||
reinterpret_cast<const char*>(ref->pixels()),
|
||||
bitmap.computeByteSize()).ToLocalChecked();
|
||||
bitmap.computeByteSize())
|
||||
.ToLocalChecked();
|
||||
}
|
||||
|
||||
v8::Local<v8::Value> NativeImage::ToJPEG(v8::Isolate* isolate, int quality) {
|
||||
|
@ -308,10 +299,10 @@ v8::Local<v8::Value> NativeImage::ToJPEG(v8::Isolate* isolate, int quality) {
|
|||
gfx::JPEG1xEncodedDataFromImage(image_, quality, &output);
|
||||
if (output.empty())
|
||||
return node::Buffer::New(isolate, 0).ToLocalChecked();
|
||||
return node::Buffer::Copy(
|
||||
isolate,
|
||||
reinterpret_cast<const char*>(&output.front()),
|
||||
output.size()).ToLocalChecked();
|
||||
return node::Buffer::Copy(isolate,
|
||||
reinterpret_cast<const char*>(&output.front()),
|
||||
output.size())
|
||||
.ToLocalChecked();
|
||||
}
|
||||
|
||||
std::string NativeImage::ToDataURL(mate::Arguments* args) {
|
||||
|
@ -338,21 +329,20 @@ v8::Local<v8::Value> NativeImage::GetBitmap(mate::Arguments* args) {
|
|||
return node::Buffer::New(args->isolate(), 0).ToLocalChecked();
|
||||
return node::Buffer::New(args->isolate(),
|
||||
reinterpret_cast<char*>(ref->pixels()),
|
||||
bitmap.computeByteSize(),
|
||||
&Noop,
|
||||
nullptr).ToLocalChecked();
|
||||
bitmap.computeByteSize(), &Noop, nullptr)
|
||||
.ToLocalChecked();
|
||||
}
|
||||
|
||||
v8::Local<v8::Value> NativeImage::GetNativeHandle(v8::Isolate* isolate,
|
||||
mate::Arguments* args) {
|
||||
#if defined(OS_MACOSX)
|
||||
if (IsEmpty()) return node::Buffer::New(isolate, 0).ToLocalChecked();
|
||||
if (IsEmpty())
|
||||
return node::Buffer::New(isolate, 0).ToLocalChecked();
|
||||
|
||||
NSImage* ptr = image_.AsNSImage();
|
||||
return node::Buffer::Copy(
|
||||
isolate,
|
||||
reinterpret_cast<char*>(ptr),
|
||||
sizeof(void*)).ToLocalChecked();
|
||||
return node::Buffer::Copy(isolate, reinterpret_cast<char*>(ptr),
|
||||
sizeof(void*))
|
||||
.ToLocalChecked();
|
||||
#else
|
||||
args->ThrowError("Not implemented");
|
||||
return v8::Undefined(isolate);
|
||||
|
@ -376,7 +366,8 @@ float NativeImage::GetAspectRatio() {
|
|||
}
|
||||
|
||||
mate::Handle<NativeImage> NativeImage::Resize(
|
||||
v8::Isolate* isolate, const base::DictionaryValue& options) {
|
||||
v8::Isolate* isolate,
|
||||
const base::DictionaryValue& options) {
|
||||
gfx::Size size = GetSize();
|
||||
int width = size.width();
|
||||
int height = size.height();
|
||||
|
@ -411,8 +402,8 @@ mate::Handle<NativeImage> NativeImage::Resize(
|
|||
|
||||
mate::Handle<NativeImage> NativeImage::Crop(v8::Isolate* isolate,
|
||||
const gfx::Rect& rect) {
|
||||
gfx::ImageSkia cropped = gfx::ImageSkiaOperations::ExtractSubset(
|
||||
image_.AsImageSkia(), rect);
|
||||
gfx::ImageSkia cropped =
|
||||
gfx::ImageSkiaOperations::ExtractSubset(image_.AsImageSkia(), rect);
|
||||
return mate::CreateHandle(isolate,
|
||||
new NativeImage(isolate, gfx::Image(cropped)));
|
||||
}
|
||||
|
@ -434,18 +425,15 @@ void NativeImage::AddRepresentation(const mate::Dictionary& options) {
|
|||
AddImageSkiaRep(
|
||||
&image_skia,
|
||||
reinterpret_cast<unsigned char*>(node::Buffer::Data(buffer)),
|
||||
node::Buffer::Length(buffer),
|
||||
width, height, scale_factor);
|
||||
node::Buffer::Length(buffer), width, height, scale_factor);
|
||||
skia_rep_added = true;
|
||||
} else if (options.Get("dataURL", &url)) {
|
||||
std::string mime_type, charset, data;
|
||||
if (net::DataURL::Parse(url, &mime_type, &charset, &data)) {
|
||||
if (mime_type == "image/png" || mime_type == "image/jpeg") {
|
||||
AddImageSkiaRep(
|
||||
&image_skia,
|
||||
reinterpret_cast<const unsigned char*>(data.c_str()),
|
||||
data.size(),
|
||||
width, height, scale_factor);
|
||||
AddImageSkiaRep(&image_skia,
|
||||
reinterpret_cast<const unsigned char*>(data.c_str()),
|
||||
data.size(), width, height, scale_factor);
|
||||
skia_rep_added = true;
|
||||
}
|
||||
}
|
||||
|
@ -459,8 +447,7 @@ void NativeImage::AddRepresentation(const mate::Dictionary& options) {
|
|||
}
|
||||
|
||||
#if !defined(OS_MACOSX)
|
||||
void NativeImage::SetTemplateImage(bool setAsTemplate) {
|
||||
}
|
||||
void NativeImage::SetTemplateImage(bool setAsTemplate) {}
|
||||
|
||||
bool NativeImage::IsTemplateImage() {
|
||||
return false;
|
||||
|
@ -473,22 +460,24 @@ mate::Handle<NativeImage> NativeImage::CreateEmpty(v8::Isolate* isolate) {
|
|||
}
|
||||
|
||||
// static
|
||||
mate::Handle<NativeImage> NativeImage::Create(
|
||||
v8::Isolate* isolate, const gfx::Image& image) {
|
||||
mate::Handle<NativeImage> NativeImage::Create(v8::Isolate* isolate,
|
||||
const gfx::Image& image) {
|
||||
return mate::CreateHandle(isolate, new NativeImage(isolate, image));
|
||||
}
|
||||
|
||||
// static
|
||||
mate::Handle<NativeImage> NativeImage::CreateFromPNG(
|
||||
v8::Isolate* isolate, const char* buffer, size_t length) {
|
||||
mate::Handle<NativeImage> NativeImage::CreateFromPNG(v8::Isolate* isolate,
|
||||
const char* buffer,
|
||||
size_t length) {
|
||||
gfx::Image image = gfx::Image::CreateFrom1xPNGBytes(
|
||||
reinterpret_cast<const unsigned char*>(buffer), length);
|
||||
return Create(isolate, image);
|
||||
}
|
||||
|
||||
// static
|
||||
mate::Handle<NativeImage> NativeImage::CreateFromJPEG(
|
||||
v8::Isolate* isolate, const char* buffer, size_t length) {
|
||||
mate::Handle<NativeImage> NativeImage::CreateFromJPEG(v8::Isolate* isolate,
|
||||
const char* buffer,
|
||||
size_t length) {
|
||||
gfx::Image image = gfx::ImageFrom1xJPEGEncodedData(
|
||||
reinterpret_cast<const unsigned char*>(buffer), length);
|
||||
return Create(isolate, image);
|
||||
|
@ -496,12 +485,12 @@ mate::Handle<NativeImage> NativeImage::CreateFromJPEG(
|
|||
|
||||
// static
|
||||
mate::Handle<NativeImage> NativeImage::CreateFromPath(
|
||||
v8::Isolate* isolate, const base::FilePath& path) {
|
||||
v8::Isolate* isolate,
|
||||
const base::FilePath& path) {
|
||||
base::FilePath image_path = NormalizePath(path);
|
||||
#if defined(OS_WIN)
|
||||
if (image_path.MatchesExtension(FILE_PATH_LITERAL(".ico"))) {
|
||||
return mate::CreateHandle(isolate,
|
||||
new NativeImage(isolate, image_path));
|
||||
return mate::CreateHandle(isolate, new NativeImage(isolate, image_path));
|
||||
}
|
||||
#endif
|
||||
gfx::ImageSkia image_skia;
|
||||
|
@ -517,7 +506,8 @@ mate::Handle<NativeImage> NativeImage::CreateFromPath(
|
|||
|
||||
// static
|
||||
mate::Handle<NativeImage> NativeImage::CreateFromBuffer(
|
||||
mate::Arguments* args, v8::Local<v8::Value> buffer) {
|
||||
mate::Arguments* args,
|
||||
v8::Local<v8::Value> buffer) {
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
double scale_factor = 1.;
|
||||
|
@ -535,16 +525,13 @@ mate::Handle<NativeImage> NativeImage::CreateFromBuffer(
|
|||
gfx::ImageSkia image_skia;
|
||||
AddImageSkiaRep(&image_skia,
|
||||
reinterpret_cast<unsigned char*>(node::Buffer::Data(buffer)),
|
||||
node::Buffer::Length(buffer),
|
||||
width,
|
||||
height,
|
||||
scale_factor);
|
||||
node::Buffer::Length(buffer), width, height, scale_factor);
|
||||
return Create(args->isolate(), gfx::Image(image_skia));
|
||||
}
|
||||
|
||||
// static
|
||||
mate::Handle<NativeImage> NativeImage::CreateFromDataURL(
|
||||
v8::Isolate* isolate, const GURL& url) {
|
||||
mate::Handle<NativeImage> NativeImage::CreateFromDataURL(v8::Isolate* isolate,
|
||||
const GURL& url) {
|
||||
std::string mime_type, charset, data;
|
||||
if (net::DataURL::Parse(url, &mime_type, &charset, &data)) {
|
||||
if (mime_type == "image/png")
|
||||
|
@ -558,14 +545,15 @@ mate::Handle<NativeImage> NativeImage::CreateFromDataURL(
|
|||
|
||||
#if !defined(OS_MACOSX)
|
||||
mate::Handle<NativeImage> NativeImage::CreateFromNamedImage(
|
||||
mate::Arguments* args, const std::string& name) {
|
||||
mate::Arguments* args,
|
||||
const std::string& name) {
|
||||
return CreateEmpty(args->isolate());
|
||||
}
|
||||
#endif
|
||||
|
||||
// static
|
||||
void NativeImage::BuildPrototype(
|
||||
v8::Isolate* isolate, v8::Local<v8::FunctionTemplate> prototype) {
|
||||
void NativeImage::BuildPrototype(v8::Isolate* isolate,
|
||||
v8::Local<v8::FunctionTemplate> prototype) {
|
||||
prototype->SetClassName(mate::StringToV8(isolate, "NativeImage"));
|
||||
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
||||
.SetMethod("toPNG", &NativeImage::ToPNG)
|
||||
|
@ -597,7 +585,8 @@ v8::Local<v8::Value> Converter<mate::Handle<atom::api::NativeImage>>::ToV8(
|
|||
}
|
||||
|
||||
bool Converter<mate::Handle<atom::api::NativeImage>>::FromV8(
|
||||
v8::Isolate* isolate, v8::Local<v8::Value> val,
|
||||
v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
mate::Handle<atom::api::NativeImage>* out) {
|
||||
// Try converting from file path.
|
||||
base::FilePath path;
|
||||
|
@ -607,8 +596,8 @@ bool Converter<mate::Handle<atom::api::NativeImage>>::FromV8(
|
|||
return !(*out)->image().IsEmpty();
|
||||
}
|
||||
|
||||
WrappableBase* wrapper = static_cast<WrappableBase*>(internal::FromV8Impl(
|
||||
isolate, val));
|
||||
WrappableBase* wrapper =
|
||||
static_cast<WrappableBase*>(internal::FromV8Impl(isolate, val));
|
||||
if (!wrapper)
|
||||
return false;
|
||||
|
||||
|
@ -620,8 +609,10 @@ bool Converter<mate::Handle<atom::api::NativeImage>>::FromV8(
|
|||
|
||||
namespace {
|
||||
|
||||
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
||||
v8::Local<v8::Context> context, void* priv) {
|
||||
void Initialize(v8::Local<v8::Object> exports,
|
||||
v8::Local<v8::Value> unused,
|
||||
v8::Local<v8::Context> context,
|
||||
void* priv) {
|
||||
mate::Dictionary dict(context->GetIsolate(), exports);
|
||||
dict.SetMethod("createEmpty", &atom::api::NativeImage::CreateEmpty);
|
||||
dict.SetMethod("createFromPath", &atom::api::NativeImage::CreateFromPath);
|
||||
|
|
|
@ -18,12 +18,13 @@
|
|||
|
||||
namespace mate {
|
||||
|
||||
template<>
|
||||
template <>
|
||||
struct Converter<base::win::ShortcutOperation> {
|
||||
static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val,
|
||||
static bool FromV8(v8::Isolate* isolate,
|
||||
v8::Handle<v8::Value> val,
|
||||
base::win::ShortcutOperation* out) {
|
||||
std::string operation;
|
||||
if (!ConvertFromV8(isolate, val, & operation))
|
||||
if (!ConvertFromV8(isolate, val, &operation))
|
||||
return false;
|
||||
if (operation.empty() || operation == "create")
|
||||
*out = base::win::SHORTCUT_CREATE_ALWAYS;
|
||||
|
@ -109,8 +110,8 @@ bool WriteShortcutLink(const base::FilePath& shortcut_path,
|
|||
properties.set_app_id(str);
|
||||
|
||||
base::win::ScopedCOMInitializer com_initializer;
|
||||
return base::win::CreateOrUpdateShortcutLink(
|
||||
shortcut_path, properties, operation);
|
||||
return base::win::CreateOrUpdateShortcutLink(shortcut_path, properties,
|
||||
operation);
|
||||
}
|
||||
|
||||
v8::Local<v8::Value> ReadShortcutLink(mate::Arguments* args,
|
||||
|
@ -135,8 +136,10 @@ v8::Local<v8::Value> ReadShortcutLink(mate::Arguments* args,
|
|||
}
|
||||
#endif
|
||||
|
||||
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
||||
v8::Local<v8::Context> context, void* priv) {
|
||||
void Initialize(v8::Local<v8::Object> exports,
|
||||
v8::Local<v8::Value> unused,
|
||||
v8::Local<v8::Context> context,
|
||||
void* priv) {
|
||||
mate::Dictionary dict(context->GetIsolate(), exports);
|
||||
dict.SetMethod("showItemInFolder", &platform_util::ShowItemInFolder);
|
||||
dict.SetMethod("openItem", &platform_util::OpenItem);
|
||||
|
|
|
@ -30,7 +30,7 @@ struct hash<std::pair<Type1, Type2>> {
|
|||
|
||||
namespace mate {
|
||||
|
||||
template<typename Type1, typename Type2>
|
||||
template <typename Type1, typename Type2>
|
||||
struct Converter<std::pair<Type1, Type2>> {
|
||||
static bool FromV8(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
|
@ -96,15 +96,17 @@ void TakeHeapSnapshot(v8::Isolate* isolate) {
|
|||
|
||||
void RequestGarbageCollectionForTesting(v8::Isolate* isolate) {
|
||||
isolate->RequestGarbageCollectionForTesting(
|
||||
v8::Isolate::GarbageCollectionType::kFullGarbageCollection);
|
||||
v8::Isolate::GarbageCollectionType::kFullGarbageCollection);
|
||||
}
|
||||
|
||||
bool IsSameOrigin(const GURL& l, const GURL& r) {
|
||||
return url::Origin(l).IsSameOriginWith(url::Origin(r));
|
||||
}
|
||||
|
||||
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
||||
v8::Local<v8::Context> context, void* priv) {
|
||||
void Initialize(v8::Local<v8::Object> exports,
|
||||
v8::Local<v8::Value> unused,
|
||||
v8::Local<v8::Context> context,
|
||||
void* priv) {
|
||||
mate::Dictionary dict(context->GetIsolate(), exports);
|
||||
dict.SetMethod("getHiddenValue", &GetHiddenValue);
|
||||
dict.SetMethod("setHiddenValue", &SetHiddenValue);
|
||||
|
|
|
@ -22,7 +22,9 @@ namespace atom {
|
|||
namespace {
|
||||
|
||||
// Dummy class type that used for crashing the program.
|
||||
struct DummyClass { bool crash; };
|
||||
struct DummyClass {
|
||||
bool crash;
|
||||
};
|
||||
|
||||
// Called when there is a fatal error in V8, we just crash the process here so
|
||||
// we can get the stack trace.
|
||||
|
@ -33,7 +35,6 @@ void FatalErrorCallback(const char* location, const char* message) {
|
|||
|
||||
} // namespace
|
||||
|
||||
|
||||
AtomBindings::AtomBindings(uv_loop_t* loop) {
|
||||
uv_async_init(loop, &call_next_tick_async_, OnCallNextTick);
|
||||
call_next_tick_async_.data = this;
|
||||
|
@ -44,8 +45,7 @@ AtomBindings::~AtomBindings() {
|
|||
uv_close(reinterpret_cast<uv_handle_t*>(&call_next_tick_async_), nullptr);
|
||||
}
|
||||
|
||||
void AtomBindings::BindTo(v8::Isolate* isolate,
|
||||
v8::Local<v8::Object> process) {
|
||||
void AtomBindings::BindTo(v8::Isolate* isolate, v8::Local<v8::Object> process) {
|
||||
v8::V8::SetFatalErrorHandler(FatalErrorCallback);
|
||||
|
||||
mate::Dictionary dict(isolate, process);
|
||||
|
@ -54,14 +54,14 @@ void AtomBindings::BindTo(v8::Isolate* isolate,
|
|||
dict.SetMethod("log", &Log);
|
||||
dict.SetMethod("getProcessMemoryInfo", &GetProcessMemoryInfo);
|
||||
dict.SetMethod("getSystemMemoryInfo", &GetSystemMemoryInfo);
|
||||
dict.SetMethod("getCPUUsage",
|
||||
base::Bind(&AtomBindings::GetCPUUsage, base::Unretained(this)));
|
||||
dict.SetMethod("getCPUUsage", base::Bind(&AtomBindings::GetCPUUsage,
|
||||
base::Unretained(this)));
|
||||
dict.SetMethod("getIOCounters", &GetIOCounters);
|
||||
#if defined(OS_POSIX)
|
||||
dict.SetMethod("setFdLimit", &base::SetFdLimit);
|
||||
#endif
|
||||
dict.SetMethod("activateUvLoop",
|
||||
base::Bind(&AtomBindings::ActivateUVLoop, base::Unretained(this)));
|
||||
dict.SetMethod("activateUvLoop", base::Bind(&AtomBindings::ActivateUVLoop,
|
||||
base::Unretained(this)));
|
||||
|
||||
#if defined(MAS_BUILD)
|
||||
dict.Set("mas", true);
|
||||
|
@ -76,8 +76,8 @@ void AtomBindings::BindTo(v8::Isolate* isolate,
|
|||
}
|
||||
|
||||
void AtomBindings::EnvironmentDestroyed(node::Environment* env) {
|
||||
auto it = std::find(pending_next_ticks_.begin(), pending_next_ticks_.end(),
|
||||
env);
|
||||
auto it =
|
||||
std::find(pending_next_ticks_.begin(), pending_next_ticks_.end(), env);
|
||||
if (it != pending_next_ticks_.end())
|
||||
pending_next_ticks_.erase(it);
|
||||
}
|
||||
|
@ -102,9 +102,7 @@ void AtomBindings::OnCallNextTick(uv_async_t* handle) {
|
|||
mate::Locker locker(env->isolate());
|
||||
v8::Context::Scope context_scope(env->context());
|
||||
node::InternalCallbackScope scope(
|
||||
env,
|
||||
v8::Local<v8::Object>(),
|
||||
{0, 0},
|
||||
env, v8::Local<v8::Object>(), {0, 0},
|
||||
node::InternalCallbackScope::kAllowEmptyResource);
|
||||
}
|
||||
|
||||
|
@ -149,7 +147,7 @@ v8::Local<v8::Value> AtomBindings::GetProcessMemoryInfo(v8::Isolate* isolate) {
|
|||
|
||||
// static
|
||||
v8::Local<v8::Value> AtomBindings::GetSystemMemoryInfo(v8::Isolate* isolate,
|
||||
mate::Arguments* args) {
|
||||
mate::Arguments* args) {
|
||||
base::SystemMemoryInfoKB mem_info;
|
||||
if (!base::GetSystemMemoryInfo(&mem_info)) {
|
||||
args->ThrowError("Unable to retrieve system memory information");
|
||||
|
|
|
@ -20,9 +20,8 @@ v8::Local<v8::Value> CallMethodWithArgs(v8::Isolate* isolate,
|
|||
v8::MicrotasksScope::kRunMicrotasks);
|
||||
// Use node::MakeCallback to call the callback, and it will also run pending
|
||||
// tasks in Node.js.
|
||||
v8::MaybeLocal<v8::Value> ret = node::MakeCallback(isolate, obj, method,
|
||||
args->size(),
|
||||
&args->front(), {0, 0});
|
||||
v8::MaybeLocal<v8::Value> ret = node::MakeCallback(
|
||||
isolate, obj, method, args->size(), &args->front(), {0, 0});
|
||||
// If the JS function throws an exception (doesn't return a value) the result
|
||||
// of MakeCallback will be empty and therefore ToLocal will be false, in this
|
||||
// case we need to return "false" as that indicates that the event emitter did
|
||||
|
|
|
@ -11,7 +11,6 @@ Locker::Locker(v8::Isolate* isolate) {
|
|||
locker_.reset(new v8::Locker(isolate));
|
||||
}
|
||||
|
||||
Locker::~Locker() {
|
||||
}
|
||||
Locker::~Locker() {}
|
||||
|
||||
} // namespace mate
|
||||
|
|
|
@ -12,8 +12,7 @@ namespace atom {
|
|||
|
||||
ObjectLifeMonitor::ObjectLifeMonitor(v8::Isolate* isolate,
|
||||
v8::Local<v8::Object> target)
|
||||
: target_(isolate, target),
|
||||
weak_ptr_factory_(this) {
|
||||
: target_(isolate, target), weak_ptr_factory_(this) {
|
||||
target_.SetWeak(this, OnObjectGC, v8::WeakCallbackType::kParameter);
|
||||
}
|
||||
|
||||
|
|
|
@ -26,11 +26,9 @@ RemoteCallbackFreer::RemoteCallbackFreer(v8::Isolate* isolate,
|
|||
content::WebContents* web_contents)
|
||||
: ObjectLifeMonitor(isolate, target),
|
||||
content::WebContentsObserver(web_contents),
|
||||
object_id_(object_id) {
|
||||
}
|
||||
object_id_(object_id) {}
|
||||
|
||||
RemoteCallbackFreer::~RemoteCallbackFreer() {
|
||||
}
|
||||
RemoteCallbackFreer::~RemoteCallbackFreer() {}
|
||||
|
||||
void RemoteCallbackFreer::RunDestructor() {
|
||||
base::string16 channel =
|
||||
|
|
|
@ -27,13 +27,15 @@ content::RenderFrame* GetCurrentRenderFrame() {
|
|||
} // namespace
|
||||
|
||||
// static
|
||||
void RemoteObjectFreer::BindTo(
|
||||
v8::Isolate* isolate, v8::Local<v8::Object> target, int object_id) {
|
||||
void RemoteObjectFreer::BindTo(v8::Isolate* isolate,
|
||||
v8::Local<v8::Object> target,
|
||||
int object_id) {
|
||||
new RemoteObjectFreer(isolate, target, object_id);
|
||||
}
|
||||
|
||||
RemoteObjectFreer::RemoteObjectFreer(
|
||||
v8::Isolate* isolate, v8::Local<v8::Object> target, int object_id)
|
||||
RemoteObjectFreer::RemoteObjectFreer(v8::Isolate* isolate,
|
||||
v8::Local<v8::Object> target,
|
||||
int object_id)
|
||||
: ObjectLifeMonitor(isolate, target),
|
||||
object_id_(object_id),
|
||||
routing_id_(MSG_ROUTING_NONE) {
|
||||
|
@ -43,8 +45,7 @@ RemoteObjectFreer::RemoteObjectFreer(
|
|||
}
|
||||
}
|
||||
|
||||
RemoteObjectFreer::~RemoteObjectFreer() {
|
||||
}
|
||||
RemoteObjectFreer::~RemoteObjectFreer() {}
|
||||
|
||||
void RemoteObjectFreer::RunDestructor() {
|
||||
content::RenderFrame* render_frame =
|
||||
|
|
|
@ -121,8 +121,7 @@ Archive::Archive(const base::FilePath& path)
|
|||
base::ThreadRestrictions::ScopedAllowIO allow_io;
|
||||
file_.Initialize(path_, base::File::FLAG_OPEN | base::File::FLAG_READ);
|
||||
#if defined(OS_WIN)
|
||||
fd_ =
|
||||
_open_osfhandle(reinterpret_cast<intptr_t>(file_.GetPlatformFile()), 0);
|
||||
fd_ = _open_osfhandle(reinterpret_cast<intptr_t>(file_.GetPlatformFile()), 0);
|
||||
#elif defined(OS_POSIX)
|
||||
fd_ = file_.GetPlatformFile();
|
||||
#else
|
||||
|
@ -145,8 +144,8 @@ Archive::~Archive() {
|
|||
bool Archive::Init() {
|
||||
if (!file_.IsValid()) {
|
||||
if (file_.error_details() != base::File::FILE_ERROR_NOT_FOUND) {
|
||||
LOG(WARNING) << "Opening " << path_.value()
|
||||
<< ": " << base::File::ErrorToString(file_.error_details());
|
||||
LOG(WARNING) << "Opening " << path_.value() << ": "
|
||||
<< base::File::ErrorToString(file_.error_details());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -165,8 +164,8 @@ bool Archive::Init() {
|
|||
}
|
||||
|
||||
uint32_t size;
|
||||
if (!base::PickleIterator(base::Pickle(buf.data(), buf.size())).ReadUInt32(
|
||||
&size)) {
|
||||
if (!base::PickleIterator(base::Pickle(buf.data(), buf.size()))
|
||||
.ReadUInt32(&size)) {
|
||||
LOG(ERROR) << "Failed to parse header size from " << path_.value();
|
||||
return false;
|
||||
}
|
||||
|
@ -182,8 +181,8 @@ bool Archive::Init() {
|
|||
}
|
||||
|
||||
std::string header;
|
||||
if (!base::PickleIterator(base::Pickle(buf.data(), buf.size())).ReadString(
|
||||
&header)) {
|
||||
if (!base::PickleIterator(base::Pickle(buf.data(), buf.size()))
|
||||
.ReadString(&header)) {
|
||||
LOG(ERROR) << "Failed to parse header from " << path_.value();
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -92,8 +92,9 @@ bool ReadFileToString(const base::FilePath& path, std::string* contents) {
|
|||
return false;
|
||||
|
||||
contents->resize(info.size);
|
||||
return static_cast<int>(info.size) == src.Read(
|
||||
info.offset, const_cast<char*>(contents->data()), contents->size());
|
||||
return static_cast<int>(info.size) ==
|
||||
src.Read(info.offset, const_cast<char*>(contents->data()),
|
||||
contents->size());
|
||||
}
|
||||
|
||||
} // namespace asar
|
||||
|
|
|
@ -11,8 +11,7 @@
|
|||
|
||||
namespace asar {
|
||||
|
||||
ScopedTemporaryFile::ScopedTemporaryFile() {
|
||||
}
|
||||
ScopedTemporaryFile::ScopedTemporaryFile() {}
|
||||
|
||||
ScopedTemporaryFile::~ScopedTemporaryFile() {
|
||||
if (!path_.empty()) {
|
||||
|
@ -51,7 +50,8 @@ bool ScopedTemporaryFile::Init(const base::FilePath::StringType& ext) {
|
|||
|
||||
bool ScopedTemporaryFile::InitFromFile(base::File* src,
|
||||
const base::FilePath::StringType& ext,
|
||||
uint64_t offset, uint64_t size) {
|
||||
uint64_t offset,
|
||||
uint64_t size) {
|
||||
if (!src->IsValid())
|
||||
return false;
|
||||
|
||||
|
@ -68,7 +68,7 @@ bool ScopedTemporaryFile::InitFromFile(base::File* src,
|
|||
return false;
|
||||
|
||||
return dest.WriteAtCurrentPos(buf.data(), buf.size()) ==
|
||||
static_cast<int>(size);
|
||||
static_cast<int>(size);
|
||||
}
|
||||
|
||||
} // namespace asar
|
||||
|
|
|
@ -16,10 +16,9 @@
|
|||
#endif
|
||||
|
||||
#ifndef ATOM_PRE_RELEASE_VERSION
|
||||
#define ATOM_VERSION_STRING \
|
||||
ATOM_STRINGIFY(ATOM_MAJOR_VERSION) \
|
||||
"." ATOM_STRINGIFY(ATOM_MINOR_VERSION) "." ATOM_STRINGIFY( \
|
||||
ATOM_PATCH_VERSION)
|
||||
#define ATOM_VERSION_STRING \
|
||||
ATOM_STRINGIFY(ATOM_MAJOR_VERSION) \
|
||||
"." ATOM_STRINGIFY(ATOM_MINOR_VERSION) "." ATOM_STRINGIFY(ATOM_PATCH_VERSION)
|
||||
#else
|
||||
#define ATOM_VERSION_STRING \
|
||||
ATOM_STRINGIFY(ATOM_MAJOR_VERSION) \
|
||||
|
|
|
@ -47,10 +47,8 @@ SkColor ParseHexColor(const std::string& color_string) {
|
|||
}
|
||||
|
||||
std::string ToRGBHex(SkColor color) {
|
||||
return base::StringPrintf("#%02X%02X%02X",
|
||||
SkColorGetR(color),
|
||||
SkColorGetG(color),
|
||||
SkColorGetB(color));
|
||||
return base::StringPrintf("#%02X%02X%02X", SkColorGetR(color),
|
||||
SkColorGetG(color), SkColorGetB(color));
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
|
|
|
@ -7,12 +7,12 @@
|
|||
#include "atom/common/common_message_generator.h"
|
||||
|
||||
// Generate constructors.
|
||||
#include "ipc/struct_constructor_macros.h"
|
||||
#include "atom/common/common_message_generator.h"
|
||||
#include "ipc/struct_constructor_macros.h"
|
||||
|
||||
// Generate destructors.
|
||||
#include "ipc/struct_destructor_macros.h"
|
||||
#include "atom/common/common_message_generator.h"
|
||||
#include "ipc/struct_destructor_macros.h"
|
||||
|
||||
// Generate param traits write methods.
|
||||
#include "ipc/param_traits_write_macros.h"
|
||||
|
|
|
@ -21,8 +21,7 @@ CrashReporter::CrashReporter() {
|
|||
is_browser_ = cmd->GetSwitchValueASCII(switches::kProcessType).empty();
|
||||
}
|
||||
|
||||
CrashReporter::~CrashReporter() {
|
||||
}
|
||||
CrashReporter::~CrashReporter() {}
|
||||
|
||||
void CrashReporter::Start(const std::string& product_name,
|
||||
const std::string& company_name,
|
||||
|
@ -45,8 +44,7 @@ void CrashReporter::SetUploadParameters(const StringMap& parameters) {
|
|||
SetUploadParameters();
|
||||
}
|
||||
|
||||
void CrashReporter::SetUploadToServer(const bool upload_to_server) {
|
||||
}
|
||||
void CrashReporter::SetUploadToServer(const bool upload_to_server) {}
|
||||
|
||||
bool CrashReporter::GetUploadToServer() {
|
||||
return true;
|
||||
|
@ -66,10 +64,10 @@ CrashReporter::GetUploadedReports(const base::FilePath& crashes_dir) {
|
|||
std::vector<std::string> report_item = base::SplitString(
|
||||
report, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
|
||||
int report_time = 0;
|
||||
if (report_item.size() >= 2 && base::StringToInt(report_item[0],
|
||||
&report_time)) {
|
||||
result.push_back(CrashReporter::UploadReportResult(report_time,
|
||||
report_item[1]));
|
||||
if (report_item.size() >= 2 &&
|
||||
base::StringToInt(report_item[0], &report_time)) {
|
||||
result.push_back(
|
||||
CrashReporter::UploadReportResult(report_time, report_item[1]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -82,18 +80,14 @@ void CrashReporter::InitBreakpad(const std::string& product_name,
|
|||
const std::string& submit_url,
|
||||
const base::FilePath& crashes_dir,
|
||||
bool auto_submit,
|
||||
bool skip_system_crash_handler) {
|
||||
}
|
||||
bool skip_system_crash_handler) {}
|
||||
|
||||
void CrashReporter::SetUploadParameters() {
|
||||
}
|
||||
void CrashReporter::SetUploadParameters() {}
|
||||
|
||||
void CrashReporter::AddExtraParameter(const std::string& key,
|
||||
const std::string& value) {
|
||||
}
|
||||
const std::string& value) {}
|
||||
|
||||
void CrashReporter::RemoveExtraParameter(const std::string& key) {
|
||||
}
|
||||
void CrashReporter::RemoveExtraParameter(const std::string& key) {}
|
||||
|
||||
std::map<std::string, std::string> CrashReporter::GetParameters() const {
|
||||
return upload_parameters_;
|
||||
|
@ -109,7 +103,8 @@ CrashReporter* CrashReporter::GetInstance() {
|
|||
|
||||
void CrashReporter::StartInstance(const mate::Dictionary& options) {
|
||||
auto reporter = GetInstance();
|
||||
if (!reporter) return;
|
||||
if (!reporter)
|
||||
return;
|
||||
|
||||
std::string product_name;
|
||||
options.Get("productName", &product_name);
|
||||
|
|
|
@ -38,9 +38,7 @@ static const off_t kMaxMinidumpFileSize = 1258291;
|
|||
} // namespace
|
||||
|
||||
CrashReporterLinux::CrashReporterLinux()
|
||||
: process_start_time_(0),
|
||||
pid_(getpid()),
|
||||
upload_to_server_(true) {
|
||||
: process_start_time_(0), pid_(getpid()), upload_to_server_(true) {
|
||||
// Set the base process start time value.
|
||||
struct timeval tv;
|
||||
if (!gettimeofday(&tv, NULL)) {
|
||||
|
@ -54,8 +52,7 @@ CrashReporterLinux::CrashReporterLinux()
|
|||
base::SetLinuxDistro(base::GetLinuxDistro());
|
||||
}
|
||||
|
||||
CrashReporterLinux::~CrashReporterLinux() {
|
||||
}
|
||||
CrashReporterLinux::~CrashReporterLinux() {}
|
||||
|
||||
void CrashReporterLinux::InitBreakpad(const std::string& product_name,
|
||||
const std::string& version,
|
||||
|
@ -101,13 +98,10 @@ void CrashReporterLinux::EnableCrashDumping(const base::FilePath& crashes_dir) {
|
|||
MinidumpDescriptor minidump_descriptor(crashes_dir.value());
|
||||
minidump_descriptor.set_size_limit(kMaxMinidumpFileSize);
|
||||
|
||||
breakpad_.reset(new ExceptionHandler(
|
||||
minidump_descriptor,
|
||||
NULL,
|
||||
CrashDone,
|
||||
this,
|
||||
true, // Install handlers.
|
||||
-1));
|
||||
breakpad_.reset(new ExceptionHandler(minidump_descriptor, NULL, CrashDone,
|
||||
this,
|
||||
true, // Install handlers.
|
||||
-1));
|
||||
}
|
||||
|
||||
bool CrashReporterLinux::CrashDone(const MinidumpDescriptor& minidump,
|
||||
|
|
|
@ -38,7 +38,7 @@ namespace {
|
|||
// Minidump with stacks, PEB, TEB, and unloaded module list.
|
||||
const MINIDUMP_TYPE kSmallDumpType = static_cast<MINIDUMP_TYPE>(
|
||||
MiniDumpWithProcessThreadData | // Get PEB and TEB.
|
||||
MiniDumpWithUnloadedModules); // Get unloaded modules when available.
|
||||
MiniDumpWithUnloadedModules); // Get unloaded modules when available.
|
||||
|
||||
const wchar_t kWaitEventFormat[] = L"$1CrashServiceWaitEvent";
|
||||
const wchar_t kPipeNameFormat[] = L"\\\\.\\pipe\\$1 Crash Service";
|
||||
|
@ -47,8 +47,8 @@ const wchar_t kPipeNameFormat[] = L"\\\\.\\pipe\\$1 Crash Service";
|
|||
const int kNameMaxLength = 64;
|
||||
const int kValueMaxLength = 64;
|
||||
|
||||
typedef NTSTATUS (WINAPI* NtTerminateProcessPtr)(HANDLE ProcessHandle,
|
||||
NTSTATUS ExitStatus);
|
||||
typedef NTSTATUS(WINAPI* NtTerminateProcessPtr)(HANDLE ProcessHandle,
|
||||
NTSTATUS ExitStatus);
|
||||
char* g_real_terminate_process_stub = NULL;
|
||||
|
||||
void TerminateProcessWithoutDump() {
|
||||
|
@ -71,11 +71,11 @@ int CrashForExceptionInNonABICompliantCodeRange(
|
|||
ULONG64 EstablisherFrame,
|
||||
PCONTEXT ContextRecord,
|
||||
PDISPATCHER_CONTEXT DispatcherContext) {
|
||||
EXCEPTION_POINTERS info = { ExceptionRecord, ContextRecord };
|
||||
EXCEPTION_POINTERS info = {ExceptionRecord, ContextRecord};
|
||||
if (!CrashReporter::GetInstance())
|
||||
return EXCEPTION_CONTINUE_SEARCH;
|
||||
return static_cast<CrashReporterWin*>(CrashReporter::GetInstance())->
|
||||
CrashForException(&info);
|
||||
return static_cast<CrashReporterWin*>(CrashReporter::GetInstance())
|
||||
->CrashForException(&info);
|
||||
}
|
||||
|
||||
struct ExceptionHandlerRecord {
|
||||
|
@ -138,12 +138,9 @@ void UnregisterNonABICompliantCodeRange(void* start) {
|
|||
} // namespace
|
||||
|
||||
CrashReporterWin::CrashReporterWin()
|
||||
: skip_system_crash_handler_(false),
|
||||
code_range_registered_(false) {
|
||||
}
|
||||
: skip_system_crash_handler_(false), code_range_registered_(false) {}
|
||||
|
||||
CrashReporterWin::~CrashReporterWin() {
|
||||
}
|
||||
CrashReporterWin::~CrashReporterWin() {}
|
||||
|
||||
void CrashReporterWin::InitBreakpad(const std::string& product_name,
|
||||
const std::string& version,
|
||||
|
@ -172,12 +169,8 @@ void CrashReporterWin::InitBreakpad(const std::string& product_name,
|
|||
breakpad_.reset();
|
||||
|
||||
breakpad_.reset(new google_breakpad::ExceptionHandler(
|
||||
crashes_dir.DirName().value(),
|
||||
FilterCallback,
|
||||
MinidumpCallback,
|
||||
this,
|
||||
google_breakpad::ExceptionHandler::HANDLER_ALL,
|
||||
kSmallDumpType,
|
||||
crashes_dir.DirName().value(), FilterCallback, MinidumpCallback, this,
|
||||
google_breakpad::ExceptionHandler::HANDLER_ALL, kSmallDumpType,
|
||||
pipe_name.c_str(),
|
||||
GetCustomInfo(product_name, version, company_name, upload_to_server)));
|
||||
|
||||
|
@ -246,13 +239,13 @@ google_breakpad::CustomClientInfo* CrashReporterWin::GetCustomInfo(
|
|||
custom_info_entries_.clear();
|
||||
custom_info_entries_.reserve(3 + upload_parameters_.size());
|
||||
|
||||
custom_info_entries_.push_back(google_breakpad::CustomInfoEntry(
|
||||
L"prod", L"Electron"));
|
||||
custom_info_entries_.push_back(
|
||||
google_breakpad::CustomInfoEntry(L"prod", L"Electron"));
|
||||
custom_info_entries_.push_back(google_breakpad::CustomInfoEntry(
|
||||
L"ver", base::UTF8ToWide(version).c_str()));
|
||||
if (!upload_to_server) {
|
||||
custom_info_entries_.push_back(google_breakpad::CustomInfoEntry(
|
||||
L"skip_upload", L"1"));
|
||||
custom_info_entries_.push_back(
|
||||
google_breakpad::CustomInfoEntry(L"skip_upload", L"1"));
|
||||
}
|
||||
|
||||
for (StringMap::const_iterator iter = upload_parameters_.begin();
|
||||
|
|
|
@ -23,7 +23,11 @@
|
|||
// where we either a) know the call cannot fail, or b) there is nothing we
|
||||
// can do when a call fails, we mark the return code as ignored. This avoids
|
||||
// spurious compiler warnings.
|
||||
#define IGNORE_RET(x) do { if (x); } while (0)
|
||||
#define IGNORE_RET(x) \
|
||||
do { \
|
||||
if (x) \
|
||||
; \
|
||||
} while (0)
|
||||
|
||||
namespace crash_reporter {
|
||||
|
||||
|
@ -68,7 +72,7 @@ void my_uint64tos(char* output, uint64_t i, unsigned i_len) {
|
|||
}
|
||||
|
||||
// Converts a struct timeval to milliseconds.
|
||||
uint64_t kernel_timeval_to_ms(struct kernel_timeval *tv) {
|
||||
uint64_t kernel_timeval_to_ms(struct kernel_timeval* tv) {
|
||||
uint64_t ret = tv->tv_sec; // Avoid overflow by explicitly using a uint64_t.
|
||||
ret *= 1000;
|
||||
ret += tv->tv_usec / 1000;
|
||||
|
@ -116,8 +120,7 @@ class MimeWriter {
|
|||
size_t msg_data_size);
|
||||
|
||||
// Append key/value pair.
|
||||
void AddPairString(const char* msg_type,
|
||||
const char* msg_data) {
|
||||
void AddPairString(const char* msg_type, const char* msg_data) {
|
||||
AddPairData(msg_type, my_strlen(msg_type), msg_data, my_strlen(msg_data));
|
||||
}
|
||||
|
||||
|
@ -145,9 +148,7 @@ class MimeWriter {
|
|||
protected:
|
||||
void AddItem(const void* base, size_t size);
|
||||
// Minor performance trade-off for easier-to-maintain code.
|
||||
void AddString(const char* str) {
|
||||
AddItem(str, my_strlen(str));
|
||||
}
|
||||
void AddString(const char* str) { AddItem(str, my_strlen(str)); }
|
||||
void AddItemWithoutTrailingSpaces(const void* base, size_t size);
|
||||
|
||||
struct kernel_iovec iov_[kIovCapacity];
|
||||
|
@ -163,13 +164,9 @@ class MimeWriter {
|
|||
};
|
||||
|
||||
MimeWriter::MimeWriter(int fd, const char* const mime_boundary)
|
||||
: iov_index_(0),
|
||||
fd_(fd),
|
||||
mime_boundary_(mime_boundary) {
|
||||
}
|
||||
: iov_index_(0), fd_(fd), mime_boundary_(mime_boundary) {}
|
||||
|
||||
MimeWriter::~MimeWriter() {
|
||||
}
|
||||
MimeWriter::~MimeWriter() {}
|
||||
|
||||
void MimeWriter::AddBoundary() {
|
||||
AddString(mime_boundary_);
|
||||
|
@ -234,7 +231,8 @@ void MimeWriter::AddPairDataInChunks(const char* msg_type,
|
|||
}
|
||||
}
|
||||
|
||||
void MimeWriter::AddFileContents(const char* filename_msg, uint8_t* file_data,
|
||||
void MimeWriter::AddFileContents(const char* filename_msg,
|
||||
uint8_t* file_data,
|
||||
size_t file_size) {
|
||||
AddString(g_form_data_msg);
|
||||
AddString(filename_msg);
|
||||
|
@ -257,12 +255,15 @@ void MimeWriter::AddItem(const void* base, size_t size) {
|
|||
}
|
||||
|
||||
void MimeWriter::AddItemWithoutTrailingSpaces(const void* base, size_t size) {
|
||||
AddItem(base, LengthWithoutTrailingSpaces(static_cast<const char*>(base),
|
||||
size));
|
||||
AddItem(base,
|
||||
LengthWithoutTrailingSpaces(static_cast<const char*>(base), size));
|
||||
}
|
||||
|
||||
void LoadDataFromFD(google_breakpad::PageAllocator* allocator,
|
||||
int fd, bool close_fd, uint8_t** file_data, size_t* size) {
|
||||
int fd,
|
||||
bool close_fd,
|
||||
uint8_t** file_data,
|
||||
size_t* size) {
|
||||
struct kernel_stat st;
|
||||
if (sys_fstat(fd, &st) != 0) {
|
||||
static const char msg[] = "Cannot upload crash dump: stat failed\n";
|
||||
|
@ -298,7 +299,9 @@ void LoadDataFromFD(google_breakpad::PageAllocator* allocator,
|
|||
|
||||
void LoadDataFromFile(google_breakpad::PageAllocator* allocator,
|
||||
const char* filename,
|
||||
int* fd, uint8_t** file_data, size_t* size) {
|
||||
int* fd,
|
||||
uint8_t** file_data,
|
||||
size_t* size) {
|
||||
// WARNING: this code runs in a compromised context. It may not call into
|
||||
// libc nor allocate memory normally.
|
||||
*fd = sys_open(filename, O_RDONLY, 0);
|
||||
|
@ -329,8 +332,8 @@ void ExecUploadProcessOrTerminate(const BreakpadInfo& info,
|
|||
// where the boundary has two fewer leading '-' chars
|
||||
static const char header_msg[] =
|
||||
"--header=Content-Type: multipart/form-data; boundary=";
|
||||
char* const header = reinterpret_cast<char*>(allocator->Alloc(
|
||||
sizeof(header_msg) - 1 + strlen(mime_boundary) - 2 + 1));
|
||||
char* const header = reinterpret_cast<char*>(
|
||||
allocator->Alloc(sizeof(header_msg) - 1 + strlen(mime_boundary) - 2 + 1));
|
||||
memcpy(header, header_msg, sizeof(header_msg) - 1);
|
||||
memcpy(header + sizeof(header_msg) - 1, mime_boundary + 2,
|
||||
strlen(mime_boundary) - 2);
|
||||
|
@ -339,26 +342,23 @@ void ExecUploadProcessOrTerminate(const BreakpadInfo& info,
|
|||
// The --post-file argument to wget looks like:
|
||||
// --post-file=/tmp/...
|
||||
static const char post_file_msg[] = "--post-file=";
|
||||
char* const post_file = reinterpret_cast<char*>(allocator->Alloc(
|
||||
sizeof(post_file_msg) - 1 + strlen(dumpfile) + 1));
|
||||
char* const post_file = reinterpret_cast<char*>(
|
||||
allocator->Alloc(sizeof(post_file_msg) - 1 + strlen(dumpfile) + 1));
|
||||
memcpy(post_file, post_file_msg, sizeof(post_file_msg) - 1);
|
||||
memcpy(post_file + sizeof(post_file_msg) - 1, dumpfile, strlen(dumpfile));
|
||||
|
||||
static const char kWgetBinary[] = "/usr/bin/wget";
|
||||
const char* args[] = {
|
||||
kWgetBinary,
|
||||
header,
|
||||
post_file,
|
||||
info.upload_url,
|
||||
"--timeout=60", // Set a timeout so we don't hang forever.
|
||||
"--tries=1", // Don't retry if the upload fails.
|
||||
"--quiet", // Be silent.
|
||||
"-O", // output reply to /dev/null.
|
||||
"/dev/fd/3",
|
||||
NULL,
|
||||
kWgetBinary, header, post_file, info.upload_url,
|
||||
"--timeout=60", // Set a timeout so we don't hang forever.
|
||||
"--tries=1", // Don't retry if the upload fails.
|
||||
"--quiet", // Be silent.
|
||||
"-O", // output reply to /dev/null.
|
||||
"/dev/fd/3", NULL,
|
||||
};
|
||||
static const char msg[] = "Cannot upload crash dump: cannot exec "
|
||||
"/usr/bin/wget\n";
|
||||
static const char msg[] =
|
||||
"Cannot upload crash dump: cannot exec "
|
||||
"/usr/bin/wget\n";
|
||||
execve(args[0], const_cast<char**>(args), environ);
|
||||
WriteLog(msg, sizeof(msg) - 1);
|
||||
sys__exit(1);
|
||||
|
@ -368,7 +368,8 @@ void ExecUploadProcessOrTerminate(const BreakpadInfo& info,
|
|||
// ExecUploadProcessOrTerminate() to finish. Returns the number of bytes written
|
||||
// to |fd| and save the written contents to |buf|.
|
||||
// |buf| needs to be big enough to hold |bytes_to_read| + 1 characters.
|
||||
size_t WaitForCrashReportUploadProcess(int fd, size_t bytes_to_read,
|
||||
size_t WaitForCrashReportUploadProcess(int fd,
|
||||
size_t bytes_to_read,
|
||||
char* buf) {
|
||||
size_t bytes_read = 0;
|
||||
|
||||
|
@ -400,7 +401,8 @@ size_t WaitForCrashReportUploadProcess(int fd, size_t bytes_to_read,
|
|||
}
|
||||
|
||||
// |buf| should be |expected_len| + 1 characters in size and NULL terminated.
|
||||
bool IsValidCrashReportId(const char* buf, size_t bytes_read,
|
||||
bool IsValidCrashReportId(const char* buf,
|
||||
size_t bytes_read,
|
||||
size_t expected_len) {
|
||||
if (bytes_read != expected_len)
|
||||
return false;
|
||||
|
@ -412,7 +414,8 @@ bool IsValidCrashReportId(const char* buf, size_t bytes_read,
|
|||
}
|
||||
|
||||
// |buf| should be |expected_len| + 1 characters in size and NULL terminated.
|
||||
void HandleCrashReportId(const char* buf, size_t bytes_read,
|
||||
void HandleCrashReportId(const char* buf,
|
||||
size_t bytes_read,
|
||||
size_t expected_len) {
|
||||
if (!IsValidCrashReportId(buf, bytes_read, expected_len)) {
|
||||
static const char msg[] = "Failed to get crash dump id.";
|
||||
|
@ -472,7 +475,8 @@ void HandleCrashDump(const BreakpadInfo& info) {
|
|||
// The FD is pointing to the end of the file.
|
||||
// Rewind, we'll read the data next.
|
||||
if (lseek(dumpfd, 0, SEEK_SET) == -1) {
|
||||
static const char msg[] = "Cannot upload crash dump: failed to "
|
||||
static const char msg[] =
|
||||
"Cannot upload crash dump: failed to "
|
||||
"reposition minidump FD\n";
|
||||
WriteLog(msg, sizeof(msg) - 1);
|
||||
IGNORE_RET(sys_close(dumpfd));
|
||||
|
@ -482,16 +486,17 @@ void HandleCrashDump(const BreakpadInfo& info) {
|
|||
} else {
|
||||
// Dump is provided with a path.
|
||||
keep_fd = false;
|
||||
LoadDataFromFile(
|
||||
&allocator, info.filename, &dumpfd, &dump_data, &dump_size);
|
||||
LoadDataFromFile(&allocator, info.filename, &dumpfd, &dump_data,
|
||||
&dump_size);
|
||||
}
|
||||
|
||||
// We need to build a MIME block for uploading to the server. Since we are
|
||||
// going to fork and run wget, it needs to be written to a temp file.
|
||||
const int ufd = sys_open("/dev/urandom", O_RDONLY, 0);
|
||||
if (ufd < 0) {
|
||||
static const char msg[] = "Cannot upload crash dump because /dev/urandom"
|
||||
" is missing\n";
|
||||
static const char msg[] =
|
||||
"Cannot upload crash dump because /dev/urandom"
|
||||
" is missing\n";
|
||||
WriteLog(msg, sizeof(msg) - 1);
|
||||
return;
|
||||
}
|
||||
|
@ -504,7 +509,8 @@ void HandleCrashDump(const BreakpadInfo& info) {
|
|||
temp_file_fd = dumpfd;
|
||||
// Rewind the destination, we are going to overwrite it.
|
||||
if (lseek(dumpfd, 0, SEEK_SET) == -1) {
|
||||
static const char msg[] = "Cannot upload crash dump: failed to "
|
||||
static const char msg[] =
|
||||
"Cannot upload crash dump: failed to "
|
||||
"reposition minidump FD (2)\n";
|
||||
WriteLog(msg, sizeof(msg) - 1);
|
||||
IGNORE_RET(sys_close(dumpfd));
|
||||
|
@ -525,7 +531,8 @@ void HandleCrashDump(const BreakpadInfo& info) {
|
|||
}
|
||||
|
||||
if (temp_file_fd < 0) {
|
||||
static const char msg[] = "Failed to create temporary file in /tmp: "
|
||||
static const char msg[] =
|
||||
"Failed to create temporary file in /tmp: "
|
||||
"cannot upload crash dump\n";
|
||||
WriteLog(msg, sizeof(msg) - 1);
|
||||
IGNORE_RET(sys_close(ufd));
|
||||
|
@ -598,8 +605,8 @@ void HandleCrashDump(const BreakpadInfo& info) {
|
|||
uint64_t pid_value_len = my_uint64_len(info.pid);
|
||||
my_uint64tos(pid_value_buf, info.pid, pid_value_len);
|
||||
static const char pid_key_name[] = "pid";
|
||||
writer.AddPairData(pid_key_name, sizeof(pid_key_name) - 1,
|
||||
pid_value_buf, pid_value_len);
|
||||
writer.AddPairData(pid_key_name, sizeof(pid_key_name) - 1, pid_value_buf,
|
||||
pid_value_len);
|
||||
writer.AddBoundary();
|
||||
}
|
||||
writer.Flush();
|
||||
|
@ -636,8 +643,8 @@ void HandleCrashDump(const BreakpadInfo& info) {
|
|||
const unsigned oom_size_len = my_uint64_len(info.oom_size);
|
||||
my_uint64tos(oom_size_str, info.oom_size, oom_size_len);
|
||||
static const char oom_size_msg[] = "oom-size";
|
||||
writer.AddPairData(oom_size_msg, sizeof(oom_size_msg) - 1,
|
||||
oom_size_str, oom_size_len);
|
||||
writer.AddPairData(oom_size_msg, sizeof(oom_size_msg) - 1, oom_size_str,
|
||||
oom_size_len);
|
||||
writer.AddBoundary();
|
||||
writer.Flush();
|
||||
}
|
||||
|
@ -732,7 +739,7 @@ void HandleCrashDump(const BreakpadInfo& info) {
|
|||
// Main browser process.
|
||||
if (child <= 0)
|
||||
return;
|
||||
(void) HANDLE_EINTR(sys_waitpid(child, NULL, 0));
|
||||
(void)HANDLE_EINTR(sys_waitpid(child, NULL, 0));
|
||||
}
|
||||
|
||||
size_t WriteLog(const char* buf, size_t nbytes) {
|
||||
|
|
|
@ -36,7 +36,8 @@ const wchar_t kCheckPointFile[] = L"crash_checkpoint.txt";
|
|||
typedef std::map<std::wstring, std::wstring> CrashMap;
|
||||
|
||||
bool CustomInfoToMap(const google_breakpad::ClientInfo* client_info,
|
||||
const std::wstring& reporter_tag, CrashMap* map) {
|
||||
const std::wstring& reporter_tag,
|
||||
CrashMap* map) {
|
||||
google_breakpad::CustomClientInfo info = client_info->GetCustomInfo();
|
||||
|
||||
for (uintptr_t i = 0; i < info.count; ++i) {
|
||||
|
@ -56,8 +57,9 @@ bool WriteCustomInfoToFile(const std::wstring& dump_path, const CrashMap& map) {
|
|||
file_path.resize(last_dot);
|
||||
file_path += L".txt";
|
||||
|
||||
std::wofstream file(file_path.c_str(),
|
||||
std::ios_base::out | std::ios_base::app | std::ios::binary);
|
||||
std::wofstream file(file_path.c_str(), std::ios_base::out |
|
||||
std::ios_base::app |
|
||||
std::ios::binary);
|
||||
if (!file.is_open())
|
||||
return false;
|
||||
|
||||
|
@ -81,8 +83,9 @@ bool WriteReportIDToFile(const std::wstring& dump_path,
|
|||
file_path.resize(last_slash);
|
||||
file_path += L"\\uploads.log";
|
||||
|
||||
std::wofstream file(file_path.c_str(),
|
||||
std::ios_base::out | std::ios_base::app | std::ios::binary);
|
||||
std::wofstream file(file_path.c_str(), std::ios_base::out |
|
||||
std::ios_base::app |
|
||||
std::ios::binary);
|
||||
if (!file.is_open())
|
||||
return false;
|
||||
|
||||
|
@ -98,8 +101,10 @@ bool WriteReportIDToFile(const std::wstring& dump_path,
|
|||
|
||||
// The window procedure task is to handle when a) the user logs off.
|
||||
// b) the system shuts down or c) when the user closes the window.
|
||||
LRESULT __stdcall CrashSvcWndProc(HWND hwnd, UINT message,
|
||||
WPARAM wparam, LPARAM lparam) {
|
||||
LRESULT __stdcall CrashSvcWndProc(HWND hwnd,
|
||||
UINT message,
|
||||
WPARAM wparam,
|
||||
LPARAM lparam) {
|
||||
switch (message) {
|
||||
case WM_CLOSE:
|
||||
case WM_ENDSESSION:
|
||||
|
@ -118,8 +123,8 @@ HWND g_top_window = NULL;
|
|||
bool CreateTopWindow(HINSTANCE instance,
|
||||
const base::string16& application_name,
|
||||
bool visible) {
|
||||
base::string16 class_name = base::ReplaceStringPlaceholders(
|
||||
kClassNameFormat, application_name, NULL);
|
||||
base::string16 class_name =
|
||||
base::ReplaceStringPlaceholders(kClassNameFormat, application_name, NULL);
|
||||
|
||||
WNDCLASSEXW wcx = {0};
|
||||
wcx.cbSize = sizeof(wcx);
|
||||
|
@ -133,8 +138,8 @@ bool CreateTopWindow(HINSTANCE instance,
|
|||
// The window size is zero but being a popup window still shows in the
|
||||
// task bar and can be closed using the system menu or using task manager.
|
||||
HWND window = CreateWindowExW(0, wcx.lpszClassName, L"crash service", style,
|
||||
CW_USEDEFAULT, CW_USEDEFAULT, 0, 0,
|
||||
NULL, NULL, instance, NULL);
|
||||
CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL,
|
||||
instance, NULL);
|
||||
if (!window)
|
||||
return false;
|
||||
|
||||
|
@ -148,15 +153,10 @@ bool CreateTopWindow(HINSTANCE instance,
|
|||
// finishes.
|
||||
class ProcessingLock {
|
||||
public:
|
||||
ProcessingLock() {
|
||||
::InterlockedIncrement(&op_count_);
|
||||
}
|
||||
~ProcessingLock() {
|
||||
::InterlockedDecrement(&op_count_);
|
||||
}
|
||||
static bool IsWorking() {
|
||||
return (op_count_ != 0);
|
||||
}
|
||||
ProcessingLock() { ::InterlockedIncrement(&op_count_); }
|
||||
~ProcessingLock() { ::InterlockedDecrement(&op_count_); }
|
||||
static bool IsWorking() { return (op_count_ != 0); }
|
||||
|
||||
private:
|
||||
static volatile LONG op_count_;
|
||||
};
|
||||
|
@ -171,21 +171,22 @@ struct DumpJobInfo {
|
|||
CrashMap map;
|
||||
std::wstring dump_path;
|
||||
|
||||
DumpJobInfo(DWORD process_id, CrashService* service,
|
||||
const CrashMap& crash_map, const std::wstring& path)
|
||||
: pid(process_id), self(service), map(crash_map), dump_path(path) {
|
||||
}
|
||||
DumpJobInfo(DWORD process_id,
|
||||
CrashService* service,
|
||||
const CrashMap& crash_map,
|
||||
const std::wstring& path)
|
||||
: pid(process_id), self(service), map(crash_map), dump_path(path) {}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
// Command line switches:
|
||||
const char CrashService::kMaxReports[] = "max-reports";
|
||||
const char CrashService::kNoWindow[] = "no-window";
|
||||
const char CrashService::kReporterTag[] = "reporter";
|
||||
const char CrashService::kDumpsDir[] = "dumps-dir";
|
||||
const char CrashService::kPipeName[] = "pipe-name";
|
||||
const char CrashService::kReporterURL[] = "reporter-url";
|
||||
const char CrashService::kMaxReports[] = "max-reports";
|
||||
const char CrashService::kNoWindow[] = "no-window";
|
||||
const char CrashService::kReporterTag[] = "reporter";
|
||||
const char CrashService::kDumpsDir[] = "dumps-dir";
|
||||
const char CrashService::kPipeName[] = "pipe-name";
|
||||
const char CrashService::kReporterURL[] = "reporter-url";
|
||||
|
||||
CrashService::CrashService()
|
||||
: sender_(NULL),
|
||||
|
@ -193,8 +194,7 @@ CrashService::CrashService()
|
|||
requests_handled_(0),
|
||||
requests_sent_(0),
|
||||
clients_connected_(0),
|
||||
clients_terminated_(0) {
|
||||
}
|
||||
clients_terminated_(0) {}
|
||||
|
||||
CrashService::~CrashService() {
|
||||
base::AutoLock lock(sending_);
|
||||
|
@ -205,8 +205,8 @@ CrashService::~CrashService() {
|
|||
bool CrashService::Initialize(const base::string16& application_name,
|
||||
const base::FilePath& operating_dir,
|
||||
const base::FilePath& dumps_path) {
|
||||
using google_breakpad::CrashReportSender;
|
||||
using google_breakpad::CrashGenerationServer;
|
||||
using google_breakpad::CrashReportSender;
|
||||
|
||||
std::wstring pipe_name = kTestPipeName;
|
||||
int max_reports = -1;
|
||||
|
@ -249,12 +249,10 @@ bool CrashService::Initialize(const base::string16& application_name,
|
|||
security_attributes.bInheritHandle = FALSE;
|
||||
|
||||
// Create the OOP crash generator object.
|
||||
dumper_ = new CrashGenerationServer(pipe_name, &security_attributes,
|
||||
&CrashService::OnClientConnected, this,
|
||||
&CrashService::OnClientDumpRequest, this,
|
||||
&CrashService::OnClientExited, this,
|
||||
NULL, NULL,
|
||||
true, &dumps_path_to_use.value());
|
||||
dumper_ = new CrashGenerationServer(
|
||||
pipe_name, &security_attributes, &CrashService::OnClientConnected, this,
|
||||
&CrashService::OnClientDumpRequest, this, &CrashService::OnClientExited,
|
||||
this, NULL, NULL, true, &dumps_path_to_use.value());
|
||||
|
||||
if (!dumper_) {
|
||||
LOG(ERROR) << "could not create dumper";
|
||||
|
@ -263,8 +261,7 @@ bool CrashService::Initialize(const base::string16& application_name,
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!CreateTopWindow(::GetModuleHandleW(NULL),
|
||||
application_name,
|
||||
if (!CreateTopWindow(::GetModuleHandleW(NULL), application_name,
|
||||
!cmd_line.HasSwitch(kNoWindow))) {
|
||||
LOG(ERROR) << "could not create window";
|
||||
if (security_attributes.lpSecurityDescriptor)
|
||||
|
@ -281,13 +278,13 @@ bool CrashService::Initialize(const base::string16& application_name,
|
|||
reporter_url_ = cmd_line.GetSwitchValueNative(kReporterURL);
|
||||
|
||||
// Log basic information.
|
||||
VLOG(1) << "pipe name is " << pipe_name
|
||||
<< "\ndumps at " << dumps_path_to_use.value();
|
||||
VLOG(1) << "pipe name is " << pipe_name << "\ndumps at "
|
||||
<< dumps_path_to_use.value();
|
||||
|
||||
if (sender_) {
|
||||
VLOG(1) << "checkpoint is " << checkpoint_path.value()
|
||||
<< "\nserver is " << reporter_url_
|
||||
<< "\nmaximum " << sender_->max_reports_per_day() << " reports/day"
|
||||
VLOG(1) << "checkpoint is " << checkpoint_path.value() << "\nserver is "
|
||||
<< reporter_url_ << "\nmaximum " << sender_->max_reports_per_day()
|
||||
<< " reports/day"
|
||||
<< "\nreporter is " << reporter_tag_;
|
||||
}
|
||||
// Start servicing clients.
|
||||
|
@ -303,15 +300,16 @@ bool CrashService::Initialize(const base::string16& application_name,
|
|||
|
||||
// Create or open an event to signal the browser process that the crash
|
||||
// service is initialized.
|
||||
base::string16 wait_name = base::ReplaceStringPlaceholders(
|
||||
kWaitEventFormat, application_name, NULL);
|
||||
base::string16 wait_name =
|
||||
base::ReplaceStringPlaceholders(kWaitEventFormat, application_name, NULL);
|
||||
HANDLE wait_event = ::CreateEventW(NULL, TRUE, TRUE, wait_name.c_str());
|
||||
::SetEvent(wait_event);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CrashService::OnClientConnected(void* context,
|
||||
void CrashService::OnClientConnected(
|
||||
void* context,
|
||||
const google_breakpad::ClientInfo* client_info) {
|
||||
ProcessingLock lock;
|
||||
VLOG(1) << "client start. pid = " << client_info->pid();
|
||||
|
@ -319,7 +317,8 @@ void CrashService::OnClientConnected(void* context,
|
|||
::InterlockedIncrement(&self->clients_connected_);
|
||||
}
|
||||
|
||||
void CrashService::OnClientExited(void* context,
|
||||
void CrashService::OnClientExited(
|
||||
void* context,
|
||||
const google_breakpad::ClientInfo* client_info) {
|
||||
ProcessingLock processing_lock;
|
||||
VLOG(1) << "client end. pid = " << client_info->pid();
|
||||
|
@ -349,7 +348,8 @@ void CrashService::OnClientExited(void* context,
|
|||
}
|
||||
}
|
||||
|
||||
void CrashService::OnClientDumpRequest(void* context,
|
||||
void CrashService::OnClientDumpRequest(
|
||||
void* context,
|
||||
const google_breakpad::ClientInfo* client_info,
|
||||
const std::wstring* file_path) {
|
||||
ProcessingLock lock;
|
||||
|
@ -378,8 +378,8 @@ void CrashService::OnClientDumpRequest(void* context,
|
|||
if (it != map.end()) {
|
||||
base::FilePath alternate_dump_location = base::FilePath(it->second);
|
||||
base::CreateDirectoryW(alternate_dump_location);
|
||||
alternate_dump_location = alternate_dump_location.Append(
|
||||
dump_location.BaseName());
|
||||
alternate_dump_location =
|
||||
alternate_dump_location.Append(dump_location.BaseName());
|
||||
base::Move(dump_location, alternate_dump_location);
|
||||
dump_location = alternate_dump_location;
|
||||
}
|
||||
|
@ -396,10 +396,10 @@ void CrashService::OnClientDumpRequest(void* context,
|
|||
|
||||
// Send the crash dump using a worker thread. This operation has retry
|
||||
// logic in case there is no internet connection at the time.
|
||||
DumpJobInfo* dump_job = new DumpJobInfo(pid, self, map,
|
||||
dump_location.value());
|
||||
if (!::QueueUserWorkItem(&CrashService::AsyncSendDump,
|
||||
dump_job, WT_EXECUTELONGFUNCTION)) {
|
||||
DumpJobInfo* dump_job =
|
||||
new DumpJobInfo(pid, self, map, dump_location.value());
|
||||
if (!::QueueUserWorkItem(&CrashService::AsyncSendDump, dump_job,
|
||||
WT_EXECUTELONGFUNCTION)) {
|
||||
LOG(ERROR) << "could not queue job";
|
||||
}
|
||||
}
|
||||
|
@ -414,16 +414,11 @@ DWORD CrashService::AsyncSendDump(void* context) {
|
|||
|
||||
std::wstring report_id = L"<unsent>";
|
||||
|
||||
const DWORD kOneMinute = 60*1000;
|
||||
const DWORD kOneHour = 60*kOneMinute;
|
||||
const DWORD kOneMinute = 60 * 1000;
|
||||
const DWORD kOneHour = 60 * kOneMinute;
|
||||
|
||||
const DWORD kSleepSchedule[] = {
|
||||
24*kOneHour,
|
||||
8*kOneHour,
|
||||
4*kOneHour,
|
||||
kOneHour,
|
||||
15*kOneMinute,
|
||||
0};
|
||||
const DWORD kSleepSchedule[] = {24 * kOneHour, 8 * kOneHour, 4 * kOneHour,
|
||||
kOneHour, 15 * kOneMinute, 0};
|
||||
|
||||
int retry_round = arraysize(kSleepSchedule) - 1;
|
||||
|
||||
|
@ -436,11 +431,9 @@ DWORD CrashService::AsyncSendDump(void* context) {
|
|||
VLOG(1) << "trying to send report for pid = " << info->pid;
|
||||
std::map<std::wstring, std::wstring> file_map;
|
||||
file_map[L"upload_file_minidump"] = info->dump_path;
|
||||
google_breakpad::ReportResult send_result
|
||||
= info->self->sender_->SendCrashReport(info->self->reporter_url_,
|
||||
info->map,
|
||||
file_map,
|
||||
&report_id);
|
||||
google_breakpad::ReportResult send_result =
|
||||
info->self->sender_->SendCrashReport(info->self->reporter_url_,
|
||||
info->map, file_map, &report_id);
|
||||
switch (send_result) {
|
||||
case google_breakpad::RESULT_FAILED:
|
||||
report_id = L"<network issue>";
|
||||
|
@ -507,9 +500,8 @@ PSECURITY_DESCRIPTOR CrashService::GetSecurityDescriptorForLowIntegrity() {
|
|||
BOOL sacl_present = FALSE;
|
||||
BOOL sacl_defaulted = FALSE;
|
||||
|
||||
if (::ConvertStringSecurityDescriptorToSecurityDescriptorW(sddl.c_str(),
|
||||
SDDL_REVISION,
|
||||
&sec_desc, NULL)) {
|
||||
if (::ConvertStringSecurityDescriptorToSecurityDescriptorW(
|
||||
sddl.c_str(), SDDL_REVISION, &sec_desc, NULL)) {
|
||||
if (::GetSecurityDescriptorSacl(sec_desc, &sacl_present, &sacl,
|
||||
&sacl_defaulted)) {
|
||||
return sec_desc;
|
||||
|
|
|
@ -21,8 +21,11 @@ const char kCrashesDirectory[] = "crashes-directory";
|
|||
const wchar_t kPipeNameFormat[] = L"\\\\.\\pipe\\$1 Crash Service";
|
||||
const wchar_t kStandardLogFile[] = L"operation_log.txt";
|
||||
|
||||
void InvalidParameterHandler(const wchar_t*, const wchar_t*, const wchar_t*,
|
||||
unsigned int, uintptr_t) {
|
||||
void InvalidParameterHandler(const wchar_t*,
|
||||
const wchar_t*,
|
||||
const wchar_t*,
|
||||
unsigned int,
|
||||
uintptr_t) {
|
||||
// noop.
|
||||
}
|
||||
|
||||
|
@ -51,8 +54,8 @@ int Main(const wchar_t* cmd) {
|
|||
<< kApplicationName;
|
||||
return 1;
|
||||
}
|
||||
std::wstring application_name = cmd_line.GetSwitchValueNative(
|
||||
kApplicationName);
|
||||
std::wstring application_name =
|
||||
cmd_line.GetSwitchValueNative(kApplicationName);
|
||||
|
||||
if (!cmd_line.HasSwitch(kCrashesDirectory)) {
|
||||
LOG(ERROR) << "Crashes directory path must be specified with --"
|
||||
|
@ -78,17 +81,15 @@ int Main(const wchar_t* cmd) {
|
|||
VLOG(1) << "Session start. cmdline is [" << cmd << "]";
|
||||
|
||||
// Setting the crash reporter.
|
||||
base::string16 pipe_name = base::ReplaceStringPlaceholders(kPipeNameFormat,
|
||||
application_name,
|
||||
NULL);
|
||||
base::string16 pipe_name =
|
||||
base::ReplaceStringPlaceholders(kPipeNameFormat, application_name, NULL);
|
||||
cmd_line.AppendSwitch("no-window");
|
||||
cmd_line.AppendSwitchASCII("max-reports", "128");
|
||||
cmd_line.AppendSwitchASCII("reporter", ATOM_PROJECT_NAME "-crash-service");
|
||||
cmd_line.AppendSwitchNative("pipe-name", pipe_name);
|
||||
|
||||
breakpad::CrashService crash_service;
|
||||
if (!crash_service.Initialize(application_name, operating_dir,
|
||||
operating_dir))
|
||||
if (!crash_service.Initialize(application_name, operating_dir, operating_dir))
|
||||
return 2;
|
||||
|
||||
VLOG(1) << "Ready to process crash requests";
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
|
||||
namespace atom {
|
||||
|
||||
DraggableRegion::DraggableRegion()
|
||||
: draggable(false) {
|
||||
}
|
||||
DraggableRegion::DraggableRegion() : draggable(false) {}
|
||||
|
||||
} // namespace atom
|
||||
|
|
|
@ -20,64 +20,160 @@ ui::KeyboardCode KeyboardCodeFromCharCode(base::char16 c, bool* shifted) {
|
|||
c = base::ToLowerASCII(c);
|
||||
*shifted = false;
|
||||
switch (c) {
|
||||
case 0x08: return ui::VKEY_BACK;
|
||||
case 0x7F: return ui::VKEY_DELETE;
|
||||
case 0x09: return ui::VKEY_TAB;
|
||||
case 0x0D: return ui::VKEY_RETURN;
|
||||
case 0x1B: return ui::VKEY_ESCAPE;
|
||||
case ' ': return ui::VKEY_SPACE;
|
||||
case 0x08:
|
||||
return ui::VKEY_BACK;
|
||||
case 0x7F:
|
||||
return ui::VKEY_DELETE;
|
||||
case 0x09:
|
||||
return ui::VKEY_TAB;
|
||||
case 0x0D:
|
||||
return ui::VKEY_RETURN;
|
||||
case 0x1B:
|
||||
return ui::VKEY_ESCAPE;
|
||||
case ' ':
|
||||
return ui::VKEY_SPACE;
|
||||
|
||||
case 'a': return ui::VKEY_A;
|
||||
case 'b': return ui::VKEY_B;
|
||||
case 'c': return ui::VKEY_C;
|
||||
case 'd': return ui::VKEY_D;
|
||||
case 'e': return ui::VKEY_E;
|
||||
case 'f': return ui::VKEY_F;
|
||||
case 'g': return ui::VKEY_G;
|
||||
case 'h': return ui::VKEY_H;
|
||||
case 'i': return ui::VKEY_I;
|
||||
case 'j': return ui::VKEY_J;
|
||||
case 'k': return ui::VKEY_K;
|
||||
case 'l': return ui::VKEY_L;
|
||||
case 'm': return ui::VKEY_M;
|
||||
case 'n': return ui::VKEY_N;
|
||||
case 'o': return ui::VKEY_O;
|
||||
case 'p': return ui::VKEY_P;
|
||||
case 'q': return ui::VKEY_Q;
|
||||
case 'r': return ui::VKEY_R;
|
||||
case 's': return ui::VKEY_S;
|
||||
case 't': return ui::VKEY_T;
|
||||
case 'u': return ui::VKEY_U;
|
||||
case 'v': return ui::VKEY_V;
|
||||
case 'w': return ui::VKEY_W;
|
||||
case 'x': return ui::VKEY_X;
|
||||
case 'y': return ui::VKEY_Y;
|
||||
case 'z': return ui::VKEY_Z;
|
||||
case 'a':
|
||||
return ui::VKEY_A;
|
||||
case 'b':
|
||||
return ui::VKEY_B;
|
||||
case 'c':
|
||||
return ui::VKEY_C;
|
||||
case 'd':
|
||||
return ui::VKEY_D;
|
||||
case 'e':
|
||||
return ui::VKEY_E;
|
||||
case 'f':
|
||||
return ui::VKEY_F;
|
||||
case 'g':
|
||||
return ui::VKEY_G;
|
||||
case 'h':
|
||||
return ui::VKEY_H;
|
||||
case 'i':
|
||||
return ui::VKEY_I;
|
||||
case 'j':
|
||||
return ui::VKEY_J;
|
||||
case 'k':
|
||||
return ui::VKEY_K;
|
||||
case 'l':
|
||||
return ui::VKEY_L;
|
||||
case 'm':
|
||||
return ui::VKEY_M;
|
||||
case 'n':
|
||||
return ui::VKEY_N;
|
||||
case 'o':
|
||||
return ui::VKEY_O;
|
||||
case 'p':
|
||||
return ui::VKEY_P;
|
||||
case 'q':
|
||||
return ui::VKEY_Q;
|
||||
case 'r':
|
||||
return ui::VKEY_R;
|
||||
case 's':
|
||||
return ui::VKEY_S;
|
||||
case 't':
|
||||
return ui::VKEY_T;
|
||||
case 'u':
|
||||
return ui::VKEY_U;
|
||||
case 'v':
|
||||
return ui::VKEY_V;
|
||||
case 'w':
|
||||
return ui::VKEY_W;
|
||||
case 'x':
|
||||
return ui::VKEY_X;
|
||||
case 'y':
|
||||
return ui::VKEY_Y;
|
||||
case 'z':
|
||||
return ui::VKEY_Z;
|
||||
|
||||
case ')': *shifted = true; case '0': return ui::VKEY_0;
|
||||
case '!': *shifted = true; case '1': return ui::VKEY_1;
|
||||
case '@': *shifted = true; case '2': return ui::VKEY_2;
|
||||
case '#': *shifted = true; case '3': return ui::VKEY_3;
|
||||
case '$': *shifted = true; case '4': return ui::VKEY_4;
|
||||
case '%': *shifted = true; case '5': return ui::VKEY_5;
|
||||
case '^': *shifted = true; case '6': return ui::VKEY_6;
|
||||
case '&': *shifted = true; case '7': return ui::VKEY_7;
|
||||
case '*': *shifted = true; case '8': return ui::VKEY_8;
|
||||
case '(': *shifted = true; case '9': return ui::VKEY_9;
|
||||
case ')':
|
||||
*shifted = true;
|
||||
case '0':
|
||||
return ui::VKEY_0;
|
||||
case '!':
|
||||
*shifted = true;
|
||||
case '1':
|
||||
return ui::VKEY_1;
|
||||
case '@':
|
||||
*shifted = true;
|
||||
case '2':
|
||||
return ui::VKEY_2;
|
||||
case '#':
|
||||
*shifted = true;
|
||||
case '3':
|
||||
return ui::VKEY_3;
|
||||
case '$':
|
||||
*shifted = true;
|
||||
case '4':
|
||||
return ui::VKEY_4;
|
||||
case '%':
|
||||
*shifted = true;
|
||||
case '5':
|
||||
return ui::VKEY_5;
|
||||
case '^':
|
||||
*shifted = true;
|
||||
case '6':
|
||||
return ui::VKEY_6;
|
||||
case '&':
|
||||
*shifted = true;
|
||||
case '7':
|
||||
return ui::VKEY_7;
|
||||
case '*':
|
||||
*shifted = true;
|
||||
case '8':
|
||||
return ui::VKEY_8;
|
||||
case '(':
|
||||
*shifted = true;
|
||||
case '9':
|
||||
return ui::VKEY_9;
|
||||
|
||||
case ':': *shifted = true; case ';': return ui::VKEY_OEM_1;
|
||||
case '+': *shifted = true; case '=': return ui::VKEY_OEM_PLUS;
|
||||
case '<': *shifted = true; case ',': return ui::VKEY_OEM_COMMA;
|
||||
case '_': *shifted = true; case '-': return ui::VKEY_OEM_MINUS;
|
||||
case '>': *shifted = true; case '.': return ui::VKEY_OEM_PERIOD;
|
||||
case '?': *shifted = true; case '/': return ui::VKEY_OEM_2;
|
||||
case '~': *shifted = true; case '`': return ui::VKEY_OEM_3;
|
||||
case '{': *shifted = true; case '[': return ui::VKEY_OEM_4;
|
||||
case '|': *shifted = true; case '\\': return ui::VKEY_OEM_5;
|
||||
case '}': *shifted = true; case ']': return ui::VKEY_OEM_6;
|
||||
case '"': *shifted = true; case '\'': return ui::VKEY_OEM_7;
|
||||
case ':':
|
||||
*shifted = true;
|
||||
case ';':
|
||||
return ui::VKEY_OEM_1;
|
||||
case '+':
|
||||
*shifted = true;
|
||||
case '=':
|
||||
return ui::VKEY_OEM_PLUS;
|
||||
case '<':
|
||||
*shifted = true;
|
||||
case ',':
|
||||
return ui::VKEY_OEM_COMMA;
|
||||
case '_':
|
||||
*shifted = true;
|
||||
case '-':
|
||||
return ui::VKEY_OEM_MINUS;
|
||||
case '>':
|
||||
*shifted = true;
|
||||
case '.':
|
||||
return ui::VKEY_OEM_PERIOD;
|
||||
case '?':
|
||||
*shifted = true;
|
||||
case '/':
|
||||
return ui::VKEY_OEM_2;
|
||||
case '~':
|
||||
*shifted = true;
|
||||
case '`':
|
||||
return ui::VKEY_OEM_3;
|
||||
case '{':
|
||||
*shifted = true;
|
||||
case '[':
|
||||
return ui::VKEY_OEM_4;
|
||||
case '|':
|
||||
*shifted = true;
|
||||
case '\\':
|
||||
return ui::VKEY_OEM_5;
|
||||
case '}':
|
||||
*shifted = true;
|
||||
case ']':
|
||||
return ui::VKEY_OEM_6;
|
||||
case '"':
|
||||
*shifted = true;
|
||||
case '\'':
|
||||
return ui::VKEY_OEM_7;
|
||||
|
||||
default: return ui::VKEY_UNKNOWN;
|
||||
default:
|
||||
return ui::VKEY_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
namespace {
|
||||
|
||||
GDesktopAppInfo* get_desktop_app_info() {
|
||||
GDesktopAppInfo * ret = nullptr;
|
||||
GDesktopAppInfo* ret = nullptr;
|
||||
|
||||
std::string desktop_id;
|
||||
if (brightray::platform_util::GetDesktopName(&desktop_id))
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include <string>
|
||||
#include "atom/common/mouse_util.h"
|
||||
#include <string>
|
||||
|
||||
using Cursor = blink::WebCursorInfo::Type;
|
||||
|
||||
|
@ -11,51 +11,96 @@ namespace atom {
|
|||
|
||||
std::string CursorTypeToString(const content::CursorInfo& info) {
|
||||
switch (info.type) {
|
||||
case Cursor::kTypePointer: return "default";
|
||||
case Cursor::kTypeCross: return "crosshair";
|
||||
case Cursor::kTypeHand: return "pointer";
|
||||
case Cursor::kTypeIBeam: return "text";
|
||||
case Cursor::kTypeWait: return "wait";
|
||||
case Cursor::kTypeHelp: return "help";
|
||||
case Cursor::kTypeEastResize: return "e-resize";
|
||||
case Cursor::kTypeNorthResize: return "n-resize";
|
||||
case Cursor::kTypeNorthEastResize: return "ne-resize";
|
||||
case Cursor::kTypeNorthWestResize: return "nw-resize";
|
||||
case Cursor::kTypeSouthResize: return "s-resize";
|
||||
case Cursor::kTypeSouthEastResize: return "se-resize";
|
||||
case Cursor::kTypeSouthWestResize: return "sw-resize";
|
||||
case Cursor::kTypeWestResize: return "w-resize";
|
||||
case Cursor::kTypeNorthSouthResize: return "ns-resize";
|
||||
case Cursor::kTypeEastWestResize: return "ew-resize";
|
||||
case Cursor::kTypeNorthEastSouthWestResize: return "nesw-resize";
|
||||
case Cursor::kTypeNorthWestSouthEastResize: return "nwse-resize";
|
||||
case Cursor::kTypeColumnResize: return "col-resize";
|
||||
case Cursor::kTypeRowResize: return "row-resize";
|
||||
case Cursor::kTypeMiddlePanning: return "m-panning";
|
||||
case Cursor::kTypeEastPanning: return "e-panning";
|
||||
case Cursor::kTypeNorthPanning: return "n-panning";
|
||||
case Cursor::kTypeNorthEastPanning: return "ne-panning";
|
||||
case Cursor::kTypeNorthWestPanning: return "nw-panning";
|
||||
case Cursor::kTypeSouthPanning: return "s-panning";
|
||||
case Cursor::kTypeSouthEastPanning: return "se-panning";
|
||||
case Cursor::kTypeSouthWestPanning: return "sw-panning";
|
||||
case Cursor::kTypeWestPanning: return "w-panning";
|
||||
case Cursor::kTypeMove: return "move";
|
||||
case Cursor::kTypeVerticalText: return "vertical-text";
|
||||
case Cursor::kTypeCell: return "cell";
|
||||
case Cursor::kTypeContextMenu: return "context-menu";
|
||||
case Cursor::kTypeAlias: return "alias";
|
||||
case Cursor::kTypeProgress: return "progress";
|
||||
case Cursor::kTypeNoDrop: return "nodrop";
|
||||
case Cursor::kTypeCopy: return "copy";
|
||||
case Cursor::kTypeNone: return "none";
|
||||
case Cursor::kTypeNotAllowed: return "not-allowed";
|
||||
case Cursor::kTypeZoomIn: return "zoom-in";
|
||||
case Cursor::kTypeZoomOut: return "zoom-out";
|
||||
case Cursor::kTypeGrab: return "grab";
|
||||
case Cursor::kTypeGrabbing: return "grabbing";
|
||||
case Cursor::kTypeCustom: return "custom";
|
||||
default: return "default";
|
||||
case Cursor::kTypePointer:
|
||||
return "default";
|
||||
case Cursor::kTypeCross:
|
||||
return "crosshair";
|
||||
case Cursor::kTypeHand:
|
||||
return "pointer";
|
||||
case Cursor::kTypeIBeam:
|
||||
return "text";
|
||||
case Cursor::kTypeWait:
|
||||
return "wait";
|
||||
case Cursor::kTypeHelp:
|
||||
return "help";
|
||||
case Cursor::kTypeEastResize:
|
||||
return "e-resize";
|
||||
case Cursor::kTypeNorthResize:
|
||||
return "n-resize";
|
||||
case Cursor::kTypeNorthEastResize:
|
||||
return "ne-resize";
|
||||
case Cursor::kTypeNorthWestResize:
|
||||
return "nw-resize";
|
||||
case Cursor::kTypeSouthResize:
|
||||
return "s-resize";
|
||||
case Cursor::kTypeSouthEastResize:
|
||||
return "se-resize";
|
||||
case Cursor::kTypeSouthWestResize:
|
||||
return "sw-resize";
|
||||
case Cursor::kTypeWestResize:
|
||||
return "w-resize";
|
||||
case Cursor::kTypeNorthSouthResize:
|
||||
return "ns-resize";
|
||||
case Cursor::kTypeEastWestResize:
|
||||
return "ew-resize";
|
||||
case Cursor::kTypeNorthEastSouthWestResize:
|
||||
return "nesw-resize";
|
||||
case Cursor::kTypeNorthWestSouthEastResize:
|
||||
return "nwse-resize";
|
||||
case Cursor::kTypeColumnResize:
|
||||
return "col-resize";
|
||||
case Cursor::kTypeRowResize:
|
||||
return "row-resize";
|
||||
case Cursor::kTypeMiddlePanning:
|
||||
return "m-panning";
|
||||
case Cursor::kTypeEastPanning:
|
||||
return "e-panning";
|
||||
case Cursor::kTypeNorthPanning:
|
||||
return "n-panning";
|
||||
case Cursor::kTypeNorthEastPanning:
|
||||
return "ne-panning";
|
||||
case Cursor::kTypeNorthWestPanning:
|
||||
return "nw-panning";
|
||||
case Cursor::kTypeSouthPanning:
|
||||
return "s-panning";
|
||||
case Cursor::kTypeSouthEastPanning:
|
||||
return "se-panning";
|
||||
case Cursor::kTypeSouthWestPanning:
|
||||
return "sw-panning";
|
||||
case Cursor::kTypeWestPanning:
|
||||
return "w-panning";
|
||||
case Cursor::kTypeMove:
|
||||
return "move";
|
||||
case Cursor::kTypeVerticalText:
|
||||
return "vertical-text";
|
||||
case Cursor::kTypeCell:
|
||||
return "cell";
|
||||
case Cursor::kTypeContextMenu:
|
||||
return "context-menu";
|
||||
case Cursor::kTypeAlias:
|
||||
return "alias";
|
||||
case Cursor::kTypeProgress:
|
||||
return "progress";
|
||||
case Cursor::kTypeNoDrop:
|
||||
return "nodrop";
|
||||
case Cursor::kTypeCopy:
|
||||
return "copy";
|
||||
case Cursor::kTypeNone:
|
||||
return "none";
|
||||
case Cursor::kTypeNotAllowed:
|
||||
return "not-allowed";
|
||||
case Cursor::kTypeZoomIn:
|
||||
return "zoom-in";
|
||||
case Cursor::kTypeZoomOut:
|
||||
return "zoom-out";
|
||||
case Cursor::kTypeGrab:
|
||||
return "grab";
|
||||
case Cursor::kTypeGrabbing:
|
||||
return "grabbing";
|
||||
case Cursor::kTypeCustom:
|
||||
return "custom";
|
||||
default:
|
||||
return "default";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,8 +11,9 @@
|
|||
namespace mate {
|
||||
|
||||
// static
|
||||
bool Converter<ui::Accelerator>::FromV8(
|
||||
v8::Isolate* isolate, v8::Local<v8::Value> val, ui::Accelerator* out) {
|
||||
bool Converter<ui::Accelerator>::FromV8(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
ui::Accelerator* out) {
|
||||
std::string keycode;
|
||||
if (!ConvertFromV8(isolate, val, &keycode))
|
||||
return false;
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
namespace {
|
||||
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
int VectorToBitArray(const std::vector<T>& vec) {
|
||||
int bits = 0;
|
||||
for (const T& item : vec)
|
||||
|
@ -36,9 +36,10 @@ int VectorToBitArray(const std::vector<T>& vec) {
|
|||
|
||||
namespace mate {
|
||||
|
||||
template<>
|
||||
template <>
|
||||
struct Converter<base::char16> {
|
||||
static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val,
|
||||
static bool FromV8(v8::Isolate* isolate,
|
||||
v8::Handle<v8::Value> val,
|
||||
base::char16* out) {
|
||||
base::string16 code = base::UTF8ToUTF16(V8ToString(val));
|
||||
if (code.length() != 1)
|
||||
|
@ -48,9 +49,10 @@ struct Converter<base::char16> {
|
|||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
template <>
|
||||
struct Converter<blink::WebInputEvent::Type> {
|
||||
static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val,
|
||||
static bool FromV8(v8::Isolate* isolate,
|
||||
v8::Handle<v8::Value> val,
|
||||
blink::WebInputEvent::Type* out) {
|
||||
std::string type = base::ToLowerASCII(V8ToString(val));
|
||||
if (type == "mousedown")
|
||||
|
@ -85,9 +87,10 @@ struct Converter<blink::WebInputEvent::Type> {
|
|||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
template <>
|
||||
struct Converter<blink::WebMouseEvent::Button> {
|
||||
static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val,
|
||||
static bool FromV8(v8::Isolate* isolate,
|
||||
v8::Handle<v8::Value> val,
|
||||
blink::WebMouseEvent::Button* out) {
|
||||
std::string button = base::ToLowerASCII(V8ToString(val));
|
||||
if (button == "left")
|
||||
|
@ -102,9 +105,10 @@ struct Converter<blink::WebMouseEvent::Button> {
|
|||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
template <>
|
||||
struct Converter<blink::WebInputEvent::Modifiers> {
|
||||
static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val,
|
||||
static bool FromV8(v8::Isolate* isolate,
|
||||
v8::Handle<v8::Value> val,
|
||||
blink::WebInputEvent::Modifiers* out) {
|
||||
std::string modifier = base::ToLowerASCII(V8ToString(val));
|
||||
if (modifier == "shift")
|
||||
|
@ -138,16 +142,16 @@ struct Converter<blink::WebInputEvent::Modifiers> {
|
|||
};
|
||||
|
||||
blink::WebInputEvent::Type GetWebInputEventType(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val) {
|
||||
v8::Local<v8::Value> val) {
|
||||
blink::WebInputEvent::Type type = blink::WebInputEvent::kUndefined;
|
||||
mate::Dictionary dict;
|
||||
ConvertFromV8(isolate, val, &dict) && dict.Get("type", &type);
|
||||
return type;
|
||||
}
|
||||
|
||||
bool Converter<blink::WebInputEvent>::FromV8(
|
||||
v8::Isolate* isolate, v8::Local<v8::Value> val,
|
||||
blink::WebInputEvent* out) {
|
||||
bool Converter<blink::WebInputEvent>::FromV8(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
blink::WebInputEvent* out) {
|
||||
mate::Dictionary dict;
|
||||
if (!ConvertFromV8(isolate, val, &dict))
|
||||
return false;
|
||||
|
@ -162,9 +166,9 @@ bool Converter<blink::WebInputEvent>::FromV8(
|
|||
return true;
|
||||
}
|
||||
|
||||
bool Converter<blink::WebKeyboardEvent>::FromV8(
|
||||
v8::Isolate* isolate, v8::Local<v8::Value> val,
|
||||
blink::WebKeyboardEvent* out) {
|
||||
bool Converter<blink::WebKeyboardEvent>::FromV8(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
blink::WebKeyboardEvent* out) {
|
||||
mate::Dictionary dict;
|
||||
if (!ConvertFromV8(isolate, val, &dict))
|
||||
return false;
|
||||
|
@ -208,7 +212,8 @@ bool Converter<blink::WebKeyboardEvent>::FromV8(
|
|||
}
|
||||
|
||||
bool Converter<content::NativeWebKeyboardEvent>::FromV8(
|
||||
v8::Isolate* isolate, v8::Local<v8::Value> val,
|
||||
v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
content::NativeWebKeyboardEvent* out) {
|
||||
mate::Dictionary dict;
|
||||
if (!ConvertFromV8(isolate, val, &dict))
|
||||
|
@ -220,7 +225,8 @@ bool Converter<content::NativeWebKeyboardEvent>::FromV8(
|
|||
}
|
||||
|
||||
v8::Local<v8::Value> Converter<content::NativeWebKeyboardEvent>::ToV8(
|
||||
v8::Isolate* isolate, const content::NativeWebKeyboardEvent& in) {
|
||||
v8::Isolate* isolate,
|
||||
const content::NativeWebKeyboardEvent& in) {
|
||||
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
|
||||
|
||||
if (in.GetType() == blink::WebInputEvent::Type::kRawKeyDown)
|
||||
|
@ -229,7 +235,7 @@ v8::Local<v8::Value> Converter<content::NativeWebKeyboardEvent>::ToV8(
|
|||
dict.Set("type", "keyUp");
|
||||
dict.Set("key", ui::KeycodeConverter::DomKeyToKeyString(in.dom_key));
|
||||
dict.Set("code", ui::KeycodeConverter::DomCodeToCodeString(
|
||||
static_cast<ui::DomCode>(in.dom_code)));
|
||||
static_cast<ui::DomCode>(in.dom_code)));
|
||||
|
||||
using Modifiers = blink::WebInputEvent::Modifiers;
|
||||
dict.Set("isAutoRepeat", (in.GetModifiers() & Modifiers::kIsAutoRepeat) != 0);
|
||||
|
@ -241,8 +247,9 @@ v8::Local<v8::Value> Converter<content::NativeWebKeyboardEvent>::ToV8(
|
|||
return dict.GetHandle();
|
||||
}
|
||||
|
||||
bool Converter<blink::WebMouseEvent>::FromV8(
|
||||
v8::Isolate* isolate, v8::Local<v8::Value> val, blink::WebMouseEvent* out) {
|
||||
bool Converter<blink::WebMouseEvent>::FromV8(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
blink::WebMouseEvent* out) {
|
||||
mate::Dictionary dict;
|
||||
if (!ConvertFromV8(isolate, val, &dict))
|
||||
return false;
|
||||
|
@ -271,7 +278,8 @@ bool Converter<blink::WebMouseEvent>::FromV8(
|
|||
}
|
||||
|
||||
bool Converter<blink::WebMouseWheelEvent>::FromV8(
|
||||
v8::Isolate* isolate, v8::Local<v8::Value> val,
|
||||
v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
blink::WebMouseWheelEvent* out) {
|
||||
mate::Dictionary dict;
|
||||
if (!ConvertFromV8(isolate, val, &dict))
|
||||
|
@ -297,32 +305,35 @@ bool Converter<blink::WebMouseWheelEvent>::FromV8(
|
|||
return true;
|
||||
}
|
||||
|
||||
bool Converter<blink::WebFloatPoint>::FromV8(
|
||||
v8::Isolate* isolate, v8::Local<v8::Value> val, blink::WebFloatPoint* out) {
|
||||
bool Converter<blink::WebFloatPoint>::FromV8(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
blink::WebFloatPoint* out) {
|
||||
mate::Dictionary dict;
|
||||
if (!ConvertFromV8(isolate, val, &dict))
|
||||
return false;
|
||||
return dict.Get("x", &out->x) && dict.Get("y", &out->y);
|
||||
}
|
||||
|
||||
template<>
|
||||
template <>
|
||||
struct Converter<base::Optional<blink::WebPoint>> {
|
||||
static bool FromV8(
|
||||
v8::Isolate* isolate, v8::Local<v8::Value> val,
|
||||
base::Optional<blink::WebPoint>* out) {
|
||||
static bool FromV8(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
base::Optional<blink::WebPoint>* out) {
|
||||
mate::Dictionary dict;
|
||||
if (!ConvertFromV8(isolate, val, &dict))
|
||||
return false;
|
||||
blink::WebPoint point;
|
||||
bool success = dict.Get("x", &point.x) && dict.Get("y", &point.y);
|
||||
if (!success) return false;
|
||||
if (!success)
|
||||
return false;
|
||||
out->emplace(point);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
bool Converter<blink::WebSize>::FromV8(
|
||||
v8::Isolate* isolate, v8::Local<v8::Value> val, blink::WebSize* out) {
|
||||
bool Converter<blink::WebSize>::FromV8(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
blink::WebSize* out) {
|
||||
mate::Dictionary dict;
|
||||
if (!ConvertFromV8(isolate, val, &dict))
|
||||
return false;
|
||||
|
@ -330,7 +341,8 @@ bool Converter<blink::WebSize>::FromV8(
|
|||
}
|
||||
|
||||
bool Converter<blink::WebDeviceEmulationParams>::FromV8(
|
||||
v8::Isolate* isolate, v8::Local<v8::Value> val,
|
||||
v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
blink::WebDeviceEmulationParams* out) {
|
||||
mate::Dictionary dict;
|
||||
if (!ConvertFromV8(isolate, val, &dict))
|
||||
|
@ -355,10 +367,9 @@ bool Converter<blink::WebDeviceEmulationParams>::FromV8(
|
|||
return true;
|
||||
}
|
||||
|
||||
bool Converter<blink::WebFindOptions>::FromV8(
|
||||
v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
blink::WebFindOptions* out) {
|
||||
bool Converter<blink::WebFindOptions>::FromV8(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
blink::WebFindOptions* out) {
|
||||
mate::Dictionary dict;
|
||||
if (!ConvertFromV8(isolate, val, &dict))
|
||||
return false;
|
||||
|
@ -373,7 +384,8 @@ bool Converter<blink::WebFindOptions>::FromV8(
|
|||
|
||||
// static
|
||||
v8::Local<v8::Value> Converter<blink::WebContextMenuData::MediaType>::ToV8(
|
||||
v8::Isolate* isolate, const blink::WebContextMenuData::MediaType& in) {
|
||||
v8::Isolate* isolate,
|
||||
const blink::WebContextMenuData::MediaType& in) {
|
||||
switch (in) {
|
||||
case blink::WebContextMenuData::kMediaTypeImage:
|
||||
return mate::StringToV8(isolate, "image");
|
||||
|
@ -394,8 +406,8 @@ v8::Local<v8::Value> Converter<blink::WebContextMenuData::MediaType>::ToV8(
|
|||
|
||||
// static
|
||||
v8::Local<v8::Value> Converter<blink::WebContextMenuData::InputFieldType>::ToV8(
|
||||
v8::Isolate* isolate,
|
||||
const blink::WebContextMenuData::InputFieldType& in) {
|
||||
v8::Isolate* isolate,
|
||||
const blink::WebContextMenuData::InputFieldType& in) {
|
||||
switch (in) {
|
||||
case blink::WebContextMenuData::kInputFieldTypePlainText:
|
||||
return mate::StringToV8(isolate, "plainText");
|
||||
|
@ -410,14 +422,10 @@ v8::Local<v8::Value> Converter<blink::WebContextMenuData::InputFieldType>::ToV8(
|
|||
|
||||
v8::Local<v8::Value> EditFlagsToV8(v8::Isolate* isolate, int editFlags) {
|
||||
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
|
||||
dict.Set("canUndo",
|
||||
!!(editFlags & blink::WebContextMenuData::kCanUndo));
|
||||
dict.Set("canRedo",
|
||||
!!(editFlags & blink::WebContextMenuData::kCanRedo));
|
||||
dict.Set("canCut",
|
||||
!!(editFlags & blink::WebContextMenuData::kCanCut));
|
||||
dict.Set("canCopy",
|
||||
!!(editFlags & blink::WebContextMenuData::kCanCopy));
|
||||
dict.Set("canUndo", !!(editFlags & blink::WebContextMenuData::kCanUndo));
|
||||
dict.Set("canRedo", !!(editFlags & blink::WebContextMenuData::kCanRedo));
|
||||
dict.Set("canCut", !!(editFlags & blink::WebContextMenuData::kCanCut));
|
||||
dict.Set("canCopy", !!(editFlags & blink::WebContextMenuData::kCanCopy));
|
||||
|
||||
bool pasteFlag = false;
|
||||
if (editFlags & blink::WebContextMenuData::kCanPaste) {
|
||||
|
@ -429,10 +437,9 @@ v8::Local<v8::Value> EditFlagsToV8(v8::Isolate* isolate, int editFlags) {
|
|||
}
|
||||
dict.Set("canPaste", pasteFlag);
|
||||
|
||||
dict.Set("canDelete",
|
||||
!!(editFlags & blink::WebContextMenuData::kCanDelete));
|
||||
dict.Set("canDelete", !!(editFlags & blink::WebContextMenuData::kCanDelete));
|
||||
dict.Set("canSelectAll",
|
||||
!!(editFlags & blink::WebContextMenuData::kCanSelectAll));
|
||||
!!(editFlags & blink::WebContextMenuData::kCanSelectAll));
|
||||
|
||||
return mate::ConvertToV8(isolate, dict);
|
||||
}
|
||||
|
@ -440,21 +447,20 @@ v8::Local<v8::Value> EditFlagsToV8(v8::Isolate* isolate, int editFlags) {
|
|||
v8::Local<v8::Value> MediaFlagsToV8(v8::Isolate* isolate, int mediaFlags) {
|
||||
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
|
||||
dict.Set("inError",
|
||||
!!(mediaFlags & blink::WebContextMenuData::kMediaInError));
|
||||
!!(mediaFlags & blink::WebContextMenuData::kMediaInError));
|
||||
dict.Set("isPaused",
|
||||
!!(mediaFlags & blink::WebContextMenuData::kMediaPaused));
|
||||
dict.Set("isMuted",
|
||||
!!(mediaFlags & blink::WebContextMenuData::kMediaMuted));
|
||||
!!(mediaFlags & blink::WebContextMenuData::kMediaPaused));
|
||||
dict.Set("isMuted", !!(mediaFlags & blink::WebContextMenuData::kMediaMuted));
|
||||
dict.Set("hasAudio",
|
||||
!!(mediaFlags & blink::WebContextMenuData::kMediaHasAudio));
|
||||
!!(mediaFlags & blink::WebContextMenuData::kMediaHasAudio));
|
||||
dict.Set("isLooping",
|
||||
(mediaFlags & blink::WebContextMenuData::kMediaLoop) != 0);
|
||||
(mediaFlags & blink::WebContextMenuData::kMediaLoop) != 0);
|
||||
dict.Set("isControlsVisible",
|
||||
(mediaFlags & blink::WebContextMenuData::kMediaControls) != 0);
|
||||
(mediaFlags & blink::WebContextMenuData::kMediaControls) != 0);
|
||||
dict.Set("canToggleControls",
|
||||
!!(mediaFlags & blink::WebContextMenuData::kMediaCanToggleControls));
|
||||
!!(mediaFlags & blink::WebContextMenuData::kMediaCanToggleControls));
|
||||
dict.Set("canRotate",
|
||||
!!(mediaFlags & blink::WebContextMenuData::kMediaCanRotate));
|
||||
!!(mediaFlags & blink::WebContextMenuData::kMediaCanRotate));
|
||||
return mate::ConvertToV8(isolate, dict);
|
||||
}
|
||||
|
||||
|
@ -483,8 +489,8 @@ v8::Local<v8::Value> Converter<blink::WebCache::ResourceTypeStats>::ToV8(
|
|||
|
||||
// static
|
||||
v8::Local<v8::Value> Converter<blink::WebReferrerPolicy>::ToV8(
|
||||
v8::Isolate* isolate,
|
||||
const blink::WebReferrerPolicy& in) {
|
||||
v8::Isolate* isolate,
|
||||
const blink::WebReferrerPolicy& in) {
|
||||
switch (in) {
|
||||
case blink::kWebReferrerPolicyDefault:
|
||||
return mate::StringToV8(isolate, "default");
|
||||
|
@ -508,8 +514,10 @@ v8::Local<v8::Value> Converter<blink::WebReferrerPolicy>::ToV8(
|
|||
}
|
||||
|
||||
// static
|
||||
bool Converter<blink::WebReferrerPolicy>::FromV8(v8::Isolate* isolate,
|
||||
v8::Handle<v8::Value> val, blink::WebReferrerPolicy* out) {
|
||||
bool Converter<blink::WebReferrerPolicy>::FromV8(
|
||||
v8::Isolate* isolate,
|
||||
v8::Handle<v8::Value> val,
|
||||
blink::WebReferrerPolicy* out) {
|
||||
std::string policy = base::ToLowerASCII(V8ToString(val));
|
||||
if (policy == "default")
|
||||
*out = blink::kWebReferrerPolicyDefault;
|
||||
|
|
|
@ -42,7 +42,7 @@ void CallTranslater(v8::Local<v8::External> external,
|
|||
|
||||
// Destroy the class on UI thread when possible.
|
||||
struct DeleteOnUIThread {
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
static void Destruct(const T* x) {
|
||||
if (Locker::IsBrowserProcess() &&
|
||||
!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
|
||||
|
@ -54,17 +54,14 @@ struct DeleteOnUIThread {
|
|||
};
|
||||
|
||||
// Like v8::Global, but ref-counted.
|
||||
template<typename T>
|
||||
class RefCountedGlobal : public base::RefCountedThreadSafe<RefCountedGlobal<T>,
|
||||
DeleteOnUIThread> {
|
||||
template <typename T>
|
||||
class RefCountedGlobal
|
||||
: public base::RefCountedThreadSafe<RefCountedGlobal<T>, DeleteOnUIThread> {
|
||||
public:
|
||||
RefCountedGlobal(v8::Isolate* isolate, v8::Local<v8::Value> value)
|
||||
: handle_(isolate, v8::Local<T>::Cast(value)) {
|
||||
}
|
||||
: handle_(isolate, v8::Local<T>::Cast(value)) {}
|
||||
|
||||
bool IsAlive() const {
|
||||
return !handle_.IsEmpty();
|
||||
}
|
||||
bool IsAlive() const { return !handle_.IsEmpty(); }
|
||||
|
||||
v8::Local<T> NewHandle(v8::Isolate* isolate) const {
|
||||
return v8::Local<T>::New(isolate, handle_);
|
||||
|
@ -77,15 +74,12 @@ class RefCountedGlobal : public base::RefCountedThreadSafe<RefCountedGlobal<T>,
|
|||
};
|
||||
|
||||
SafeV8Function::SafeV8Function(v8::Isolate* isolate, v8::Local<v8::Value> value)
|
||||
: v8_function_(new RefCountedGlobal<v8::Function>(isolate, value)) {
|
||||
}
|
||||
: v8_function_(new RefCountedGlobal<v8::Function>(isolate, value)) {}
|
||||
|
||||
SafeV8Function::SafeV8Function(const SafeV8Function& other)
|
||||
: v8_function_(other.v8_function_) {
|
||||
}
|
||||
: v8_function_(other.v8_function_) {}
|
||||
|
||||
SafeV8Function::~SafeV8Function() {
|
||||
}
|
||||
SafeV8Function::~SafeV8Function() {}
|
||||
|
||||
bool SafeV8Function::IsAlive() const {
|
||||
return v8_function_.get() && v8_function_->IsAlive();
|
||||
|
@ -96,22 +90,20 @@ v8::Local<v8::Function> SafeV8Function::NewHandle(v8::Isolate* isolate) const {
|
|||
}
|
||||
|
||||
v8::Local<v8::Value> CreateFunctionFromTranslater(
|
||||
v8::Isolate* isolate, const Translater& translater) {
|
||||
v8::Isolate* isolate,
|
||||
const Translater& translater) {
|
||||
// The FunctionTemplate is cached.
|
||||
if (g_call_translater.IsEmpty())
|
||||
g_call_translater.Reset(
|
||||
isolate,
|
||||
mate::CreateFunctionTemplate(isolate, base::Bind(&CallTranslater)));
|
||||
g_call_translater.Reset(isolate, mate::CreateFunctionTemplate(
|
||||
isolate, base::Bind(&CallTranslater)));
|
||||
|
||||
v8::Local<v8::FunctionTemplate> call_translater =
|
||||
v8::Local<v8::FunctionTemplate>::New(isolate, g_call_translater);
|
||||
auto* holder = new TranslaterHolder;
|
||||
holder->translater = translater;
|
||||
return BindFunctionWith(isolate,
|
||||
isolate->GetCurrentContext(),
|
||||
call_translater->GetFunction(),
|
||||
v8::External::New(isolate, holder),
|
||||
v8::Object::New(isolate));
|
||||
return BindFunctionWith(
|
||||
isolate, isolate->GetCurrentContext(), call_translater->GetFunction(),
|
||||
v8::External::New(isolate, holder), v8::Object::New(isolate));
|
||||
}
|
||||
|
||||
// func.bind(func, arg1).
|
||||
|
|
|
@ -78,7 +78,8 @@ namespace mate {
|
|||
|
||||
// static
|
||||
v8::Local<v8::Value> Converter<content::MenuItem::Type>::ToV8(
|
||||
v8::Isolate* isolate, const content::MenuItem::Type& val) {
|
||||
v8::Isolate* isolate,
|
||||
const content::MenuItem::Type& val) {
|
||||
switch (val) {
|
||||
case content::MenuItem::CHECKABLE_OPTION:
|
||||
return StringToV8(isolate, "checkbox");
|
||||
|
@ -96,7 +97,8 @@ v8::Local<v8::Value> Converter<content::MenuItem::Type>::ToV8(
|
|||
|
||||
// static
|
||||
v8::Local<v8::Value> Converter<ContextMenuParamsWithWebContents>::ToV8(
|
||||
v8::Isolate* isolate, const ContextMenuParamsWithWebContents& val) {
|
||||
v8::Isolate* isolate,
|
||||
const ContextMenuParamsWithWebContents& val) {
|
||||
const auto& params = val.first;
|
||||
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
|
||||
dict.Set("x", params.x);
|
||||
|
@ -109,8 +111,8 @@ v8::Local<v8::Value> Converter<ContextMenuParamsWithWebContents>::ToV8(
|
|||
dict.Set("mediaType", params.media_type);
|
||||
dict.Set("mediaFlags", MediaFlagsToV8(isolate, params.media_flags));
|
||||
bool has_image_contents =
|
||||
(params.media_type == blink::WebContextMenuData::kMediaTypeImage) &&
|
||||
params.has_image_contents;
|
||||
(params.media_type == blink::WebContextMenuData::kMediaTypeImage) &&
|
||||
params.has_image_contents;
|
||||
dict.Set("hasImageContents", has_image_contents);
|
||||
dict.Set("isEditable", params.is_editable);
|
||||
dict.Set("editFlags", EditFlagsToV8(isolate, params.edit_flags));
|
||||
|
@ -119,7 +121,7 @@ v8::Local<v8::Value> Converter<ContextMenuParamsWithWebContents>::ToV8(
|
|||
dict.Set("misspelledWord", params.misspelled_word);
|
||||
dict.Set("frameCharset", params.frame_charset);
|
||||
dict.Set("inputFieldType", params.input_field_type);
|
||||
dict.Set("menuSourceType", params.source_type);
|
||||
dict.Set("menuSourceType", params.source_type);
|
||||
|
||||
if (params.custom_context.is_pepper_menu)
|
||||
dict.Set("menu", MenuToV8(isolate, val.second, params.custom_context,
|
||||
|
@ -146,7 +148,8 @@ bool Converter<blink::mojom::PermissionStatus>::FromV8(
|
|||
|
||||
// static
|
||||
v8::Local<v8::Value> Converter<content::PermissionType>::ToV8(
|
||||
v8::Isolate* isolate, const content::PermissionType& val) {
|
||||
v8::Isolate* isolate,
|
||||
const content::PermissionType& val) {
|
||||
using PermissionType = atom::WebContentsPermissionHelper::PermissionType;
|
||||
switch (val) {
|
||||
case content::PermissionType::MIDI_SYSEX:
|
||||
|
@ -181,10 +184,9 @@ v8::Local<v8::Value> Converter<content::PermissionType>::ToV8(
|
|||
}
|
||||
|
||||
// static
|
||||
bool Converter<content::StopFindAction>::FromV8(
|
||||
v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
content::StopFindAction* out) {
|
||||
bool Converter<content::StopFindAction>::FromV8(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
content::StopFindAction* out) {
|
||||
std::string action;
|
||||
if (!ConvertFromV8(isolate, val, &action))
|
||||
return false;
|
||||
|
@ -202,8 +204,7 @@ bool Converter<content::StopFindAction>::FromV8(
|
|||
}
|
||||
|
||||
// static
|
||||
v8::Local<v8::Value>
|
||||
Converter<scoped_refptr<ResourceRequestBody>>::ToV8(
|
||||
v8::Local<v8::Value> Converter<scoped_refptr<ResourceRequestBody>>::ToV8(
|
||||
v8::Isolate* isolate,
|
||||
const scoped_refptr<ResourceRequestBody>& val) {
|
||||
if (!val)
|
||||
|
@ -214,9 +215,8 @@ Converter<scoped_refptr<ResourceRequestBody>>::ToV8(
|
|||
new base::DictionaryValue);
|
||||
auto type = element.type();
|
||||
if (type == ResourceRequestBody::Element::TYPE_BYTES) {
|
||||
std::unique_ptr<base::Value> bytes(
|
||||
base::Value::CreateWithCopiedBuffer(
|
||||
element.bytes(), static_cast<size_t>(element.length())));
|
||||
std::unique_ptr<base::Value> bytes(base::Value::CreateWithCopiedBuffer(
|
||||
element.bytes(), static_cast<size_t>(element.length())));
|
||||
post_data_dict->SetString("type", "rawData");
|
||||
post_data_dict->Set("bytes", std::move(bytes));
|
||||
} else if (type == ResourceRequestBody::Element::TYPE_FILE) {
|
||||
|
@ -284,8 +284,7 @@ bool Converter<scoped_refptr<ResourceRequestBody>>::FromV8(
|
|||
dict->GetInteger("file", &length);
|
||||
dict->GetDouble("modificationTime", &modification_time);
|
||||
(*out)->AppendFileSystemFileRange(
|
||||
GURL(file_system_url),
|
||||
static_cast<uint64_t>(offset),
|
||||
GURL(file_system_url), static_cast<uint64_t>(offset),
|
||||
static_cast<uint64_t>(length),
|
||||
base::Time::FromDoubleT(modification_time));
|
||||
} else if (type == "blob") {
|
||||
|
@ -299,17 +298,17 @@ bool Converter<scoped_refptr<ResourceRequestBody>>::FromV8(
|
|||
|
||||
// static
|
||||
v8::Local<v8::Value> Converter<content::WebContents*>::ToV8(
|
||||
v8::Isolate* isolate, content::WebContents* val) {
|
||||
v8::Isolate* isolate,
|
||||
content::WebContents* val) {
|
||||
if (!val)
|
||||
return v8::Null(isolate);
|
||||
return atom::api::WebContents::CreateFrom(isolate, val).ToV8();
|
||||
}
|
||||
|
||||
// static
|
||||
bool Converter<content::WebContents*>::FromV8(
|
||||
v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
content::WebContents** out) {
|
||||
bool Converter<content::WebContents*>::FromV8(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
content::WebContents** out) {
|
||||
atom::api::WebContents* web_contents = nullptr;
|
||||
if (!ConvertFromV8(isolate, val, &web_contents) || !web_contents)
|
||||
return false;
|
||||
|
@ -320,7 +319,8 @@ bool Converter<content::WebContents*>::FromV8(
|
|||
|
||||
// static
|
||||
v8::Local<v8::Value> Converter<content::Referrer>::ToV8(
|
||||
v8::Isolate* isolate, const content::Referrer& val) {
|
||||
v8::Isolate* isolate,
|
||||
const content::Referrer& val) {
|
||||
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
|
||||
dict.Set("url", ConvertToV8(isolate, val.url));
|
||||
dict.Set("policy", ConvertToV8(isolate, val.policy));
|
||||
|
@ -328,10 +328,9 @@ v8::Local<v8::Value> Converter<content::Referrer>::ToV8(
|
|||
}
|
||||
|
||||
// static
|
||||
bool Converter<content::Referrer>::FromV8(
|
||||
v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
content::Referrer* out) {
|
||||
bool Converter<content::Referrer>::FromV8(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
content::Referrer* out) {
|
||||
mate::Dictionary dict;
|
||||
if (!ConvertFromV8(isolate, val, &dict))
|
||||
return false;
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
namespace mate {
|
||||
|
||||
v8::Local<v8::Value> Converter<gfx::Point>::ToV8(v8::Isolate* isolate,
|
||||
const gfx::Point& val) {
|
||||
const gfx::Point& val) {
|
||||
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
|
||||
dict.SetHidden("simple", true);
|
||||
dict.Set("x", val.x());
|
||||
|
@ -58,7 +58,7 @@ bool Converter<gfx::Size>::FromV8(v8::Isolate* isolate,
|
|||
}
|
||||
|
||||
v8::Local<v8::Value> Converter<gfx::Rect>::ToV8(v8::Isolate* isolate,
|
||||
const gfx::Rect& val) {
|
||||
const gfx::Rect& val) {
|
||||
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
|
||||
dict.SetHidden("simple", true);
|
||||
dict.Set("x", val.x());
|
||||
|
@ -75,17 +75,17 @@ bool Converter<gfx::Rect>::FromV8(v8::Isolate* isolate,
|
|||
if (!ConvertFromV8(isolate, val, &dict))
|
||||
return false;
|
||||
int x, y, width, height;
|
||||
if (!dict.Get("x", &x) || !dict.Get("y", &y) ||
|
||||
!dict.Get("width", &width) || !dict.Get("height", &height))
|
||||
if (!dict.Get("x", &x) || !dict.Get("y", &y) || !dict.Get("width", &width) ||
|
||||
!dict.Get("height", &height))
|
||||
return false;
|
||||
*out = gfx::Rect(x, y, width, height);
|
||||
return true;
|
||||
}
|
||||
|
||||
template<>
|
||||
template <>
|
||||
struct Converter<display::Display::TouchSupport> {
|
||||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||
const display::Display::TouchSupport& val) {
|
||||
const display::Display::TouchSupport& val) {
|
||||
switch (val) {
|
||||
case display::Display::TOUCH_SUPPORT_AVAILABLE:
|
||||
return StringToV8(isolate, "available");
|
||||
|
@ -98,7 +98,8 @@ struct Converter<display::Display::TouchSupport> {
|
|||
};
|
||||
|
||||
v8::Local<v8::Value> Converter<display::Display>::ToV8(
|
||||
v8::Isolate* isolate, const display::Display& val) {
|
||||
v8::Isolate* isolate,
|
||||
const display::Display& val) {
|
||||
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
|
||||
dict.SetHidden("simple", true);
|
||||
dict.Set("id", val.id());
|
||||
|
|
|
@ -36,7 +36,7 @@ bool Converter<gfx::Image>::FromV8(v8::Isolate* isolate,
|
|||
}
|
||||
|
||||
v8::Local<v8::Value> Converter<gfx::Image>::ToV8(v8::Isolate* isolate,
|
||||
const gfx::Image& val) {
|
||||
const gfx::Image& val) {
|
||||
return ConvertToV8(isolate, atom::api::NativeImage::Create(isolate, val));
|
||||
}
|
||||
|
||||
|
|
|
@ -29,10 +29,10 @@ namespace mate {
|
|||
namespace {
|
||||
|
||||
bool CertFromData(const std::string& data,
|
||||
scoped_refptr<net::X509Certificate>* out) {
|
||||
scoped_refptr<net::X509Certificate>* out) {
|
||||
auto cert_list = net::X509Certificate::CreateCertificateListFromBytes(
|
||||
data.c_str(), data.length(),
|
||||
net::X509Certificate::FORMAT_SINGLE_CERTIFICATE);
|
||||
data.c_str(), data.length(),
|
||||
net::X509Certificate::FORMAT_SINGLE_CERTIFICATE);
|
||||
if (cert_list.empty())
|
||||
return false;
|
||||
|
||||
|
@ -49,7 +49,8 @@ bool CertFromData(const std::string& data,
|
|||
|
||||
// static
|
||||
v8::Local<v8::Value> Converter<const net::AuthChallengeInfo*>::ToV8(
|
||||
v8::Isolate* isolate, const net::AuthChallengeInfo* val) {
|
||||
v8::Isolate* isolate,
|
||||
const net::AuthChallengeInfo* val) {
|
||||
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
|
||||
dict.Set("isProxy", val->is_proxy);
|
||||
dict.Set("scheme", val->scheme);
|
||||
|
@ -61,11 +62,11 @@ v8::Local<v8::Value> Converter<const net::AuthChallengeInfo*>::ToV8(
|
|||
|
||||
// static
|
||||
v8::Local<v8::Value> Converter<scoped_refptr<net::X509Certificate>>::ToV8(
|
||||
v8::Isolate* isolate, const scoped_refptr<net::X509Certificate>& val) {
|
||||
v8::Isolate* isolate,
|
||||
const scoped_refptr<net::X509Certificate>& val) {
|
||||
mate::Dictionary dict(isolate, v8::Object::New(isolate));
|
||||
std::string encoded_data;
|
||||
net::X509Certificate::GetPEMEncoded(
|
||||
val->os_cert_handle(), &encoded_data);
|
||||
net::X509Certificate::GetPEMEncoded(val->os_cert_handle(), &encoded_data);
|
||||
|
||||
dict.Set("data", encoded_data);
|
||||
dict.Set("issuer", val->issuer());
|
||||
|
@ -77,8 +78,8 @@ v8::Local<v8::Value> Converter<scoped_refptr<net::X509Certificate>>::ToV8(
|
|||
dict.Set("validStart", val->valid_start().ToDoubleT());
|
||||
dict.Set("validExpiry", val->valid_expiry().ToDoubleT());
|
||||
dict.Set("fingerprint",
|
||||
net::HashValue(
|
||||
val->CalculateFingerprint256(val->os_cert_handle())).ToString());
|
||||
net::HashValue(val->CalculateFingerprint256(val->os_cert_handle()))
|
||||
.ToString());
|
||||
|
||||
if (!val->GetIntermediateCertificates().empty()) {
|
||||
net::X509Certificate::OSCertHandles issuer_intermediates(
|
||||
|
@ -86,8 +87,7 @@ v8::Local<v8::Value> Converter<scoped_refptr<net::X509Certificate>>::ToV8(
|
|||
val->GetIntermediateCertificates().end());
|
||||
const scoped_refptr<net::X509Certificate>& issuer_cert =
|
||||
net::X509Certificate::CreateFromHandle(
|
||||
val->GetIntermediateCertificates().front(),
|
||||
issuer_intermediates);
|
||||
val->GetIntermediateCertificates().front(), issuer_intermediates);
|
||||
dict.Set("issuerCert", issuer_cert);
|
||||
}
|
||||
|
||||
|
@ -95,7 +95,8 @@ v8::Local<v8::Value> Converter<scoped_refptr<net::X509Certificate>>::ToV8(
|
|||
}
|
||||
|
||||
bool Converter<scoped_refptr<net::X509Certificate>>::FromV8(
|
||||
v8::Isolate* isolate, v8::Local<v8::Value> val,
|
||||
v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
scoped_refptr<net::X509Certificate>* out) {
|
||||
mate::Dictionary dict;
|
||||
if (!ConvertFromV8(isolate, val, &dict))
|
||||
|
@ -110,10 +111,10 @@ bool Converter<scoped_refptr<net::X509Certificate>>::FromV8(
|
|||
scoped_refptr<net::X509Certificate> parent;
|
||||
if (dict.Get("issuerCert", &parent)) {
|
||||
auto parents = std::vector<net::X509Certificate::OSCertHandle>(
|
||||
parent->GetIntermediateCertificates());
|
||||
parent->GetIntermediateCertificates());
|
||||
parents.insert(parents.begin(), parent->os_cert_handle());
|
||||
auto cert = net::X509Certificate::CreateFromHandle(
|
||||
leaf_cert->os_cert_handle(), parents);
|
||||
leaf_cert->os_cert_handle(), parents);
|
||||
if (!cert)
|
||||
return false;
|
||||
|
||||
|
@ -127,7 +128,8 @@ bool Converter<scoped_refptr<net::X509Certificate>>::FromV8(
|
|||
|
||||
// static
|
||||
v8::Local<v8::Value> Converter<net::CertPrincipal>::ToV8(
|
||||
v8::Isolate* isolate, const net::CertPrincipal& val) {
|
||||
v8::Isolate* isolate,
|
||||
const net::CertPrincipal& val) {
|
||||
mate::Dictionary dict(isolate, v8::Object::New(isolate));
|
||||
|
||||
dict.Set("commonName", val.common_name);
|
||||
|
@ -202,7 +204,8 @@ void FillRequestDetails(base::DictionaryValue* details,
|
|||
const net::URLRequest* request) {
|
||||
details->SetString("method", request->method());
|
||||
std::string url;
|
||||
if (!request->url_chain().empty()) url = request->url().spec();
|
||||
if (!request->url_chain().empty())
|
||||
url = request->url().spec();
|
||||
details->SetKey("url", base::Value(url));
|
||||
details->SetString("referrer", request->referrer());
|
||||
std::unique_ptr<base::ListValue> list(new base::ListValue);
|
||||
|
@ -231,13 +234,11 @@ void GetUploadData(base::ListValue* upload_data_list,
|
|||
if (reader->AsBytesReader()) {
|
||||
const net::UploadBytesElementReader* bytes_reader =
|
||||
reader->AsBytesReader();
|
||||
std::unique_ptr<base::Value> bytes(
|
||||
base::Value::CreateWithCopiedBuffer(bytes_reader->bytes(),
|
||||
bytes_reader->length()));
|
||||
std::unique_ptr<base::Value> bytes(base::Value::CreateWithCopiedBuffer(
|
||||
bytes_reader->bytes(), bytes_reader->length()));
|
||||
upload_data_dict->Set("bytes", std::move(bytes));
|
||||
} else if (reader->AsFileReader()) {
|
||||
const net::UploadFileElementReader* file_reader =
|
||||
reader->AsFileReader();
|
||||
const net::UploadFileElementReader* file_reader = reader->AsFileReader();
|
||||
auto file_path = file_reader->path().AsUTF8Unsafe();
|
||||
upload_data_dict->SetKey("file", base::Value(file_path));
|
||||
} else {
|
||||
|
|
|
@ -32,9 +32,7 @@ class V8ValueConverter::FromV8ValueState {
|
|||
explicit Level(FromV8ValueState* state) : state_(state) {
|
||||
state_->max_recursion_depth_--;
|
||||
}
|
||||
~Level() {
|
||||
state_->max_recursion_depth_++;
|
||||
}
|
||||
~Level() { state_->max_recursion_depth_++; }
|
||||
|
||||
private:
|
||||
FromV8ValueState* state_;
|
||||
|
@ -68,9 +66,7 @@ class V8ValueConverter::FromV8ValueState {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool HasReachedMaxRecursionDepth() {
|
||||
return max_recursion_depth_ < 0;
|
||||
}
|
||||
bool HasReachedMaxRecursionDepth() { return max_recursion_depth_ < 0; }
|
||||
|
||||
private:
|
||||
using HashToHandleMap = std::multimap<int, v8::Local<v8::Object>>;
|
||||
|
@ -118,7 +114,7 @@ class V8ValueConverter::ScopedUniquenessGuard {
|
|||
bool is_valid() const { return is_valid_; }
|
||||
|
||||
private:
|
||||
typedef std::multimap<int, v8::Local<v8::Object> > HashToHandleMap;
|
||||
typedef std::multimap<int, v8::Local<v8::Object>> HashToHandleMap;
|
||||
V8ValueConverter::FromV8ValueState* state_;
|
||||
v8::Local<v8::Object> value_;
|
||||
bool is_valid_;
|
||||
|
@ -149,7 +145,8 @@ void V8ValueConverter::SetDisableNode(bool val) {
|
|||
}
|
||||
|
||||
v8::Local<v8::Value> V8ValueConverter::ToV8Value(
|
||||
const base::Value* value, v8::Local<v8::Context> context) const {
|
||||
const base::Value* value,
|
||||
v8::Local<v8::Context> context) const {
|
||||
v8::Context::Scope context_scope(context);
|
||||
v8::EscapableHandleScope handle_scope(context->GetIsolate());
|
||||
return handle_scope.Escape(ToV8ValueImpl(context->GetIsolate(), value));
|
||||
|
@ -165,7 +162,8 @@ base::Value* V8ValueConverter::FromV8Value(
|
|||
}
|
||||
|
||||
v8::Local<v8::Value> V8ValueConverter::ToV8ValueImpl(
|
||||
v8::Isolate* isolate, const base::Value* value) const {
|
||||
v8::Isolate* isolate,
|
||||
const base::Value* value) const {
|
||||
switch (value->GetType()) {
|
||||
case base::Value::Type::NONE:
|
||||
return v8::Null(isolate);
|
||||
|
@ -191,8 +189,8 @@ v8::Local<v8::Value> V8ValueConverter::ToV8ValueImpl(
|
|||
case base::Value::Type::STRING: {
|
||||
std::string val;
|
||||
value->GetAsString(&val);
|
||||
return v8::String::NewFromUtf8(
|
||||
isolate, val.c_str(), v8::String::kNormalString, val.length());
|
||||
return v8::String::NewFromUtf8(isolate, val.c_str(),
|
||||
v8::String::kNormalString, val.length());
|
||||
}
|
||||
|
||||
case base::Value::Type::LIST:
|
||||
|
@ -203,8 +201,7 @@ v8::Local<v8::Value> V8ValueConverter::ToV8ValueImpl(
|
|||
static_cast<const base::DictionaryValue*>(value));
|
||||
|
||||
case base::Value::Type::BINARY:
|
||||
return ToArrayBuffer(isolate,
|
||||
static_cast<const base::Value*>(value));
|
||||
return ToArrayBuffer(isolate, static_cast<const base::Value*>(value));
|
||||
|
||||
default:
|
||||
LOG(ERROR) << "Unexpected value type: " << value->GetType();
|
||||
|
@ -213,7 +210,8 @@ v8::Local<v8::Value> V8ValueConverter::ToV8ValueImpl(
|
|||
}
|
||||
|
||||
v8::Local<v8::Value> V8ValueConverter::ToV8Array(
|
||||
v8::Isolate* isolate, const base::ListValue* val) const {
|
||||
v8::Isolate* isolate,
|
||||
const base::ListValue* val) const {
|
||||
v8::Local<v8::Array> result(v8::Array::New(isolate, val->GetSize()));
|
||||
|
||||
for (size_t i = 0; i < val->GetSize(); ++i) {
|
||||
|
@ -232,12 +230,13 @@ v8::Local<v8::Value> V8ValueConverter::ToV8Array(
|
|||
}
|
||||
|
||||
v8::Local<v8::Value> V8ValueConverter::ToV8Object(
|
||||
v8::Isolate* isolate, const base::DictionaryValue* val) const {
|
||||
v8::Isolate* isolate,
|
||||
const base::DictionaryValue* val) const {
|
||||
mate::Dictionary result = mate::Dictionary::CreateEmpty(isolate);
|
||||
result.SetHidden("simple", true);
|
||||
|
||||
for (base::DictionaryValue::Iterator iter(*val);
|
||||
!iter.IsAtEnd(); iter.Advance()) {
|
||||
for (base::DictionaryValue::Iterator iter(*val); !iter.IsAtEnd();
|
||||
iter.Advance()) {
|
||||
const std::string& key = iter.key();
|
||||
v8::Local<v8::Value> child_v8 = ToV8ValueImpl(isolate, &iter.value());
|
||||
|
||||
|
@ -253,7 +252,8 @@ v8::Local<v8::Value> V8ValueConverter::ToV8Object(
|
|||
}
|
||||
|
||||
v8::Local<v8::Value> V8ValueConverter::ToArrayBuffer(
|
||||
v8::Isolate* isolate, const base::Value* value) const {
|
||||
v8::Isolate* isolate,
|
||||
const base::Value* value) const {
|
||||
const char* data = value->GetBlob().data();
|
||||
size_t length = value->GetBlob().size();
|
||||
|
||||
|
@ -282,14 +282,11 @@ v8::Local<v8::Value> V8ValueConverter::ToArrayBuffer(
|
|||
|
||||
mate::Dictionary buffer_class(isolate, buffer_value->ToObject());
|
||||
v8::Local<v8::Value> from_value;
|
||||
if (!buffer_class.Get("from", &from_value) ||
|
||||
!from_value->IsFunction()) {
|
||||
if (!buffer_class.Get("from", &from_value) || !from_value->IsFunction()) {
|
||||
return v8::Uint8Array::New(array_buffer, 0, length);
|
||||
}
|
||||
|
||||
v8::Local<v8::Value> args[] = {
|
||||
array_buffer
|
||||
};
|
||||
v8::Local<v8::Value> args[] = {array_buffer};
|
||||
auto func = v8::Local<v8::Function>::Cast(from_value);
|
||||
auto result = func->Call(context, v8::Null(isolate), 1, args);
|
||||
if (!result.IsEmpty()) {
|
||||
|
@ -299,10 +296,9 @@ v8::Local<v8::Value> V8ValueConverter::ToArrayBuffer(
|
|||
return v8::Uint8Array::New(array_buffer, 0, length);
|
||||
}
|
||||
|
||||
base::Value* V8ValueConverter::FromV8ValueImpl(
|
||||
FromV8ValueState* state,
|
||||
v8::Local<v8::Value> val,
|
||||
v8::Isolate* isolate) const {
|
||||
base::Value* V8ValueConverter::FromV8ValueImpl(FromV8ValueState* state,
|
||||
v8::Local<v8::Value> val,
|
||||
v8::Isolate* isolate) const {
|
||||
FromV8ValueState::Level state_level(state);
|
||||
if (state->HasReachedMaxRecursionDepth())
|
||||
return nullptr;
|
||||
|
@ -379,10 +375,9 @@ base::Value* V8ValueConverter::FromV8ValueImpl(
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
base::Value* V8ValueConverter::FromV8Array(
|
||||
v8::Local<v8::Array> val,
|
||||
FromV8ValueState* state,
|
||||
v8::Isolate* isolate) const {
|
||||
base::Value* V8ValueConverter::FromV8Array(v8::Local<v8::Array> val,
|
||||
FromV8ValueState* state,
|
||||
v8::Isolate* isolate) const {
|
||||
ScopedUniquenessGuard uniqueness_guard(state, val);
|
||||
if (!uniqueness_guard.is_valid())
|
||||
return std::make_unique<base::Value>().release();
|
||||
|
@ -419,18 +414,17 @@ base::Value* V8ValueConverter::FromV8Array(
|
|||
return result;
|
||||
}
|
||||
|
||||
base::Value* V8ValueConverter::FromNodeBuffer(
|
||||
v8::Local<v8::Value> value,
|
||||
FromV8ValueState* state,
|
||||
v8::Isolate* isolate) const {
|
||||
return base::Value::CreateWithCopiedBuffer(
|
||||
node::Buffer::Data(value), node::Buffer::Length(value)).release();
|
||||
base::Value* V8ValueConverter::FromNodeBuffer(v8::Local<v8::Value> value,
|
||||
FromV8ValueState* state,
|
||||
v8::Isolate* isolate) const {
|
||||
return base::Value::CreateWithCopiedBuffer(node::Buffer::Data(value),
|
||||
node::Buffer::Length(value))
|
||||
.release();
|
||||
}
|
||||
|
||||
base::Value* V8ValueConverter::FromV8Object(
|
||||
v8::Local<v8::Object> val,
|
||||
FromV8ValueState* state,
|
||||
v8::Isolate* isolate) const {
|
||||
base::Value* V8ValueConverter::FromV8Object(v8::Local<v8::Object> val,
|
||||
FromV8ValueState* state,
|
||||
v8::Isolate* isolate) const {
|
||||
ScopedUniquenessGuard uniqueness_guard(state, val);
|
||||
if (!uniqueness_guard.is_valid())
|
||||
return std::make_unique<base::Value>().release();
|
||||
|
@ -449,9 +443,9 @@ base::Value* V8ValueConverter::FromV8Object(
|
|||
v8::Local<v8::Value> key(property_names->Get(i));
|
||||
|
||||
// Extend this test to cover more types as necessary and if sensible.
|
||||
if (!key->IsString() &&
|
||||
!key->IsNumber()) {
|
||||
NOTREACHED() << "Key \"" << *v8::String::Utf8Value(key) << "\" "
|
||||
if (!key->IsString() && !key->IsNumber()) {
|
||||
NOTREACHED() << "Key \"" << *v8::String::Utf8Value(key)
|
||||
<< "\" "
|
||||
"is neither a string nor a number";
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -13,8 +13,8 @@ bool Converter<base::DictionaryValue>::FromV8(v8::Isolate* isolate,
|
|||
v8::Local<v8::Value> val,
|
||||
base::DictionaryValue* out) {
|
||||
std::unique_ptr<atom::V8ValueConverter> converter(new atom::V8ValueConverter);
|
||||
std::unique_ptr<base::Value> value(converter->FromV8Value(
|
||||
val, isolate->GetCurrentContext()));
|
||||
std::unique_ptr<base::Value> value(
|
||||
converter->FromV8Value(val, isolate->GetCurrentContext()));
|
||||
if (value && value->IsType(base::Value::Type::DICTIONARY)) {
|
||||
out->Swap(static_cast<base::DictionaryValue*>(value.get()));
|
||||
return true;
|
||||
|
@ -34,8 +34,8 @@ bool Converter<base::ListValue>::FromV8(v8::Isolate* isolate,
|
|||
v8::Local<v8::Value> val,
|
||||
base::ListValue* out) {
|
||||
std::unique_ptr<atom::V8ValueConverter> converter(new atom::V8ValueConverter);
|
||||
std::unique_ptr<base::Value> value(converter->FromV8Value(
|
||||
val, isolate->GetCurrentContext()));
|
||||
std::unique_ptr<base::Value> value(
|
||||
converter->FromV8Value(val, isolate->GetCurrentContext()));
|
||||
if (value->IsType(base::Value::Type::LIST)) {
|
||||
out->Swap(static_cast<base::ListValue*>(value.get()));
|
||||
return true;
|
||||
|
|
|
@ -77,11 +77,13 @@ namespace {
|
|||
void stop_and_close_uv_loop(uv_loop_t* loop) {
|
||||
// Close any active handles
|
||||
uv_stop(loop);
|
||||
uv_walk(loop, [](uv_handle_t* handle, void*){
|
||||
if (!uv_is_closing(handle)) {
|
||||
uv_close(handle, nullptr);
|
||||
}
|
||||
}, nullptr);
|
||||
uv_walk(loop,
|
||||
[](uv_handle_t* handle, void*) {
|
||||
if (!uv_is_closing(handle)) {
|
||||
uv_close(handle, nullptr);
|
||||
}
|
||||
},
|
||||
nullptr);
|
||||
|
||||
// Run the loop to let it finish all the closing handles
|
||||
// NB: after uv_stop(), uv_run(UV_RUN_DEFAULT) returns 0 when that's done
|
||||
|
@ -102,9 +104,9 @@ namespace {
|
|||
// Convert the given vector to an array of C-strings. The strings in the
|
||||
// returned vector are only guaranteed valid so long as the vector of strings
|
||||
// is not modified.
|
||||
std::unique_ptr<const char*[]> StringVectorToArgArray(
|
||||
std::unique_ptr<const char* []> StringVectorToArgArray(
|
||||
const std::vector<std::string>& vector) {
|
||||
std::unique_ptr<const char*[]> array(new const char*[vector.size()]);
|
||||
std::unique_ptr<const char* []> array(new const char*[vector.size()]);
|
||||
for (size_t i = 0; i < vector.size(); ++i) {
|
||||
array[i] = vector[i].c_str();
|
||||
}
|
||||
|
@ -118,9 +120,10 @@ base::FilePath GetResourcesPath(bool is_browser) {
|
|||
|
||||
base::FilePath resources_path =
|
||||
#if defined(OS_MACOSX)
|
||||
is_browser ? exec_path.DirName().DirName().Append("Resources") :
|
||||
exec_path.DirName().DirName().DirName().DirName().DirName()
|
||||
.Append("Resources");
|
||||
is_browser
|
||||
? exec_path.DirName().DirName().Append("Resources")
|
||||
: exec_path.DirName().DirName().DirName().DirName().DirName().Append(
|
||||
"Resources");
|
||||
#else
|
||||
exec_path.DirName().Append(FILE_PATH_LITERAL("resources"));
|
||||
#endif
|
||||
|
@ -221,11 +224,11 @@ node::Environment* NodeBindings::CreateEnvironment(
|
|||
base::FilePath resources_path = GetResourcesPath(browser_env_ == BROWSER);
|
||||
base::FilePath script_path =
|
||||
resources_path.Append(FILE_PATH_LITERAL("electron.asar"))
|
||||
.Append(process_type)
|
||||
.Append(FILE_PATH_LITERAL("init.js"));
|
||||
.Append(process_type)
|
||||
.Append(FILE_PATH_LITERAL("init.js"));
|
||||
args.insert(args.begin() + 1, script_path.AsUTF8Unsafe());
|
||||
|
||||
std::unique_ptr<const char*[]> c_argv = StringVectorToArgArray(args);
|
||||
std::unique_ptr<const char* []> c_argv = StringVectorToArgArray(args);
|
||||
node::Environment* env = node::CreateEnvironment(
|
||||
node::CreateIsolateData(context->GetIsolate(), uv_loop_, platform),
|
||||
context, args.size(), c_argv.get(), 0, nullptr);
|
||||
|
@ -324,7 +327,7 @@ void NodeBindings::WakeupEmbedThread() {
|
|||
}
|
||||
|
||||
// static
|
||||
void NodeBindings::EmbedThreadRunner(void *arg) {
|
||||
void NodeBindings::EmbedThreadRunner(void* arg) {
|
||||
NodeBindings* self = static_cast<NodeBindings*>(arg);
|
||||
|
||||
while (true) {
|
||||
|
|
|
@ -9,17 +9,15 @@
|
|||
namespace atom {
|
||||
|
||||
NodeBindingsLinux::NodeBindingsLinux(BrowserEnvironment browser_env)
|
||||
: NodeBindings(browser_env),
|
||||
epoll_(epoll_create(1)) {
|
||||
: NodeBindings(browser_env), epoll_(epoll_create(1)) {
|
||||
int backend_fd = uv_backend_fd(uv_loop_);
|
||||
struct epoll_event ev = { 0 };
|
||||
struct epoll_event ev = {0};
|
||||
ev.events = EPOLLIN;
|
||||
ev.data.fd = backend_fd;
|
||||
epoll_ctl(epoll_, EPOLL_CTL_ADD, backend_fd, &ev);
|
||||
}
|
||||
|
||||
NodeBindingsLinux::~NodeBindingsLinux() {
|
||||
}
|
||||
NodeBindingsLinux::~NodeBindingsLinux() {}
|
||||
|
||||
void NodeBindingsLinux::RunMessageLoop() {
|
||||
// Get notified when libuv's watcher queue changes.
|
||||
|
|
|
@ -15,11 +15,9 @@
|
|||
namespace atom {
|
||||
|
||||
NodeBindingsMac::NodeBindingsMac(BrowserEnvironment browser_env)
|
||||
: NodeBindings(browser_env) {
|
||||
}
|
||||
: NodeBindings(browser_env) {}
|
||||
|
||||
NodeBindingsMac::~NodeBindingsMac() {
|
||||
}
|
||||
NodeBindingsMac::~NodeBindingsMac() {}
|
||||
|
||||
void NodeBindingsMac::RunMessageLoop() {
|
||||
// Get notified when libuv's watcher queue changes.
|
||||
|
|
|
@ -15,11 +15,9 @@ extern "C" {
|
|||
namespace atom {
|
||||
|
||||
NodeBindingsWin::NodeBindingsWin(BrowserEnvironment browser_env)
|
||||
: NodeBindings(browser_env) {
|
||||
}
|
||||
: NodeBindings(browser_env) {}
|
||||
|
||||
NodeBindingsWin::~NodeBindingsWin() {
|
||||
}
|
||||
NodeBindingsWin::~NodeBindingsWin() {}
|
||||
|
||||
void NodeBindingsWin::PollEvents() {
|
||||
// If there are other kinds of events pending, uv_backend_timeout will
|
||||
|
@ -30,18 +28,11 @@ void NodeBindingsWin::PollEvents() {
|
|||
|
||||
timeout = uv_backend_timeout(uv_loop_);
|
||||
|
||||
GetQueuedCompletionStatus(uv_loop_->iocp,
|
||||
&bytes,
|
||||
&key,
|
||||
&overlapped,
|
||||
timeout);
|
||||
GetQueuedCompletionStatus(uv_loop_->iocp, &bytes, &key, &overlapped, timeout);
|
||||
|
||||
// Give the event back so libuv can deal with it.
|
||||
if (overlapped != NULL)
|
||||
PostQueuedCompletionStatus(uv_loop_->iocp,
|
||||
bytes,
|
||||
key,
|
||||
overlapped);
|
||||
PostQueuedCompletionStatus(uv_loop_->iocp, bytes, key, overlapped);
|
||||
}
|
||||
|
||||
// static
|
||||
|
|
|
@ -8,26 +8,26 @@ namespace atom {
|
|||
|
||||
namespace options {
|
||||
|
||||
const char kTitle[] = "title";
|
||||
const char kIcon[] = "icon";
|
||||
const char kFrame[] = "frame";
|
||||
const char kShow[] = "show";
|
||||
const char kCenter[] = "center";
|
||||
const char kX[] = "x";
|
||||
const char kY[] = "y";
|
||||
const char kWidth[] = "width";
|
||||
const char kHeight[] = "height";
|
||||
const char kMinWidth[] = "minWidth";
|
||||
const char kMinHeight[] = "minHeight";
|
||||
const char kMaxWidth[] = "maxWidth";
|
||||
const char kMaxHeight[] = "maxHeight";
|
||||
const char kResizable[] = "resizable";
|
||||
const char kMovable[] = "movable";
|
||||
const char kMinimizable[] = "minimizable";
|
||||
const char kMaximizable[] = "maximizable";
|
||||
const char kTitle[] = "title";
|
||||
const char kIcon[] = "icon";
|
||||
const char kFrame[] = "frame";
|
||||
const char kShow[] = "show";
|
||||
const char kCenter[] = "center";
|
||||
const char kX[] = "x";
|
||||
const char kY[] = "y";
|
||||
const char kWidth[] = "width";
|
||||
const char kHeight[] = "height";
|
||||
const char kMinWidth[] = "minWidth";
|
||||
const char kMinHeight[] = "minHeight";
|
||||
const char kMaxWidth[] = "maxWidth";
|
||||
const char kMaxHeight[] = "maxHeight";
|
||||
const char kResizable[] = "resizable";
|
||||
const char kMovable[] = "movable";
|
||||
const char kMinimizable[] = "minimizable";
|
||||
const char kMaximizable[] = "maximizable";
|
||||
const char kFullScreenable[] = "fullscreenable";
|
||||
const char kClosable[] = "closable";
|
||||
const char kFullscreen[] = "fullscreen";
|
||||
const char kClosable[] = "closable";
|
||||
const char kFullscreen[] = "fullscreen";
|
||||
|
||||
// Whether the window should show in taskbar.
|
||||
const char kSkipTaskbar[] = "skipTaskbar";
|
||||
|
@ -117,7 +117,7 @@ const char kContextIsolation[] = "contextIsolation";
|
|||
const char kGuestInstanceID[] = "guestInstanceId";
|
||||
|
||||
// Web runtime features.
|
||||
const char kExperimentalFeatures[] = "experimentalFeatures";
|
||||
const char kExperimentalFeatures[] = "experimentalFeatures";
|
||||
const char kExperimentalCanvasFeatures[] = "experimentalCanvasFeatures";
|
||||
|
||||
// Opener window's ID.
|
||||
|
@ -182,21 +182,21 @@ const char kAppPath[] = "app-path";
|
|||
const char kContextId[] = "context-id";
|
||||
|
||||
// The command line switch versions of the options.
|
||||
const char kBackgroundColor[] = "background-color";
|
||||
const char kPreloadScript[] = "preload";
|
||||
const char kPreloadURL[] = "preload-url";
|
||||
const char kPreloadScripts[] = "preload-scripts";
|
||||
const char kNodeIntegration[] = "node-integration";
|
||||
const char kBackgroundColor[] = "background-color";
|
||||
const char kPreloadScript[] = "preload";
|
||||
const char kPreloadURL[] = "preload-url";
|
||||
const char kPreloadScripts[] = "preload-scripts";
|
||||
const char kNodeIntegration[] = "node-integration";
|
||||
const char kContextIsolation[] = "context-isolation";
|
||||
const char kGuestInstanceID[] = "guest-instance-id";
|
||||
const char kOpenerID[] = "opener-id";
|
||||
const char kScrollBounce[] = "scroll-bounce";
|
||||
const char kHiddenPage[] = "hidden-page";
|
||||
const char kGuestInstanceID[] = "guest-instance-id";
|
||||
const char kOpenerID[] = "opener-id";
|
||||
const char kScrollBounce[] = "scroll-bounce";
|
||||
const char kHiddenPage[] = "hidden-page";
|
||||
const char kNativeWindowOpen[] = "native-window-open";
|
||||
const char kWebviewTag[] = "webview-tag";
|
||||
const char kWebviewTag[] = "webview-tag";
|
||||
|
||||
// Command switch passed to renderer process to control nodeIntegration.
|
||||
const char kNodeIntegrationInWorker[] = "node-integration-in-worker";
|
||||
const char kNodeIntegrationInWorker[] = "node-integration-in-worker";
|
||||
|
||||
// Widevine options
|
||||
// Path to Widevine CDM binaries.
|
||||
|
|
|
@ -19,8 +19,7 @@
|
|||
|
||||
namespace {
|
||||
|
||||
bool XDGUtilV(const std::vector<std::string>& argv,
|
||||
const bool wait_for_exit) {
|
||||
bool XDGUtilV(const std::vector<std::string>& argv, const bool wait_for_exit) {
|
||||
base::LaunchOptions options;
|
||||
options.allow_new_privs = true;
|
||||
// xdg-open can fall back on mailcap which eventually might plumb through
|
||||
|
@ -91,7 +90,8 @@ bool OpenExternal(const GURL& url, bool activate) {
|
|||
return XDGOpen(url.spec(), false);
|
||||
}
|
||||
|
||||
void OpenExternal(const GURL& url, bool activate,
|
||||
void OpenExternal(const GURL& url,
|
||||
bool activate,
|
||||
const OpenExternalCallback& callback) {
|
||||
// TODO(gabriel): Implement async open if callback is specified
|
||||
callback.Run(OpenExternal(url, activate) ? "" : "Failed to open");
|
||||
|
|
|
@ -35,8 +35,8 @@ namespace {
|
|||
// is empty. This function tells if it is.
|
||||
bool ValidateShellCommandForScheme(const std::string& scheme) {
|
||||
base::win::RegKey key;
|
||||
base::string16 registry_path = base::ASCIIToUTF16(scheme) +
|
||||
L"\\shell\\open\\command";
|
||||
base::string16 registry_path =
|
||||
base::ASCIIToUTF16(scheme) + L"\\shell\\open\\command";
|
||||
key.Open(HKEY_CLASSES_ROOT, registry_path.c_str(), KEY_READ);
|
||||
if (!key.Valid())
|
||||
return false;
|
||||
|
@ -60,25 +60,34 @@ class DeleteFileProgressSink : public IFileOperationProgressSink {
|
|||
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, LPVOID* ppvObj);
|
||||
HRESULT STDMETHODCALLTYPE StartOperations(void);
|
||||
HRESULT STDMETHODCALLTYPE FinishOperations(HRESULT);
|
||||
HRESULT STDMETHODCALLTYPE PreRenameItem(
|
||||
DWORD, IShellItem*, LPCWSTR);
|
||||
HRESULT STDMETHODCALLTYPE PostRenameItem(
|
||||
DWORD, IShellItem*, LPCWSTR, HRESULT, IShellItem*);
|
||||
HRESULT STDMETHODCALLTYPE PreMoveItem(
|
||||
DWORD, IShellItem*, IShellItem*, LPCWSTR);
|
||||
HRESULT STDMETHODCALLTYPE PostMoveItem(
|
||||
DWORD, IShellItem*, IShellItem*, LPCWSTR, HRESULT, IShellItem*);
|
||||
HRESULT STDMETHODCALLTYPE PreCopyItem(
|
||||
DWORD, IShellItem*, IShellItem*, LPCWSTR);
|
||||
HRESULT STDMETHODCALLTYPE PostCopyItem(
|
||||
DWORD, IShellItem*, IShellItem*, LPCWSTR, HRESULT, IShellItem*);
|
||||
HRESULT STDMETHODCALLTYPE PreRenameItem(DWORD, IShellItem*, LPCWSTR);
|
||||
HRESULT STDMETHODCALLTYPE
|
||||
PostRenameItem(DWORD, IShellItem*, LPCWSTR, HRESULT, IShellItem*);
|
||||
HRESULT STDMETHODCALLTYPE PreMoveItem(DWORD,
|
||||
IShellItem*,
|
||||
IShellItem*,
|
||||
LPCWSTR);
|
||||
HRESULT STDMETHODCALLTYPE
|
||||
PostMoveItem(DWORD, IShellItem*, IShellItem*, LPCWSTR, HRESULT, IShellItem*);
|
||||
HRESULT STDMETHODCALLTYPE PreCopyItem(DWORD,
|
||||
IShellItem*,
|
||||
IShellItem*,
|
||||
LPCWSTR);
|
||||
HRESULT STDMETHODCALLTYPE
|
||||
PostCopyItem(DWORD, IShellItem*, IShellItem*, LPCWSTR, HRESULT, IShellItem*);
|
||||
HRESULT STDMETHODCALLTYPE PreDeleteItem(DWORD, IShellItem*);
|
||||
HRESULT STDMETHODCALLTYPE PostDeleteItem(
|
||||
DWORD, IShellItem*, HRESULT, IShellItem*);
|
||||
HRESULT STDMETHODCALLTYPE PreNewItem(
|
||||
DWORD, IShellItem*, LPCWSTR);
|
||||
HRESULT STDMETHODCALLTYPE PostNewItem(
|
||||
DWORD, IShellItem*, LPCWSTR, LPCWSTR, DWORD, HRESULT, IShellItem*);
|
||||
HRESULT STDMETHODCALLTYPE PostDeleteItem(DWORD,
|
||||
IShellItem*,
|
||||
HRESULT,
|
||||
IShellItem*);
|
||||
HRESULT STDMETHODCALLTYPE PreNewItem(DWORD, IShellItem*, LPCWSTR);
|
||||
HRESULT STDMETHODCALLTYPE PostNewItem(DWORD,
|
||||
IShellItem*,
|
||||
LPCWSTR,
|
||||
LPCWSTR,
|
||||
DWORD,
|
||||
HRESULT,
|
||||
IShellItem*);
|
||||
HRESULT STDMETHODCALLTYPE UpdateProgress(UINT, UINT);
|
||||
HRESULT STDMETHODCALLTYPE ResetTimer(void);
|
||||
HRESULT STDMETHODCALLTYPE PauseTimer(void);
|
||||
|
@ -144,43 +153,66 @@ HRESULT DeleteFileProgressSink::PreRenameItem(DWORD, IShellItem*, LPCWSTR) {
|
|||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT DeleteFileProgressSink::PostRenameItem(
|
||||
DWORD, IShellItem*, __RPC__in_string LPCWSTR, HRESULT, IShellItem*) {
|
||||
HRESULT DeleteFileProgressSink::PostRenameItem(DWORD,
|
||||
IShellItem*,
|
||||
__RPC__in_string LPCWSTR,
|
||||
HRESULT,
|
||||
IShellItem*) {
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
HRESULT DeleteFileProgressSink::PreMoveItem(
|
||||
DWORD, IShellItem*, IShellItem*, LPCWSTR) {
|
||||
HRESULT DeleteFileProgressSink::PreMoveItem(DWORD,
|
||||
IShellItem*,
|
||||
IShellItem*,
|
||||
LPCWSTR) {
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
HRESULT DeleteFileProgressSink::PostMoveItem(
|
||||
DWORD, IShellItem*, IShellItem*, LPCWSTR, HRESULT, IShellItem*) {
|
||||
HRESULT DeleteFileProgressSink::PostMoveItem(DWORD,
|
||||
IShellItem*,
|
||||
IShellItem*,
|
||||
LPCWSTR,
|
||||
HRESULT,
|
||||
IShellItem*) {
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
HRESULT DeleteFileProgressSink::PreCopyItem(
|
||||
DWORD, IShellItem*, IShellItem*, LPCWSTR) {
|
||||
HRESULT DeleteFileProgressSink::PreCopyItem(DWORD,
|
||||
IShellItem*,
|
||||
IShellItem*,
|
||||
LPCWSTR) {
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
HRESULT DeleteFileProgressSink::PostCopyItem(
|
||||
DWORD, IShellItem*, IShellItem*, LPCWSTR, HRESULT, IShellItem*) {
|
||||
HRESULT DeleteFileProgressSink::PostCopyItem(DWORD,
|
||||
IShellItem*,
|
||||
IShellItem*,
|
||||
LPCWSTR,
|
||||
HRESULT,
|
||||
IShellItem*) {
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
HRESULT DeleteFileProgressSink::PostDeleteItem(
|
||||
DWORD, IShellItem*, HRESULT, IShellItem*) {
|
||||
HRESULT DeleteFileProgressSink::PostDeleteItem(DWORD,
|
||||
IShellItem*,
|
||||
HRESULT,
|
||||
IShellItem*) {
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT DeleteFileProgressSink::PreNewItem(
|
||||
DWORD dwFlags, IShellItem*, LPCWSTR) {
|
||||
HRESULT DeleteFileProgressSink::PreNewItem(DWORD dwFlags,
|
||||
IShellItem*,
|
||||
LPCWSTR) {
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
HRESULT DeleteFileProgressSink::PostNewItem(
|
||||
DWORD, IShellItem*, LPCWSTR, LPCWSTR, DWORD, HRESULT, IShellItem*) {
|
||||
HRESULT DeleteFileProgressSink::PostNewItem(DWORD,
|
||||
IShellItem*,
|
||||
LPCWSTR,
|
||||
LPCWSTR,
|
||||
DWORD,
|
||||
HRESULT,
|
||||
IShellItem*) {
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
|
@ -214,14 +246,12 @@ bool ShowItemInFolder(const base::FilePath& full_path) {
|
|||
if (dir.empty())
|
||||
return false;
|
||||
|
||||
typedef HRESULT (WINAPI *SHOpenFolderAndSelectItemsFuncPtr)(
|
||||
PCIDLIST_ABSOLUTE pidl_Folder,
|
||||
UINT cidl,
|
||||
PCUITEMID_CHILD_ARRAY pidls,
|
||||
typedef HRESULT(WINAPI * SHOpenFolderAndSelectItemsFuncPtr)(
|
||||
PCIDLIST_ABSOLUTE pidl_Folder, UINT cidl, PCUITEMID_CHILD_ARRAY pidls,
|
||||
DWORD flags);
|
||||
|
||||
static SHOpenFolderAndSelectItemsFuncPtr open_folder_and_select_itemsPtr =
|
||||
NULL;
|
||||
NULL;
|
||||
static bool initialize_open_folder_proc = true;
|
||||
if (initialize_open_folder_proc) {
|
||||
initialize_open_folder_proc = false;
|
||||
|
@ -236,8 +266,8 @@ bool ShowItemInFolder(const base::FilePath& full_path) {
|
|||
return false;
|
||||
}
|
||||
open_folder_and_select_itemsPtr =
|
||||
reinterpret_cast<SHOpenFolderAndSelectItemsFuncPtr>
|
||||
(GetProcAddress(shell32_base, "SHOpenFolderAndSelectItems"));
|
||||
reinterpret_cast<SHOpenFolderAndSelectItemsFuncPtr>(
|
||||
GetProcAddress(shell32_base, "SHOpenFolderAndSelectItems"));
|
||||
}
|
||||
if (!open_folder_and_select_itemsPtr) {
|
||||
return ui::win::OpenFolderViaShell(dir);
|
||||
|
@ -250,21 +280,21 @@ bool ShowItemInFolder(const base::FilePath& full_path) {
|
|||
|
||||
base::win::ScopedCoMem<ITEMIDLIST> dir_item;
|
||||
hr = desktop->ParseDisplayName(NULL, NULL,
|
||||
const_cast<wchar_t *>(dir.value().c_str()),
|
||||
const_cast<wchar_t*>(dir.value().c_str()),
|
||||
NULL, &dir_item, NULL);
|
||||
if (FAILED(hr)) {
|
||||
return ui::win::OpenFolderViaShell(dir);
|
||||
}
|
||||
|
||||
base::win::ScopedCoMem<ITEMIDLIST> file_item;
|
||||
hr = desktop->ParseDisplayName(NULL, NULL,
|
||||
const_cast<wchar_t *>(full_path.value().c_str()),
|
||||
NULL, &file_item, NULL);
|
||||
hr = desktop->ParseDisplayName(
|
||||
NULL, NULL, const_cast<wchar_t*>(full_path.value().c_str()), NULL,
|
||||
&file_item, NULL);
|
||||
if (FAILED(hr)) {
|
||||
return ui::win::OpenFolderViaShell(dir);
|
||||
}
|
||||
|
||||
const ITEMIDLIST* highlight[] = { file_item };
|
||||
const ITEMIDLIST* highlight[] = {file_item};
|
||||
|
||||
hr = (*open_folder_and_select_itemsPtr)(dir_item, arraysize(highlight),
|
||||
highlight, NULL);
|
||||
|
@ -279,13 +309,11 @@ bool ShowItemInFolder(const base::FilePath& full_path) {
|
|||
} else {
|
||||
LPTSTR message = NULL;
|
||||
DWORD message_length = FormatMessage(
|
||||
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
|
||||
0, hr, 0, reinterpret_cast<LPTSTR>(&message), 0, NULL);
|
||||
LOG(WARNING) << " " << __FUNCTION__
|
||||
<< "(): Can't open full_path = \""
|
||||
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, 0, hr, 0,
|
||||
reinterpret_cast<LPTSTR>(&message), 0, NULL);
|
||||
LOG(WARNING) << " " << __FUNCTION__ << "(): Can't open full_path = \""
|
||||
<< full_path.value() << "\""
|
||||
<< " hr = " << hr
|
||||
<< " " << reinterpret_cast<LPTSTR>(&message);
|
||||
<< " hr = " << hr << " " << reinterpret_cast<LPTSTR>(&message);
|
||||
if (message)
|
||||
LocalFree(message);
|
||||
|
||||
|
@ -306,9 +334,9 @@ bool OpenExternal(const base::string16& url, bool activate) {
|
|||
// have been escaped.
|
||||
base::string16 escaped_url = L"\"" + url + L"\"";
|
||||
|
||||
if (reinterpret_cast<ULONG_PTR>(ShellExecuteW(NULL, L"open",
|
||||
escaped_url.c_str(), NULL, NULL,
|
||||
SW_SHOWNORMAL)) <= 32) {
|
||||
if (reinterpret_cast<ULONG_PTR>(ShellExecuteW(
|
||||
NULL, L"open", escaped_url.c_str(), NULL, NULL, SW_SHOWNORMAL)) <=
|
||||
32) {
|
||||
// We fail to execute the call. We could display a message to the user.
|
||||
// TODO(nsylvain): we should also add a dialog to warn on errors. See
|
||||
// bug 1136923.
|
||||
|
@ -317,7 +345,8 @@ bool OpenExternal(const base::string16& url, bool activate) {
|
|||
return true;
|
||||
}
|
||||
|
||||
void OpenExternal(const base::string16& url, bool activate,
|
||||
void OpenExternal(const base::string16& url,
|
||||
bool activate,
|
||||
const OpenExternalCallback& callback) {
|
||||
// TODO(gabriel): Implement async open if callback is specified
|
||||
callback.Run(OpenExternal(url, activate) ? "" : "Failed to open");
|
||||
|
@ -339,19 +368,14 @@ bool MoveItemToTrash(const base::FilePath& path) {
|
|||
if (base::win::GetVersion() >= base::win::VERSION_WIN8) {
|
||||
// Windows 8 introduces the flag RECYCLEONDELETE and deprecates the
|
||||
// ALLOWUNDO in favor of ADDUNDORECORD.
|
||||
if (FAILED(pfo->SetOperationFlags(FOF_NO_UI |
|
||||
FOFX_ADDUNDORECORD |
|
||||
FOF_NOERRORUI |
|
||||
FOF_SILENT |
|
||||
FOFX_SHOWELEVATIONPROMPT |
|
||||
FOFX_RECYCLEONDELETE)))
|
||||
if (FAILED(pfo->SetOperationFlags(
|
||||
FOF_NO_UI | FOFX_ADDUNDORECORD | FOF_NOERRORUI | FOF_SILENT |
|
||||
FOFX_SHOWELEVATIONPROMPT | FOFX_RECYCLEONDELETE)))
|
||||
return false;
|
||||
} else {
|
||||
// For Windows 7 and Vista, RecycleOnDelete is the default behavior.
|
||||
if (FAILED(pfo->SetOperationFlags(FOF_NO_UI |
|
||||
FOF_ALLOWUNDO |
|
||||
FOF_NOERRORUI |
|
||||
FOF_SILENT |
|
||||
if (FAILED(pfo->SetOperationFlags(FOF_NO_UI | FOF_ALLOWUNDO |
|
||||
FOF_NOERRORUI | FOF_SILENT |
|
||||
FOFX_SHOWELEVATIONPROMPT)))
|
||||
return false;
|
||||
}
|
||||
|
@ -359,9 +383,8 @@ bool MoveItemToTrash(const base::FilePath& path) {
|
|||
// Create an IShellItem from the supplied source path.
|
||||
base::win::ScopedComPtr<IShellItem> delete_item;
|
||||
if (FAILED(SHCreateItemFromParsingName(
|
||||
path.value().c_str(),
|
||||
NULL,
|
||||
IID_PPV_ARGS(delete_item.GetAddressOf()))))
|
||||
path.value().c_str(), NULL,
|
||||
IID_PPV_ARGS(delete_item.GetAddressOf()))))
|
||||
return false;
|
||||
|
||||
base::win::ScopedComPtr<IFileOperationProgressSink> delete_sink(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue