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 3 // found in the LICENSE file. 4 5 #ifndef CHROME_RENDERER_EXTENSIONS_API_ACTIVITY_LOGGER_H_ 6 #define CHROME_RENDERER_EXTENSIONS_API_ACTIVITY_LOGGER_H_ 7 8 #include <string> 9 #include "chrome/renderer/extensions/chrome_v8_extension.h" 10 #include "chrome/renderer/extensions/dispatcher.h" 11 #include "extensions/common/features/feature.h" 12 #include "v8/include/v8.h" 13 14 namespace extensions { 15 16 // Used to log extension API calls and events that are implemented with custom 17 // bindings.The actions are sent via IPC to extensions::ActivityLog for 18 // recording and display. 19 class APIActivityLogger : public ChromeV8Extension { 20 public: 21 APIActivityLogger(Dispatcher* dispatcher, ChromeV8Context* context); 22 23 private: 24 // Used to distinguish API calls & events from each other in LogInternal. 25 enum CallType { 26 APICALL, 27 EVENT 28 }; 29 30 // This is ultimately invoked in bindings.js with JavaScript arguments. 31 // arg0 - extension ID as a string 32 // arg1 - API call name as a string 33 // arg2 - arguments to the API call 34 // arg3 - any extra logging info as a string (optional) 35 static void LogAPICall(const v8::FunctionCallbackInfo<v8::Value>& args); 36 37 // This is ultimately invoked in bindings.js with JavaScript arguments. 38 // arg0 - extension ID as a string 39 // arg1 - Event name as a string 40 // arg2 - Event arguments 41 // arg3 - any extra logging info as a string (optional) 42 static void LogEvent(const v8::FunctionCallbackInfo<v8::Value>& args); 43 44 // LogAPICall and LogEvent are really the same underneath except for 45 // how they are ultimately dispatched to the log. 46 static void LogInternal(const CallType call_type, 47 const v8::FunctionCallbackInfo<v8::Value>& args); 48 49 DISALLOW_COPY_AND_ASSIGN(APIActivityLogger); 50 }; 51 52 } // namespace extensions 53 54 #endif // CHROME_RENDERER_EXTENSIONS_API_ACTIVITY_LOGGER_H_ 55