Enable and connect the WebInspectorServer with WebKit2 pages.
authorjocelyn.turcotte@nokia.com <jocelyn.turcotte@nokia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 3 Apr 2012 13:24:56 +0000 (13:24 +0000)
committerjocelyn.turcotte@nokia.com <jocelyn.turcotte@nokia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 3 Apr 2012 13:24:56 +0000 (13:24 +0000)
https://bugs.webkit.org/show_bug.cgi?id=73094

Reviewed by Simon Hausmann.

Source/WebKit2:

Pages are registered/unregistered as they are created/destroyed, if they have
developer extras enabled. The server is run on the UI process and communicates
with the web process through IPC for each message between the inspector
controller and the remote frontend.

Includes the server spawning logic for the Qt port, the server is
started through an environment variable specifying the interface and
port to bind the server to, by default on 127.0.0.1.

* UIProcess/WebInspectorProxy.cpp:
(WebKit::WebInspectorProxy::WebInspectorProxy):
(WebKit::WebInspectorProxy::invalidate):
(WebKit):
(WebKit::WebInspectorProxy::enableRemoteInspection):
(WebKit::WebInspectorProxy::remoteFrontendConnected):
(WebKit::WebInspectorProxy::remoteFrontendDisconnected):
(WebKit::WebInspectorProxy::dispatchMessageFromRemoteFrontend):
(WebKit::WebInspectorProxy::sendMessageToRemoteFrontend):
* UIProcess/WebInspectorProxy.h:
(WebInspectorProxy):
* UIProcess/WebInspectorProxy.messages.in:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::initializeWebPage):
(WebKit::WebPageProxy::preferencesDidChange):
* UIProcess/qt/QtWebContext.cpp:
(WebKit::initInspectorServer):
(WebKit):
(WebKit::globalInitialization):
(WebKit::QtWebContext::create):
* WebProcess/WebCoreSupport/WebInspectorClient.cpp:
(WebKit::WebInspectorClient::sendMessageToFrontend):
* WebProcess/WebPage/WebInspector.cpp:
(WebKit::WebInspector::WebInspector):
(WebKit):
(WebKit::WebInspector::sendMessageToRemoteFrontend):
(WebKit::WebInspector::dispatchMessageFromRemoteFrontend):
(WebKit::WebInspector::remoteFrontendConnected):
(WebKit::WebInspector::remoteFrontendDisconnected):
* WebProcess/WebPage/WebInspector.h:
(WebInspector):
(WebKit::WebInspector::hasRemoteFrontendConnected):
* WebProcess/WebPage/WebInspector.messages.in:

Tools:

Enable developer extras on pages in MiniBrowser for Qt.

* MiniBrowser/qt/qml/BrowserWindow.qml:

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

12 files changed:
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/WebInspectorProxy.cpp
Source/WebKit2/UIProcess/WebInspectorProxy.h
Source/WebKit2/UIProcess/WebInspectorProxy.messages.in
Source/WebKit2/UIProcess/WebPageProxy.cpp
Source/WebKit2/UIProcess/qt/QtWebContext.cpp
Source/WebKit2/WebProcess/WebCoreSupport/WebInspectorClient.cpp
Source/WebKit2/WebProcess/WebPage/WebInspector.cpp
Source/WebKit2/WebProcess/WebPage/WebInspector.h
Source/WebKit2/WebProcess/WebPage/WebInspector.messages.in
Tools/ChangeLog
Tools/MiniBrowser/qt/qml/BrowserWindow.qml

index 07ddbf2..e0ae589 100644 (file)
@@ -1,3 +1,53 @@
+2012-04-02  Jocelyn Turcotte  <jocelyn.turcotte@nokia.com>
+
+        Enable and connect the WebInspectorServer with WebKit2 pages.
+        https://bugs.webkit.org/show_bug.cgi?id=73094
+
+        Reviewed by Simon Hausmann.
+
+        Pages are registered/unregistered as they are created/destroyed, if they have
+        developer extras enabled. The server is run on the UI process and communicates
+        with the web process through IPC for each message between the inspector
+        controller and the remote frontend.
+
+        Includes the server spawning logic for the Qt port, the server is
+        started through an environment variable specifying the interface and
+        port to bind the server to, by default on 127.0.0.1.
+
+        * UIProcess/WebInspectorProxy.cpp:
+        (WebKit::WebInspectorProxy::WebInspectorProxy):
+        (WebKit::WebInspectorProxy::invalidate):
+        (WebKit):
+        (WebKit::WebInspectorProxy::enableRemoteInspection):
+        (WebKit::WebInspectorProxy::remoteFrontendConnected):
+        (WebKit::WebInspectorProxy::remoteFrontendDisconnected):
+        (WebKit::WebInspectorProxy::dispatchMessageFromRemoteFrontend):
+        (WebKit::WebInspectorProxy::sendMessageToRemoteFrontend):
+        * UIProcess/WebInspectorProxy.h:
+        (WebInspectorProxy):
+        * UIProcess/WebInspectorProxy.messages.in:
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::initializeWebPage):
+        (WebKit::WebPageProxy::preferencesDidChange):
+        * UIProcess/qt/QtWebContext.cpp:
+        (WebKit::initInspectorServer):
+        (WebKit):
+        (WebKit::globalInitialization):
+        (WebKit::QtWebContext::create):
+        * WebProcess/WebCoreSupport/WebInspectorClient.cpp:
+        (WebKit::WebInspectorClient::sendMessageToFrontend):
+        * WebProcess/WebPage/WebInspector.cpp:
+        (WebKit::WebInspector::WebInspector):
+        (WebKit):
+        (WebKit::WebInspector::sendMessageToRemoteFrontend):
+        (WebKit::WebInspector::dispatchMessageFromRemoteFrontend):
+        (WebKit::WebInspector::remoteFrontendConnected):
+        (WebKit::WebInspector::remoteFrontendDisconnected):
+        * WebProcess/WebPage/WebInspector.h:
+        (WebInspector):
+        (WebKit::WebInspector::hasRemoteFrontendConnected):
+        * WebProcess/WebPage/WebInspector.messages.in:
+
 2012-03-29  Joseph Pecoraro  <joepeck@webkit.org> and Jocelyn Turcotte  <jocelyn.turcotte@nokia.com>
 
         WebInspectorServer for WebKit2.
index f5ccd9f..ab19d5d 100644 (file)
@@ -39,6 +39,9 @@
 #include "WebProcessProxy.h"
 #include "WebURLRequest.h"
 
+#if ENABLE(INSPECTOR_SERVER)
+#include "WebInspectorServer.h"
+#endif
 #if PLATFORM(WIN)
 #include "WebView.h"
 #endif
@@ -81,6 +84,9 @@ WebInspectorProxy::WebInspectorProxy(WebPageProxy* page)
     , m_inspectorView(0)
     , m_inspectorWindow(0)
 #endif
+#if ENABLE(INSPECTOR_SERVER)
+    , m_remoteInspectionPageId(0)
+#endif
 {
 }
 
@@ -90,6 +96,11 @@ WebInspectorProxy::~WebInspectorProxy()
 
 void WebInspectorProxy::invalidate()
 {
+#if ENABLE(INSPECTOR_SERVER)
+    if (m_remoteInspectionPageId)
+        WebInspectorServer::shared().unregisterPage(m_remoteInspectionPageId);
+#endif
+
     m_page->close();
     didClose();
 
@@ -256,6 +267,29 @@ static void decidePolicyForNavigationAction(WKPageRef, WKFrameRef frameRef, WKFr
     webInspectorProxy->page()->loadURLRequest(toImpl(requestRef));
 }
 
+#if ENABLE(INSPECTOR_SERVER)
+void WebInspectorProxy::enableRemoteInspection()
+{
+    if (!m_remoteInspectionPageId)
+        m_remoteInspectionPageId = WebInspectorServer::shared().registerPage(this);
+}
+
+void WebInspectorProxy::remoteFrontendConnected()
+{
+    m_page->process()->send(Messages::WebInspector::RemoteFrontendConnected(), m_page->pageID());
+}
+
+void WebInspectorProxy::remoteFrontendDisconnected()
+{
+    m_page->process()->send(Messages::WebInspector::RemoteFrontendDisconnected(), m_page->pageID());
+}
+
+void WebInspectorProxy::dispatchMessageFromRemoteFrontend(const String& message)
+{
+    m_page->process()->send(Messages::WebInspector::DispatchMessageFromRemoteFrontend(message), m_page->pageID());
+}
+#endif
+
 // Called by WebInspectorProxy messages
 void WebInspectorProxy::createInspectorPage(uint64_t& inspectorPageID, WebPageCreationParameters& inspectorPageParameters)
 {
@@ -348,6 +382,14 @@ bool WebInspectorProxy::shouldOpenAttached()
     return inspectorPageGroup()->preferences()->inspectorStartsAttached() && canAttach();
 }
 
+#if ENABLE(INSPECTOR_SERVER)
+void WebInspectorProxy::sendMessageToRemoteFrontend(const String& message)
+{
+    ASSERT(m_remoteInspectionPageId);
+    WebInspectorServer::shared().sendMessageOverConnection(m_remoteInspectionPageId, message);
+}
+#endif
+
 } // namespace WebKit
 
 #endif // ENABLE(INSPECTOR)
index 501789e..9614672 100644 (file)
@@ -123,6 +123,13 @@ public:
     String inspectorPageURL() const;
     String inspectorBaseURL() const;
 
+#if ENABLE(INSPECTOR_SERVER)
+    void enableRemoteInspection();
+    void remoteFrontendConnected();
+    void remoteFrontendDisconnected();
+    void dispatchMessageFromRemoteFrontend(const String& message);
+#endif
+
 private:
     WebInspectorProxy(WebPageProxy* page);
 
@@ -146,6 +153,10 @@ private:
     void bringToFront();
     void inspectedURLChanged(const String&);
 
+#if ENABLE(INSPECTOR_SERVER)
+    void sendMessageToRemoteFrontend(const String& message);
+#endif
+
     bool canAttach();
     bool shouldOpenAttached();
 
@@ -194,6 +205,9 @@ private:
     GtkWidget* m_inspectorView;
     GtkWidget* m_inspectorWindow;
 #endif
+#if ENABLE(INSPECTOR_SERVER)
+    int m_remoteInspectionPageId;
+#endif
 };
 
 } // namespace WebKit
index a194985..2b66633 100644 (file)
@@ -32,6 +32,10 @@ messages -> WebInspectorProxy {
     Attach()
     Detach()
     SetAttachedWindowHeight(unsigned height)
+
+#if ENABLE(INSPECTOR_SERVER)
+    SendMessageToRemoteFrontend(WTF::String message)
+#endif
 }
 
 #endif
index edee77b..bab9810 100644 (file)
@@ -339,6 +339,11 @@ void WebPageProxy::initializeWebPage()
     m_drawingArea = m_pageClient->createDrawingAreaProxy();
     ASSERT(m_drawingArea);
 
+#if ENABLE(INSPECTOR_SERVER)
+    if (m_pageGroup->preferences()->developerExtrasEnabled())
+        inspector()->enableRemoteInspection();
+#endif
+
     process()->send(Messages::WebProcess::CreateWebPage(m_pageID, creationParameters()), 0);
 }
 
@@ -1571,6 +1576,11 @@ void WebPageProxy::preferencesDidChange()
     if (!isValid())
         return;
 
+#if ENABLE(INSPECTOR_SERVER)
+    if (m_pageGroup->preferences()->developerExtrasEnabled())
+        inspector()->enableRemoteInspection();
+#endif
+
     // FIXME: It probably makes more sense to send individual preference changes.
     // However, WebKitTestRunner depends on getting a preference change notification
     // even if nothing changed in UI process, so that overrides get removed.
index a800fef..46117af 100644 (file)
@@ -26,6 +26,7 @@
 #include "QtWebIconDatabaseClient.h"
 #include "WKAPICast.h"
 #include "WebContext.h"
+#include "WebInspectorServer.h"
 #include "WebPageProxy.h"
 #include <WKArray.h>
 #include <WKPage.h>
@@ -44,6 +45,46 @@ static HashMap<uint64_t, QtWebContext*> contextMap;
 
 QtWebContext* QtWebContext::s_defaultContext = 0;
 
+static void initInspectorServer()
+{
+    QString inspectorEnv = QString::fromUtf8(qgetenv("QTWEBKIT_INSPECTOR_SERVER"));
+    if (!inspectorEnv.isEmpty()) {
+        QString bindAddress = QLatin1String("127.0.0.1");
+        QString portStr = inspectorEnv;
+        int port = 0;
+
+        int portColonPos = inspectorEnv.lastIndexOf(':');
+        if (portColonPos != -1) {
+            portStr = inspectorEnv.mid(portColonPos + 1);
+            bindAddress = inspectorEnv.mid(0, portColonPos);
+        }
+
+        bool ok = false;
+        port = portStr.toInt(&ok);
+        if (!ok) {
+            qWarning("Non numeric port for the inspector server \"%s\". Examples of valid input: \"12345\" or \"192.168.2.14:12345\" (with the address of one of this host's interface).", qPrintable(portStr));
+            return;
+        }
+
+        bool success = WebInspectorServer::shared().listen(bindAddress, port);
+        if (success) {
+            QString inspectorServerUrl = QString::fromLatin1("http://%1:%2").arg(bindAddress).arg(port);
+            qWarning("Inspector server started successfully. Try pointing a WebKit browser to %s", qPrintable(inspectorServerUrl));
+        } else
+            qWarning("Couldn't start the inspector server on bind address \"%s\" and port \"%d\". In case of invalid input, try something like: \"12345\" or \"192.168.2.14:12345\" (with the address of one of this host's interface).", qPrintable(bindAddress), port);
+    }
+}
+
+static void globalInitialization()
+{
+    static bool initialized = false;
+    if (initialized)
+        return;
+
+    initInspectorServer();
+    initialized = true;
+}
+
 QtWebContext::QtWebContext(WebContext* context)
     : m_contextID(generateContextID())
     , m_context(context)
@@ -63,6 +104,7 @@ QtWebContext::~QtWebContext()
 // Used only by WebKitTestRunner. It avoids calling initialize(), so that we don't register any clients.
 PassRefPtr<QtWebContext> QtWebContext::create(WebContext* context)
 {
+    globalInitialization();
     return adoptRef(new QtWebContext(context));
 }
 
index 90a8705..5bfc950 100644 (file)
@@ -89,10 +89,19 @@ bool WebInspectorClient::sendMessageToFrontend(const String& message)
     WebInspector* inspector = m_page->inspector();
     if (!inspector)
         return false;
+
+#if ENABLE(INSPECTOR_SERVER)
+    if (inspector->hasRemoteFrontendConnected()) {
+        inspector->sendMessageToRemoteFrontend(message);
+        return true;
+    }
+#endif
+
     WebPage* inspectorPage = inspector->inspectorPage();
-    if (!inspectorPage)
-        return false;
-    return doDispatchMessageOnFrontendPage(inspectorPage->corePage(), message);
+    if (inspectorPage)
+        return doDispatchMessageOnFrontendPage(inspectorPage->corePage(), message);
+
+    return false;
 }
 
 void WebInspectorClient::pageOverlayDestroyed(PageOverlay*)
index 417837d..01b3cc2 100644 (file)
@@ -50,6 +50,9 @@ WebInspector::WebInspector(WebPage* page)
     : m_page(page)
     , m_inspectorPage(0)
     , m_frontendClient(0)
+#if ENABLE(INSPECTOR_SERVER)
+    , m_remoteFrontendConnected(false)
+#endif
 {
 }
 
@@ -236,6 +239,36 @@ void WebInspector::updateDockingAvailability()
         m_frontendClient->setDockingUnavailable(!m_frontendClient->canAttachWindow());
 }
 
+#if ENABLE(INSPECTOR_SERVER)
+void WebInspector::sendMessageToRemoteFrontend(const String& message)
+{
+    ASSERT(m_remoteFrontendConnected);
+    WebProcess::shared().connection()->send(Messages::WebInspectorProxy::SendMessageToRemoteFrontend(message), m_page->pageID());
+}
+
+void WebInspector::dispatchMessageFromRemoteFrontend(const String& message)
+{
+    m_page->corePage()->inspectorController()->dispatchMessageFromFrontend(message);
+}
+
+void WebInspector::remoteFrontendConnected()
+{
+    ASSERT(!m_remoteFrontendConnected);
+    // Switching between in-process and remote inspectors isn't supported yet.
+    ASSERT(!m_inspectorPage);
+
+    m_page->corePage()->inspectorController()->connectFrontend();
+    m_remoteFrontendConnected = true;
+}
+
+void WebInspector::remoteFrontendDisconnected()
+{
+    ASSERT(m_remoteFrontendConnected);
+    m_page->corePage()->inspectorController()->disconnectFrontend();
+    m_remoteFrontendConnected = false;
+}
+#endif
+
 } // namespace WebKit
 
 #endif // ENABLE(INSPECTOR)
index 0906e64..575725a 100644 (file)
@@ -61,6 +61,14 @@ public:
     void startPageProfiling();
     void stopPageProfiling();
 
+#if ENABLE(INSPECTOR_SERVER)
+    bool hasRemoteFrontendConnected() const { return m_remoteFrontendConnected; }
+    void sendMessageToRemoteFrontend(const String& message);
+    void dispatchMessageFromRemoteFrontend(const String& message);
+    void remoteFrontendConnected();
+    void remoteFrontendDisconnected();
+#endif
+
 #if PLATFORM(MAC)
     void setInspectorUsesWebKitUserInterface(bool);
 #endif
@@ -111,6 +119,9 @@ private:
 #if PLATFORM(MAC)
     String m_localizedStringsURL;
 #endif
+#if ENABLE(INSPECTOR_SERVER)
+    bool m_remoteFrontendConnected;
+#endif
 };
 
 } // namespace WebKit
index a1a80f0..998272d 100644 (file)
@@ -34,6 +34,12 @@ messages -> WebInspector {
     StopJavaScriptProfiling()
     StartPageProfiling()
     StopPageProfiling()
+
+#if ENABLE(INSPECTOR_SERVER)
+    DispatchMessageFromRemoteFrontend(WTF::String message)
+    RemoteFrontendConnected()
+    RemoteFrontendDisconnected()
+#endif
 }
 
 #endif
index 20ce9f4..16e01fc 100644 (file)
@@ -1,3 +1,14 @@
+2012-04-02  Jocelyn Turcotte  <jocelyn.turcotte@nokia.com>
+
+        Enable and connect the WebInspectorServer with WebKit2 pages.
+        https://bugs.webkit.org/show_bug.cgi?id=73094
+
+        Reviewed by Simon Hausmann.
+
+        Enable developer extras on pages in MiniBrowser for Qt.
+
+        * MiniBrowser/qt/qml/BrowserWindow.qml:
+
 2012-04-03  Christophe Dumez  <christophe.dumez@intel.com>
 
         [EFL] LayoutTestController needs implementation of setDefersLoading
index 7d8a91f..eeb8816 100644 (file)
@@ -314,6 +314,7 @@ Rectangle {
         experimental.authenticationDialog: AuthenticationDialog { }
         experimental.proxyAuthenticationDialog: ProxyAuthenticationDialog { }
         experimental.filePicker: FilePicker { }
+        experimental.preferences.developerExtrasEnabled: true
         experimental.databaseQuotaDialog: Item {
             Timer {
                 interval: 1