ad294f68b0419cfdae553d36f3b6cd03a62752a7
[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 "WebInspector.h"
27
28 #if ENABLE(INSPECTOR)
29
30 #include "WebInspectorProxyMessages.h"
31 #include "WebPage.h"
32 #include "WebPageCreationParameters.h"
33 #include "WebProcess.h"
34 #include <WebCore/InspectorController.h>
35 #include <WebCore/Page.h>
36
37 using namespace WebCore;
38
39 namespace WebKit {
40
41 WebInspector::WebInspector(WebPage* page)
42     : m_page(page)
43     , m_inspectorPage(0)
44 {
45 }
46
47 // Called from WebInspectorClient
48 WebPage* WebInspector::createInspectorPage()
49 {
50     if (!m_page)
51         return 0;
52
53     uint64_t inspectorPageID = 0;
54     WebPageCreationParameters parameters;
55
56     if (!WebProcess::shared().connection()->sendSync(Messages::WebInspectorProxy::CreateInspectorPage(),
57             Messages::WebInspectorProxy::CreateInspectorPage::Reply(inspectorPageID, parameters),
58             m_page->pageID(), CoreIPC::Connection::NoTimeout)) {
59         return 0;
60     }
61
62     if (!inspectorPageID)
63         return 0;
64
65     WebProcess::shared().createWebPage(inspectorPageID, parameters);
66     m_inspectorPage = WebProcess::shared().webPage(inspectorPageID);
67     ASSERT(m_inspectorPage);
68
69     return m_inspectorPage;
70 }
71
72 // Called from WebInspectorFrontendClient
73 void WebInspector::didLoadInspectorPage()
74 {
75     WebProcess::shared().connection()->send(Messages::WebInspectorProxy::DidLoadInspectorPage(), m_page->pageID());
76 }
77
78 void WebInspector::didClose()
79 {
80     WebProcess::shared().connection()->send(Messages::WebInspectorProxy::DidClose(), m_page->pageID());
81 }
82
83 // Called by WebInspector messages
84 void WebInspector::show()
85 {
86     m_page->corePage()->inspectorController()->show();
87 }
88
89 void WebInspector::close()
90 {
91     m_page->corePage()->inspectorController()->close();
92 }
93
94 void WebInspector::showConsole()
95 {
96     m_page->corePage()->inspectorController()->showPanel(InspectorController::ConsolePanel);
97 }
98
99 void WebInspector::startJavaScriptDebugging()
100 {
101 #if ENABLE(JAVASCRIPT_DEBUGGER)
102     m_page->corePage()->inspectorController()->showPanel(InspectorController::ScriptsPanel);
103     m_page->corePage()->inspectorController()->enableDebugger();
104 #endif
105 }
106
107 void WebInspector::stopJavaScriptDebugging()
108 {
109 #if ENABLE(JAVASCRIPT_DEBUGGER)
110     m_page->corePage()->inspectorController()->disableDebugger();
111 #endif
112 }
113
114 void WebInspector::startJavaScriptProfiling()
115 {
116 #if ENABLE(JAVASCRIPT_DEBUGGER)
117     m_page->corePage()->inspectorController()->startUserInitiatedProfiling();
118 #endif
119 }
120
121 void WebInspector::stopJavaScriptProfiling()
122 {
123 #if ENABLE(JAVASCRIPT_DEBUGGER)
124     m_page->corePage()->inspectorController()->stopUserInitiatedProfiling();
125     m_page->corePage()->inspectorController()->showPanel(InspectorController::ProfilesPanel);
126 #endif
127 }
128
129 void WebInspector::startPageProfiling()
130 {
131     m_page->corePage()->inspectorController()->startTimelineProfiler();
132 }
133
134 void WebInspector::stopPageProfiling()
135 {
136     m_page->corePage()->inspectorController()->stopTimelineProfiler();
137     // FIXME: show the Timeline panel.
138 }
139
140 } // namespace WebKit
141
142 #endif // ENABLE(INSPECTOR)