Add conversions between V8 Value and GURL.
This commit is contained in:
parent
7cffbc8a1a
commit
121163f9ca
1 changed files with 15 additions and 0 deletions
|
@ -12,6 +12,7 @@
|
||||||
#include "base/files/file_path.h"
|
#include "base/files/file_path.h"
|
||||||
#include "base/string16.h"
|
#include "base/string16.h"
|
||||||
#include "browser/api/atom_api_window.h"
|
#include "browser/api/atom_api_window.h"
|
||||||
|
#include "googleurl/src/gurl.h"
|
||||||
#include "ui/gfx/rect.h"
|
#include "ui/gfx/rect.h"
|
||||||
#include "v8/include/v8.h"
|
#include "v8/include/v8.h"
|
||||||
|
|
||||||
|
@ -36,6 +37,11 @@ struct FromV8Value {
|
||||||
return string16(reinterpret_cast<const char16*>(*s), s.length());
|
return string16(reinterpret_cast<const char16*>(*s), s.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
operator GURL() {
|
||||||
|
std::string str = FromV8Value(value_);
|
||||||
|
return GURL(str);
|
||||||
|
}
|
||||||
|
|
||||||
operator base::FilePath() {
|
operator base::FilePath() {
|
||||||
return base::FilePath::FromUTF8Unsafe(FromV8Value(value_));
|
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());
|
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) {
|
inline v8::Handle<v8::Value> ToV8Value(const base::FilePath& path) {
|
||||||
std::string path_string(path.AsUTF8Unsafe());
|
std::string path_string(path.AsUTF8Unsafe());
|
||||||
return v8::String::New(path_string.data(), path_string.size());
|
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);
|
return V8ValueCanBeConvertedTo<std::string>(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<> inline
|
||||||
|
bool V8ValueCanBeConvertedTo<GURL>(v8::Handle<v8::Value> value) {
|
||||||
|
return V8ValueCanBeConvertedTo<std::string>(value);
|
||||||
|
}
|
||||||
|
|
||||||
template<> inline
|
template<> inline
|
||||||
bool V8ValueCanBeConvertedTo<base::FilePath>(v8::Handle<v8::Value> value) {
|
bool V8ValueCanBeConvertedTo<base::FilePath>(v8::Handle<v8::Value> value) {
|
||||||
return V8ValueCanBeConvertedTo<std::string>(value);
|
return V8ValueCanBeConvertedTo<std::string>(value);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue