Chromium Code Reviews| 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 "base/values.h" | |
| 6 #include "chrome/renderer/extensions/activity_log_value_converter.h" | |
| 7 | |
| 8 namespace extensions { | |
| 9 | |
| 10 ActivityLogValueConverter::ActivityLogValueConverter() | |
| 11 : v8_value_converter_(content::V8ValueConverter::create()) { | |
| 12 } | |
| 13 | |
| 14 ActivityLogValueConverter::~ActivityLogValueConverter() {} | |
| 15 | |
| 16 base::Value* ActivityLogValueConverter::FromV8Value( | |
| 17 v8::Handle<v8::Value> value, | |
| 18 v8::Handle<v8::Context> context) const { | |
| 19 | |
| 20 if (!value->IsObject()) | |
| 21 return v8_value_converter_->FromV8Value(value, context); | |
| 22 | |
| 23 // Handle JSObject. | |
| 24 // We cannot use value->Get(key/index) as there may be an accessor installed | |
| 25 // on the key/index. If that is the case, V8ValueConverter will execute the | |
| 26 // getter function which may interfere with the JS execution environment in | |
| 27 // the way unexpected by a developer. Moreover, executing getter functions may | |
| 28 // lead to recursive logging by ActivityLog when the getter accesses | |
| 29 // properties or issues calls on a JS object that happens to be a wrapper of a | |
| 30 // DOM object. V8 API does not allow to check if a property has a getter | |
|
not at google - send to devlin
2013/07/19 01:15:45
I believe this will return false for getters:
htt
| |
| 31 // method installed. One way to do it is by using getOwnPropertyDescriptor | |
| 32 // method of the JS object; however, the function may be redefined and return | |
| 33 // bogus values. Apart from accessors, a JS object may have an interceptor | |
| 34 // installed which is not a problem as it can be tested with the | |
| 35 // HasNamedLookupInterceptor and HasIndexedLookupInterceptor V8 API calls. | |
| 36 | |
| 37 // We may want to convert and log certain properties of DOM elements. The way | |
| 38 // to do it is to obtain WebKit's DOM element from the JS object that wraps | |
| 39 // this element and access relevant properties on WebKit's DOM element. | |
| 40 | |
| 41 v8::Handle<v8::String> name = v8::String::New("["); | |
| 42 | |
| 43 if (value->IsFunction()) { | |
| 44 name = v8::String::Concat(name, v8::String::New("Function")); | |
| 45 v8::Handle<v8::Value> fname = | |
| 46 v8::Handle<v8::Function>::Cast(value)->GetName(); | |
| 47 if (fname->IsString() && v8::Handle<v8::String>::Cast(fname)->Length()) { | |
| 48 name = v8::String::Concat(name, v8::String::New(" ")); | |
| 49 name = v8::String::Concat(name, v8::Handle<v8::String>::Cast(fname)); | |
| 50 name = v8::String::Concat(name, v8::String::New("()")); | |
| 51 } | |
| 52 } else { | |
| 53 name = v8::String::Concat(name, value->ToObject()->GetConstructorName()); | |
| 54 } | |
| 55 | |
| 56 name = v8::String::Concat(name, v8::String::New("]")); | |
| 57 v8::String::Utf8Value utf8(name); | |
| 58 return new base::StringValue(std::string(*utf8, utf8.length())); | |
| 59 } | |
| 60 | |
| 61 } // namespace extensions | |
| 62 | |
| OLD | NEW |