1 /*
2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com>
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
15 * its contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30 #include "config.h"
31 #include "InspectorFrontendHost.h"
32
33 #if ENABLE(INSPECTOR)
34
35 #include "ContextMenu.h"
36 #include "ContextMenuItem.h"
37 #include "ContextMenuController.h"
38 #include "ContextMenuProvider.h"
39 #include "Element.h"
40 #include "Frame.h"
41 #include "FrameLoader.h"
42 #include "HitTestResult.h"
43 #include "HTMLFrameOwnerElement.h"
44 #include "InspectorClient.h"
45 #include "InspectorFrontend.h"
46 #include "InspectorResource.h"
47 #include "Page.h"
48 #include "Pasteboard.h"
49
50 #include <wtf/RefPtr.h>
51 #include <wtf/StdLibExtras.h>
52
53 using namespace std;
54
55 namespace WebCore {
56
InspectorFrontendHost(InspectorController * inspectorController,InspectorClient * client)57 InspectorFrontendHost::InspectorFrontendHost(InspectorController* inspectorController, InspectorClient* client)
58 : m_inspectorController(inspectorController)
59 , m_client(client)
60 {
61 }
62
~InspectorFrontendHost()63 InspectorFrontendHost::~InspectorFrontendHost()
64 {
65 if (m_menuProvider)
66 m_menuProvider->disconnect();
67 }
68
loaded()69 void InspectorFrontendHost::loaded()
70 {
71 if (m_inspectorController)
72 m_inspectorController->scriptObjectReady();
73 }
74
attach()75 void InspectorFrontendHost::attach()
76 {
77 if (m_inspectorController)
78 m_inspectorController->attachWindow();
79 }
80
detach()81 void InspectorFrontendHost::detach()
82 {
83 if (m_inspectorController)
84 m_inspectorController->detachWindow();
85 }
86
closeWindow()87 void InspectorFrontendHost::closeWindow()
88 {
89 if (m_inspectorController)
90 m_inspectorController->closeWindow();
91 }
92
windowUnloading()93 void InspectorFrontendHost::windowUnloading()
94 {
95 if (m_inspectorController)
96 m_inspectorController->close();
97 }
98
setAttachedWindowHeight(unsigned height)99 void InspectorFrontendHost::setAttachedWindowHeight(unsigned height)
100 {
101 if (m_inspectorController)
102 m_inspectorController->setAttachedWindowHeight(height);
103 }
104
moveWindowBy(float x,float y) const105 void InspectorFrontendHost::moveWindowBy(float x, float y) const
106 {
107 if (m_inspectorController)
108 m_inspectorController->moveWindowBy(x, y);
109 }
110
localizedStringsURL()111 String InspectorFrontendHost::localizedStringsURL()
112 {
113 return m_client->localizedStringsURL();
114 }
115
hiddenPanels()116 String InspectorFrontendHost::hiddenPanels()
117 {
118 return m_client->hiddenPanels();
119 }
120
platform() const121 const String& InspectorFrontendHost::platform() const
122 {
123 #if PLATFORM(MAC)
124 DEFINE_STATIC_LOCAL(const String, platform, ("mac"));
125 #elif OS(WINDOWS)
126 DEFINE_STATIC_LOCAL(const String, platform, ("windows"));
127 #elif OS(LINUX)
128 DEFINE_STATIC_LOCAL(const String, platform, ("linux"));
129 #else
130 DEFINE_STATIC_LOCAL(const String, platform, ("unknown"));
131 #endif
132 return platform;
133 }
134
port() const135 const String& InspectorFrontendHost::port() const
136 {
137 #if PLATFORM(QT)
138 DEFINE_STATIC_LOCAL(const String, port, ("qt"));
139 #elif PLATFORM(GTK)
140 DEFINE_STATIC_LOCAL(const String, port, ("gtk"));
141 #elif PLATFORM(WX)
142 DEFINE_STATIC_LOCAL(const String, port, ("wx"));
143 #else
144 DEFINE_STATIC_LOCAL(const String, port, ("unknown"));
145 #endif
146
147 return port;
148 }
149
copyText(const String & text)150 void InspectorFrontendHost::copyText(const String& text)
151 {
152 Pasteboard::generalPasteboard()->writePlainText(text);
153 }
154
showContextMenu(Event * event,const Vector<ContextMenuItem * > & items)155 void InspectorFrontendHost::showContextMenu(Event* event, const Vector<ContextMenuItem*>& items)
156 {
157 if (!m_inspectorController)
158 return;
159 if (!m_inspectorController->windowVisible())
160 return;
161
162
163 m_menuProvider = MenuProvider::create(this, items);
164 ContextMenuController* menuController = m_inspectorController->m_page->contextMenuController();
165 menuController->showContextMenu(event, m_menuProvider);
166 }
167
contextMenuItemSelected(ContextMenuItem * item)168 void InspectorFrontendHost::contextMenuItemSelected(ContextMenuItem* item)
169 {
170 if (m_inspectorController && m_inspectorController->windowVisible()) {
171 int itemNumber = item->action() - ContextMenuItemBaseCustomTag;
172 m_inspectorController->m_frontend->contextMenuItemSelected(itemNumber);
173 }
174 }
175
contextMenuCleared()176 void InspectorFrontendHost::contextMenuCleared()
177 {
178 m_menuProvider = 0;
179 if (m_inspectorController && m_inspectorController->windowVisible())
180 m_inspectorController->m_frontend->contextMenuCleared();
181 }
182
183 } // namespace WebCore
184
185 #endif // ENABLE(INSPECTOR)
186