[EFL][WK2] Add Remote Web Inspector
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 8 Dec 2012 17:16:05 +0000 (17:16 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 8 Dec 2012 17:16:05 +0000 (17:16 +0000)
https://bugs.webkit.org/show_bug.cgi?id=98705

Patch by Seokju Kwon <seokju.kwon@gmail.com> on 2012-12-08
Reviewed by Gyuyoung Kim.

.:

Prepare inspectorPageIndex.html for remote web inspector.

* Source/PlatformEfl.cmake:

Source/WebKit2:

Add Remote Web Inspector to EFL port.
The WebInspectorSever will be started during WebKit context initialization.
The IP address and port number for the server can be set in WEBKIT_INSPECTOR_SERVER.

* CMakeLists.txt:
* PlatformEfl.cmake:
* UIProcess/InspectorServer/WebInspectorServer.h:
(WebInspectorServer):
* UIProcess/InspectorServer/WebSocketServer.h:
(WebSocketServer):
* UIProcess/InspectorServer/efl/WebInspectorServerEfl.cpp: Added.
(WebKit):
(WebKit::inspectorResourcePath):
(WebKit::WebInspectorServer::platformResourceForPath):
(WebKit::WebInspectorServer::buildPageList):
* UIProcess/InspectorServer/soup/WebSocketServerSoup.cpp:
(WebKit::connectionCallback):
* UIProcess/efl/WebContextEfl.cpp:
(WebKit::initializeInspectorServer):
(WebKit):
(WebKit::WebContext::platformInitializeWebProcess):
* config.h:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@137035 268f45cc-cd09-0410-ab3c-d52691b4dbfc

ChangeLog
Source/PlatformEfl.cmake
Source/WebKit2/CMakeLists.txt
Source/WebKit2/ChangeLog
Source/WebKit2/PlatformEfl.cmake
Source/WebKit2/UIProcess/InspectorServer/WebInspectorServer.h
Source/WebKit2/UIProcess/InspectorServer/WebSocketServer.h
Source/WebKit2/UIProcess/InspectorServer/efl/WebInspectorServerEfl.cpp [new file with mode: 0644]
Source/WebKit2/UIProcess/InspectorServer/soup/WebSocketServerSoup.cpp
Source/WebKit2/UIProcess/efl/WebContextEfl.cpp
Source/WebKit2/config.h

index 116cf05..50f9bde 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2012-12-08  Seokju Kwon  <seokju.kwon@gmail.com>
+
+        [EFL][WK2] Add Remote Web Inspector
+        https://bugs.webkit.org/show_bug.cgi?id=98705
+
+        Reviewed by Gyuyoung Kim.
+
+        Prepare inspectorPageIndex.html for remote web inspector.
+
+        * Source/PlatformEfl.cmake:
+
 2012-12-06  Rick Byers  <rbyers@chromium.org>
 
         CSS cursor property should support webkit-image-set
index cf5e113..6532faa 100644 (file)
@@ -5,6 +5,7 @@ if (ENABLE_INSPECTOR)
         web-inspector-resources ALL
         COMMAND ${CMAKE_COMMAND} -E copy_directory ${WEBCORE_DIR}/inspector/front-end ${WEB_INSPECTOR_DIR}
         COMMAND ${CMAKE_COMMAND} -E copy ${WEBCORE_DIR}/English.lproj/localizedStrings.js ${WEB_INSPECTOR_DIR}
+        COMMAND ${CMAKE_COMMAND} -E copy ${WEBKIT2_DIR}/UIProcess/InspectorServer/front-end/inspectorPageIndex.html ${WEB_INSPECTOR_DIR}
         COMMAND ${CMAKE_COMMAND} -E copy ${DERIVED_SOURCES_WEBCORE_DIR}/InspectorBackendCommands.js ${WEB_INSPECTOR_DIR}
         DEPENDS ${WebCore_LIBRARY_NAME}
         WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
index 8f3b6f9..83b6eeb 100644 (file)
@@ -18,6 +18,7 @@ set(WebKit2_INCLUDE_DIRECTORIES
     "${WEBKIT2_DIR}/UIProcess/Authentication"
     "${WEBKIT2_DIR}/UIProcess/CoordinatedGraphics"
     "${WEBKIT2_DIR}/UIProcess/Downloads"
+    "${WEBKIT2_DIR}/UIProcess/InspectorServer"
     "${WEBKIT2_DIR}/UIProcess/Launcher"
     "${WEBKIT2_DIR}/UIProcess/Notifications"
     "${WEBKIT2_DIR}/UIProcess/Plugins"
@@ -60,6 +61,7 @@ set(WebKit2_INCLUDE_DIRECTORIES
     "${WEBCORE_DIR}/dom"
     "${WEBCORE_DIR}/dom/default"
     "${WEBCORE_DIR}/editing"
+    "${WEBCORE_DIR}/fileapi"
     "${WEBCORE_DIR}/history"
     "${WEBCORE_DIR}/html"
     "${WEBCORE_DIR}/html/shadow"
index 96c2b81..731178c 100644 (file)
@@ -1,3 +1,33 @@
+2012-12-08  Seokju Kwon  <seokju.kwon@gmail.com>
+
+        [EFL][WK2] Add Remote Web Inspector
+        https://bugs.webkit.org/show_bug.cgi?id=98705
+
+        Reviewed by Gyuyoung Kim.
+
+        Add Remote Web Inspector to EFL port.
+        The WebInspectorSever will be started during WebKit context initialization.
+        The IP address and port number for the server can be set in WEBKIT_INSPECTOR_SERVER.
+
+        * CMakeLists.txt:
+        * PlatformEfl.cmake:
+        * UIProcess/InspectorServer/WebInspectorServer.h:
+        (WebInspectorServer):
+        * UIProcess/InspectorServer/WebSocketServer.h:
+        (WebSocketServer):
+        * UIProcess/InspectorServer/efl/WebInspectorServerEfl.cpp: Added.
+        (WebKit):
+        (WebKit::inspectorResourcePath):
+        (WebKit::WebInspectorServer::platformResourceForPath):
+        (WebKit::WebInspectorServer::buildPageList):
+        * UIProcess/InspectorServer/soup/WebSocketServerSoup.cpp:
+        (WebKit::connectionCallback):
+        * UIProcess/efl/WebContextEfl.cpp:
+        (WebKit::initializeInspectorServer):
+        (WebKit):
+        (WebKit::WebContext::platformInitializeWebProcess):
+        * config.h:
+
 2012-12-08  Gustavo Noronha Silva  <gns@gnome.org>
 
         Unreviewed. Make building the WebKit2 GIR file conditional on building the WebKit2 library.
index 5b2388d..b3716de 100644 (file)
@@ -106,6 +106,9 @@ list(APPEND WebKit2_SOURCES
     UIProcess/efl/WebPreferencesEfl.cpp
     UIProcess/efl/WebProcessProxyEfl.cpp
 
+    UIProcess/InspectorServer/efl/WebInspectorServerEfl.cpp
+    UIProcess/InspectorServer/soup/WebSocketServerSoup.cpp
+
     UIProcess/soup/WebCookieManagerProxySoup.cpp
     UIProcess/soup/WebSoupRequestManagerClient.cpp
     UIProcess/soup/WebSoupRequestManagerProxy.cpp
index 5dd87f5..124c46f 100644 (file)
@@ -61,7 +61,7 @@ private:
     virtual void didCloseWebSocketConnection(WebSocketServerConnection*);
 
     bool platformResourceForPath(const String& path, Vector<char>& data, String& contentType);
-#if PLATFORM(QT) || PLATFORM(GTK)
+#if PLATFORM(QT) || PLATFORM(GTK) || PLATFORM(EFL)
     void buildPageList(Vector<char>& data, String& contentType);
 #endif
 
index 80405c6..68ed64f 100644 (file)
 
 #if ENABLE(INSPECTOR_SERVER)
 
-#if PLATFORM(GTK)
-#include <gio/gio.h>
-#endif
 #include <wtf/Deque.h>
 #include <wtf/OwnPtr.h>
-#if PLATFORM(GTK)
+#include <wtf/text/WTFString.h>
+
+#if USE(SOUP)
+#include <gio/gio.h>
 #include <wtf/gobject/GRefPtr.h>
 #endif
-#include <wtf/text/WTFString.h>
 
 #if PLATFORM(QT)
 namespace WebKit {
@@ -84,7 +83,7 @@ private:
     unsigned short m_port;
 #if PLATFORM(QT)
     OwnPtr<QtTcpServerHandler> m_tcpServerHandler;
-#elif PLATFORM(GTK)
+#elif USE(SOUP)
     GRefPtr<GSocketService> m_socketService;
 #endif
     friend class WebSocketServerConnection;
diff --git a/Source/WebKit2/UIProcess/InspectorServer/efl/WebInspectorServerEfl.cpp b/Source/WebKit2/UIProcess/InspectorServer/efl/WebInspectorServerEfl.cpp
new file mode 100644 (file)
index 0000000..c2132c5
--- /dev/null
@@ -0,0 +1,113 @@
+/*
+ * Copyright (C) 2012 Seokju Kwon (seokju.kwon@gmail.com)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebInspectorServer.h"
+
+#include "WebInspectorProxy.h"
+#include "WebPageProxy.h"
+#include <WebCore/MIMETypeRegistry.h>
+#include <sys/stat.h>
+
+namespace WebKit {
+
+static String inspectorResourcePath()
+{
+    String inspectorFilesPath = String::fromUTF8(WEB_INSPECTOR_INSTALL_DIR);
+    if (access(inspectorFilesPath.utf8().data(), R_OK))
+        inspectorFilesPath = String::fromUTF8(WEB_INSPECTOR_DIR);
+
+    return inspectorFilesPath;
+}
+
+bool WebInspectorServer::platformResourceForPath(const String& path, Vector<char>& data, String& contentType)
+{
+    // The page list contains an unformated list of pages that can be inspected with a link to open a session.
+    if (path == "/pagelist.json") {
+        buildPageList(data, contentType);
+        return true;
+    }
+
+    // Point the default path to a formatted page that queries the page list and display them.
+    String localPath = inspectorResourcePath() + ((path == "/") ? ASCIILiteral("/inspectorPageIndex.html") : path);
+
+    FILE* fileHandle = fopen(localPath.utf8().data(), "r");
+    if (!fileHandle)
+        return false;
+
+    struct stat fileStat;
+    if (fstat(fileno(fileHandle), &fileStat)) {
+        fclose(fileHandle);
+        return false;
+    }
+
+    data.grow(fileStat.st_size);
+    int bytesRead = fread(data.data(), 1, fileStat.st_size, fileHandle);
+    fclose(fileHandle);
+
+    if (bytesRead < fileStat.st_size)
+        return false;
+
+    size_t extStart = localPath.reverseFind('.');
+    if (extStart == notFound)
+        return false;
+
+    String ext = localPath.substring(extStart + 1);
+    if (ext.isEmpty())
+        return false;
+
+    contentType = WebCore::MIMETypeRegistry::getMIMETypeForExtension(ext);
+
+    return true;
+}
+
+void WebInspectorServer::buildPageList(Vector<char>& data, String& contentType)
+{
+    StringBuilder builder;
+    builder.append('[');
+
+    ClientMap::iterator end = m_clientMap.end();
+    for (ClientMap::iterator it = m_clientMap.begin(); it != end; ++it) {
+        WebPageProxy* webPage = it->value->page();
+        if (it != m_clientMap.begin())
+            builder.appendLiteral(", ");
+        builder.appendLiteral("{ \"id\": ");
+        builder.appendNumber(it->key);
+        builder.appendLiteral(", \"title\": \"");
+        builder.append(webPage->pageTitle());
+        builder.appendLiteral("\", \"url\": \"");
+        builder.append(webPage->activeURL());
+        builder.appendLiteral("\", \"inspectorUrl\": \"");
+        builder.appendLiteral("/inspector.html?page=");
+        builder.appendNumber(it->key);
+        builder.appendLiteral("\" }");
+    }
+
+    builder.append(']');
+    CString clientList = builder.toString().utf8();
+    data.append(clientList.data(), clientList.length());
+    contentType = String("application/json; charset=utf-8", String::ConstructFromLiteral);
+}
+
+}
index e095be9..28f4f21 100644 (file)
@@ -39,7 +39,7 @@ using namespace WebCore;
 
 namespace WebKit {
 
-static gboolean connectionCallback(GSocketService* service, GSocketConnection* connection, GObject* sourceObject, WebSocketServer* server)
+static gboolean connectionCallback(GSocketService* /*service*/, GSocketConnection* connection, GObject* /*sourceObject*/, WebSocketServer* server)
 {
 #if !LOG_DISABLED
     GRefPtr<GSocketAddress> socketAddress = adoptGRef(g_socket_connection_get_remote_address(connection, 0));
index a3d4725..c71a93c 100644 (file)
 
 #include "config.h"
 #include "WebContext.h"
+
+#include "Logging.h"
+#include "WebInspectorServer.h"
 #include "WebProcessCreationParameters.h"
 #include "WebSoupRequestManagerProxy.h"
-
 #include <Efreet.h>
 #include <WebCore/ApplicationCacheStorage.h>
 #include <WebCore/IconDatabase.h>
 
 namespace WebKit {
 
+static void initializeInspectorServer()
+{
+#if ENABLE(INSPECTOR_SERVER)
+    static bool initialized = false;
+    if (initialized)
+        return;
+
+    // It should be set to true always.
+    // Because it is to ensure initializeInspectorServer() is executed only once,
+    // even if the server fails to run.
+    initialized = true;
+
+    String serverAddress(getenv("WEBKIT_INSPECTOR_SERVER"));
+    if (!serverAddress.isNull()) {
+        String bindAddress = ASCIILiteral("127.0.0.1");
+        unsigned short port = 2999;
+
+        Vector<String> result;
+        serverAddress.split(':', result);
+
+        if (result.size() == 2) {
+            bindAddress = result[0];
+            bool ok = false;
+            port = result[1].toUInt(&ok);
+            if (!ok) {
+                port = 2999;
+                LOG_ERROR("Couldn't parse the port. Using 2999 instead.");
+            }
+        } else
+            LOG_ERROR("Couldn't parse %s, wrong format? Using 127.0.0.1:2999 instead.", serverAddress.utf8().data());
+
+        if (!WebInspectorServer::shared().listen(bindAddress, port))
+            LOG_ERROR("Couldn't start listening on: IP address=%s, port=%d.", bindAddress.utf8().data(), port);
+
+        return;
+    }
+
+    LOG(InspectorServer, "To start inspector server set WEBKIT_INSPECTOR_SERVER to 127.0.0.1:2999 for example.");
+#endif
+}
+
 String WebContext::applicationCacheDirectory()
 {
     return String::fromUTF8(efreet_cache_home_get()) + "/WebKitEfl/Applications";
@@ -42,6 +85,8 @@ String WebContext::applicationCacheDirectory()
 
 void WebContext::platformInitializeWebProcess(WebProcessCreationParameters& parameters)
 {
+    initializeInspectorServer();
+
     parameters.urlSchemesRegistered = m_soupRequestManagerProxy->registeredURISchemes();
 }
 
index c43a78f..f0085be 100644 (file)
@@ -120,7 +120,7 @@ static const type& name() \
 #define PLUGIN_ARCHITECTURE(ARCH) (defined PLUGIN_ARCHITECTURE_##ARCH && PLUGIN_ARCHITECTURE_##ARCH)
 
 #ifndef ENABLE_INSPECTOR_SERVER
-#if PLATFORM(QT) || PLATFORM(GTK)
+#if PLATFORM(QT) || PLATFORM(GTK) || PLATFORM(EFL)
 #define ENABLE_INSPECTOR_SERVER 1
 #endif
 #endif