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" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
47 // A worker's ScriptContext neither lives in ScriptContextSet nor it has a | 47 // A worker's ScriptContext neither lives in ScriptContextSet nor it has a |
48 // RenderFrame associated with it, so early exit in this case. | 48 // RenderFrame associated with it, so early exit in this case. |
49 // TODO(lazyboy): Fix. | 49 // TODO(lazyboy): Fix. |
50 if (content::WorkerThread::GetCurrentId() > 0) | 50 if (content::WorkerThread::GetCurrentId() > 0) |
51 return; | 51 return; |
52 | 52 |
53 v8::Local<v8::Context> context = info.GetIsolate()->GetCurrentContext(); | 53 v8::Local<v8::Context> context = info.GetIsolate()->GetCurrentContext(); |
54 ScriptContext* script_context = | 54 ScriptContext* script_context = |
55 ScriptContextSet::GetContextByV8Context(context); | 55 ScriptContextSet::GetContextByV8Context(context); |
56 // TODO(devlin): Consider (D)CHECK(script_context) | 56 // TODO(devlin): Consider (D)CHECK(script_context) |
57 content::RenderFrame* render_frame = | |
58 script_context ? script_context->GetRenderFrame() : nullptr; | |
59 const auto level = static_cast<content::ConsoleMessageLevel>( | 57 const auto level = static_cast<content::ConsoleMessageLevel>( |
60 info.Data().As<v8::Int32>()->Value()); | 58 info.Data().As<v8::Int32>()->Value()); |
61 AddMessage(render_frame, level, message); | 59 AddMessage(script_context, level, message); |
62 } | 60 } |
63 | 61 |
64 gin::WrapperInfo kWrapperInfo = {gin::kEmbedderNativeGin}; | 62 gin::WrapperInfo kWrapperInfo = {gin::kEmbedderNativeGin}; |
65 | 63 |
66 } // namespace | 64 } // namespace |
67 | 65 |
68 void Fatal(content::RenderFrame* render_frame, const std::string& message) { | 66 void Fatal(ScriptContext* context, const std::string& message) { |
69 AddMessage(render_frame, content::CONSOLE_MESSAGE_LEVEL_ERROR, message); | 67 AddMessage(context, content::CONSOLE_MESSAGE_LEVEL_ERROR, message); |
70 CheckWithMinidump(message); | 68 CheckWithMinidump(message); |
71 } | 69 } |
72 | 70 |
73 void AddMessage(content::RenderFrame* render_frame, | 71 void AddMessage(ScriptContext* script_context, |
74 content::ConsoleMessageLevel level, | 72 content::ConsoleMessageLevel level, |
75 const std::string& message) { | 73 const std::string& message) { |
76 if (!render_frame) { | 74 if (!script_context) { |
77 LOG(WARNING) << "Could not log \"" << message | 75 LOG(WARNING) << "Could not log \"" << message |
78 << "\": no render frame found"; | 76 << "\": no render frame found"; |
jbroman
2017/04/19 17:45:04
nit: no script context found?
Devlin
2017/04/19 19:45:33
Done.
| |
79 } else { | 77 } else { |
80 render_frame->AddMessageToConsole(level, message); | 78 script_context->AddMessageToConsole(level, message); |
81 } | 79 } |
82 } | 80 } |
83 | 81 |
84 v8::Local<v8::Object> AsV8Object(v8::Isolate* isolate) { | 82 v8::Local<v8::Object> AsV8Object(v8::Isolate* isolate) { |
85 v8::EscapableHandleScope handle_scope(isolate); | 83 v8::EscapableHandleScope handle_scope(isolate); |
86 gin::PerIsolateData* data = gin::PerIsolateData::From(isolate); | 84 gin::PerIsolateData* data = gin::PerIsolateData::From(isolate); |
87 v8::Local<v8::ObjectTemplate> templ = data->GetObjectTemplate(&kWrapperInfo); | 85 v8::Local<v8::ObjectTemplate> templ = data->GetObjectTemplate(&kWrapperInfo); |
88 if (templ.IsEmpty()) { | 86 if (templ.IsEmpty()) { |
89 templ = v8::ObjectTemplate::New(isolate); | 87 templ = v8::ObjectTemplate::New(isolate); |
90 static const struct { | 88 static const struct { |
(...skipping 13 matching lines...) Expand all Loading... | |
104 templ->Set(gin::StringToSymbol(isolate, method.name), function); | 102 templ->Set(gin::StringToSymbol(isolate, method.name), function); |
105 } | 103 } |
106 data->SetObjectTemplate(&kWrapperInfo, templ); | 104 data->SetObjectTemplate(&kWrapperInfo, templ); |
107 } | 105 } |
108 return handle_scope.Escape( | 106 return handle_scope.Escape( |
109 templ->NewInstance(isolate->GetCurrentContext()).ToLocalChecked()); | 107 templ->NewInstance(isolate->GetCurrentContext()).ToLocalChecked()); |
110 } | 108 } |
111 | 109 |
112 } // namespace console | 110 } // namespace console |
113 } // namespace extensions | 111 } // namespace extensions |
OLD | NEW |