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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/renderer/extensions/activity_log_value_converter.cc
diff --git a/chrome/renderer/extensions/activity_log_value_converter.cc b/chrome/renderer/extensions/activity_log_value_converter.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7dd90f75ca06f0c2e5137e3f61a21ace86592261
--- /dev/null
+++ b/chrome/renderer/extensions/activity_log_value_converter.cc
@@ -0,0 +1,58 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/values.h"
+#include "chrome/renderer/extensions/activity_log_value_converter.h"
+
+namespace extensions {
+
+ActivityLogValueConverter::ActivityLogValueConverter()
+ : v8_value_converter_(content::V8ValueConverter::create()) {
+}
+
+ActivityLogValueConverter::~ActivityLogValueConverter() {}
+
+base::Value* ActivityLogValueConverter::FromV8Value(
+ v8::Handle<v8::Value> value,
+ v8::Handle<v8::Context> context) const {
+
+ if (!value->IsObject())
+ return v8_value_converter_->FromV8Value(value, context);
+
+ // Handle JSObject.
+ // We cannot use value->Get(key/index) as there may be an accessor installed
+ // on the key/index. If that is the case, V8ValueConverter will execute the
+ // getter function which may interfere with the JS execution environment in
+ // the way unexpected by a developer. Moreover, executing getter functions may
+ // lead to recursive logging by ActivityLog when the getter accesses
+ // properties or issues calls on a JS object that happens to be a wrapper of a
+ // DOM object. V8 API does not allow to check if a property has a getter
+ // method installed. One way to do it is by using getOwnPropertyDescriptor
+ // method of the JS object; however, the function may be redefined and return
+ // bogus values. Apart from accessors, a JS object may have an interceptor
+ // installed which is not a problem as it can be tested with the
+ // HasNamedLookupInterceptor and HasIndexedLookupInterceptor V8 API calls.
+
+ v8::Handle<v8::String> name = v8::String::New("[");
+
+ if (value->IsFunction()) {
+ name = v8::String::Concat(name, v8::String::New("Function"));
+ v8::Handle<v8::Value> fname =
+ v8::Handle<v8::Function>::Cast(value)->GetName();
+ if (fname->IsString() && v8::Handle<v8::String>::Cast(fname)->Length()) {
+ name = v8::String::Concat(name, v8::String::New(" "));
+ name = v8::String::Concat(name, v8::Handle<v8::String>::Cast(fname));
+ name = v8::String::Concat(name, v8::String::New("()"));
+ }
+ } else {
+ name = v8::String::Concat(name, value->ToObject()->GetConstructorName());
+ }
+
+ name = v8::String::Concat(name, v8::String::New("]"));
+ v8::String::Utf8Value utf8(name);
+ return new base::StringValue(std::string(*utf8, utf8.length()));
+}
+
+} // namespace extensions
+

Powered by Google App Engine
This is Rietveld 408576698