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

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: test fix and comments 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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698