Don't throw exceptions when v8 objects/contexts are missing, and catch
exceptions that are thrown on GC. There is a path crashing the renderer:
v8 GC -> run extension function -> throws exception -> webkit tries to log ->
context has been GCed -> crash. Try to avoid that.
BUG=196581
[email protected]
[email protected]
Review URL: https://chromiumcodereview.appspot.com/12853007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@188631 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/renderer/extensions/console.h b/chrome/renderer/extensions/console.h
new file mode 100644
index 0000000..c4018cfe
--- /dev/null
+++ b/chrome/renderer/extensions/console.h
@@ -0,0 +1,46 @@
+// Copyright 2013 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.
+
+#ifndef CHROME_RENDERER_EXTENSIONS_CONSOLE_H_
+#define CHROME_RENDERER_EXTENSIONS_CONSOLE_H_
+
+#include <string>
+
+#include "content/public/common/console_message_level.h"
+#include "v8/include/v8.h"
+
+namespace content {
+class RenderView;
+}
+
+namespace extensions {
+
+// Utility for logging messages to RenderViews.
+namespace console {
+
+// Adds |message| to the console of |render_view| at various log levels.
+void Debug(content::RenderView* render_view, const std::string& message);
+void Log(content::RenderView* render_view, const std::string& message);
+void Warn(content::RenderView* render_view, const std::string& message);
+void Error(content::RenderView* render_view, const std::string& message);
+
+void AddMessage(content::RenderView* render_view,
+ content::ConsoleMessageLevel level,
+ const std::string& message);
+
+// Adds |message| to the console that hosts |context|, if any.
+void Debug(v8::Handle<v8::Context> context, const std::string& message);
+void Log(v8::Handle<v8::Context> context, const std::string& message);
+void Warn(v8::Handle<v8::Context> context, const std::string& message);
+void Error(v8::Handle<v8::Context> context, const std::string& message);
+
+void AddMessage(v8::Handle<v8::Context> context,
+ content::ConsoleMessageLevel level,
+ const std::string& message);
+
+} // namespace console
+
+} // namespace extensions
+
+#endif // CHROME_RENDERER_EXTENSIONS_CONSOLE_H_