summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/renderer/extensions/send_request_natives.cc1
-rw-r--r--content/public/renderer/v8_value_converter.h11
-rw-r--r--content/renderer/render_view_impl.cc4
-rw-r--r--content/renderer/v8_value_converter_impl.cc36
-rw-r--r--content/renderer/v8_value_converter_impl.h23
-rw-r--r--content/renderer/v8_value_converter_impl_unittest.cc8
6 files changed, 57 insertions, 26 deletions
diff --git a/chrome/renderer/extensions/send_request_natives.cc b/chrome/renderer/extensions/send_request_natives.cc
index 17e0ba9..5bf48e5 100644
--- a/chrome/renderer/extensions/send_request_natives.cc
+++ b/chrome/renderer/extensions/send_request_natives.cc
@@ -41,6 +41,7 @@ v8::Handle<v8::Value> SendRequestNatives::StartRequest(
bool for_io_thread = args[4]->BooleanValue();
scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create());
+ converter->SetUndefinedAllowed(true); // Allow passing optional values.
scoped_ptr<Value> value_args(
converter->FromV8Value(args[1], v8::Context::GetCurrent()));
if (!value_args.get() || !value_args->IsType(Value::TYPE_LIST)) {
diff --git a/content/public/renderer/v8_value_converter.h b/content/public/renderer/v8_value_converter.h
index 6e785c1..bed8cdb 100644
--- a/content/public/renderer/v8_value_converter.h
+++ b/content/public/renderer/v8_value_converter.h
@@ -28,6 +28,17 @@ class CONTENT_EXPORT V8ValueConverter {
virtual ~V8ValueConverter() {}
+ // Use the following setters to support additional types other than the
+ // default ones.
+ virtual bool GetUndefinedAllowed() const = 0;
+ virtual void SetUndefinedAllowed(bool val) = 0;
+
+ virtual bool GetDateAllowed() const = 0;
+ virtual void SetDateAllowed(bool val) = 0;
+
+ virtual bool GetRegexpAllowed() const = 0;
+ virtual void SetRegexpAllowed(bool val) = 0;
+
// Converts Value to v8::Value. Unsupported types are replaced with null.
// If an array or object throws while setting a value, that property or item
// is skipped, leaving a hole in the case of arrays.
diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc
index 58cdf35..06a4946 100644
--- a/content/renderer/render_view_impl.cc
+++ b/content/renderer/render_view_impl.cc
@@ -3676,8 +3676,8 @@ void RenderViewImpl::EvaluateScript(const string16& frame_xpath,
v8::Local<v8::Context> context = web_frame->mainWorldScriptContext();
v8::Context::Scope context_scope(context);
V8ValueConverterImpl converter;
- converter.set_allow_date(true);
- converter.set_allow_regexp(true);
+ converter.SetDateAllowed(true);
+ converter.SetRegexpAllowed(true);
list.Set(0, converter.FromV8Value(result, context));
} else {
list.Set(0, Value::CreateNullValue());
diff --git a/content/renderer/v8_value_converter_impl.cc b/content/renderer/v8_value_converter_impl.cc
index c457377..9161196 100644
--- a/content/renderer/v8_value_converter_impl.cc
+++ b/content/renderer/v8_value_converter_impl.cc
@@ -29,9 +29,33 @@ V8ValueConverter* V8ValueConverter::create() {
}
V8ValueConverterImpl::V8ValueConverterImpl()
- : allow_undefined_(false),
- allow_date_(false),
- allow_regexp_(false) {
+ : undefined_allowed_(false),
+ date_allowed_(false),
+ regexp_allowed_(false) {
+}
+
+bool V8ValueConverterImpl::GetUndefinedAllowed() const {
+ return undefined_allowed_;
+}
+
+void V8ValueConverterImpl::SetUndefinedAllowed(bool val) {
+ undefined_allowed_ = val;
+}
+
+bool V8ValueConverterImpl::GetDateAllowed() const {
+ return date_allowed_;
+}
+
+void V8ValueConverterImpl::SetDateAllowed(bool val) {
+ date_allowed_ = val;
+}
+
+bool V8ValueConverterImpl::GetRegexpAllowed() const {
+ return regexp_allowed_;
+}
+
+void V8ValueConverterImpl::SetRegexpAllowed(bool val) {
+ regexp_allowed_ = val;
}
v8::Handle<v8::Value> V8ValueConverterImpl::ToV8Value(
@@ -167,15 +191,15 @@ Value* V8ValueConverterImpl::FromV8ValueImpl(v8::Handle<v8::Value> val) const {
return Value::CreateStringValue(std::string(*utf8, utf8.length()));
}
- if (allow_undefined_ && val->IsUndefined())
+ if (undefined_allowed_ && val->IsUndefined())
return Value::CreateNullValue();
- if (allow_date_ && val->IsDate()) {
+ if (date_allowed_ && val->IsDate()) {
v8::Date* date = v8::Date::Cast(*val);
return Value::CreateDoubleValue(date->NumberValue() / 1000.0);
}
- if (allow_regexp_ && val->IsRegExp()) {
+ if (regexp_allowed_ && val->IsRegExp()) {
return Value::CreateStringValue(
*v8::String::Utf8Value(val->ToString()));
}
diff --git a/content/renderer/v8_value_converter_impl.h b/content/renderer/v8_value_converter_impl.h
index c43da46..7f9baea 100644
--- a/content/renderer/v8_value_converter_impl.h
+++ b/content/renderer/v8_value_converter_impl.h
@@ -20,18 +20,13 @@ class CONTENT_EXPORT V8ValueConverterImpl : public content::V8ValueConverter {
public:
V8ValueConverterImpl();
- // Use the following setters to support additional types other than the
- // default ones.
- bool allow_undefined() const { return allow_undefined_; }
- void set_allow_undefined(bool val) { allow_undefined_ = val; }
-
- bool allow_date() const { return allow_date_; }
- void set_allow_date(bool val) { allow_date_ = val; }
-
- bool allow_regexp() const { return allow_regexp_; }
- void set_allow_regexp(bool val) { allow_regexp_ = val; }
-
// V8ValueConverter implementation.
+ virtual bool GetUndefinedAllowed() const OVERRIDE;
+ virtual void SetUndefinedAllowed(bool val) OVERRIDE;
+ virtual bool GetDateAllowed() const OVERRIDE;
+ virtual void SetDateAllowed(bool val) OVERRIDE;
+ virtual bool GetRegexpAllowed() const OVERRIDE;
+ virtual void SetRegexpAllowed(bool val) OVERRIDE;
virtual v8::Handle<v8::Value> ToV8Value(
const base::Value* value,
v8::Handle<v8::Context> context) const OVERRIDE;
@@ -57,13 +52,13 @@ class CONTENT_EXPORT V8ValueConverterImpl : public content::V8ValueConverter {
base::DictionaryValue* FromV8Object(v8::Handle<v8::Object> object) const;
// If true, we will convert undefined JavaScript values to null.
- bool allow_undefined_;
+ bool undefined_allowed_;
// If true, we will convert Date JavaScript objects to doubles.
- bool allow_date_;
+ bool date_allowed_;
// If true, we will convet RegExp JavaScript objects to string.
- bool allow_regexp_;
+ bool regexp_allowed_;
};
#endif // CONTENT_RENDERER_V8_VALUE_CONVERTER_IMPL_H_
diff --git a/content/renderer/v8_value_converter_impl_unittest.cc b/content/renderer/v8_value_converter_impl_unittest.cc
index 44b4712..79f6105 100644
--- a/content/renderer/v8_value_converter_impl_unittest.cc
+++ b/content/renderer/v8_value_converter_impl_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -293,14 +293,14 @@ TEST_F(V8ValueConverterImplTest, WeirdTypes) {
TestWeirdType(converter, v8::Date::New(1000), Value::TYPE_DICTIONARY, NULL);
TestWeirdType(converter, regex, Value::TYPE_DICTIONARY, NULL);
- converter.set_allow_undefined(true);
+ converter.SetUndefinedAllowed(true);
TestWeirdType(converter, v8::Undefined(), Value::TYPE_NULL, NULL);
- converter.set_allow_date(true);
+ converter.SetDateAllowed(true);
TestWeirdType(converter, v8::Date::New(1000), Value::TYPE_DOUBLE,
Value::CreateDoubleValue(1));
- converter.set_allow_regexp(true);
+ converter.SetRegexpAllowed(true);
TestWeirdType(converter, regex, Value::TYPE_STRING,
Value::CreateStringValue("/./"));
}