Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(329)

Side by Side Diff: chrome/renderer/extensions/activity_log_value_converter.cc

Issue 19730002: V8ValueConverter for the activity logger that does not invoke interceptors and (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: a nit Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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
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 v8::Handle<v8::String> name = v8::String::New("[");
38
39 if (value->IsFunction()) {
40 name = v8::String::Concat(name, v8::String::New("Function"));
41 v8::Handle<v8::Value> fname =
42 v8::Handle<v8::Function>::Cast(value)->GetName();
43 if (fname->IsString() && v8::Handle<v8::String>::Cast(fname)->Length()) {
44 name = v8::String::Concat(name, v8::String::New(" "));
45 name = v8::String::Concat(name, v8::Handle<v8::String>::Cast(fname));
46 name = v8::String::Concat(name, v8::String::New("()"));
47 }
48 } else {
49 name = v8::String::Concat(name, value->ToObject()->GetConstructorName());
50 }
51
52 name = v8::String::Concat(name, v8::String::New("]"));
53 v8::String::Utf8Value utf8(name);
54 return new base::StringValue(std::string(*utf8, utf8.length()));
55 }
56
57 } // namespace extensions
58
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698