From 121163f9ca55f1c86ef3b5bfa952719084be4031 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 5 Dec 2013 10:07:51 +0800 Subject: [PATCH] Add conversions between V8 Value and GURL. --- common/v8_conversions.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/common/v8_conversions.h b/common/v8_conversions.h index 57d69c2daa..55b770996a 100644 --- a/common/v8_conversions.h +++ b/common/v8_conversions.h @@ -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(*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 ToV8Value(const string16& s) { return v8::String::New(reinterpret_cast(s.data()), s.size()); } +inline v8::Handle ToV8Value(const GURL& url) { + return ToV8Value(url.spec()); +} + inline v8::Handle 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(v8::Handle value) { return V8ValueCanBeConvertedTo(value); } +template<> inline +bool V8ValueCanBeConvertedTo(v8::Handle value) { + return V8ValueCanBeConvertedTo(value); +} + template<> inline bool V8ValueCanBeConvertedTo(v8::Handle value) { return V8ValueCanBeConvertedTo(value);