| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2011 Google Inc. All rights reserved. | 2 * Copyright (c) 2011 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 #include "bindings/core/v8/ScriptController.h" | 35 #include "bindings/core/v8/ScriptController.h" |
| 36 #include "bindings/core/v8/SourceLocation.h" | 36 #include "bindings/core/v8/SourceLocation.h" |
| 37 #include "bindings/core/v8/V8Node.h" | 37 #include "bindings/core/v8/V8Node.h" |
| 38 #include "bindings/core/v8/V8Window.h" | 38 #include "bindings/core/v8/V8Window.h" |
| 39 #include "core/dom/ContainerNode.h" | 39 #include "core/dom/ContainerNode.h" |
| 40 #include "core/dom/Document.h" | 40 #include "core/dom/Document.h" |
| 41 #include "core/dom/Element.h" | 41 #include "core/dom/Element.h" |
| 42 #include "core/dom/ExecutionContext.h" | 42 #include "core/dom/ExecutionContext.h" |
| 43 #include "core/dom/StaticNodeList.h" | 43 #include "core/dom/StaticNodeList.h" |
| 44 #include "core/frame/FrameConsole.h" | 44 #include "core/frame/FrameConsole.h" |
| 45 #include "core/frame/FrameHost.h" |
| 45 #include "core/frame/LocalDOMWindow.h" | 46 #include "core/frame/LocalDOMWindow.h" |
| 46 #include "core/frame/LocalFrame.h" | 47 #include "core/frame/LocalFrame.h" |
| 47 #include "core/frame/UseCounter.h" | 48 #include "core/frame/UseCounter.h" |
| 48 #include "core/inspector/ConsoleMessage.h" | 49 #include "core/inspector/ConsoleMessage.h" |
| 50 #include "core/inspector/ConsoleMessageStorage.h" |
| 49 #include "core/inspector/IdentifiersFactory.h" | 51 #include "core/inspector/IdentifiersFactory.h" |
| 50 #include "core/inspector/InspectedFrames.h" | 52 #include "core/inspector/InspectedFrames.h" |
| 51 #include "core/inspector/InspectorTaskRunner.h" | 53 #include "core/inspector/InspectorTaskRunner.h" |
| 52 #include "core/timing/MemoryInfo.h" | 54 #include "core/timing/MemoryInfo.h" |
| 53 #include "core/workers/MainThreadWorkletGlobalScope.h" | 55 #include "core/workers/MainThreadWorkletGlobalScope.h" |
| 54 #include "core/xml/XPathEvaluator.h" | 56 #include "core/xml/XPathEvaluator.h" |
| 55 #include "core/xml/XPathResult.h" | 57 #include "core/xml/XPathResult.h" |
| 56 #include "platform/UserGestureIndicator.h" | 58 #include "platform/UserGestureIndicator.h" |
| 57 #include "platform/v8_inspector/public/V8Debugger.h" | 59 #include "platform/v8_inspector/public/V8Debugger.h" |
| 58 #include "wtf/PtrUtil.h" | 60 #include "wtf/PtrUtil.h" |
| 59 #include "wtf/ThreadingPrimitives.h" | 61 #include "wtf/ThreadingPrimitives.h" |
| 60 #include <memory> | 62 #include <memory> |
| 61 | 63 |
| 62 namespace blink { | 64 namespace blink { |
| 63 | 65 |
| 64 namespace { | 66 namespace { |
| 65 | 67 |
| 66 int frameId(LocalFrame* frame) | 68 int frameId(LocalFrame* frame) |
| 67 { | 69 { |
| 68 ASSERT(frame); | 70 ASSERT(frame); |
| 69 return WeakIdentifierMap<LocalFrame>::identifier(frame); | 71 return WeakIdentifierMap<LocalFrame>::identifier(frame); |
| 70 } | 72 } |
| 71 | 73 |
| 72 Mutex& creationMutex() | 74 Mutex& creationMutex() |
| 73 { | 75 { |
| 74 DEFINE_THREAD_SAFE_STATIC_LOCAL(Mutex, mutex, (new Mutex)); | 76 DEFINE_THREAD_SAFE_STATIC_LOCAL(Mutex, mutex, (new Mutex)); |
| 75 return mutex; | 77 return mutex; |
| 76 } | 78 } |
| 77 | 79 |
| 80 LocalFrame* toFrame(ExecutionContext* context) |
| 81 { |
| 82 if (!context) |
| 83 return nullptr; |
| 84 if (context->isDocument()) |
| 85 return toDocument(context)->frame(); |
| 86 if (context->isMainThreadWorkletGlobalScope()) |
| 87 return toMainThreadWorkletGlobalScope(context)->frame(); |
| 88 return nullptr; |
| 89 } |
| 90 |
| 78 } | 91 } |
| 79 | 92 |
| 80 MainThreadDebugger* MainThreadDebugger::s_instance = nullptr; | 93 MainThreadDebugger* MainThreadDebugger::s_instance = nullptr; |
| 81 | 94 |
| 82 MainThreadDebugger::MainThreadDebugger(v8::Isolate* isolate) | 95 MainThreadDebugger::MainThreadDebugger(v8::Isolate* isolate) |
| 83 : ThreadDebugger(isolate) | 96 : ThreadDebugger(isolate) |
| 84 , m_taskRunner(wrapUnique(new InspectorTaskRunner())) | 97 , m_taskRunner(wrapUnique(new InspectorTaskRunner())) |
| 85 , m_paused(false) | 98 , m_paused(false) |
| 86 , m_muteConsoleCount(0) | |
| 87 { | 99 { |
| 88 MutexLocker locker(creationMutex()); | 100 MutexLocker locker(creationMutex()); |
| 89 ASSERT(!s_instance); | 101 ASSERT(!s_instance); |
| 90 s_instance = this; | 102 s_instance = this; |
| 91 } | 103 } |
| 92 | 104 |
| 93 MainThreadDebugger::~MainThreadDebugger() | 105 MainThreadDebugger::~MainThreadDebugger() |
| 94 { | 106 { |
| 95 MutexLocker locker(creationMutex()); | 107 MutexLocker locker(creationMutex()); |
| 96 ASSERT(s_instance == this); | 108 ASSERT(s_instance == this); |
| 97 s_instance = nullptr; | 109 s_instance = nullptr; |
| 98 } | 110 } |
| 99 | 111 |
| 100 void MainThreadDebugger::reportConsoleMessage(ExecutionContext* context, Console
Message* message) | 112 void MainThreadDebugger::reportConsoleMessage(ExecutionContext* context, Console
Message* message) |
| 101 { | 113 { |
| 102 if (!context) | 114 if (LocalFrame* frame = toFrame(context)) |
| 103 return; | |
| 104 LocalFrame* frame = nullptr; | |
| 105 if (context->isDocument()) | |
| 106 frame = toDocument(context)->frame(); | |
| 107 if (context->isMainThreadWorkletGlobalScope()) | |
| 108 frame = toMainThreadWorkletGlobalScope(context)->frame(); | |
| 109 if (frame) | |
| 110 frame->console().reportMessageToClient(message); | 115 frame->console().reportMessageToClient(message); |
| 111 } | 116 } |
| 112 | 117 |
| 118 int MainThreadDebugger::contextGroupId(ExecutionContext* context) |
| 119 { |
| 120 LocalFrame* frame = toFrame(context); |
| 121 return frame ? contextGroupId(frame) : 0; |
| 122 } |
| 123 |
| 113 void MainThreadDebugger::setClientMessageLoop(std::unique_ptr<ClientMessageLoop>
clientMessageLoop) | 124 void MainThreadDebugger::setClientMessageLoop(std::unique_ptr<ClientMessageLoop>
clientMessageLoop) |
| 114 { | 125 { |
| 115 ASSERT(!m_clientMessageLoop); | 126 ASSERT(!m_clientMessageLoop); |
| 116 ASSERT(clientMessageLoop); | 127 ASSERT(clientMessageLoop); |
| 117 m_clientMessageLoop = std::move(clientMessageLoop); | 128 m_clientMessageLoop = std::move(clientMessageLoop); |
| 118 } | 129 } |
| 119 | 130 |
| 120 void MainThreadDebugger::didClearContextsForFrame(LocalFrame* frame) | 131 void MainThreadDebugger::didClearContextsForFrame(LocalFrame* frame) |
| 121 { | 132 { |
| 122 DCHECK(isMainThread()); | 133 DCHECK(isMainThread()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 133 } | 144 } |
| 134 | 145 |
| 135 void MainThreadDebugger::contextWillBeDestroyed(ScriptState* scriptState) | 146 void MainThreadDebugger::contextWillBeDestroyed(ScriptState* scriptState) |
| 136 { | 147 { |
| 137 v8::HandleScope handles(scriptState->isolate()); | 148 v8::HandleScope handles(scriptState->isolate()); |
| 138 debugger()->contextDestroyed(scriptState->context()); | 149 debugger()->contextDestroyed(scriptState->context()); |
| 139 } | 150 } |
| 140 | 151 |
| 141 void MainThreadDebugger::exceptionThrown(LocalFrame* frame, const String& errorM
essage, std::unique_ptr<SourceLocation> location) | 152 void MainThreadDebugger::exceptionThrown(LocalFrame* frame, const String& errorM
essage, std::unique_ptr<SourceLocation> location) |
| 142 { | 153 { |
| 143 if (m_muteConsoleCount) | 154 if (frame->host() && frame->host()->consoleMessageStorage().isMuted()) |
| 144 return; | 155 return; |
| 145 debugger()->exceptionThrown(contextGroupId(frame), errorMessage, location->u
rl(), location->lineNumber(), location->columnNumber(), location->cloneStackTrac
e(), location->scriptId()); | 156 debugger()->exceptionThrown(contextGroupId(frame), errorMessage, location->u
rl(), location->lineNumber(), location->columnNumber(), location->cloneStackTrac
e(), location->scriptId()); |
| 146 frame->console().reportMessageToClient(ConsoleMessage::create(JSMessageSourc
e, ErrorMessageLevel, errorMessage, std::move(location))); | 157 frame->console().reportMessageToClient(ConsoleMessage::create(JSMessageSourc
e, ErrorMessageLevel, errorMessage, std::move(location))); |
| 147 } | 158 } |
| 148 | 159 |
| 149 bool MainThreadDebugger::addConsoleMessage(LocalFrame* frame, ConsoleMessage* co
nsoleMessage) | |
| 150 { | |
| 151 if (m_muteConsoleCount) | |
| 152 return false; | |
| 153 debugger()->addConsoleMessage( | |
| 154 contextGroupId(frame), | |
| 155 consoleMessage->source(), | |
| 156 consoleMessage->level(), | |
| 157 consoleMessage->message(), | |
| 158 consoleMessage->location()->url(), | |
| 159 consoleMessage->location()->lineNumber(), | |
| 160 consoleMessage->location()->columnNumber(), | |
| 161 consoleMessage->location()->cloneStackTrace(), | |
| 162 consoleMessage->location()->scriptId(), | |
| 163 IdentifiersFactory::requestId(consoleMessage->requestIdentifier()), | |
| 164 consoleMessage->workerId()); | |
| 165 return true; | |
| 166 } | |
| 167 | |
| 168 int MainThreadDebugger::contextGroupId(LocalFrame* frame) | 160 int MainThreadDebugger::contextGroupId(LocalFrame* frame) |
| 169 { | 161 { |
| 170 LocalFrame* localFrameRoot = frame->localFrameRoot(); | 162 LocalFrame* localFrameRoot = frame->localFrameRoot(); |
| 171 return frameId(localFrameRoot); | 163 return frameId(localFrameRoot); |
| 172 } | 164 } |
| 173 | 165 |
| 174 MainThreadDebugger* MainThreadDebugger::instance() | 166 MainThreadDebugger* MainThreadDebugger::instance() |
| 175 { | 167 { |
| 176 ASSERT(isMainThread()); | 168 ASSERT(isMainThread()); |
| 177 V8PerIsolateData* data = V8PerIsolateData::from(V8PerIsolateData::mainThread
Isolate()); | 169 V8PerIsolateData* data = V8PerIsolateData::from(V8PerIsolateData::mainThread
Isolate()); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 204 m_clientMessageLoop->run(pausedFrame); | 196 m_clientMessageLoop->run(pausedFrame); |
| 205 } | 197 } |
| 206 | 198 |
| 207 void MainThreadDebugger::quitMessageLoopOnPause() | 199 void MainThreadDebugger::quitMessageLoopOnPause() |
| 208 { | 200 { |
| 209 m_paused = false; | 201 m_paused = false; |
| 210 if (m_clientMessageLoop) | 202 if (m_clientMessageLoop) |
| 211 m_clientMessageLoop->quitNow(); | 203 m_clientMessageLoop->quitNow(); |
| 212 } | 204 } |
| 213 | 205 |
| 214 void MainThreadDebugger::muteWarningsAndDeprecations() | 206 void MainThreadDebugger::muteWarningsAndDeprecations(int contextGroupId) |
| 215 { | 207 { |
| 216 UseCounter::muteForInspector(); | 208 UseCounter::muteForInspector(); |
| 217 m_muteConsoleCount++; | 209 LocalFrame* frame = WeakIdentifierMap<LocalFrame>::lookup(contextGroupId); |
| 210 if (frame && frame->host()) |
| 211 frame->host()->consoleMessageStorage().mute(); |
| 218 } | 212 } |
| 219 | 213 |
| 220 void MainThreadDebugger::unmuteWarningsAndDeprecations() | 214 void MainThreadDebugger::unmuteWarningsAndDeprecations(int contextGroupId) |
| 221 { | 215 { |
| 222 UseCounter::unmuteForInspector(); | 216 UseCounter::unmuteForInspector(); |
| 223 m_muteConsoleCount--; | 217 LocalFrame* frame = WeakIdentifierMap<LocalFrame>::lookup(contextGroupId); |
| 218 if (frame && frame->host()) |
| 219 frame->host()->consoleMessageStorage().unmute(); |
| 224 } | 220 } |
| 225 | 221 |
| 226 bool MainThreadDebugger::callingContextCanAccessContext(v8::Local<v8::Context> c
alling, v8::Local<v8::Context> target) | 222 bool MainThreadDebugger::callingContextCanAccessContext(v8::Local<v8::Context> c
alling, v8::Local<v8::Context> target) |
| 227 { | 223 { |
| 228 return BindingSecurity::shouldAllowAccessTo(m_isolate, calling, target, DoNo
tReportSecurityError); | 224 return BindingSecurity::shouldAllowAccessTo(m_isolate, calling, target, DoNo
tReportSecurityError); |
| 229 } | 225 } |
| 230 | 226 |
| 231 v8::Local<v8::Context> MainThreadDebugger::ensureDefaultContextInGroup(int conte
xtGroupId) | 227 v8::Local<v8::Context> MainThreadDebugger::ensureDefaultContextInGroup(int conte
xtGroupId) |
| 232 { | 228 { |
| 233 LocalFrame* frame = WeakIdentifierMap<LocalFrame>::lookup(contextGroupId); | 229 LocalFrame* frame = WeakIdentifierMap<LocalFrame>::lookup(contextGroupId); |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 return; | 346 return; |
| 351 if (!nodes->Set(context, index++, toV8(node, info.Holder(), info.Get
Isolate())).FromMaybe(false)) | 347 if (!nodes->Set(context, index++, toV8(node, info.Holder(), info.Get
Isolate())).FromMaybe(false)) |
| 352 return; | 348 return; |
| 353 } | 349 } |
| 354 info.GetReturnValue().Set(nodes); | 350 info.GetReturnValue().Set(nodes); |
| 355 } | 351 } |
| 356 exceptionState.throwIfNeeded(); | 352 exceptionState.throwIfNeeded(); |
| 357 } | 353 } |
| 358 | 354 |
| 359 } // namespace blink | 355 } // namespace blink |
| OLD | NEW |