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 "webkit/plugins/ppapi/ppb_console_impl.h" |
| 6 |
| 7 #include "base/string_util.h" |
| 8 #include "base/utf_string_conversions.h" |
| 9 #include "ppapi/c/dev/ppb_console_dev.h" |
| 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebConsoleMessage.h" |
| 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
| 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" |
| 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" |
| 15 #include "webkit/plugins/ppapi/plugin_module.h" |
| 16 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
| 17 #include "webkit/plugins/ppapi/resource_tracker.h" |
| 18 #include "webkit/plugins/ppapi/var.h" |
| 19 |
| 20 using WebKit::WebConsoleMessage; |
| 21 using WebKit::WebString; |
| 22 |
| 23 namespace webkit { |
| 24 namespace ppapi { |
| 25 |
| 26 namespace { |
| 27 |
| 28 void LogWithSource(PP_Instance instance_id, |
| 29 PP_LogLevel_Dev level, |
| 30 PP_Var source, |
| 31 PP_Var value) { |
| 32 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); |
| 33 if (!instance) |
| 34 return; |
| 35 |
| 36 // Convert the log level, defaulting to error. |
| 37 WebConsoleMessage::Level web_level; |
| 38 switch (level) { |
| 39 case PP_LOGLEVEL_TIP: |
| 40 web_level = WebConsoleMessage::LevelTip; |
| 41 break; |
| 42 case PP_LOGLEVEL_LOG: |
| 43 web_level = WebConsoleMessage::LevelLog; |
| 44 break; |
| 45 case PP_LOGLEVEL_WARNING: |
| 46 web_level = WebConsoleMessage::LevelWarning; |
| 47 break; |
| 48 case PP_LOGLEVEL_ERROR: |
| 49 default: |
| 50 web_level = WebConsoleMessage::LevelError; |
| 51 break; |
| 52 } |
| 53 |
| 54 // Format is the "<source>: <value>". The source defaults to the module name |
| 55 // if the source isn't a string or is empty. |
| 56 std::string message; |
| 57 if (source.type == PP_VARTYPE_STRING) |
| 58 message = Var::PPVarToLogString(source); |
| 59 if (message.empty()) |
| 60 message = instance->module()->name(); |
| 61 message.append(": "); |
| 62 message.append(Var::PPVarToLogString(value)); |
| 63 |
| 64 instance->container()->element().document().frame()->addMessageToConsole( |
| 65 WebConsoleMessage(web_level, WebString(UTF8ToUTF16(message)))); |
| 66 } |
| 67 |
| 68 void Log(PP_Instance instance, PP_LogLevel_Dev level, PP_Var value) { |
| 69 LogWithSource(instance, level, PP_MakeUndefined(), value); |
| 70 } |
| 71 |
| 72 const PPB_Console_Dev ppb_console = { |
| 73 &Log, |
| 74 &LogWithSource |
| 75 }; |
| 76 |
| 77 } // namespace |
| 78 |
| 79 // static |
| 80 const struct PPB_Console_Dev* PPB_Console_Impl::GetInterface() { |
| 81 return &ppb_console; |
| 82 } |
| 83 |
| 84 } // namespace ppapi |
| 85 } // namespace webkit |
| 86 |
OLD | NEW |