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

Side by Side Diff: chrome/renderer/extensions/activity_log_converter_strategy.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: 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 "chrome/renderer/extensions/activity_log_converter_strategy.h"
6 #include "base/values.h"
7
8 namespace extensions {
9
10 bool ActivityLogConverterStrategy::ToV8Value(const base::Value* value,
11 v8::Handle<v8::Value>* out) const {
12 return false; // Default V8ValueConverter behavior.
13 }
14
15 bool ActivityLogConverterStrategy::FromV8Value(v8::Handle<v8::Value> value,
16 base::Value** out) const {
17 if (!value->IsObject())
18 return false; // Default V8ValueConverter behavior.
19
20 // Handle JSObject.
21 // We cannot use value->Get(key/index) as there may be an accessor installed
22 // on the key/index. If that is the case, we will execute the getter function
23 // which may interfere with the JS execution environment in the way unexpected
24 // by a developer. Moreover, executing getter functions may lead to logging
25 // events unrelated to extension execution which are caused by the converter.
26 // One way to solve this problem is to make the converter to check if a getter
27 // installed on a property with the HasRealNamedProperty() and
28 // HasRealIndexedProperty() V8 API calls, and return NULL for such properties.
29 // This behavior must be regulated by a flag.
30
31 // We may want to convert and log certain properties of DOM elements. The way
32 // to do it is to obtain WebKit's DOM element from the JS object that wraps
33 // this element and access relevant properties on WebKit's DOM element. If we
34 // access these properties via JS wrapper object, an extension may disguise
35 // the real values by setting getter methods.
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 *out = new base::StringValue(std::string(*utf8, utf8.length()));
55 return true;
56 }
57
58 } // namespace extensions
59
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698