| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/renderer/activity_log_converter_strategy.h" | 5 #include "extensions/renderer/activity_log_converter_strategy.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "v8/include/v8.h" | 9 #include "v8/include/v8.h" |
| 10 | 10 |
| 11 namespace extensions { | 11 namespace extensions { |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 // Summarize a V8 value. This performs a shallow conversion in all cases, and | 15 // Summarize a V8 value. This performs a shallow conversion in all cases, and |
| 16 // returns only a string with a description of the value (e.g., | 16 // returns only a string with a description of the value (e.g., |
| 17 // "[HTMLElement]"). | 17 // "[HTMLElement]"). |
| 18 scoped_ptr<base::Value> SummarizeV8Value(v8::Isolate* isolate, | 18 scoped_ptr<base::Value> SummarizeV8Value(v8::Isolate* isolate, |
| 19 v8::Handle<v8::Object> object) { | 19 v8::Local<v8::Object> object) { |
| 20 v8::TryCatch try_catch; | 20 v8::TryCatch try_catch; |
| 21 v8::Isolate::DisallowJavascriptExecutionScope scope( | 21 v8::Isolate::DisallowJavascriptExecutionScope scope( |
| 22 isolate, v8::Isolate::DisallowJavascriptExecutionScope::THROW_ON_FAILURE); | 22 isolate, v8::Isolate::DisallowJavascriptExecutionScope::THROW_ON_FAILURE); |
| 23 v8::Local<v8::String> name = v8::String::NewFromUtf8(isolate, "["); | 23 v8::Local<v8::String> name = v8::String::NewFromUtf8(isolate, "["); |
| 24 if (object->IsFunction()) { | 24 if (object->IsFunction()) { |
| 25 name = | 25 name = |
| 26 v8::String::Concat(name, v8::String::NewFromUtf8(isolate, "Function")); | 26 v8::String::Concat(name, v8::String::NewFromUtf8(isolate, "Function")); |
| 27 v8::Local<v8::Value> fname = | 27 v8::Local<v8::Value> fname = |
| 28 v8::Handle<v8::Function>::Cast(object)->GetName(); | 28 v8::Local<v8::Function>::Cast(object)->GetName(); |
| 29 if (fname->IsString() && v8::Handle<v8::String>::Cast(fname)->Length()) { | 29 if (fname->IsString() && v8::Local<v8::String>::Cast(fname)->Length()) { |
| 30 name = v8::String::Concat(name, v8::String::NewFromUtf8(isolate, " ")); | 30 name = v8::String::Concat(name, v8::String::NewFromUtf8(isolate, " ")); |
| 31 name = v8::String::Concat(name, v8::Handle<v8::String>::Cast(fname)); | 31 name = v8::String::Concat(name, v8::Local<v8::String>::Cast(fname)); |
| 32 name = v8::String::Concat(name, v8::String::NewFromUtf8(isolate, "()")); | 32 name = v8::String::Concat(name, v8::String::NewFromUtf8(isolate, "()")); |
| 33 } | 33 } |
| 34 } else { | 34 } else { |
| 35 name = v8::String::Concat(name, object->GetConstructorName()); | 35 name = v8::String::Concat(name, object->GetConstructorName()); |
| 36 } | 36 } |
| 37 name = v8::String::Concat(name, v8::String::NewFromUtf8(isolate, "]")); | 37 name = v8::String::Concat(name, v8::String::NewFromUtf8(isolate, "]")); |
| 38 | 38 |
| 39 if (try_catch.HasCaught()) { | 39 if (try_catch.HasCaught()) { |
| 40 return scoped_ptr<base::Value>( | 40 return scoped_ptr<base::Value>( |
| 41 new base::StringValue("[JS Execution Exception]")); | 41 new base::StringValue("[JS Execution Exception]")); |
| 42 } | 42 } |
| 43 | 43 |
| 44 return scoped_ptr<base::Value>( | 44 return scoped_ptr<base::Value>( |
| 45 new base::StringValue(std::string(*v8::String::Utf8Value(name)))); | 45 new base::StringValue(std::string(*v8::String::Utf8Value(name)))); |
| 46 } | 46 } |
| 47 | 47 |
| 48 } // namespace | 48 } // namespace |
| 49 | 49 |
| 50 ActivityLogConverterStrategy::ActivityLogConverterStrategy() {} | 50 ActivityLogConverterStrategy::ActivityLogConverterStrategy() {} |
| 51 | 51 |
| 52 ActivityLogConverterStrategy::~ActivityLogConverterStrategy() {} | 52 ActivityLogConverterStrategy::~ActivityLogConverterStrategy() {} |
| 53 | 53 |
| 54 bool ActivityLogConverterStrategy::FromV8Object( | 54 bool ActivityLogConverterStrategy::FromV8Object( |
| 55 v8::Handle<v8::Object> value, | 55 v8::Local<v8::Object> value, |
| 56 base::Value** out, | 56 base::Value** out, |
| 57 v8::Isolate* isolate, | 57 v8::Isolate* isolate, |
| 58 const FromV8ValueCallback& callback) const { | 58 const FromV8ValueCallback& callback) const { |
| 59 return FromV8Internal(value, out, isolate, callback); | 59 return FromV8Internal(value, out, isolate, callback); |
| 60 } | 60 } |
| 61 | 61 |
| 62 bool ActivityLogConverterStrategy::FromV8Array( | 62 bool ActivityLogConverterStrategy::FromV8Array( |
| 63 v8::Handle<v8::Array> value, | 63 v8::Local<v8::Array> value, |
| 64 base::Value** out, | 64 base::Value** out, |
| 65 v8::Isolate* isolate, | 65 v8::Isolate* isolate, |
| 66 const FromV8ValueCallback& callback) const { | 66 const FromV8ValueCallback& callback) const { |
| 67 return FromV8Internal(value, out, isolate, callback); | 67 return FromV8Internal(value, out, isolate, callback); |
| 68 } | 68 } |
| 69 | 69 |
| 70 bool ActivityLogConverterStrategy::FromV8Internal( | 70 bool ActivityLogConverterStrategy::FromV8Internal( |
| 71 v8::Handle<v8::Object> value, | 71 v8::Local<v8::Object> value, |
| 72 base::Value** out, | 72 base::Value** out, |
| 73 v8::Isolate* isolate, | 73 v8::Isolate* isolate, |
| 74 const FromV8ValueCallback& callback) const { | 74 const FromV8ValueCallback& callback) const { |
| 75 scoped_ptr<base::Value> parsed_value; | 75 scoped_ptr<base::Value> parsed_value; |
| 76 parsed_value = SummarizeV8Value(isolate, value); | 76 parsed_value = SummarizeV8Value(isolate, value); |
| 77 *out = parsed_value.release(); | 77 *out = parsed_value.release(); |
| 78 | 78 |
| 79 return true; | 79 return true; |
| 80 } | 80 } |
| 81 | 81 |
| 82 } // namespace extensions | 82 } // namespace extensions |
| OLD | NEW |