2 * Copyright (C) 2013 Apple Inc. All Rights Reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #if ENABLE(REMOTE_INSPECTOR)
28 #ifndef RemoteInspector_h
29 #define RemoteInspector_h
31 #import "RemoteInspectorXPCConnection.h"
32 #import <wtf/Forward.h>
33 #import <wtf/HashMap.h>
34 #import <wtf/RetainPtr.h>
36 OBJC_CLASS NSDictionary
;
41 class RemoteInspectorClient
;
42 class RemoteInspectorDebuggable
;
43 class RemoteInspectorDebuggableConnection
;
44 struct RemoteInspectorDebuggableInfo
;
46 class JS_EXPORT_PRIVATE RemoteInspector final
: public RemoteInspectorXPCConnection::Client
{
48 static void startDisabled();
49 static RemoteInspector
& singleton();
50 friend class NeverDestroyed
<RemoteInspector
>;
52 void registerDebuggable(RemoteInspectorDebuggable
*);
53 void unregisterDebuggable(RemoteInspectorDebuggable
*);
54 void updateDebuggable(RemoteInspectorDebuggable
*);
55 void updateDebuggableAutomaticInspectCandidate(RemoteInspectorDebuggable
*);
56 void sendMessageToRemoteFrontend(unsigned identifier
, const String
& message
);
57 void setupFailed(unsigned identifier
);
58 void setupCompleted(unsigned identifier
);
59 bool waitingForAutomaticInspection(unsigned identifier
);
61 bool enabled() const { return m_enabled
; }
62 bool hasActiveDebugSession() const { return m_hasActiveDebugSession
; }
67 bool hasParentProcessInformation() const { return m_parentProcessIdentifier
!= 0; }
68 pid_t
parentProcessIdentifier() const { return m_parentProcessIdentifier
; }
69 RetainPtr
<CFDataRef
> parentProcessAuditData() const { return m_parentProcessAuditData
; }
70 void setParentProcessInformation(pid_t
, RetainPtr
<CFDataRef
> auditData
);
71 void setParentProcessInfomationIsDelayed();
76 unsigned nextAvailableIdentifier();
78 enum class StopSource
{ API
, XPCMessage
};
79 void stopInternal(StopSource
);
81 void setupXPCConnectionIfNeeded();
83 NSDictionary
*listingForDebuggable(const RemoteInspectorDebuggableInfo
&) const;
84 void pushListingNow();
85 void pushListingSoon();
87 void updateHasActiveDebugSession();
89 void sendAutomaticInspectionCandidateMessage();
91 virtual void xpcConnectionReceivedMessage(RemoteInspectorXPCConnection
*, NSString
*messageName
, NSDictionary
*userInfo
) override
;
92 virtual void xpcConnectionFailed(RemoteInspectorXPCConnection
*) override
;
93 virtual void xpcConnectionUnhandledMessage(RemoteInspectorXPCConnection
*, xpc_object_t
) override
;
95 void receivedSetupMessage(NSDictionary
*userInfo
);
96 void receivedDataMessage(NSDictionary
*userInfo
);
97 void receivedDidCloseMessage(NSDictionary
*userInfo
);
98 void receivedGetListingMessage(NSDictionary
*userInfo
);
99 void receivedIndicateMessage(NSDictionary
*userInfo
);
100 void receivedProxyApplicationSetupMessage(NSDictionary
*userInfo
);
101 void receivedConnectionDiedMessage(NSDictionary
*userInfo
);
102 void receivedAutomaticInspectionConfigurationMessage(NSDictionary
*userInfo
);
103 void receivedAutomaticInspectionRejectMessage(NSDictionary
*userInfo
);
105 static bool startEnabled
;
107 // Debuggables can be registered from any thread at any time.
108 // Any debuggable can send messages over the XPC connection.
109 // So lock access to all maps and state as they can change
113 HashMap
<unsigned, std::pair
<RemoteInspectorDebuggable
*, RemoteInspectorDebuggableInfo
>> m_debuggableMap
;
114 HashMap
<unsigned, RefPtr
<RemoteInspectorDebuggableConnection
>> m_connectionMap
;
115 RefPtr
<RemoteInspectorXPCConnection
> m_xpcConnection
;
117 dispatch_queue_t m_xpcQueue
;
118 unsigned m_nextAvailableIdentifier
;
121 bool m_hasActiveDebugSession
;
122 bool m_pushScheduled
;
124 pid_t m_parentProcessIdentifier
;
125 RetainPtr
<CFDataRef
> m_parentProcessAuditData
;
126 bool m_shouldSendParentProcessInformation
;
127 bool m_automaticInspectionEnabled
;
128 bool m_automaticInspectionPaused
;
129 unsigned m_automaticInspectionCandidateIdentifier
;
132 } // namespace Inspector
134 #endif // RemoteInspector_h
136 #endif // ENABLE(REMOTE_INSPECTOR)