Web Inspector: Generate Individual InspectorBackendDispatchers, add base InspectorBac...
authorjoepeck@webkit.org <joepeck@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 Nov 2013 02:24:46 +0000 (02:24 +0000)
committerjoepeck@webkit.org <joepeck@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 Nov 2013 02:24:46 +0000 (02:24 +0000)
https://bugs.webkit.org/show_bug.cgi?id=124296

Reviewed by Timothy Hatcher.

No new tests, this is just refactoring without changing functionality.
Set of changes made:

  - Add inspector/InspectorBackendDispatcher.{h,cpp}. This used to be almost entirely
    written in the code generator strings file, but make it actual source files
    because there is nothing changing in the code. Also clean this up a bit.
  - Give the base dispatcher a list of domain dispatchers and a way to register.
  - Make InspectorBackendDispatcher::dispatch read the domain of incoming request
    and pass the request on to the domain dispatcher.
  - Create per-domain dispatcher classes named "InspectorFooBackendDispatcher"
  - Convert "InspectorBackendDispatcher::FooCommandHandler" interfaces to
    "InspectorFooBackendDispatcherHandler" interfaces.
  - Convert all "InspectorBackendDispatcherImpl::FooDomain_fooMethod" methods to
    "InspectorFooBackendDispatcher::fooMethod" methods. These can also remove their
    "if (!agent)" checks because that can never be the case anymore.
  - Remove InspectorBackendDispatcherImpl, now that there are base and domain dispatchers.
  - Add ASCIILiteral in many places in generated code where possible.
  - In all agents, create dispatchers in didCreateFrontendAndBackend and clear
    them in willDestroyFrontendAndBackend, right alongside frontend dispatchers.

* inspector/CodeGeneratorInspector.py:
(DomainNameFixes.get_fixed_data.Res):
(TypeBindings.create_type_declaration_.EnumBinding.get_code_generator.CodeGenerator.generate_type_builder):
(Generator):
(Generator.go):
(Generator.process_command):
(Generator.generate_send_method):
* inspector/CodeGeneratorInspectorStrings.py:
(void):
(HashMap):
(InspectorBackendDispatchers_h):
* inspector/InspectorAgent.cpp:
(WebCore::InspectorAgent::didCreateFrontendAndBackend):
(WebCore::InspectorAgent::willDestroyFrontendAndBackend):
* inspector/InspectorAgent.h:
* inspector/InspectorAllInOne.cpp:
* inspector/InspectorApplicationCacheAgent.cpp:
(WebCore::InspectorApplicationCacheAgent::didCreateFrontendAndBackend):
(WebCore::InspectorApplicationCacheAgent::willDestroyFrontendAndBackend):
* inspector/InspectorApplicationCacheAgent.h:
* inspector/InspectorBackendDispatcher.cpp: Added.
(WebCore::InspectorBackendDispatcher::CallbackBase::CallbackBase):
(WebCore::InspectorBackendDispatcher::CallbackBase::isActive):
(WebCore::InspectorBackendDispatcher::CallbackBase::sendFailure):
(WebCore::InspectorBackendDispatcher::CallbackBase::sendIfActive):
(WebCore::InspectorBackendDispatcher::create):
(WebCore::InspectorBackendDispatcher::registerDispatcherForDomain):
(WebCore::InspectorBackendDispatcher::dispatch):
(WebCore::InspectorBackendDispatcher::sendResponse):
(WebCore::InspectorBackendDispatcher::reportProtocolError):
(WebCore::InspectorBackendDispatcher::getPropertyValue):
(WebCore::AsMethodBridges::asInt):
(WebCore::AsMethodBridges::asDouble):
(WebCore::AsMethodBridges::asString):
(WebCore::AsMethodBridges::asBoolean):
(WebCore::AsMethodBridges::asObject):
(WebCore::AsMethodBridges::asArray):
(WebCore::InspectorBackendDispatcher::getInt):
(WebCore::InspectorBackendDispatcher::getDouble):
(WebCore::InspectorBackendDispatcher::getString):
(WebCore::InspectorBackendDispatcher::getBoolean):
(WebCore::InspectorBackendDispatcher::getObject):
(WebCore::InspectorBackendDispatcher::getArray):
* inspector/InspectorBackendDispatcher.h: Added.
(WebCore::InspectorSupplementalBackendDispatcher::InspectorSupplementalBackendDispatcher):
(WebCore::InspectorSupplementalBackendDispatcher::~InspectorSupplementalBackendDispatcher):
(WebCore::InspectorBackendDispatcher::~InspectorBackendDispatcher):
(WebCore::InspectorBackendDispatcher::clearFrontend):
(WebCore::InspectorBackendDispatcher::isActive):
(WebCore::InspectorBackendDispatcher::InspectorBackendDispatcher):
* inspector/InspectorCSSAgent.cpp:
(WebCore::InspectorCSSAgent::didCreateFrontendAndBackend):
(WebCore::InspectorCSSAgent::willDestroyFrontendAndBackend):
* inspector/InspectorCSSAgent.h:
* inspector/InspectorCanvasAgent.cpp:
(WebCore::InspectorCanvasAgent::didCreateFrontendAndBackend):
(WebCore::InspectorCanvasAgent::willDestroyFrontendAndBackend):
* inspector/InspectorCanvasAgent.h:
* inspector/InspectorConsoleAgent.cpp:
(WebCore::InspectorConsoleAgent::didCreateFrontendAndBackend):
(WebCore::InspectorConsoleAgent::willDestroyFrontendAndBackend):
* inspector/InspectorConsoleAgent.h:
* inspector/InspectorDOMAgent.cpp:
(WebCore::InspectorDOMAgent::didCreateFrontendAndBackend):
(WebCore::InspectorDOMAgent::willDestroyFrontendAndBackend):
* inspector/InspectorDOMAgent.h:
* inspector/InspectorDOMDebuggerAgent.cpp:
(WebCore::InspectorDOMDebuggerAgent::didCreateFrontendAndBackend):
(WebCore::InspectorDOMDebuggerAgent::willDestroyFrontendAndBackend):
* inspector/InspectorDOMDebuggerAgent.h:
* inspector/InspectorDOMStorageAgent.cpp:
(WebCore::InspectorDOMStorageAgent::didCreateFrontendAndBackend):
(WebCore::InspectorDOMStorageAgent::willDestroyFrontendAndBackend):
* inspector/InspectorDOMStorageAgent.h:
* inspector/InspectorDatabaseAgent.cpp:
(WebCore::InspectorDatabaseAgent::didCreateFrontendAndBackend):
(WebCore::InspectorDatabaseAgent::willDestroyFrontendAndBackend):
* inspector/InspectorDatabaseAgent.h:
* inspector/InspectorDebuggerAgent.cpp:
(WebCore::InspectorDebuggerAgent::didCreateFrontendAndBackend):
(WebCore::InspectorDebuggerAgent::willDestroyFrontendAndBackend):
* inspector/InspectorDebuggerAgent.h:
* inspector/InspectorHeapProfilerAgent.cpp:
(WebCore::InspectorHeapProfilerAgent::didCreateFrontendAndBackend):
(WebCore::InspectorHeapProfilerAgent::willDestroyFrontendAndBackend):
* inspector/InspectorHeapProfilerAgent.h:
* inspector/InspectorIndexedDBAgent.cpp:
(WebCore::InspectorIndexedDBAgent::didCreateFrontendAndBackend):
(WebCore::InspectorIndexedDBAgent::willDestroyFrontendAndBackend):
* inspector/InspectorIndexedDBAgent.h:
* inspector/InspectorInputAgent.cpp:
(WebCore::InspectorInputAgent::didCreateFrontendAndBackend):
(WebCore::InspectorInputAgent::willDestroyFrontendAndBackend):
* inspector/InspectorInputAgent.h:
* inspector/InspectorLayerTreeAgent.cpp:
(WebCore::InspectorLayerTreeAgent::didCreateFrontendAndBackend):
(WebCore::InspectorLayerTreeAgent::willDestroyFrontendAndBackend):
* inspector/InspectorLayerTreeAgent.h:
* inspector/InspectorMemoryAgent.cpp:
(WebCore::InspectorMemoryAgent::didCreateFrontendAndBackend):
(WebCore::InspectorMemoryAgent::willDestroyFrontendAndBackend):
* inspector/InspectorMemoryAgent.h:
* inspector/InspectorPageAgent.cpp:
(WebCore::InspectorPageAgent::didCreateFrontendAndBackend):
(WebCore::InspectorPageAgent::willDestroyFrontendAndBackend):
(WebCore::InspectorPageAgent::getScriptExecutionStatus):
* inspector/InspectorPageAgent.h:
* inspector/InspectorProfilerAgent.cpp:
(WebCore::InspectorProfilerAgent::didCreateFrontendAndBackend):
(WebCore::InspectorProfilerAgent::willDestroyFrontendAndBackend):
* inspector/InspectorProfilerAgent.h:
* inspector/InspectorResourceAgent.cpp:
(WebCore::InspectorResourceAgent::didCreateFrontendAndBackend):
(WebCore::InspectorResourceAgent::willDestroyFrontendAndBackend):
* inspector/InspectorResourceAgent.h:
* inspector/InspectorRuntimeAgent.h:
* inspector/InspectorTimelineAgent.cpp:
(WebCore::InspectorTimelineAgent::didCreateFrontendAndBackend):
(WebCore::InspectorTimelineAgent::willDestroyFrontendAndBackend):
* inspector/InspectorTimelineAgent.h:
* inspector/InspectorWorkerAgent.cpp:
(WebCore::InspectorWorkerAgent::didCreateFrontendAndBackend):
(WebCore::InspectorWorkerAgent::willDestroyFrontendAndBackend):
* inspector/InspectorWorkerAgent.h:
* inspector/PageRuntimeAgent.cpp:
(WebCore::PageRuntimeAgent::didCreateFrontendAndBackend):
(WebCore::PageRuntimeAgent::willDestroyFrontendAndBackend):
* inspector/PageRuntimeAgent.h:
* inspector/WorkerRuntimeAgent.cpp:
(WebCore::WorkerRuntimeAgent::didCreateFrontendAndBackend):
(WebCore::WorkerRuntimeAgent::willDestroyFrontendAndBackend):
* inspector/WorkerRuntimeAgent.h:

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

54 files changed:
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/GNUmakefile.list.am
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/inspector/CodeGeneratorInspector.py
Source/WebCore/inspector/CodeGeneratorInspectorStrings.py
Source/WebCore/inspector/InspectorAgent.cpp
Source/WebCore/inspector/InspectorAgent.h
Source/WebCore/inspector/InspectorAllInOne.cpp
Source/WebCore/inspector/InspectorApplicationCacheAgent.cpp
Source/WebCore/inspector/InspectorApplicationCacheAgent.h
Source/WebCore/inspector/InspectorBackendDispatcher.cpp [new file with mode: 0644]
Source/WebCore/inspector/InspectorBackendDispatcher.h [new file with mode: 0644]
Source/WebCore/inspector/InspectorCSSAgent.cpp
Source/WebCore/inspector/InspectorCSSAgent.h
Source/WebCore/inspector/InspectorCanvasAgent.cpp
Source/WebCore/inspector/InspectorCanvasAgent.h
Source/WebCore/inspector/InspectorConsoleAgent.cpp
Source/WebCore/inspector/InspectorConsoleAgent.h
Source/WebCore/inspector/InspectorDOMAgent.cpp
Source/WebCore/inspector/InspectorDOMAgent.h
Source/WebCore/inspector/InspectorDOMDebuggerAgent.cpp
Source/WebCore/inspector/InspectorDOMDebuggerAgent.h
Source/WebCore/inspector/InspectorDOMStorageAgent.cpp
Source/WebCore/inspector/InspectorDOMStorageAgent.h
Source/WebCore/inspector/InspectorDatabaseAgent.cpp
Source/WebCore/inspector/InspectorDatabaseAgent.h
Source/WebCore/inspector/InspectorDebuggerAgent.cpp
Source/WebCore/inspector/InspectorDebuggerAgent.h
Source/WebCore/inspector/InspectorHeapProfilerAgent.cpp
Source/WebCore/inspector/InspectorHeapProfilerAgent.h
Source/WebCore/inspector/InspectorIndexedDBAgent.cpp
Source/WebCore/inspector/InspectorIndexedDBAgent.h
Source/WebCore/inspector/InspectorInputAgent.cpp
Source/WebCore/inspector/InspectorInputAgent.h
Source/WebCore/inspector/InspectorLayerTreeAgent.cpp
Source/WebCore/inspector/InspectorLayerTreeAgent.h
Source/WebCore/inspector/InspectorMemoryAgent.cpp
Source/WebCore/inspector/InspectorMemoryAgent.h
Source/WebCore/inspector/InspectorPageAgent.cpp
Source/WebCore/inspector/InspectorPageAgent.h
Source/WebCore/inspector/InspectorProfilerAgent.cpp
Source/WebCore/inspector/InspectorProfilerAgent.h
Source/WebCore/inspector/InspectorResourceAgent.cpp
Source/WebCore/inspector/InspectorResourceAgent.h
Source/WebCore/inspector/InspectorRuntimeAgent.h
Source/WebCore/inspector/InspectorTimelineAgent.cpp
Source/WebCore/inspector/InspectorTimelineAgent.h
Source/WebCore/inspector/InspectorWorkerAgent.cpp
Source/WebCore/inspector/InspectorWorkerAgent.h
Source/WebCore/inspector/PageRuntimeAgent.cpp
Source/WebCore/inspector/PageRuntimeAgent.h
Source/WebCore/inspector/WorkerRuntimeAgent.cpp
Source/WebCore/inspector/WorkerRuntimeAgent.h

index d1de072..74e38f4 100644 (file)
@@ -1571,6 +1571,7 @@ set(WebCore_SOURCES
     inspector/InspectorAgent.cpp
     inspector/InspectorAgentRegistry.cpp
     inspector/InspectorApplicationCacheAgent.cpp
+    inspector/InspectorBackendDispatcher.cpp
     inspector/InspectorCSSAgent.cpp
     inspector/InspectorCanvasAgent.cpp
     inspector/InspectorClient.cpp
index 51855f8..c5835e8 100644 (file)
@@ -1,3 +1,163 @@
+2013-11-13  Joseph Pecoraro  <pecoraro@apple.com>
+
+        Web Inspector: Generate Individual InspectorBackendDispatchers, add base InspectorBackendDispatcher
+        https://bugs.webkit.org/show_bug.cgi?id=124296
+
+        Reviewed by Timothy Hatcher.
+
+        No new tests, this is just refactoring without changing functionality.
+        Set of changes made:
+
+          - Add inspector/InspectorBackendDispatcher.{h,cpp}. This used to be almost entirely
+            written in the code generator strings file, but make it actual source files
+            because there is nothing changing in the code. Also clean this up a bit.
+          - Give the base dispatcher a list of domain dispatchers and a way to register.
+          - Make InspectorBackendDispatcher::dispatch read the domain of incoming request
+            and pass the request on to the domain dispatcher.
+          - Create per-domain dispatcher classes named "InspectorFooBackendDispatcher"
+          - Convert "InspectorBackendDispatcher::FooCommandHandler" interfaces to
+            "InspectorFooBackendDispatcherHandler" interfaces.
+          - Convert all "InspectorBackendDispatcherImpl::FooDomain_fooMethod" methods to
+            "InspectorFooBackendDispatcher::fooMethod" methods. These can also remove their
+            "if (!agent)" checks because that can never be the case anymore.
+          - Remove InspectorBackendDispatcherImpl, now that there are base and domain dispatchers.
+          - Add ASCIILiteral in many places in generated code where possible.
+          - In all agents, create dispatchers in didCreateFrontendAndBackend and clear
+            them in willDestroyFrontendAndBackend, right alongside frontend dispatchers.
+
+        * inspector/CodeGeneratorInspector.py:
+        (DomainNameFixes.get_fixed_data.Res):
+        (TypeBindings.create_type_declaration_.EnumBinding.get_code_generator.CodeGenerator.generate_type_builder):
+        (Generator):
+        (Generator.go):
+        (Generator.process_command):
+        (Generator.generate_send_method):
+        * inspector/CodeGeneratorInspectorStrings.py:
+        (void):
+        (HashMap):
+        (InspectorBackendDispatchers_h):
+        * inspector/InspectorAgent.cpp:
+        (WebCore::InspectorAgent::didCreateFrontendAndBackend):
+        (WebCore::InspectorAgent::willDestroyFrontendAndBackend):
+        * inspector/InspectorAgent.h:
+        * inspector/InspectorAllInOne.cpp:
+        * inspector/InspectorApplicationCacheAgent.cpp:
+        (WebCore::InspectorApplicationCacheAgent::didCreateFrontendAndBackend):
+        (WebCore::InspectorApplicationCacheAgent::willDestroyFrontendAndBackend):
+        * inspector/InspectorApplicationCacheAgent.h:
+        * inspector/InspectorBackendDispatcher.cpp: Added.
+        (WebCore::InspectorBackendDispatcher::CallbackBase::CallbackBase):
+        (WebCore::InspectorBackendDispatcher::CallbackBase::isActive):
+        (WebCore::InspectorBackendDispatcher::CallbackBase::sendFailure):
+        (WebCore::InspectorBackendDispatcher::CallbackBase::sendIfActive):
+        (WebCore::InspectorBackendDispatcher::create):
+        (WebCore::InspectorBackendDispatcher::registerDispatcherForDomain):
+        (WebCore::InspectorBackendDispatcher::dispatch):
+        (WebCore::InspectorBackendDispatcher::sendResponse):
+        (WebCore::InspectorBackendDispatcher::reportProtocolError):
+        (WebCore::InspectorBackendDispatcher::getPropertyValue):
+        (WebCore::AsMethodBridges::asInt):
+        (WebCore::AsMethodBridges::asDouble):
+        (WebCore::AsMethodBridges::asString):
+        (WebCore::AsMethodBridges::asBoolean):
+        (WebCore::AsMethodBridges::asObject):
+        (WebCore::AsMethodBridges::asArray):
+        (WebCore::InspectorBackendDispatcher::getInt):
+        (WebCore::InspectorBackendDispatcher::getDouble):
+        (WebCore::InspectorBackendDispatcher::getString):
+        (WebCore::InspectorBackendDispatcher::getBoolean):
+        (WebCore::InspectorBackendDispatcher::getObject):
+        (WebCore::InspectorBackendDispatcher::getArray):
+        * inspector/InspectorBackendDispatcher.h: Added.
+        (WebCore::InspectorSupplementalBackendDispatcher::InspectorSupplementalBackendDispatcher):
+        (WebCore::InspectorSupplementalBackendDispatcher::~InspectorSupplementalBackendDispatcher):
+        (WebCore::InspectorBackendDispatcher::~InspectorBackendDispatcher):
+        (WebCore::InspectorBackendDispatcher::clearFrontend):
+        (WebCore::InspectorBackendDispatcher::isActive):
+        (WebCore::InspectorBackendDispatcher::InspectorBackendDispatcher):
+        * inspector/InspectorCSSAgent.cpp:
+        (WebCore::InspectorCSSAgent::didCreateFrontendAndBackend):
+        (WebCore::InspectorCSSAgent::willDestroyFrontendAndBackend):
+        * inspector/InspectorCSSAgent.h:
+        * inspector/InspectorCanvasAgent.cpp:
+        (WebCore::InspectorCanvasAgent::didCreateFrontendAndBackend):
+        (WebCore::InspectorCanvasAgent::willDestroyFrontendAndBackend):
+        * inspector/InspectorCanvasAgent.h:
+        * inspector/InspectorConsoleAgent.cpp:
+        (WebCore::InspectorConsoleAgent::didCreateFrontendAndBackend):
+        (WebCore::InspectorConsoleAgent::willDestroyFrontendAndBackend):
+        * inspector/InspectorConsoleAgent.h:
+        * inspector/InspectorDOMAgent.cpp:
+        (WebCore::InspectorDOMAgent::didCreateFrontendAndBackend):
+        (WebCore::InspectorDOMAgent::willDestroyFrontendAndBackend):
+        * inspector/InspectorDOMAgent.h:
+        * inspector/InspectorDOMDebuggerAgent.cpp:
+        (WebCore::InspectorDOMDebuggerAgent::didCreateFrontendAndBackend):
+        (WebCore::InspectorDOMDebuggerAgent::willDestroyFrontendAndBackend):
+        * inspector/InspectorDOMDebuggerAgent.h:
+        * inspector/InspectorDOMStorageAgent.cpp:
+        (WebCore::InspectorDOMStorageAgent::didCreateFrontendAndBackend):
+        (WebCore::InspectorDOMStorageAgent::willDestroyFrontendAndBackend):
+        * inspector/InspectorDOMStorageAgent.h:
+        * inspector/InspectorDatabaseAgent.cpp:
+        (WebCore::InspectorDatabaseAgent::didCreateFrontendAndBackend):
+        (WebCore::InspectorDatabaseAgent::willDestroyFrontendAndBackend):
+        * inspector/InspectorDatabaseAgent.h:
+        * inspector/InspectorDebuggerAgent.cpp:
+        (WebCore::InspectorDebuggerAgent::didCreateFrontendAndBackend):
+        (WebCore::InspectorDebuggerAgent::willDestroyFrontendAndBackend):
+        * inspector/InspectorDebuggerAgent.h:
+        * inspector/InspectorHeapProfilerAgent.cpp:
+        (WebCore::InspectorHeapProfilerAgent::didCreateFrontendAndBackend):
+        (WebCore::InspectorHeapProfilerAgent::willDestroyFrontendAndBackend):
+        * inspector/InspectorHeapProfilerAgent.h:
+        * inspector/InspectorIndexedDBAgent.cpp:
+        (WebCore::InspectorIndexedDBAgent::didCreateFrontendAndBackend):
+        (WebCore::InspectorIndexedDBAgent::willDestroyFrontendAndBackend):
+        * inspector/InspectorIndexedDBAgent.h:
+        * inspector/InspectorInputAgent.cpp:
+        (WebCore::InspectorInputAgent::didCreateFrontendAndBackend):
+        (WebCore::InspectorInputAgent::willDestroyFrontendAndBackend):
+        * inspector/InspectorInputAgent.h:
+        * inspector/InspectorLayerTreeAgent.cpp:
+        (WebCore::InspectorLayerTreeAgent::didCreateFrontendAndBackend):
+        (WebCore::InspectorLayerTreeAgent::willDestroyFrontendAndBackend):
+        * inspector/InspectorLayerTreeAgent.h:
+        * inspector/InspectorMemoryAgent.cpp:
+        (WebCore::InspectorMemoryAgent::didCreateFrontendAndBackend):
+        (WebCore::InspectorMemoryAgent::willDestroyFrontendAndBackend):
+        * inspector/InspectorMemoryAgent.h:
+        * inspector/InspectorPageAgent.cpp:
+        (WebCore::InspectorPageAgent::didCreateFrontendAndBackend):
+        (WebCore::InspectorPageAgent::willDestroyFrontendAndBackend):
+        (WebCore::InspectorPageAgent::getScriptExecutionStatus):
+        * inspector/InspectorPageAgent.h:
+        * inspector/InspectorProfilerAgent.cpp:
+        (WebCore::InspectorProfilerAgent::didCreateFrontendAndBackend):
+        (WebCore::InspectorProfilerAgent::willDestroyFrontendAndBackend):
+        * inspector/InspectorProfilerAgent.h:
+        * inspector/InspectorResourceAgent.cpp:
+        (WebCore::InspectorResourceAgent::didCreateFrontendAndBackend):
+        (WebCore::InspectorResourceAgent::willDestroyFrontendAndBackend):
+        * inspector/InspectorResourceAgent.h:
+        * inspector/InspectorRuntimeAgent.h:
+        * inspector/InspectorTimelineAgent.cpp:
+        (WebCore::InspectorTimelineAgent::didCreateFrontendAndBackend):
+        (WebCore::InspectorTimelineAgent::willDestroyFrontendAndBackend):
+        * inspector/InspectorTimelineAgent.h:
+        * inspector/InspectorWorkerAgent.cpp:
+        (WebCore::InspectorWorkerAgent::didCreateFrontendAndBackend):
+        (WebCore::InspectorWorkerAgent::willDestroyFrontendAndBackend):
+        * inspector/InspectorWorkerAgent.h:
+        * inspector/PageRuntimeAgent.cpp:
+        (WebCore::PageRuntimeAgent::didCreateFrontendAndBackend):
+        (WebCore::PageRuntimeAgent::willDestroyFrontendAndBackend):
+        * inspector/PageRuntimeAgent.h:
+        * inspector/WorkerRuntimeAgent.cpp:
+        (WebCore::WorkerRuntimeAgent::didCreateFrontendAndBackend):
+        (WebCore::WorkerRuntimeAgent::willDestroyFrontendAndBackend):
+        * inspector/WorkerRuntimeAgent.h:
+
 2013-11-13  Andy Estes  <aestes@apple.com>
 
         Use NSCalendarIdentifierGregorian instead of NSGregorianCalendar on OS X 10.9 and iOS
index ec07951..91b93d2 100644 (file)
@@ -3769,6 +3769,8 @@ webcore_sources += \
        Source/WebCore/inspector/InspectorAgentRegistry.h \
        Source/WebCore/inspector/InspectorApplicationCacheAgent.cpp \
        Source/WebCore/inspector/InspectorApplicationCacheAgent.h \
+       Source/WebCore/inspector/InspectorBackendDispatcher.cpp \
+       Source/WebCore/inspector/InspectorBackendDispatcher.h \
        Source/WebCore/inspector/InspectorBaseAgent.h \
        Source/WebCore/inspector/InspectorCanvasAgent.cpp \
        Source/WebCore/inspector/InspectorCanvasAgent.h \
index 32a6513..1330bd8 100644 (file)
                A5732B0A136A161D005C8D7C /* DateComponents.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A5732B08136A161D005C8D7C /* DateComponents.cpp */; };
                A5732B0B136A161D005C8D7C /* DateComponents.h in Headers */ = {isa = PBXBuildFile; fileRef = A5732B09136A161D005C8D7C /* DateComponents.h */; };
                A5ABB78713B904BC00F197E3 /* LineBreakIteratorPoolICU.h in Headers */ = {isa = PBXBuildFile; fileRef = A5ABB78613B904BC00F197E3 /* LineBreakIteratorPoolICU.h */; };
+               A5AC4AEF18336975007114E0 /* InspectorBackendDispatcher.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A5AC4AED18336975007114E0 /* InspectorBackendDispatcher.cpp */; };
+               A5AC4AF018336975007114E0 /* InspectorBackendDispatcher.h in Headers */ = {isa = PBXBuildFile; fileRef = A5AC4AEE18336975007114E0 /* InspectorBackendDispatcher.h */; settings = {ATTRIBUTES = (Private, ); }; };
                A5AFB34F115151A700B045CB /* StepRange.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A5AFB34D115151A700B045CB /* StepRange.cpp */; };
                A5AFB350115151A700B045CB /* StepRange.h in Headers */ = {isa = PBXBuildFile; fileRef = A5AFB34E115151A700B045CB /* StepRange.h */; settings = {ATTRIBUTES = (Private, ); }; };
                A5C566AB127A3AAD00E8A3FF /* DiskImageCacheClientIOS.h in Headers */ = {isa = PBXBuildFile; fileRef = A5C566AA127A3AAD00E8A3FF /* DiskImageCacheClientIOS.h */; settings = {ATTRIBUTES = (Private, ); }; };
                A5732B08136A161D005C8D7C /* DateComponents.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DateComponents.cpp; sourceTree = "<group>"; };
                A5732B09136A161D005C8D7C /* DateComponents.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DateComponents.h; sourceTree = "<group>"; };
                A5ABB78613B904BC00F197E3 /* LineBreakIteratorPoolICU.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LineBreakIteratorPoolICU.h; sourceTree = "<group>"; };
+               A5AC4AED18336975007114E0 /* InspectorBackendDispatcher.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InspectorBackendDispatcher.cpp; sourceTree = "<group>"; };
+               A5AC4AEE18336975007114E0 /* InspectorBackendDispatcher.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorBackendDispatcher.h; sourceTree = "<group>"; };
                A5AFB34D115151A700B045CB /* StepRange.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StepRange.cpp; sourceTree = "<group>"; };
                A5AFB34E115151A700B045CB /* StepRange.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StepRange.h; sourceTree = "<group>"; };
                A5C566AA127A3AAD00E8A3FF /* DiskImageCacheClientIOS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DiskImageCacheClientIOS.h; sourceTree = "<group>"; };
                                A556C287183206A8008CB720 /* InspectorAgentRegistry.h */,
                                B885E8D211E06DD2009FFBF4 /* InspectorApplicationCacheAgent.cpp */,
                                B885E8D311E06DD2009FFBF4 /* InspectorApplicationCacheAgent.h */,
+                               A5AC4AED18336975007114E0 /* InspectorBackendDispatcher.cpp */,
+                               A5AC4AEE18336975007114E0 /* InspectorBackendDispatcher.h */,
                                7AA51B6C1483B61600AD2752 /* InspectorBaseAgent.h */,
                                AAD766E8157E502F00E85423 /* InspectorCanvasAgent.cpp */,
                                AAD766E9157E502F00E85423 /* InspectorCanvasAgent.h */,
                                A80E6D010A1989CA007FB8C5 /* CSSInheritedValue.h in Headers */,
                                A80E6D080A1989CA007FB8C5 /* CSSInitialValue.h in Headers */,
                                BC772E131331620C001EC9CE /* CSSLineBoxContainValue.h in Headers */,
+                               A5AC4AF018336975007114E0 /* InspectorBackendDispatcher.h in Headers */,
                                A80E6D030A1989CA007FB8C5 /* CSSMediaRule.h in Headers */,
                                F98FFF4511A2676200F548E8 /* CSSOMUtils.h in Headers */,
                                A80E6D000A1989CA007FB8C5 /* CSSPageRule.h in Headers */,
                                59B597731108656B007159E8 /* BridgeJSC.cpp in Sources */,
                                F55B3DAF1251F12D003EF269 /* ButtonInputType.cpp in Sources */,
                                1A569CF70D7E2B82007C3983 /* c_class.cpp in Sources */,
+                               A5AC4AEF18336975007114E0 /* InspectorBackendDispatcher.cpp in Sources */,
                                1A569CF90D7E2B82007C3983 /* c_instance.cpp in Sources */,
                                1A569CFB0D7E2B82007C3983 /* c_runtime.cpp in Sources */,
                                1A569CFD0D7E2B82007C3983 /* c_utility.cpp in Sources */,
index 2c3929c..ea43101 100755 (executable)
@@ -190,7 +190,6 @@ class DomainNameFixes:
 
         class Res(object):
             skip_js_bind = domain_name in cls.skip_js_bind_domains
-            agent_field_name = field_name_res
 
             @staticmethod
             def get_guard():
@@ -959,7 +958,7 @@ class TypeBindings:
 
                                 writer.newline("}; // struct ")
                                 writer.append(enum_name)
-                                writer.append("\n\n")
+                                writer.append("\n")
 
                             @staticmethod
                             def register_use(forward_listener):
@@ -1245,7 +1244,7 @@ class TypeBindings:
                                     writer.append_multiline("\n    void %s" % setter_name)
                                     writer.append("(%s value)\n" % param_type_binding.get_type_model().get_input_param_type_text())
                                     writer.newline("    {\n")
-                                    writer.newline("        this->set%s(\"%s\", %s);\n"
+                                    writer.newline("        this->set%s(ASCIILiteral(\"%s\"), %s);\n"
                                         % (param_type_binding.reduce_to_raw_type().get_setter_name(), prop_data.p["name"],
                                            format_setter_value_expression(param_type_binding, "value")))
                                     writer.newline("    }\n")
@@ -1730,6 +1729,8 @@ class Templates:
 """)
 
     frontend_domain_class = string.Template(CodeGeneratorInspectorStrings.frontend_domain_class)
+    backend_dispatcher_constructor = string.Template(CodeGeneratorInspectorStrings.backend_dispatcher_constructor)
+    backend_dispatcher_dispatch_method = string.Template(CodeGeneratorInspectorStrings.backend_dispatcher_dispatch_method)
     backend_method = string.Template(CodeGeneratorInspectorStrings.backend_method)
     frontend_method = string.Template(CodeGeneratorInspectorStrings.frontend_method)
     callback_method = string.Template(CodeGeneratorInspectorStrings.callback_method)
@@ -1823,19 +1824,12 @@ def format_setter_value_expression(param_type_binding, value_ref):
 class Generator:
     frontend_domain_class_lines = []
 
-    method_name_enum_list = []
-    backend_method_declaration_list = []
     backend_method_implementation_list = []
-    backend_method_name_declaration_list = []
-    method_handler_list = []
     frontend_method_list = []
     backend_js_domain_initializer_list = []
 
-    backend_virtual_setters_list = []
-    backend_agent_interface_list = []
-    backend_setters_list = []
-    backend_constructor_init_list = []
-    backend_field_list = []
+    backend_handler_interface_list = []
+    backend_dispatcher_interface_list = []
     type_builder_fragments = []
     type_builder_forwards = []
     validator_impl_list = []
@@ -1847,16 +1841,9 @@ class Generator:
         Generator.process_types(type_map)
 
         first_cycle_guardable_list_list = [
-            Generator.backend_method_declaration_list,
             Generator.backend_method_implementation_list,
-            Generator.backend_method_name_declaration_list,
-            Generator.backend_agent_interface_list,
-            Generator.method_handler_list,
-            Generator.method_name_enum_list,
-            Generator.backend_constructor_init_list,
-            Generator.backend_virtual_setters_list,
-            Generator.backend_setters_list,
-            Generator.backend_field_list]
+            Generator.backend_handler_interface_list,
+            Generator.backend_dispatcher_interface_list]
 
         for json_domain in json_api["domains"]:
             domain_name = json_domain["domain"]
@@ -1870,8 +1857,6 @@ class Generator:
                 for l in first_cycle_guardable_list_list:
                     domain_guard.generate_open(l)
 
-            agent_field_name = domain_fixes.agent_field_name
-
             frontend_method_declaration_lines = []
 
             Generator.backend_js_domain_initializer_list.append("// %s.\n" % domain_name)
@@ -1907,20 +1892,43 @@ class Generator:
                     domain_guard.generate_close(Generator.frontend_method_list)
                     domain_guard.generate_close(Generator.frontend_domain_class_lines)
 
-            agent_interface_name = Capitalizer.lower_camel_case_to_upper(domain_name) + "CommandHandler"
-            Generator.backend_agent_interface_list.append("    class %s {\n" % agent_interface_name)
-            Generator.backend_agent_interface_list.append("    public:\n")
+            dispatcher_name = "Inspector" + Capitalizer.lower_camel_case_to_upper(domain_name) + "BackendDispatcher"
+            agent_interface_name = dispatcher_name + "Handler"
+
+            Generator.backend_dispatcher_interface_list.append("class %s FINAL : public InspectorSupplementalBackendDispatcher {\n" % dispatcher_name)
+            Generator.backend_dispatcher_interface_list.append("public:\n")
+            Generator.backend_dispatcher_interface_list.append("    static PassRefPtr<%s> create(InspectorBackendDispatcher*, %s*);\n" % (dispatcher_name, agent_interface_name))
+            Generator.backend_dispatcher_interface_list.append("    virtual void dispatch(long callId, const String& method, PassRefPtr<InspectorObject> message) OVERRIDE;\n")
+            Generator.backend_dispatcher_interface_list.append("private:\n")
+
+            Generator.backend_handler_interface_list.append("class %s {\n" % agent_interface_name)
+            Generator.backend_handler_interface_list.append("public:\n")
+
+            backend_method_count = len(Generator.backend_method_implementation_list)
+
+            dispatcher_commands_list = []
             if "commands" in json_domain:
                 for json_command in json_domain["commands"]:
-                    Generator.process_command(json_command, domain_name, agent_field_name, agent_interface_name)
-            Generator.backend_agent_interface_list.append("\n    protected:\n")
-            Generator.backend_agent_interface_list.append("        virtual ~%s() { }\n" % agent_interface_name)
-            Generator.backend_agent_interface_list.append("    };\n\n")
+                    Generator.process_command(json_command, domain_name, agent_interface_name, dispatcher_name, dispatcher_commands_list)
+
+            Generator.backend_handler_interface_list.append("protected:\n")
+            Generator.backend_handler_interface_list.append("    virtual ~%s() { }\n" % agent_interface_name)
+            Generator.backend_handler_interface_list.append("};\n\n")
 
-            Generator.backend_constructor_init_list.append("        , m_%s(0)" % agent_field_name)
-            Generator.backend_virtual_setters_list.append("    virtual void registerAgent(%s* %s) = 0;" % (agent_interface_name, agent_field_name))
-            Generator.backend_setters_list.append("    virtual void registerAgent(%s* %s) { ASSERT(!m_%s); m_%s = %s; }" % (agent_interface_name, agent_field_name, agent_field_name, agent_field_name, agent_field_name))
-            Generator.backend_field_list.append("    %s* m_%s;" % (agent_interface_name, agent_field_name))
+            Generator.backend_dispatcher_interface_list.append("private:\n")
+            Generator.backend_dispatcher_interface_list.append("    %s(InspectorBackendDispatcher*, %s*);\n" % (dispatcher_name, agent_interface_name))
+            Generator.backend_dispatcher_interface_list.append("    %s* m_agent;\n" % agent_interface_name)
+            Generator.backend_dispatcher_interface_list.append("};\n\n")
+
+            Generator.backend_method_implementation_list.insert(backend_method_count, Templates.backend_dispatcher_constructor.substitute(None,
+                domainName=domain_name,
+                dispatcherName=dispatcher_name,
+                agentName=agent_interface_name))
+
+            Generator.backend_method_implementation_list.insert(backend_method_count + 1, Templates.backend_dispatcher_dispatch_method.substitute(None,
+                domainName=domain_name,
+                dispatcherName=dispatcher_name,
+                dispatcherCommands="\n".join(dispatcher_commands_list)))
 
             if domain_guard:
                 for l in reversed(first_cycle_guardable_list_list):
@@ -1976,20 +1984,18 @@ class Generator:
         container_name = "paramsObject"
 
     @staticmethod
-    def process_command(json_command, domain_name, agent_field_name, agent_interface_name):
+    def process_command(json_command, domain_name, agent_interface_name, dispatcher_name, dispatcher_commands_list):
         json_command_name = json_command["name"]
 
-        cmd_enum_name = "k%s_%sCmd" % (domain_name, json_command["name"])
+        ad_hoc_type_output = []
+        Generator.backend_handler_interface_list.append(ad_hoc_type_output)
+        ad_hoc_type_writer = Writer(ad_hoc_type_output, "    ")
 
-        Generator.method_name_enum_list.append("        %s," % cmd_enum_name)
-        Generator.method_handler_list.append("            &InspectorBackendDispatcherImpl::%s_%s," % (domain_name, json_command_name))
-        Generator.backend_method_declaration_list.append("    void %s_%s(long callId, InspectorObject* requestMessageObject);" % (domain_name, json_command_name))
+        Generator.backend_dispatcher_interface_list.append("    void %s(long callId, const InspectorObject& message);\n" % json_command_name)
 
-        ad_hoc_type_output = []
-        Generator.backend_agent_interface_list.append(ad_hoc_type_output)
-        ad_hoc_type_writer = Writer(ad_hoc_type_output, "        ")
+        Generator.backend_handler_interface_list.append("    virtual void %s(ErrorString*" % json_command_name)
 
-        Generator.backend_agent_interface_list.append("        virtual void %s(ErrorString*" % json_command_name)
+        dispatcher_commands_list.append("            { \"%s\",  &%s::%s }," % (json_command_name, dispatcher_name, json_command_name))
 
         method_in_code = ""
         method_out_code = ""
@@ -2000,7 +2006,7 @@ class Generator:
         if "parameters" in json_command:
             json_params = json_command["parameters"]
             method_in_code += Templates.param_container_access_code
-            request_message_param = " requestMessageObject"
+            request_message_param = " message"
             js_param_list = []
 
             for json_parameter in json_params:
@@ -2019,13 +2025,13 @@ class Generator:
 
                 if optional:
                     code = ("    bool %s_valueFound = false;\n"
-                            "    %s in_%s = get%s(paramsContainerPtr, \"%s\", &%s_valueFound, protocolErrorsPtr);\n" %
+                            "    %s in_%s = InspectorBackendDispatcher::get%s(paramsContainerPtr, ASCIILiteral(\"%s\"), &%s_valueFound, protocolErrorsPtr);\n" %
                            (json_param_name, non_optional_type_model.get_command_return_pass_model().get_return_var_type(), json_param_name, getter_name, json_param_name, json_param_name))
                     param = ", %s_valueFound ? &in_%s : 0" % (json_param_name, json_param_name)
                     # FIXME: pass optional refptr-values as PassRefPtr
                     formal_param_type_pattern = "const %s*"
                 else:
-                    code = ("    %s in_%s = get%s(paramsContainerPtr, \"%s\", 0, protocolErrorsPtr);\n" %
+                    code = ("    %s in_%s = InspectorBackendDispatcher::get%s(paramsContainerPtr, ASCIILiteral(\"%s\"), nullptr, protocolErrorsPtr);\n" %
                             (non_optional_type_model.get_command_return_pass_model().get_return_var_type(), json_param_name, getter_name, json_param_name))
                     param = ", in_%s" % json_param_name
                     # FIXME: pass not-optional refptr-values as NonNullPassRefPtr
@@ -2036,7 +2042,7 @@ class Generator:
 
                 method_in_code += code
                 agent_call_param_list.append(param)
-                Generator.backend_agent_interface_list.append(", %s in_%s" % (formal_param_type_pattern % non_optional_type_model.get_command_return_pass_model().get_return_var_type(), json_param_name))
+                Generator.backend_handler_interface_list.append(", %s in_%s" % (formal_param_type_pattern % non_optional_type_model.get_command_return_pass_model().get_return_var_type(), json_param_name))
 
                 js_bind_type = param_raw_type.get_js_bind_type()
                 js_param_text = "{\"name\": \"%s\", \"type\": \"%s\", \"optional\": %s}" % (
@@ -2060,22 +2066,22 @@ class Generator:
                                            decl_parameter_list,
                                            Generator.CallbackMethodStructTemplate,
                                            Generator.backend_method_implementation_list, Templates.callback_method,
-                                           {"callbackName": callback_name, "agentName": agent_interface_name})
+                                           {"callbackName": callback_name, "handlerName": agent_interface_name})
 
-            callback_writer.newline("class " + callback_name + " : public CallbackBase {\n")
+            callback_writer.newline("class " + callback_name + " : public InspectorBackendDispatcher::CallbackBase {\n")
             callback_writer.newline("public:\n")
-            callback_writer.newline("    " + callback_name + "(PassRefPtr<InspectorBackendDispatcherImpl>, int id);\n")
+            callback_writer.newline("    " + callback_name + "(PassRefPtr<InspectorBackendDispatcher>, int id);\n")
             callback_writer.newline("    void sendSuccess(" + ", ".join(decl_parameter_list) + ");\n")
             callback_writer.newline("};\n")
 
             ad_hoc_type_output.append(callback_output)
 
-            method_out_code += "    RefPtr<" + agent_interface_name + "::" + callback_name + "> callback = adoptRef(new " + agent_interface_name + "::" + callback_name + "(this, callId));\n"
+            method_out_code += "    RefPtr<" + agent_interface_name + "::" + callback_name + "> callback = adoptRef(new " + agent_interface_name + "::" + callback_name + "(m_backendDispatcher, callId));\n"
             agent_call_param_list.append(", callback")
-            response_cook_text += "        if (!error.length()) \n"
+            response_cook_text += "        if (!error.length())\n"
             response_cook_text += "            return;\n"
             response_cook_text += "        callback->disable();\n"
-            Generator.backend_agent_interface_list.append(", PassRefPtr<%s> callback" % callback_name)
+            Generator.backend_handler_interface_list.append(", PassRefPtr<%s> callback" % callback_name)
         else:
             if "returns" in json_command:
                 method_out_code += "\n"
@@ -2102,7 +2108,7 @@ class Generator:
                     if return_type_binding.get_setter_value_expression_pattern():
                         setter_argument = return_type_binding.get_setter_value_expression_pattern() % setter_argument
 
-                    cook = "            result->set%s(\"%s\", %s);\n" % (setter_type, json_return_name,
+                    cook = "            result->set%s(ASCIILiteral(\"%s\"), %s);\n" % (setter_type, json_return_name,
                                                                          setter_argument)
 
                     set_condition_pattern = type_model.get_command_return_pass_model().get_set_return_condition()
@@ -2114,7 +2120,7 @@ class Generator:
                     if optional:
                         param_name = "opt_" + param_name
 
-                    Generator.backend_agent_interface_list.append(", %s %s" % (annotated_type, param_name))
+                    Generator.backend_handler_interface_list.append(", %s %s" % (annotated_type, param_name))
                     response_cook_list.append(cook)
 
                     method_out_code += code
@@ -2134,18 +2140,16 @@ class Generator:
         js_reply_list = "[%s]" % ", ".join(backend_js_reply_param_list)
 
         Generator.backend_method_implementation_list.append(Templates.backend_method.substitute(None,
-            domainName=domain_name, methodName=json_command_name,
-            agentField="m_" + agent_field_name,
+            dispatcherName=dispatcher_name,
+            methodName=json_command_name,
             methodInCode=method_in_code,
             methodOutCode=method_out_code,
             agentCallParams="".join(agent_call_param_list),
             requestMessageObject=request_message_param,
-            responseCook=response_cook_text,
-            commandNameIndex=cmd_enum_name))
-        Generator.backend_method_name_declaration_list.append("    \"%s.%s\"," % (domain_name, json_command_name))
+            responseCook=response_cook_text))
 
         Generator.backend_js_domain_initializer_list.append("InspectorBackend.registerCommand(\"%s.%s\", [%s], %s);\n" % (domain_name, json_command_name, js_parameters_text, js_reply_list))
-        Generator.backend_agent_interface_list.append(") = 0;\n")
+        Generator.backend_handler_interface_list.append(") = 0;\n")
 
     class CallbackMethodStructTemplate:
         @staticmethod
@@ -2193,7 +2197,7 @@ class Generator:
                 if mode_type_binding.get_setter_value_expression_pattern():
                     setter_argument = mode_type_binding.get_setter_value_expression_pattern() % setter_argument
 
-                setter_code = "    %s->set%s(\"%s\", %s);\n" % (method_struct_template.container_name, setter_type, parameter_name, setter_argument)
+                setter_code = "    %s->set%s(ASCIILiteral(\"%s\"), %s);\n" % (method_struct_template.container_name, setter_type, parameter_name, setter_argument)
                 if optional:
                     setter_code = ("    if (%s)\n    " % parameter_name) + setter_code
                 method_line_list.append(setter_code)
@@ -2375,18 +2379,11 @@ backend_js_file = SmartOutput(output_js_dirname + "/InspectorBackendCommands.js"
 
 
 backend_h_file.write(Templates.backend_h.substitute(None,
-    virtualSetters="\n".join(Generator.backend_virtual_setters_list),
-    agentInterfaces="".join(flatten_list(Generator.backend_agent_interface_list)),
-    methodNamesEnumContent="\n".join(Generator.method_name_enum_list)))
+    handlerInterfaces="".join(flatten_list(Generator.backend_handler_interface_list)),
+    dispatcherInterfaces="".join(flatten_list(Generator.backend_dispatcher_interface_list))))
 
 backend_cpp_file.write(Templates.backend_cpp.substitute(None,
-    constructorInit="\n".join(Generator.backend_constructor_init_list),
-    setters="\n".join(Generator.backend_setters_list),
-    fieldDeclarations="\n".join(Generator.backend_field_list),
-    methodNameDeclarations="\n".join(Generator.backend_method_name_declaration_list),
-    methods="\n".join(Generator.backend_method_implementation_list),
-    methodDeclarations="\n".join(Generator.backend_method_declaration_list),
-    messageHandlers="\n".join(Generator.method_handler_list)))
+    methods="\n".join(Generator.backend_method_implementation_list)))
 
 frontend_h_file.write(Templates.frontend_h.substitute(None,
     domainClassList="".join(Generator.frontend_domain_class_lines)))
@@ -2418,3 +2415,14 @@ typebuilder_h_file.close()
 typebuilder_cpp_file.close()
 
 backend_js_file.close()
+
+# FIXME: This exists to remove some old generated files that can cause build issues if
+# a compiler includes the old files instead of the new files with the same name. This
+# can be removed after a week or so once bots and developers have built with this.
+# Otherwise, developers can always just do a clean build or remove their DerivedSources.
+old_backend_h_file = os.path.join(output_header_dirname, "InspectorBackendDispatcher.h")
+old_backend_cpp_file = os.path.join(output_header_dirname, "InspectorBackendDispatcher.cpp")
+if os.path.exists(old_backend_h_file):
+    os.remove(old_backend_h_file)
+if os.path.exists(old_backend_cpp_file):
+    os.remove(old_backend_cpp_file)
index 8f7d04c..3cdc517 100644 (file)
@@ -39,23 +39,63 @@ ${frontendDomainMethodDeclarations}private:
 
 """)
 
+backend_dispatcher_constructor = (
+"""PassRefPtr<${dispatcherName}> ${dispatcherName}::create(InspectorBackendDispatcher* backendDispatcher, ${agentName}* agent)
+{
+    return adoptRef(new ${dispatcherName}(backendDispatcher, agent));
+}
+
+${dispatcherName}::${dispatcherName}(InspectorBackendDispatcher* backendDispatcher, ${agentName}* agent)
+    : InspectorSupplementalBackendDispatcher(backendDispatcher)
+    , m_agent(agent)
+{
+    m_backendDispatcher->registerDispatcherForDomain(ASCIILiteral("${domainName}"), this);
+}
+""")
+
+backend_dispatcher_dispatch_method = (
+"""void ${dispatcherName}::dispatch(long callId, const String& method, PassRefPtr<InspectorObject> message)
+{
+    Ref<${dispatcherName}> protect(*this);
+
+    typedef void (${dispatcherName}::*CallHandler)(long callId, const InspectorObject& message);
+    typedef HashMap<String, CallHandler> DispatchMap;
+    DEFINE_STATIC_LOCAL(DispatchMap, dispatchMap, ());
+    if (dispatchMap.isEmpty()) {
+        static const struct MethodTable {
+            const char* name;
+            CallHandler handler;
+        } commands[] = {
+${dispatcherCommands}
+        };
+        size_t length = WTF_ARRAY_LENGTH(commands);
+        for (size_t i = 0; i < length; ++i)
+            dispatchMap.add(commands[i].name, commands[i].handler);
+    }
+
+    HashMap<String, CallHandler>::iterator it = dispatchMap.find(method);
+    if (it == dispatchMap.end()) {
+        m_backendDispatcher->reportProtocolError(&callId, InspectorBackendDispatcher::MethodNotFound, String("'") + "${domainName}" + '.' + method + "' was not found");
+        return;
+    }
+
+    ((*this).*it->value)(callId, *message.get());
+}
+""")
+
 backend_method = (
-"""void InspectorBackendDispatcherImpl::${domainName}_$methodName(long callId, InspectorObject*$requestMessageObject)
+"""void ${dispatcherName}::${methodName}(long callId, const InspectorObject&${requestMessageObject})
 {
     RefPtr<InspectorArray> protocolErrors = InspectorArray::create();
-
-    if (!$agentField)
-        protocolErrors->pushString("${domainName} handler is not available.");
-$methodOutCode
-$methodInCode
+${methodOutCode}${methodInCode}
     RefPtr<InspectorObject> result = InspectorObject::create();
     ErrorString error;
     if (!protocolErrors->length()) {
-        $agentField->$methodName(&error$agentCallParams);
+        m_agent->${methodName}(&error${agentCallParams});
 
 ${responseCook}
     }
-    sendResponse(callId, result.release(), commandNames[$commandNameIndex], protocolErrors.release(), error);
+    m_backendDispatcher->sendResponse(callId, result.release(), protocolErrors.release(), error);
 }
 """)
 
@@ -69,12 +109,12 @@ $code
 """)
 
 callback_method = (
-"""InspectorBackendDispatcher::$agentName::$callbackName::$callbackName(PassRefPtr<InspectorBackendDispatcherImpl> backendImpl, int id) : CallbackBase(backendImpl, id) {}
+"""${handlerName}::${callbackName}::${callbackName}(PassRefPtr<InspectorBackendDispatcher> backendDispatcher, int id) : InspectorBackendDispatcher::CallbackBase(backendDispatcher, id) { }
 
-void InspectorBackendDispatcher::$agentName::$callbackName::sendSuccess($parameters)
+void ${handlerName}::${callbackName}::sendSuccess(${parameters})
 {
     RefPtr<InspectorObject> jsonMessage = InspectorObject::create();
-$code    sendIfActive(jsonMessage, ErrorString());
+${code}    sendIfActive(jsonMessage, ErrorString());
 }
 """)
 
@@ -106,84 +146,28 @@ backend_h = (
 """#ifndef InspectorBackendDispatchers_h
 #define InspectorBackendDispatchers_h
 
+#include "InspectorBackendDispatcher.h"
+#include "InspectorTypeBuilder.h"
 #include <wtf/PassRefPtr.h>
-#include <wtf/RefCounted.h>
 #include <wtf/text/WTFString.h>
-#include "InspectorTypeBuilder.h"
 
 namespace WebCore {
 
-class InspectorAgent;
 class InspectorObject;
 class InspectorArray;
-class InspectorFrontendChannel;
 
 typedef String ErrorString;
 
-class InspectorBackendDispatcherImpl;
-
-class InspectorBackendDispatcher: public RefCounted<InspectorBackendDispatcher> {
-public:
-    static PassRefPtr<InspectorBackendDispatcher> create(InspectorFrontendChannel* inspectorFrontendChannel);
-    virtual ~InspectorBackendDispatcher() { }
-
-    class CallbackBase: public RefCounted<CallbackBase> {
-    public:
-        CallbackBase(PassRefPtr<InspectorBackendDispatcherImpl> backendImpl, int id);
-        virtual ~CallbackBase();
-        void sendFailure(const ErrorString&);
-        bool isActive();
-
-    protected:
-        void sendIfActive(PassRefPtr<InspectorObject> partialMessage, const ErrorString& invocationError);
-
-    private:
-        void disable() { m_alreadySent = true; }
-
-        RefPtr<InspectorBackendDispatcherImpl> m_backendImpl;
-        int m_id;
-        bool m_alreadySent;
-
-        friend class InspectorBackendDispatcherImpl;
-    };
-
-$agentInterfaces
-$virtualSetters
-
-    virtual void clearFrontend() = 0;
-
-    enum CommonErrorCode {
-        ParseError = 0,
-        InvalidRequest,
-        MethodNotFound,
-        InvalidParams,
-        InternalError,
-        ServerError,
-        LastEntry,
-    };
-
-    void reportProtocolError(const long* const callId, CommonErrorCode, const String& errorMessage) const;
-    virtual void reportProtocolError(const long* const callId, CommonErrorCode, const String& errorMessage, PassRefPtr<InspectorArray> data) const = 0;
-    virtual void dispatch(const String& message) = 0;
-
-    enum MethodNames {
-$methodNamesEnumContent
-
-        kMethodNamesEnumSize
-    };
-
-    static const char* commandNames[];
-};
+$handlerInterfaces
 
+$dispatcherInterfaces
 } // namespace WebCore
-#endif // !defined(InspectorBackendDispatchers_h)
-
 
+#endif // !defined(InspectorBackendDispatchers_h)
 """)
 
 backend_cpp = (
 """
-
 #include "config.h"
 
 #if ENABLE(INSPECTOR)
@@ -198,275 +182,7 @@ backend_cpp = (
 
 namespace WebCore {
 
-const char* InspectorBackendDispatcher::commandNames[] = {
-$methodNameDeclarations
-};
-
-
-class InspectorBackendDispatcherImpl : public InspectorBackendDispatcher {
-public:
-    InspectorBackendDispatcherImpl(InspectorFrontendChannel* inspectorFrontendChannel)
-        : m_inspectorFrontendChannel(inspectorFrontendChannel)
-$constructorInit
-    { }
-
-    virtual void clearFrontend() { m_inspectorFrontendChannel = 0; }
-    virtual void dispatch(const String& message);
-    virtual void reportProtocolError(const long* const callId, CommonErrorCode, const String& errorMessage, PassRefPtr<InspectorArray> data) const;
-    using InspectorBackendDispatcher::reportProtocolError;
-
-    void sendResponse(long callId, PassRefPtr<InspectorObject> result, const ErrorString& invocationError);
-    bool isActive() { return m_inspectorFrontendChannel; }
-
-$setters
-private:
-$methodDeclarations
-
-    InspectorFrontendChannel* m_inspectorFrontendChannel;
-$fieldDeclarations
-
-    template<typename R, typename V, typename V0>
-    static R getPropertyValueImpl(InspectorObject* object, const String& name, bool* valueFound, InspectorArray* protocolErrors, V0 initial_value, bool (*as_method)(InspectorValue*, V*), const char* type_name);
-
-    static int getInt(InspectorObject* object, const String& name, bool* valueFound, InspectorArray* protocolErrors);
-    static double getDouble(InspectorObject* object, const String& name, bool* valueFound, InspectorArray* protocolErrors);
-    static String getString(InspectorObject* object, const String& name, bool* valueFound, InspectorArray* protocolErrors);
-    static bool getBoolean(InspectorObject* object, const String& name, bool* valueFound, InspectorArray* protocolErrors);
-    static PassRefPtr<InspectorObject> getObject(InspectorObject* object, const String& name, bool* valueFound, InspectorArray* protocolErrors);
-    static PassRefPtr<InspectorArray> getArray(InspectorObject* object, const String& name, bool* valueFound, InspectorArray* protocolErrors);
-
-    void sendResponse(long callId, PassRefPtr<InspectorObject> result, const char* commandName, PassRefPtr<InspectorArray> protocolErrors, ErrorString invocationError);
-
-};
-
 $methods
-
-PassRefPtr<InspectorBackendDispatcher> InspectorBackendDispatcher::create(InspectorFrontendChannel* inspectorFrontendChannel)
-{
-    return adoptRef(new InspectorBackendDispatcherImpl(inspectorFrontendChannel));
-}
-
-
-void InspectorBackendDispatcherImpl::dispatch(const String& message)
-{
-    Ref<InspectorBackendDispatcher> protect(*this);
-    typedef void (InspectorBackendDispatcherImpl::*CallHandler)(long callId, InspectorObject* messageObject);
-    typedef HashMap<String, CallHandler> DispatchMap;
-    DEFINE_STATIC_LOCAL(DispatchMap, dispatchMap, );
-    long callId = 0;
-
-    if (dispatchMap.isEmpty()) {
-        static CallHandler handlers[] = {
-$messageHandlers
-        };
-        size_t length = WTF_ARRAY_LENGTH(commandNames);
-        for (size_t i = 0; i < length; ++i)
-            dispatchMap.add(commandNames[i], handlers[i]);
-    }
-
-    RefPtr<InspectorValue> parsedMessage = InspectorValue::parseJSON(message);
-    if (!parsedMessage) {
-        reportProtocolError(0, ParseError, "Message must be in JSON format");
-        return;
-    }
-
-    RefPtr<InspectorObject> messageObject = parsedMessage->asObject();
-    if (!messageObject) {
-        reportProtocolError(0, InvalidRequest, "Message must be a JSONified object");
-        return;
-    }
-
-    RefPtr<InspectorValue> callIdValue = messageObject->get("id");
-    if (!callIdValue) {
-        reportProtocolError(0, InvalidRequest, "'id' property was not found");
-        return;
-    }
-
-    if (!callIdValue->asNumber(&callId)) {
-        reportProtocolError(0, InvalidRequest, "The type of 'id' property must be number");
-        return;
-    }
-
-    RefPtr<InspectorValue> methodValue = messageObject->get("method");
-    if (!methodValue) {
-        reportProtocolError(&callId, InvalidRequest, "'method' property wasn't found");
-        return;
-    }
-
-    String method;
-    if (!methodValue->asString(&method)) {
-        reportProtocolError(&callId, InvalidRequest, "The type of 'method' property must be string");
-        return;
-    }
-
-    HashMap<String, CallHandler>::iterator it = dispatchMap.find(method);
-    if (it == dispatchMap.end()) {
-        reportProtocolError(&callId, MethodNotFound, "'" + method + "' wasn't found");
-        return;
-    }
-
-    ((*this).*it->value)(callId, messageObject.get());
-}
-
-void InspectorBackendDispatcherImpl::sendResponse(long callId, PassRefPtr<InspectorObject> result, const char* commandName, PassRefPtr<InspectorArray> protocolErrors, ErrorString invocationError)
-{
-    if (protocolErrors->length()) {
-        String errorMessage = String::format("Some arguments of method '%s' can't be processed", commandName);
-        reportProtocolError(&callId, InvalidParams, errorMessage, protocolErrors);
-        return;
-    }
-    sendResponse(callId, result, invocationError);
-}
-
-void InspectorBackendDispatcherImpl::sendResponse(long callId, PassRefPtr<InspectorObject> result, const ErrorString& invocationError)
-{
-    if (invocationError.length()) {
-        reportProtocolError(&callId, ServerError, invocationError);
-        return;
-    }
-
-    RefPtr<InspectorObject> responseMessage = InspectorObject::create();
-    responseMessage->setObject("result", result);
-    responseMessage->setNumber("id", callId);
-    if (m_inspectorFrontendChannel)
-        m_inspectorFrontendChannel->sendMessageToFrontend(responseMessage->toJSONString());
-}
-
-void InspectorBackendDispatcher::reportProtocolError(const long* const callId, CommonErrorCode code, const String& errorMessage) const
-{
-    reportProtocolError(callId, code, errorMessage, 0);
-}
-
-void InspectorBackendDispatcherImpl::reportProtocolError(const long* const callId, CommonErrorCode code, const String& errorMessage, PassRefPtr<InspectorArray> data) const
-{
-    DEFINE_STATIC_LOCAL(Vector<int>,s_commonErrors,);
-    if (!s_commonErrors.size()) {
-        s_commonErrors.insert(ParseError, -32700);
-        s_commonErrors.insert(InvalidRequest, -32600);
-        s_commonErrors.insert(MethodNotFound, -32601);
-        s_commonErrors.insert(InvalidParams, -32602);
-        s_commonErrors.insert(InternalError, -32603);
-        s_commonErrors.insert(ServerError, -32000);
-    }
-    ASSERT(code >=0);
-    ASSERT((unsigned)code < s_commonErrors.size());
-    ASSERT(s_commonErrors[code]);
-    RefPtr<InspectorObject> error = InspectorObject::create();
-    error->setNumber("code", s_commonErrors[code]);
-    error->setString("message", errorMessage);
-    ASSERT(error);
-    if (data)
-        error->setArray("data", data);
-    RefPtr<InspectorObject> message = InspectorObject::create();
-    message->setObject("error", error.release());
-    if (callId)
-        message->setNumber("id", *callId);
-    else
-        message->setValue("id", InspectorValue::null());
-    if (m_inspectorFrontendChannel)
-        m_inspectorFrontendChannel->sendMessageToFrontend(message->toJSONString());
-}
-
-template<typename R, typename V, typename V0>
-R InspectorBackendDispatcherImpl::getPropertyValueImpl(InspectorObject* object, const String& name, bool* valueFound, InspectorArray* protocolErrors, V0 initial_value, bool (*as_method)(InspectorValue*, V*), const char* type_name)
-{
-    ASSERT(protocolErrors);
-
-    if (valueFound)
-        *valueFound = false;
-
-    V value = initial_value;
-
-    if (!object) {
-        if (!valueFound) {
-            // Required parameter in missing params container.
-            protocolErrors->pushString(String::format("'params' object must contain required parameter '%s' with type '%s'.", name.utf8().data(), type_name));
-        }
-        return value;
-    }
-
-    InspectorObject::const_iterator end = object->end();
-    InspectorObject::const_iterator valueIterator = object->find(name);
-
-    if (valueIterator == end) {
-        if (!valueFound)
-            protocolErrors->pushString(String::format("Parameter '%s' with type '%s' was not found.", name.utf8().data(), type_name));
-        return value;
-    }
-
-    if (!as_method(valueIterator->value.get(), &value))
-        protocolErrors->pushString(String::format("Parameter '%s' has wrong type. It must be '%s'.", name.utf8().data(), type_name));
-    else
-        if (valueFound)
-            *valueFound = true;
-    return value;
-}
-
-struct AsMethodBridges {
-    static bool asInt(InspectorValue* value, int* output) { return value->asNumber(output); }
-    static bool asDouble(InspectorValue* value, double* output) { return value->asNumber(output); }
-    static bool asString(InspectorValue* value, String* output) { return value->asString(output); }
-    static bool asBoolean(InspectorValue* value, bool* output) { return value->asBoolean(output); }
-    static bool asObject(InspectorValue* value, RefPtr<InspectorObject>* output) { return value->asObject(output); }
-    static bool asArray(InspectorValue* value, RefPtr<InspectorArray>* output) { return value->asArray(output); }
-};
-
-int InspectorBackendDispatcherImpl::getInt(InspectorObject* object, const String& name, bool* valueFound, InspectorArray* protocolErrors)
-{
-    return getPropertyValueImpl<int, int, int>(object, name, valueFound, protocolErrors, 0, AsMethodBridges::asInt, "Number");
-}
-
-double InspectorBackendDispatcherImpl::getDouble(InspectorObject* object, const String& name, bool* valueFound, InspectorArray* protocolErrors)
-{
-    return getPropertyValueImpl<double, double, double>(object, name, valueFound, protocolErrors, 0, AsMethodBridges::asDouble, "Number");
-}
-
-String InspectorBackendDispatcherImpl::getString(InspectorObject* object, const String& name, bool* valueFound, InspectorArray* protocolErrors)
-{
-    return getPropertyValueImpl<String, String, String>(object, name, valueFound, protocolErrors, "", AsMethodBridges::asString, "String");
-}
-
-bool InspectorBackendDispatcherImpl::getBoolean(InspectorObject* object, const String& name, bool* valueFound, InspectorArray* protocolErrors)
-{
-    return getPropertyValueImpl<bool, bool, bool>(object, name, valueFound, protocolErrors, false, AsMethodBridges::asBoolean, "Boolean");
-}
-
-PassRefPtr<InspectorObject> InspectorBackendDispatcherImpl::getObject(InspectorObject* object, const String& name, bool* valueFound, InspectorArray* protocolErrors)
-{
-    return getPropertyValueImpl<PassRefPtr<InspectorObject>, RefPtr<InspectorObject>, InspectorObject*>(object, name, valueFound, protocolErrors, 0, AsMethodBridges::asObject, "Object");
-}
-
-PassRefPtr<InspectorArray> InspectorBackendDispatcherImpl::getArray(InspectorObject* object, const String& name, bool* valueFound, InspectorArray* protocolErrors)
-{
-    return getPropertyValueImpl<PassRefPtr<InspectorArray>, RefPtr<InspectorArray>, InspectorArray*>(object, name, valueFound, protocolErrors, 0, AsMethodBridges::asArray, "Array");
-}
-
-InspectorBackendDispatcher::CallbackBase::CallbackBase(PassRefPtr<InspectorBackendDispatcherImpl> backendImpl, int id)
-    : m_backendImpl(backendImpl), m_id(id), m_alreadySent(false) {}
-
-InspectorBackendDispatcher::CallbackBase::~CallbackBase() {}
-
-void InspectorBackendDispatcher::CallbackBase::sendFailure(const ErrorString& error)
-{
-    ASSERT(error.length());
-    sendIfActive(0, error);
-}
-
-bool InspectorBackendDispatcher::CallbackBase::isActive()
-{
-    return !m_alreadySent && m_backendImpl->isActive();
-}
-
-void InspectorBackendDispatcher::CallbackBase::sendIfActive(PassRefPtr<InspectorObject> partialMessage, const ErrorString& invocationError)
-{
-    if (m_alreadySent)
-        return;
-    m_backendImpl->sendResponse(m_id, partialMessage, invocationError);
-    m_alreadySent = true;
-}
-
-COMPILE_ASSERT(static_cast<int>(InspectorBackendDispatcher::kMethodNamesEnumSize) == WTF_ARRAY_LENGTH(InspectorBackendDispatcher::commandNames), command_name_array_problem);
-
 } // namespace WebCore
 
 #endif // ENABLE(INSPECTOR)
@@ -601,12 +317,12 @@ public:
         ArrayItemHelper<T>::Traits::pushRaw(this->openAccessors(), value);
     }
 
-    static PassRefPtr<Array<T> > create()
+    static PassRefPtr<Array<T>> create()
     {
         return adoptRef(new Array<T>());
     }
 
-    static PassRefPtr<Array<T> > runtimeCast(PassRefPtr<InspectorValue> value)
+    static PassRefPtr<Array<T>> runtimeCast(PassRefPtr<InspectorValue> value)
     {
         RefPtr<InspectorArray> array;
         bool castRes = value->asArray(&array);
@@ -765,9 +481,9 @@ struct ArrayItemHelper<InspectorArray> {
 };
 
 template<typename T>
-struct ArrayItemHelper<TypeBuilder::Array<T> > {
+struct ArrayItemHelper<TypeBuilder::Array<T>> {
     struct Traits {
-        static void pushRefPtr(InspectorArray* array, PassRefPtr<TypeBuilder::Array<T> > value)
+        static void pushRefPtr(InspectorArray* array, PassRefPtr<TypeBuilder::Array<T>> value)
         {
             array->pushValue(value);
         }
@@ -853,7 +569,7 @@ $domainInitializers
 """)
 
 param_container_access_code = """
-    RefPtr<InspectorObject> paramsContainer = requestMessageObject->getObject("params");
+    RefPtr<InspectorObject> paramsContainer = message.getObject("params");
     InspectorObject* paramsContainerPtr = paramsContainer.get();
     InspectorArray* protocolErrorsPtr = protocolErrors.get();
 """
index 4eadde4..7ac330a 100644 (file)
@@ -96,12 +96,13 @@ void InspectorAgent::didClearWindowObjectInWorld(Frame* frame, DOMWrapperWorld&
 void InspectorAgent::didCreateFrontendAndBackend(InspectorFrontendChannel* frontendChannel, InspectorBackendDispatcher* backendDispatcher)
 {
     m_frontendDispatcher = std::make_unique<InspectorInspectorFrontendDispatcher>(frontendChannel);
-    backendDispatcher->registerAgent(this);
+    m_backendDispatcher = InspectorInspectorBackendDispatcher::create(backendDispatcher, this);
 }
 
 void InspectorAgent::willDestroyFrontendAndBackend()
 {
     m_frontendDispatcher = nullptr;
+    m_backendDispatcher.clear();
 
     m_pendingEvaluateTestCommands.clear();
     m_injectedScriptManager->discardInjectedScripts();
index f8f3b06..911189e 100644 (file)
@@ -51,7 +51,7 @@ class Page;
 
 typedef String ErrorString;
 
-class InspectorAgent : public InspectorBaseAgent, public InspectorBackendDispatcher::InspectorCommandHandler {
+class InspectorAgent : public InspectorBaseAgent, public InspectorInspectorBackendDispatcherHandler {
     WTF_MAKE_NONCOPYABLE(InspectorAgent);
 public:
     static PassOwnPtr<InspectorAgent> create(Page* page, InjectedScriptManager* injectedScriptManager, InstrumentingAgents* instrumentingAgents)
@@ -92,6 +92,7 @@ private:
 
     Page* m_inspectedPage;
     std::unique_ptr<InspectorInspectorFrontendDispatcher> m_frontendDispatcher;
+    RefPtr<InspectorInspectorBackendDispatcher> m_backendDispatcher;
     InjectedScriptManager* m_injectedScriptManager;
 
     Vector<pair<long, String>> m_pendingEvaluateTestCommands;
index 2b3e159..3be023e 100644 (file)
@@ -39,6 +39,7 @@
 #include "InspectorAgent.cpp"
 #include "InspectorAgentRegistry.cpp"
 #include "InspectorApplicationCacheAgent.cpp"
+#include "InspectorBackendDispatcher.cpp"
 #include "InspectorCSSAgent.cpp"
 #include "InspectorCanvasAgent.cpp"
 #include "InspectorClient.cpp"
index 75f25ae..04cc53a 100644 (file)
@@ -53,12 +53,13 @@ InspectorApplicationCacheAgent::InspectorApplicationCacheAgent(InstrumentingAgen
 void InspectorApplicationCacheAgent::didCreateFrontendAndBackend(InspectorFrontendChannel* frontendChannel, InspectorBackendDispatcher* backendDispatcher)
 {
     m_frontendDispatcher = std::make_unique<InspectorApplicationCacheFrontendDispatcher>(frontendChannel);
-    backendDispatcher->registerAgent(this);
+    m_backendDispatcher = InspectorApplicationCacheBackendDispatcher::create(backendDispatcher, this);
 }
 
 void InspectorApplicationCacheAgent::willDestroyFrontendAndBackend()
 {
     m_frontendDispatcher = nullptr;
+    m_backendDispatcher.clear();
 
     m_instrumentingAgents->setInspectorApplicationCacheAgent(0);
 }
index e4faa11..eb06c8f 100644 (file)
@@ -48,7 +48,7 @@ class ResourceResponse;
 
 typedef String ErrorString;
 
-class InspectorApplicationCacheAgent : public InspectorBaseAgent, public InspectorBackendDispatcher::ApplicationCacheCommandHandler {
+class InspectorApplicationCacheAgent : public InspectorBaseAgent, public InspectorApplicationCacheBackendDispatcherHandler {
     WTF_MAKE_NONCOPYABLE(InspectorApplicationCacheAgent); WTF_MAKE_FAST_ALLOCATED;
 public:
     static PassOwnPtr<InspectorApplicationCacheAgent> create(InstrumentingAgents* instrumentingAgents, InspectorPageAgent* pageAgent)
@@ -81,6 +81,7 @@ private:
 
     InspectorPageAgent* m_pageAgent;
     std::unique_ptr<InspectorApplicationCacheFrontendDispatcher> m_frontendDispatcher;
+    RefPtr<InspectorApplicationCacheBackendDispatcher> m_backendDispatcher;
 };
 
 } // namespace WebCore
diff --git a/Source/WebCore/inspector/InspectorBackendDispatcher.cpp b/Source/WebCore/inspector/InspectorBackendDispatcher.cpp
new file mode 100644 (file)
index 0000000..c615659
--- /dev/null
@@ -0,0 +1,277 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All Rights Reserved.
+ * Copyright (C) 2011 The Chromium Authors. All rights reserved.
+ *
+ * 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 APPLE INC. ``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 APPLE INC. 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 "InspectorBackendDispatcher.h"
+
+#if ENABLE(INSPECTOR)
+
+#include "InspectorFrontendChannel.h"
+#include "InspectorValues.h"
+#include <wtf/text/CString.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+InspectorBackendDispatcher::CallbackBase::CallbackBase(PassRefPtr<InspectorBackendDispatcher> backendDispatcher, int id)
+    : m_backendDispatcher(backendDispatcher)
+    , m_id(id)
+    , m_alreadySent(false)
+{
+}
+
+bool InspectorBackendDispatcher::CallbackBase::isActive() const
+{
+    return !m_alreadySent && m_backendDispatcher->isActive();
+}
+
+void InspectorBackendDispatcher::CallbackBase::sendFailure(const ErrorString& error)
+{
+    ASSERT(error.length());
+    sendIfActive(nullptr, error);
+}
+
+void InspectorBackendDispatcher::CallbackBase::sendIfActive(PassRefPtr<InspectorObject> partialMessage, const ErrorString& invocationError)
+{
+    if (m_alreadySent)
+        return;
+
+    m_backendDispatcher->sendResponse(m_id, partialMessage, invocationError);
+    m_alreadySent = true;
+}
+
+PassRefPtr<InspectorBackendDispatcher> InspectorBackendDispatcher::create(InspectorFrontendChannel* inspectorFrontendChannel)
+{
+    return adoptRef(new InspectorBackendDispatcher(inspectorFrontendChannel));
+}
+
+void InspectorBackendDispatcher::registerDispatcherForDomain(const String& domain, InspectorSupplementalBackendDispatcher* dispatcher)
+{
+    auto result = m_dispatchers.add(domain, dispatcher);
+    ASSERT_UNUSED(result, result.isNewEntry);
+}
+
+void InspectorBackendDispatcher::dispatch(const String& message)
+{
+    Ref<InspectorBackendDispatcher> protect(*this);
+
+    RefPtr<InspectorValue> parsedMessage = InspectorValue::parseJSON(message);
+    if (!parsedMessage) {
+        reportProtocolError(nullptr, ParseError, "Message must be in JSON format");
+        return;
+    }
+
+    RefPtr<InspectorObject> messageObject = parsedMessage->asObject();
+    if (!messageObject) {
+        reportProtocolError(nullptr, InvalidRequest, "Message must be a JSONified object");
+        return;
+    }
+
+    RefPtr<InspectorValue> callIdValue = messageObject->get("id");
+    if (!callIdValue) {
+        reportProtocolError(nullptr, InvalidRequest, "'id' property was not found");
+        return;
+    }
+
+    long callId = 0;
+    if (!callIdValue->asNumber(&callId)) {
+        reportProtocolError(nullptr, InvalidRequest, "The type of 'id' property must be number");
+        return;
+    }
+
+    RefPtr<InspectorValue> methodValue = messageObject->get("method");
+    if (!methodValue) {
+        reportProtocolError(&callId, InvalidRequest, "'method' property wasn't found");
+        return;
+    }
+
+    String method;
+    if (!methodValue->asString(&method)) {
+        reportProtocolError(&callId, InvalidRequest, "The type of 'method' property must be string");
+        return;
+    }
+
+    size_t position = method.find('.');
+    if (position == WTF::notFound) {
+        reportProtocolError(&callId, InvalidRequest, "The 'method' property was formatted incorrectly. It should be 'Domain.method'");
+        return;
+    }
+
+    String domain = method.substring(0, position);
+    InspectorSupplementalBackendDispatcher* domainDispatcher = m_dispatchers.get(domain);
+    if (!domainDispatcher) {
+        reportProtocolError(&callId, MethodNotFound, "'" + domain + "' domain was not found");
+        return;
+    }
+
+    String domainMethod = method.substring(position + 1);
+    domainDispatcher->dispatch(callId, domainMethod, messageObject.release());
+}
+
+// FIXME: Remove this by building better generated code.
+void InspectorBackendDispatcher::sendResponse(long callId, PassRefPtr<InspectorObject> result, PassRefPtr<InspectorArray> protocolErrors, const ErrorString& invocationError)
+{
+    if (protocolErrors->length()) {
+        String errorMessage = String::format("Some arguments of method ??? can't be processed");
+        reportProtocolError(&callId, InvalidParams, errorMessage, protocolErrors);
+        return;
+    }
+
+    sendResponse(callId, result, invocationError);
+}
+
+void InspectorBackendDispatcher::sendResponse(long callId, PassRefPtr<InspectorObject> result, const ErrorString& invocationError)
+{
+    if (!m_inspectorFrontendChannel)
+        return;
+
+    if (invocationError.length()) {
+        reportProtocolError(&callId, ServerError, invocationError);
+        return;
+    }
+
+    RefPtr<InspectorObject> responseMessage = InspectorObject::create();
+    responseMessage->setObject("result", result);
+    responseMessage->setNumber("id", callId);
+    m_inspectorFrontendChannel->sendMessageToFrontend(responseMessage->toJSONString());
+}
+
+void InspectorBackendDispatcher::reportProtocolError(const long* const callId, CommonErrorCode errorCode, const String& errorMessage) const
+{
+    reportProtocolError(callId, errorCode, errorMessage, nullptr);
+}
+
+void InspectorBackendDispatcher::reportProtocolError(const long* const callId, CommonErrorCode errorCode, const String& errorMessage, PassRefPtr<InspectorArray> data) const
+{
+    DEFINE_STATIC_LOCAL(Vector<int>, commonErrors, ());
+    if (!commonErrors.size()) {
+        commonErrors.insert(ParseError, -32700);
+        commonErrors.insert(InvalidRequest, -32600);
+        commonErrors.insert(MethodNotFound, -32601);
+        commonErrors.insert(InvalidParams, -32602);
+        commonErrors.insert(InternalError, -32603);
+        commonErrors.insert(ServerError, -32000);
+    }
+
+    ASSERT(errorCode >= 0);
+    ASSERT((unsigned)errorCode < commonErrors.size());
+    ASSERT(commonErrors[errorCode]);
+
+    if (!m_inspectorFrontendChannel)
+        return;
+
+    RefPtr<InspectorObject> error = InspectorObject::create();
+    error->setNumber("code", commonErrors[errorCode]);
+    error->setString("message", errorMessage);
+    if (data)
+        error->setArray("data", data);
+
+    RefPtr<InspectorObject> message = InspectorObject::create();
+    message->setObject("error", error.release());
+    if (callId)
+        message->setNumber("id", *callId);
+    else
+        message->setValue("id", InspectorValue::null());
+
+    m_inspectorFrontendChannel->sendMessageToFrontend(message->toJSONString());
+}
+
+template<typename ReturnValueType, typename ValueType, typename DefaultValueType>
+ReturnValueType InspectorBackendDispatcher::getPropertyValue(InspectorObject* object, const String& name, bool* valueFound, InspectorArray* protocolErrors, DefaultValueType defaultValue, bool (*asMethod)(InspectorValue*, ValueType*), const char* typeName)
+{
+    ASSERT(protocolErrors);
+
+    ValueType value = defaultValue;
+    if (valueFound)
+        *valueFound = false;
+
+    if (!object) {
+        if (!valueFound)
+            protocolErrors->pushString(String::format("'params' object must contain required parameter '%s' with type '%s'.", name.utf8().data(), typeName));
+        return value;
+    }
+
+    InspectorObject::const_iterator end = object->end();
+    InspectorObject::const_iterator valueIterator = object->find(name);
+    if (valueIterator == end) {
+        if (!valueFound)
+            protocolErrors->pushString(String::format("Parameter '%s' with type '%s' was not found.", name.utf8().data(), typeName));
+        return value;
+    }
+
+    if (!asMethod(valueIterator->value.get(), &value)) {
+        protocolErrors->pushString(String::format("Parameter '%s' has wrong type. It must be '%s'.", name.utf8().data(), typeName));
+        return value;
+    }
+
+    if (valueFound)
+        *valueFound = true;
+
+    return value;
+}
+
+struct AsMethodBridges {
+    static bool asInt(InspectorValue* value, int* output) { return value->asNumber(output); }
+    static bool asDouble(InspectorValue* value, double* output) { return value->asNumber(output); }
+    static bool asString(InspectorValue* value, String* output) { return value->asString(output); }
+    static bool asBoolean(InspectorValue* value, bool* output) { return value->asBoolean(output); }
+    static bool asObject(InspectorValue* value, RefPtr<InspectorObject>* output) { return value->asObject(output); }
+    static bool asArray(InspectorValue* value, RefPtr<InspectorArray>* output) { return value->asArray(output); }
+};
+
+int InspectorBackendDispatcher::getInt(InspectorObject* object, const String& name, bool* valueFound, InspectorArray* protocolErrors)
+{
+    return getPropertyValue<int, int, int>(object, name, valueFound, protocolErrors, 0, AsMethodBridges::asInt, "Number");
+}
+
+double InspectorBackendDispatcher::getDouble(InspectorObject* object, const String& name, bool* valueFound, InspectorArray* protocolErrors)
+{
+    return getPropertyValue<double, double, double>(object, name, valueFound, protocolErrors, 0, AsMethodBridges::asDouble, "Number");
+}
+
+String InspectorBackendDispatcher::getString(InspectorObject* object, const String& name, bool* valueFound, InspectorArray* protocolErrors)
+{
+    return getPropertyValue<String, String, String>(object, name, valueFound, protocolErrors, "", AsMethodBridges::asString, "String");
+}
+
+bool InspectorBackendDispatcher::getBoolean(InspectorObject* object, const String& name, bool* valueFound, InspectorArray* protocolErrors)
+{
+    return getPropertyValue<bool, bool, bool>(object, name, valueFound, protocolErrors, false, AsMethodBridges::asBoolean, "Boolean");
+}
+
+PassRefPtr<InspectorObject> InspectorBackendDispatcher::getObject(InspectorObject* object, const String& name, bool* valueFound, InspectorArray* protocolErrors)
+{
+    return getPropertyValue<PassRefPtr<InspectorObject>, RefPtr<InspectorObject>, InspectorObject*>(object, name, valueFound, protocolErrors, nullptr, AsMethodBridges::asObject, "Object");
+}
+
+PassRefPtr<InspectorArray> InspectorBackendDispatcher::getArray(InspectorObject* object, const String& name, bool* valueFound, InspectorArray* protocolErrors)
+{
+    return getPropertyValue<PassRefPtr<InspectorArray>, RefPtr<InspectorArray>, InspectorArray*>(object, name, valueFound, protocolErrors, nullptr, AsMethodBridges::asArray, "Array");
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(INSPECTOR)
diff --git a/Source/WebCore/inspector/InspectorBackendDispatcher.h b/Source/WebCore/inspector/InspectorBackendDispatcher.h
new file mode 100644 (file)
index 0000000..ccc4a5d
--- /dev/null
@@ -0,0 +1,113 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All Rights Reserved.
+ * Copyright (C) 2011 The Chromium Authors. All rights reserved.
+ *
+ * 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 APPLE INC. ``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 APPLE INC. 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.
+ */
+
+#ifndef InspectorBackendDispatcher_h
+#define InspectorBackendDispatcher_h
+
+#include "InspectorTypeBuilder.h"
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+class InspectorBackendDispatcher;
+class InspectorFrontendChannel;
+typedef String ErrorString;
+
+class InspectorSupplementalBackendDispatcher : public RefCounted<InspectorSupplementalBackendDispatcher> {
+public:
+    InspectorSupplementalBackendDispatcher(InspectorBackendDispatcher *backendDispatcher) : m_backendDispatcher(backendDispatcher) { }
+    virtual ~InspectorSupplementalBackendDispatcher() { }
+    virtual void dispatch(long callId, const String& method, PassRefPtr<InspectorObject> message) = 0;
+protected:
+    RefPtr<InspectorBackendDispatcher> m_backendDispatcher;
+};
+
+class InspectorBackendDispatcher : public RefCounted<InspectorBackendDispatcher> {
+public:
+    static PassRefPtr<InspectorBackendDispatcher> create(InspectorFrontendChannel*);
+    virtual ~InspectorBackendDispatcher() { }
+
+    class CallbackBase: public RefCounted<CallbackBase> {
+    public:
+        CallbackBase(PassRefPtr<InspectorBackendDispatcher>, int id);
+        virtual ~CallbackBase() { }
+
+        bool isActive() const;
+        void sendFailure(const ErrorString&);
+        void disable() { m_alreadySent = true; }
+
+    protected:
+        void sendIfActive(PassRefPtr<InspectorObject> partialMessage, const ErrorString& invocationError);
+
+    private:
+        RefPtr<InspectorBackendDispatcher> m_backendDispatcher;
+        int m_id;
+        bool m_alreadySent;
+    };
+
+    void clearFrontend() { m_inspectorFrontendChannel = nullptr; }
+    bool isActive() const { return !!m_inspectorFrontendChannel; }
+
+    enum CommonErrorCode {
+        ParseError = 0,
+        InvalidRequest,
+        MethodNotFound,
+        InvalidParams,
+        InternalError,
+        ServerError
+    };
+
+    void registerDispatcherForDomain(const String& domain, InspectorSupplementalBackendDispatcher*);
+    void dispatch(const String& message);
+    void sendResponse(long callId, PassRefPtr<InspectorObject> result, const ErrorString& invocationError);
+    void reportProtocolError(const long* const callId, CommonErrorCode, const String& errorMessage) const;
+    void reportProtocolError(const long* const callId, CommonErrorCode, const String& errorMessage, PassRefPtr<InspectorArray> data) const;
+
+    // FIXME: Remove this by building better generated code.
+    void sendResponse(long callId, PassRefPtr<InspectorObject> result, PassRefPtr<InspectorArray> protocolErrors, const ErrorString& invocationError);
+
+    static int getInt(InspectorObject*, const String& name, bool* valueFound, InspectorArray* protocolErrors);
+    static double getDouble(InspectorObject*, const String& name, bool* valueFound, InspectorArray* protocolErrors);
+    static String getString(InspectorObject*, const String& name, bool* valueFound, InspectorArray* protocolErrors);
+    static bool getBoolean(InspectorObject*, const String& name, bool* valueFound, InspectorArray* protocolErrors);
+    static PassRefPtr<InspectorObject> getObject(InspectorObject*, const String& name, bool* valueFound, InspectorArray* protocolErrors);
+    static PassRefPtr<InspectorArray> getArray(InspectorObject*, const String& name, bool* valueFound, InspectorArray* protocolErrors);
+
+private:
+    InspectorBackendDispatcher(InspectorFrontendChannel* inspectorFrontendChannel) : m_inspectorFrontendChannel(inspectorFrontendChannel) { }
+
+    template<typename ReturnValueType, typename ValueType, typename DefaultValueType>
+    static ReturnValueType getPropertyValue(InspectorObject* object, const String& name, bool* valueFound, InspectorArray* protocolErrors, DefaultValueType defaultValue, bool (*asMethod)(InspectorValue*, ValueType*), const char* typeName);
+
+    InspectorFrontendChannel* m_inspectorFrontendChannel;
+    HashMap<String, InspectorSupplementalBackendDispatcher*> m_dispatchers;
+};
+
+} // namespace WebCore
+
+#endif // !defined(InspectorBackendDispatcher_h)
index 6077ca1..51e4902 100644 (file)
@@ -632,12 +632,13 @@ InspectorCSSAgent::~InspectorCSSAgent()
 void InspectorCSSAgent::didCreateFrontendAndBackend(InspectorFrontendChannel* frontendChannel, InspectorBackendDispatcher* backendDispatcher)
 {
     m_frontendDispatcher = std::make_unique<InspectorCSSFrontendDispatcher>(frontendChannel);
-    backendDispatcher->registerAgent(this);
+    m_backendDispatcher = InspectorCSSBackendDispatcher::create(backendDispatcher, this);
 }
 
 void InspectorCSSAgent::willDestroyFrontendAndBackend()
 {
     m_frontendDispatcher = nullptr;
+    m_backendDispatcher.clear();
 
     resetNonPersistentData();
     String errorString;
index cbe6c36..9d3b40d 100644 (file)
@@ -66,7 +66,7 @@ class ChangeRegionOversetTask;
 class InspectorCSSAgent
     : public InspectorBaseAgent
     , public InspectorDOMAgent::DOMListener
-    , public InspectorBackendDispatcher::CSSCommandHandler
+    , public InspectorCSSBackendDispatcherHandler
     , public InspectorStyleSheet::Listener {
     WTF_MAKE_NONCOPYABLE(InspectorCSSAgent);
 public:
@@ -184,6 +184,7 @@ private:
     void resetPseudoStates();
 
     std::unique_ptr<InspectorCSSFrontendDispatcher> m_frontendDispatcher;
+    RefPtr<InspectorCSSBackendDispatcher> m_backendDispatcher;
     InspectorDOMAgent* m_domAgent;
 
     IdToInspectorStyleSheet m_idToInspectorStyleSheet;
index 3de8d67..f9f72f2 100644 (file)
@@ -76,12 +76,13 @@ InspectorCanvasAgent::~InspectorCanvasAgent()
 void InspectorCanvasAgent::didCreateFrontendAndBackend(InspectorFrontendChannel* frontendChannel, InspectorBackendDispatcher* backendDispatcher)
 {
     m_frontendDispatcher = std::make_unique<InspectorCanvasFrontendDispatcher>(frontendChannel);
-    backendDispatcher->registerAgent(this);
+    m_backendDispatcher = InspectorCanvasBackendDispatcher::create(backendDispatcher, this);
 }
 
 void InspectorCanvasAgent::willDestroyFrontendAndBackend()
 {
     m_frontendDispatcher = nullptr;
+    m_backendDispatcher.clear();
 
     disable(nullptr);
 }
index 2ebc71b..49d03e8 100644 (file)
@@ -53,7 +53,7 @@ class ScriptObject;
 
 typedef String ErrorString;
 
-class InspectorCanvasAgent : public InspectorBaseAgent, public InspectorBackendDispatcher::CanvasCommandHandler {
+class InspectorCanvasAgent : public InspectorBaseAgent, public InspectorCanvasBackendDispatcherHandler {
 public:
     static PassOwnPtr<InspectorCanvasAgent> create(InstrumentingAgents* instrumentingAgents, InspectorPageAgent* pageAgent, InjectedScriptManager* injectedScriptManager)
     {
@@ -101,6 +101,7 @@ private:
     InspectorPageAgent* m_pageAgent;
     InjectedScriptManager* m_injectedScriptManager;
     std::unique_ptr<InspectorCanvasFrontendDispatcher> m_frontendDispatcher;
+    RefPtr<InspectorCanvasBackendDispatcher> m_backendDispatcher;
     bool m_enabled;
     // Contains all frames with canvases, value is true only for frames that have an uninstrumented canvas.
     typedef HashMap<Frame*, bool> FramesWithUninstrumentedCanvases;
index 62b9e32..daa9c5b 100644 (file)
@@ -125,12 +125,13 @@ void InspectorConsoleAgent::reset()
 void InspectorConsoleAgent::didCreateFrontendAndBackend(InspectorFrontendChannel* frontendChannel, InspectorBackendDispatcher* backendDispatcher)
 {
     m_frontendDispatcher = std::make_unique<InspectorConsoleFrontendDispatcher>(frontendChannel);
-    backendDispatcher->registerAgent(this);
+    m_backendDispatcher = InspectorConsoleBackendDispatcher::create(backendDispatcher, this);
 }
 
 void InspectorConsoleAgent::willDestroyFrontendAndBackend()
 {
     m_frontendDispatcher = nullptr;
+    m_backendDispatcher.clear();
 
     String errorString;
     disable(&errorString);
index 4504abd..c0f0adc 100644 (file)
@@ -52,7 +52,7 @@ class ScriptProfile;
 
 typedef String ErrorString;
 
-class InspectorConsoleAgent : public InspectorBaseAgent, public InspectorBackendDispatcher::ConsoleCommandHandler {
+class InspectorConsoleAgent : public InspectorBaseAgent, public InspectorConsoleBackendDispatcherHandler {
     WTF_MAKE_NONCOPYABLE(InspectorConsoleAgent);
 public:
     InspectorConsoleAgent(InstrumentingAgents*, InjectedScriptManager*);
@@ -101,6 +101,7 @@ protected:
 
     InjectedScriptManager* m_injectedScriptManager;
     std::unique_ptr<InspectorConsoleFrontendDispatcher> m_frontendDispatcher;
+    RefPtr<InspectorConsoleBackendDispatcher> m_backendDispatcher;
     ConsoleMessage* m_previousMessage;
     Vector<OwnPtr<ConsoleMessage>> m_consoleMessages;
     int m_expiredConsoleMessageCount;
index e6bcb4c..25eed86 100644 (file)
@@ -234,7 +234,7 @@ InspectorDOMAgent::~InspectorDOMAgent()
 void InspectorDOMAgent::didCreateFrontendAndBackend(InspectorFrontendChannel* frontendChannel, InspectorBackendDispatcher* backendDispatcher)
 {
     m_frontendDispatcher = std::make_unique<InspectorDOMFrontendDispatcher>(frontendChannel);
-    backendDispatcher->registerAgent(this);
+    m_backendDispatcher = InspectorDOMBackendDispatcher::create(backendDispatcher, this);
 
     m_history = adoptPtr(new InspectorHistory());
     m_domEditor = adoptPtr(new DOMEditor(m_history.get()));
@@ -249,6 +249,7 @@ void InspectorDOMAgent::didCreateFrontendAndBackend(InspectorFrontendChannel* fr
 void InspectorDOMAgent::willDestroyFrontendAndBackend()
 {
     m_frontendDispatcher = nullptr;
+    m_backendDispatcher.clear();
 
     m_history.clear();
     m_domEditor.clear();
index 31ed69d..1196c98 100644 (file)
@@ -90,7 +90,7 @@ struct EventListenerInfo {
     const EventListenerVector eventListenerVector;
 };
 
-class InspectorDOMAgent : public InspectorBaseAgent, public InspectorBackendDispatcher::DOMCommandHandler {
+class InspectorDOMAgent : public InspectorBaseAgent, public InspectorDOMBackendDispatcherHandler {
     WTF_MAKE_NONCOPYABLE(InspectorDOMAgent);
 public:
     struct DOMListener {
@@ -245,6 +245,7 @@ private:
     InspectorOverlay* m_overlay;
     InspectorClient* m_client;
     std::unique_ptr<InspectorDOMFrontendDispatcher> m_frontendDispatcher;
+    RefPtr<InspectorDOMBackendDispatcher> m_backendDispatcher;
     DOMListener* m_domListener;
     NodeToIdMap m_documentNodeToIdMap;
     typedef HashMap<RefPtr<Node>, BackendNodeId> NodeToBackendIdMap;
index cfe5eef..89ff6e9 100644 (file)
@@ -113,11 +113,13 @@ void InspectorDOMDebuggerAgent::disable()
 
 void InspectorDOMDebuggerAgent::didCreateFrontendAndBackend(InspectorFrontendChannel*, InspectorBackendDispatcher* backendDispatcher)
 {
-    backendDispatcher->registerAgent(this);
+    m_backendDispatcher = InspectorDOMDebuggerBackendDispatcher::create(backendDispatcher, this);
 }
 
 void InspectorDOMDebuggerAgent::willDestroyFrontendAndBackend()
 {
+    m_backendDispatcher.clear();
+
     disable();
 }
 
index ae25a03..96f88a9 100644 (file)
@@ -52,7 +52,7 @@ class Node;
 
 typedef String ErrorString;
 
-class InspectorDOMDebuggerAgent : public InspectorBaseAgent, public InspectorDebuggerAgent::Listener, public InspectorBackendDispatcher::DOMDebuggerCommandHandler {
+class InspectorDOMDebuggerAgent : public InspectorBaseAgent, public InspectorDebuggerAgent::Listener, public InspectorDOMDebuggerBackendDispatcherHandler {
     WTF_MAKE_NONCOPYABLE(InspectorDOMDebuggerAgent);
 public:
     static PassOwnPtr<InspectorDOMDebuggerAgent> create(InstrumentingAgents*, InspectorDOMAgent*, InspectorDebuggerAgent*, InspectorAgent*);
@@ -104,6 +104,7 @@ private:
 
     InspectorDOMAgent* m_domAgent;
     InspectorDebuggerAgent* m_debuggerAgent;
+    RefPtr<InspectorDOMDebuggerBackendDispatcher> m_backendDispatcher;
     HashMap<Node*, uint32_t> m_domBreakpoints;
     HashSet<String> m_eventListenerBreakpoints;
     HashSet<String> m_xhrBreakpoints;
index 419af92..646de23 100644 (file)
@@ -72,12 +72,13 @@ InspectorDOMStorageAgent::~InspectorDOMStorageAgent()
 void InspectorDOMStorageAgent::didCreateFrontendAndBackend(InspectorFrontendChannel* frontendChannel, InspectorBackendDispatcher* backendDispatcher)
 {
     m_frontendDispatcher = std::make_unique<InspectorDOMStorageFrontendDispatcher>(frontendChannel);
-    backendDispatcher->registerAgent(this);
+    m_backendDispatcher = InspectorDOMStorageBackendDispatcher::create(backendDispatcher, this);
 }
 
 void InspectorDOMStorageAgent::willDestroyFrontendAndBackend()
 {
     m_frontendDispatcher = nullptr;
+    m_backendDispatcher.clear();
 
     disable(nullptr);
 }
index 84ab932..2cd17b3 100644 (file)
@@ -49,7 +49,7 @@ class StorageArea;
 
 typedef String ErrorString;
 
-class InspectorDOMStorageAgent : public InspectorBaseAgent, public InspectorBackendDispatcher::DOMStorageCommandHandler {
+class InspectorDOMStorageAgent : public InspectorBaseAgent, public InspectorDOMStorageBackendDispatcherHandler {
 public:
     static PassOwnPtr<InspectorDOMStorageAgent> create(InstrumentingAgents* instrumentingAgents, InspectorPageAgent* pageAgent)
     {
@@ -82,6 +82,7 @@ private:
 
     InspectorPageAgent* m_pageAgent;
     std::unique_ptr<InspectorDOMStorageFrontendDispatcher> m_frontendDispatcher;
+    RefPtr<InspectorDOMStorageBackendDispatcher> m_backendDispatcher;
     bool m_enabled;
 };
 
index 7a77415..c5800ea 100644 (file)
@@ -53,7 +53,7 @@
 
 #include <wtf/Vector.h>
 
-typedef WebCore::InspectorBackendDispatcher::DatabaseCommandHandler::ExecuteSQLCallback ExecuteSQLCallback;
+typedef WebCore::InspectorDatabaseBackendDispatcherHandler::ExecuteSQLCallback ExecuteSQLCallback;
 
 namespace WebCore {
 
@@ -225,12 +225,13 @@ InspectorDatabaseAgent::~InspectorDatabaseAgent()
 void InspectorDatabaseAgent::didCreateFrontendAndBackend(InspectorFrontendChannel* frontendChannel, InspectorBackendDispatcher* backendDispatcher)
 {
     m_frontendDispatcher = std::make_unique<InspectorDatabaseFrontendDispatcher>(frontendChannel);
-    backendDispatcher->registerAgent(this);
+    m_backendDispatcher = InspectorDatabaseBackendDispatcher::create(backendDispatcher, this);
 }
 
 void InspectorDatabaseAgent::willDestroyFrontendAndBackend()
 {
     m_frontendDispatcher = nullptr;
+    m_backendDispatcher.clear();
 
     disable(nullptr);
 }
index a21bca8..a32f064 100644 (file)
@@ -46,7 +46,7 @@ class InstrumentingAgents;
 
 typedef String ErrorString;
 
-class InspectorDatabaseAgent : public InspectorBaseAgent, public InspectorBackendDispatcher::DatabaseCommandHandler {
+class InspectorDatabaseAgent : public InspectorBaseAgent, public InspectorDatabaseBackendDispatcherHandler {
 public:
     static PassOwnPtr<InspectorDatabaseAgent> create(InstrumentingAgents* instrumentingAgents)
     {
@@ -76,6 +76,7 @@ private:
     InspectorDatabaseResource* findByFileName(const String& fileName);
 
     std::unique_ptr<InspectorDatabaseFrontendDispatcher> m_frontendDispatcher;
+    RefPtr<InspectorDatabaseBackendDispatcher> m_backendDispatcher;
     typedef HashMap<String, RefPtr<InspectorDatabaseResource>> DatabaseResourcesMap;
     DatabaseResourcesMap m_resources;
     bool m_enabled;
index 2df58c3..ac2b70e 100644 (file)
@@ -139,12 +139,13 @@ void InspectorDebuggerAgent::disable(ErrorString*)
 void InspectorDebuggerAgent::didCreateFrontendAndBackend(InspectorFrontendChannel* frontendChannel, InspectorBackendDispatcher* backendDispatcher)
 {
     m_frontendDispatcher = std::make_unique<InspectorDebuggerFrontendDispatcher>(frontendChannel);
-    backendDispatcher->registerAgent(this);
+    m_backendDispatcher = InspectorDebuggerBackendDispatcher::create(backendDispatcher, this);
 }
 
 void InspectorDebuggerAgent::willDestroyFrontendAndBackend()
 {
     m_frontendDispatcher = nullptr;
+    m_backendDispatcher.clear();
 
     disable();
 }
index 42951dd..4be6000 100644 (file)
@@ -60,7 +60,7 @@ class ScriptValue;
 
 typedef String ErrorString;
 
-class InspectorDebuggerAgent : public InspectorBaseAgent, public ScriptDebugListener, public InspectorBackendDispatcher::DebuggerCommandHandler {
+class InspectorDebuggerAgent : public InspectorBaseAgent, public ScriptDebugListener, public InspectorDebuggerBackendDispatcherHandler {
     WTF_MAKE_NONCOPYABLE(InspectorDebuggerAgent); WTF_MAKE_FAST_ALLOCATED;
 public:
     static const char* backtraceObjectGroup;
@@ -168,6 +168,7 @@ private:
 
     InjectedScriptManager* m_injectedScriptManager;
     std::unique_ptr<InspectorDebuggerFrontendDispatcher> m_frontendDispatcher;
+    RefPtr<InspectorDebuggerBackendDispatcher> m_backendDispatcher;
     JSC::ExecState* m_pausedScriptState;
     ScriptValue m_currentCallStack;
     ScriptsMap m_scripts;
index 8ccbf15..0814a0f 100644 (file)
@@ -83,12 +83,13 @@ void InspectorHeapProfilerAgent::resetFrontendProfiles()
 void InspectorHeapProfilerAgent::didCreateFrontendAndBackend(InspectorFrontendChannel* frontendChannel, InspectorBackendDispatcher* backendDispatcher)
 {
     m_frontendDispatcher = std::make_unique<InspectorHeapProfilerFrontendDispatcher>(frontendChannel);
-    backendDispatcher->registerAgent(this);
+    m_backendDispatcher = InspectorHeapProfilerBackendDispatcher::create(backendDispatcher, this);
 }
 
 void InspectorHeapProfilerAgent::willDestroyFrontendAndBackend()
 {
     m_frontendDispatcher = nullptr;
+    m_backendDispatcher.clear();
 
     m_profileHeadersRequested = false;
 }
index 26c2d19..cc36868 100644 (file)
@@ -49,7 +49,7 @@ class ScriptProfile;
 
 typedef String ErrorString;
 
-class InspectorHeapProfilerAgent : public InspectorBaseAgent, public InspectorBackendDispatcher::HeapProfilerCommandHandler {
+class InspectorHeapProfilerAgent : public InspectorBaseAgent, public InspectorHeapProfilerBackendDispatcherHandler {
     WTF_MAKE_NONCOPYABLE(InspectorHeapProfilerAgent); WTF_MAKE_FAST_ALLOCATED;
 public:
     static PassOwnPtr<InspectorHeapProfilerAgent> create(InstrumentingAgents*, InjectedScriptManager*);
@@ -84,6 +84,7 @@ private:
 
     InjectedScriptManager* m_injectedScriptManager;
     std::unique_ptr<InspectorHeapProfilerFrontendDispatcher> m_frontendDispatcher;
+    RefPtr<InspectorHeapProfilerBackendDispatcher> m_backendDispatcher;
     unsigned m_nextUserInitiatedHeapSnapshotNumber;
     IdToHeapSnapshotMap m_snapshots;
     bool m_profileHeadersRequested;
index 1e27207..896de99 100644 (file)
@@ -76,11 +76,11 @@ using WebCore::TypeBuilder::IndexedDB::KeyRange;
 using WebCore::TypeBuilder::IndexedDB::ObjectStore;
 using WebCore::TypeBuilder::IndexedDB::ObjectStoreIndex;
 
-typedef WebCore::InspectorBackendDispatcher::IndexedDBCommandHandler::RequestDatabaseNamesCallback RequestDatabaseNamesCallback;
-typedef WebCore::InspectorBackendDispatcher::IndexedDBCommandHandler::RequestDatabaseCallback RequestDatabaseCallback;
-typedef WebCore::InspectorBackendDispatcher::IndexedDBCommandHandler::RequestDataCallback RequestDataCallback;
+typedef WebCore::InspectorIndexedDBBackendDispatcherHandler::RequestDatabaseNamesCallback RequestDatabaseNamesCallback;
+typedef WebCore::InspectorIndexedDBBackendDispatcherHandler::RequestDatabaseCallback RequestDatabaseCallback;
+typedef WebCore::InspectorIndexedDBBackendDispatcherHandler::RequestDataCallback RequestDataCallback;
 typedef WebCore::InspectorBackendDispatcher::CallbackBase RequestCallback;
-typedef WebCore::InspectorBackendDispatcher::IndexedDBCommandHandler::ClearObjectStoreCallback ClearObjectStoreCallback;
+typedef WebCore::InspectorIndexedDBBackendDispatcherHandler::ClearObjectStoreCallback ClearObjectStoreCallback;
 
 namespace WebCore {
 
@@ -569,11 +569,13 @@ InspectorIndexedDBAgent::~InspectorIndexedDBAgent()
 
 void InspectorIndexedDBAgent::didCreateFrontendAndBackend(InspectorFrontendChannel*, InspectorBackendDispatcher* backendDispatcher)
 {
-    backendDispatcher->registerAgent(this);
+    m_backendDispatcher = InspectorIndexedDBBackendDispatcher::create(backendDispatcher, this);
 }
 
 void InspectorIndexedDBAgent::willDestroyFrontendAndBackend()
 {
+    m_backendDispatcher.clear();
+
     disable(nullptr);
 }
 
index ef40dbc..ba3759a 100644 (file)
@@ -44,7 +44,7 @@ class InspectorPageAgent;
 
 typedef String ErrorString;
 
-class InspectorIndexedDBAgent : public InspectorBaseAgent, public InspectorBackendDispatcher::IndexedDBCommandHandler {
+class InspectorIndexedDBAgent : public InspectorBaseAgent, public InspectorIndexedDBBackendDispatcherHandler {
 public:
     static PassOwnPtr<InspectorIndexedDBAgent> create(InstrumentingAgents* instrumentingAgents, InjectedScriptManager* injectedScriptManager, InspectorPageAgent* pageAgent)
     {
@@ -68,6 +68,7 @@ private:
 
     InjectedScriptManager* m_injectedScriptManager;
     InspectorPageAgent* m_pageAgent;
+    RefPtr<InspectorIndexedDBBackendDispatcher> m_backendDispatcher;
 };
 
 } // namespace WebCore
index f26d71d..7eccb8d 100644 (file)
@@ -63,11 +63,12 @@ InspectorInputAgent::~InspectorInputAgent()
 
 void InspectorInputAgent::didCreateFrontendAndBackend(InspectorFrontendChannel*, InspectorBackendDispatcher* backendDispatcher)
 {
-    backendDispatcher->registerAgent(this);
+    m_backendDispatcher = InspectorInputBackendDispatcher::create(backendDispatcher, this);
 }
 
 void InspectorInputAgent::willDestroyFrontendAndBackend()
 {
+    m_backendDispatcher.clear();
 }
 
 void InspectorInputAgent::dispatchKeyEvent(ErrorString* error, const String& type, const int* modifiers, const double* timestamp, const String* text, const String* unmodifiedText, const String* keyIdentifier, const int* windowsVirtualKeyCode, const int* nativeVirtualKeyCode, const int* macCharCode, const bool* autoRepeat, const bool* isKeypad, const bool* isSystemKey)
index 3f71e74..acba299 100644 (file)
@@ -44,7 +44,7 @@ class Page;
 
 typedef String ErrorString;
 
-class InspectorInputAgent : public InspectorBaseAgent, public InspectorBackendDispatcher::InputCommandHandler {
+class InspectorInputAgent : public InspectorBaseAgent, public InspectorInputBackendDispatcherHandler {
     WTF_MAKE_NONCOPYABLE(InspectorInputAgent);
 public:
     static PassOwnPtr<InspectorInputAgent> create(InstrumentingAgents* instrumentingAgents, Page* page)
@@ -65,6 +65,7 @@ private:
     InspectorInputAgent(InstrumentingAgents*, Page*);
 
     Page* m_page;
+    RefPtr<InspectorInputBackendDispatcher> m_backendDispatcher;
 };
 
 #endif // ENABLE(INSPECTOR)
index 35a511e..d27f909 100644 (file)
@@ -61,12 +61,13 @@ InspectorLayerTreeAgent::~InspectorLayerTreeAgent()
 void InspectorLayerTreeAgent::didCreateFrontendAndBackend(InspectorFrontendChannel* frontendChannel, InspectorBackendDispatcher* backendDispatcher)
 {
     m_frontendDispatcher = std::make_unique<InspectorLayerTreeFrontendDispatcher>(frontendChannel);
-    backendDispatcher->registerAgent(this);
+    m_backendDispatcher = InspectorLayerTreeBackendDispatcher::create(backendDispatcher, this);
 }
 
 void InspectorLayerTreeAgent::willDestroyFrontendAndBackend()
 {
     m_frontendDispatcher = nullptr;
+    m_backendDispatcher.clear();
 
     disable(nullptr);
 }
index 27d55d7..af55a92 100644 (file)
@@ -46,7 +46,7 @@ class InstrumentingAgents;
 
 typedef String ErrorString;
 
-class InspectorLayerTreeAgent : public InspectorBaseAgent, public InspectorBackendDispatcher::LayerTreeCommandHandler {
+class InspectorLayerTreeAgent : public InspectorBaseAgent, public InspectorLayerTreeBackendDispatcherHandler {
 public:
     static PassOwnPtr<InspectorLayerTreeAgent> create(InstrumentingAgents* instrumentingAgents)
     {
@@ -87,6 +87,7 @@ private:
     void unbindPseudoElement(PseudoElement*);
 
     std::unique_ptr<InspectorLayerTreeFrontendDispatcher> m_frontendDispatcher;
+    RefPtr<InspectorLayerTreeBackendDispatcher> m_backendDispatcher;
 
     HashMap<const RenderLayer*, String> m_documentLayerToIdMap;
     HashMap<String, const RenderLayer*> m_idToLayer;
index 3c269fc..758b7b4 100644 (file)
@@ -69,11 +69,12 @@ InspectorMemoryAgent::~InspectorMemoryAgent()
 
 void InspectorMemoryAgent::didCreateFrontendAndBackend(InspectorFrontendChannel*, InspectorBackendDispatcher* backendDispatcher)
 {
-    backendDispatcher->registerAgent(this);
+    m_backendDispatcher = InspectorMemoryBackendDispatcher::create(backendDispatcher, this);
 }
 
 void InspectorMemoryAgent::willDestroyFrontendAndBackend()
 {
+    m_backendDispatcher.clear();
 }
 
 void InspectorMemoryAgent::getDOMCounters(ErrorString*, int* documents, int* nodes, int* jsEventListeners)
index f14dba9..e1910de 100644 (file)
@@ -45,7 +45,7 @@ class InstrumentingAgents;
 
 typedef String ErrorString;
 
-class InspectorMemoryAgent : public InspectorBaseAgent, public InspectorBackendDispatcher::MemoryCommandHandler {
+class InspectorMemoryAgent : public InspectorBaseAgent, public InspectorMemoryBackendDispatcherHandler {
     WTF_MAKE_NONCOPYABLE(InspectorMemoryAgent);
 public:
     static PassOwnPtr<InspectorMemoryAgent> create(InstrumentingAgents* instrumentingAgents);
@@ -58,6 +58,8 @@ public:
 
 private:
     InspectorMemoryAgent(InstrumentingAgents*);
+
+    RefPtr<InspectorMemoryBackendDispatcher> m_backendDispatcher;
 };
 
 } // namespace WebCore
index e136d11..ec3d243 100644 (file)
@@ -371,12 +371,13 @@ InspectorPageAgent::InspectorPageAgent(InstrumentingAgents* instrumentingAgents,
 void InspectorPageAgent::didCreateFrontendAndBackend(InspectorFrontendChannel* frontendChannel, InspectorBackendDispatcher* backendDispatcher)
 {
     m_frontendDispatcher = std::make_unique<InspectorPageFrontendDispatcher>(frontendChannel);
-    backendDispatcher->registerAgent(this);
+    m_backendDispatcher = InspectorPageBackendDispatcher::create(backendDispatcher, this);
 }
 
 void InspectorPageAgent::willDestroyFrontendAndBackend()
 {
     m_frontendDispatcher = nullptr;
+    m_backendDispatcher.clear();
 
     ErrorString error;
     disable(&error);
@@ -781,7 +782,7 @@ void InspectorPageAgent::setContinuousPaintingEnabled(ErrorString*, bool enabled
         mainFrame()->view()->invalidate();
 }
 
-void InspectorPageAgent::getScriptExecutionStatus(ErrorString*, PageCommandHandler::Result::Enum* status)
+void InspectorPageAgent::getScriptExecutionStatus(ErrorString*, InspectorPageBackendDispatcherHandler::Result::Enum* status)
 {
     bool disabledByScriptController = false;
     bool disabledInSettings = false;
@@ -792,14 +793,14 @@ void InspectorPageAgent::getScriptExecutionStatus(ErrorString*, PageCommandHandl
     }
 
     if (!disabledByScriptController) {
-        *status = PageCommandHandler::Result::Allowed;
+        *status = InspectorPageBackendDispatcherHandler::Result::Allowed;
         return;
     }
 
     if (disabledInSettings)
-        *status = PageCommandHandler::Result::Disabled;
+        *status = InspectorPageBackendDispatcherHandler::Result::Disabled;
     else
-        *status = PageCommandHandler::Result::Forbidden;
+        *status = InspectorPageBackendDispatcherHandler::Result::Forbidden;
 }
 
 void InspectorPageAgent::setScriptExecutionDisabled(ErrorString*, bool value)
index 7645f44..8f4bd44 100644 (file)
@@ -67,7 +67,7 @@ class TextResourceDecoder;
 
 typedef String ErrorString;
 
-class InspectorPageAgent : public InspectorBaseAgent, public InspectorBackendDispatcher::PageCommandHandler {
+class InspectorPageAgent : public InspectorBaseAgent, public InspectorPageBackendDispatcherHandler {
     WTF_MAKE_NONCOPYABLE(InspectorPageAgent);
 public:
     enum ResourceType {
@@ -117,7 +117,7 @@ public:
     virtual void setShowFPSCounter(ErrorString*, bool show);
     virtual void canContinuouslyPaint(ErrorString*, bool*);
     virtual void setContinuousPaintingEnabled(ErrorString*, bool enabled);
-    virtual void getScriptExecutionStatus(ErrorString*, PageCommandHandler::Result::Enum*);
+    virtual void getScriptExecutionStatus(ErrorString*, InspectorPageBackendDispatcherHandler::Result::Enum*);
     virtual void setScriptExecutionDisabled(ErrorString*, bool);
     virtual void setGeolocationOverride(ErrorString*, const double*, const double*, const double*);
     virtual void clearGeolocationOverride(ErrorString*);
@@ -198,6 +198,7 @@ private:
     InjectedScriptManager* m_injectedScriptManager;
     InspectorClient* m_client;
     std::unique_ptr<InspectorPageFrontendDispatcher> m_frontendDispatcher;
+    RefPtr<InspectorPageBackendDispatcher> m_backendDispatcher;
     InspectorOverlay* m_overlay;
     long m_lastScriptIdentifier;
     String m_pendingScriptToEvaluateOnLoadOnce;
index d6465a2..529cae6 100644 (file)
@@ -332,12 +332,13 @@ void InspectorProfilerAgent::resetFrontendProfiles()
 void InspectorProfilerAgent::didCreateFrontendAndBackend(InspectorFrontendChannel* frontendChannel, InspectorBackendDispatcher* backendDispatcher)
 {
     m_frontendDispatcher = std::make_unique<InspectorProfilerFrontendDispatcher>(frontendChannel);
-    backendDispatcher->registerAgent(this);
+    m_backendDispatcher = InspectorProfilerBackendDispatcher::create(backendDispatcher, this);
 }
 
 void InspectorProfilerAgent::willDestroyFrontendAndBackend()
 {
     m_frontendDispatcher = nullptr;
+    m_backendDispatcher.clear();
 
     stop();
     ErrorString error;
index 6ec77ea..e0550b6 100644 (file)
@@ -54,7 +54,7 @@ class WorkerGlobalScope;
 
 typedef String ErrorString;
 
-class InspectorProfilerAgent : public InspectorBaseAgent, public InspectorBackendDispatcher::ProfilerCommandHandler {
+class InspectorProfilerAgent : public InspectorBaseAgent, public InspectorProfilerBackendDispatcherHandler {
     WTF_MAKE_NONCOPYABLE(InspectorProfilerAgent); WTF_MAKE_FAST_ALLOCATED;
 public:
     static PassOwnPtr<InspectorProfilerAgent> create(InstrumentingAgents*, InspectorConsoleAgent*, Page*, InjectedScriptManager*);
@@ -116,6 +116,7 @@ private:
     InspectorConsoleAgent* m_consoleAgent;
     InjectedScriptManager* m_injectedScriptManager;
     std::unique_ptr<InspectorProfilerFrontendDispatcher> m_frontendDispatcher;
+    RefPtr<InspectorProfilerBackendDispatcher> m_backendDispatcher;
     bool m_enabled;
     bool m_profileHeadersRequested;
     bool m_recordingCPUProfile;
index 208802d..38dcdaa 100644 (file)
@@ -79,12 +79,13 @@ namespace WebCore {
 void InspectorResourceAgent::didCreateFrontendAndBackend(InspectorFrontendChannel* frontendChannel, InspectorBackendDispatcher* backendDispatcher)
 {
     m_frontendDispatcher = std::make_unique<InspectorNetworkFrontendDispatcher>(frontendChannel);
-    backendDispatcher->registerAgent(this);
+    m_backendDispatcher = InspectorNetworkBackendDispatcher::create(backendDispatcher, this);
 }
 
 void InspectorResourceAgent::willDestroyFrontendAndBackend()
 {
     m_frontendDispatcher = nullptr;
+    m_backendDispatcher.clear();
 
     ErrorString error;
     disable(&error);
index afea1ee..8c27f94 100644 (file)
@@ -76,7 +76,7 @@ struct WebSocketFrame;
 
 typedef String ErrorString;
 
-class InspectorResourceAgent : public InspectorBaseAgent, public InspectorBackendDispatcher::NetworkCommandHandler {
+class InspectorResourceAgent : public InspectorBaseAgent, public InspectorNetworkBackendDispatcherHandler {
 public:
     static PassOwnPtr<InspectorResourceAgent> create(InstrumentingAgents* instrumentingAgents, InspectorPageAgent* pageAgent, InspectorClient* client)
     {
@@ -154,6 +154,7 @@ private:
     InspectorPageAgent* m_pageAgent;
     InspectorClient* m_client;
     std::unique_ptr<InspectorNetworkFrontendDispatcher> m_frontendDispatcher;
+    RefPtr<InspectorNetworkBackendDispatcher> m_backendDispatcher;
     String m_userAgentOverride;
     OwnPtr<NetworkResourcesData> m_resourcesData;
     bool m_enabled;
index 3e35219..9b57e2b 100644 (file)
@@ -51,7 +51,7 @@ class WorkerGlobalScope;
 
 typedef String ErrorString;
 
-class InspectorRuntimeAgent : public InspectorBaseAgent, public InspectorBackendDispatcher::RuntimeCommandHandler {
+class InspectorRuntimeAgent : public InspectorBaseAgent, public InspectorRuntimeBackendDispatcherHandler {
     WTF_MAKE_NONCOPYABLE(InspectorRuntimeAgent);
 public:
     virtual ~InspectorRuntimeAgent();
index f04dc23..4c88b1b 100644 (file)
@@ -68,12 +68,13 @@ InspectorTimelineAgent::~InspectorTimelineAgent()
 void InspectorTimelineAgent::didCreateFrontendAndBackend(InspectorFrontendChannel* frontendChannel, InspectorBackendDispatcher* backendDispatcher)
 {
     m_frontendDispatcher = std::make_unique<InspectorTimelineFrontendDispatcher>(frontendChannel);
-    backendDispatcher->registerAgent(this);
+    m_backendDispatcher = InspectorTimelineBackendDispatcher::create(backendDispatcher, this);
 }
 
 void InspectorTimelineAgent::willDestroyFrontendAndBackend()
 {
     m_frontendDispatcher = nullptr;
+    m_backendDispatcher.clear();
 
     ErrorString error;
     stop(&error);
index 707e227..45dc2f3 100644 (file)
@@ -122,7 +122,7 @@ private:
 
 class InspectorTimelineAgent
     : public InspectorBaseAgent
-    , public InspectorBackendDispatcher::TimelineCommandHandler {
+    , public InspectorTimelineBackendDispatcherHandler {
     WTF_MAKE_NONCOPYABLE(InspectorTimelineAgent);
 public:
     enum InspectorType { PageInspector, WorkerInspector };
@@ -259,6 +259,7 @@ private:
     TimelineTimeConverter m_timeConverter;
 
     std::unique_ptr<InspectorTimelineFrontendDispatcher> m_frontendDispatcher;
+    RefPtr<InspectorTimelineBackendDispatcher> m_backendDispatcher;
     double m_timestampOffset;
 
     Vector<TimelineRecordEntry> m_recordStack;
index 25d2293..f648549 100644 (file)
@@ -122,7 +122,7 @@ InspectorWorkerAgent::~InspectorWorkerAgent()
 void InspectorWorkerAgent::didCreateFrontendAndBackend(InspectorFrontendChannel* frontendChannel, InspectorBackendDispatcher* backendDispatcher)
 {
     m_frontendDispatcher = std::make_unique<InspectorWorkerFrontendDispatcher>(frontendChannel);
-    backendDispatcher->registerAgent(this);
+    m_backendDispatcher = InspectorWorkerBackendDispatcher::create(backendDispatcher, this);
 }
 
 void InspectorWorkerAgent::willDestroyFrontendAndBackend()
@@ -131,6 +131,7 @@ void InspectorWorkerAgent::willDestroyFrontendAndBackend()
     disable(nullptr);
 
     m_frontendDispatcher = nullptr;
+    m_backendDispatcher.clear();
 }
 
 void InspectorWorkerAgent::enable(ErrorString*)
index c81cf0f..78559de 100644 (file)
@@ -46,7 +46,7 @@ class WorkerGlobalScopeProxy;
 
 typedef String ErrorString;
 
-class InspectorWorkerAgent : public InspectorBaseAgent, public InspectorBackendDispatcher::WorkerCommandHandler {
+class InspectorWorkerAgent : public InspectorBaseAgent, public InspectorWorkerBackendDispatcherHandler {
 public:
     static PassOwnPtr<InspectorWorkerAgent> create(InstrumentingAgents*);
     ~InspectorWorkerAgent();
@@ -75,6 +75,7 @@ private:
     void destroyWorkerFrontendChannels();
 
     std::unique_ptr<InspectorWorkerFrontendDispatcher> m_frontendDispatcher;
+    RefPtr<InspectorWorkerBackendDispatcher> m_backendDispatcher;
     bool m_enabled;
     bool m_shouldPauseDedicatedWorkerOnStart;
 
index b883b98..57b3b30 100644 (file)
@@ -66,12 +66,13 @@ PageRuntimeAgent::~PageRuntimeAgent()
 void PageRuntimeAgent::didCreateFrontendAndBackend(InspectorFrontendChannel* frontendChannel, InspectorBackendDispatcher* backendDispatcher)
 {
     m_frontendDispatcher = std::make_unique<InspectorRuntimeFrontendDispatcher>(frontendChannel);
-    backendDispatcher->registerAgent(this);
+    m_backendDispatcher = InspectorRuntimeBackendDispatcher::create(backendDispatcher, this);
 }
 
 void PageRuntimeAgent::willDestroyFrontendAndBackend()
 {
     m_frontendDispatcher = nullptr;
+    m_backendDispatcher.clear();
 
     String errorString;
     disable(&errorString);
index e6b413d..e8b33b2 100644 (file)
@@ -71,6 +71,7 @@ private:
     Page* m_inspectedPage;
     InspectorPageAgent* m_pageAgent;
     std::unique_ptr<InspectorRuntimeFrontendDispatcher> m_frontendDispatcher;
+    RefPtr<InspectorRuntimeBackendDispatcher> m_backendDispatcher;
     bool m_mainWorldContextCreated;
 };
 
index 194c504..0ab9033 100644 (file)
@@ -59,11 +59,12 @@ WorkerRuntimeAgent::~WorkerRuntimeAgent()
 
 void WorkerRuntimeAgent::didCreateFrontendAndBackend(InspectorFrontendChannel*, InspectorBackendDispatcher* backendDispatcher)
 {
-    backendDispatcher->registerAgent(this);
+    m_backendDispatcher = InspectorRuntimeBackendDispatcher::create(backendDispatcher, this);
 }
 
 void WorkerRuntimeAgent::willDestroyFrontendAndBackend()
 {
+    m_backendDispatcher.clear();
 }
 
 InjectedScript WorkerRuntimeAgent::injectedScriptForEval(ErrorString* error, const int* executionContextId)
index 6c326a6..3172275 100644 (file)
@@ -64,6 +64,7 @@ private:
     virtual void muteConsole();
     virtual void unmuteConsole();
     WorkerGlobalScope* m_workerGlobalScope;
+    RefPtr<InspectorRuntimeBackendDispatcher> m_backendDispatcher;
     bool m_paused;
 };