зеркало из https://github.com/electron/electron.git
Add conversions between V8 Value and GURL.
This commit is contained in:
Родитель
7cffbc8a1a
Коммит
121163f9ca
|
@ -12,6 +12,7 @@
|
|||
#include "base/files/file_path.h"
|
||||
#include "base/string16.h"
|
||||
#include "browser/api/atom_api_window.h"
|
||||
#include "googleurl/src/gurl.h"
|
||||
#include "ui/gfx/rect.h"
|
||||
#include "v8/include/v8.h"
|
||||
|
||||
|
@ -36,6 +37,11 @@ struct FromV8Value {
|
|||
return string16(reinterpret_cast<const char16*>(*s), s.length());
|
||||
}
|
||||
|
||||
operator GURL() {
|
||||
std::string str = FromV8Value(value_);
|
||||
return GURL(str);
|
||||
}
|
||||
|
||||
operator base::FilePath() {
|
||||
return base::FilePath::FromUTF8Unsafe(FromV8Value(value_));
|
||||
}
|
||||
|
@ -116,6 +122,10 @@ inline v8::Handle<v8::Value> ToV8Value(const string16& s) {
|
|||
return v8::String::New(reinterpret_cast<const uint16_t*>(s.data()), s.size());
|
||||
}
|
||||
|
||||
inline v8::Handle<v8::Value> ToV8Value(const GURL& url) {
|
||||
return ToV8Value(url.spec());
|
||||
}
|
||||
|
||||
inline v8::Handle<v8::Value> ToV8Value(const base::FilePath& path) {
|
||||
std::string path_string(path.AsUTF8Unsafe());
|
||||
return v8::String::New(path_string.data(), path_string.size());
|
||||
|
@ -159,6 +169,11 @@ bool V8ValueCanBeConvertedTo<string16>(v8::Handle<v8::Value> value) {
|
|||
return V8ValueCanBeConvertedTo<std::string>(value);
|
||||
}
|
||||
|
||||
template<> inline
|
||||
bool V8ValueCanBeConvertedTo<GURL>(v8::Handle<v8::Value> value) {
|
||||
return V8ValueCanBeConvertedTo<std::string>(value);
|
||||
}
|
||||
|
||||
template<> inline
|
||||
bool V8ValueCanBeConvertedTo<base::FilePath>(v8::Handle<v8::Value> value) {
|
||||
return V8ValueCanBeConvertedTo<std::string>(value);
|
||||
|
|
Загрузка…
Ссылка в новой задаче