| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/renderer/extensions/console.h" | 5 #include "chrome/renderer/extensions/console.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/debug/alias.h" | 8 #include "base/debug/alias.h" |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 info.Data().As<v8::External>()->Value()); | 70 info.Data().As<v8::External>()->Value()); |
| 71 std::string message; | 71 std::string message; |
| 72 for (int i = 0; i < info.Length(); ++i) { | 72 for (int i = 0; i < info.Length(); ++i) { |
| 73 if (i > 0) | 73 if (i > 0) |
| 74 message += " "; | 74 message += " "; |
| 75 message += *v8::String::AsciiValue(info[i]); | 75 message += *v8::String::AsciiValue(info[i]); |
| 76 } | 76 } |
| 77 (*log_method)(v8::Context::GetCalling(), message); | 77 (*log_method)(v8::Context::GetCalling(), message); |
| 78 } | 78 } |
| 79 | 79 |
| 80 void BindLogMethod(v8::Local<v8::Object> target, | 80 void BindLogMethod(v8::Isolate* isolate, |
| 81 v8::Local<v8::Object> target, |
| 81 const std::string& name, | 82 const std::string& name, |
| 82 LogMethod log_method) { | 83 LogMethod log_method) { |
| 83 v8::Local<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New( | 84 v8::Local<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New( |
| 84 &BoundLogMethodCallback, | 85 &BoundLogMethodCallback, |
| 85 v8::External::New(reinterpret_cast<void*>(log_method))); | 86 v8::External::New(isolate, reinterpret_cast<void*>(log_method))); |
| 86 target->Set(v8::String::New(name.c_str()), tmpl->GetFunction()); | 87 target->Set(v8::String::New(name.c_str()), tmpl->GetFunction()); |
| 87 } | 88 } |
| 88 | 89 |
| 89 } // namespace | 90 } // namespace |
| 90 | 91 |
| 91 void Debug(content::RenderView* render_view, const std::string& message) { | 92 void Debug(content::RenderView* render_view, const std::string& message) { |
| 92 AddMessage(render_view, content::CONSOLE_MESSAGE_LEVEL_DEBUG, message); | 93 AddMessage(render_view, content::CONSOLE_MESSAGE_LEVEL_DEBUG, message); |
| 93 } | 94 } |
| 94 | 95 |
| 95 void Log(content::RenderView* render_view, const std::string& message) { | 96 void Log(content::RenderView* render_view, const std::string& message) { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 } | 166 } |
| 166 content::RenderView* render_view = ByContextFinder::Find(context); | 167 content::RenderView* render_view = ByContextFinder::Find(context); |
| 167 if (!render_view) { | 168 if (!render_view) { |
| 168 LOG(WARNING) << "Could not log \"" << message << "\": no render view found"; | 169 LOG(WARNING) << "Could not log \"" << message << "\": no render view found"; |
| 169 return; | 170 return; |
| 170 } | 171 } |
| 171 AddMessage(render_view, level, message); | 172 AddMessage(render_view, level, message); |
| 172 } | 173 } |
| 173 | 174 |
| 174 v8::Local<v8::Object> AsV8Object() { | 175 v8::Local<v8::Object> AsV8Object() { |
| 175 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); | 176 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 177 v8::HandleScope handle_scope(isolate); |
| 176 v8::Local<v8::Object> console_object = v8::Object::New(); | 178 v8::Local<v8::Object> console_object = v8::Object::New(); |
| 177 BindLogMethod(console_object, "debug", &Debug); | 179 BindLogMethod(isolate, console_object, "debug", &Debug); |
| 178 BindLogMethod(console_object, "log", &Log); | 180 BindLogMethod(isolate, console_object, "log", &Log); |
| 179 BindLogMethod(console_object, "warn", &Warn); | 181 BindLogMethod(isolate, console_object, "warn", &Warn); |
| 180 BindLogMethod(console_object, "error", &Error); | 182 BindLogMethod(isolate, console_object, "error", &Error); |
| 181 return handle_scope.Close(console_object); | 183 return handle_scope.Close(console_object); |
| 182 } | 184 } |
| 183 | 185 |
| 184 } // namespace console | 186 } // namespace console |
| 185 } // namespace extensions | 187 } // namespace extensions |
| OLD | NEW |