2011-01-17 Pavel Feldman <pfeldman@chromium.org>
[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()->showAndEnableDebugger();
103 #endif
104 }
105
106 void WebInspector::stopJavaScriptDebugging()
107 {
108 #if ENABLE(JAVASCRIPT_DEBUGGER)
109     m_page->corePage()->inspectorController()->disableDebugger();
110 #endif
111 }
112
113 void WebInspector::startJavaScriptProfiling()
114 {
115 #if ENABLE(JAVASCRIPT_DEBUGGER)
116     m_page->corePage()->inspectorController()->startUserInitiatedProfiling();
117 #endif
118 }
119
120 void WebInspector::stopJavaScriptProfiling()
121 {
122 #if ENABLE(JAVASCRIPT_DEBUGGER)
123     m_page->corePage()->inspectorController()->stopUserInitiatedProfiling();
124     m_page->corePage()->inspectorController()->showPanel(InspectorController::ProfilesPanel);
125 #endif
126 }
127
128 void WebInspector::startPageProfiling()
129 {
130     m_page->corePage()->inspectorController()->startTimelineProfiler();
131 }
132
133 void WebInspector::stopPageProfiling()
134 {
135     m_page->corePage()->inspectorController()->stopTimelineProfiler();
136     // FIXME: show the Timeline panel.
137 }
138
139 } // namespace WebKit
140
141 #endif // ENABLE(INSPECTOR)