Chromium Code Reviews| 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(Strategy* 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; |
| 111 return handle_scope.Close(ToV8ValueImpl(value)); | 116 return handle_scope.Close(ToV8ValueImpl(value)); |
| 112 } | 117 } |
| 113 | 118 |
| 114 Value* V8ValueConverterImpl::FromV8Value( | 119 Value* V8ValueConverterImpl::FromV8Value( |
| 115 v8::Handle<v8::Value> val, | 120 v8::Handle<v8::Value> val, |
| 116 v8::Handle<v8::Context> context) const { | 121 v8::Handle<v8::Context> context) const { |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 287 | 292 |
| 288 LOG(ERROR) << "Unexpected v8 value type encountered."; | 293 LOG(ERROR) << "Unexpected v8 value type encountered."; |
| 289 return NULL; | 294 return NULL; |
| 290 } | 295 } |
| 291 | 296 |
| 292 base::Value* V8ValueConverterImpl::FromV8Array( | 297 base::Value* V8ValueConverterImpl::FromV8Array( |
| 293 v8::Handle<v8::Array> val, | 298 v8::Handle<v8::Array> val, |
| 294 FromV8ValueState* state) const { | 299 FromV8ValueState* state) const { |
| 295 if (!state->UpdateAndCheckUniqueness(val)) | 300 if (!state->UpdateAndCheckUniqueness(val)) |
| 296 return base::Value::CreateNullValue(); | 301 return base::Value::CreateNullValue(); |
| 302 if (strategy_) { | |
| 303 Value* out = NULL; | |
| 304 if (strategy_->FromV8Array(val, &out)) | |
| 305 return out; | |
| 306 } | |
|
not at google - send to devlin
2013/08/07 22:07:56
I think the context scope stuff below might actual
pmarch
2013/08/08 00:53:07
Done.
| |
| 297 | 307 |
| 298 scoped_ptr<v8::Context::Scope> scope; | 308 scoped_ptr<v8::Context::Scope> scope; |
| 299 // If val was created in a different context than our current one, change to | 309 // If val was created in a different context than our current one, change to |
| 300 // that context, but change back after val is converted. | 310 // that context, but change back after val is converted. |
| 301 if (!val->CreationContext().IsEmpty() && | 311 if (!val->CreationContext().IsEmpty() && |
| 302 val->CreationContext() != v8::Context::GetCurrent()) | 312 val->CreationContext() != v8::Context::GetCurrent()) |
| 303 scope.reset(new v8::Context::Scope(val->CreationContext())); | 313 scope.reset(new v8::Context::Scope(val->CreationContext())); |
| 304 | 314 |
| 305 base::ListValue* result = new base::ListValue(); | 315 base::ListValue* result = new base::ListValue(); |
| 306 | 316 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 350 return base::BinaryValue::CreateWithCopiedBuffer(data, length); | 360 return base::BinaryValue::CreateWithCopiedBuffer(data, length); |
| 351 else | 361 else |
| 352 return NULL; | 362 return NULL; |
| 353 } | 363 } |
| 354 | 364 |
| 355 base::Value* V8ValueConverterImpl::FromV8Object( | 365 base::Value* V8ValueConverterImpl::FromV8Object( |
| 356 v8::Handle<v8::Object> val, | 366 v8::Handle<v8::Object> val, |
| 357 FromV8ValueState* state) const { | 367 FromV8ValueState* state) const { |
| 358 if (!state->UpdateAndCheckUniqueness(val)) | 368 if (!state->UpdateAndCheckUniqueness(val)) |
| 359 return base::Value::CreateNullValue(); | 369 return base::Value::CreateNullValue(); |
| 370 if (strategy_) { | |
| 371 Value* out = NULL; | |
| 372 if (strategy_->FromV8Object(val, &out)) | |
| 373 return out; | |
| 374 } | |
|
not at google - send to devlin
2013/08/07 22:07:56
likewise
pmarch
2013/08/08 00:53:07
Done.
| |
| 360 scoped_ptr<v8::Context::Scope> scope; | 375 scoped_ptr<v8::Context::Scope> scope; |
| 361 // If val was created in a different context than our current one, change to | 376 // If val was created in a different context than our current one, change to |
| 362 // that context, but change back after val is converted. | 377 // that context, but change back after val is converted. |
| 363 if (!val->CreationContext().IsEmpty() && | 378 if (!val->CreationContext().IsEmpty() && |
| 364 val->CreationContext() != v8::Context::GetCurrent()) | 379 val->CreationContext() != v8::Context::GetCurrent()) |
| 365 scope.reset(new v8::Context::Scope(val->CreationContext())); | 380 scope.reset(new v8::Context::Scope(val->CreationContext())); |
| 366 | 381 |
| 367 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue()); | 382 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue()); |
| 368 v8::Handle<v8::Array> property_names(val->GetOwnPropertyNames()); | 383 v8::Handle<v8::Array> property_names(val->GetOwnPropertyNames()); |
| 369 | 384 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 419 continue; | 434 continue; |
| 420 | 435 |
| 421 result->SetWithoutPathExpansion(std::string(*name_utf8, name_utf8.length()), | 436 result->SetWithoutPathExpansion(std::string(*name_utf8, name_utf8.length()), |
| 422 child.release()); | 437 child.release()); |
| 423 } | 438 } |
| 424 | 439 |
| 425 return result.release(); | 440 return result.release(); |
| 426 } | 441 } |
| 427 | 442 |
| 428 } // namespace content | 443 } // namespace content |
| OLD | NEW |