OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "extensions/renderer/console.h" | 5 #include "extensions/renderer/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/macros.h" | 10 #include "base/macros.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "content/public/child/worker_thread.h" |
14 #include "content/public/renderer/render_frame.h" | 15 #include "content/public/renderer/render_frame.h" |
15 #include "extensions/renderer/extension_frame_helper.h" | 16 #include "extensions/renderer/extension_frame_helper.h" |
16 #include "extensions/renderer/script_context.h" | 17 #include "extensions/renderer/script_context.h" |
17 #include "extensions/renderer/script_context_set.h" | 18 #include "extensions/renderer/script_context_set.h" |
18 #include "extensions/renderer/v8_helpers.h" | 19 #include "extensions/renderer/v8_helpers.h" |
19 | 20 |
20 namespace extensions { | 21 namespace extensions { |
21 namespace console { | 22 namespace console { |
22 | 23 |
23 using namespace v8_helpers; | 24 using namespace v8_helpers; |
(...skipping 19 matching lines...) Expand all Loading... |
43 message += " "; | 44 message += " "; |
44 message += *v8::String::Utf8Value(info[i]); | 45 message += *v8::String::Utf8Value(info[i]); |
45 } | 46 } |
46 | 47 |
47 v8::Local<v8::Context> context = info.GetIsolate()->GetCurrentContext(); | 48 v8::Local<v8::Context> context = info.GetIsolate()->GetCurrentContext(); |
48 if (context.IsEmpty()) { | 49 if (context.IsEmpty()) { |
49 LOG(WARNING) << "Could not log \"" << message << "\": no context given"; | 50 LOG(WARNING) << "Could not log \"" << message << "\": no context given"; |
50 return; | 51 return; |
51 } | 52 } |
52 | 53 |
| 54 // A worker's ScriptContext neither lives in ScriptContextSet nor it has a |
| 55 // RenderFrame associated with it, so early exit in this case. |
| 56 // TODO(lazyboy): Fix. |
| 57 if (content::WorkerThread::GetCurrentId() > 0) |
| 58 return; |
| 59 |
53 ScriptContext* script_context = | 60 ScriptContext* script_context = |
54 ScriptContextSet::GetContextByV8Context(context); | 61 ScriptContextSet::GetContextByV8Context(context); |
55 LogMethod log_method = | 62 LogMethod log_method = |
56 reinterpret_cast<LogMethod>(info.Data().As<v8::External>()->Value()); | 63 reinterpret_cast<LogMethod>(info.Data().As<v8::External>()->Value()); |
57 (*log_method)(script_context ? script_context->GetRenderFrame() : nullptr, | 64 (*log_method)(script_context ? script_context->GetRenderFrame() : nullptr, |
58 message); | 65 message); |
59 } | 66 } |
60 | 67 |
61 void BindLogMethod(v8::Isolate* isolate, | 68 void BindLogMethod(v8::Isolate* isolate, |
62 v8::Local<v8::Object> target, | 69 v8::Local<v8::Object> target, |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 v8::Local<v8::Object> console_object = v8::Object::New(isolate); | 125 v8::Local<v8::Object> console_object = v8::Object::New(isolate); |
119 BindLogMethod(isolate, console_object, "debug", &Debug); | 126 BindLogMethod(isolate, console_object, "debug", &Debug); |
120 BindLogMethod(isolate, console_object, "log", &Log); | 127 BindLogMethod(isolate, console_object, "log", &Log); |
121 BindLogMethod(isolate, console_object, "warn", &Warn); | 128 BindLogMethod(isolate, console_object, "warn", &Warn); |
122 BindLogMethod(isolate, console_object, "error", &Error); | 129 BindLogMethod(isolate, console_object, "error", &Error); |
123 return handle_scope.Escape(console_object); | 130 return handle_scope.Escape(console_object); |
124 } | 131 } |
125 | 132 |
126 } // namespace console | 133 } // namespace console |
127 } // namespace extensions | 134 } // namespace extensions |
OLD | NEW |