blob: 68a3c53ecb9633426c93be4489ecb18169afd7f4 [file] [log] [blame]
joepeck@webkit.orgd2ecf372013-12-04 18:20:37 +00001/*
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
joepeck@webkit.orgd2ecf372013-12-04 18:20:37 +000031#import "RemoteInspectorXPCConnection.h"
32#import <wtf/Forward.h>
33#import <wtf/HashMap.h>
fpizlo@apple.com2082ad12015-08-19 18:18:19 +000034#import <wtf/Lock.h>
joepeck@webkit.org859b13b2014-05-10 01:30:13 +000035#import <wtf/RetainPtr.h>
joepeck@webkit.orgd2ecf372013-12-04 18:20:37 +000036
joepeck@webkit.orgd2ecf372013-12-04 18:20:37 +000037OBJC_CLASS NSDictionary;
commit-queue@webkit.org3bffb342014-01-16 05:05:55 +000038OBJC_CLASS NSString;
joepeck@webkit.orgd2ecf372013-12-04 18:20:37 +000039
40namespace Inspector {
41
joepeck@webkit.org859b13b2014-05-10 01:30:13 +000042class RemoteInspectorClient;
joepeck@webkit.orgd2ecf372013-12-04 18:20:37 +000043class RemoteInspectorDebuggable;
commit-queue@webkit.org3bffb342014-01-16 05:05:55 +000044class RemoteInspectorDebuggableConnection;
joepeck@webkit.orgd2ecf372013-12-04 18:20:37 +000045struct RemoteInspectorDebuggableInfo;
46
andersca@apple.com16d2dd42014-01-16 23:08:24 +000047class JS_EXPORT_PRIVATE RemoteInspector final : public RemoteInspectorXPCConnection::Client {
joepeck@webkit.orgd2ecf372013-12-04 18:20:37 +000048public:
commit-queue@webkit.org3bffb342014-01-16 05:05:55 +000049 static void startDisabled();
cdumez@apple.com4faf1ef2015-01-30 20:49:33 +000050 static RemoteInspector& singleton();
joepeck@webkit.orgd2ecf372013-12-04 18:20:37 +000051 friend class NeverDestroyed<RemoteInspector>;
52
53 void registerDebuggable(RemoteInspectorDebuggable*);
54 void unregisterDebuggable(RemoteInspectorDebuggable*);
55 void updateDebuggable(RemoteInspectorDebuggable*);
commit-queue@webkit.org14efa362014-09-23 18:38:24 +000056 void updateDebuggableAutomaticInspectCandidate(RemoteInspectorDebuggable*);
joepeck@webkit.orgd2ecf372013-12-04 18:20:37 +000057 void sendMessageToRemoteFrontend(unsigned identifier, const String& message);
commit-queue@webkit.org711b38a2014-03-01 02:51:39 +000058 void setupFailed(unsigned identifier);
commit-queue@webkit.orgaad25492014-09-26 23:25:17 +000059 void setupCompleted(unsigned identifier);
commit-queue@webkit.org14efa362014-09-23 18:38:24 +000060 bool waitingForAutomaticInspection(unsigned identifier);
joepeck@webkit.orgd2ecf372013-12-04 18:20:37 +000061
62 bool enabled() const { return m_enabled; }
63 bool hasActiveDebugSession() const { return m_hasActiveDebugSession; }
64
65 void start();
66 void stop();
67
joepeck@webkit.org859b13b2014-05-10 01:30:13 +000068 bool hasParentProcessInformation() const { return m_parentProcessIdentifier != 0; }
69 pid_t parentProcessIdentifier() const { return m_parentProcessIdentifier; }
70 RetainPtr<CFDataRef> parentProcessAuditData() const { return m_parentProcessAuditData; }
71 void setParentProcessInformation(pid_t, RetainPtr<CFDataRef> auditData);
72 void setParentProcessInfomationIsDelayed();
73
joepeck@webkit.orgd2ecf372013-12-04 18:20:37 +000074private:
75 RemoteInspector();
76
77 unsigned nextAvailableIdentifier();
78
commit-queue@webkit.org58619b52014-04-09 00:12:11 +000079 enum class StopSource { API, XPCMessage };
80 void stopInternal(StopSource);
81
joepeck@webkit.orgd2ecf372013-12-04 18:20:37 +000082 void setupXPCConnectionIfNeeded();
83
84 NSDictionary *listingForDebuggable(const RemoteInspectorDebuggableInfo&) const;
85 void pushListingNow();
86 void pushListingSoon();
87
88 void updateHasActiveDebugSession();
89
commit-queue@webkit.org14efa362014-09-23 18:38:24 +000090 void sendAutomaticInspectionCandidateMessage();
91
commit-queue@webkit.org2dfe6cb2014-01-16 19:42:50 +000092 virtual void xpcConnectionReceivedMessage(RemoteInspectorXPCConnection*, NSString *messageName, NSDictionary *userInfo) override;
93 virtual void xpcConnectionFailed(RemoteInspectorXPCConnection*) override;
94 virtual void xpcConnectionUnhandledMessage(RemoteInspectorXPCConnection*, xpc_object_t) override;
joepeck@webkit.orgd2ecf372013-12-04 18:20:37 +000095
96 void receivedSetupMessage(NSDictionary *userInfo);
97 void receivedDataMessage(NSDictionary *userInfo);
98 void receivedDidCloseMessage(NSDictionary *userInfo);
99 void receivedGetListingMessage(NSDictionary *userInfo);
100 void receivedIndicateMessage(NSDictionary *userInfo);
joepeck@webkit.org859b13b2014-05-10 01:30:13 +0000101 void receivedProxyApplicationSetupMessage(NSDictionary *userInfo);
joepeck@webkit.orgd2ecf372013-12-04 18:20:37 +0000102 void receivedConnectionDiedMessage(NSDictionary *userInfo);
commit-queue@webkit.org14efa362014-09-23 18:38:24 +0000103 void receivedAutomaticInspectionConfigurationMessage(NSDictionary *userInfo);
104 void receivedAutomaticInspectionRejectMessage(NSDictionary *userInfo);
joepeck@webkit.orgd2ecf372013-12-04 18:20:37 +0000105
commit-queue@webkit.org3bffb342014-01-16 05:05:55 +0000106 static bool startEnabled;
107
joepeck@webkit.orgd2ecf372013-12-04 18:20:37 +0000108 // Debuggables can be registered from any thread at any time.
109 // Any debuggable can send messages over the XPC connection.
110 // So lock access to all maps and state as they can change
111 // from any thread.
fpizlo@apple.com2082ad12015-08-19 18:18:19 +0000112 Lock m_mutex;
joepeck@webkit.orgd2ecf372013-12-04 18:20:37 +0000113
114 HashMap<unsigned, std::pair<RemoteInspectorDebuggable*, RemoteInspectorDebuggableInfo>> m_debuggableMap;
115 HashMap<unsigned, RefPtr<RemoteInspectorDebuggableConnection>> m_connectionMap;
commit-queue@webkit.orgca88d4a2014-01-28 04:55:55 +0000116 RefPtr<RemoteInspectorXPCConnection> m_xpcConnection;
joepeck@webkit.org859b13b2014-05-10 01:30:13 +0000117
commit-queue@webkit.org6ffeece62014-02-07 22:31:00 +0000118 dispatch_queue_t m_xpcQueue;
joepeck@webkit.orgd2ecf372013-12-04 18:20:37 +0000119 unsigned m_nextAvailableIdentifier;
120 int m_notifyToken;
121 bool m_enabled;
122 bool m_hasActiveDebugSession;
123 bool m_pushScheduled;
joepeck@webkit.org859b13b2014-05-10 01:30:13 +0000124
125 pid_t m_parentProcessIdentifier;
126 RetainPtr<CFDataRef> m_parentProcessAuditData;
127 bool m_shouldSendParentProcessInformation;
commit-queue@webkit.org14efa362014-09-23 18:38:24 +0000128 bool m_automaticInspectionEnabled;
129 bool m_automaticInspectionPaused;
130 unsigned m_automaticInspectionCandidateIdentifier;
joepeck@webkit.orgd2ecf372013-12-04 18:20:37 +0000131};
132
133} // namespace Inspector
134
commit-queue@webkit.org3bffb342014-01-16 05:05:55 +0000135#endif // RemoteInspector_h
joepeck@webkit.orgd2ecf372013-12-04 18:20:37 +0000136
commit-queue@webkit.org3bffb342014-01-16 05:05:55 +0000137#endif // ENABLE(REMOTE_INSPECTOR)