OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 CHROME_RENDERER_EXTENSIONS_API_ACTIVITY_LOGGER_H_ | 5 #ifndef CHROME_RENDERER_EXTENSIONS_API_ACTIVITY_LOGGER_H_ |
6 #define CHROME_RENDERER_EXTENSIONS_API_ACTIVITY_LOGGER_H_ | 6 #define CHROME_RENDERER_EXTENSIONS_API_ACTIVITY_LOGGER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
| 9 #include "chrome/common/extensions/features/feature.h" |
9 #include "chrome/renderer/extensions/chrome_v8_extension.h" | 10 #include "chrome/renderer/extensions/chrome_v8_extension.h" |
10 #include "chrome/renderer/extensions/dispatcher.h" | 11 #include "chrome/renderer/extensions/dispatcher.h" |
11 #include "v8/include/v8.h" | 12 #include "v8/include/v8.h" |
12 | 13 |
13 namespace extensions { | 14 namespace extensions { |
14 | 15 |
15 // Used to log extension API calls and events that are implemented with custom | 16 // Used to log extension API calls and events that are implemented with custom |
16 // bindings.The actions are sent via IPC to extensions::ActivityLog for | 17 // bindings.The actions are sent via IPC to extensions::ActivityLog for |
17 // recording and display. | 18 // recording and display. |
18 class APIActivityLogger : public ChromeV8Extension { | 19 class APIActivityLogger : public ChromeV8Extension { |
19 public: | 20 public: |
20 APIActivityLogger(Dispatcher* dispatcher, ChromeV8Context* context); | 21 APIActivityLogger(Dispatcher* dispatcher, ChromeV8Context* context); |
21 | 22 |
22 // This is ultimately invoked in schema_generated_bindings.js with | 23 // This is to use to log blocked API calls. |
23 // JavaScript arguments. Logged as an APIAction. | |
24 // arg0 - extension ID as a string | |
25 // arg1 - API call name as a string | |
26 // arg2 - arguments to the API call | |
27 // arg3 - any extra logging info as a string (optional) | |
28 static void LogAPICall(const v8::FunctionCallbackInfo<v8::Value>& args); | |
29 | |
30 // This is ultimately invoked in schema_generated_bindings.js with | |
31 // JavaScript arguments. Logged as an EventAction. | |
32 // arg0 - extension ID as a string | |
33 // arg1 - Event name as a string | |
34 // arg2 - Event arguments | |
35 // arg3 - any extra logging info as a string (optional) | |
36 static void LogEvent(const v8::FunctionCallbackInfo<v8::Value>& args); | |
37 | |
38 // This is for the Dispatcher to use to log blocked API calls. | |
39 static void LogBlockedCall(const std::string& extension_id, | 24 static void LogBlockedCall(const std::string& extension_id, |
40 const std::string& function_name); | 25 const std::string& function_name, |
| 26 Feature::AvailabilityResult result); |
41 | 27 |
42 private: | 28 private: |
43 // Used to distinguish API calls & events from each other in LogInternal. | 29 // Used to distinguish API calls & events from each other in LogInternal. |
44 enum CallType { | 30 enum CallType { |
45 APICALL, | 31 APICALL, |
46 EVENT | 32 EVENT |
47 }; | 33 }; |
48 | 34 |
| 35 // This is ultimately invoked in bindings.js with JavaScript arguments. |
| 36 // arg0 - extension ID as a string |
| 37 // arg1 - API call name as a string |
| 38 // arg2 - arguments to the API call |
| 39 // arg3 - any extra logging info as a string (optional) |
| 40 static void LogAPICall(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 41 |
| 42 // This is ultimately invoked in bindings.js with JavaScript arguments. |
| 43 // arg0 - extension ID as a string |
| 44 // arg1 - Event name as a string |
| 45 // arg2 - Event arguments |
| 46 // arg3 - any extra logging info as a string (optional) |
| 47 static void LogEvent(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 48 |
| 49 // This is invoked in binding.js with JavaScript arguments. |
| 50 // arg0 - extension ID as string |
| 51 // arg1 - Function name as a string |
| 52 // arg2 - Reason for the failure |
| 53 static void LogBlockedCallWrapper( |
| 54 const v8::FunctionCallbackInfo<v8::Value>& args); |
| 55 |
49 // LogAPICall and LogEvent are really the same underneath except for | 56 // LogAPICall and LogEvent are really the same underneath except for |
50 // how they are ultimately dispatched to the log. | 57 // how they are ultimately dispatched to the log. |
51 static void LogInternal(const CallType call_type, | 58 static void LogInternal(const CallType call_type, |
52 const v8::FunctionCallbackInfo<v8::Value>& args); | 59 const v8::FunctionCallbackInfo<v8::Value>& args); |
53 | 60 |
54 DISALLOW_COPY_AND_ASSIGN(APIActivityLogger); | 61 DISALLOW_COPY_AND_ASSIGN(APIActivityLogger); |
55 }; | 62 }; |
56 | 63 |
57 } // namespace extensions | 64 } // namespace extensions |
58 | 65 |
59 #endif // CHROME_RENDERER_EXTENSIONS_API_ACTIVITY_LOGGER_H_ | 66 #endif // CHROME_RENDERER_EXTENSIONS_API_ACTIVITY_LOGGER_H_ |
OLD | NEW |