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/common/extensions/features/feature.h" 10 #include "chrome/renderer/extensions/chrome_v8_extension.h" 11 #include "chrome/renderer/extensions/dispatcher.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 // This is to use to log blocked API calls. 24 static void LogBlockedCall(const std::string& extension_id, 25 const std::string& function_name, 26 Feature::AvailabilityResult result); 27 28 private: 29 // Used to distinguish API calls & events from each other in LogInternal. 30 enum CallType { 31 APICALL, 32 EVENT 33 }; 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 56 // LogAPICall and LogEvent are really the same underneath except for 57 // how they are ultimately dispatched to the log. 58 static void LogInternal(const CallType call_type, 59 const v8::FunctionCallbackInfo<v8::Value>& args); 60 61 DISALLOW_COPY_AND_ASSIGN(APIActivityLogger); 62 }; 63 64 } // namespace extensions 65 66 #endif // CHROME_RENDERER_EXTENSIONS_API_ACTIVITY_LOGGER_H_ 67