Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Unified Diff: ppapi/proxy/ppb_console_proxy.cc

Issue 6667010: Add a console interface for logging to the JS console from a PPAPI plugin.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ppapi/proxy/ppb_console_proxy.cc
===================================================================
--- ppapi/proxy/ppb_console_proxy.cc (revision 0)
+++ ppapi/proxy/ppb_console_proxy.cc (revision 0)
@@ -0,0 +1,104 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ppapi/proxy/ppb_console_proxy.h"
+
+#include "ppapi/c/dev/ppb_console_dev.h"
+#include "ppapi/proxy/plugin_dispatcher.h"
+#include "ppapi/proxy/ppapi_messages.h"
+#include "ppapi/proxy/serialized_var.h"
yzshen1 2011/03/11 00:40:35 This has already been included in the .h file, I t
+
+namespace pp {
+namespace proxy {
+
+namespace {
+
+void Log(PP_Instance instance, PP_LogLevel_Dev level, PP_Var value) {
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
+ if (!dispatcher)
+ return;
+ dispatcher->Send(new PpapiHostMsg_PPBConsole_Log(
+ INTERFACE_ID_PPB_CONSOLE, instance, static_cast<int>(level),
+ SerializedVarSendInput(dispatcher, value)));
+}
+
+void LogWithSource(PP_Instance instance,
+ PP_LogLevel_Dev level,
+ const PP_Var source,
+ const PP_Var value) {
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
+ if (!dispatcher)
+ return;
+ dispatcher->Send(new PpapiHostMsg_PPBConsole_LogWithSource(
+ INTERFACE_ID_PPB_CONSOLE, instance, static_cast<int>(level),
+ SerializedVarSendInput(dispatcher, source),
+ SerializedVarSendInput(dispatcher, value)));
+}
+
+const PPB_Console_Dev console_interface = {
+ &Log,
+ &LogWithSource
+};
+
+InterfaceProxy* CreateConsoleProxy(Dispatcher* dispatcher,
+ const void* target_interface) {
+ return new PPB_Console_Proxy(dispatcher, target_interface);
+}
+
+} // namespace
+
+PPB_Console_Proxy::PPB_Console_Proxy(Dispatcher* dispatcher,
+ const void* target_interface)
+ : InterfaceProxy(dispatcher, target_interface) {
+}
+
+PPB_Console_Proxy::~PPB_Console_Proxy() {
+}
+
+// static
+const InterfaceProxy::Info* PPB_Console_Proxy::GetInfo() {
+ static const Info info = {
+ &console_interface,
+ PPB_CONSOLE_DEV_INTERFACE,
+ INTERFACE_ID_PPB_CONSOLE,
+ false,
+ &CreateConsoleProxy,
+ };
+ return &info;
+}
+
+bool PPB_Console_Proxy::OnMessageReceived(const IPC::Message& msg) {
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP(PPB_Console_Proxy, msg)
+ IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBConsole_Log,
+ OnMsgLog)
+ IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBConsole_LogWithSource,
+ OnMsgLogWithSource)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+ return handled;
+}
+
+void PPB_Console_Proxy::OnMsgLog(PP_Instance instance,
+ int log_level,
+ SerializedVarReceiveInput value) {
+ ppb_console_target()->Log(instance,
+ static_cast<PP_LogLevel_Dev>(log_level),
yzshen1 2011/03/11 00:40:35 Wrong indent.
+ value.Get(dispatcher()));
+}
+
+void PPB_Console_Proxy::OnMsgLogWithSource(PP_Instance instance,
+ int log_level,
+ SerializedVarReceiveInput source,
+ SerializedVarReceiveInput value) {
+ ppb_console_target()->LogWithSource(
+ instance,
+ static_cast<PP_LogLevel_Dev>(log_level),
+ source.Get(dispatcher()),
+ value.Get(dispatcher()));
+}
+
+} // namespace proxy
+} // namespace pp
+
Property changes on: ppapi/proxy/ppb_console_proxy.cc
___________________________________________________________________
Added: svn:eol-style
+ LF

Powered by Google App Engine
This is Rietveld 408576698