3693844516f1ebd54c4bdd5daceded0afa6b32a5
[WebKit-https.git] / Source / WebCore / inspector / InspectorAgent.cpp
1 /*
2  * Copyright (C) 2007, 2008, 2009, 2010 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 "InspectorAgent.h"
32
33 #if ENABLE(INSPECTOR)
34
35 #include "CachedResource.h"
36 #include "CachedResourceLoader.h"
37 #include "Chrome.h"
38 #include "Cookie.h"
39 #include "CookieJar.h"
40 #include "DOMWindow.h"
41 #include "DOMWrapperWorld.h"
42 #include "Document.h"
43 #include "DocumentLoader.h"
44 #include "Element.h"
45 #include "FloatConversion.h"
46 #include "FloatQuad.h"
47 #include "FloatRect.h"
48 #include "Frame.h"
49 #include "FrameLoadRequest.h"
50 #include "FrameLoader.h"
51 #include "FrameTree.h"
52 #include "FrameView.h"
53 #include "GraphicsContext.h"
54 #include "HTMLFrameOwnerElement.h"
55 #include "HTTPHeaderMap.h"
56 #include "HitTestResult.h"
57 #include "InjectedScript.h"
58 #include "InjectedScriptHost.h"
59 #include "InspectorBrowserDebuggerAgent.h"
60 #include "InspectorCSSAgent.h"
61 #include "InspectorClient.h"
62 #include "InspectorConsoleAgent.h"
63 #include "InspectorController.h"
64 #include "InspectorDOMAgent.h"
65 #include "InspectorDOMStorageResource.h"
66 #include "InspectorDatabaseResource.h"
67 #include "InspectorDebuggerAgent.h"
68 #include "InspectorFrontend.h"
69 #include "InspectorFrontendClient.h"
70 #include "InspectorInstrumentation.h"
71 #include "InspectorProfilerAgent.h"
72 #include "InspectorResourceAgent.h"
73 #include "InspectorRuntimeAgent.h"
74 #include "InspectorState.h"
75 #include "InspectorTimelineAgent.h"
76 #include "InspectorValues.h"
77 #include "InspectorWorkerResource.h"
78 #include "InstrumentingAgents.h"
79 #include "IntRect.h"
80 #include "Page.h"
81 #include "ProgressTracker.h"
82 #include "Range.h"
83 #include "RenderInline.h"
84 #include "ResourceRequest.h"
85 #include "ResourceResponse.h"
86 #include "ScriptArguments.h"
87 #include "ScriptCallStack.h"
88 #include "ScriptFunctionCall.h"
89 #include "ScriptObject.h"
90 #include "ScriptProfile.h"
91 #include "ScriptProfiler.h"
92 #include "ScriptSourceCode.h"
93 #include "ScriptState.h"
94 #include "SecurityOrigin.h"
95 #include "Settings.h"
96 #include "SharedBuffer.h"
97 #include "TextEncoding.h"
98 #include "TextIterator.h"
99 #include "TextRun.h"
100 #include "UserGestureIndicator.h"
101 #include "WindowFeatures.h"
102 #include <wtf/CurrentTime.h>
103 #include <wtf/ListHashSet.h>
104 #include <wtf/RefCounted.h>
105 #include <wtf/StdLibExtras.h>
106 #include <wtf/UnusedParam.h>
107 #include <wtf/text/StringConcatenate.h>
108
109 #if ENABLE(DATABASE)
110 #include "InspectorDatabaseAgent.h"
111 #endif
112
113 #if ENABLE(DOM_STORAGE)
114 #include "InspectorDOMStorageAgent.h"
115 #endif
116
117 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
118 #include "InspectorApplicationCacheAgent.h"
119 #endif
120
121 using namespace std;
122
123 namespace WebCore {
124
125 namespace InspectorAgentState {
126 static const char searchingForNode[] = "searchingForNode";
127 static const char timelineProfilerEnabled[] = "timelineProfilerEnabled";
128 static const char userInitiatedProfiling[] = "userInitiatedProfiling";
129 static const char debuggerEnabled[] = "debuggerEnabled";
130 static const char profilerEnabled[] = "profilerEnabled";
131 }
132
133 static const char scriptsPanelName[] = "scripts";
134 static const char consolePanelName[] = "console";
135 static const char profilesPanelName[] = "profiles";
136
137 InspectorAgent::InspectorAgent(Page* page, InspectorClient* client)
138     : m_inspectedPage(page)
139     , m_client(client)
140     , m_frontend(0)
141     , m_instrumentingAgents(new InstrumentingAgents())
142     , m_injectedScriptHost(InjectedScriptHost::create(this))
143     , m_domAgent(InspectorDOMAgent::create(m_instrumentingAgents.get(), m_injectedScriptHost.get()))
144     , m_cssAgent(new InspectorCSSAgent(m_domAgent.get()))
145 #if ENABLE(DATABASE)
146     , m_databaseAgentResources(InspectorDatabaseAgent::createStorage())
147 #endif
148 #if ENABLE(DOM_STORAGE)
149     , m_domStorageAgentResources(InspectorDOMStorageAgent::createStorage())
150 #endif
151     , m_state(new InspectorState(client))
152     , m_consoleAgent(new InspectorConsoleAgent(m_instrumentingAgents.get(), this, m_state.get(), m_injectedScriptHost.get(), m_domAgent.get()))
153 #if ENABLE(JAVASCRIPT_DEBUGGER)
154     , m_profilerAgent(InspectorProfilerAgent::create(this))
155 #endif
156 {
157     ASSERT_ARG(page, page);
158     ASSERT_ARG(client, client);
159     InspectorInstrumentation::bindInspectorAgent(m_inspectedPage, this);
160 }
161
162 InspectorAgent::~InspectorAgent()
163 {
164     // These should have been cleared in inspectedPageDestroyed().
165     ASSERT(!m_client);
166     ASSERT(!m_inspectedPage);
167     ASSERT(!m_highlightedNode);
168 }
169
170 void InspectorAgent::inspectedPageDestroyed()
171 {
172     if (m_frontend)
173         m_frontend->disconnectFromBackend();
174
175     hideHighlight();
176
177 #if ENABLE(JAVASCRIPT_DEBUGGER)
178     m_debuggerAgent.clear();
179     m_browserDebuggerAgent.clear();
180 #endif
181
182     ASSERT(m_inspectedPage);
183     InspectorInstrumentation::unbindInspectorAgent(m_inspectedPage);
184     m_inspectedPage = 0;
185
186     releaseFrontendLifetimeAgents();
187     m_injectedScriptHost->disconnectController();
188
189     m_client->inspectorDestroyed();
190     m_client = 0;
191 }
192
193 bool InspectorAgent::searchingForNodeInPage() const
194 {
195     return m_state->getBoolean(InspectorAgentState::searchingForNode);
196 }
197
198 void InspectorAgent::restoreInspectorStateFromCookie(const String& inspectorStateCookie)
199 {
200     m_state = new InspectorState(m_client, inspectorStateCookie);
201
202     m_frontend->frontendReused();
203     m_frontend->inspectedURLChanged(inspectedURL().string());
204     pushDataCollectedOffline();
205
206     m_resourceAgent = InspectorResourceAgent::restore(m_inspectedPage, m_state.get(), m_frontend);
207     m_timelineAgent = InspectorTimelineAgent::restore(m_state.get(), m_frontend);
208
209 #if ENABLE(JAVASCRIPT_DEBUGGER)
210     restoreDebugger(false);
211     restoreProfiler(ProfilerRestoreResetAgent);
212     if (m_state->getBoolean(InspectorAgentState::userInitiatedProfiling))
213         startUserInitiatedProfiling();
214 #endif
215 }
216
217 void InspectorAgent::inspect(Node* node)
218 {
219     if (node->nodeType() != Node::ELEMENT_NODE && node->nodeType() != Node::DOCUMENT_NODE)
220         node = node->parentNode();
221     m_nodeToFocus = node;
222
223     if (!m_frontend)
224         return;
225
226     focusNode();
227 }
228
229 void InspectorAgent::focusNode()
230 {
231     if (!enabled())
232         return;
233
234     ASSERT(m_frontend);
235     ASSERT(m_nodeToFocus);
236
237     long id = m_domAgent->pushNodePathToFrontend(m_nodeToFocus.get());
238     m_frontend->updateFocusedNode(id);
239     m_nodeToFocus = 0;
240 }
241
242 void InspectorAgent::highlight(Node* node)
243 {
244     if (!enabled())
245         return;
246     ASSERT_ARG(node, node);
247     m_highlightedNode = node;
248     m_client->highlight(node);
249 }
250
251 void InspectorAgent::highlightDOMNode(long nodeId)
252 {
253     Node* node = 0;
254     if (m_domAgent && (node = m_domAgent->nodeForId(nodeId)))
255         highlight(node);
256 }
257
258 void InspectorAgent::highlightFrame(unsigned long frameId)
259 {
260     Frame* mainFrame = m_inspectedPage->mainFrame();
261     for (Frame* frame = mainFrame; frame; frame = frame->tree()->traverseNext(mainFrame)) {
262         if (reinterpret_cast<uintptr_t>(frame) == frameId && frame->ownerElement()) {
263             highlight(frame->ownerElement());
264             return;
265         }
266     }
267 }
268
269 void InspectorAgent::hideHighlight()
270 {
271     if (!enabled())
272         return;
273     m_highlightedNode = 0;
274     m_client->hideHighlight();
275 }
276
277 void InspectorAgent::mouseDidMoveOverElement(const HitTestResult& result, unsigned)
278 {
279     if (!enabled() || !searchingForNodeInPage())
280         return;
281
282     Node* node = result.innerNode();
283     while (node && node->nodeType() == Node::TEXT_NODE)
284         node = node->parentNode();
285     if (node)
286         highlight(node);
287 }
288
289 bool InspectorAgent::handleMousePress()
290 {
291     if (!enabled() || !searchingForNodeInPage())
292         return false;
293
294     if (m_highlightedNode) {
295         RefPtr<Node> node = m_highlightedNode;
296         setSearchingForNode(false);
297         inspect(node.get());
298     }
299     return true;
300 }
301
302 void InspectorAgent::didClearWindowObjectInWorld(Frame* frame, DOMWrapperWorld* world)
303 {
304     if (world != mainThreadNormalWorld())
305         return;
306
307     if (enabled()) {
308         if (m_frontend && frame == m_inspectedPage->mainFrame())
309             m_injectedScriptHost->discardInjectedScripts();
310
311         if (m_scriptsToEvaluateOnLoad.size()) {
312             ScriptState* scriptState = mainWorldScriptState(frame);
313             for (Vector<String>::iterator it = m_scriptsToEvaluateOnLoad.begin();
314                   it != m_scriptsToEvaluateOnLoad.end(); ++it) {
315                 m_injectedScriptHost->injectScript(*it, scriptState);
316             }
317         }
318     }
319
320     if (!m_inspectorExtensionAPI.isEmpty())
321         m_injectedScriptHost->injectScript(m_inspectorExtensionAPI, mainWorldScriptState(frame));
322 }
323
324 void InspectorAgent::setSearchingForNode(bool enabled)
325 {
326     if (searchingForNodeInPage() == enabled)
327         return;
328     m_state->setBoolean(InspectorAgentState::searchingForNode, enabled);
329     if (!enabled)
330         hideHighlight();
331 }
332
333 void InspectorAgent::setSearchingForNode(bool enabled, bool* newState)
334 {
335     *newState = enabled;
336     setSearchingForNode(enabled);
337 }
338
339 void InspectorAgent::setFrontend(InspectorFrontend* inspectorFrontend)
340 {
341     // We can reconnect to existing front-end -> unmute state.
342     m_state->unmute();
343
344     m_frontend = inspectorFrontend;
345     createFrontendLifetimeAgents();
346
347     m_domAgent->setFrontend(m_frontend);
348     m_consoleAgent->setFrontend(m_frontend);
349
350     // Initialize Web Inspector title.
351     m_frontend->inspectedURLChanged(inspectedURL().string());
352 }
353
354 void InspectorAgent::disconnectFrontend()
355 {
356     if (!m_frontend)
357         return;
358
359     // Destroying agents would change the state, but we don't want that.
360     // Pre-disconnect state will be used to restore inspector agents.
361     m_state->mute();
362
363     m_frontend = 0;
364
365 #if ENABLE(JAVASCRIPT_DEBUGGER)
366     // If the window is being closed with the debugger enabled,
367     // remember this state to re-enable debugger on the next window
368     // opening.
369     disableDebugger();
370 #endif
371     setSearchingForNode(false);
372
373     hideHighlight();
374
375 #if ENABLE(JAVASCRIPT_DEBUGGER)
376     m_profilerAgent->setFrontend(0);
377     m_profilerAgent->stopUserInitiatedProfiling(true);
378 #endif
379
380     m_consoleAgent->clearFrontend();
381     m_domAgent->clearFrontend();
382
383     releaseFrontendLifetimeAgents();
384     m_userAgentOverride = "";
385 }
386
387 InspectorResourceAgent* InspectorAgent::resourceAgent()
388 {
389     if (!m_resourceAgent && m_frontend)
390         m_resourceAgent = InspectorResourceAgent::create(m_inspectedPage, m_state.get(), m_frontend);
391     return m_resourceAgent.get();
392 }
393
394 void InspectorAgent::createFrontendLifetimeAgents()
395 {
396     m_runtimeAgent = InspectorRuntimeAgent::create(m_injectedScriptHost.get());
397
398 #if ENABLE(DATABASE)
399     m_databaseAgent = InspectorDatabaseAgent::create(databaseAgentResources(), m_frontend);
400 #endif
401
402 #if ENABLE(DOM_STORAGE)
403     m_domStorageAgent = InspectorDOMStorageAgent::create(domStorageAgentResources(), m_frontend);
404 #endif
405
406 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
407     m_applicationCacheAgent = new InspectorApplicationCacheAgent(m_inspectedPage->mainFrame()->loader()->documentLoader(), m_frontend);
408 #endif
409 }
410
411 void InspectorAgent::releaseFrontendLifetimeAgents()
412 {
413     m_resourceAgent.clear();
414     m_runtimeAgent.clear();
415     m_timelineAgent.clear();
416
417 #if ENABLE(DATABASE)
418     m_databaseAgent.clear();
419 #endif
420
421 #if ENABLE(DOM_STORAGE)
422     m_domStorageAgent.clear();
423 #endif
424
425 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
426     m_applicationCacheAgent.clear();
427 #endif
428 }
429
430 void InspectorAgent::populateScriptObjects()
431 {
432     ASSERT(m_frontend);
433     if (!m_frontend)
434         return;
435
436 #if ENABLE(JAVASCRIPT_DEBUGGER)
437     if (m_profilerAgent->enabled())
438         m_frontend->profilerWasEnabled();
439 #endif
440
441     pushDataCollectedOffline();
442
443     if (m_nodeToFocus)
444         focusNode();
445
446     if (!m_showPanelAfterVisible.isEmpty()) {
447         m_frontend->showPanel(m_showPanelAfterVisible);
448         m_showPanelAfterVisible = "";
449     }
450
451     restoreDebugger(true);
452     restoreProfiler(ProfilerRestoreNoAction);
453
454     // Dispatch pending frontend commands
455     for (Vector<pair<long, String> >::iterator it = m_pendingEvaluateTestCommands.begin(); it != m_pendingEvaluateTestCommands.end(); ++it)
456         m_frontend->evaluateForTestInFrontend((*it).first, (*it).second);
457     m_pendingEvaluateTestCommands.clear();
458 }
459
460 void InspectorAgent::pushDataCollectedOffline()
461 {
462     m_domAgent->setDocument(m_inspectedPage->mainFrame()->document());
463
464 #if ENABLE(JAVASCRIPT_DEBUGGER) && ENABLE(WORKERS)
465     WorkersMap::iterator workersEnd = m_workers.end();
466     for (WorkersMap::iterator it = m_workers.begin(); it != workersEnd; ++it) {
467         InspectorWorkerResource* worker = it->second.get();
468         m_frontend->didCreateWorker(worker->id(), worker->url(), worker->isSharedWorker());
469     }
470 #endif
471 }
472
473 void InspectorAgent::restoreDebugger(bool eraseStickyBreakpoints)
474 {
475     ASSERT(m_frontend);
476 #if ENABLE(JAVASCRIPT_DEBUGGER)
477     if (m_state->getBoolean(InspectorAgentState::debuggerEnabled))
478         enableDebugger(eraseStickyBreakpoints);
479 #endif
480 }
481
482 void InspectorAgent::restoreProfiler(ProfilerRestoreAction action)
483 {
484     ASSERT(m_frontend);
485 #if ENABLE(JAVASCRIPT_DEBUGGER)
486     m_profilerAgent->setFrontend(m_frontend);
487     if (m_state->getBoolean(InspectorAgentState::profilerEnabled))
488         enableProfiler();
489     if (action == ProfilerRestoreResetAgent)
490         m_profilerAgent->resetFrontendProfiles();
491 #endif
492 }
493
494 void InspectorAgent::didCommitLoad(DocumentLoader* loader)
495 {
496     if (!enabled())
497         return;
498
499     if (m_resourceAgent)
500         m_resourceAgent->didCommitLoad(loader);
501
502     ASSERT(m_inspectedPage);
503
504     if (loader->frame() == m_inspectedPage->mainFrame()) {
505         if (m_frontend)
506             m_frontend->inspectedURLChanged(loader->url().string());
507
508         m_injectedScriptHost->discardInjectedScripts();
509         m_consoleAgent->reset();
510
511         if (m_timelineAgent)
512             m_timelineAgent->didCommitLoad();
513
514 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
515         if (m_applicationCacheAgent)
516             m_applicationCacheAgent->didCommitLoad(loader);
517 #endif
518
519 #if ENABLE(JAVASCRIPT_DEBUGGER)
520         if (m_debuggerAgent) {
521             KURL url = inspectedURLWithoutFragment();
522             m_debuggerAgent->inspectedURLChanged(url);
523             if (m_browserDebuggerAgent)
524                 m_browserDebuggerAgent->inspectedURLChanged(url);
525         }
526 #endif
527
528 #if ENABLE(JAVASCRIPT_DEBUGGER) && USE(JSC)
529         m_profilerAgent->stopUserInitiatedProfiling(true);
530         m_profilerAgent->resetState();
531 #endif
532
533         if (m_frontend) {
534             m_frontend->reset();
535             m_domAgent->reset();
536             m_cssAgent->reset();
537         }
538 #if ENABLE(WORKERS)
539         m_workers.clear();
540 #endif
541 #if ENABLE(DATABASE)
542         InspectorDatabaseAgent::clear(this);
543 #endif
544 #if ENABLE(DOM_STORAGE)
545         InspectorDOMStorageAgent::clear(this);
546 #endif
547
548         if (InspectorDOMAgent* domAgent = m_instrumentingAgents->inspectorDOMAgent())
549             domAgent->setDocument(m_inspectedPage->mainFrame()->document());
550     }
551 }
552
553 void InspectorAgent::domContentLoadedEventFired(DocumentLoader* loader, const KURL& url)
554 {
555     if (!enabled() || !isMainResourceLoader(loader, url))
556         return;
557
558     if (InspectorDOMAgent* domAgent = m_instrumentingAgents->inspectorDOMAgent())
559         domAgent->mainFrameDOMContentLoaded();
560     if (m_timelineAgent)
561         m_timelineAgent->didMarkDOMContentEvent();
562     if (m_frontend)
563         m_frontend->domContentEventFired(currentTime());
564 }
565
566 void InspectorAgent::loadEventFired(DocumentLoader* loader, const KURL& url)
567 {
568     if (!enabled())
569         return;
570
571     if (InspectorDOMAgent* domAgent = m_instrumentingAgents->inspectorDOMAgent())
572         domAgent->loadEventFired(loader->frame()->document());
573
574     if (!isMainResourceLoader(loader, url))
575         return;
576
577     if (m_timelineAgent)
578         m_timelineAgent->didMarkLoadEvent();
579     if (m_frontend)
580         m_frontend->loadEventFired(currentTime());
581 }
582
583 bool InspectorAgent::isMainResourceLoader(DocumentLoader* loader, const KURL& requestUrl)
584 {
585     return loader->frame() == m_inspectedPage->mainFrame() && requestUrl == loader->requestURL();
586 }
587
588 void InspectorAgent::setUserAgentOverride(const String& userAgent)
589 {
590     m_userAgentOverride = userAgent;
591 }
592
593 void InspectorAgent::applyUserAgentOverride(String* userAgent) const
594 {
595     if (!m_userAgentOverride.isEmpty())
596         *userAgent = m_userAgentOverride;
597 }
598
599 void InspectorAgent::startTimelineProfiler()
600 {
601     if (m_timelineAgent || !enabled() || !m_frontend)
602         return;
603
604     m_timelineAgent = InspectorTimelineAgent::create(m_state.get(), m_frontend);
605 }
606
607 void InspectorAgent::stopTimelineProfiler()
608 {
609     m_timelineAgent.clear();
610 }
611
612 #if ENABLE(WORKERS)
613 class PostWorkerNotificationToFrontendTask : public ScriptExecutionContext::Task {
614 public:
615     static PassOwnPtr<PostWorkerNotificationToFrontendTask> create(PassRefPtr<InspectorWorkerResource> worker, InspectorAgent::WorkerAction action)
616     {
617         return new PostWorkerNotificationToFrontendTask(worker, action);
618     }
619
620 private:
621     PostWorkerNotificationToFrontendTask(PassRefPtr<InspectorWorkerResource> worker, InspectorAgent::WorkerAction action)
622         : m_worker(worker)
623         , m_action(action)
624     {
625     }
626
627     virtual void performTask(ScriptExecutionContext* scriptContext)
628     {
629         if (scriptContext->isDocument()) {
630             if (InspectorAgent* inspectorAgent = static_cast<Document*>(scriptContext)->page()->inspectorController()->m_inspectorAgent.get())
631                 inspectorAgent->postWorkerNotificationToFrontend(*m_worker, m_action);
632         }
633     }
634
635 private:
636     RefPtr<InspectorWorkerResource> m_worker;
637     InspectorAgent::WorkerAction m_action;
638 };
639
640 void InspectorAgent::postWorkerNotificationToFrontend(const InspectorWorkerResource& worker, InspectorAgent::WorkerAction action)
641 {
642     if (!m_frontend)
643         return;
644 #if ENABLE(JAVASCRIPT_DEBUGGER)
645     switch (action) {
646     case InspectorAgent::WorkerCreated:
647         m_frontend->didCreateWorker(worker.id(), worker.url(), worker.isSharedWorker());
648         break;
649     case InspectorAgent::WorkerDestroyed:
650         m_frontend->didDestroyWorker(worker.id());
651         break;
652     }
653 #endif
654 }
655
656 void InspectorAgent::didCreateWorker(intptr_t id, const String& url, bool isSharedWorker)
657 {
658     if (!enabled())
659         return;
660
661     RefPtr<InspectorWorkerResource> workerResource(InspectorWorkerResource::create(id, url, isSharedWorker));
662     m_workers.set(id, workerResource);
663     if (m_inspectedPage && m_frontend)
664         m_inspectedPage->mainFrame()->document()->postTask(PostWorkerNotificationToFrontendTask::create(workerResource, InspectorAgent::WorkerCreated));
665 }
666
667 void InspectorAgent::didDestroyWorker(intptr_t id)
668 {
669     if (!enabled())
670         return;
671
672     WorkersMap::iterator workerResource = m_workers.find(id);
673     if (workerResource == m_workers.end())
674         return;
675     if (m_inspectedPage && m_frontend)
676         m_inspectedPage->mainFrame()->document()->postTask(PostWorkerNotificationToFrontendTask::create(workerResource->second, InspectorAgent::WorkerDestroyed));
677     m_workers.remove(workerResource);
678 }
679 #endif // ENABLE(WORKERS)
680
681 void InspectorAgent::getCookies(RefPtr<InspectorArray>* cookies, WTF::String* cookiesString)
682 {
683     // If we can get raw cookies.
684     ListHashSet<Cookie> rawCookiesList;
685
686     // If we can't get raw cookies - fall back to String representation
687     String stringCookiesList;
688
689     // Return value to getRawCookies should be the same for every call because
690     // the return value is platform/network backend specific, and the call will
691     // always return the same true/false value.
692     bool rawCookiesImplemented = false;
693
694     for (Frame* frame = m_inspectedPage->mainFrame(); frame; frame = frame->tree()->traverseNext(m_inspectedPage->mainFrame())) {
695         Document* document = frame->document();
696         const CachedResourceLoader::DocumentResourceMap& allResources = document->cachedResourceLoader()->allCachedResources();
697         CachedResourceLoader::DocumentResourceMap::const_iterator end = allResources.end();
698         for (CachedResourceLoader::DocumentResourceMap::const_iterator it = allResources.begin(); it != end; ++it) {
699             Vector<Cookie> docCookiesList;
700             rawCookiesImplemented = getRawCookies(document, KURL(ParsedURLString, it->second->url()), docCookiesList);
701
702             if (!rawCookiesImplemented) {
703                 // FIXME: We need duplication checking for the String representation of cookies.
704                 ExceptionCode ec = 0;
705                 stringCookiesList += document->cookie(ec);
706                 // Exceptions are thrown by cookie() in sandboxed frames. That won't happen here
707                 // because "document" is the document of the main frame of the page.
708                 ASSERT(!ec);
709             } else {
710                 int cookiesSize = docCookiesList.size();
711                 for (int i = 0; i < cookiesSize; i++) {
712                     if (!rawCookiesList.contains(docCookiesList[i]))
713                         rawCookiesList.add(docCookiesList[i]);
714                 }
715             }
716         }
717     }
718
719     if (rawCookiesImplemented)
720         *cookies = buildArrayForCookies(rawCookiesList);
721     else
722         *cookiesString = stringCookiesList;
723 }
724
725 PassRefPtr<InspectorArray> InspectorAgent::buildArrayForCookies(ListHashSet<Cookie>& cookiesList)
726 {
727     RefPtr<InspectorArray> cookies = InspectorArray::create();
728
729     ListHashSet<Cookie>::iterator end = cookiesList.end();
730     ListHashSet<Cookie>::iterator it = cookiesList.begin();
731     for (int i = 0; it != end; ++it, i++)
732         cookies->pushObject(buildObjectForCookie(*it));
733
734     return cookies;
735 }
736
737 PassRefPtr<InspectorObject> InspectorAgent::buildObjectForCookie(const Cookie& cookie)
738 {
739     RefPtr<InspectorObject> value = InspectorObject::create();
740     value->setString("name", cookie.name);
741     value->setString("value", cookie.value);
742     value->setString("domain", cookie.domain);
743     value->setString("path", cookie.path);
744     value->setNumber("expires", cookie.expires);
745     value->setNumber("size", (cookie.name.length() + cookie.value.length()));
746     value->setBoolean("httpOnly", cookie.httpOnly);
747     value->setBoolean("secure", cookie.secure);
748     value->setBoolean("session", cookie.session);
749     return value;
750 }
751
752 void InspectorAgent::deleteCookie(const String& cookieName, const String& domain)
753 {
754     for (Frame* frame = m_inspectedPage->mainFrame(); frame; frame = frame->tree()->traverseNext(m_inspectedPage->mainFrame())) {
755         Document* document = frame->document();
756         if (document->url().host() != domain)
757             continue;
758         const CachedResourceLoader::DocumentResourceMap& allResources = document->cachedResourceLoader()->allCachedResources();
759         CachedResourceLoader::DocumentResourceMap::const_iterator end = allResources.end();
760         for (CachedResourceLoader::DocumentResourceMap::const_iterator it = allResources.begin(); it != end; ++it)
761             WebCore::deleteCookie(document, KURL(ParsedURLString, it->second->url()), cookieName);
762     }
763 }
764
765 #if ENABLE(WEB_SOCKETS)
766 void InspectorAgent::didCreateWebSocket(unsigned long identifier, const KURL& requestURL, const KURL& documentURL)
767 {
768     if (!enabled())
769         return;
770     ASSERT(m_inspectedPage);
771
772     if (m_resourceAgent)
773         m_resourceAgent->didCreateWebSocket(identifier, requestURL);
774     UNUSED_PARAM(documentURL);
775 }
776
777 void InspectorAgent::willSendWebSocketHandshakeRequest(unsigned long identifier, const WebSocketHandshakeRequest& request)
778 {
779     if (m_resourceAgent)
780         m_resourceAgent->willSendWebSocketHandshakeRequest(identifier, request);
781 }
782
783 void InspectorAgent::didReceiveWebSocketHandshakeResponse(unsigned long identifier, const WebSocketHandshakeResponse& response)
784 {
785     if (m_resourceAgent)
786         m_resourceAgent->didReceiveWebSocketHandshakeResponse(identifier, response);
787 }
788
789 void InspectorAgent::didCloseWebSocket(unsigned long identifier)
790 {
791     if (m_resourceAgent)
792         m_resourceAgent->didCloseWebSocket(identifier);
793 }
794 #endif // ENABLE(WEB_SOCKETS)
795
796 #if ENABLE(JAVASCRIPT_DEBUGGER)
797 bool InspectorAgent::isRecordingUserInitiatedProfile() const
798 {
799     return m_profilerAgent->isRecordingUserInitiatedProfile();
800 }
801
802 void InspectorAgent::startUserInitiatedProfiling()
803 {
804     if (!enabled())
805         return;
806     m_profilerAgent->startUserInitiatedProfiling();
807     m_state->setBoolean(InspectorAgentState::userInitiatedProfiling, true);
808 }
809
810 void InspectorAgent::stopUserInitiatedProfiling()
811 {
812     m_profilerAgent->stopUserInitiatedProfiling();
813     m_state->setBoolean(InspectorAgentState::userInitiatedProfiling, false);
814     showPanel(profilesPanelName);
815 }
816
817 bool InspectorAgent::profilerEnabled() const
818 {
819     return enabled() && m_profilerAgent->enabled();
820 }
821
822 void InspectorAgent::enableProfiler()
823 {
824     if (profilerEnabled())
825         return;
826     m_state->setBoolean(InspectorAgentState::profilerEnabled, true);
827     m_profilerAgent->enable(false);
828 }
829
830 void InspectorAgent::disableProfiler()
831 {
832     m_state->setBoolean(InspectorAgentState::profilerEnabled, false);
833     m_profilerAgent->disable();
834 }
835 #endif
836
837 #if ENABLE(JAVASCRIPT_DEBUGGER)
838 void InspectorAgent::startUserInitiatedDebugging()
839 {
840     if (debuggerEnabled())
841         return;
842
843     showPanel(scriptsPanelName);
844     if (!m_frontend) {
845         // We are called after show(), set the debuggerEnabled flag so that it was enabled
846         // upon frontend opening.
847         m_state->setBoolean(InspectorAgentState::debuggerEnabled, true);
848     } else
849         enableDebugger(true);
850 }
851
852 void InspectorAgent::enableDebugger(bool eraseStickyBreakpoints)
853 {
854     if (debuggerEnabled())
855         return;
856     m_state->setBoolean(InspectorAgentState::debuggerEnabled, true);
857     ASSERT(m_inspectedPage);
858
859     m_debuggerAgent = InspectorDebuggerAgent::create(this, m_frontend, eraseStickyBreakpoints);
860     m_browserDebuggerAgent = InspectorBrowserDebuggerAgent::create(this, eraseStickyBreakpoints);
861
862     m_frontend->debuggerWasEnabled();
863 }
864
865 void InspectorAgent::disableDebugger()
866 {
867     if (!enabled())
868         return;
869     ASSERT(m_inspectedPage);
870     m_debuggerAgent.clear();
871     m_browserDebuggerAgent.clear();
872
873     if (m_frontend) {
874         m_frontend->debuggerWasDisabled();
875         m_state->setBoolean(InspectorAgentState::debuggerEnabled, false);
876     }
877 }
878
879 void InspectorAgent::resume()
880 {
881     if (m_debuggerAgent)
882         m_debuggerAgent->resume();
883 }
884 #endif
885
886 void InspectorAgent::evaluateForTestInFrontend(long callId, const String& script)
887 {
888     if (m_frontend)
889         m_frontend->evaluateForTestInFrontend(callId, script);
890     else
891         m_pendingEvaluateTestCommands.append(pair<long, String>(callId, script));
892 }
893
894 void InspectorAgent::didEvaluateForTestInFrontend(long callId, const String& jsonResult)
895 {
896     ScriptState* scriptState = scriptStateFromPage(debuggerWorld(), m_inspectedPage);
897     ScriptObject window;
898     ScriptGlobalObject::get(scriptState, "window", window);
899     ScriptFunctionCall function(window, "didEvaluateForTestInFrontend");
900     function.appendArgument(callId);
901     function.appendArgument(jsonResult);
902     function.call();
903 }
904
905 static Path quadToPath(const FloatQuad& quad)
906 {
907     Path quadPath;
908     quadPath.moveTo(quad.p1());
909     quadPath.addLineTo(quad.p2());
910     quadPath.addLineTo(quad.p3());
911     quadPath.addLineTo(quad.p4());
912     quadPath.closeSubpath();
913     return quadPath;
914 }
915
916 static void drawOutlinedQuad(GraphicsContext& context, const FloatQuad& quad, const Color& fillColor)
917 {
918     static const int outlineThickness = 2;
919     static const Color outlineColor(62, 86, 180, 228);
920
921     Path quadPath = quadToPath(quad);
922
923     // Clip out the quad, then draw with a 2px stroke to get a pixel
924     // of outline (because inflating a quad is hard)
925     {
926         context.save();
927         context.clipOut(quadPath);
928
929         context.setStrokeThickness(outlineThickness);
930         context.setStrokeColor(outlineColor, ColorSpaceDeviceRGB);
931         context.strokePath(quadPath);
932
933         context.restore();
934     }
935
936     // Now do the fill
937     context.setFillColor(fillColor, ColorSpaceDeviceRGB);
938     context.fillPath(quadPath);
939 }
940
941 static void drawOutlinedQuadWithClip(GraphicsContext& context, const FloatQuad& quad, const FloatQuad& clipQuad, const Color& fillColor)
942 {
943     context.save();
944     Path clipQuadPath = quadToPath(clipQuad);
945     context.clipOut(clipQuadPath);
946     drawOutlinedQuad(context, quad, fillColor);
947     context.restore();
948 }
949
950 static void drawHighlightForBox(GraphicsContext& context, const FloatQuad& contentQuad, const FloatQuad& paddingQuad, const FloatQuad& borderQuad, const FloatQuad& marginQuad)
951 {
952     static const Color contentBoxColor(125, 173, 217, 128);
953     static const Color paddingBoxColor(125, 173, 217, 160);
954     static const Color borderBoxColor(125, 173, 217, 192);
955     static const Color marginBoxColor(125, 173, 217, 228);
956
957     if (marginQuad != borderQuad)
958         drawOutlinedQuadWithClip(context, marginQuad, borderQuad, marginBoxColor);
959     if (borderQuad != paddingQuad)
960         drawOutlinedQuadWithClip(context, borderQuad, paddingQuad, borderBoxColor);
961     if (paddingQuad != contentQuad)
962         drawOutlinedQuadWithClip(context, paddingQuad, contentQuad, paddingBoxColor);
963
964     drawOutlinedQuad(context, contentQuad, contentBoxColor);
965 }
966
967 static void drawHighlightForLineBoxesOrSVGRenderer(GraphicsContext& context, const Vector<FloatQuad>& lineBoxQuads)
968 {
969     static const Color lineBoxColor(125, 173, 217, 128);
970
971     for (size_t i = 0; i < lineBoxQuads.size(); ++i)
972         drawOutlinedQuad(context, lineBoxQuads[i], lineBoxColor);
973 }
974
975 static inline void convertFromFrameToMainFrame(Frame* frame, IntRect& rect)
976 {
977     rect = frame->page()->mainFrame()->view()->windowToContents(frame->view()->contentsToWindow(rect));
978 }
979
980 static inline IntSize frameToMainFrameOffset(Frame* frame)
981 {
982     IntPoint mainFramePoint = frame->page()->mainFrame()->view()->windowToContents(frame->view()->contentsToWindow(IntPoint()));
983     return mainFramePoint - IntPoint();
984 }
985
986 void InspectorAgent::drawNodeHighlight(GraphicsContext& context) const
987 {
988     if (!m_highlightedNode)
989         return;
990
991     RenderObject* renderer = m_highlightedNode->renderer();
992     Frame* containingFrame = m_highlightedNode->document()->frame();
993     if (!renderer || !containingFrame)
994         return;
995
996     IntSize mainFrameOffset = frameToMainFrameOffset(containingFrame);
997     IntRect boundingBox = renderer->absoluteBoundingBoxRect(true);
998     boundingBox.move(mainFrameOffset);
999
1000     IntRect titleReferenceBox = boundingBox;
1001
1002     ASSERT(m_inspectedPage);
1003
1004     FrameView* view = m_inspectedPage->mainFrame()->view();
1005     FloatRect overlayRect = view->visibleContentRect();
1006     if (!overlayRect.contains(boundingBox) && !boundingBox.contains(enclosingIntRect(overlayRect)))
1007         overlayRect = view->visibleContentRect();
1008     context.translate(-overlayRect.x(), -overlayRect.y());
1009
1010     // RenderSVGRoot should be highlighted through the isBox() code path, all other SVG elements should just dump their absoluteQuads().
1011 #if ENABLE(SVG)
1012     bool isSVGRenderer = renderer->node() && renderer->node()->isSVGElement() && !renderer->isSVGRoot();
1013 #else
1014     bool isSVGRenderer = false;
1015 #endif
1016
1017     if (renderer->isBox() && !isSVGRenderer) {
1018         RenderBox* renderBox = toRenderBox(renderer);
1019
1020         IntRect contentBox = renderBox->contentBoxRect();
1021
1022         IntRect paddingBox(contentBox.x() - renderBox->paddingLeft(), contentBox.y() - renderBox->paddingTop(),
1023                            contentBox.width() + renderBox->paddingLeft() + renderBox->paddingRight(), contentBox.height() + renderBox->paddingTop() + renderBox->paddingBottom());
1024         IntRect borderBox(paddingBox.x() - renderBox->borderLeft(), paddingBox.y() - renderBox->borderTop(),
1025                           paddingBox.width() + renderBox->borderLeft() + renderBox->borderRight(), paddingBox.height() + renderBox->borderTop() + renderBox->borderBottom());
1026         IntRect marginBox(borderBox.x() - renderBox->marginLeft(), borderBox.y() - renderBox->marginTop(),
1027                           borderBox.width() + renderBox->marginLeft() + renderBox->marginRight(), borderBox.height() + renderBox->marginTop() + renderBox->marginBottom());
1028
1029
1030         FloatQuad absContentQuad = renderBox->localToAbsoluteQuad(FloatRect(contentBox));
1031         FloatQuad absPaddingQuad = renderBox->localToAbsoluteQuad(FloatRect(paddingBox));
1032         FloatQuad absBorderQuad = renderBox->localToAbsoluteQuad(FloatRect(borderBox));
1033         FloatQuad absMarginQuad = renderBox->localToAbsoluteQuad(FloatRect(marginBox));
1034
1035         absContentQuad.move(mainFrameOffset);
1036         absPaddingQuad.move(mainFrameOffset);
1037         absBorderQuad.move(mainFrameOffset);
1038         absMarginQuad.move(mainFrameOffset);
1039
1040         titleReferenceBox = absMarginQuad.enclosingBoundingBox();
1041
1042         drawHighlightForBox(context, absContentQuad, absPaddingQuad, absBorderQuad, absMarginQuad);
1043     } else if (renderer->isRenderInline() || isSVGRenderer) {
1044         // FIXME: We should show margins/padding/border for inlines.
1045         Vector<FloatQuad> lineBoxQuads;
1046         renderer->absoluteQuads(lineBoxQuads);
1047         for (unsigned i = 0; i < lineBoxQuads.size(); ++i)
1048             lineBoxQuads[i] += mainFrameOffset;
1049
1050         drawHighlightForLineBoxesOrSVGRenderer(context, lineBoxQuads);
1051     }
1052
1053     // Draw node title if necessary.
1054
1055     if (!m_highlightedNode->isElementNode())
1056         return;
1057
1058     WebCore::Settings* settings = containingFrame->settings();
1059     drawElementTitle(context, titleReferenceBox, overlayRect, settings);
1060 }
1061
1062 void InspectorAgent::drawElementTitle(GraphicsContext& context, const IntRect& boundingBox, const FloatRect& overlayRect, WebCore::Settings* settings) const
1063 {
1064     static const int rectInflatePx = 4;
1065     static const int fontHeightPx = 12;
1066     static const int borderWidthPx = 1;
1067     static const Color tooltipBackgroundColor(255, 255, 194, 255);
1068     static const Color tooltipBorderColor(Color::black);
1069     static const Color tooltipFontColor(Color::black);
1070
1071     Element* element = static_cast<Element*>(m_highlightedNode.get());
1072     bool isXHTML = element->document()->isXHTMLDocument();
1073     String nodeTitle = isXHTML ? element->nodeName() : element->nodeName().lower();
1074     const AtomicString& idValue = element->getIdAttribute();
1075     if (!idValue.isNull() && !idValue.isEmpty()) {
1076         nodeTitle += "#";
1077         nodeTitle += idValue;
1078     }
1079     if (element->hasClass() && element->isStyledElement()) {
1080         const SpaceSplitString& classNamesString = static_cast<StyledElement*>(element)->classNames();
1081         size_t classNameCount = classNamesString.size();
1082         if (classNameCount) {
1083             HashSet<AtomicString> usedClassNames;
1084             for (size_t i = 0; i < classNameCount; ++i) {
1085                 const AtomicString& className = classNamesString[i];
1086                 if (usedClassNames.contains(className))
1087                     continue;
1088                 usedClassNames.add(className);
1089                 nodeTitle += ".";
1090                 nodeTitle += className;
1091             }
1092         }
1093     }
1094
1095     Element* highlightedElement = m_highlightedNode->isElementNode() ? static_cast<Element*>(m_highlightedNode.get()) : 0;
1096     nodeTitle += " [";
1097     nodeTitle += String::number(highlightedElement ? highlightedElement->offsetWidth() : boundingBox.width());
1098     nodeTitle.append(static_cast<UChar>(0x00D7)); // &times;
1099     nodeTitle += String::number(highlightedElement ? highlightedElement->offsetHeight() : boundingBox.height());
1100     nodeTitle += "]";
1101
1102     FontDescription desc;
1103     FontFamily family;
1104     family.setFamily(settings->fixedFontFamily());
1105     desc.setFamily(family);
1106     desc.setComputedSize(fontHeightPx);
1107     Font font = Font(desc, 0, 0);
1108     font.update(0);
1109
1110     TextRun nodeTitleRun(nodeTitle);
1111     IntPoint titleBasePoint = IntPoint(boundingBox.x(), boundingBox.maxY() - 1);
1112     titleBasePoint.move(rectInflatePx, rectInflatePx);
1113     IntRect titleRect = enclosingIntRect(font.selectionRectForText(nodeTitleRun, titleBasePoint, fontHeightPx));
1114     titleRect.inflate(rectInflatePx);
1115
1116     // The initial offsets needed to compensate for a 1px-thick border stroke (which is not a part of the rectangle).
1117     int dx = -borderWidthPx;
1118     int dy = borderWidthPx;
1119
1120     // If the tip sticks beyond the right of overlayRect, right-align the tip with the said boundary.
1121     if (titleRect.maxX() > overlayRect.maxX())
1122         dx = overlayRect.maxX() - titleRect.maxX();
1123
1124     // If the tip sticks beyond the left of overlayRect, left-align the tip with the said boundary.
1125     if (titleRect.x() + dx < overlayRect.x())
1126         dx = overlayRect.x() - titleRect.x() - borderWidthPx;
1127
1128     // If the tip sticks beyond the bottom of overlayRect, show the tip at top of bounding box.
1129     if (titleRect.maxY() > overlayRect.maxY()) {
1130         dy = boundingBox.y() - titleRect.maxY() - borderWidthPx;
1131         // If the tip still sticks beyond the bottom of overlayRect, bottom-align the tip with the said boundary.
1132         if (titleRect.maxY() + dy > overlayRect.maxY())
1133             dy = overlayRect.maxY() - titleRect.maxY();
1134     }
1135
1136     // If the tip sticks beyond the top of overlayRect, show the tip at top of overlayRect.
1137     if (titleRect.y() + dy < overlayRect.y())
1138         dy = overlayRect.y() - titleRect.y() + borderWidthPx;
1139
1140     titleRect.move(dx, dy);
1141     context.setStrokeColor(tooltipBorderColor, ColorSpaceDeviceRGB);
1142     context.setStrokeThickness(borderWidthPx);
1143     context.setFillColor(tooltipBackgroundColor, ColorSpaceDeviceRGB);
1144     context.drawRect(titleRect);
1145     context.setFillColor(tooltipFontColor, ColorSpaceDeviceRGB);
1146     context.drawText(font, nodeTitleRun, IntPoint(titleRect.x() + rectInflatePx, titleRect.y() + font.fontMetrics().height()));
1147 }
1148
1149 void InspectorAgent::openInInspectedWindow(const String& url)
1150 {
1151     Frame* mainFrame = m_inspectedPage->mainFrame();
1152
1153     FrameLoadRequest request(mainFrame->document()->securityOrigin(), ResourceRequest(), "_blank");
1154
1155     bool created;
1156     WindowFeatures windowFeatures;
1157     Frame* newFrame = WebCore::createWindow(mainFrame, mainFrame, request, windowFeatures, created);
1158     if (!newFrame)
1159         return;
1160
1161     UserGestureIndicator indicator(DefinitelyProcessingUserGesture);
1162     newFrame->loader()->setOpener(mainFrame);
1163     newFrame->page()->setOpenedByDOM();
1164     newFrame->loader()->changeLocation(mainFrame->document()->securityOrigin(), newFrame->loader()->completeURL(url), "", false, false);
1165 }
1166
1167 void InspectorAgent::addScriptToEvaluateOnLoad(const String& source)
1168 {
1169     m_scriptsToEvaluateOnLoad.append(source);
1170 }
1171
1172 void InspectorAgent::removeAllScriptsToEvaluateOnLoad()
1173 {
1174     m_scriptsToEvaluateOnLoad.clear();
1175 }
1176
1177 void InspectorAgent::setInspectorExtensionAPI(const String& source)
1178 {
1179     m_inspectorExtensionAPI = source;
1180 }
1181
1182 KURL InspectorAgent::inspectedURL() const
1183 {
1184     return m_inspectedPage->mainFrame()->document()->url();
1185 }
1186
1187 KURL InspectorAgent::inspectedURLWithoutFragment() const
1188 {
1189     KURL url = inspectedURL();
1190     url.removeFragmentIdentifier();
1191     return url;
1192 }
1193
1194 void InspectorAgent::reloadPage(bool ignoreCache)
1195 {
1196     m_inspectedPage->mainFrame()->loader()->reload(ignoreCache);
1197 }
1198
1199 bool InspectorAgent::enabled() const
1200 {
1201     if (!m_inspectedPage)
1202         return false;
1203     return m_inspectedPage->settings()->developerExtrasEnabled();
1204 }
1205
1206 void InspectorAgent::showConsole()
1207 {
1208     showPanel(consolePanelName);
1209 }
1210
1211 void InspectorAgent::showPanel(const String& panel)
1212 {
1213     if (!m_frontend) {
1214         m_showPanelAfterVisible = panel;
1215         return;
1216     }
1217     m_frontend->showPanel(panel);
1218 }
1219
1220 } // namespace WebCore
1221
1222 #endif // ENABLE(INSPECTOR)