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