1 /* 2 * Copyright (C) 2010 Apple Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 23 * THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26 #include "config.h" 27 #include "WebInspector.h" 28 29 #if ENABLE(INSPECTOR) 30 31 #include "WebInspectorProxyMessages.h" 32 #include "WebPage.h" 33 #include "WebPageCreationParameters.h" 34 #include "WebProcess.h" 35 #include <WebCore/InspectorController.h> 36 #include <WebCore/Page.h> 37 38 using namespace WebCore; 39 40 namespace WebKit { 41 42 PassRefPtr<WebInspector> WebInspector::create(WebPage* page) 43 { 44 return adoptRef(new WebInspector(page)); 45 } 46 47 WebInspector::WebInspector(WebPage* page) 48 : m_page(page) 49 , m_inspectorPage(0) 50 { 51 } 52 53 // Called from WebInspectorClient 54 WebPage* WebInspector::createInspectorPage() 55 { 56 if (!m_page) 57 return 0; 58 59 uint64_t inspectorPageID = 0; 60 WebPageCreationParameters parameters; 61 62 if (!WebProcess::shared().connection()->sendSync(Messages::WebInspectorProxy::CreateInspectorPage(), 63 Messages::WebInspectorProxy::CreateInspectorPage::Reply(inspectorPageID, parameters), 64 m_page->pageID(), CoreIPC::Connection::NoTimeout)) { 65 return 0; 66 } 67 68 if (!inspectorPageID) 69 return 0; 70 71 WebProcess::shared().createWebPage(inspectorPageID, parameters); 72 m_inspectorPage = WebProcess::shared().webPage(inspectorPageID); 73 ASSERT(m_inspectorPage); 74 75 return m_inspectorPage; 76 } 77 78 // Called from WebInspectorFrontendClient 79 void WebInspector::didLoadInspectorPage() 80 { 81 WebProcess::shared().connection()->send(Messages::WebInspectorProxy::DidLoadInspectorPage(), m_page->pageID()); 82 } 83 84 void WebInspector::didClose() 85 { 86 WebProcess::shared().connection()->send(Messages::WebInspectorProxy::DidClose(), m_page->pageID()); 87 } 88 89 void WebInspector::inspectedURLChanged(const String& urlString) 90 { 91 WebProcess::shared().connection()->send(Messages::WebInspectorProxy::InspectedURLChanged(urlString), m_page->pageID()); 92 } 93 94 // Called by WebInspector messages 95 void WebInspector::show() 96 { 97 m_page->corePage()->inspectorController()->show(); 98 } 99 100 void WebInspector::close() 101 { 102 m_page->corePage()->inspectorController()->close(); 103 } 104 105 void WebInspector::evaluateScriptForTest(long callID, const String& script) 106 { 107 m_page->corePage()->inspectorController()->evaluateForTestInFrontend(callID, script); 108 } 109 110 void WebInspector::showConsole() 111 { 112 m_page->corePage()->inspectorController()->showConsole(); 113 } 114 115 void WebInspector::startJavaScriptDebugging() 116 { 117 #if ENABLE(JAVASCRIPT_DEBUGGER) 118 m_page->corePage()->inspectorController()->showAndEnableDebugger(); 119 #endif 120 } 121 122 void WebInspector::stopJavaScriptDebugging() 123 { 124 #if ENABLE(JAVASCRIPT_DEBUGGER) 125 m_page->corePage()->inspectorController()->disableDebugger(); 126 #endif 127 } 128 129 void WebInspector::startJavaScriptProfiling() 130 { 131 #if ENABLE(JAVASCRIPT_DEBUGGER) 132 m_page->corePage()->inspectorController()->startUserInitiatedProfiling(); 133 #endif 134 } 135 136 void WebInspector::stopJavaScriptProfiling() 137 { 138 #if ENABLE(JAVASCRIPT_DEBUGGER) 139 m_page->corePage()->inspectorController()->stopUserInitiatedProfiling(); 140 #endif 141 } 142 143 void WebInspector::startPageProfiling() 144 { 145 m_page->corePage()->inspectorController()->startTimelineProfiler(); 146 } 147 148 void WebInspector::stopPageProfiling() 149 { 150 m_page->corePage()->inspectorController()->stopTimelineProfiler(); 151 // FIXME: show the Timeline panel. 152 } 153 154 } // namespace WebKit 155 156 #endif // ENABLE(INSPECTOR) 157