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 "InspectorValues.h"
31 #include <wtf/PassRefPtr.h>
32 #include <wtf/RefCounted.h>
33 #include <wtf/text/WTFString.h>
37 class InspectorBackendDispatcher
;
38 class InspectorFrontendChannel
;
39 typedef String ErrorString
;
41 class InspectorSupplementalBackendDispatcher
: public RefCounted
<InspectorSupplementalBackendDispatcher
> {
43 InspectorSupplementalBackendDispatcher(InspectorBackendDispatcher
* backendDispatcher
) : m_backendDispatcher(backendDispatcher
) { }
44 virtual ~InspectorSupplementalBackendDispatcher() { }
45 virtual void dispatch(long callId
, const String
& method
, PassRefPtr
<InspectorObject
> message
) = 0;
47 RefPtr
<InspectorBackendDispatcher
> m_backendDispatcher
;
50 class JS_EXPORT_PRIVATE InspectorBackendDispatcher
: public RefCounted
<InspectorBackendDispatcher
> {
52 static PassRefPtr
<InspectorBackendDispatcher
> create(InspectorFrontendChannel
*);
54 class JS_EXPORT_PRIVATE CallbackBase
: public RefCounted
<CallbackBase
> {
56 CallbackBase(PassRefPtr
<InspectorBackendDispatcher
>, int id
);
58 bool isActive() const;
59 void sendFailure(const ErrorString
&);
60 void disable() { m_alreadySent
= true; }
63 void sendIfActive(PassRefPtr
<InspectorObject
> partialMessage
, const ErrorString
& invocationError
);
66 RefPtr
<InspectorBackendDispatcher
> m_backendDispatcher
;
71 void clearFrontend() { m_inspectorFrontendChannel
= nullptr; }
72 bool isActive() const { return !!m_inspectorFrontendChannel
; }
74 enum CommonErrorCode
{
83 void registerDispatcherForDomain(const String
& domain
, InspectorSupplementalBackendDispatcher
*);
84 void dispatch(const String
& message
);
85 void sendResponse(long callId
, PassRefPtr
<InspectorObject
> result
, const ErrorString
& invocationError
);
86 void reportProtocolError(const long* const callId
, CommonErrorCode
, const String
& errorMessage
) const;
87 void reportProtocolError(const long* const callId
, CommonErrorCode
, const String
& errorMessage
, PassRefPtr
<InspectorArray
> data
) const;
89 static int getInt(InspectorObject
*, const String
& name
, bool* valueFound
, InspectorArray
* protocolErrors
);
90 static double getDouble(InspectorObject
*, const String
& name
, bool* valueFound
, InspectorArray
* protocolErrors
);
91 static String
getString(InspectorObject
*, const String
& name
, bool* valueFound
, InspectorArray
* protocolErrors
);
92 static bool getBoolean(InspectorObject
*, const String
& name
, bool* valueFound
, InspectorArray
* protocolErrors
);
93 static PassRefPtr
<InspectorObject
> getObject(InspectorObject
*, const String
& name
, bool* valueFound
, InspectorArray
* protocolErrors
);
94 static PassRefPtr
<InspectorArray
> getArray(InspectorObject
*, const String
& name
, bool* valueFound
, InspectorArray
* protocolErrors
);
97 InspectorBackendDispatcher(InspectorFrontendChannel
* inspectorFrontendChannel
) : m_inspectorFrontendChannel(inspectorFrontendChannel
) { }
99 InspectorFrontendChannel
* m_inspectorFrontendChannel
;
100 HashMap
<String
, InspectorSupplementalBackendDispatcher
*> m_dispatchers
;
103 } // namespace Inspector
105 #endif // !defined(InspectorBackendDispatcher_h)