2 * Copyright (C) 2011 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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
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.
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.
32 #include "PageDebuggerAgent.h"
34 #if ENABLE(JAVASCRIPT_DEBUGGER) && ENABLE(INSPECTOR)
36 #include "CachedResource.h"
37 #include "InspectorOverlay.h"
38 #include "InspectorPageAgent.h"
39 #include "InstrumentingAgents.h"
41 #include "PageConsole.h"
42 #include "PageScriptDebugServer.h"
43 #include "ScriptState.h"
44 #include <inspector/InjectedScript.h>
45 #include <inspector/InjectedScriptManager.h>
47 using namespace Inspector;
51 PageDebuggerAgent::PageDebuggerAgent(InjectedScriptManager* injectedScriptManager, InstrumentingAgents* instrumentingAgents, InspectorPageAgent* pageAgent, InspectorOverlay* overlay)
52 : WebDebuggerAgent(injectedScriptManager, instrumentingAgents)
53 , m_pageAgent(pageAgent)
58 void PageDebuggerAgent::enable()
60 WebDebuggerAgent::enable();
61 m_instrumentingAgents->setPageDebuggerAgent(this);
64 void PageDebuggerAgent::disable(bool isBeingDestroyed)
66 WebDebuggerAgent::disable(isBeingDestroyed);
67 m_instrumentingAgents->setPageDebuggerAgent(nullptr);
70 String PageDebuggerAgent::sourceMapURLForScript(const Script& script)
72 DEFINE_STATIC_LOCAL(String, sourceMapHTTPHeader, (ASCIILiteral("SourceMap")));
73 DEFINE_STATIC_LOCAL(String, sourceMapHTTPHeaderDeprecated, (ASCIILiteral("X-SourceMap")));
75 if (!script.url.isEmpty()) {
76 CachedResource* resource = m_pageAgent->cachedResource(m_pageAgent->mainFrame(), URL(ParsedURLString, script.url));
78 String sourceMapHeader = resource->response().httpHeaderField(sourceMapHTTPHeader);
79 if (!sourceMapHeader.isEmpty())
80 return sourceMapHeader;
82 sourceMapHeader = resource->response().httpHeaderField(sourceMapHTTPHeaderDeprecated);
83 if (!sourceMapHeader.isEmpty())
84 return sourceMapHeader;
88 return InspectorDebuggerAgent::sourceMapURLForScript(script);
91 void PageDebuggerAgent::startListeningScriptDebugServer()
93 scriptDebugServer().addListener(this, m_pageAgent->page());
96 void PageDebuggerAgent::stopListeningScriptDebugServer(bool isBeingDestroyed)
98 scriptDebugServer().removeListener(this, m_pageAgent->page(), isBeingDestroyed);
101 PageScriptDebugServer& PageDebuggerAgent::scriptDebugServer()
103 return PageScriptDebugServer::shared();
106 void PageDebuggerAgent::muteConsole()
111 void PageDebuggerAgent::unmuteConsole()
113 PageConsole::unmute();
116 void PageDebuggerAgent::breakpointActionLog(JSC::ExecState*, const String& message)
118 m_pageAgent->page()->console().addMessage(JSMessageSource, LogMessageLevel, message);
121 InjectedScript PageDebuggerAgent::injectedScriptForEval(ErrorString* errorString, const int* executionContextId)
123 if (!executionContextId) {
124 JSC::ExecState* scriptState = mainWorldExecState(m_pageAgent->mainFrame());
125 return injectedScriptManager()->injectedScriptFor(scriptState);
128 InjectedScript injectedScript = injectedScriptManager()->injectedScriptForId(*executionContextId);
129 if (injectedScript.hasNoValue())
130 *errorString = ASCIILiteral("Execution context with given id not found.");
132 return injectedScript;
135 void PageDebuggerAgent::setOverlayMessage(ErrorString*, const String* message)
137 m_overlay->setPausedInDebuggerMessage(message);
140 void PageDebuggerAgent::didClearMainFrameWindowObject()
142 didClearGlobalObject();
145 } // namespace WebCore
147 #endif // ENABLE(JAVASCRIPT_DEBUGGER) && ENABLE(INSPECTOR)