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