| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (c) 2011 Google Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions are | |
| 6 * met: | |
| 7 * | |
| 8 * * Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * * Redistributions in binary form must reproduce the above | |
| 11 * copyright notice, this list of conditions and the following disclaimer | |
| 12 * in the documentation and/or other materials provided with the | |
| 13 * distribution. | |
| 14 * * Neither the name of Google Inc. nor the names of its | |
| 15 * contributors may be used to endorse or promote products derived from | |
| 16 * this software without specific prior written permission. | |
| 17 * | |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 29 */ | |
| 30 | |
| 31 #include "config.h" | |
| 32 #include "bindings/core/v8/MainThreadDebugger.h" | |
| 33 | |
| 34 #include "bindings/core/v8/DOMWrapperWorld.h" | |
| 35 #include "bindings/core/v8/ScriptController.h" | |
| 36 #include "bindings/core/v8/ScriptSourceCode.h" | |
| 37 #include "bindings/core/v8/V8Binding.h" | |
| 38 #include "bindings/core/v8/V8ScriptRunner.h" | |
| 39 #include "bindings/core/v8/WindowProxy.h" | |
| 40 #include "core/frame/FrameConsole.h" | |
| 41 #include "core/frame/FrameHost.h" | |
| 42 #include "core/frame/LocalFrame.h" | |
| 43 #include "core/frame/UseCounter.h" | |
| 44 #include "core/inspector/InspectorInstrumentation.h" | |
| 45 #include "core/inspector/InspectorTaskRunner.h" | |
| 46 #include "core/inspector/InspectorTraceEvents.h" | |
| 47 #include "core/inspector/ScriptDebugListener.h" | |
| 48 #include "core/page/Page.h" | |
| 49 #include "wtf/OwnPtr.h" | |
| 50 #include "wtf/PassOwnPtr.h" | |
| 51 #include "wtf/StdLibExtras.h" | |
| 52 #include "wtf/TemporaryChange.h" | |
| 53 #include "wtf/ThreadingPrimitives.h" | |
| 54 #include "wtf/text/StringBuilder.h" | |
| 55 | |
| 56 namespace blink { | |
| 57 | |
| 58 static LocalFrame* retrieveFrameWithGlobalObjectCheck(v8::Local<v8::Context> con
text) | |
| 59 { | |
| 60 return toLocalFrame(toFrameIfNotDetached(context)); | |
| 61 } | |
| 62 | |
| 63 // TODO(Oilpan): avoid keeping a raw reference separate from the | |
| 64 // owner one; does not enable heap-movable objects. | |
| 65 MainThreadDebugger* MainThreadDebugger::s_instance = nullptr; | |
| 66 | |
| 67 MainThreadDebugger::MainThreadDebugger(PassOwnPtr<ClientMessageLoop> clientMessa
geLoop, v8::Isolate* isolate) | |
| 68 : ScriptDebuggerBase(isolate, V8Debugger::create(isolate, this)) | |
| 69 , m_clientMessageLoop(clientMessageLoop) | |
| 70 , m_pausedFrame(nullptr) | |
| 71 , m_taskRunner(adoptPtr(new InspectorTaskRunner(isolate))) | |
| 72 { | |
| 73 MutexLocker locker(creationMutex()); | |
| 74 ASSERT(!s_instance); | |
| 75 s_instance = this; | |
| 76 } | |
| 77 | |
| 78 MainThreadDebugger::~MainThreadDebugger() | |
| 79 { | |
| 80 MutexLocker locker(creationMutex()); | |
| 81 ASSERT(s_instance == this); | |
| 82 s_instance = nullptr; | |
| 83 } | |
| 84 | |
| 85 Mutex& MainThreadDebugger::creationMutex() | |
| 86 { | |
| 87 AtomicallyInitializedStaticReference(Mutex, mutex, (new Mutex)); | |
| 88 return mutex; | |
| 89 } | |
| 90 | |
| 91 DEFINE_TRACE(MainThreadDebugger) | |
| 92 { | |
| 93 #if ENABLE(OILPAN) | |
| 94 visitor->trace(m_pausedFrame); | |
| 95 visitor->trace(m_listenersMap); | |
| 96 #endif | |
| 97 ScriptDebuggerBase::trace(visitor); | |
| 98 } | |
| 99 | |
| 100 void MainThreadDebugger::setContextDebugData(v8::Local<v8::Context> context, con
st String& type, int contextDebugId) | |
| 101 { | |
| 102 String debugData = "[" + type + "," + String::number(contextDebugId) + "]"; | |
| 103 V8Debugger::setContextDebugData(context, debugData); | |
| 104 } | |
| 105 | |
| 106 void MainThreadDebugger::addListener(ScriptDebugListener* listener, LocalFrame*
localFrameRoot, int contextDebugId) | |
| 107 { | |
| 108 ASSERT(localFrameRoot == localFrameRoot->localFrameRoot()); | |
| 109 | |
| 110 ScriptController& scriptController = localFrameRoot->script(); | |
| 111 if (!scriptController.canExecuteScripts(NotAboutToExecuteScript)) | |
| 112 return; | |
| 113 | |
| 114 if (m_listenersMap.isEmpty()) | |
| 115 debugger()->enable(); | |
| 116 m_listenersMap.set(localFrameRoot, listener); | |
| 117 String contextDataSubstring = "," + String::number(contextDebugId) + "]"; | |
| 118 debugger()->reportCompiledScripts(contextDataSubstring, listener); | |
| 119 } | |
| 120 | |
| 121 void MainThreadDebugger::removeListener(ScriptDebugListener* listener, LocalFram
e* localFrame) | |
| 122 { | |
| 123 if (!m_listenersMap.contains(localFrame)) | |
| 124 return; | |
| 125 | |
| 126 if (m_pausedFrame == localFrame) | |
| 127 debugger()->continueProgram(); | |
| 128 | |
| 129 m_listenersMap.remove(localFrame); | |
| 130 | |
| 131 if (m_listenersMap.isEmpty()) | |
| 132 debugger()->disable(); | |
| 133 } | |
| 134 | |
| 135 MainThreadDebugger* MainThreadDebugger::instance() | |
| 136 { | |
| 137 ASSERT(isMainThread()); | |
| 138 return s_instance; | |
| 139 } | |
| 140 | |
| 141 void MainThreadDebugger::interruptMainThreadAndRun(PassOwnPtr<InspectorTaskRunne
r::Task> task) | |
| 142 { | |
| 143 MutexLocker locker(creationMutex()); | |
| 144 if (s_instance) | |
| 145 s_instance->m_taskRunner->interruptAndRun(task); | |
| 146 } | |
| 147 | |
| 148 ScriptDebugListener* MainThreadDebugger::getDebugListenerForContext(v8::Local<v8
::Context> context) | |
| 149 { | |
| 150 v8::HandleScope scope(context->GetIsolate()); | |
| 151 LocalFrame* frame = retrieveFrameWithGlobalObjectCheck(context); | |
| 152 if (!frame) | |
| 153 return 0; | |
| 154 return m_listenersMap.get(frame->localFrameRoot()); | |
| 155 } | |
| 156 | |
| 157 void MainThreadDebugger::runMessageLoopOnPause(v8::Local<v8::Context> context) | |
| 158 { | |
| 159 v8::HandleScope scope(context->GetIsolate()); | |
| 160 LocalFrame* frame = retrieveFrameWithGlobalObjectCheck(context); | |
| 161 m_pausedFrame = frame->localFrameRoot(); | |
| 162 | |
| 163 // Wait for continue or step command. | |
| 164 m_clientMessageLoop->run(m_pausedFrame); | |
| 165 | |
| 166 // The listener may have been removed in the nested loop. | |
| 167 if (ScriptDebugListener* listener = m_listenersMap.get(m_pausedFrame)) | |
| 168 listener->didContinue(); | |
| 169 | |
| 170 m_pausedFrame = 0; | |
| 171 } | |
| 172 | |
| 173 void MainThreadDebugger::quitMessageLoopOnPause() | |
| 174 { | |
| 175 m_clientMessageLoop->quitNow(); | |
| 176 } | |
| 177 | |
| 178 } // namespace blink | |
| OLD | NEW |