| 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/module_system.h" | 5 #include "extensions/renderer/module_system.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.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/trace_event/trace_event.h" | 13 #include "base/trace_event/trace_event.h" |
| 14 #include "content/public/renderer/render_frame.h" | 14 #include "content/public/renderer/render_frame.h" |
| 15 #include "content/public/renderer/render_view.h" | 15 #include "content/public/renderer/render_view.h" |
| 16 #include "extensions/common/extension.h" | 16 #include "extensions/common/extension.h" |
| 17 #include "extensions/common/extensions_client.h" | 17 #include "extensions/common/extensions_client.h" |
| 18 #include "extensions/renderer/console.h" | 18 #include "extensions/renderer/console.h" |
| 19 #include "extensions/renderer/safe_builtins.h" | 19 #include "extensions/renderer/safe_builtins.h" |
| 20 #include "extensions/renderer/script_context.h" | 20 #include "extensions/renderer/script_context.h" |
| 21 #include "extensions/renderer/script_context_set.h" |
| 21 #include "extensions/renderer/v8_helpers.h" | 22 #include "extensions/renderer/v8_helpers.h" |
| 22 #include "gin/modules/module_registry.h" | 23 #include "gin/modules/module_registry.h" |
| 23 #include "third_party/WebKit/public/web/WebFrame.h" | 24 #include "third_party/WebKit/public/web/WebFrame.h" |
| 24 #include "third_party/WebKit/public/web/WebScopedMicrotaskSuppression.h" | 25 #include "third_party/WebKit/public/web/WebScopedMicrotaskSuppression.h" |
| 25 | 26 |
| 26 namespace extensions { | 27 namespace extensions { |
| 27 | 28 |
| 28 using namespace v8_helpers; | 29 using namespace v8_helpers; |
| 29 | 30 |
| 30 namespace { | 31 namespace { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 50 full_message += " context"; | 51 full_message += " context"; |
| 51 if (context->extension()) { | 52 if (context->extension()) { |
| 52 full_message += " for "; | 53 full_message += " for "; |
| 53 full_message += context->extension()->id(); | 54 full_message += context->extension()->id(); |
| 54 } | 55 } |
| 55 full_message += ") "; | 56 full_message += ") "; |
| 56 full_message += message; | 57 full_message += message; |
| 57 | 58 |
| 58 ExtensionsClient* client = ExtensionsClient::Get(); | 59 ExtensionsClient* client = ExtensionsClient::Get(); |
| 59 if (client->ShouldSuppressFatalErrors()) { | 60 if (client->ShouldSuppressFatalErrors()) { |
| 60 console::Error(context->isolate()->GetCallingContext(), full_message); | 61 console::Error(context->GetRenderFrame(), full_message); |
| 61 client->RecordDidSuppressFatalError(); | 62 client->RecordDidSuppressFatalError(); |
| 62 } else { | 63 } else { |
| 63 console::Fatal(context->isolate()->GetCallingContext(), full_message); | 64 console::Fatal(context->GetRenderFrame(), full_message); |
| 64 } | 65 } |
| 65 } | 66 } |
| 66 | 67 |
| 67 void Warn(v8::Isolate* isolate, const std::string& message) { | 68 void Warn(v8::Isolate* isolate, const std::string& message) { |
| 68 console::Warn(isolate->GetCallingContext(), message); | 69 ScriptContext* script_context = |
| 70 ScriptContextSet::GetContextByV8Context(isolate->GetCallingContext()); |
| 71 console::Warn(script_context ? script_context->GetRenderFrame() : nullptr, |
| 72 message); |
| 69 } | 73 } |
| 70 | 74 |
| 71 // Default exception handler which logs the exception. | 75 // Default exception handler which logs the exception. |
| 72 class DefaultExceptionHandler : public ModuleSystem::ExceptionHandler { | 76 class DefaultExceptionHandler : public ModuleSystem::ExceptionHandler { |
| 73 public: | 77 public: |
| 74 explicit DefaultExceptionHandler(ScriptContext* context) | 78 explicit DefaultExceptionHandler(ScriptContext* context) |
| 75 : ModuleSystem::ExceptionHandler(context) {} | 79 : ModuleSystem::ExceptionHandler(context) {} |
| 76 | 80 |
| 77 // Fatally dumps the debug info from |try_catch| to the console. | 81 // Fatally dumps the debug info from |try_catch| to the console. |
| 78 // Make sure this is never used for exceptions that originate in external | 82 // Make sure this is never used for exceptions that originate in external |
| (...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 738 | 742 |
| 739 void ModuleSystem::ClobberExistingNativeHandler(const std::string& name) { | 743 void ModuleSystem::ClobberExistingNativeHandler(const std::string& name) { |
| 740 NativeHandlerMap::iterator existing_handler = native_handler_map_.find(name); | 744 NativeHandlerMap::iterator existing_handler = native_handler_map_.find(name); |
| 741 if (existing_handler != native_handler_map_.end()) { | 745 if (existing_handler != native_handler_map_.end()) { |
| 742 clobbered_native_handlers_.push_back(existing_handler->second); | 746 clobbered_native_handlers_.push_back(existing_handler->second); |
| 743 native_handler_map_.erase(existing_handler); | 747 native_handler_map_.erase(existing_handler); |
| 744 } | 748 } |
| 745 } | 749 } |
| 746 | 750 |
| 747 } // namespace extensions | 751 } // namespace extensions |
| OLD | NEW |