summaryrefslogtreecommitdiffstats
path: root/WebKit/gtk/WebCoreSupport/InspectorClientGtk.cpp
blob: 210995a278cf224de593465580430282dafe58b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/*
 * Copyright (C) 2008 Gustavo Noronha Silva
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include "config.h"
#include "InspectorClientGtk.h"

#include "webkitwebview.h"
#include "webkitwebinspector.h"
#include "webkitprivate.h"
#include "CString.h"
#include "InspectorController.h"
#include "NotImplemented.h"
#include "PlatformString.h"

using namespace WebCore;

namespace WebKit {

static void notifyWebViewDestroyed(WebKitWebView* webView, InspectorClient* inspectorClient)
{
    inspectorClient->webViewDestroyed();
}

InspectorClient::InspectorClient(WebKitWebView* webView)
    : m_webView(0)
    , m_inspectedWebView(webView)
    , m_webInspector(0)
{}

void InspectorClient::inspectorDestroyed()
{
    if (m_webView) {
        gboolean handled = FALSE;
        g_signal_emit_by_name(m_webInspector, "destroy", &handled);

        /* we can now dispose our own reference */
        g_object_unref(m_webInspector);
    }

    delete this;
}

void InspectorClient::webViewDestroyed()
{
    m_webView = 0;
    core(m_inspectedWebView)->inspectorController()->pageDestroyed();

    // createPage will be called again, if the user chooses to inspect
    // something else, and the inspector will be referenced again,
    // there.
    g_object_unref(m_webInspector);
}

Page* InspectorClient::createPage()
{
    if (m_webView)
      return core(m_webView);

    // This g_object_get will ref the inspector. We're not doing an
    // unref if this method succeeds because the inspector object must
    // be alive even after the inspected WebView is destroyed - the
    // close-window and destroy signals still need to be
    // emitted.
    WebKitWebInspector* webInspector;
    g_object_get(G_OBJECT(m_inspectedWebView), "web-inspector", &webInspector, NULL);
    m_webInspector = webInspector;

    g_signal_emit_by_name(m_webInspector, "inspect-web-view", m_inspectedWebView, &m_webView);

    if (!m_webView) {
        g_object_unref(m_webInspector);
        return 0;
    }

    webkit_web_inspector_set_web_view(m_webInspector, m_webView);

    g_signal_connect(G_OBJECT(m_webView), "destroy",
                     G_CALLBACK(notifyWebViewDestroyed), (gpointer)this);

    webkit_web_view_open(m_webView, "file://"DATA_DIR"/webkit-1.0/webinspector/inspector.html");
    gtk_widget_show(GTK_WIDGET(m_webView));

    return core(m_webView);
}

String InspectorClient::localizedStringsURL()
{
    notImplemented();
    return String();
}

void InspectorClient::showWindow()
{
    if (!m_webView)
        return;

    gboolean handled = FALSE;
    g_signal_emit_by_name(m_webInspector, "show-window", &handled);

    core(m_inspectedWebView)->inspectorController()->setWindowVisible(true);
}

void InspectorClient::closeWindow()
{
    if (!m_webView)
        return;

    gboolean handled = FALSE;
    g_signal_emit_by_name(m_webInspector, "close-window", &handled);

    core(m_inspectedWebView)->inspectorController()->setWindowVisible(false);
}

void InspectorClient::attachWindow()
{
    if (!m_webView)
        return;

    gboolean handled = FALSE;
    g_signal_emit_by_name(m_webInspector, "attach-window", &handled);
}

void InspectorClient::detachWindow()
{
    if (!m_webView)
        return;

    gboolean handled = FALSE;
    g_signal_emit_by_name(m_webInspector, "detach-window", &handled);
}

void InspectorClient::setAttachedWindowHeight(unsigned height)
{
    notImplemented();
}

void InspectorClient::highlight(Node* node)
{
    notImplemented();
}

void InspectorClient::hideHighlight()
{
    notImplemented();
}

void InspectorClient::inspectedURLChanged(const String& newURL)
{
    if (!m_webView)
        return;

    webkit_web_inspector_set_inspected_uri(m_webInspector, newURL.utf8().data());
}

void InspectorClient::populateSetting(const String& key, InspectorController::Setting& setting)
{
    notImplemented();
}

void InspectorClient::storeSetting(const String& key, const InspectorController::Setting& setting)
{
    notImplemented();
}

void InspectorClient::removeSetting(const String& key)
{
    notImplemented();
}

}