| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007, 2008, 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2008, 2009 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com> | 3 * Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com> |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * | 8 * |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 , m_windowVisible(false) | 136 , m_windowVisible(false) |
| 137 , m_showAfterVisible(CurrentPanel) | 137 , m_showAfterVisible(CurrentPanel) |
| 138 , m_groupLevel(0) | 138 , m_groupLevel(0) |
| 139 , m_searchingForNode(false) | 139 , m_searchingForNode(false) |
| 140 , m_previousMessage(0) | 140 , m_previousMessage(0) |
| 141 , m_resourceTrackingEnabled(false) | 141 , m_resourceTrackingEnabled(false) |
| 142 , m_resourceTrackingSettingsLoaded(false) | 142 , m_resourceTrackingSettingsLoaded(false) |
| 143 , m_inspectorBackend(InspectorBackend::create(this)) | 143 , m_inspectorBackend(InspectorBackend::create(this)) |
| 144 , m_inspectorFrontendHost(InspectorFrontendHost::create(this, client)) | 144 , m_inspectorFrontendHost(InspectorFrontendHost::create(this, client)) |
| 145 , m_injectedScriptHost(InjectedScriptHost::create(this)) | 145 , m_injectedScriptHost(InjectedScriptHost::create(this)) |
| 146 , m_lastBoundObjectId(1) | |
| 147 #if ENABLE(JAVASCRIPT_DEBUGGER) | 146 #if ENABLE(JAVASCRIPT_DEBUGGER) |
| 148 , m_debuggerEnabled(false) | 147 , m_debuggerEnabled(false) |
| 149 , m_attachDebuggerWhenShown(false) | 148 , m_attachDebuggerWhenShown(false) |
| 150 , m_profilerEnabled(false) | 149 , m_profilerEnabled(false) |
| 151 , m_recordingUserInitiatedProfile(false) | 150 , m_recordingUserInitiatedProfile(false) |
| 152 , m_currentUserInitiatedProfileNumber(-1) | 151 , m_currentUserInitiatedProfileNumber(-1) |
| 153 , m_nextUserInitiatedProfileNumber(1) | 152 , m_nextUserInitiatedProfileNumber(1) |
| 154 , m_startProfiling(this, &InspectorController::startUserInitiatedProfiling) | 153 , m_startProfiling(this, &InspectorController::startUserInitiatedProfiling) |
| 155 #endif | 154 #endif |
| 156 { | 155 { |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 } | 367 } |
| 369 } | 368 } |
| 370 | 369 |
| 371 void InspectorController::clearConsoleMessages() | 370 void InspectorController::clearConsoleMessages() |
| 372 { | 371 { |
| 373 deleteAllValues(m_consoleMessages); | 372 deleteAllValues(m_consoleMessages); |
| 374 m_consoleMessages.clear(); | 373 m_consoleMessages.clear(); |
| 375 m_expiredConsoleMessageCount = 0; | 374 m_expiredConsoleMessageCount = 0; |
| 376 m_previousMessage = 0; | 375 m_previousMessage = 0; |
| 377 m_groupLevel = 0; | 376 m_groupLevel = 0; |
| 378 releaseWrapperObjectGroup("console"); | 377 m_injectedScriptHost->releaseWrapperObjectGroup(0 /* release the group in al
l scripts */, "console"); |
| 379 if (m_domAgent) | 378 if (m_domAgent) |
| 380 m_domAgent->releaseDanglingNodes(); | 379 m_domAgent->releaseDanglingNodes(); |
| 381 if (m_frontend) | 380 if (m_frontend) |
| 382 m_frontend->clearConsoleMessages(); | 381 m_frontend->clearConsoleMessages(); |
| 383 } | 382 } |
| 384 | 383 |
| 385 void InspectorController::startGroup(MessageSource source, ScriptCallStack* call
Stack) | 384 void InspectorController::startGroup(MessageSource source, ScriptCallStack* call
Stack) |
| 386 { | 385 { |
| 387 ++m_groupLevel; | 386 ++m_groupLevel; |
| 388 | 387 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 return; | 492 return; |
| 494 | 493 |
| 495 // inspect() will implicitly call ElementsPanel's focusedNodeChanged() and t
he hover feedback will be stopped there. | 494 // inspect() will implicitly call ElementsPanel's focusedNodeChanged() and t
he hover feedback will be stopped there. |
| 496 inspect(node); | 495 inspect(node); |
| 497 } | 496 } |
| 498 | 497 |
| 499 void InspectorController::inspectedWindowScriptObjectCleared(Frame* frame) | 498 void InspectorController::inspectedWindowScriptObjectCleared(Frame* frame) |
| 500 { | 499 { |
| 501 if (!enabled() || !m_frontend || frame != m_inspectedPage->mainFrame()) | 500 if (!enabled() || !m_frontend || frame != m_inspectedPage->mainFrame()) |
| 502 return; | 501 return; |
| 503 resetInjectedScript(); | 502 m_injectedScriptHost->discardInjectedScripts(); |
| 504 } | 503 } |
| 505 | 504 |
| 506 void InspectorController::windowScriptObjectAvailable() | 505 void InspectorController::windowScriptObjectAvailable() |
| 507 { | 506 { |
| 508 if (!m_page || !enabled()) | 507 if (!m_page || !enabled()) |
| 509 return; | 508 return; |
| 510 | 509 |
| 511 // Grant the inspector the ability to script the inspected page. | 510 // Grant the inspector the ability to script the inspected page. |
| 512 m_page->mainFrame()->document()->securityOrigin()->grantUniversalAccess(); | 511 m_page->mainFrame()->document()->securityOrigin()->grantUniversalAccess(); |
| 513 m_scriptState = scriptStateFromPage(debuggerWorld(), m_page); | 512 m_scriptState = scriptStateFromPage(debuggerWorld(), m_page); |
| 514 ScriptGlobalObject::set(m_scriptState, "InspectorBackend", m_inspectorBacken
d.get()); | 513 ScriptGlobalObject::set(m_scriptState, "InspectorBackend", m_inspectorBacken
d.get()); |
| 515 ScriptGlobalObject::set(m_scriptState, "InspectorFrontendHost", m_inspectorF
rontendHost.get()); | 514 ScriptGlobalObject::set(m_scriptState, "InspectorFrontendHost", m_inspectorF
rontendHost.get()); |
| 516 ScriptGlobalObject::set(m_scriptState, "InjectedScriptHost", m_injectedScrip
tHost.get()); | |
| 517 } | 515 } |
| 518 | 516 |
| 519 void InspectorController::scriptObjectReady() | 517 void InspectorController::scriptObjectReady() |
| 520 { | 518 { |
| 521 ASSERT(m_scriptState); | 519 ASSERT(m_scriptState); |
| 522 if (!m_scriptState) | 520 if (!m_scriptState) |
| 523 return; | 521 return; |
| 524 | 522 |
| 525 ScriptObject webInspectorObj; | 523 ScriptObject webInspectorObj; |
| 526 if (!ScriptGlobalObject::get(m_scriptState, "WebInspector", webInspectorObj)
) | 524 if (!ScriptGlobalObject::get(m_scriptState, "WebInspector", webInspectorObj)
) |
| 527 return; | 525 return; |
| 528 ScriptObject injectedScriptObj; | 526 ScriptObject injectedScriptObj; |
| 529 if (!ScriptGlobalObject::get(m_scriptState, "InjectedScript", injectedScript
Obj)) | |
| 530 return; | |
| 531 setFrontendProxyObject(m_scriptState, webInspectorObj, injectedScriptObj); | 527 setFrontendProxyObject(m_scriptState, webInspectorObj, injectedScriptObj); |
| 532 | 528 |
| 533 #if ENABLE(JAVASCRIPT_DEBUGGER) | 529 #if ENABLE(JAVASCRIPT_DEBUGGER) |
| 534 String debuggerEnabled = setting(debuggerEnabledSettingName); | 530 String debuggerEnabled = setting(debuggerEnabledSettingName); |
| 535 if (debuggerEnabled == "true") | 531 if (debuggerEnabled == "true") |
| 536 enableDebugger(); | 532 enableDebugger(); |
| 537 String profilerEnabled = setting(profilerEnabledSettingName); | 533 String profilerEnabled = setting(profilerEnabledSettingName); |
| 538 if (profilerEnabled == "true") | 534 if (profilerEnabled == "true") |
| 539 enableProfiler(); | 535 enableProfiler(); |
| 540 #endif | 536 #endif |
| 541 | 537 |
| 542 // Make sure our window is visible now that the page loaded | 538 // Make sure our window is visible now that the page loaded |
| 543 showWindow(); | 539 showWindow(); |
| 544 | 540 |
| 545 m_client->inspectorWindowObjectCleared(); | 541 m_client->inspectorWindowObjectCleared(); |
| 546 } | 542 } |
| 547 | 543 |
| 548 void InspectorController::setFrontendProxyObject(ScriptState* scriptState, Scrip
tObject webInspectorObj, ScriptObject injectedScriptObj) | 544 void InspectorController::setFrontendProxyObject(ScriptState* scriptState, Scrip
tObject webInspectorObj, ScriptObject) |
| 549 { | 545 { |
| 550 m_scriptState = scriptState; | 546 m_scriptState = scriptState; |
| 551 m_injectedScriptObj = injectedScriptObj; | |
| 552 m_frontend.set(new InspectorFrontend(this, scriptState, webInspectorObj)); | 547 m_frontend.set(new InspectorFrontend(this, scriptState, webInspectorObj)); |
| 553 releaseDOMAgent(); | 548 releaseDOMAgent(); |
| 554 m_domAgent = InspectorDOMAgent::create(m_frontend.get()); | 549 m_domAgent = InspectorDOMAgent::create(m_frontend.get()); |
| 555 if (m_timelineAgent) | 550 if (m_timelineAgent) |
| 556 m_timelineAgent->resetFrontendProxyObject(m_frontend.get()); | 551 m_timelineAgent->resetFrontendProxyObject(m_frontend.get()); |
| 557 } | 552 } |
| 558 | 553 |
| 559 void InspectorController::show() | 554 void InspectorController::show() |
| 560 { | 555 { |
| 561 if (!enabled()) | 556 if (!enabled()) |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 599 { | 594 { |
| 600 if (!enabled()) | 595 if (!enabled()) |
| 601 return; | 596 return; |
| 602 | 597 |
| 603 #if ENABLE(JAVASCRIPT_DEBUGGER) | 598 #if ENABLE(JAVASCRIPT_DEBUGGER) |
| 604 stopUserInitiatedProfiling(); | 599 stopUserInitiatedProfiling(); |
| 605 disableDebugger(); | 600 disableDebugger(); |
| 606 #endif | 601 #endif |
| 607 closeWindow(); | 602 closeWindow(); |
| 608 | 603 |
| 609 m_injectedScriptObj = ScriptObject(); | |
| 610 releaseDOMAgent(); | 604 releaseDOMAgent(); |
| 611 m_frontend.set(0); | 605 m_frontend.set(0); |
| 612 m_timelineAgent = 0; | 606 m_timelineAgent = 0; |
| 613 m_scriptState = 0; | 607 m_scriptState = 0; |
| 614 if (m_page) { | 608 if (m_page) { |
| 615 if (!m_page->mainFrame() || !m_page->mainFrame()->loader() || !m_page->m
ainFrame()->loader()->isLoading()) { | 609 if (!m_page->mainFrame() || !m_page->mainFrame()->loader() || !m_page->m
ainFrame()->loader()->isLoading()) { |
| 616 m_page->setParentInspectorController(0); | 610 m_page->setParentInspectorController(0); |
| 617 m_page = 0; | 611 m_page = 0; |
| 618 } | 612 } |
| 619 } | 613 } |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 708 DOMStorageResourcesMap::iterator domStorageEnd = m_domStorageResources.end()
; | 702 DOMStorageResourcesMap::iterator domStorageEnd = m_domStorageResources.end()
; |
| 709 for (DOMStorageResourcesMap::iterator it = m_domStorageResources.begin(); it
!= domStorageEnd; ++it) | 703 for (DOMStorageResourcesMap::iterator it = m_domStorageResources.begin(); it
!= domStorageEnd; ++it) |
| 710 it->second->unbind(); | 704 it->second->unbind(); |
| 711 #endif | 705 #endif |
| 712 | 706 |
| 713 if (m_timelineAgent) | 707 if (m_timelineAgent) |
| 714 m_timelineAgent->reset(); | 708 m_timelineAgent->reset(); |
| 715 | 709 |
| 716 m_frontend->reset(); | 710 m_frontend->reset(); |
| 717 m_domAgent->reset(); | 711 m_domAgent->reset(); |
| 718 m_objectGroups.clear(); | |
| 719 m_idToWrappedObject.clear(); | |
| 720 } | 712 } |
| 721 | 713 |
| 722 void InspectorController::pruneResources(ResourcesMap* resourceMap, DocumentLoad
er* loaderToKeep) | 714 void InspectorController::pruneResources(ResourcesMap* resourceMap, DocumentLoad
er* loaderToKeep) |
| 723 { | 715 { |
| 724 ASSERT_ARG(resourceMap, resourceMap); | 716 ASSERT_ARG(resourceMap, resourceMap); |
| 725 | 717 |
| 726 ResourcesMap mapCopy(*resourceMap); | 718 ResourcesMap mapCopy(*resourceMap); |
| 727 ResourcesMap::iterator end = mapCopy.end(); | 719 ResourcesMap::iterator end = mapCopy.end(); |
| 728 for (ResourcesMap::iterator it = mapCopy.begin(); it != end; ++it) { | 720 for (ResourcesMap::iterator it = mapCopy.begin(); it != end; ++it) { |
| 729 InspectorResource* resource = (*it).second.get(); | 721 InspectorResource* resource = (*it).second.get(); |
| (...skipping 854 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1584 m_frontend->parsedScriptSource(source); | 1576 m_frontend->parsedScriptSource(source); |
| 1585 } | 1577 } |
| 1586 | 1578 |
| 1587 void InspectorController::failedToParseSource(ExecState*, const SourceCode& sour
ce, int errorLine, const UString& errorMessage) | 1579 void InspectorController::failedToParseSource(ExecState*, const SourceCode& sour
ce, int errorLine, const UString& errorMessage) |
| 1588 { | 1580 { |
| 1589 m_frontend->failedToParseScriptSource(source, errorLine, errorMessage); | 1581 m_frontend->failedToParseScriptSource(source, errorLine, errorMessage); |
| 1590 } | 1582 } |
| 1591 | 1583 |
| 1592 void InspectorController::didPause() | 1584 void InspectorController::didPause() |
| 1593 { | 1585 { |
| 1594 ScriptFunctionCall function(m_scriptState, m_injectedScriptObj, "getCallFram
es"); | 1586 JavaScriptCallFrame* callFrame = m_injectedScriptHost->currentCallFrame(); |
| 1595 ScriptValue callFrames = function.call(); | 1587 ScriptState* scriptState = callFrame->scopeChain()->globalObject->globalExec
(); |
| 1588 ASSERT(scriptState); |
| 1589 ScriptObject injectedScriptObj = m_injectedScriptHost->injectedScriptFor(scr
iptState); |
| 1590 ScriptFunctionCall function(scriptState, injectedScriptObj, "getCallFrames")
; |
| 1591 ScriptValue callFramesValue = function.call(); |
| 1592 String callFrames = callFramesValue.toString(scriptState); |
| 1593 |
| 1596 m_frontend->pausedScript(callFrames); | 1594 m_frontend->pausedScript(callFrames); |
| 1597 } | 1595 } |
| 1598 | 1596 |
| 1599 void InspectorController::didContinue() | 1597 void InspectorController::didContinue() |
| 1600 { | 1598 { |
| 1601 m_frontend->resumedScript(); | 1599 m_frontend->resumedScript(); |
| 1602 } | 1600 } |
| 1603 | 1601 |
| 1604 #endif | 1602 #endif |
| 1605 | 1603 |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1813 else if (panelName == "profiles") | 1811 else if (panelName == "profiles") |
| 1814 return ProfilesPanel; | 1812 return ProfilesPanel; |
| 1815 else if (panelName == "storage" || panelName == "databases") | 1813 else if (panelName == "storage" || panelName == "databases") |
| 1816 return StoragePanel; | 1814 return StoragePanel; |
| 1817 else if (panelName == "console") | 1815 else if (panelName == "console") |
| 1818 return ConsolePanel; | 1816 return ConsolePanel; |
| 1819 else | 1817 else |
| 1820 return ElementsPanel; | 1818 return ElementsPanel; |
| 1821 } | 1819 } |
| 1822 | 1820 |
| 1823 ScriptValue InspectorController::wrapObject(const ScriptValue& quarantinedObject
, const String& objectGroup) | |
| 1824 { | |
| 1825 ScriptFunctionCall function(m_scriptState, m_injectedScriptObj, "createProxy
Object"); | |
| 1826 function.appendArgument(quarantinedObject); | |
| 1827 if (quarantinedObject.isObject()) { | |
| 1828 long id = m_lastBoundObjectId++; | |
| 1829 String objectId = String::format("object#%ld", id); | |
| 1830 m_idToWrappedObject.set(objectId, quarantinedObject); | |
| 1831 ObjectGroupsMap::iterator it = m_objectGroups.find(objectGroup); | |
| 1832 if (it == m_objectGroups.end()) | |
| 1833 it = m_objectGroups.set(objectGroup, Vector<String>()).first; | |
| 1834 it->second.append(objectId); | |
| 1835 function.appendArgument(objectId); | |
| 1836 } | |
| 1837 ScriptValue wrapper = function.call(); | |
| 1838 return wrapper; | |
| 1839 } | |
| 1840 | |
| 1841 ScriptValue InspectorController::unwrapObject(const String& objectId) | |
| 1842 { | |
| 1843 HashMap<String, ScriptValue>::iterator it = m_idToWrappedObject.find(objectI
d); | |
| 1844 if (it != m_idToWrappedObject.end()) | |
| 1845 return it->second; | |
| 1846 return ScriptValue(); | |
| 1847 } | |
| 1848 | |
| 1849 void InspectorController::releaseWrapperObjectGroup(const String& objectGroup) | |
| 1850 { | |
| 1851 ObjectGroupsMap::iterator groupIt = m_objectGroups.find(objectGroup); | |
| 1852 if (groupIt == m_objectGroups.end()) | |
| 1853 return; | |
| 1854 | |
| 1855 Vector<String>& groupIds = groupIt->second; | |
| 1856 for (Vector<String>::iterator it = groupIds.begin(); it != groupIds.end(); +
+it) | |
| 1857 m_idToWrappedObject.remove(*it); | |
| 1858 m_objectGroups.remove(groupIt); | |
| 1859 } | |
| 1860 | |
| 1861 void InspectorController::resetInjectedScript() | |
| 1862 { | |
| 1863 ScriptFunctionCall function(m_scriptState, m_injectedScriptObj, "reset"); | |
| 1864 function.call(); | |
| 1865 } | |
| 1866 | |
| 1867 void InspectorController::deleteCookie(const String& cookieName, const String& d
omain) | 1821 void InspectorController::deleteCookie(const String& cookieName, const String& d
omain) |
| 1868 { | 1822 { |
| 1869 ResourcesMap::iterator resourcesEnd = m_resources.end(); | 1823 ResourcesMap::iterator resourcesEnd = m_resources.end(); |
| 1870 for (ResourcesMap::iterator it = m_resources.begin(); it != resourcesEnd; ++
it) { | 1824 for (ResourcesMap::iterator it = m_resources.begin(); it != resourcesEnd; ++
it) { |
| 1871 Document* document = it->second->frame()->document(); | 1825 Document* document = it->second->frame()->document(); |
| 1872 if (document->url().host() == domain) | 1826 if (document->url().host() == domain) |
| 1873 WebCore::deleteCookie(document, document->cookieURL(), cookieName); | 1827 WebCore::deleteCookie(document, document->cookieURL(), cookieName); |
| 1874 } | 1828 } |
| 1875 } | 1829 } |
| 1876 | 1830 |
| 1877 void InspectorController::didInsertDOMNode(Node* node) | 1831 void InspectorController::didInsertDOMNode(Node* node) |
| 1878 { | 1832 { |
| 1879 if (m_domAgent) | 1833 if (m_domAgent) |
| 1880 m_domAgent->didInsertDOMNode(node); | 1834 m_domAgent->didInsertDOMNode(node); |
| 1881 } | 1835 } |
| 1882 | 1836 |
| 1883 void InspectorController::didRemoveDOMNode(Node* node) | 1837 void InspectorController::didRemoveDOMNode(Node* node) |
| 1884 { | 1838 { |
| 1885 if (m_domAgent) | 1839 if (m_domAgent) |
| 1886 m_domAgent->didRemoveDOMNode(node); | 1840 m_domAgent->didRemoveDOMNode(node); |
| 1887 } | 1841 } |
| 1888 | 1842 |
| 1889 void InspectorController::didModifyDOMAttr(Element* element) | 1843 void InspectorController::didModifyDOMAttr(Element* element) |
| 1890 { | 1844 { |
| 1891 if (m_domAgent) | 1845 if (m_domAgent) |
| 1892 m_domAgent->didModifyDOMAttr(element); | 1846 m_domAgent->didModifyDOMAttr(element); |
| 1893 } | 1847 } |
| 1894 | 1848 |
| 1895 } // namespace WebCore | 1849 ScriptObject InspectorController::injectedScriptForNodeId(long id) |
| 1850 { |
| 1851 |
| 1852 Frame* frame = 0; |
| 1853 if (id) { |
| 1854 ASSERT(m_domAgent); |
| 1855 Node* node = m_domAgent->nodeForId(id); |
| 1856 if (node) { |
| 1857 Document* document = node->ownerDocument(); |
| 1858 if (document) |
| 1859 frame = document->frame(); |
| 1860 } |
| 1861 } else |
| 1862 frame = m_inspectedPage->mainFrame(); |
| 1863 |
| 1864 if (frame) |
| 1865 return m_injectedScriptHost->injectedScriptFor(frame->script()->mainWorl
dScriptState()); |
| 1866 |
| 1867 return ScriptObject(); |
| 1868 } |
| 1869 |
| 1870 } // namespace WebCore |
| 1896 | 1871 |
| 1897 #endif // ENABLE(INSPECTOR) | 1872 #endif // ENABLE(INSPECTOR) |
| OLD | NEW |