• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
3  * Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com>
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1.  Redistributions of source code must retain the above copyright
10  *     notice, this list of conditions and the following disclaimer.
11  * 2.  Redistributions in binary form must reproduce the above copyright
12  *     notice, this list of conditions and the following disclaimer in the
13  *     documentation and/or other materials provided with the distribution.
14  * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
15  *     its contributors may be used to endorse or promote products derived
16  *     from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
19  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #include "config.h"
31 #include "InspectorBackend.h"
32 
33 #include "Element.h"
34 #include "Frame.h"
35 #include "FrameLoader.h"
36 #include "HTMLFrameOwnerElement.h"
37 #include "InspectorClient.h"
38 #include "InspectorController.h"
39 #include "InspectorDOMAgent.h"
40 #include "InspectorResource.h"
41 
42 #if ENABLE(JAVASCRIPT_DEBUGGER)
43 #include "JavaScriptCallFrame.h"
44 #include "JavaScriptDebugServer.h"
45 using namespace JSC;
46 #endif
47 
48 #include <wtf/RefPtr.h>
49 #include <wtf/StdLibExtras.h>
50 
51 using namespace std;
52 
53 namespace WebCore {
54 
InspectorBackend(InspectorController * inspectorController,InspectorClient * client)55 InspectorBackend::InspectorBackend(InspectorController* inspectorController, InspectorClient* client)
56     : m_inspectorController(inspectorController)
57     , m_client(client)
58 {
59 }
60 
~InspectorBackend()61 InspectorBackend::~InspectorBackend()
62 {
63 }
64 
hideDOMNodeHighlight()65 void InspectorBackend::hideDOMNodeHighlight()
66 {
67     if (m_inspectorController)
68         m_inspectorController->hideHighlight();
69 }
70 
localizedStringsURL()71 String InspectorBackend::localizedStringsURL()
72 {
73     return m_client->localizedStringsURL();
74 }
75 
hiddenPanels()76 String InspectorBackend::hiddenPanels()
77 {
78     return m_client->hiddenPanels();
79 }
80 
windowUnloading()81 void InspectorBackend::windowUnloading()
82 {
83     if (m_inspectorController)
84         m_inspectorController->close();
85 }
86 
isWindowVisible()87 bool InspectorBackend::isWindowVisible()
88 {
89     if (m_inspectorController)
90         return m_inspectorController->windowVisible();
91     return false;
92 }
93 
addResourceSourceToFrame(long identifier,Node * frame)94 void InspectorBackend::addResourceSourceToFrame(long identifier, Node* frame)
95 {
96     if (!m_inspectorController)
97         return;
98     RefPtr<InspectorResource> resource = m_inspectorController->resources().get(identifier);
99     if (resource) {
100         String sourceString = resource->sourceString();
101         if (!sourceString.isEmpty())
102             addSourceToFrame(resource->mimeType(), sourceString, frame);
103     }
104 }
105 
addSourceToFrame(const String & mimeType,const String & source,Node * frameNode)106 bool InspectorBackend::addSourceToFrame(const String& mimeType, const String& source, Node* frameNode)
107 {
108     ASSERT_ARG(frameNode, frameNode);
109 
110     if (!frameNode)
111         return false;
112 
113     if (!frameNode->attached()) {
114         ASSERT_NOT_REACHED();
115         return false;
116     }
117 
118     ASSERT(frameNode->isElementNode());
119     if (!frameNode->isElementNode())
120         return false;
121 
122     Element* element = static_cast<Element*>(frameNode);
123     ASSERT(element->isFrameOwnerElement());
124     if (!element->isFrameOwnerElement())
125         return false;
126 
127     HTMLFrameOwnerElement* frameOwner = static_cast<HTMLFrameOwnerElement*>(element);
128     ASSERT(frameOwner->contentFrame());
129     if (!frameOwner->contentFrame())
130         return false;
131 
132     FrameLoader* loader = frameOwner->contentFrame()->loader();
133 
134     loader->setResponseMIMEType(mimeType);
135     loader->begin();
136     loader->write(source);
137     loader->end();
138 
139     return true;
140 }
141 
clearMessages()142 void InspectorBackend::clearMessages()
143 {
144     if (m_inspectorController)
145         m_inspectorController->clearConsoleMessages();
146 }
147 
toggleNodeSearch()148 void InspectorBackend::toggleNodeSearch()
149 {
150     if (m_inspectorController)
151         m_inspectorController->toggleSearchForNodeInPage();
152 }
153 
attach()154 void InspectorBackend::attach()
155 {
156     if (m_inspectorController)
157         m_inspectorController->attachWindow();
158 }
159 
detach()160 void InspectorBackend::detach()
161 {
162     if (m_inspectorController)
163         m_inspectorController->detachWindow();
164 }
165 
setAttachedWindowHeight(unsigned height)166 void InspectorBackend::setAttachedWindowHeight(unsigned height)
167 {
168     if (m_inspectorController)
169         m_inspectorController->setAttachedWindowHeight(height);
170 }
171 
storeLastActivePanel(const String & panelName)172 void InspectorBackend::storeLastActivePanel(const String& panelName)
173 {
174     if (m_inspectorController)
175         m_inspectorController->storeLastActivePanel(panelName);
176 }
177 
searchingForNode()178 bool InspectorBackend::searchingForNode()
179 {
180     if (m_inspectorController)
181         return m_inspectorController->searchingForNodeInPage();
182     return false;
183 }
184 
loaded(bool enableDOMAgent)185 void InspectorBackend::loaded(bool enableDOMAgent)
186 {
187     if (m_inspectorController)
188         m_inspectorController->scriptObjectReady(enableDOMAgent);
189 }
190 
enableResourceTracking(bool always)191 void InspectorBackend::enableResourceTracking(bool always)
192 {
193     if (m_inspectorController)
194         m_inspectorController->enableResourceTracking(always);
195 }
196 
disableResourceTracking(bool always)197 void InspectorBackend::disableResourceTracking(bool always)
198 {
199     if (m_inspectorController)
200         m_inspectorController->disableResourceTracking(always);
201 }
202 
resourceTrackingEnabled() const203 bool InspectorBackend::resourceTrackingEnabled() const
204 {
205     if (m_inspectorController)
206         return m_inspectorController->resourceTrackingEnabled();
207     return false;
208 }
209 
moveWindowBy(float x,float y) const210 void InspectorBackend::moveWindowBy(float x, float y) const
211 {
212     if (m_inspectorController)
213         m_inspectorController->moveWindowBy(x, y);
214 }
215 
closeWindow()216 void InspectorBackend::closeWindow()
217 {
218     if (m_inspectorController)
219         m_inspectorController->closeWindow();
220 }
221 
platform() const222 const String& InspectorBackend::platform() const
223 {
224 #if PLATFORM(MAC)
225 #ifdef BUILDING_ON_TIGER
226     DEFINE_STATIC_LOCAL(const String, platform, ("mac-tiger"));
227 #else
228     DEFINE_STATIC_LOCAL(const String, platform, ("mac-leopard"));
229 #endif
230 #elif PLATFORM(WIN_OS)
231     DEFINE_STATIC_LOCAL(const String, platform, ("windows"));
232 #elif PLATFORM(QT)
233     DEFINE_STATIC_LOCAL(const String, platform, ("qt"));
234 #elif PLATFORM(GTK)
235     DEFINE_STATIC_LOCAL(const String, platform, ("gtk"));
236 #elif PLATFORM(WX)
237     DEFINE_STATIC_LOCAL(const String, platform, ("wx"));
238 #else
239     DEFINE_STATIC_LOCAL(const String, platform, ("unknown"));
240 #endif
241 
242     return platform;
243 }
244 
245 #if ENABLE(JAVASCRIPT_DEBUGGER)
profiles() const246 const ProfilesArray& InspectorBackend::profiles() const
247 {
248     if (m_inspectorController)
249         return m_inspectorController->profiles();
250     return m_emptyProfiles;
251 }
252 
startProfiling()253 void InspectorBackend::startProfiling()
254 {
255     if (m_inspectorController)
256         m_inspectorController->startUserInitiatedProfiling();
257 }
258 
stopProfiling()259 void InspectorBackend::stopProfiling()
260 {
261     if (m_inspectorController)
262         m_inspectorController->stopUserInitiatedProfiling();
263 }
264 
enableProfiler(bool always)265 void InspectorBackend::enableProfiler(bool always)
266 {
267     if (m_inspectorController)
268         m_inspectorController->enableProfiler(always);
269 }
270 
disableProfiler(bool always)271 void InspectorBackend::disableProfiler(bool always)
272 {
273     if (m_inspectorController)
274         m_inspectorController->disableProfiler(always);
275 }
276 
profilerEnabled()277 bool InspectorBackend::profilerEnabled()
278 {
279     if (m_inspectorController)
280         return m_inspectorController->profilerEnabled();
281     return false;
282 }
283 
enableDebugger(bool always)284 void InspectorBackend::enableDebugger(bool always)
285 {
286     if (m_inspectorController)
287         m_inspectorController->enableDebuggerFromFrontend(always);
288 }
289 
disableDebugger(bool always)290 void InspectorBackend::disableDebugger(bool always)
291 {
292     if (m_inspectorController)
293         m_inspectorController->disableDebugger(always);
294 }
295 
debuggerEnabled() const296 bool InspectorBackend::debuggerEnabled() const
297 {
298     if (m_inspectorController)
299         return m_inspectorController->debuggerEnabled();
300     return false;
301 }
302 
currentCallFrame() const303 JavaScriptCallFrame* InspectorBackend::currentCallFrame() const
304 {
305     return JavaScriptDebugServer::shared().currentCallFrame();
306 }
307 
addBreakpoint(const String & sourceID,unsigned lineNumber)308 void InspectorBackend::addBreakpoint(const String& sourceID, unsigned lineNumber)
309 {
310     intptr_t sourceIDValue = sourceID.toIntPtr();
311     JavaScriptDebugServer::shared().addBreakpoint(sourceIDValue, lineNumber);
312 }
313 
removeBreakpoint(const String & sourceID,unsigned lineNumber)314 void InspectorBackend::removeBreakpoint(const String& sourceID, unsigned lineNumber)
315 {
316     intptr_t sourceIDValue = sourceID.toIntPtr();
317     JavaScriptDebugServer::shared().removeBreakpoint(sourceIDValue, lineNumber);
318 }
319 
pauseOnExceptions()320 bool InspectorBackend::pauseOnExceptions()
321 {
322     return JavaScriptDebugServer::shared().pauseOnExceptions();
323 }
324 
setPauseOnExceptions(bool pause)325 void InspectorBackend::setPauseOnExceptions(bool pause)
326 {
327     JavaScriptDebugServer::shared().setPauseOnExceptions(pause);
328 }
329 
pauseInDebugger()330 void InspectorBackend::pauseInDebugger()
331 {
332     JavaScriptDebugServer::shared().pauseProgram();
333 }
334 
resumeDebugger()335 void InspectorBackend::resumeDebugger()
336 {
337     if (m_inspectorController)
338         m_inspectorController->resumeDebugger();
339 }
340 
stepOverStatementInDebugger()341 void InspectorBackend::stepOverStatementInDebugger()
342 {
343     JavaScriptDebugServer::shared().stepOverStatement();
344 }
345 
stepIntoStatementInDebugger()346 void InspectorBackend::stepIntoStatementInDebugger()
347 {
348     JavaScriptDebugServer::shared().stepIntoStatement();
349 }
350 
stepOutOfFunctionInDebugger()351 void InspectorBackend::stepOutOfFunctionInDebugger()
352 {
353     JavaScriptDebugServer::shared().stepOutOfFunction();
354 }
355 
356 #endif
357 
getChildNodes(long callId,long elementId)358 void InspectorBackend::getChildNodes(long callId, long elementId)
359 {
360     if (m_inspectorController)
361         m_inspectorController->domAgent()->getChildNodes(callId, elementId);
362 }
363 
setAttribute(long callId,long elementId,const String & name,const String & value)364 void InspectorBackend::setAttribute(long callId, long elementId, const String& name, const String& value)
365 {
366     if (m_inspectorController)
367         m_inspectorController->domAgent()->setAttribute(callId, elementId, name, value);
368 }
369 
removeAttribute(long callId,long elementId,const String & name)370 void InspectorBackend::removeAttribute(long callId, long elementId, const String& name)
371 {
372     if (m_inspectorController)
373         m_inspectorController->domAgent()->removeAttribute(callId, elementId, name);
374 }
375 
setTextNodeValue(long callId,long elementId,const String & value)376 void InspectorBackend::setTextNodeValue(long callId, long elementId, const String& value)
377 {
378     if (m_inspectorController)
379         m_inspectorController->domAgent()->setTextNodeValue(callId, elementId, value);
380 }
381 
highlight(Node * node)382 void InspectorBackend::highlight(Node* node)
383 {
384     if (m_inspectorController)
385         m_inspectorController->highlight(node);
386 }
387 
388 } // namespace WebCore
389