OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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 #include "ppapi/proxy/ppb_console_proxy.h" |
| 6 |
| 7 #include "ppapi/c/dev/ppb_console_dev.h" |
| 8 #include "ppapi/proxy/plugin_dispatcher.h" |
| 9 #include "ppapi/proxy/ppapi_messages.h" |
| 10 #include "ppapi/proxy/serialized_var.h" |
| 11 |
| 12 namespace pp { |
| 13 namespace proxy { |
| 14 |
| 15 namespace { |
| 16 |
| 17 void Log(PP_Instance instance, PP_LogLevel_Dev level, PP_Var value) { |
| 18 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); |
| 19 if (!dispatcher) |
| 20 return; |
| 21 dispatcher->Send(new PpapiHostMsg_PPBConsole_Log( |
| 22 INTERFACE_ID_PPB_CONSOLE, instance, static_cast<int>(level), |
| 23 SerializedVarSendInput(dispatcher, value))); |
| 24 } |
| 25 |
| 26 void LogWithSource(PP_Instance instance, |
| 27 PP_LogLevel_Dev level, |
| 28 const PP_Var source, |
| 29 const PP_Var value) { |
| 30 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); |
| 31 if (!dispatcher) |
| 32 return; |
| 33 dispatcher->Send(new PpapiHostMsg_PPBConsole_LogWithSource( |
| 34 INTERFACE_ID_PPB_CONSOLE, instance, static_cast<int>(level), |
| 35 SerializedVarSendInput(dispatcher, source), |
| 36 SerializedVarSendInput(dispatcher, value))); |
| 37 } |
| 38 |
| 39 const PPB_Console_Dev console_interface = { |
| 40 &Log, |
| 41 &LogWithSource |
| 42 }; |
| 43 |
| 44 InterfaceProxy* CreateConsoleProxy(Dispatcher* dispatcher, |
| 45 const void* target_interface) { |
| 46 return new PPB_Console_Proxy(dispatcher, target_interface); |
| 47 } |
| 48 |
| 49 } // namespace |
| 50 |
| 51 PPB_Console_Proxy::PPB_Console_Proxy(Dispatcher* dispatcher, |
| 52 const void* target_interface) |
| 53 : InterfaceProxy(dispatcher, target_interface) { |
| 54 } |
| 55 |
| 56 PPB_Console_Proxy::~PPB_Console_Proxy() { |
| 57 } |
| 58 |
| 59 // static |
| 60 const InterfaceProxy::Info* PPB_Console_Proxy::GetInfo() { |
| 61 static const Info info = { |
| 62 &console_interface, |
| 63 PPB_CONSOLE_DEV_INTERFACE, |
| 64 INTERFACE_ID_PPB_CONSOLE, |
| 65 false, |
| 66 &CreateConsoleProxy, |
| 67 }; |
| 68 return &info; |
| 69 } |
| 70 |
| 71 bool PPB_Console_Proxy::OnMessageReceived(const IPC::Message& msg) { |
| 72 bool handled = true; |
| 73 IPC_BEGIN_MESSAGE_MAP(PPB_Console_Proxy, msg) |
| 74 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBConsole_Log, |
| 75 OnMsgLog) |
| 76 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBConsole_LogWithSource, |
| 77 OnMsgLogWithSource) |
| 78 IPC_MESSAGE_UNHANDLED(handled = false) |
| 79 IPC_END_MESSAGE_MAP() |
| 80 return handled; |
| 81 } |
| 82 |
| 83 void PPB_Console_Proxy::OnMsgLog(PP_Instance instance, |
| 84 int log_level, |
| 85 SerializedVarReceiveInput value) { |
| 86 ppb_console_target()->Log(instance, |
| 87 static_cast<PP_LogLevel_Dev>(log_level), |
| 88 value.Get(dispatcher())); |
| 89 } |
| 90 |
| 91 void PPB_Console_Proxy::OnMsgLogWithSource(PP_Instance instance, |
| 92 int log_level, |
| 93 SerializedVarReceiveInput source, |
| 94 SerializedVarReceiveInput value) { |
| 95 ppb_console_target()->LogWithSource( |
| 96 instance, |
| 97 static_cast<PP_LogLevel_Dev>(log_level), |
| 98 source.Get(dispatcher()), |
| 99 value.Get(dispatcher())); |
| 100 } |
| 101 |
| 102 } // namespace proxy |
| 103 } // namespace pp |
| 104 |
OLD | NEW |