diff options
author | rdevlin.cronin <rdevlin.cronin@chromium.org> | 2015-06-24 13:36:01 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-06-24 20:36:34 +0000 |
commit | b2cec918668eb5b49df32d4983df84f777e9d37f (patch) | |
tree | 5bb9785b9ab5abe27c63c567dcff8a76152910e5 /extensions/renderer/console.cc | |
parent | 11af83139c09b9a3fe17fabc8f32642527f0536f (diff) | |
download | chromium_src-b2cec918668eb5b49df32d4983df84f777e9d37f.zip chromium_src-b2cec918668eb5b49df32d4983df84f777e9d37f.tar.gz chromium_src-b2cec918668eb5b49df32d4983df84f777e9d37f.tar.bz2 |
[Extensions] Kill off ExtensionMsg_AddMessageToConsole
ExtensionMsg_AddMessageToConsole does the same things as
RenderFrameHost::AddMessageToConsole, and adds a fair amount of code bloat.
Remove it.
In addition to being a nice cleanup, this kills off a bunch of
RenderViewHost dependencies, as well.
BUG=455776
TBR=timvolodine@chromium.org
Review URL: https://codereview.chromium.org/1200503002
Cr-Commit-Position: refs/heads/master@{#335991}
Diffstat (limited to 'extensions/renderer/console.cc')
-rw-r--r-- | extensions/renderer/console.cc | 143 |
1 files changed, 34 insertions, 109 deletions
diff --git a/extensions/renderer/console.cc b/extensions/renderer/console.cc index 172c5915..c2dc09b 100644 --- a/extensions/renderer/console.cc +++ b/extensions/renderer/console.cc @@ -10,50 +10,16 @@ #include "base/strings/string_util.h" #include "base/strings/stringprintf.h" #include "base/strings/utf_string_conversions.h" -#include "content/public/renderer/render_view.h" -#include "content/public/renderer/render_view_visitor.h" -#include "extensions/renderer/dispatcher.h" -#include "extensions/renderer/extension_helper.h" -#include "third_party/WebKit/public/web/WebConsoleMessage.h" -#include "third_party/WebKit/public/web/WebFrame.h" -#include "third_party/WebKit/public/web/WebView.h" +#include "content/public/renderer/render_frame.h" +#include "extensions/renderer/extension_frame_helper.h" +#include "extensions/renderer/script_context.h" +#include "extensions/renderer/script_context_set.h" namespace extensions { namespace console { namespace { -// Finds the RenderView associated with a context. Note: there will be multiple -// contexts in each RenderView. -class ByContextFinder : public content::RenderViewVisitor { - public: - static content::RenderView* Find(v8::Local<v8::Context> context) { - ByContextFinder finder(context); - content::RenderView::ForEach(&finder); - return finder.found_; - } - - private: - explicit ByContextFinder(v8::Local<v8::Context> context) - : context_(context), found_(NULL) {} - - bool Visit(content::RenderView* render_view) override { - ExtensionHelper* helper = ExtensionHelper::Get(render_view); - if (helper) { - ScriptContext* script_context = - helper->dispatcher()->script_context_set().GetByV8Context(context_); - if (script_context && script_context->GetRenderView() == render_view) - found_ = render_view; - } - return !found_; - } - - v8::Local<v8::Context> context_; - content::RenderView* found_; - - DISALLOW_COPY_AND_ASSIGN(ByContextFinder); -}; - // Writes |message| to stack to show up in minidump, then crashes. void CheckWithMinidump(const std::string& message) { char minidump[1024]; @@ -63,19 +29,29 @@ void CheckWithMinidump(const std::string& message) { CHECK(false) << message; } -typedef void (*LogMethod)(v8::Local<v8::Context> context, +typedef void (*LogMethod)(content::RenderFrame* render_frame, const std::string& message); void BoundLogMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { - LogMethod log_method = - reinterpret_cast<LogMethod>(info.Data().As<v8::External>()->Value()); std::string message; for (int i = 0; i < info.Length(); ++i) { if (i > 0) message += " "; message += *v8::String::Utf8Value(info[i]); } - (*log_method)(info.GetIsolate()->GetCallingContext(), message); + + v8::Local<v8::Context> context = info.GetIsolate()->GetCallingContext(); + if (context.IsEmpty()) { + LOG(WARNING) << "Could not log \"" << message << "\": no context given"; + return; + } + + ScriptContext* script_context = + ScriptContextSet::GetContextByV8Context(context); + LogMethod log_method = + reinterpret_cast<LogMethod>(info.Data().As<v8::External>()->Value()); + (*log_method)(script_context ? script_context->GetRenderFrame() : nullptr, + message); } void BindLogMethod(v8::Isolate* isolate, @@ -92,87 +68,36 @@ void BindLogMethod(v8::Isolate* isolate, } // namespace -void Debug(content::RenderView* render_view, const std::string& message) { - AddMessage(render_view, content::CONSOLE_MESSAGE_LEVEL_DEBUG, message); -} - -void Log(content::RenderView* render_view, const std::string& message) { - AddMessage(render_view, content::CONSOLE_MESSAGE_LEVEL_LOG, message); -} - -void Warn(content::RenderView* render_view, const std::string& message) { - AddMessage(render_view, content::CONSOLE_MESSAGE_LEVEL_WARNING, message); -} - -void Error(content::RenderView* render_view, const std::string& message) { - AddMessage(render_view, content::CONSOLE_MESSAGE_LEVEL_ERROR, message); -} - -void Fatal(content::RenderView* render_view, const std::string& message) { - Error(render_view, message); - CheckWithMinidump(message); +void Debug(content::RenderFrame* render_frame, const std::string& message) { + AddMessage(render_frame, content::CONSOLE_MESSAGE_LEVEL_DEBUG, message); } -void AddMessage(content::RenderView* render_view, - content::ConsoleMessageLevel level, - const std::string& message) { - blink::WebView* web_view = render_view->GetWebView(); - if (!web_view || !web_view->mainFrame()) - return; - blink::WebConsoleMessage::Level target_level = - blink::WebConsoleMessage::LevelLog; - switch (level) { - case content::CONSOLE_MESSAGE_LEVEL_DEBUG: - target_level = blink::WebConsoleMessage::LevelDebug; - break; - case content::CONSOLE_MESSAGE_LEVEL_LOG: - target_level = blink::WebConsoleMessage::LevelLog; - break; - case content::CONSOLE_MESSAGE_LEVEL_WARNING: - target_level = blink::WebConsoleMessage::LevelWarning; - break; - case content::CONSOLE_MESSAGE_LEVEL_ERROR: - target_level = blink::WebConsoleMessage::LevelError; - break; - } - web_view->mainFrame()->addMessageToConsole( - blink::WebConsoleMessage(target_level, base::UTF8ToUTF16(message))); +void Log(content::RenderFrame* render_frame, const std::string& message) { + AddMessage(render_frame, content::CONSOLE_MESSAGE_LEVEL_LOG, message); } -void Debug(v8::Local<v8::Context> context, const std::string& message) { - AddMessage(context, content::CONSOLE_MESSAGE_LEVEL_DEBUG, message); +void Warn(content::RenderFrame* render_frame, const std::string& message) { + AddMessage(render_frame, content::CONSOLE_MESSAGE_LEVEL_WARNING, message); } -void Log(v8::Local<v8::Context> context, const std::string& message) { - AddMessage(context, content::CONSOLE_MESSAGE_LEVEL_LOG, message); +void Error(content::RenderFrame* render_frame, const std::string& message) { + AddMessage(render_frame, content::CONSOLE_MESSAGE_LEVEL_ERROR, message); } -void Warn(v8::Local<v8::Context> context, const std::string& message) { - AddMessage(context, content::CONSOLE_MESSAGE_LEVEL_WARNING, message); -} - -void Error(v8::Local<v8::Context> context, const std::string& message) { - AddMessage(context, content::CONSOLE_MESSAGE_LEVEL_ERROR, message); -} - -void Fatal(v8::Local<v8::Context> context, const std::string& message) { - Error(context, message); +void Fatal(content::RenderFrame* render_frame, const std::string& message) { + Error(render_frame, message); CheckWithMinidump(message); } -void AddMessage(v8::Local<v8::Context> context, +void AddMessage(content::RenderFrame* render_frame, content::ConsoleMessageLevel level, const std::string& message) { - if (context.IsEmpty()) { - LOG(WARNING) << "Could not log \"" << message << "\": no context given"; - return; - } - content::RenderView* render_view = ByContextFinder::Find(context); - if (!render_view) { - LOG(WARNING) << "Could not log \"" << message << "\": no render view found"; - return; + if (!render_frame) { + LOG(WARNING) << "Could not log \"" << message + << "\": no render frame found"; + } else { + render_frame->AddMessageToConsole(level, message); } - AddMessage(render_view, level, message); } v8::Local<v8::Object> AsV8Object(v8::Isolate* isolate) { |