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

Unified Diff: chrome/renderer/extensions/api_activity_logger.cc

Issue 12517011: Added activity logging for ext APIs with custom bindings (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: lint fix Created 7 years, 9 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/api_activity_logger.cc
diff --git a/chrome/renderer/extensions/api_activity_logger.cc b/chrome/renderer/extensions/api_activity_logger.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e904a1cb754f5d5d952d92aff3281cffa7f8ea58
--- /dev/null
+++ b/chrome/renderer/extensions/api_activity_logger.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 <string>
+#include "chrome/common/extensions/extension_messages.h"
+#include "chrome/renderer/chrome_render_process_observer.h"
+#include "chrome/renderer/extensions/api_activity_logger.h"
+#include "content/public/renderer/render_thread.h"
+#include "content/public/renderer/v8_value_converter.h"
+
+using content::V8ValueConverter;
+
+namespace extensions {
+
+APIActivityLogger::APIActivityLogger() : ChromeV8Extension(NULL) {
+ RouteStaticFunction("LogActivity", &APIActivityLogger::LogActivity);
+}
+
+// static
+v8::Handle<v8::Value> APIActivityLogger::LogActivity(
+ const v8::Arguments& args) {
+ DCHECK_GT(args.Length(), 2);
+ DCHECK(args[0]->IsString());
+ DCHECK(args[1]->IsString());
+ DCHECK(args[2]->IsArray());
+
+ // Get the simple values.
+ std::string ext_id = *v8::String::AsciiValue(args[0]->ToString());
+ ExtensionHostMsg_APIAction_Params params;
+ params.api_call = *v8::String::AsciiValue(args[1]->ToString());
+ if (args.Length() == 4) // Extras are optional.
+ params.extra = *v8::String::AsciiValue(args[3]->ToString());
+ else
+ params.extra = "";
+
+ // Get the array of api call arguments.
+ v8::Local<v8::Array> arg_array = v8::Local<v8::Array>::Cast(args[2]);
+ if (arg_array->Length() > 0) {
+ scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create());
Matt Perry 2013/03/14 20:32:31 converter->FromV8Value(args[2]) should work and re
felt 2013/03/15 00:04:47 converter->FromV8Value(args[2], v8::Context::GetCu
Matt Perry 2013/03/15 17:51:06 If args[2] is a v8::Array, the Value* will be of t
+ scoped_ptr<ListValue> arg_list(new ListValue());
+ for (uint i = 0; i < arg_array->Length(); i++) {
+ arg_list->Set(i,
+ converter->FromV8Value(arg_array->Get(i),
+ v8::Context::GetCurrent()));
+ }
+ params.arguments.Swap(arg_list.get());
+ }
+
+ // Initiate the IPC process.
Matt Perry 2013/03/14 20:32:31 nit: superfluous comment
felt 2013/03/15 00:04:47 Done.
+ content::RenderThread::Get()->Send(
+ new ExtensionHostMsg_AddAPIActionToActivityLog(ext_id, params));
+
+ return v8::Undefined();
+}
+
+} // namespace extensions
+

Powered by Google App Engine
This is Rietveld 408576698