]> git.saurik.com Git - apple/javascriptcore.git/blob - inspector/remote/RemoteInspector.h
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / inspector / remote / RemoteInspector.h
1 /*
2 * Copyright (C) 2013 Apple Inc. All Rights Reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
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.
12 *
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.
24 */
25
26 #if ENABLE(REMOTE_INSPECTOR)
27
28 #ifndef RemoteInspector_h
29 #define RemoteInspector_h
30
31 #import "RemoteInspectorXPCConnection.h"
32 #import <wtf/Forward.h>
33 #import <wtf/HashMap.h>
34 #import <wtf/RetainPtr.h>
35
36 OBJC_CLASS NSDictionary;
37 OBJC_CLASS NSString;
38
39 namespace Inspector {
40
41 class RemoteInspectorClient;
42 class RemoteInspectorDebuggable;
43 class RemoteInspectorDebuggableConnection;
44 struct RemoteInspectorDebuggableInfo;
45
46 class JS_EXPORT_PRIVATE RemoteInspector final : public RemoteInspectorXPCConnection::Client {
47 public:
48 static void startDisabled();
49 static RemoteInspector& singleton();
50 friend class NeverDestroyed<RemoteInspector>;
51
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);
60
61 bool enabled() const { return m_enabled; }
62 bool hasActiveDebugSession() const { return m_hasActiveDebugSession; }
63
64 void start();
65 void stop();
66
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();
72
73 private:
74 RemoteInspector();
75
76 unsigned nextAvailableIdentifier();
77
78 enum class StopSource { API, XPCMessage };
79 void stopInternal(StopSource);
80
81 void setupXPCConnectionIfNeeded();
82
83 NSDictionary *listingForDebuggable(const RemoteInspectorDebuggableInfo&) const;
84 void pushListingNow();
85 void pushListingSoon();
86
87 void updateHasActiveDebugSession();
88
89 void sendAutomaticInspectionCandidateMessage();
90
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;
94
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);
104
105 static bool startEnabled;
106
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
110 // from any thread.
111 std::mutex m_mutex;
112
113 HashMap<unsigned, std::pair<RemoteInspectorDebuggable*, RemoteInspectorDebuggableInfo>> m_debuggableMap;
114 HashMap<unsigned, RefPtr<RemoteInspectorDebuggableConnection>> m_connectionMap;
115 RefPtr<RemoteInspectorXPCConnection> m_xpcConnection;
116
117 dispatch_queue_t m_xpcQueue;
118 unsigned m_nextAvailableIdentifier;
119 int m_notifyToken;
120 bool m_enabled;
121 bool m_hasActiveDebugSession;
122 bool m_pushScheduled;
123
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;
130 };
131
132 } // namespace Inspector
133
134 #endif // RemoteInspector_h
135
136 #endif // ENABLE(REMOTE_INSPECTOR)