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 #ifndef EXTENSIONS_RENDERER_API_ACTIVITY_LOGGER_H_ | 5 #ifndef EXTENSIONS_RENDERER_API_ACTIVITY_LOGGER_H_ |
6 #define EXTENSIONS_RENDERER_API_ACTIVITY_LOGGER_H_ | 6 #define EXTENSIONS_RENDERER_API_ACTIVITY_LOGGER_H_ |
7 | 7 |
| 8 #include <memory> |
8 #include <string> | 9 #include <string> |
| 10 #include <vector> |
9 | 11 |
10 #include "base/macros.h" | 12 #include "base/macros.h" |
11 #include "extensions/common/features/feature.h" | |
12 #include "extensions/renderer/object_backed_native_handler.h" | 13 #include "extensions/renderer/object_backed_native_handler.h" |
13 #include "v8/include/v8.h" | 14 #include "v8/include/v8.h" |
14 | 15 |
| 16 namespace base { |
| 17 class ListValue; |
| 18 } |
| 19 |
15 namespace extensions { | 20 namespace extensions { |
16 class Dispatcher; | 21 class Dispatcher; |
17 | 22 |
18 // Used to log extension API calls and events that are implemented with custom | 23 // Used to log extension API calls and events that are implemented with custom |
19 // bindings.The actions are sent via IPC to extensions::ActivityLog for | 24 // bindings.The actions are sent via IPC to extensions::ActivityLog for |
20 // recording and display. | 25 // recording and display. |
21 class APIActivityLogger : public ObjectBackedNativeHandler { | 26 class APIActivityLogger : public ObjectBackedNativeHandler { |
22 public: | 27 public: |
23 APIActivityLogger(ScriptContext* context, Dispatcher* dispatcher); | 28 APIActivityLogger(ScriptContext* context, Dispatcher* dispatcher); |
24 ~APIActivityLogger() override; | 29 ~APIActivityLogger() override; |
25 | 30 |
| 31 // Notifies the browser that an API method has been called, if and only if |
| 32 // activity logging is enabled. |
| 33 static void LogAPICall(v8::Local<v8::Context> context, |
| 34 const std::string& call_name, |
| 35 const std::vector<v8::Local<v8::Value>>& arguments); |
| 36 |
26 private: | 37 private: |
27 // Used to distinguish API calls & events from each other in LogInternal. | 38 // Used to distinguish API calls & events from each other in LogInternal. |
28 enum CallType { APICALL, EVENT }; | 39 enum CallType { APICALL, EVENT }; |
29 | 40 |
30 // This is ultimately invoked in bindings.js with JavaScript arguments. | 41 // This is ultimately invoked in bindings.js with JavaScript arguments. |
31 // arg0 - extension ID as a string | 42 // arg0 - extension ID as a string |
32 // arg1 - API call name as a string | 43 // arg1 - API method/Event name as a string |
33 // arg2 - arguments to the API call | 44 // arg2 - arguments to the API call/event |
34 // arg3 - any extra logging info as a string (optional) | 45 // arg3 - any extra logging info as a string (optional) |
35 void LogAPICall(const v8::FunctionCallbackInfo<v8::Value>& args); | 46 // TODO(devlin): Does arg3 ever exist? |
| 47 void LogForJS(const CallType call_type, |
| 48 const v8::FunctionCallbackInfo<v8::Value>& args); |
36 | 49 |
37 // This is ultimately invoked in bindings.js with JavaScript arguments. | 50 // Common implementation method for sending a logging IPC. |
38 // arg0 - extension ID as a string | 51 static void LogInternal(const CallType call_type, |
39 // arg1 - Event name as a string | 52 const std::string& extension_id, |
40 // arg2 - Event arguments | 53 const std::string& call_name, |
41 // arg3 - any extra logging info as a string (optional) | 54 std::unique_ptr<base::ListValue> arguments, |
42 void LogEvent(const v8::FunctionCallbackInfo<v8::Value>& args); | 55 const std::string& extra); |
43 | |
44 // LogAPICall and LogEvent are really the same underneath except for | |
45 // how they are ultimately dispatched to the log. | |
46 void LogInternal(const CallType call_type, | |
47 const v8::FunctionCallbackInfo<v8::Value>& args); | |
48 | 56 |
49 Dispatcher* dispatcher_; | 57 Dispatcher* dispatcher_; |
50 | 58 |
51 DISALLOW_COPY_AND_ASSIGN(APIActivityLogger); | 59 DISALLOW_COPY_AND_ASSIGN(APIActivityLogger); |
52 }; | 60 }; |
53 | 61 |
54 } // namespace extensions | 62 } // namespace extensions |
55 | 63 |
56 #endif // EXTENSIONS_RENDERER_API_ACTIVITY_LOGGER_H_ | 64 #endif // EXTENSIONS_RENDERER_API_ACTIVITY_LOGGER_H_ |
OLD | NEW |