1// Copyright 2014 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#ifndef EXTENSIONS_RENDERER_CONSOLE_H_ 6#define EXTENSIONS_RENDERER_CONSOLE_H_ 7 8#include <string> 9 10#include "content/public/common/console_message_level.h" 11#include "v8/include/v8.h" 12 13namespace content { 14class RenderView; 15} 16 17namespace extensions { 18 19// Utility for logging messages to RenderViews. 20namespace console { 21 22// Adds |message| to the console of |render_view| at various log levels. 23void Debug(content::RenderView* render_view, const std::string& message); 24void Log(content::RenderView* render_view, const std::string& message); 25void Warn(content::RenderView* render_view, const std::string& message); 26void Error(content::RenderView* render_view, const std::string& message); 27 28// Logs an Error then crashes the current process. 29void Fatal(content::RenderView* render_view, const std::string& message); 30 31void AddMessage(content::RenderView* render_view, 32 content::ConsoleMessageLevel level, 33 const std::string& message); 34 35// Adds |message| to the console that hosts |context|, if any. 36void Debug(v8::Handle<v8::Context> context, const std::string& message); 37void Log(v8::Handle<v8::Context> context, const std::string& message); 38void Warn(v8::Handle<v8::Context> context, const std::string& message); 39void Error(v8::Handle<v8::Context> context, const std::string& message); 40 41// Logs an Error then crashes the current process. 42void Fatal(v8::Handle<v8::Context> context, const std::string& message); 43 44void AddMessage(v8::Handle<v8::Context> context, 45 content::ConsoleMessageLevel level, 46 const std::string& message); 47 48// Returns a new v8::Object with each standard log method (Debug/Log/Warn/Error) 49// bound to respective debug/log/warn/error methods. This is a direct drop-in 50// replacement for the standard devtools console.* methods usually accessible 51// from JS. 52v8::Local<v8::Object> AsV8Object(); 53 54} // namespace console 55 56} // namespace extensions 57 58#endif // EXTENSIONS_RENDERER_CONSOLE_H_ 59