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

Unified Diff: webkit/plugins/ppapi/var.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
« webkit/plugins/ppapi/ppb_console_impl.cc ('K') | « webkit/plugins/ppapi/var.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/plugins/ppapi/var.cc
===================================================================
--- webkit/plugins/ppapi/var.cc (revision 77666)
+++ webkit/plugins/ppapi/var.cc (working copy)
@@ -8,6 +8,7 @@
#include "base/logging.h"
#include "base/scoped_ptr.h"
+#include "base/string_number_conversions.h"
#include "base/string_util.h"
#include "ppapi/c/dev/ppb_var_deprecated.h"
#include "ppapi/c/ppb_var.h"
@@ -724,6 +725,38 @@
}
// static
+std::string Var::PPVarToLogString(PP_Var var) {
+ switch (var.type) {
+ case PP_VARTYPE_UNDEFINED:
+ return "[Undefined]";
+ case PP_VARTYPE_NULL:
+ return "[Null]";
+ case PP_VARTYPE_BOOL:
+ return var.value.as_bool ? "[True]" : "[False]";
+ case PP_VARTYPE_INT32:
+ return base::IntToString(var.value.as_int);
+ case PP_VARTYPE_DOUBLE:
+ return base::DoubleToString(var.value.as_double);
+ case PP_VARTYPE_STRING: {
+ scoped_refptr<StringVar> string(StringVar::FromPPVar(var));
+ if (!string)
+ return "[Invalid string]";
+
+ // Since this is for logging, escape NULLs.
+ std::string result = string->value();
+ std::string null;
+ null.push_back(0);
+ ReplaceSubstringsAfterOffset(&result, 0, null, "\\0");
+ return result;
+ }
+ case PP_VARTYPE_OBJECT:
+ return "[Object]";
+ default:
+ return "[Invalid var]";
+ }
+}
+
+// static
void Var::PluginAddRefPPVar(PP_Var var) {
if (var.type == PP_VARTYPE_STRING || var.type == PP_VARTYPE_OBJECT) {
if (!ResourceTracker::Get()->AddRefVar(static_cast<int32>(var.value.as_id)))
« webkit/plugins/ppapi/ppb_console_impl.cc ('K') | « webkit/plugins/ppapi/var.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698