| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "content/public/child/v8_value_converter.h" | 10 #include "content/public/child/v8_value_converter.h" |
| 11 #include "content/public/renderer/render_thread.h" | 11 #include "content/public/renderer/render_thread.h" |
| 12 #include "extensions/common/extension_messages.h" | 12 #include "extensions/common/extension_messages.h" |
| 13 #include "extensions/renderer/activity_log_converter_strategy.h" | 13 #include "extensions/renderer/activity_log_converter_strategy.h" |
| 14 #include "extensions/renderer/api_activity_logger.h" | 14 #include "extensions/renderer/api_activity_logger.h" |
| 15 #include "extensions/renderer/dispatcher.h" | 15 #include "extensions/renderer/dispatcher.h" |
| 16 #include "extensions/renderer/script_context.h" | 16 #include "extensions/renderer/script_context.h" |
| 17 | 17 |
| 18 using content::V8ValueConverter; | |
| 19 | |
| 20 namespace extensions { | 18 namespace extensions { |
| 21 | 19 |
| 22 APIActivityLogger::APIActivityLogger(ScriptContext* context, | 20 APIActivityLogger::APIActivityLogger(ScriptContext* context, |
| 23 Dispatcher* dispatcher) | 21 Dispatcher* dispatcher) |
| 24 : ObjectBackedNativeHandler(context), dispatcher_(dispatcher) { | 22 : ObjectBackedNativeHandler(context), dispatcher_(dispatcher) { |
| 25 RouteFunction("LogEvent", base::Bind(&APIActivityLogger::LogEvent, | 23 RouteFunction("LogEvent", base::Bind(&APIActivityLogger::LogEvent, |
| 26 base::Unretained(this))); | 24 base::Unretained(this))); |
| 27 RouteFunction("LogAPICall", base::Bind(&APIActivityLogger::LogAPICall, | 25 RouteFunction("LogAPICall", base::Bind(&APIActivityLogger::LogAPICall, |
| 28 base::Unretained(this))); | 26 base::Unretained(this))); |
| 29 } | 27 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 58 ExtensionHostMsg_APIActionOrEvent_Params params; | 56 ExtensionHostMsg_APIActionOrEvent_Params params; |
| 59 params.api_call = *v8::String::Utf8Value(args[1]); | 57 params.api_call = *v8::String::Utf8Value(args[1]); |
| 60 if (args.Length() == 4) // Extras are optional. | 58 if (args.Length() == 4) // Extras are optional. |
| 61 params.extra = *v8::String::Utf8Value(args[3]); | 59 params.extra = *v8::String::Utf8Value(args[3]); |
| 62 else | 60 else |
| 63 params.extra = ""; | 61 params.extra = ""; |
| 64 | 62 |
| 65 // Get the array of api call arguments. | 63 // Get the array of api call arguments. |
| 66 v8::Local<v8::Array> arg_array = v8::Local<v8::Array>::Cast(args[2]); | 64 v8::Local<v8::Array> arg_array = v8::Local<v8::Array>::Cast(args[2]); |
| 67 if (arg_array->Length() > 0) { | 65 if (arg_array->Length() > 0) { |
| 68 std::unique_ptr<V8ValueConverter> converter(V8ValueConverter::create()); | 66 std::unique_ptr<content::V8ValueConverter> converter = |
| 67 content::V8ValueConverter::Create(); |
| 69 ActivityLogConverterStrategy strategy; | 68 ActivityLogConverterStrategy strategy; |
| 70 converter->SetFunctionAllowed(true); | 69 converter->SetFunctionAllowed(true); |
| 71 converter->SetStrategy(&strategy); | 70 converter->SetStrategy(&strategy); |
| 72 std::unique_ptr<base::ListValue> arg_list(new base::ListValue()); | 71 std::unique_ptr<base::ListValue> arg_list(new base::ListValue()); |
| 73 for (size_t i = 0; i < arg_array->Length(); ++i) { | 72 for (size_t i = 0; i < arg_array->Length(); ++i) { |
| 74 arg_list->Set( | 73 arg_list->Set( |
| 75 i, | 74 i, |
| 76 converter->FromV8Value(arg_array->Get(i), | 75 converter->FromV8Value(arg_array->Get(i), |
| 77 args.GetIsolate()->GetCurrentContext())); | 76 args.GetIsolate()->GetCurrentContext())); |
| 78 } | 77 } |
| 79 params.arguments.Swap(arg_list.get()); | 78 params.arguments.Swap(arg_list.get()); |
| 80 } | 79 } |
| 81 | 80 |
| 82 if (call_type == APICALL) { | 81 if (call_type == APICALL) { |
| 83 content::RenderThread::Get()->Send( | 82 content::RenderThread::Get()->Send( |
| 84 new ExtensionHostMsg_AddAPIActionToActivityLog(ext_id, params)); | 83 new ExtensionHostMsg_AddAPIActionToActivityLog(ext_id, params)); |
| 85 } else if (call_type == EVENT) { | 84 } else if (call_type == EVENT) { |
| 86 content::RenderThread::Get()->Send( | 85 content::RenderThread::Get()->Send( |
| 87 new ExtensionHostMsg_AddEventToActivityLog(ext_id, params)); | 86 new ExtensionHostMsg_AddEventToActivityLog(ext_id, params)); |
| 88 } | 87 } |
| 89 } | 88 } |
| 90 | 89 |
| 91 } // namespace extensions | 90 } // namespace extensions |
| OLD | NEW |