2 * Copyright (C) 2013 Apple Inc. All Rights Reserved.
3 * Copyright (C) 2011 The Chromium Authors. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #ifndef InspectorBackendDispatcher_h
28 #define InspectorBackendDispatcher_h
30 #include "InspectorProtocolTypes.h"
31 #include <wtf/RefCounted.h>
32 #include <wtf/text/WTFString.h>
36 class BackendDispatcher
;
37 class FrontendChannel
;
39 typedef String ErrorString
;
41 class SupplementalBackendDispatcher
: public RefCounted
<SupplementalBackendDispatcher
> {
43 SupplementalBackendDispatcher(BackendDispatcher
& backendDispatcher
)
44 : m_backendDispatcher(backendDispatcher
) { }
45 virtual ~SupplementalBackendDispatcher() { }
46 virtual void dispatch(long callId
, const String
& method
, Ref
<InspectorObject
>&& message
) = 0;
48 Ref
<BackendDispatcher
> m_backendDispatcher
;
51 class JS_EXPORT_PRIVATE BackendDispatcher
: public RefCounted
<BackendDispatcher
> {
53 static Ref
<BackendDispatcher
> create(FrontendChannel
*);
55 class JS_EXPORT_PRIVATE CallbackBase
: public RefCounted
<CallbackBase
> {
57 CallbackBase(Ref
<BackendDispatcher
>&&, int id
);
59 bool isActive() const;
60 void sendFailure(const ErrorString
&);
61 void disable() { m_alreadySent
= true; }
64 void sendIfActive(RefPtr
<InspectorObject
>&& partialMessage
, const ErrorString
& invocationError
);
67 Ref
<BackendDispatcher
> m_backendDispatcher
;
72 void clearFrontend() { m_frontendChannel
= nullptr; }
73 bool isActive() const { return !!m_frontendChannel
; }
75 enum CommonErrorCode
{
84 void registerDispatcherForDomain(const String
& domain
, SupplementalBackendDispatcher
*);
85 void dispatch(const String
& message
);
86 void sendResponse(long callId
, RefPtr
<InspectorObject
>&& result
, const ErrorString
& invocationError
);
87 void reportProtocolError(const long* const callId
, CommonErrorCode
, const String
& errorMessage
) const;
88 void reportProtocolError(const long* const callId
, CommonErrorCode
, const String
& errorMessage
, RefPtr
<Inspector::Protocol::Array
<String
>>&& data
) const;
90 static int getInteger(InspectorObject
*, const String
& name
, bool* valueFound
, Inspector::Protocol::Array
<String
>& protocolErrors
);
91 static double getDouble(InspectorObject
*, const String
& name
, bool* valueFound
, Inspector::Protocol::Array
<String
>& protocolErrors
);
92 static String
getString(InspectorObject
*, const String
& name
, bool* valueFound
, Inspector::Protocol::Array
<String
>& protocolErrors
);
93 static bool getBoolean(InspectorObject
*, const String
& name
, bool* valueFound
, Inspector::Protocol::Array
<String
>& protocolErrors
);
94 static RefPtr
<InspectorValue
> getValue(InspectorObject
*, const String
& name
, bool* valueFound
, Inspector::Protocol::Array
<String
>& protocolErrors
);
95 static RefPtr
<InspectorObject
> getObject(InspectorObject
*, const String
& name
, bool* valueFound
, Inspector::Protocol::Array
<String
>& protocolErrors
);
96 static RefPtr
<InspectorArray
> getArray(InspectorObject
*, const String
& name
, bool* valueFound
, Inspector::Protocol::Array
<String
>& protocolErrors
);
99 BackendDispatcher(FrontendChannel
* FrontendChannel
)
100 : m_frontendChannel(FrontendChannel
) { }
102 FrontendChannel
* m_frontendChannel
;
103 HashMap
<String
, SupplementalBackendDispatcher
*> m_dispatchers
;
106 } // namespace Inspector
108 #endif // !defined(InspectorBackendDispatcher_h)