Web Inspector: dispatch messages from the front-end to the backend asynchronously.
authorpfeldman@chromium.org <pfeldman@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 18 Nov 2011 13:29:22 +0000 (13:29 +0000)
committerpfeldman@chromium.org <pfeldman@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 18 Nov 2011 13:29:22 +0000 (13:29 +0000)
https://bugs.webkit.org/show_bug.cgi?id=72621

Source/WebCore:

We should align the way we dispatch messages from the front-end to backend across the environments:
  - WebKit has it synchronoulsly
  - Chromium has it asynchronously
  - Remote debugging has it asynchronously
Making it asynchronous made a number of flaky Qt tests pass.

Tests uncovered console agent problem that was also fixed.

Reviewed by Yury Semikhatsky.

* inspector/InspectorConsoleAgent.cpp:
(WebCore::InspectorConsoleAgent::clearFrontend):
* inspector/InspectorFrontendClient.h:
* inspector/InspectorFrontendClientLocal.cpp:
(WebCore::InspectorBackendDispatchTask::InspectorBackendDispatchTask):
(WebCore::InspectorBackendDispatchTask::dispatch):
(WebCore::InspectorBackendDispatchTask::reset):
(WebCore::InspectorBackendDispatchTask::onTimer):
(WebCore::InspectorFrontendClientLocal::InspectorFrontendClientLocal):
(WebCore::InspectorFrontendClientLocal::windowObjectCleared):
(WebCore::InspectorFrontendClientLocal::sendMessageToBackend):
* inspector/InspectorFrontendClientLocal.h:

Source/WebKit/chromium:

Reviewed by Yury Semikhatsky.

* src/InspectorFrontendClientImpl.cpp:
(WebKit::InspectorFrontendClientImpl::performDisconnectFromBackend):
* src/InspectorFrontendClientImpl.h:

LayoutTests:

Now that dispatching is asynchronous, timeline test needed a fix.

Reviewed by Yury Semikhatsky.

* inspector/timeline/timeline-script-tag-1.html:
* platform/qt/Skipped:

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

LayoutTests/ChangeLog
LayoutTests/inspector/timeline/timeline-script-tag-1.html
Source/WebCore/ChangeLog
Source/WebCore/inspector/InspectorConsoleAgent.cpp
Source/WebCore/inspector/InspectorFrontendClientLocal.cpp
Source/WebCore/inspector/InspectorFrontendClientLocal.h
Source/WebKit/chromium/ChangeLog

index 83048d2..64f82ce 100755 (executable)
@@ -1,3 +1,15 @@
+2011-11-17  Pavel Feldman  <pfeldman@google.com>
+
+        Web Inspector: dispatch messages from the front-end to the backend asynchronously.
+        https://bugs.webkit.org/show_bug.cgi?id=72621
+
+        Now that dispatching is asynchronous, timeline test needed a fix.
+        
+        Reviewed by Yury Semikhatsky.
+
+        * inspector/timeline/timeline-script-tag-1.html:
+        * platform/qt/Skipped:
+
 2011-11-18  Sergio Villar Senin  <svillar@igalia.com>
 
         [GTK][WK2] Invalid TestNetscapePlugin path when using new-run-webkit-tests
index e8f6131..8d790f6 100644 (file)
@@ -27,11 +27,19 @@ function test()
 
     function step3()
     {
-        function format(record) {
+        function format(record)
+        {
             if (record.type === WebInspector.TimelineAgent.RecordType.EvaluateScript)
                 InspectorTest.printTimelineRecordProperties(record);
-            else if (record.type === WebInspector.TimelineAgent.RecordType.ParseHTML)
+            else if (record.type === WebInspector.TimelineAgent.RecordType.ParseHTML) {
+                var children = [];
+                for (var i = 0; i < record.children.length; ++i) {
+                    if (record.children[i].type !== WebInspector.TimelineAgent.RecordType.RecalculateStyles)
+                        children.push(record.children[i]);
+                }
+                record.children = children;
                 InspectorTest.dumpTimelineRecord(record);
+            }
         }
         InspectorTest.printTimelineRecords(null, format);
         InspectorTest.completeTest();
index 111b884..63ad086 100644 (file)
@@ -1,3 +1,31 @@
+2011-11-17  Pavel Feldman  <pfeldman@google.com>
+
+        Web Inspector: dispatch messages from the front-end to the backend asynchronously.
+        https://bugs.webkit.org/show_bug.cgi?id=72621
+
+        We should align the way we dispatch messages from the front-end to backend across the environments:
+          - WebKit has it synchronoulsly
+          - Chromium has it asynchronously
+          - Remote debugging has it asynchronously
+        Making it asynchronous made a number of flaky Qt tests pass.
+
+        Tests uncovered console agent problem that was also fixed.
+
+        Reviewed by Yury Semikhatsky.
+
+        * inspector/InspectorConsoleAgent.cpp:
+        (WebCore::InspectorConsoleAgent::clearFrontend):
+        * inspector/InspectorFrontendClient.h:
+        * inspector/InspectorFrontendClientLocal.cpp:
+        (WebCore::InspectorBackendDispatchTask::InspectorBackendDispatchTask):
+        (WebCore::InspectorBackendDispatchTask::dispatch):
+        (WebCore::InspectorBackendDispatchTask::reset):
+        (WebCore::InspectorBackendDispatchTask::onTimer):
+        (WebCore::InspectorFrontendClientLocal::InspectorFrontendClientLocal):
+        (WebCore::InspectorFrontendClientLocal::windowObjectCleared):
+        (WebCore::InspectorFrontendClientLocal::sendMessageToBackend):
+        * inspector/InspectorFrontendClientLocal.h:
+
 2011-11-18  Iain Merrick  <husky@google.com>
 
         [chromium] Pass screen refresh rate into compositor.
index 82f6044..1e3d7eb 100644 (file)
@@ -135,6 +135,7 @@ void InspectorConsoleAgent::setFrontend(InspectorFrontend* frontend)
 void InspectorConsoleAgent::clearFrontend()
 {
     m_frontend = 0;
+    m_inspectorState->setBoolean(ConsoleAgentState::consoleMessagesEnabled, false);
 }
 
 void InspectorConsoleAgent::addMessageToConsole(MessageSource source, MessageType type, MessageLevel level, const String& message, PassRefPtr<ScriptArguments> arguments, PassRefPtr<ScriptCallStack> callStack)
index 7743ec0..6e08f41 100644 (file)
@@ -45,6 +45,8 @@
 #include "ScriptFunctionCall.h"
 #include "ScriptObject.h"
 #include "Settings.h"
+#include "Timer.h"
+#include <wtf/Deque.h>
 
 namespace WebCore {
 
@@ -53,6 +55,42 @@ static const unsigned defaultAttachedHeight = 300;
 static const float minimumAttachedHeight = 250.0f;
 static const float maximumAttachedHeightRatio = 0.75f;
 
+class InspectorBackendDispatchTask {
+public:
+    InspectorBackendDispatchTask(InspectorController* inspectorController)
+        : m_inspectorController(inspectorController)
+        , m_timer(this, &InspectorBackendDispatchTask::onTimer)
+    {
+    }
+
+    void dispatch(const String& message)
+    {
+        m_messages.append(message);
+        if (!m_timer.isActive())
+            m_timer.startOneShot(0);
+    }
+
+    void reset()
+    {
+        m_messages.clear();
+        m_timer.stop();
+    }
+
+    void onTimer(Timer<InspectorBackendDispatchTask>*)
+    {
+        if (!m_messages.isEmpty()) {
+            // Dispatch can lead to the timer destruction -> schedule the next shot first.
+            m_timer.startOneShot(0);
+            m_inspectorController->dispatchMessageFromFrontend(m_messages.takeFirst());
+        }
+    }
+
+private:
+    InspectorController* m_inspectorController;
+    Timer<InspectorBackendDispatchTask> m_timer;
+    Deque<String> m_messages;
+};
+
 String InspectorFrontendClientLocal::Settings::getProperty(const String&)
 {
     return String();
@@ -69,6 +107,7 @@ InspectorFrontendClientLocal::InspectorFrontendClientLocal(InspectorController*
     , m_settings(settings)
 {
     m_frontendPage->settings()->setAllowFileAccessFromFileURLs(true);
+    m_dispatchTask = adoptPtr(new InspectorBackendDispatchTask(inspectorController));
 }
 
 InspectorFrontendClientLocal::~InspectorFrontendClientLocal()
@@ -163,7 +202,7 @@ unsigned InspectorFrontendClientLocal::constrainedAttachedWindowHeight(unsigned
 
 void InspectorFrontendClientLocal::sendMessageToBackend(const String& message)
 {
-    m_inspectorController->dispatchMessageFromFrontend(message);
+    m_dispatchTask->dispatch(message);
 }
 
 } // namespace WebCore
index e095b45..47b1570 100644 (file)
@@ -39,6 +39,7 @@
 namespace WebCore {
 
 class InspectorController;
+class InspectorBackendDispatchTask;
 class InspectorFrontendHost;
 class Page;
 
@@ -88,6 +89,7 @@ private:
     // TODO(yurys): this ref shouldn't be needed.
     RefPtr<InspectorFrontendHost> m_frontendHost;
     OwnPtr<InspectorFrontendClientLocal::Settings> m_settings;
+    OwnPtr<InspectorBackendDispatchTask> m_dispatchTask;
 };
 
 } // namespace WebCore
index e723354..84f3a9a 100644 (file)
@@ -1,3 +1,14 @@
+2011-11-17  Pavel Feldman  <pfeldman@google.com>
+
+        Web Inspector: dispatch messages from the front-end to the backend asynchronously.
+        https://bugs.webkit.org/show_bug.cgi?id=72621
+
+        Reviewed by Yury Semikhatsky.
+
+        * src/InspectorFrontendClientImpl.cpp:
+        (WebKit::InspectorFrontendClientImpl::performDisconnectFromBackend):
+        * src/InspectorFrontendClientImpl.h:
+
 2011-11-18  Iain Merrick  <husky@google.com>
 
         [chromium] Pass screen refresh rate into compositor.