| 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 27 matching lines...) Expand all Loading... |
| 38 #include "core/frame/FrameConsole.h" | 38 #include "core/frame/FrameConsole.h" |
| 39 #include "core/frame/LocalDOMWindow.h" | 39 #include "core/frame/LocalDOMWindow.h" |
| 40 #include "core/frame/LocalFrame.h" | 40 #include "core/frame/LocalFrame.h" |
| 41 #include "core/frame/UseCounter.h" | 41 #include "core/frame/UseCounter.h" |
| 42 #include "core/inspector/IdentifiersFactory.h" | 42 #include "core/inspector/IdentifiersFactory.h" |
| 43 #include "core/inspector/InspectedFrames.h" | 43 #include "core/inspector/InspectedFrames.h" |
| 44 #include "core/inspector/InspectorTaskRunner.h" | 44 #include "core/inspector/InspectorTaskRunner.h" |
| 45 #include "core/workers/MainThreadWorkletGlobalScope.h" | 45 #include "core/workers/MainThreadWorkletGlobalScope.h" |
| 46 #include "platform/UserGestureIndicator.h" | 46 #include "platform/UserGestureIndicator.h" |
| 47 #include "platform/v8_inspector/public/V8Debugger.h" | 47 #include "platform/v8_inspector/public/V8Debugger.h" |
| 48 #include "public/platform/Platform.h" |
| 48 #include "wtf/OwnPtr.h" | 49 #include "wtf/OwnPtr.h" |
| 49 #include "wtf/PassOwnPtr.h" | 50 #include "wtf/PassOwnPtr.h" |
| 50 #include "wtf/ThreadingPrimitives.h" | 51 #include "wtf/ThreadingPrimitives.h" |
| 51 | 52 |
| 52 namespace blink { | 53 namespace blink { |
| 53 | 54 |
| 54 namespace { | 55 namespace { |
| 55 | 56 |
| 56 int frameId(LocalFrame* frame) | 57 int frameId(LocalFrame* frame) |
| 57 { | 58 { |
| 58 ASSERT(frame); | 59 ASSERT(frame); |
| 59 return WeakIdentifierMap<LocalFrame>::identifier(frame); | 60 return WeakIdentifierMap<LocalFrame>::identifier(frame); |
| 60 } | 61 } |
| 61 | 62 |
| 63 Mutex& creationMutex() |
| 64 { |
| 65 DEFINE_THREAD_SAFE_STATIC_LOCAL(Mutex, mutex, (new Mutex)); |
| 66 return mutex; |
| 67 } |
| 68 |
| 62 } | 69 } |
| 63 | 70 |
| 64 // TODO(Oilpan): avoid keeping a raw reference separate from the | 71 // TODO(Oilpan): avoid keeping a raw reference separate from the |
| 65 // owner one; does not enable heap-movable objects. | 72 // owner one; does not enable heap-movable objects. |
| 66 MainThreadDebugger* MainThreadDebugger::s_instance = nullptr; | 73 MainThreadDebugger* MainThreadDebugger::s_instance = nullptr; |
| 67 | 74 |
| 68 MainThreadDebugger::MainThreadDebugger(PassOwnPtr<ClientMessageLoop> clientMessa
geLoop, v8::Isolate* isolate) | 75 MainThreadDebugger::MainThreadDebugger(v8::Isolate* isolate) |
| 69 : ThreadDebugger(isolate) | 76 : ThreadDebugger(isolate) |
| 70 , m_clientMessageLoop(clientMessageLoop) | |
| 71 , m_taskRunner(adoptPtr(new InspectorTaskRunner())) | 77 , m_taskRunner(adoptPtr(new InspectorTaskRunner())) |
| 72 { | 78 { |
| 73 MutexLocker locker(creationMutex()); | 79 MutexLocker locker(creationMutex()); |
| 74 ASSERT(!s_instance); | 80 ASSERT(!s_instance); |
| 75 s_instance = this; | 81 s_instance = this; |
| 82 IdentifiersFactory::setProcessId(Platform::current()->getUniqueIdForProcess(
)); |
| 76 } | 83 } |
| 77 | 84 |
| 78 MainThreadDebugger::~MainThreadDebugger() | 85 MainThreadDebugger::~MainThreadDebugger() |
| 79 { | 86 { |
| 80 MutexLocker locker(creationMutex()); | 87 MutexLocker locker(creationMutex()); |
| 81 ASSERT(s_instance == this); | 88 ASSERT(s_instance == this); |
| 82 s_instance = nullptr; | 89 s_instance = nullptr; |
| 83 } | 90 } |
| 84 | 91 |
| 85 Mutex& MainThreadDebugger::creationMutex() | 92 void MainThreadDebugger::setClientMessageLoop(PassOwnPtr<ClientMessageLoop> clie
ntMessageLoop) |
| 86 { | 93 { |
| 87 DEFINE_THREAD_SAFE_STATIC_LOCAL(Mutex, mutex, (new Mutex)); | 94 ASSERT(!m_clientMessageLoop); |
| 88 return mutex; | 95 ASSERT(clientMessageLoop); |
| 96 m_clientMessageLoop = clientMessageLoop; |
| 89 } | 97 } |
| 90 | 98 |
| 91 void MainThreadDebugger::contextCreated(ScriptState* scriptState, LocalFrame* fr
ame, SecurityOrigin* origin) | 99 void MainThreadDebugger::contextCreated(ScriptState* scriptState, LocalFrame* fr
ame, SecurityOrigin* origin) |
| 92 { | 100 { |
| 93 ASSERT(isMainThread()); | 101 ASSERT(isMainThread()); |
| 94 v8::HandleScope handles(scriptState->isolate()); | 102 v8::HandleScope handles(scriptState->isolate()); |
| 95 DOMWrapperWorld& world = scriptState->world(); | 103 DOMWrapperWorld& world = scriptState->world(); |
| 96 V8Debugger::setContextDebugData(scriptState->context(), world.isMainWorld()
? "page" : "injected", contextGroupId(frame)); | 104 if (frame->localFrameRoot() == frame && world.isMainWorld()) |
| 97 if (s_instance) { | 105 debugger()->resetContextGroup(contextGroupId(frame)); |
| 98 if (frame->localFrameRoot() == frame && world.isMainWorld()) | 106 debugger()->contextCreated(V8ContextInfo(scriptState->context(), contextGrou
pId(frame), world.isMainWorld(), origin ? origin->toRawString() : "", world.isIs
olatedWorld() ? world.isolatedWorldHumanReadableName() : "", IdentifiersFactory:
:frameId(frame))); |
| 99 s_instance->debugger()->resetContextGroup(contextGroupId(frame)); | |
| 100 s_instance->debugger()->contextCreated(V8ContextInfo(scriptState->contex
t(), world.isMainWorld(), origin ? origin->toRawString() : "", world.isIsolatedW
orld() ? world.isolatedWorldHumanReadableName() : "", IdentifiersFactory::frameI
d(frame))); | |
| 101 } | |
| 102 } | 107 } |
| 103 | 108 |
| 104 void MainThreadDebugger::contextWillBeDestroyed(ScriptState* scriptState) | 109 void MainThreadDebugger::contextWillBeDestroyed(ScriptState* scriptState) |
| 105 { | 110 { |
| 106 if (s_instance) { | 111 v8::HandleScope handles(scriptState->isolate()); |
| 107 v8::HandleScope handles(scriptState->isolate()); | 112 debugger()->contextDestroyed(scriptState->context()); |
| 108 s_instance->debugger()->contextDestroyed(scriptState->context()); | |
| 109 } | |
| 110 } | 113 } |
| 111 | 114 |
| 112 int MainThreadDebugger::contextGroupId(LocalFrame* frame) | 115 int MainThreadDebugger::contextGroupId(LocalFrame* frame) |
| 113 { | 116 { |
| 114 LocalFrame* localFrameRoot = frame->localFrameRoot(); | 117 LocalFrame* localFrameRoot = frame->localFrameRoot(); |
| 115 return frameId(localFrameRoot); | 118 return frameId(localFrameRoot); |
| 116 } | 119 } |
| 117 | 120 |
| 118 MainThreadDebugger* MainThreadDebugger::instance() | 121 MainThreadDebugger* MainThreadDebugger::instance() |
| 119 { | 122 { |
| 120 ASSERT(isMainThread()); | 123 ASSERT(isMainThread()); |
| 121 return s_instance; | 124 v8::Isolate* isolate = V8PerIsolateData::mainThreadIsolate(); |
| 125 V8PerIsolateData* data = V8PerIsolateData::from(isolate); |
| 126 return static_cast<MainThreadDebugger*>(data->threadDebugger()); |
| 122 } | 127 } |
| 123 | 128 |
| 124 void MainThreadDebugger::interruptMainThreadAndRun(PassOwnPtr<InspectorTaskRunne
r::Task> task) | 129 void MainThreadDebugger::interruptMainThreadAndRun(PassOwnPtr<InspectorTaskRunne
r::Task> task) |
| 125 { | 130 { |
| 126 MutexLocker locker(creationMutex()); | 131 MutexLocker locker(creationMutex()); |
| 127 if (s_instance) { | 132 if (s_instance) { |
| 128 s_instance->m_taskRunner->appendTask(task); | 133 s_instance->m_taskRunner->appendTask(task); |
| 129 s_instance->m_taskRunner->interruptAndRunAllTasksDontWait(s_instance->m_
isolate); | 134 s_instance->m_taskRunner->interruptAndRunAllTasksDontWait(s_instance->m_
isolate); |
| 130 } | 135 } |
| 131 } | 136 } |
| 132 | 137 |
| 133 void MainThreadDebugger::runMessageLoopOnPause(int contextGroupId) | 138 void MainThreadDebugger::runMessageLoopOnPause(int contextGroupId) |
| 134 { | 139 { |
| 135 LocalFrame* pausedFrame = WeakIdentifierMap<LocalFrame>::lookup(contextGroup
Id); | 140 LocalFrame* pausedFrame = WeakIdentifierMap<LocalFrame>::lookup(contextGroup
Id); |
| 136 // Do not pause in Context of detached frame. | 141 // Do not pause in Context of detached frame. |
| 137 if (!pausedFrame) | 142 if (!pausedFrame) |
| 138 return; | 143 return; |
| 139 ASSERT(pausedFrame == pausedFrame->localFrameRoot()); | 144 ASSERT(pausedFrame == pausedFrame->localFrameRoot()); |
| 140 | 145 |
| 141 if (UserGestureToken* token = UserGestureIndicator::currentToken()) | 146 if (UserGestureToken* token = UserGestureIndicator::currentToken()) |
| 142 token->setPauseInDebugger(); | 147 token->setPauseInDebugger(); |
| 143 // Wait for continue or step command. | 148 // Wait for continue or step command. |
| 144 m_clientMessageLoop->run(pausedFrame); | 149 if (m_clientMessageLoop) |
| 150 m_clientMessageLoop->run(pausedFrame); |
| 145 } | 151 } |
| 146 | 152 |
| 147 void MainThreadDebugger::quitMessageLoopOnPause() | 153 void MainThreadDebugger::quitMessageLoopOnPause() |
| 148 { | 154 { |
| 149 m_clientMessageLoop->quitNow(); | 155 if (m_clientMessageLoop) |
| 156 m_clientMessageLoop->quitNow(); |
| 150 } | 157 } |
| 151 | 158 |
| 152 void MainThreadDebugger::muteWarningsAndDeprecations() | 159 void MainThreadDebugger::muteWarningsAndDeprecations() |
| 153 { | 160 { |
| 154 FrameConsole::mute(); | 161 FrameConsole::mute(); |
| 155 UseCounter::muteForInspector(); | 162 UseCounter::muteForInspector(); |
| 156 } | 163 } |
| 157 | 164 |
| 158 void MainThreadDebugger::unmuteWarningsAndDeprecations() | 165 void MainThreadDebugger::unmuteWarningsAndDeprecations() |
| 159 { | 166 { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 Vector<std::pair<ScriptState*, SecurityOrigin*>> isolatedContexts; | 199 Vector<std::pair<ScriptState*, SecurityOrigin*>> isolatedContexts; |
| 193 for (LocalFrame* frame : *inspectedFrames) { | 200 for (LocalFrame* frame : *inspectedFrames) { |
| 194 if (!frame->script().canExecuteScripts(NotAboutToExecuteScript)) | 201 if (!frame->script().canExecuteScripts(NotAboutToExecuteScript)) |
| 195 continue; | 202 continue; |
| 196 String frameId = IdentifiersFactory::frameId(frame); | 203 String frameId = IdentifiersFactory::frameId(frame); |
| 197 | 204 |
| 198 // Ensure execution context is created. | 205 // Ensure execution context is created. |
| 199 // If initializeMainWorld returns true, then is registered by didCreateS
criptContext | 206 // If initializeMainWorld returns true, then is registered by didCreateS
criptContext |
| 200 if (!frame->script().initializeMainWorld()) { | 207 if (!frame->script().initializeMainWorld()) { |
| 201 ScriptState* scriptState = ScriptState::forMainWorld(frame); | 208 ScriptState* scriptState = ScriptState::forMainWorld(frame); |
| 202 contexts.append(V8ContextInfo(scriptState->context(), true, "", "",
frameId)); | 209 contexts.append(V8ContextInfo(scriptState->context(), contextGroupId
, true, "", "", frameId)); |
| 203 } | 210 } |
| 204 frame->script().collectIsolatedContexts(isolatedContexts); | 211 frame->script().collectIsolatedContexts(isolatedContexts); |
| 205 if (isolatedContexts.isEmpty()) | 212 if (isolatedContexts.isEmpty()) |
| 206 continue; | 213 continue; |
| 207 for (const auto& pair : isolatedContexts) { | 214 for (const auto& pair : isolatedContexts) { |
| 208 String originString = pair.second ? pair.second->toRawString() : ""; | 215 String originString = pair.second ? pair.second->toRawString() : ""; |
| 209 ScriptState* scriptState = pair.first; | 216 ScriptState* scriptState = pair.first; |
| 210 contexts.append(V8ContextInfo(scriptState->context(), false, originS
tring, scriptState->world().isolatedWorldHumanReadableName(), frameId)); | 217 contexts.append(V8ContextInfo(scriptState->context(), contextGroupId
, false, originString, scriptState->world().isolatedWorldHumanReadableName(), fr
ameId)); |
| 211 } | 218 } |
| 212 isolatedContexts.clear(); | 219 isolatedContexts.clear(); |
| 213 } | 220 } |
| 214 } | 221 } |
| 215 | 222 |
| 216 } // namespace blink | 223 } // namespace blink |
| OLD | NEW |