cde90f96b5f8cc1a3dee5625cead59b51cf02f33
[WebKit-https.git] / Source / WebKit2 / WebProcess / WebPage / WebInspector.cpp
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 // Called by WebInspector messages
90 void WebInspector::show()
91 {
92     m_page->corePage()->inspectorController()->show();
93 }
94
95 void WebInspector::close()
96 {
97     m_page->corePage()->inspectorController()->close();
98 }
99
100 void WebInspector::evaluateScriptForTest(long callID, const String& script)
101 {
102     m_page->corePage()->inspectorController()->evaluateForTestInFrontend(callID, script);
103 }
104
105 void WebInspector::showConsole()
106 {
107     m_page->corePage()->inspectorController()->showPanel(InspectorController::ConsolePanel);
108 }
109
110 void WebInspector::startJavaScriptDebugging()
111 {
112 #if ENABLE(JAVASCRIPT_DEBUGGER)
113     m_page->corePage()->inspectorController()->showAndEnableDebugger();
114 #endif
115 }
116
117 void WebInspector::stopJavaScriptDebugging()
118 {
119 #if ENABLE(JAVASCRIPT_DEBUGGER)
120     m_page->corePage()->inspectorController()->disableDebugger();
121 #endif
122 }
123
124 void WebInspector::startJavaScriptProfiling()
125 {
126 #if ENABLE(JAVASCRIPT_DEBUGGER)
127     m_page->corePage()->inspectorController()->startUserInitiatedProfiling();
128 #endif
129 }
130
131 void WebInspector::stopJavaScriptProfiling()
132 {
133 #if ENABLE(JAVASCRIPT_DEBUGGER)
134     m_page->corePage()->inspectorController()->stopUserInitiatedProfiling();
135     m_page->corePage()->inspectorController()->showPanel(InspectorController::ProfilesPanel);
136 #endif
137 }
138
139 void WebInspector::startPageProfiling()
140 {
141     m_page->corePage()->inspectorController()->startTimelineProfiler();
142 }
143
144 void WebInspector::stopPageProfiling()
145 {
146     m_page->corePage()->inspectorController()->stopTimelineProfiler();
147     // FIXME: show the Timeline panel.
148 }
149
150 } // namespace WebKit
151
152 #endif // ENABLE(INSPECTOR)