2010-11-08 Nicolas Dufresne <nicolas.dufresne@collabora.co.uk>
[WebKit-https.git] / WebKit / gtk / WebCoreSupport / InspectorClientGtk.cpp
index b0dd40e..312b8c8 100644 (file)
@@ -36,7 +36,7 @@ namespace WebKit {
 
 static void notifyWebViewDestroyed(WebKitWebView* webView, InspectorFrontendClient* inspectorFrontendClient)
 {
-    inspectorFrontendClient->destroyInspectorWindow();
+    inspectorFrontendClient->destroyInspectorWindow(true);
 }
 
 InspectorClient::InspectorClient(WebKitWebView* webView)
@@ -78,19 +78,9 @@ void InspectorClient::openInspectorFrontend(InspectorController* controller)
     }
 
     webkit_web_inspector_set_web_view(webInspector, inspectorWebView);
-
-    GOwnPtr<gchar> inspectorURI;
-
-    // Make the Web Inspector work when running tests
-    // FixMe: it is not working. It should be not the subdirectory of the current directory, but a subdirectory of $(WEBKITOUTPUTDIR).
-    if (g_file_test("resources/inspector/inspector.html", G_FILE_TEST_EXISTS)) {
-        GOwnPtr<gchar> currentDirectory(g_get_current_dir());
-        GOwnPtr<gchar> fullPath(g_strdup_printf("%s/resources/inspector/inspector.html", currentDirectory.get()));
-        inspectorURI.set(g_filename_to_uri(fullPath.get(), NULL, NULL));
-    } else {
-        inspectorURI.set(g_filename_to_uri(DATA_DIR"/webkitgtk-"WEBKITGTK_API_VERSION_STRING"/webinspector/inspector.html", NULL, NULL));
-    }
-
+    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));
@@ -98,6 +88,9 @@ void InspectorClient::openInspectorFrontend(InspectorController* controller)
     m_frontendPage = core(inspectorWebView);
     m_frontendClient = new InspectorFrontendClient(m_inspectedWebView, inspectorWebView, webInspector, m_frontendPage, this);
     m_frontendPage->inspectorController()->setInspectorFrontendClient(m_frontendClient);
+
+    // The inspector must be in it's own PageGroup to avoid deadlock while debugging.
+    m_frontendPage->setGroupName("");
 }
 
 void InspectorClient::releaseFrontendPage()
@@ -185,7 +178,7 @@ void InspectorClient::populateSetting(const String& key, String* value)
     if (!settings)
         return;
 
-    GRefPtr<GVariant> variant = adoptGRef(g_settings_get_value(settings, toGSettingName(key).utf8().data()));
+    PlatformRefPtr<GVariant> variant = adoptPlatformRef(g_settings_get_value(settings, toGSettingName(key).utf8().data()));
 
     if (key == "resourceTrackingEnabled" || key == "xhrMonitor"
         || key == "debuggerEnabled" || key == "profilerEnabled")
@@ -203,15 +196,15 @@ void InspectorClient::storeSetting(const String& key, const String& value)
     if (!settings)
         return;
 
-    GRefPtr<GVariant> variant(0);
+    PlatformRefPtr<GVariant> variant(0);
 
     // Set the key with the appropriate type, and also avoid setting
     // unknown keys to avoid aborting the execution.
     if (key == "resourceTrackingEnabled" || key == "xhrMonitor"
         || key == "debuggerEnabled" || key == "profilerEnabled")
-        variant = adoptGRef(variantFromTruthString(value));
+        variant = adoptPlatformRef(variantFromTruthString(value));
     else if (key == "frontendSettings")
-        variant = adoptGRef(g_variant_new_string(value.utf8().data()));
+        variant = adoptPlatformRef(g_variant_new_string(value.utf8().data()));
 
     if (!variant)
         return;
@@ -232,26 +225,23 @@ void InspectorClient::storeSetting(const String&, const String&)
 
 bool InspectorClient::sendMessageToFrontend(const String& message)
 {
-    if (!m_frontendPage)
-        return false;
+    return doDispatchMessageOnFrontendPage(m_frontendPage, message);
+}
 
-    Frame* frame = m_frontendPage->mainFrame();
-    if (!frame)
-        return false;
+const char* InspectorClient::inspectorFilesPath()
+{
+    if (m_inspectorFilesPath)
+        m_inspectorFilesPath.get();
 
-    ScriptController* scriptController = frame->script();
-    if (!scriptController)
-        return false;
+    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));
 
-    String dispatchToFrontend("WebInspector.dispatchMessageFromBackend(");
-    dispatchToFrontend += message;
-    dispatchToFrontend += ");";
-    scriptController->executeScript(dispatchToFrontend);
-    return true;
+    return m_inspectorFilesPath.get();
 }
 
-bool destroyed = TRUE;
-
 InspectorFrontendClient::InspectorFrontendClient(WebKitWebView* inspectedWebView, WebKitWebView* inspectorWebView, WebKitWebInspector* webInspector, Page* inspectorPage, InspectorClient* inspectorClient)
     : InspectorFrontendClientLocal(core(inspectedWebView)->inspectorController(), inspectorPage)
     , m_inspectorWebView(inspectorWebView)
@@ -272,7 +262,7 @@ InspectorFrontendClient::~InspectorFrontendClient()
     ASSERT(!m_webInspector);
 }
 
-void InspectorFrontendClient::destroyInspectorWindow()
+void InspectorFrontendClient::destroyInspectorWindow(bool notifyInspectorController)
 {
     if (!m_webInspector)
         return;
@@ -282,7 +272,8 @@ void InspectorFrontendClient::destroyInspectorWindow()
     g_signal_handlers_disconnect_by_func(m_inspectorWebView, (gpointer)notifyWebViewDestroyed, (gpointer)this);
     m_inspectorWebView = 0;
 
-    core(m_inspectedWebView)->inspectorController()->disconnectFrontend();
+    if (notifyInspectorController)
+        core(m_inspectedWebView)->inspectorController()->disconnectFrontend();
 
     if (m_inspectorClient)
         m_inspectorClient->releaseFrontendPage();
@@ -300,20 +291,11 @@ void InspectorFrontendClient::destroyInspectorWindow()
 
 String InspectorFrontendClient::localizedStringsURL()
 {
-    GOwnPtr<gchar> URL;
-
-    // Make the Web Inspector work when running tests
-    if (g_file_test("WebCore/English.lproj/localizedStrings.js", G_FILE_TEST_EXISTS)) {
-        GOwnPtr<gchar> currentDirectory(g_get_current_dir());
-        GOwnPtr<gchar> fullPath(g_strdup_printf("%s/WebCore/English.lproj/localizedStrings.js", currentDirectory.get()));
-        URL.set(g_filename_to_uri(fullPath.get(), NULL, NULL));
-    } else {
-        GOwnPtr<gchar> localizedStringsPath(g_strdup_printf(DATA_DIR"/webkitgtk-%.1f/webinspector/localizedStrings.js", WEBKITGTK_API_VERSION));
-        URL.set(g_filename_to_uri(localizedStringsPath.get(), NULL, NULL));
-    }
+    GOwnPtr<gchar> stringsPath(g_build_filename(m_inspectorClient->inspectorFilesPath(), "localizedStrings.js", NULL));
+    GOwnPtr<gchar> stringsURI(g_filename_to_uri(stringsPath.get(), 0, 0));
 
     // FIXME: support l10n of localizedStrings.js
-    return String::fromUTF8(URL.get());
+    return String::fromUTF8(stringsURI.get());
 }
 
 String InspectorFrontendClient::hiddenPanels()
@@ -333,7 +315,12 @@ void InspectorFrontendClient::bringToFront()
 
 void InspectorFrontendClient::closeWindow()
 {
-    destroyInspectorWindow();
+    destroyInspectorWindow(true);
+}
+
+void InspectorFrontendClient::disconnectFromBackend()
+{
+    destroyInspectorWindow(false);
 }
 
 void InspectorFrontendClient::attachWindow()