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/script_context.h" | 16 #include "extensions/renderer/script_context.h" |
16 | 17 |
17 using content::V8ValueConverter; | 18 using content::V8ValueConverter; |
18 | 19 |
19 namespace extensions { | 20 namespace extensions { |
20 | 21 |
21 APIActivityLogger::APIActivityLogger(ScriptContext* context) | 22 APIActivityLogger::APIActivityLogger(ScriptContext* context, |
22 : ObjectBackedNativeHandler(context) { | 23 Dispatcher* dispatcher) |
23 RouteFunction("LogEvent", base::Bind(&APIActivityLogger::LogEvent)); | 24 : ObjectBackedNativeHandler(context), dispatcher_(dispatcher) { |
24 RouteFunction("LogAPICall", base::Bind(&APIActivityLogger::LogAPICall)); | 25 RouteFunction("LogEvent", base::Bind(&APIActivityLogger::LogEvent, |
| 26 base::Unretained(this))); |
| 27 RouteFunction("LogAPICall", base::Bind(&APIActivityLogger::LogAPICall, |
| 28 base::Unretained(this))); |
25 } | 29 } |
26 | 30 |
| 31 APIActivityLogger::~APIActivityLogger() {} |
| 32 |
27 // static | 33 // static |
28 void APIActivityLogger::LogAPICall( | 34 void APIActivityLogger::LogAPICall( |
29 const v8::FunctionCallbackInfo<v8::Value>& args) { | 35 const v8::FunctionCallbackInfo<v8::Value>& args) { |
30 LogInternal(APICALL, args); | 36 LogInternal(APICALL, args); |
31 } | 37 } |
32 | 38 |
33 // static | 39 // static |
34 void APIActivityLogger::LogEvent( | 40 void APIActivityLogger::LogEvent( |
35 const v8::FunctionCallbackInfo<v8::Value>& args) { | 41 const v8::FunctionCallbackInfo<v8::Value>& args) { |
36 LogInternal(EVENT, args); | 42 LogInternal(EVENT, args); |
37 } | 43 } |
38 | 44 |
39 // static | 45 // static |
40 void APIActivityLogger::LogInternal( | 46 void APIActivityLogger::LogInternal( |
41 const CallType call_type, | 47 const CallType call_type, |
42 const v8::FunctionCallbackInfo<v8::Value>& args) { | 48 const v8::FunctionCallbackInfo<v8::Value>& args) { |
43 CHECK_GT(args.Length(), 2); | 49 CHECK_GT(args.Length(), 2); |
44 CHECK(args[0]->IsString()); | 50 CHECK(args[0]->IsString()); |
45 CHECK(args[1]->IsString()); | 51 CHECK(args[1]->IsString()); |
46 CHECK(args[2]->IsArray()); | 52 CHECK(args[2]->IsArray()); |
47 | 53 |
| 54 if (!dispatcher_->activity_logging_enabled()) |
| 55 return; |
| 56 |
48 std::string ext_id = *v8::String::Utf8Value(args[0]); | 57 std::string ext_id = *v8::String::Utf8Value(args[0]); |
49 ExtensionHostMsg_APIActionOrEvent_Params params; | 58 ExtensionHostMsg_APIActionOrEvent_Params params; |
50 params.api_call = *v8::String::Utf8Value(args[1]); | 59 params.api_call = *v8::String::Utf8Value(args[1]); |
51 if (args.Length() == 4) // Extras are optional. | 60 if (args.Length() == 4) // Extras are optional. |
52 params.extra = *v8::String::Utf8Value(args[3]); | 61 params.extra = *v8::String::Utf8Value(args[3]); |
53 else | 62 else |
54 params.extra = ""; | 63 params.extra = ""; |
55 | 64 |
56 // Get the array of api call arguments. | 65 // Get the array of api call arguments. |
57 v8::Local<v8::Array> arg_array = v8::Local<v8::Array>::Cast(args[2]); | 66 v8::Local<v8::Array> arg_array = v8::Local<v8::Array>::Cast(args[2]); |
(...skipping 15 matching lines...) Expand all Loading... |
73 if (call_type == APICALL) { | 82 if (call_type == APICALL) { |
74 content::RenderThread::Get()->Send( | 83 content::RenderThread::Get()->Send( |
75 new ExtensionHostMsg_AddAPIActionToActivityLog(ext_id, params)); | 84 new ExtensionHostMsg_AddAPIActionToActivityLog(ext_id, params)); |
76 } else if (call_type == EVENT) { | 85 } else if (call_type == EVENT) { |
77 content::RenderThread::Get()->Send( | 86 content::RenderThread::Get()->Send( |
78 new ExtensionHostMsg_AddEventToActivityLog(ext_id, params)); | 87 new ExtensionHostMsg_AddEventToActivityLog(ext_id, params)); |
79 } | 88 } |
80 } | 89 } |
81 | 90 |
82 } // namespace extensions | 91 } // namespace extensions |
OLD | NEW |