Home | History | Annotate | Download | only in WebCoreSupport
      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 
     34 static void notifyWebViewDestroyed(WebKitWebView* webView, InspectorClient* inspectorClient)
     35 {
     36     inspectorClient->webViewDestroyed();
     37 }
     38 
     39 InspectorClient::InspectorClient(WebKitWebView* webView)
     40     : m_webView(0)
     41     , m_inspectedWebView(webView)
     42     , m_webInspector(0)
     43 {}
     44 
     45 void InspectorClient::inspectorDestroyed()
     46 {
     47     if (m_webInspector)
     48         g_object_unref(m_webInspector);
     49 
     50     delete this;
     51 }
     52 
     53 void InspectorClient::webViewDestroyed()
     54 {
     55     m_webView = 0;
     56     core(m_inspectedWebView)->inspectorController()->pageDestroyed();
     57 
     58     // createPage will be called again, if the user chooses to inspect
     59     // something else, and the inspector will be referenced again,
     60     // there.
     61     g_object_unref(m_webInspector);
     62     m_webInspector = 0;
     63 }
     64 
     65 Page* InspectorClient::createPage()
     66 {
     67     if (m_webView) {
     68         gboolean handled = FALSE;
     69         g_signal_emit_by_name(m_webInspector, "destroy", &handled);
     70 
     71         /* we can now dispose our own reference */
     72         g_object_unref(m_webInspector);
     73     }
     74 
     75     // This g_object_get will ref the inspector. We're not doing an
     76     // unref if this method succeeds because the inspector object must
     77     // be alive even after the inspected WebView is destroyed - the
     78     // close-window and destroy signals still need to be
     79     // emitted.
     80     WebKitWebInspector* webInspector;
     81     g_object_get(m_inspectedWebView, "web-inspector", &webInspector, NULL);
     82     m_webInspector = webInspector;
     83 
     84     g_signal_emit_by_name(m_webInspector, "inspect-web-view", m_inspectedWebView, &m_webView);
     85 
     86     if (!m_webView) {
     87         g_object_unref(m_webInspector);
     88         return 0;
     89     }
     90 
     91     webkit_web_inspector_set_web_view(m_webInspector, m_webView);
     92 
     93     g_signal_connect(m_webView, "destroy",
     94                      G_CALLBACK(notifyWebViewDestroyed), (gpointer)this);
     95 
     96     GOwnPtr<gchar> inspectorURI;
     97 
     98     // Make the Web Inspector work when running tests
     99     if (g_file_test("WebCore/inspector/front-end/inspector.html", G_FILE_TEST_EXISTS)) {
    100         GOwnPtr<gchar> currentDirectory(g_get_current_dir());
    101         GOwnPtr<gchar> fullPath(g_strdup_printf("%s/WebCore/inspector/front-end/inspector.html", currentDirectory.get()));
    102         inspectorURI.set(g_filename_to_uri(fullPath.get(), NULL, NULL));
    103     } else
    104         inspectorURI.set(g_filename_to_uri(DATA_DIR"/webkit-1.0/webinspector/inspector.html", NULL, NULL));
    105 
    106     webkit_web_view_load_uri(m_webView, inspectorURI.get());
    107 
    108     gtk_widget_show(GTK_WIDGET(m_webView));
    109 
    110     return core(m_webView);
    111 }
    112 
    113 String InspectorClient::localizedStringsURL()
    114 {
    115     GOwnPtr<gchar> URL;
    116 
    117     // Make the Web Inspector work when running tests
    118     if (g_file_test("WebCore/English.lproj/localizedStrings.js", G_FILE_TEST_EXISTS)) {
    119         GOwnPtr<gchar> currentDirectory(g_get_current_dir());
    120         GOwnPtr<gchar> fullPath(g_strdup_printf("%s/WebCore/English.lproj/localizedStrings.js", currentDirectory.get()));
    121         URL.set(g_filename_to_uri(fullPath.get(), NULL, NULL));
    122     } else
    123         URL.set(g_filename_to_uri(DATA_DIR"/webkit-1.0/webinspector/localizedStrings.js", NULL, NULL));
    124 
    125     // FIXME: support l10n of localizedStrings.js
    126     return String::fromUTF8(URL.get());
    127 }
    128 
    129 String InspectorClient::hiddenPanels()
    130 {
    131     notImplemented();
    132     return String();
    133 }
    134 
    135 void InspectorClient::showWindow()
    136 {
    137     if (!m_webView)
    138         return;
    139 
    140     gboolean handled = FALSE;
    141     g_signal_emit_by_name(m_webInspector, "show-window", &handled);
    142 
    143     core(m_inspectedWebView)->inspectorController()->setWindowVisible(true);
    144 }
    145 
    146 void InspectorClient::closeWindow()
    147 {
    148     if (!m_webView)
    149         return;
    150 
    151     gboolean handled = FALSE;
    152     g_signal_emit_by_name(m_webInspector, "close-window", &handled);
    153 
    154     core(m_inspectedWebView)->inspectorController()->setWindowVisible(false);
    155 }
    156 
    157 void InspectorClient::attachWindow()
    158 {
    159     if (!m_webView)
    160         return;
    161 
    162     gboolean handled = FALSE;
    163     g_signal_emit_by_name(m_webInspector, "attach-window", &handled);
    164 }
    165 
    166 void InspectorClient::detachWindow()
    167 {
    168     if (!m_webView)
    169         return;
    170 
    171     gboolean handled = FALSE;
    172     g_signal_emit_by_name(m_webInspector, "detach-window", &handled);
    173 }
    174 
    175 void InspectorClient::setAttachedWindowHeight(unsigned height)
    176 {
    177     notImplemented();
    178 }
    179 
    180 void InspectorClient::highlight(Node* node)
    181 {
    182     notImplemented();
    183 }
    184 
    185 void InspectorClient::hideHighlight()
    186 {
    187     notImplemented();
    188 }
    189 
    190 void InspectorClient::inspectedURLChanged(const String& newURL)
    191 {
    192     if (!m_webView)
    193         return;
    194 
    195     webkit_web_inspector_set_inspected_uri(m_webInspector, newURL.utf8().data());
    196 }
    197 
    198 void InspectorClient::inspectorWindowObjectCleared()
    199 {
    200     notImplemented();
    201 }
    202 
    203 void InspectorClient::populateSetting(const String& key, String* value)
    204 {
    205     notImplemented();
    206 }
    207 
    208 void InspectorClient::storeSetting(const String& key, const String& value)
    209 {
    210     notImplemented();
    211 }
    212 
    213 }
    214 
    215