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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/renderer/extensions/activity_log_converter_strategy.cc
diff --git a/chrome/renderer/extensions/activity_log_converter_strategy.cc b/chrome/renderer/extensions/activity_log_converter_strategy.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d8a76f13b89f97dc3c4e6e07bd9a7ead0373afa4
--- /dev/null
+++ b/chrome/renderer/extensions/activity_log_converter_strategy.cc
@@ -0,0 +1,59 @@
+// 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 "chrome/renderer/extensions/activity_log_converter_strategy.h"
+#include "base/values.h"
+
+namespace extensions {
+
+bool ActivityLogConverterStrategy::ToV8Value(const base::Value* value,
+ v8::Handle<v8::Value>* out) const {
+ return false; // Default V8ValueConverter behavior.
+}
+
+bool ActivityLogConverterStrategy::FromV8Value(v8::Handle<v8::Value> value,
+ base::Value** out) const {
+ if (!value->IsObject())
+ return false; // Default V8ValueConverter behavior.
+
+ // 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, we 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 logging
+ // events unrelated to extension execution which are caused by the converter.
+ // One way to solve this problem is to make the converter to check if a getter
+ // installed on a property with the HasRealNamedProperty() and
+ // HasRealIndexedProperty() V8 API calls, and return NULL for such properties.
+ // This behavior must be regulated by a flag.
+
+ // We may want to convert and log certain properties of DOM elements. The way
+ // to do it is to obtain WebKit's DOM element from the JS object that wraps
+ // this element and access relevant properties on WebKit's DOM element. If we
+ // access these properties via JS wrapper object, an extension may disguise
+ // the real values by setting getter methods.
+
+ 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);
+ *out = new base::StringValue(std::string(*utf8, utf8.length()));
+ return true;
+}
+
+} // namespace extensions
+

Powered by Google App Engine
This is Rietveld 408576698