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

Unified Diff: webkit/plugins/ppapi/ppb_console_impl.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
« no previous file with comments | « webkit/plugins/ppapi/ppb_console_impl.h ('k') | webkit/plugins/ppapi/var.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/plugins/ppapi/ppb_console_impl.cc
===================================================================
--- webkit/plugins/ppapi/ppb_console_impl.cc (revision 0)
+++ webkit/plugins/ppapi/ppb_console_impl.cc (revision 0)
@@ -0,0 +1,86 @@
+// 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 "webkit/plugins/ppapi/ppb_console_impl.h"
+
+#include "base/string_util.h"
+#include "base/utf_string_conversions.h"
+#include "ppapi/c/dev/ppb_console_dev.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebConsoleMessage.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
+#include "webkit/plugins/ppapi/plugin_module.h"
+#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
+#include "webkit/plugins/ppapi/resource_tracker.h"
+#include "webkit/plugins/ppapi/var.h"
+
+using WebKit::WebConsoleMessage;
+using WebKit::WebString;
+
+namespace webkit {
+namespace ppapi {
+
+namespace {
+
+void LogWithSource(PP_Instance instance_id,
+ PP_LogLevel_Dev level,
+ PP_Var source,
+ PP_Var value) {
+ PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
+ if (!instance)
+ return;
+
+ // Convert the log level, defaulting to error.
+ WebConsoleMessage::Level web_level;
+ switch (level) {
+ case PP_LOGLEVEL_TIP:
+ web_level = WebConsoleMessage::LevelTip;
+ break;
+ case PP_LOGLEVEL_LOG:
+ web_level = WebConsoleMessage::LevelLog;
+ break;
+ case PP_LOGLEVEL_WARNING:
+ web_level = WebConsoleMessage::LevelWarning;
+ break;
+ case PP_LOGLEVEL_ERROR:
+ default:
+ web_level = WebConsoleMessage::LevelError;
+ break;
+ }
+
+ // Format is the "<source>: <value>". The source defaults to the module name
+ // if the source isn't a string or is empty.
+ std::string message;
+ if (source.type == PP_VARTYPE_STRING)
+ message = Var::PPVarToLogString(source);
+ if (message.empty())
+ message = instance->module()->name();
+ message.append(": ");
+ message.append(Var::PPVarToLogString(value));
+
+ instance->container()->element().document().frame()->addMessageToConsole(
+ WebConsoleMessage(web_level, WebString(UTF8ToUTF16(message))));
+}
+
+void Log(PP_Instance instance, PP_LogLevel_Dev level, PP_Var value) {
+ LogWithSource(instance, level, PP_MakeUndefined(), value);
+}
+
+const PPB_Console_Dev ppb_console = {
+ &Log,
+ &LogWithSource
+};
+
+} // namespace
+
+// static
+const struct PPB_Console_Dev* PPB_Console_Impl::GetInterface() {
+ return &ppb_console;
+}
+
+} // namespace ppapi
+} // namespace webkit
+
Property changes on: webkit/plugins/ppapi/ppb_console_impl.cc
___________________________________________________________________
Added: svn:eol-style
+ LF
« no previous file with comments | « webkit/plugins/ppapi/ppb_console_impl.h ('k') | webkit/plugins/ppapi/var.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698