| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 typedef void (*LogMethod)(v8::Handle<v8::Context> context, | 65 typedef void (*LogMethod)(v8::Handle<v8::Context> context, |
| 66 const std::string& message); | 66 const std::string& message); |
| 67 | 67 |
| 68 void BoundLogMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 68 void BoundLogMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 69 LogMethod log_method = reinterpret_cast<LogMethod>( | 69 LogMethod log_method = reinterpret_cast<LogMethod>( |
| 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::Utf8Value(info[i]); |
| 76 } | 76 } |
| 77 (*log_method)(v8::Context::GetCalling(), message); | 77 (*log_method)(info.GetIsolate()->GetCallingContext(), message); |
| 78 } | 78 } |
| 79 | 79 |
| 80 void BindLogMethod(v8::Isolate* isolate, | 80 void BindLogMethod(v8::Isolate* isolate, |
| 81 v8::Local<v8::Object> target, | 81 v8::Local<v8::Object> target, |
| 82 const std::string& name, | 82 const std::string& name, |
| 83 LogMethod log_method) { | 83 LogMethod log_method) { |
| 84 v8::Local<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New( | 84 v8::Local<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New( |
| 85 &BoundLogMethodCallback, | 85 &BoundLogMethodCallback, |
| 86 v8::External::New(isolate, reinterpret_cast<void*>(log_method))); | 86 v8::External::New(isolate, reinterpret_cast<void*>(log_method))); |
| 87 target->Set(v8::String::NewFromUtf8(isolate, name.c_str()), | 87 target->Set(v8::String::NewFromUtf8(isolate, name.c_str()), |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 content::RenderView* render_view = ByContextFinder::Find(context); | 168 content::RenderView* render_view = ByContextFinder::Find(context); |
| 169 if (!render_view) { | 169 if (!render_view) { |
| 170 LOG(WARNING) << "Could not log \"" << message << "\": no render view found"; | 170 LOG(WARNING) << "Could not log \"" << message << "\": no render view found"; |
| 171 return; | 171 return; |
| 172 } | 172 } |
| 173 AddMessage(render_view, level, message); | 173 AddMessage(render_view, level, message); |
| 174 } | 174 } |
| 175 | 175 |
| 176 v8::Local<v8::Object> AsV8Object() { | 176 v8::Local<v8::Object> AsV8Object() { |
| 177 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 177 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 178 v8::HandleScope handle_scope(isolate); | 178 v8::EscapableHandleScope handle_scope(isolate); |
| 179 v8::Local<v8::Object> console_object = v8::Object::New(); | 179 v8::Local<v8::Object> console_object = v8::Object::New(); |
| 180 BindLogMethod(isolate, console_object, "debug", &Debug); | 180 BindLogMethod(isolate, console_object, "debug", &Debug); |
| 181 BindLogMethod(isolate, console_object, "log", &Log); | 181 BindLogMethod(isolate, console_object, "log", &Log); |
| 182 BindLogMethod(isolate, console_object, "warn", &Warn); | 182 BindLogMethod(isolate, console_object, "warn", &Warn); |
| 183 BindLogMethod(isolate, console_object, "error", &Error); | 183 BindLogMethod(isolate, console_object, "error", &Error); |
| 184 return handle_scope.Close(console_object); | 184 return handle_scope.Escape(console_object); |
| 185 } | 185 } |
| 186 | 186 |
| 187 } // namespace console | 187 } // namespace console |
| 188 } // namespace extensions | 188 } // namespace extensions |
| OLD | NEW |