Chromium Code Reviews| 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 10 matching lines...) Expand all Loading... | |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "sky/engine/config.h" |
| 32 #include "bindings/core/v8/PageScriptDebugServer.h" | 32 #include "sky/engine/bindings/core/v8/PageScriptDebugServer.h" |
| 33 | 33 |
| 34 #include "bindings/core/v8/DOMWrapperWorld.h" | 34 #include "gen/sky/bindings/core/v8/V8Window.h" |
| 35 #include "bindings/core/v8/ScriptController.h" | 35 #include "sky/engine/bindings/core/v8/DOMWrapperWorld.h" |
| 36 #include "bindings/core/v8/ScriptSourceCode.h" | 36 #include "sky/engine/bindings/core/v8/ScriptController.h" |
| 37 #include "bindings/core/v8/V8Binding.h" | 37 #include "sky/engine/bindings/core/v8/ScriptSourceCode.h" |
| 38 #include "bindings/core/v8/V8ScriptRunner.h" | 38 #include "sky/engine/bindings/core/v8/V8Binding.h" |
| 39 #include "bindings/core/v8/V8Window.h" | 39 #include "sky/engine/bindings/core/v8/V8ScriptRunner.h" |
| 40 #include "bindings/core/v8/WindowProxy.h" | 40 #include "sky/engine/bindings/core/v8/WindowProxy.h" |
| 41 #include "core/dom/ExecutionContext.h" | 41 #include "sky/engine/core/dom/ExecutionContext.h" |
| 42 #include "core/frame/FrameConsole.h" | 42 #include "sky/engine/core/frame/FrameConsole.h" |
| 43 #include "core/frame/FrameHost.h" | 43 #include "sky/engine/core/frame/LocalFrame.h" |
| 44 #include "core/frame/LocalFrame.h" | 44 #include "sky/engine/core/frame/UseCounter.h" |
| 45 #include "core/frame/UseCounter.h" | 45 #include "sky/engine/core/inspector/InspectorTraceEvents.h" |
| 46 #include "core/inspector/InspectorTraceEvents.h" | 46 #include "sky/engine/core/inspector/ScriptDebugListener.h" |
| 47 #include "core/inspector/ScriptDebugListener.h" | 47 #include "sky/engine/core/page/Page.h" |
| 48 #include "core/page/Page.h" | 48 #include "sky/engine/v8_inspector/inspector_host.h" |
| 49 #include "wtf/OwnPtr.h" | 49 #include "sky/engine/wtf/OwnPtr.h" |
| 50 #include "wtf/PassOwnPtr.h" | 50 #include "sky/engine/wtf/PassOwnPtr.h" |
| 51 #include "wtf/StdLibExtras.h" | 51 #include "sky/engine/wtf/StdLibExtras.h" |
| 52 #include "wtf/TemporaryChange.h" | 52 #include "sky/engine/wtf/TemporaryChange.h" |
| 53 #include "wtf/text/StringBuilder.h" | 53 #include "sky/engine/wtf/text/StringBuilder.h" |
| 54 #include "gin/modules/console.h" | |
| 55 #include "gin/converter.h" | |
| 56 | 54 |
| 57 namespace blink { | 55 namespace blink { |
| 58 | 56 |
| 59 static LocalFrame* retrieveFrameWithGlobalObjectCheck(v8::Handle<v8::Context> co ntext) | 57 static LocalFrame* retrieveFrameWithGlobalObjectCheck(v8::Handle<v8::Context> co ntext) |
| 60 { | 58 { |
| 61 if (context.IsEmpty()) | 59 if (context.IsEmpty()) |
| 62 return 0; | 60 return 0; |
| 63 | 61 |
| 64 // FIXME: This is a temporary hack for crbug.com/345014. | 62 // FIXME: This is a temporary hack for crbug.com/345014. |
| 65 // Currently it's possible that V8 can trigger Debugger::ProcessDebugEvent f or a context | 63 // Currently it's possible that V8 can trigger Debugger::ProcessDebugEvent f or a context |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 93 | 91 |
| 94 v8::Isolate* PageScriptDebugServer::s_mainThreadIsolate = 0; | 92 v8::Isolate* PageScriptDebugServer::s_mainThreadIsolate = 0; |
| 95 | 93 |
| 96 void PageScriptDebugServer::setMainThreadIsolate(v8::Isolate* isolate) | 94 void PageScriptDebugServer::setMainThreadIsolate(v8::Isolate* isolate) |
| 97 { | 95 { |
| 98 s_mainThreadIsolate = isolate; | 96 s_mainThreadIsolate = isolate; |
| 99 } | 97 } |
| 100 | 98 |
| 101 PageScriptDebugServer::PageScriptDebugServer() | 99 PageScriptDebugServer::PageScriptDebugServer() |
| 102 : ScriptDebugServer(s_mainThreadIsolate) | 100 : ScriptDebugServer(s_mainThreadIsolate) |
| 103 , m_pausedPage(0) | 101 , m_pausedHost(0) |
| 104 { | 102 { |
| 105 } | 103 } |
| 106 | 104 |
| 107 PageScriptDebugServer::~PageScriptDebugServer() | 105 PageScriptDebugServer::~PageScriptDebugServer() |
| 108 { | 106 { |
| 109 } | 107 } |
| 110 | 108 |
| 111 void PageScriptDebugServer::addListener(ScriptDebugListener* listener, Page* pag e) | 109 void PageScriptDebugServer::addListener(ScriptDebugListener* listener, inspector ::InspectorHost* host) |
| 112 { | 110 { |
| 113 ScriptController& scriptController = page->mainFrame()->script(); | |
| 114 | |
| 115 v8::HandleScope scope(m_isolate); | 111 v8::HandleScope scope(m_isolate); |
| 116 | 112 |
| 117 if (!m_listenersMap.size()) { | 113 if (!m_listenersMap.size()) { |
| 118 v8::Debug::SetDebugEventListener(&PageScriptDebugServer::v8DebugEventCal lback, v8::External::New(m_isolate, this)); | 114 v8::Debug::SetDebugEventListener(&PageScriptDebugServer::v8DebugEventCal lback, v8::External::New(m_isolate, this)); |
| 119 ensureDebuggerScriptCompiled(); | 115 ensureDebuggerScriptCompiled(); |
| 120 } | 116 } |
| 121 | 117 |
| 122 v8::Local<v8::Context> debuggerContext = v8::Debug::GetDebugContext(); | 118 v8::Local<v8::Context> debuggerContext = v8::Debug::GetDebugContext(); |
| 123 v8::Context::Scope contextScope(debuggerContext); | 119 v8::Context::Scope contextScope(debuggerContext); |
| 124 | 120 |
| 125 v8::Local<v8::Value> console = gin::Console::GetModule(m_isolate); | |
|
eseidel
2014/11/20 22:19:53
I also removed this as it was left-over debugging
| |
| 126 debuggerContext->Global()->Set(gin::StringToV8(m_isolate, "console"), consol e); | |
| 127 | |
| 128 v8::Local<v8::Object> debuggerScript = m_debuggerScript.newLocal(m_isolate); | 121 v8::Local<v8::Object> debuggerScript = m_debuggerScript.newLocal(m_isolate); |
| 129 ASSERT(!debuggerScript->IsUndefined()); | 122 ASSERT(!debuggerScript->IsUndefined()); |
| 130 m_listenersMap.set(page, listener); | 123 m_listenersMap.set(host, listener); |
| 131 | 124 |
| 132 WindowProxy* windowProxy = scriptController.existingWindowProxy(DOMWrapperWo rld::mainWorld()); | 125 v8::Local<v8::Context> context = host->GetContext(); |
| 133 if (!windowProxy || !windowProxy->isContextInitialized()) | |
| 134 return; | |
| 135 v8::Local<v8::Context> context = windowProxy->context(); | |
| 136 v8::Handle<v8::Function> getScriptsFunction = v8::Local<v8::Function>::Cast( debuggerScript->Get(v8AtomicString(m_isolate, "getScripts"))); | 126 v8::Handle<v8::Function> getScriptsFunction = v8::Local<v8::Function>::Cast( debuggerScript->Get(v8AtomicString(m_isolate, "getScripts"))); |
| 137 v8::Handle<v8::Value> argv[] = { context->GetEmbedderData(0) }; | 127 v8::Handle<v8::Value> argv[] = { context->GetEmbedderData(0) }; |
| 138 v8::Handle<v8::Value> value = V8ScriptRunner::callInternalFunction(getScript sFunction, debuggerScript, WTF_ARRAY_LENGTH(argv), argv, m_isolate); | 128 v8::Handle<v8::Value> value = V8ScriptRunner::callInternalFunction(getScript sFunction, debuggerScript, WTF_ARRAY_LENGTH(argv), argv, m_isolate); |
| 139 if (value.IsEmpty()) | 129 if (value.IsEmpty()) |
| 140 return; | 130 return; |
| 141 ASSERT(!value->IsUndefined() && value->IsArray()); | 131 ASSERT(!value->IsUndefined() && value->IsArray()); |
| 142 v8::Handle<v8::Array> scriptsArray = v8::Handle<v8::Array>::Cast(value); | 132 v8::Handle<v8::Array> scriptsArray = v8::Handle<v8::Array>::Cast(value); |
| 143 for (unsigned i = 0; i < scriptsArray->Length(); ++i) | 133 for (unsigned i = 0; i < scriptsArray->Length(); ++i) |
| 144 dispatchDidParseSource(listener, v8::Handle<v8::Object>::Cast(scriptsArr ay->Get(v8::Integer::New(m_isolate, i))), CompileSuccess); | 134 dispatchDidParseSource(listener, v8::Handle<v8::Object>::Cast(scriptsArr ay->Get(v8::Integer::New(m_isolate, i))), CompileSuccess); |
| 145 } | 135 } |
| 146 | 136 |
| 147 void PageScriptDebugServer::removeListener(ScriptDebugListener* listener, Page* page) | 137 void PageScriptDebugServer::removeListener(ScriptDebugListener* listener, inspec tor::InspectorHost* host) |
| 148 { | 138 { |
| 149 if (!m_listenersMap.contains(page)) | 139 if (!m_listenersMap.contains(host)) |
| 150 return; | 140 return; |
| 151 | 141 |
| 152 if (m_pausedPage == page) | 142 if (m_pausedHost == host) |
| 153 continueProgram(); | 143 continueProgram(); |
| 154 | 144 |
| 155 m_listenersMap.remove(page); | 145 m_listenersMap.remove(host); |
| 156 | 146 |
| 157 if (m_listenersMap.isEmpty()) { | 147 if (m_listenersMap.isEmpty()) { |
| 158 discardDebuggerScript(); | 148 discardDebuggerScript(); |
| 159 v8::Debug::SetDebugEventListener(0); | 149 v8::Debug::SetDebugEventListener(0); |
| 160 // FIXME: Remove all breakpoints set by the agent. | 150 // FIXME: Remove all breakpoints set by the agent. |
| 161 } | 151 } |
| 162 } | 152 } |
| 163 | 153 |
| 164 void PageScriptDebugServer::interruptAndRun(PassOwnPtr<Task> task) | 154 void PageScriptDebugServer::interruptAndRun(PassOwnPtr<Task> task) |
| 165 { | 155 { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 200 | 190 |
| 201 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Update Counters", TRACE_EVENT_SCOPE_PROCESS, "data", InspectorUpdateCountersEvent::data ()); | 191 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Update Counters", TRACE_EVENT_SCOPE_PROCESS, "data", InspectorUpdateCountersEvent::data ()); |
| 202 } | 192 } |
| 203 | 193 |
| 204 ScriptDebugListener* PageScriptDebugServer::getDebugListenerForContext(v8::Handl e<v8::Context> context) | 194 ScriptDebugListener* PageScriptDebugServer::getDebugListenerForContext(v8::Handl e<v8::Context> context) |
| 205 { | 195 { |
| 206 v8::HandleScope scope(m_isolate); | 196 v8::HandleScope scope(m_isolate); |
| 207 LocalFrame* frame = retrieveFrameWithGlobalObjectCheck(context); | 197 LocalFrame* frame = retrieveFrameWithGlobalObjectCheck(context); |
| 208 if (!frame) | 198 if (!frame) |
| 209 return 0; | 199 return 0; |
| 210 return m_listenersMap.get(frame->page()); | 200 return m_listenersMap.get(frame->page()->inspectorHost()); |
| 211 } | 201 } |
| 212 | 202 |
| 213 void PageScriptDebugServer::runMessageLoopOnPause(v8::Handle<v8::Context> contex t) | 203 void PageScriptDebugServer::runMessageLoopOnPause(v8::Handle<v8::Context> contex t) |
| 214 { | 204 { |
| 215 v8::HandleScope scope(m_isolate); | 205 v8::HandleScope scope(m_isolate); |
| 216 LocalFrame* frame = retrieveFrameWithGlobalObjectCheck(context); | 206 LocalFrame* frame = retrieveFrameWithGlobalObjectCheck(context); |
| 217 m_pausedPage = frame->page(); | 207 m_pausedHost = frame->page()->inspectorHost(); |
| 218 | 208 |
| 219 // Wait for continue or step command. | 209 // Wait for continue or step command. |
| 220 m_clientMessageLoop->run(m_pausedPage); | 210 m_clientMessageLoop->run(m_pausedHost); |
| 221 | 211 |
| 222 // The listener may have been removed in the nested loop. | 212 // The listener may have been removed in the nested loop. |
| 223 if (ScriptDebugListener* listener = m_listenersMap.get(m_pausedPage)) | 213 if (ScriptDebugListener* listener = m_listenersMap.get(m_pausedHost)) |
| 224 listener->didContinue(); | 214 listener->didContinue(); |
| 225 | 215 |
| 226 m_pausedPage = 0; | 216 m_pausedHost = 0; |
| 227 } | 217 } |
| 228 | 218 |
| 229 void PageScriptDebugServer::quitMessageLoopOnPause() | 219 void PageScriptDebugServer::quitMessageLoopOnPause() |
| 230 { | 220 { |
| 231 m_clientMessageLoop->quitNow(); | 221 m_clientMessageLoop->quitNow(); |
| 232 } | 222 } |
| 233 | 223 |
| 234 void PageScriptDebugServer::preprocessBeforeCompile(const v8::Debug::EventDetail s& eventDetails) | 224 void PageScriptDebugServer::preprocessBeforeCompile(const v8::Debug::EventDetail s& eventDetails) |
| 235 { | 225 { |
| 236 v8::Handle<v8::Context> eventContext = eventDetails.GetEventContext(); | 226 v8::Handle<v8::Context> eventContext = eventDetails.GetEventContext(); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 316 UseCounter::muteForInspector(); | 306 UseCounter::muteForInspector(); |
| 317 } | 307 } |
| 318 | 308 |
| 319 void PageScriptDebugServer::unmuteWarningsAndDeprecations() | 309 void PageScriptDebugServer::unmuteWarningsAndDeprecations() |
| 320 { | 310 { |
| 321 FrameConsole::unmute(); | 311 FrameConsole::unmute(); |
| 322 UseCounter::unmuteForInspector(); | 312 UseCounter::unmuteForInspector(); |
| 323 } | 313 } |
| 324 | 314 |
| 325 } // namespace blink | 315 } // namespace blink |
| OLD | NEW |