OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/renderer/extensions/activity_log_converter_strategy.h" | |
6 #include "base/values.h" | |
7 | |
8 namespace extensions { | |
9 | |
10 bool ActivityLogConverterStrategy::FromV8Object(v8::Handle<v8::Object> value, | |
11 base::Value** out) const { | |
12 return FromV8ObjectInternal(value, out); | |
13 } | |
14 | |
15 bool ActivityLogConverterStrategy::FromV8Array(v8::Handle<v8::Array> value, | |
16 base::Value** out) const { | |
17 return FromV8ObjectInternal(value, out); | |
18 } | |
19 | |
20 bool ActivityLogConverterStrategy::FromV8ObjectInternal( | |
21 v8::Handle<v8::Object> value, | |
22 base::Value** out) const { | |
23 | |
24 // Handle JSObject. | |
25 // We cannot use value->Get(key/index) as there may be a getter method, | |
26 // accessor, interceptor/handler, or access check callback set on the | |
27 // property. If that it is the case, any of those may invoke JS code that | |
28 // may result on logging extension activity events caused by value conversion | |
29 // rather than extension itself. | |
30 | |
31 // V8 arrays are handled here in the same way as other JSObjects as they may | |
32 // also have getter methods, accessor, interceptor/handler, and access check | |
33 // callback. | |
34 | |
35 v8::Handle<v8::String> name = v8::String::New("["); | |
36 if (value->IsFunction()) { | |
37 name = v8::String::Concat(name, v8::String::New("Function")); | |
38 v8::Handle<v8::Value> fname = | |
39 v8::Handle<v8::Function>::Cast(value)->GetName(); | |
40 if (fname->IsString() && v8::Handle<v8::String>::Cast(fname)->Length()) { | |
41 name = v8::String::Concat(name, v8::String::New(" ")); | |
42 name = v8::String::Concat(name, v8::Handle<v8::String>::Cast(fname)); | |
43 name = v8::String::Concat(name, v8::String::New("()")); | |
44 } | |
45 } else { | |
46 name = v8::String::Concat(name, value->ToObject()->GetConstructorName()); | |
dcarney
2013/08/12 08:47:04
Do you want ToObject? This is relatively expensiv
pmarch
2013/08/12 13:39:26
Thanks Dan, nice catch. TOObject is absolutely red
| |
47 } | |
48 name = v8::String::Concat(name, v8::String::New("]")); | |
49 *out = new base::StringValue(std::string(*v8::String::Utf8Value(name))); | |
50 // Prevent V8ValueConverter from further processing this object. | |
51 return true; | |
52 } | |
53 | |
54 } // namespace extensions | |
OLD | NEW |