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

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
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,90 @@
+// 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.
+ scoped_refptr<StringVar> source_string(StringVar::FromPPVar(source));
+ std::string message = source_string.get() ? source_string->value() :
+ instance->module()->name();
+ message.append(": ");
+ message.append(Var::PPVarToLogString(value));
+
+ // PP_Vars can contain embedded NULLs, don't pass these through. Even if the
+ // WebKit console handles it properly, you wouldn't be able to see them which
+ // is probably not useful.
+ std::string null;
+ null.push_back(0);
+ ReplaceSubstringsAfterOffset(&message, 0, null, "\\0");
yzshen1 2011/03/11 00:40:35 We have duplicate code for escaping NULLs, and we
+
+ 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

Powered by Google App Engine
This is Rietveld 408576698