InspectorClientGtk.cpp [plain text]
#include "config.h"
#include "InspectorClientGtk.h"
#include "Frame.h"
#include "InspectorController.h"
#include "NotImplemented.h"
#include "Page.h"
#include "PlatformString.h"
#include "webkitversion.h"
#include "webkitwebinspector.h"
#include "webkitwebinspectorprivate.h"
#include "webkitwebview.h"
#include "webkitwebviewprivate.h"
#include <wtf/text/CString.h>
using namespace WebCore;
namespace WebKit {
static void notifyWebViewDestroyed(WebKitWebView* webView, InspectorFrontendClient* inspectorFrontendClient)
{
inspectorFrontendClient->destroyInspectorWindow(true);
}
namespace {
class InspectorFrontendSettingsGtk : public InspectorFrontendClientLocal::Settings {
private:
virtual ~InspectorFrontendSettingsGtk() { }
#ifdef HAVE_GSETTINGS
static bool shouldIgnoreSetting(const String& key)
{
LOG_VERBOSE(NotYetImplemented, "Unknown key ignored: %s", key.ascii().data());
return true;
}
virtual String getProperty(const String& name)
{
if (shouldIgnoreSetting(name))
return String();
GSettings* settings = inspectorGSettings();
if (!settings)
return String();
GRefPtr<GVariant> variant = adoptGRef(g_settings_get_value(settings, name.utf8().data()));
return String(g_variant_get_string(variant.get(), 0));
}
virtual void setProperty(const String& name, const String& value)
{
if (shouldIgnoreSetting(name))
return;
GSettings* settings = inspectorGSettings();
if (!settings)
return;
GRefPtr<GVariant> variant = adoptGRef(g_variant_new_string(value.utf8().data()));
g_settings_set_value(settings, name.utf8().data(), variant.get());
}
#else
virtual String getProperty(const String&)
{
notImplemented();
return String();
}
virtual void setProperty(const String&, const String&)
{
notImplemented();
}
#endif // HAVE_GSETTINGS
};
}
InspectorClient::InspectorClient(WebKitWebView* webView)
: m_inspectedWebView(webView)
, m_frontendPage(0)
, m_frontendClient(0)
{}
InspectorClient::~InspectorClient()
{
if (m_frontendClient) {
m_frontendClient->disconnectInspectorClient();
m_frontendClient = 0;
}
}
void InspectorClient::inspectorDestroyed()
{
delete this;
}
void InspectorClient::openInspectorFrontend(InspectorController* controller)
{
WebKitWebInspector* webInspector = 0;
g_object_get(m_inspectedWebView, "web-inspector", &webInspector, NULL);
ASSERT(webInspector);
WebKitWebView* inspectorWebView = 0;
g_signal_emit_by_name(webInspector, "inspect-web-view", m_inspectedWebView, &inspectorWebView);
if (!inspectorWebView) {
g_object_unref(webInspector);
return;
}
webkit_web_inspector_set_web_view(webInspector, inspectorWebView);
GOwnPtr<gchar> inspectorPath(g_build_filename(inspectorFilesPath(), "inspector.html", NULL));
GOwnPtr<gchar> inspectorURI(g_filename_to_uri(inspectorPath.get(), 0, 0));
webkit_web_view_load_uri(inspectorWebView, inspectorURI.get());
gtk_widget_show(GTK_WIDGET(inspectorWebView));
m_frontendPage = core(inspectorWebView);
m_frontendClient = new InspectorFrontendClient(m_inspectedWebView, inspectorWebView, webInspector, m_frontendPage, this);
m_frontendPage->inspectorController()->setInspectorFrontendClient(m_frontendClient);
m_frontendPage->setGroupName("");
}
void InspectorClient::releaseFrontendPage()
{
m_frontendPage = 0;
}
void InspectorClient::highlight(Node*)
{
hideHighlight();
}
void InspectorClient::hideHighlight()
{
gtk_widget_queue_draw(GTK_WIDGET(m_inspectedWebView));
}
bool InspectorClient::sendMessageToFrontend(const String& message)
{
return doDispatchMessageOnFrontendPage(m_frontendPage, message);
}
const char* InspectorClient::inspectorFilesPath()
{
if (m_inspectorFilesPath)
m_inspectorFilesPath.get();
const char* environmentPath = getenv("WEBKIT_INSPECTOR_PATH");
if (environmentPath && g_file_test(environmentPath, G_FILE_TEST_IS_DIR))
m_inspectorFilesPath.set(g_strdup(environmentPath));
else
m_inspectorFilesPath.set(g_build_filename(DATA_DIR, "webkitgtk-"WEBKITGTK_API_VERSION_STRING, "webinspector", NULL));
return m_inspectorFilesPath.get();
}
InspectorFrontendClient::InspectorFrontendClient(WebKitWebView* inspectedWebView, WebKitWebView* inspectorWebView, WebKitWebInspector* webInspector, Page* inspectorPage, InspectorClient* inspectorClient)
: InspectorFrontendClientLocal(core(inspectedWebView)->inspectorController(), inspectorPage, new InspectorFrontendSettingsGtk())
, m_inspectorWebView(inspectorWebView)
, m_inspectedWebView(inspectedWebView)
, m_webInspector(webInspector)
, m_inspectorClient(inspectorClient)
{
g_signal_connect(m_inspectorWebView, "destroy",
G_CALLBACK(notifyWebViewDestroyed), (gpointer)this);
}
InspectorFrontendClient::~InspectorFrontendClient()
{
if (m_inspectorClient) {
m_inspectorClient->disconnectFrontendClient();
m_inspectorClient = 0;
}
ASSERT(!m_webInspector);
}
void InspectorFrontendClient::destroyInspectorWindow(bool notifyInspectorController)
{
if (!m_webInspector)
return;
WebKitWebInspector* webInspector = m_webInspector;
m_webInspector = 0;
g_signal_handlers_disconnect_by_func(m_inspectorWebView, (gpointer)notifyWebViewDestroyed, (gpointer)this);
m_inspectorWebView = 0;
if (notifyInspectorController)
core(m_inspectedWebView)->inspectorController()->disconnectFrontend();
if (m_inspectorClient)
m_inspectorClient->releaseFrontendPage();
gboolean handled = FALSE;
g_signal_emit_by_name(webInspector, "close-window", &handled);
ASSERT(handled);
g_object_unref(webInspector);
}
String InspectorFrontendClient::localizedStringsURL()
{
GOwnPtr<gchar> stringsPath(g_build_filename(m_inspectorClient->inspectorFilesPath(), "localizedStrings.js", NULL));
GOwnPtr<gchar> stringsURI(g_filename_to_uri(stringsPath.get(), 0, 0));
return String::fromUTF8(stringsURI.get());
}
String InspectorFrontendClient::hiddenPanels()
{
notImplemented();
return String();
}
void InspectorFrontendClient::bringToFront()
{
if (!m_inspectorWebView)
return;
gboolean handled = FALSE;
g_signal_emit_by_name(m_webInspector, "show-window", &handled);
}
void InspectorFrontendClient::closeWindow()
{
destroyInspectorWindow(true);
}
void InspectorFrontendClient::disconnectFromBackend()
{
destroyInspectorWindow(false);
}
void InspectorFrontendClient::attachWindow()
{
if (!m_inspectorWebView)
return;
gboolean handled = FALSE;
g_signal_emit_by_name(m_webInspector, "attach-window", &handled);
}
void InspectorFrontendClient::detachWindow()
{
if (!m_inspectorWebView)
return;
gboolean handled = FALSE;
g_signal_emit_by_name(m_webInspector, "detach-window", &handled);
}
void InspectorFrontendClient::setAttachedWindowHeight(unsigned height)
{
notImplemented();
}
void InspectorFrontendClient::inspectedURLChanged(const String& newURL)
{
if (!m_inspectorWebView)
return;
webkit_web_inspector_set_inspected_uri(m_webInspector, newURL.utf8().data());
}
}