OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/v8_value_converter_impl.h" | 5 #include "content/renderer/v8_value_converter_impl.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/float_util.h" | 9 #include "base/float_util.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 | 79 |
80 V8ValueConverter* V8ValueConverter::create() { | 80 V8ValueConverter* V8ValueConverter::create() { |
81 return new V8ValueConverterImpl(); | 81 return new V8ValueConverterImpl(); |
82 } | 82 } |
83 | 83 |
84 V8ValueConverterImpl::V8ValueConverterImpl() | 84 V8ValueConverterImpl::V8ValueConverterImpl() |
85 : date_allowed_(false), | 85 : date_allowed_(false), |
86 reg_exp_allowed_(false), | 86 reg_exp_allowed_(false), |
87 function_allowed_(false), | 87 function_allowed_(false), |
88 strip_null_from_objects_(false), | 88 strip_null_from_objects_(false), |
89 avoid_identity_hash_for_testing_(false) {} | 89 avoid_identity_hash_for_testing_(false), |
| 90 strategy_(NULL) {} |
90 | 91 |
91 void V8ValueConverterImpl::SetDateAllowed(bool val) { | 92 void V8ValueConverterImpl::SetDateAllowed(bool val) { |
92 date_allowed_ = val; | 93 date_allowed_ = val; |
93 } | 94 } |
94 | 95 |
95 void V8ValueConverterImpl::SetRegExpAllowed(bool val) { | 96 void V8ValueConverterImpl::SetRegExpAllowed(bool val) { |
96 reg_exp_allowed_ = val; | 97 reg_exp_allowed_ = val; |
97 } | 98 } |
98 | 99 |
99 void V8ValueConverterImpl::SetFunctionAllowed(bool val) { | 100 void V8ValueConverterImpl::SetFunctionAllowed(bool val) { |
100 function_allowed_ = val; | 101 function_allowed_ = val; |
101 } | 102 } |
102 | 103 |
103 void V8ValueConverterImpl::SetStripNullFromObjects(bool val) { | 104 void V8ValueConverterImpl::SetStripNullFromObjects(bool val) { |
104 strip_null_from_objects_ = val; | 105 strip_null_from_objects_ = val; |
105 } | 106 } |
106 | 107 |
| 108 void V8ValueConverterImpl::SetStrategy(V8ValueConverterStrategy* strategy) { |
| 109 strategy_ = strategy; |
| 110 } |
| 111 |
107 v8::Handle<v8::Value> V8ValueConverterImpl::ToV8Value( | 112 v8::Handle<v8::Value> V8ValueConverterImpl::ToV8Value( |
108 const base::Value* value, v8::Handle<v8::Context> context) const { | 113 const base::Value* value, v8::Handle<v8::Context> context) const { |
109 v8::Context::Scope context_scope(context); | 114 v8::Context::Scope context_scope(context); |
110 v8::HandleScope handle_scope; | 115 v8::HandleScope handle_scope; |
| 116 if (strategy_) { |
| 117 v8::Handle<v8::Value> out; |
| 118 if (strategy_->ToV8Value(value, &out)) { |
| 119 return handle_scope.Close(out); |
| 120 } |
| 121 } |
111 return handle_scope.Close(ToV8ValueImpl(value)); | 122 return handle_scope.Close(ToV8ValueImpl(value)); |
112 } | 123 } |
113 | 124 |
114 Value* V8ValueConverterImpl::FromV8Value( | 125 Value* V8ValueConverterImpl::FromV8Value( |
115 v8::Handle<v8::Value> val, | 126 v8::Handle<v8::Value> val, |
116 v8::Handle<v8::Context> context) const { | 127 v8::Handle<v8::Context> context) const { |
117 v8::Context::Scope context_scope(context); | 128 v8::Context::Scope context_scope(context); |
118 v8::HandleScope handle_scope; | 129 v8::HandleScope handle_scope; |
| 130 if (strategy_) { |
| 131 Value* out = NULL; |
| 132 if (strategy_->FromV8Value(val, &out)) |
| 133 return out; |
| 134 } |
119 FromV8ValueState state(avoid_identity_hash_for_testing_); | 135 FromV8ValueState state(avoid_identity_hash_for_testing_); |
120 return FromV8ValueImpl(val, &state); | 136 return FromV8ValueImpl(val, &state); |
121 } | 137 } |
122 | 138 |
123 v8::Handle<v8::Value> V8ValueConverterImpl::ToV8ValueImpl( | 139 v8::Handle<v8::Value> V8ValueConverterImpl::ToV8ValueImpl( |
124 const base::Value* value) const { | 140 const base::Value* value) const { |
125 CHECK(value); | 141 CHECK(value); |
126 switch (value->GetType()) { | 142 switch (value->GetType()) { |
127 case base::Value::TYPE_NULL: | 143 case base::Value::TYPE_NULL: |
128 return v8::Null(); | 144 return v8::Null(); |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 continue; | 435 continue; |
420 | 436 |
421 result->SetWithoutPathExpansion(std::string(*name_utf8, name_utf8.length()), | 437 result->SetWithoutPathExpansion(std::string(*name_utf8, name_utf8.length()), |
422 child.release()); | 438 child.release()); |
423 } | 439 } |
424 | 440 |
425 return result.release(); | 441 return result.release(); |
426 } | 442 } |
427 | 443 |
428 } // namespace content | 444 } // namespace content |
OLD | NEW |