joepeck@webkit.org | d2ecf37 | 2013-12-04 18:20:37 +0000 | [diff] [blame] | 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 | |
joepeck@webkit.org | d2ecf37 | 2013-12-04 18:20:37 +0000 | [diff] [blame] | 31 | #import "RemoteInspectorXPCConnection.h" |
| 32 | #import <wtf/Forward.h> |
| 33 | #import <wtf/HashMap.h> |
fpizlo@apple.com | 2082ad1 | 2015-08-19 18:18:19 +0000 | [diff] [blame] | 34 | #import <wtf/Lock.h> |
joepeck@webkit.org | 859b13b | 2014-05-10 01:30:13 +0000 | [diff] [blame] | 35 | #import <wtf/RetainPtr.h> |
joepeck@webkit.org | d2ecf37 | 2013-12-04 18:20:37 +0000 | [diff] [blame] | 36 | |
joepeck@webkit.org | d2ecf37 | 2013-12-04 18:20:37 +0000 | [diff] [blame] | 37 | OBJC_CLASS NSDictionary; |
commit-queue@webkit.org | 3bffb34 | 2014-01-16 05:05:55 +0000 | [diff] [blame] | 38 | OBJC_CLASS NSString; |
joepeck@webkit.org | d2ecf37 | 2013-12-04 18:20:37 +0000 | [diff] [blame] | 39 | |
| 40 | namespace Inspector { |
| 41 | |
joepeck@webkit.org | 859b13b | 2014-05-10 01:30:13 +0000 | [diff] [blame] | 42 | class RemoteInspectorClient; |
joepeck@webkit.org | d2ecf37 | 2013-12-04 18:20:37 +0000 | [diff] [blame] | 43 | class RemoteInspectorDebuggable; |
commit-queue@webkit.org | 3bffb34 | 2014-01-16 05:05:55 +0000 | [diff] [blame] | 44 | class RemoteInspectorDebuggableConnection; |
joepeck@webkit.org | d2ecf37 | 2013-12-04 18:20:37 +0000 | [diff] [blame] | 45 | struct RemoteInspectorDebuggableInfo; |
| 46 | |
andersca@apple.com | 16d2dd4 | 2014-01-16 23:08:24 +0000 | [diff] [blame] | 47 | class JS_EXPORT_PRIVATE RemoteInspector final : public RemoteInspectorXPCConnection::Client { |
joepeck@webkit.org | d2ecf37 | 2013-12-04 18:20:37 +0000 | [diff] [blame] | 48 | public: |
commit-queue@webkit.org | 3bffb34 | 2014-01-16 05:05:55 +0000 | [diff] [blame] | 49 | static void startDisabled(); |
cdumez@apple.com | 4faf1ef | 2015-01-30 20:49:33 +0000 | [diff] [blame] | 50 | static RemoteInspector& singleton(); |
joepeck@webkit.org | d2ecf37 | 2013-12-04 18:20:37 +0000 | [diff] [blame] | 51 | friend class NeverDestroyed<RemoteInspector>; |
| 52 | |
| 53 | void registerDebuggable(RemoteInspectorDebuggable*); |
| 54 | void unregisterDebuggable(RemoteInspectorDebuggable*); |
| 55 | void updateDebuggable(RemoteInspectorDebuggable*); |
commit-queue@webkit.org | 14efa36 | 2014-09-23 18:38:24 +0000 | [diff] [blame] | 56 | void updateDebuggableAutomaticInspectCandidate(RemoteInspectorDebuggable*); |
joepeck@webkit.org | d2ecf37 | 2013-12-04 18:20:37 +0000 | [diff] [blame] | 57 | void sendMessageToRemoteFrontend(unsigned identifier, const String& message); |
commit-queue@webkit.org | 711b38a | 2014-03-01 02:51:39 +0000 | [diff] [blame] | 58 | void setupFailed(unsigned identifier); |
commit-queue@webkit.org | aad2549 | 2014-09-26 23:25:17 +0000 | [diff] [blame] | 59 | void setupCompleted(unsigned identifier); |
commit-queue@webkit.org | 14efa36 | 2014-09-23 18:38:24 +0000 | [diff] [blame] | 60 | bool waitingForAutomaticInspection(unsigned identifier); |
joepeck@webkit.org | d2ecf37 | 2013-12-04 18:20:37 +0000 | [diff] [blame] | 61 | |
| 62 | bool enabled() const { return m_enabled; } |
| 63 | bool hasActiveDebugSession() const { return m_hasActiveDebugSession; } |
| 64 | |
| 65 | void start(); |
| 66 | void stop(); |
| 67 | |
joepeck@webkit.org | 859b13b | 2014-05-10 01:30:13 +0000 | [diff] [blame] | 68 | 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.org | d2ecf37 | 2013-12-04 18:20:37 +0000 | [diff] [blame] | 74 | private: |
| 75 | RemoteInspector(); |
| 76 | |
| 77 | unsigned nextAvailableIdentifier(); |
| 78 | |
commit-queue@webkit.org | 58619b5 | 2014-04-09 00:12:11 +0000 | [diff] [blame] | 79 | enum class StopSource { API, XPCMessage }; |
| 80 | void stopInternal(StopSource); |
| 81 | |
joepeck@webkit.org | d2ecf37 | 2013-12-04 18:20:37 +0000 | [diff] [blame] | 82 | void setupXPCConnectionIfNeeded(); |
| 83 | |
| 84 | NSDictionary *listingForDebuggable(const RemoteInspectorDebuggableInfo&) const; |
| 85 | void pushListingNow(); |
| 86 | void pushListingSoon(); |
| 87 | |
| 88 | void updateHasActiveDebugSession(); |
| 89 | |
commit-queue@webkit.org | 14efa36 | 2014-09-23 18:38:24 +0000 | [diff] [blame] | 90 | void sendAutomaticInspectionCandidateMessage(); |
| 91 | |
commit-queue@webkit.org | 2dfe6cb | 2014-01-16 19:42:50 +0000 | [diff] [blame] | 92 | 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.org | d2ecf37 | 2013-12-04 18:20:37 +0000 | [diff] [blame] | 95 | |
| 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.org | 859b13b | 2014-05-10 01:30:13 +0000 | [diff] [blame] | 101 | void receivedProxyApplicationSetupMessage(NSDictionary *userInfo); |
joepeck@webkit.org | d2ecf37 | 2013-12-04 18:20:37 +0000 | [diff] [blame] | 102 | void receivedConnectionDiedMessage(NSDictionary *userInfo); |
commit-queue@webkit.org | 14efa36 | 2014-09-23 18:38:24 +0000 | [diff] [blame] | 103 | void receivedAutomaticInspectionConfigurationMessage(NSDictionary *userInfo); |
| 104 | void receivedAutomaticInspectionRejectMessage(NSDictionary *userInfo); |
joepeck@webkit.org | d2ecf37 | 2013-12-04 18:20:37 +0000 | [diff] [blame] | 105 | |
commit-queue@webkit.org | 3bffb34 | 2014-01-16 05:05:55 +0000 | [diff] [blame] | 106 | static bool startEnabled; |
| 107 | |
joepeck@webkit.org | d2ecf37 | 2013-12-04 18:20:37 +0000 | [diff] [blame] | 108 | // 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.com | 2082ad1 | 2015-08-19 18:18:19 +0000 | [diff] [blame] | 112 | Lock m_mutex; |
joepeck@webkit.org | d2ecf37 | 2013-12-04 18:20:37 +0000 | [diff] [blame] | 113 | |
| 114 | HashMap<unsigned, std::pair<RemoteInspectorDebuggable*, RemoteInspectorDebuggableInfo>> m_debuggableMap; |
| 115 | HashMap<unsigned, RefPtr<RemoteInspectorDebuggableConnection>> m_connectionMap; |
commit-queue@webkit.org | ca88d4a | 2014-01-28 04:55:55 +0000 | [diff] [blame] | 116 | RefPtr<RemoteInspectorXPCConnection> m_xpcConnection; |
joepeck@webkit.org | 859b13b | 2014-05-10 01:30:13 +0000 | [diff] [blame] | 117 | |
commit-queue@webkit.org | 6ffeece6 | 2014-02-07 22:31:00 +0000 | [diff] [blame] | 118 | dispatch_queue_t m_xpcQueue; |
joepeck@webkit.org | d2ecf37 | 2013-12-04 18:20:37 +0000 | [diff] [blame] | 119 | unsigned m_nextAvailableIdentifier; |
| 120 | int m_notifyToken; |
| 121 | bool m_enabled; |
| 122 | bool m_hasActiveDebugSession; |
| 123 | bool m_pushScheduled; |
joepeck@webkit.org | 859b13b | 2014-05-10 01:30:13 +0000 | [diff] [blame] | 124 | |
| 125 | pid_t m_parentProcessIdentifier; |
| 126 | RetainPtr<CFDataRef> m_parentProcessAuditData; |
| 127 | bool m_shouldSendParentProcessInformation; |
commit-queue@webkit.org | 14efa36 | 2014-09-23 18:38:24 +0000 | [diff] [blame] | 128 | bool m_automaticInspectionEnabled; |
| 129 | bool m_automaticInspectionPaused; |
| 130 | unsigned m_automaticInspectionCandidateIdentifier; |
joepeck@webkit.org | d2ecf37 | 2013-12-04 18:20:37 +0000 | [diff] [blame] | 131 | }; |
| 132 | |
| 133 | } // namespace Inspector |
| 134 | |
commit-queue@webkit.org | 3bffb34 | 2014-01-16 05:05:55 +0000 | [diff] [blame] | 135 | #endif // RemoteInspector_h |
joepeck@webkit.org | d2ecf37 | 2013-12-04 18:20:37 +0000 | [diff] [blame] | 136 | |
commit-queue@webkit.org | 3bffb34 | 2014-01-16 05:05:55 +0000 | [diff] [blame] | 137 | #endif // ENABLE(REMOTE_INSPECTOR) |