Chromium Code Reviews| 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 #include <string> | 5 #include <string> |
| 6 #include "base/bind.h" | 6 #include "base/bind.h" |
| 7 #include "chrome/common/extensions/extension_messages.h" | 7 #include "chrome/common/extensions/extension_messages.h" |
| 8 #include "chrome/renderer/chrome_render_process_observer.h" | 8 #include "chrome/renderer/chrome_render_process_observer.h" |
| 9 #include "chrome/renderer/extensions/api_activity_logger.h" | 9 #include "chrome/renderer/extensions/api_activity_logger.h" |
| 10 #include "content/public/renderer/render_thread.h" | 10 #include "content/public/renderer/render_thread.h" |
| 11 #include "content/public/renderer/v8_value_converter.h" | 11 #include "content/public/renderer/v8_value_converter.h" |
| 12 | 12 |
| 13 using content::V8ValueConverter; | 13 using content::V8ValueConverter; |
| 14 | 14 |
| 15 namespace extensions { | 15 namespace extensions { |
| 16 | 16 |
| 17 APIActivityLogger::APIActivityLogger( | 17 APIActivityLogger::APIActivityLogger( |
| 18 Dispatcher* dispatcher, ChromeV8Context* context) | 18 Dispatcher* dispatcher, ChromeV8Context* context) |
| 19 : ChromeV8Extension(dispatcher, context) { | 19 : ChromeV8Extension(dispatcher, context) { |
| 20 RouteFunction("LogEvent", base::Bind(&APIActivityLogger::LogEvent)); | 20 RouteFunction("LogEvent", base::Bind(&APIActivityLogger::LogEvent)); |
| 21 RouteFunction("LogAPICall", base::Bind(&APIActivityLogger::LogAPICall)); | 21 RouteFunction("LogAPICall", base::Bind(&APIActivityLogger::LogAPICall)); |
| 22 RouteFunction("LogBlockedCall", | |
| 23 base::Bind(&APIActivityLogger::LogBlockedCallWrapper)); | |
| 22 } | 24 } |
| 23 | 25 |
| 24 // static | 26 // static |
| 25 void APIActivityLogger::LogAPICall( | 27 void APIActivityLogger::LogAPICall( |
| 26 const v8::FunctionCallbackInfo<v8::Value>& args) { | 28 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 27 LogInternal(APICALL, args); | 29 LogInternal(APICALL, args); |
| 28 } | 30 } |
| 29 | 31 |
| 30 // static | 32 // static |
| 31 void APIActivityLogger::LogEvent( | 33 void APIActivityLogger::LogEvent( |
| 32 const v8::FunctionCallbackInfo<v8::Value>& args) { | 34 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 33 LogInternal(EVENT, args); | 35 LogInternal(EVENT, args); |
| 34 } | 36 } |
| 35 | 37 |
| 36 // static | 38 // static |
| 39 void APIActivityLogger::LogBlockedCallWrapper( | |
| 40 const v8::FunctionCallbackInfo<v8::Value>& args) { | |
| 41 DCHECK_EQ(args.Length(), 2); | |
| 42 DCHECK(args[0]->IsString()); | |
| 43 DCHECK(args[1]->IsString()); | |
| 44 LogBlockedCall(*v8::String::AsciiValue(args[0]->ToString()), | |
| 45 *v8::String::AsciiValue(args[1]->ToString())); | |
|
not at google - send to devlin
2013/07/11 19:22:33
you actually don't need the ToString() here. Ascii
felt
2013/07/12 01:53:04
Done.
| |
| 46 } | |
| 47 | |
| 48 // static | |
| 37 void APIActivityLogger::LogInternal( | 49 void APIActivityLogger::LogInternal( |
| 38 const CallType call_type, | 50 const CallType call_type, |
| 39 const v8::FunctionCallbackInfo<v8::Value>& args) { | 51 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 40 DCHECK_GT(args.Length(), 2); | 52 DCHECK_GT(args.Length(), 2); |
| 41 DCHECK(args[0]->IsString()); | 53 DCHECK(args[0]->IsString()); |
| 42 DCHECK(args[1]->IsString()); | 54 DCHECK(args[1]->IsString()); |
| 43 DCHECK(args[2]->IsArray()); | 55 DCHECK(args[2]->IsArray()); |
| 44 | 56 |
| 45 std::string ext_id = *v8::String::AsciiValue(args[0]->ToString()); | 57 std::string ext_id = *v8::String::AsciiValue(args[0]->ToString()); |
| 46 ExtensionHostMsg_APIActionOrEvent_Params params; | 58 ExtensionHostMsg_APIActionOrEvent_Params params; |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 75 // static | 87 // static |
| 76 void APIActivityLogger::LogBlockedCall(const std::string& extension_id, | 88 void APIActivityLogger::LogBlockedCall(const std::string& extension_id, |
| 77 const std::string& function_name) { | 89 const std::string& function_name) { |
| 78 content::RenderThread::Get()->Send( | 90 content::RenderThread::Get()->Send( |
| 79 new ExtensionHostMsg_AddBlockedCallToActivityLog(extension_id, | 91 new ExtensionHostMsg_AddBlockedCallToActivityLog(extension_id, |
| 80 function_name)); | 92 function_name)); |
| 81 } | 93 } |
| 82 | 94 |
| 83 | 95 |
| 84 } // namespace extensions | 96 } // namespace extensions |
| OLD | NEW |