Use native_mate to simplify dialog api.
This commit is contained in:
parent
6e2bf824f0
commit
aa1efe70e2
10 changed files with 189 additions and 143 deletions
|
@ -28,7 +28,7 @@ int32_t IDWeakMap::Add(v8::Isolate* isolate, v8::Handle<v8::Object> object) {
|
|||
object->SetHiddenValue(mate::StringToV8(isolate, "IDWeakMapKey"),
|
||||
mate::Converter<int32_t>::ToV8(isolate, key));
|
||||
|
||||
map_[key] = new RefCountedPersistent<v8::Object>(object);
|
||||
map_[key] = new mate::RefCountedPersistent<v8::Object>(object);
|
||||
map_[key]->MakeWeak(this, WeakCallback);
|
||||
return key;
|
||||
}
|
||||
|
|
|
@ -9,8 +9,8 @@
|
|||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#include "atom/common/v8/scoped_persistent.h"
|
||||
#include "base/basictypes.h"
|
||||
#include "native_mate/scoped_persistent.h"
|
||||
#include "native_mate/wrappable.h"
|
||||
|
||||
namespace atom {
|
||||
|
@ -40,6 +40,9 @@ class IDWeakMap : public mate::Wrappable {
|
|||
IDWeakMap* self);
|
||||
|
||||
int32_t next_id_;
|
||||
|
||||
typedef scoped_refptr<mate::RefCountedPersistent<v8::Object> >
|
||||
RefCountedV8Object;
|
||||
std::map<int32_t, RefCountedV8Object> map_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(IDWeakMap);
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include <string>
|
||||
|
||||
#include "atom/common/platform_util.h"
|
||||
#include "base/files/file_path.h"
|
||||
#include "atom/common/v8_converters/file_path_converter.h"
|
||||
#include "native_mate/object_template_builder.h"
|
||||
#include "url/gurl.h"
|
||||
|
||||
|
@ -28,21 +28,6 @@ struct Converter<GURL> {
|
|||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct Converter<base::FilePath> {
|
||||
static bool FromV8(v8::Isolate* isolate,
|
||||
v8::Handle<v8::Value> val,
|
||||
base::FilePath* out) {
|
||||
std::string path;
|
||||
if (Converter<std::string>::FromV8(isolate, val, &path)) {
|
||||
*out = base::FilePath::FromUTF8Unsafe(path);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace mate
|
||||
|
||||
namespace {
|
||||
|
|
34
atom/common/v8_converters/file_path_converter.h
Normal file
34
atom/common/v8_converters/file_path_converter.h
Normal file
|
@ -0,0 +1,34 @@
|
|||
// Copyright (c) 2014 GitHub, Inc. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef ATOM_COMMON_V8_CONVERTERS_FILE_PATH_CONVERTER_H_
|
||||
#define ATOM_COMMON_V8_CONVERTERS_FILE_PATH_CONVERTER_H_
|
||||
|
||||
#include "atom/common/v8_converters/string16_converter.h"
|
||||
#include "base/files/file_path.h"
|
||||
|
||||
namespace mate {
|
||||
|
||||
template<>
|
||||
struct Converter<base::FilePath> {
|
||||
static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate,
|
||||
const base::FilePath& val) {
|
||||
return Converter<base::FilePath::StringType>::ToV8(isolate, val.value());
|
||||
}
|
||||
static bool FromV8(v8::Isolate* isolate,
|
||||
v8::Handle<v8::Value> val,
|
||||
base::FilePath* out) {
|
||||
std::string path;
|
||||
if (Converter<std::string>::FromV8(isolate, val, &path)) {
|
||||
*out = base::FilePath::FromUTF8Unsafe(path);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace mate
|
||||
|
||||
#endif // ATOM_COMMON_V8_CONVERTERS_FILE_PATH_CONVERTER_H_
|
31
atom/common/v8_converters/string16_converter.h
Normal file
31
atom/common/v8_converters/string16_converter.h
Normal file
|
@ -0,0 +1,31 @@
|
|||
// Copyright (c) 2014 GitHub, Inc. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef ATOM_COMMON_V8_CONVERTERS_STRING16_CONVERTER_H_
|
||||
#define ATOM_COMMON_V8_CONVERTERS_STRING16_CONVERTER_H_
|
||||
|
||||
#include "base/strings/string16.h"
|
||||
#include "native_mate/converter.h"
|
||||
|
||||
namespace mate {
|
||||
|
||||
template<>
|
||||
struct Converter<string16> {
|
||||
static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate,
|
||||
const string16& val) {
|
||||
return v8::String::New(reinterpret_cast<const uint16_t*>(val.data()),
|
||||
val.size());
|
||||
}
|
||||
static bool FromV8(v8::Isolate* isolate,
|
||||
v8::Handle<v8::Value> val,
|
||||
string16* out) {
|
||||
v8::String::Value s(val);
|
||||
*out = string16(reinterpret_cast<const char16*>(*s), s.length());
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace mate
|
||||
|
||||
#endif // ATOM_COMMON_V8_CONVERTERS_STRING16_CONVERTER_H_
|
Loading…
Add table
Add a link
Reference in a new issue