• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 Gustavo Noronha Silva
3  *
4  *  This library is free software; you can redistribute it and/or
5  *  modify it under the terms of the GNU Lesser General Public
6  *  License as published by the Free Software Foundation; either
7  *  version 2 of the License, or (at your option) any later version.
8  *
9  *  This library is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  *  Lesser General Public License for more details.
13  *
14  *  You should have received a copy of the GNU Lesser General Public
15  *  License along with this library; if not, write to the Free Software
16  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
17  */
18 
19 #include "config.h"
20 #include "InspectorClientGtk.h"
21 
22 #include "webkitwebview.h"
23 #include "webkitwebinspector.h"
24 #include "webkitprivate.h"
25 #include "CString.h"
26 #include "InspectorController.h"
27 #include "NotImplemented.h"
28 #include "PlatformString.h"
29 
30 using namespace WebCore;
31 
32 namespace WebKit {
33 
notifyWebViewDestroyed(WebKitWebView * webView,InspectorClient * inspectorClient)34 static void notifyWebViewDestroyed(WebKitWebView* webView, InspectorClient* inspectorClient)
35 {
36     inspectorClient->webViewDestroyed();
37 }
38 
InspectorClient(WebKitWebView * webView)39 InspectorClient::InspectorClient(WebKitWebView* webView)
40     : m_webView(0)
41     , m_inspectedWebView(webView)
42     , m_webInspector(0)
43 {}
44 
inspectorDestroyed()45 void InspectorClient::inspectorDestroyed()
46 {
47     if (m_webView) {
48         gboolean handled = FALSE;
49         g_signal_emit_by_name(m_webInspector, "destroy", &handled);
50 
51         /* we can now dispose our own reference */
52         g_object_unref(m_webInspector);
53     }
54 
55     delete this;
56 }
57 
webViewDestroyed()58 void InspectorClient::webViewDestroyed()
59 {
60     m_webView = 0;
61     core(m_inspectedWebView)->inspectorController()->pageDestroyed();
62 
63     // createPage will be called again, if the user chooses to inspect
64     // something else, and the inspector will be referenced again,
65     // there.
66     g_object_unref(m_webInspector);
67 }
68 
createPage()69 Page* InspectorClient::createPage()
70 {
71     if (m_webView)
72       return core(m_webView);
73 
74     // This g_object_get will ref the inspector. We're not doing an
75     // unref if this method succeeds because the inspector object must
76     // be alive even after the inspected WebView is destroyed - the
77     // close-window and destroy signals still need to be
78     // emitted.
79     WebKitWebInspector* webInspector;
80     g_object_get(m_inspectedWebView, "web-inspector", &webInspector, NULL);
81     m_webInspector = webInspector;
82 
83     g_signal_emit_by_name(m_webInspector, "inspect-web-view", m_inspectedWebView, &m_webView);
84 
85     if (!m_webView) {
86         g_object_unref(m_webInspector);
87         return 0;
88     }
89 
90     webkit_web_inspector_set_web_view(m_webInspector, m_webView);
91 
92     g_signal_connect(m_webView, "destroy",
93                      G_CALLBACK(notifyWebViewDestroyed), (gpointer)this);
94 
95     gchar* inspectorURI = g_filename_to_uri(DATA_DIR"/webkit-1.0/webinspector/inspector.html", NULL, NULL);
96     webkit_web_view_load_uri(m_webView, inspectorURI);
97     g_free(inspectorURI);
98 
99     gtk_widget_show(GTK_WIDGET(m_webView));
100 
101     return core(m_webView);
102 }
103 
localizedStringsURL()104 String InspectorClient::localizedStringsURL()
105 {
106     // FIXME: support l10n of localizedStrings.js
107     return String::fromUTF8(g_filename_to_uri(DATA_DIR"/webkit-1.0/webinspector/localizedStrings.js", NULL, NULL));
108 }
109 
hiddenPanels()110 String InspectorClient::hiddenPanels()
111 {
112     notImplemented();
113     return String();
114 }
115 
showWindow()116 void InspectorClient::showWindow()
117 {
118     if (!m_webView)
119         return;
120 
121     gboolean handled = FALSE;
122     g_signal_emit_by_name(m_webInspector, "show-window", &handled);
123 
124     core(m_inspectedWebView)->inspectorController()->setWindowVisible(true);
125 }
126 
closeWindow()127 void InspectorClient::closeWindow()
128 {
129     if (!m_webView)
130         return;
131 
132     gboolean handled = FALSE;
133     g_signal_emit_by_name(m_webInspector, "close-window", &handled);
134 
135     core(m_inspectedWebView)->inspectorController()->setWindowVisible(false);
136 }
137 
attachWindow()138 void InspectorClient::attachWindow()
139 {
140     if (!m_webView)
141         return;
142 
143     gboolean handled = FALSE;
144     g_signal_emit_by_name(m_webInspector, "attach-window", &handled);
145 }
146 
detachWindow()147 void InspectorClient::detachWindow()
148 {
149     if (!m_webView)
150         return;
151 
152     gboolean handled = FALSE;
153     g_signal_emit_by_name(m_webInspector, "detach-window", &handled);
154 }
155 
setAttachedWindowHeight(unsigned height)156 void InspectorClient::setAttachedWindowHeight(unsigned height)
157 {
158     notImplemented();
159 }
160 
highlight(Node * node)161 void InspectorClient::highlight(Node* node)
162 {
163     notImplemented();
164 }
165 
hideHighlight()166 void InspectorClient::hideHighlight()
167 {
168     notImplemented();
169 }
170 
inspectedURLChanged(const String & newURL)171 void InspectorClient::inspectedURLChanged(const String& newURL)
172 {
173     if (!m_webView)
174         return;
175 
176     webkit_web_inspector_set_inspected_uri(m_webInspector, newURL.utf8().data());
177 }
178 
inspectorWindowObjectCleared()179 void InspectorClient::inspectorWindowObjectCleared()
180 {
181     notImplemented();
182 }
183 
184 
populateSetting(const String & key,InspectorController::Setting & setting)185 void InspectorClient::populateSetting(const String& key, InspectorController::Setting& setting)
186 {
187     notImplemented();
188 }
189 
storeSetting(const String & key,const InspectorController::Setting & setting)190 void InspectorClient::storeSetting(const String& key, const InspectorController::Setting& setting)
191 {
192     notImplemented();
193 }
194 
removeSetting(const String & key)195 void InspectorClient::removeSetting(const String& key)
196 {
197     notImplemented();
198 }
199 
200 }
201 
202