summaryrefslogtreecommitdiff
path: root/Source/JavaScriptCore/inspector/remote
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2016-05-24 08:28:08 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2016-05-24 08:28:08 +0000
commita4e969f4965059196ca948db781e52f7cfebf19e (patch)
tree6ca352808c8fdc52006a0f33f6ae3c593b23867d /Source/JavaScriptCore/inspector/remote
parent41386e9cb918eed93b3f13648cbef387e371e451 (diff)
downloadWebKitGtk-tarball-a4e969f4965059196ca948db781e52f7cfebf19e.tar.gz
webkitgtk-2.12.3webkitgtk-2.12.3
Diffstat (limited to 'Source/JavaScriptCore/inspector/remote')
-rw-r--r--Source/JavaScriptCore/inspector/remote/RemoteAutomationTarget.cpp47
-rw-r--r--Source/JavaScriptCore/inspector/remote/RemoteAutomationTarget.h59
-rw-r--r--Source/JavaScriptCore/inspector/remote/RemoteConnectionToTarget.h98
-rw-r--r--Source/JavaScriptCore/inspector/remote/RemoteControllableTarget.cpp52
-rw-r--r--Source/JavaScriptCore/inspector/remote/RemoteControllableTarget.h72
-rw-r--r--Source/JavaScriptCore/inspector/remote/RemoteInspectionTarget.cpp72
-rw-r--r--Source/JavaScriptCore/inspector/remote/RemoteInspectionTarget.h78
-rw-r--r--Source/JavaScriptCore/inspector/remote/RemoteInspector.h157
-rw-r--r--Source/JavaScriptCore/inspector/remote/RemoteInspectorConstants.h105
-rw-r--r--Source/JavaScriptCore/inspector/remote/RemoteInspectorXPCConnection.h80
10 files changed, 820 insertions, 0 deletions
diff --git a/Source/JavaScriptCore/inspector/remote/RemoteAutomationTarget.cpp b/Source/JavaScriptCore/inspector/remote/RemoteAutomationTarget.cpp
new file mode 100644
index 000000000..565218c69
--- /dev/null
+++ b/Source/JavaScriptCore/inspector/remote/RemoteAutomationTarget.cpp
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2015, 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "RemoteAutomationTarget.h"
+
+#if ENABLE(REMOTE_INSPECTOR)
+
+#include "RemoteInspector.h"
+
+namespace Inspector {
+
+void RemoteAutomationTarget::setIsPaired(bool paired)
+{
+ if (m_paired == paired)
+ return;
+
+ m_paired = paired;
+
+ update();
+}
+
+} // namespace Inspector
+
+#endif // ENABLE(REMOTE_INSPECTOR)
diff --git a/Source/JavaScriptCore/inspector/remote/RemoteAutomationTarget.h b/Source/JavaScriptCore/inspector/remote/RemoteAutomationTarget.h
new file mode 100644
index 000000000..0b289db3a
--- /dev/null
+++ b/Source/JavaScriptCore/inspector/remote/RemoteAutomationTarget.h
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2015, 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if ENABLE(REMOTE_INSPECTOR)
+
+#ifndef RemoteAutomationTarget_h
+#define RemoteAutomationTarget_h
+
+#include "RemoteControllableTarget.h"
+#include <wtf/text/WTFString.h>
+
+namespace Inspector {
+
+class FrontendChannel;
+
+class JS_EXPORT_PRIVATE RemoteAutomationTarget : public RemoteControllableTarget {
+public:
+ virtual ~RemoteAutomationTarget() { }
+
+ bool isPaired() const { return m_paired; }
+ void setIsPaired(bool);
+
+ virtual String name() const = 0;
+ virtual RemoteControllableTarget::Type type() const override { return RemoteControllableTarget::Type::Automation; }
+ virtual bool remoteControlAllowed() const override { return !m_paired; };
+
+private:
+ bool m_paired { false };
+};
+
+} // namespace Inspector
+
+SPECIALIZE_TYPE_TRAITS_CONTROLLABLE_TARGET(Inspector::RemoteAutomationTarget, Automation)
+
+#endif // RemoteAutomationTarget_h
+
+#endif // ENABLE(REMOTE_INSPECTOR)
diff --git a/Source/JavaScriptCore/inspector/remote/RemoteConnectionToTarget.h b/Source/JavaScriptCore/inspector/remote/RemoteConnectionToTarget.h
new file mode 100644
index 000000000..d3e8d319b
--- /dev/null
+++ b/Source/JavaScriptCore/inspector/remote/RemoteConnectionToTarget.h
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2013, 2015 Apple Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if ENABLE(REMOTE_INSPECTOR)
+
+#ifndef RemoteConnectionToTarget_h
+#define RemoteConnectionToTarget_h
+
+#import "InspectorFrontendChannel.h"
+#import "RemoteConnectionToTarget.h"
+#import "RemoteInspector.h"
+#import <mutex>
+#import <wtf/BlockPtr.h>
+#import <wtf/Lock.h>
+#import <wtf/RetainPtr.h>
+#import <wtf/ThreadSafeRefCounted.h>
+
+OBJC_CLASS NSString;
+
+namespace Inspector {
+
+typedef Vector<BlockPtr<void ()>> RemoteTargetQueue;
+
+class RemoteConnectionToTarget final : public ThreadSafeRefCounted<RemoteConnectionToTarget>, public FrontendChannel {
+public:
+ RemoteConnectionToTarget(RemoteControllableTarget*, NSString *connectionIdentifier, NSString *destination);
+ virtual ~RemoteConnectionToTarget();
+
+ // Main API.
+ bool setup(bool isAutomaticInspection = false, bool automaticallyPause = false);
+ virtual void sendMessageToTarget(NSString *);
+ virtual void close();
+ virtual void targetClosed();
+
+ Optional<unsigned> targetIdentifier() const;
+ NSString *connectionIdentifier() const;
+ NSString *destination() const;
+
+ Lock& queueMutex() { return m_queueMutex; }
+ const RemoteTargetQueue& queue() const { return m_queue; }
+ void clearQueue() { m_queue.clear(); }
+
+ // FrontendChannel overrides.
+ virtual ConnectionType connectionType() const override { return ConnectionType::Remote; }
+ virtual bool sendMessageToFrontend(const String&) override;
+
+private:
+ void dispatchAsyncOnTarget(void (^block)());
+
+ void setupRunLoop();
+ void teardownRunLoop();
+ void queueTaskOnPrivateRunLoop(void (^block)());
+
+ // This connection from the RemoteInspector singleton to the InspectionTarget
+ // can be used on multiple threads. So any access to the target
+ // itself must take this mutex to ensure m_target is valid.
+ Lock m_targetMutex;
+
+ // If a target has a specific run loop it wants to evaluate on
+ // we setup our run loop sources on that specific run loop.
+ RetainPtr<CFRunLoopRef> m_runLoop;
+ RetainPtr<CFRunLoopSourceRef> m_runLoopSource;
+ RemoteTargetQueue m_queue;
+ Lock m_queueMutex;
+
+ RemoteControllableTarget* m_target { nullptr };
+ RetainPtr<NSString> m_connectionIdentifier;
+ RetainPtr<NSString> m_destination;
+ bool m_connected { false };
+};
+
+} // namespace Inspector
+
+#endif // RemoteConnectionToTarget_h
+
+#endif // ENABLE(REMOTE_INSPECTOR)
diff --git a/Source/JavaScriptCore/inspector/remote/RemoteControllableTarget.cpp b/Source/JavaScriptCore/inspector/remote/RemoteControllableTarget.cpp
new file mode 100644
index 000000000..f52852b15
--- /dev/null
+++ b/Source/JavaScriptCore/inspector/remote/RemoteControllableTarget.cpp
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "RemoteControllableTarget.h"
+
+#if ENABLE(REMOTE_INSPECTOR)
+
+#include "RemoteInspector.h"
+
+namespace Inspector {
+
+RemoteControllableTarget::~RemoteControllableTarget()
+{
+ RemoteInspector::singleton().unregisterTarget(this);
+}
+
+void RemoteControllableTarget::init()
+{
+ RemoteInspector::singleton().registerTarget(this);
+}
+
+void RemoteControllableTarget::update()
+{
+ RemoteInspector::singleton().updateTarget(this);
+}
+
+} // namespace Inspector
+
+#endif // ENABLE(REMOTE_INSPECTOR)
diff --git a/Source/JavaScriptCore/inspector/remote/RemoteControllableTarget.h b/Source/JavaScriptCore/inspector/remote/RemoteControllableTarget.h
new file mode 100644
index 000000000..349ad9ece
--- /dev/null
+++ b/Source/JavaScriptCore/inspector/remote/RemoteControllableTarget.h
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if ENABLE(REMOTE_INSPECTOR)
+
+#ifndef RemoteControllableTarget_h
+#define RemoteControllableTarget_h
+
+#include <CoreFoundation/CFRunLoop.h>
+#include <wtf/TypeCasts.h>
+#include <wtf/text/WTFString.h>
+
+namespace Inspector {
+
+class FrontendChannel;
+
+class JS_EXPORT_PRIVATE RemoteControllableTarget {
+public:
+ virtual ~RemoteControllableTarget();
+
+ void init();
+ void update();
+
+ virtual void connect(FrontendChannel*, bool isAutomaticConnection = false) = 0;
+ virtual void disconnect(FrontendChannel*) = 0;
+
+ unsigned targetIdentifier() const { return m_identifier; }
+ void setTargetIdentifier(unsigned identifier) { m_identifier = identifier; }
+
+ enum class Type { JavaScript, Web, Automation };
+ virtual Type type() const = 0;
+ virtual bool remoteControlAllowed() const = 0;
+ virtual void dispatchMessageFromRemote(const String& message) = 0;
+
+ // The dispatch block will be scheduled on a global run loop if null is returned.
+ virtual CFRunLoopRef targetRunLoop() { return nullptr; }
+private:
+ unsigned m_identifier {0};
+};
+
+} // namespace Inspector
+
+#define SPECIALIZE_TYPE_TRAITS_CONTROLLABLE_TARGET(ToClassName, ToClassType) \
+SPECIALIZE_TYPE_TRAITS_BEGIN(ToClassName) \
+ static bool isType(const Inspector::RemoteControllableTarget& target) { return target.type() == Inspector::RemoteControllableTarget::Type::ToClassType; } \
+SPECIALIZE_TYPE_TRAITS_END()
+
+#endif // RemoteControllableTarget_h
+
+#endif // ENABLE(REMOTE_INSPECTOR)
diff --git a/Source/JavaScriptCore/inspector/remote/RemoteInspectionTarget.cpp b/Source/JavaScriptCore/inspector/remote/RemoteInspectionTarget.cpp
new file mode 100644
index 000000000..5d5f3ebc7
--- /dev/null
+++ b/Source/JavaScriptCore/inspector/remote/RemoteInspectionTarget.cpp
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2013, 2015 Apple Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "RemoteInspectionTarget.h"
+
+#if ENABLE(REMOTE_INSPECTOR)
+
+#include "EventLoop.h"
+#include "RemoteInspector.h"
+
+namespace Inspector {
+
+bool RemoteInspectionTarget::remoteControlAllowed() const
+{
+ return remoteDebuggingAllowed() || hasLocalDebugger();
+}
+
+void RemoteInspectionTarget::setRemoteDebuggingAllowed(bool allowed)
+{
+ if (m_allowed == allowed)
+ return;
+
+ m_allowed = allowed;
+
+ if (m_allowed && automaticInspectionAllowed())
+ RemoteInspector::singleton().updateAutomaticInspectionCandidate(this);
+ else
+ RemoteInspector::singleton().updateTarget(this);
+}
+
+void RemoteInspectionTarget::pauseWaitingForAutomaticInspection()
+{
+ ASSERT(targetIdentifier());
+ ASSERT(m_allowed);
+ ASSERT(automaticInspectionAllowed());
+
+ EventLoop loop;
+ while (RemoteInspector::singleton().waitingForAutomaticInspection(targetIdentifier()) && !loop.ended())
+ loop.cycle();
+}
+
+void RemoteInspectionTarget::unpauseForInitializedInspector()
+{
+ RemoteInspector::singleton().setupCompleted(targetIdentifier());
+}
+
+} // namespace Inspector
+
+#endif // ENABLE(REMOTE_INSPECTOR)
diff --git a/Source/JavaScriptCore/inspector/remote/RemoteInspectionTarget.h b/Source/JavaScriptCore/inspector/remote/RemoteInspectionTarget.h
new file mode 100644
index 000000000..f595ddffd
--- /dev/null
+++ b/Source/JavaScriptCore/inspector/remote/RemoteInspectionTarget.h
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2013, 2015 Apple Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if ENABLE(REMOTE_INSPECTOR)
+
+#ifndef RemoteInspectionTarget_h
+#define RemoteInspectionTarget_h
+
+#include "RemoteControllableTarget.h"
+#include <wtf/RetainPtr.h>
+#include <wtf/TypeCasts.h>
+#include <wtf/text/WTFString.h>
+
+namespace Inspector {
+
+class FrontendChannel;
+
+class JS_EXPORT_PRIVATE RemoteInspectionTarget : public RemoteControllableTarget {
+public:
+ bool remoteDebuggingAllowed() const { return m_allowed; }
+ void setRemoteDebuggingAllowed(bool);
+
+ CFRunLoopRef targetRunLoop() override { return m_runLoop.get(); }
+ void setTargetRunLoop(CFRunLoopRef runLoop) { m_runLoop = runLoop; }
+
+ virtual String name() const { return String(); } // JavaScript and Web
+ virtual String url() const { return String(); } // Web
+ virtual bool hasLocalDebugger() const = 0;
+
+ virtual void setIndicating(bool) { } // Default is to do nothing.
+ virtual void pause() { };
+
+ virtual bool automaticInspectionAllowed() const { return false; }
+ virtual void pauseWaitingForAutomaticInspection();
+ virtual void unpauseForInitializedInspector();
+
+ // RemoteControllableTarget overrides.
+ virtual bool remoteControlAllowed() const override;
+private:
+ bool m_allowed {false};
+ RetainPtr<CFRunLoopRef> m_runLoop;
+};
+
+} // namespace Inspector
+
+SPECIALIZE_TYPE_TRAITS_BEGIN(Inspector::RemoteInspectionTarget) \
+ static bool isType(const Inspector::RemoteControllableTarget& target) \
+ { \
+ return target.type() == Inspector::RemoteControllableTarget::Type::JavaScript \
+ || target.type() == Inspector::RemoteControllableTarget::Type::Web; \
+ }
+SPECIALIZE_TYPE_TRAITS_END()
+
+#endif // RemoteInspectionTarget_h
+
+#endif // ENABLE(REMOTE_INSPECTOR)
diff --git a/Source/JavaScriptCore/inspector/remote/RemoteInspector.h b/Source/JavaScriptCore/inspector/remote/RemoteInspector.h
new file mode 100644
index 000000000..3f2c50f88
--- /dev/null
+++ b/Source/JavaScriptCore/inspector/remote/RemoteInspector.h
@@ -0,0 +1,157 @@
+/*
+ * Copyright (C) 2013, 2015, 2016 Apple Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if ENABLE(REMOTE_INSPECTOR)
+
+#ifndef RemoteInspector_h
+#define RemoteInspector_h
+
+#import "RemoteInspectorXPCConnection.h"
+#import <wtf/Forward.h>
+#import <wtf/HashMap.h>
+#import <wtf/Lock.h>
+#import <wtf/RetainPtr.h>
+#import <wtf/Vector.h>
+
+OBJC_CLASS NSDictionary;
+OBJC_CLASS NSString;
+
+namespace Inspector {
+
+class RemoteAutomationTarget;
+class RemoteConnectionToTarget;
+class RemoteControllableTarget;
+class RemoteInspectionTarget;
+class RemoteInspectorClient;
+
+class JS_EXPORT_PRIVATE RemoteInspector final : public RemoteInspectorXPCConnection::Client {
+public:
+ class Client {
+ public:
+ virtual ~Client() { }
+ virtual bool remoteAutomationAllowed() const = 0;
+ virtual void requestAutomationSession(const String& sessionIdentifier) = 0;
+ };
+
+ static void startDisabled();
+ static RemoteInspector& singleton();
+ friend class NeverDestroyed<RemoteInspector>;
+
+ void registerTarget(RemoteControllableTarget*);
+ void unregisterTarget(RemoteControllableTarget*);
+ void updateTarget(RemoteControllableTarget*);
+ void sendMessageToRemote(unsigned targetIdentifier, const String& message);
+
+ void updateAutomaticInspectionCandidate(RemoteInspectionTarget*);
+ void setRemoteInspectorClient(RemoteInspector::Client*);
+
+ void setupFailed(unsigned targetIdentifier);
+ void setupCompleted(unsigned targetIdentifier);
+ bool waitingForAutomaticInspection(unsigned targetIdentifier);
+ void clientCapabilitiesDidChange() { pushListingsSoon(); }
+
+ bool enabled() const { return m_enabled; }
+ bool hasActiveDebugSession() const { return m_hasActiveDebugSession; }
+
+ void start();
+ void stop();
+
+ bool hasParentProcessInformation() const { return m_parentProcessIdentifier != 0; }
+ pid_t parentProcessIdentifier() const { return m_parentProcessIdentifier; }
+ RetainPtr<CFDataRef> parentProcessAuditData() const { return m_parentProcessAuditData; }
+ void setParentProcessInformation(pid_t, RetainPtr<CFDataRef> auditData);
+ void setParentProcessInfomationIsDelayed();
+
+private:
+ RemoteInspector();
+
+ unsigned nextAvailableTargetIdentifier();
+
+ enum class StopSource { API, XPCMessage };
+ void stopInternal(StopSource);
+
+ void setupXPCConnectionIfNeeded();
+
+ RetainPtr<NSDictionary> listingForTarget(const RemoteControllableTarget&) const;
+ RetainPtr<NSDictionary> listingForInspectionTarget(const RemoteInspectionTarget&) const;
+ RetainPtr<NSDictionary> listingForAutomationTarget(const RemoteAutomationTarget&) const;
+ void pushListingsNow();
+ void pushListingsSoon();
+
+ void updateHasActiveDebugSession();
+
+ void sendAutomaticInspectionCandidateMessage();
+
+ virtual void xpcConnectionReceivedMessage(RemoteInspectorXPCConnection*, NSString *messageName, NSDictionary *userInfo) override;
+ virtual void xpcConnectionFailed(RemoteInspectorXPCConnection*) override;
+ virtual void xpcConnectionUnhandledMessage(RemoteInspectorXPCConnection*, xpc_object_t) override;
+
+ void receivedSetupMessage(NSDictionary *userInfo);
+ void receivedDataMessage(NSDictionary *userInfo);
+ void receivedDidCloseMessage(NSDictionary *userInfo);
+ void receivedGetListingMessage(NSDictionary *userInfo);
+ void receivedIndicateMessage(NSDictionary *userInfo);
+ void receivedProxyApplicationSetupMessage(NSDictionary *userInfo);
+ void receivedConnectionDiedMessage(NSDictionary *userInfo);
+ void receivedAutomaticInspectionConfigurationMessage(NSDictionary *userInfo);
+ void receivedAutomaticInspectionRejectMessage(NSDictionary *userInfo);
+ void receivedAutomationSessionRequestMessage(NSDictionary *userInfo);
+
+ static bool startEnabled;
+
+ // Targets can be registered from any thread at any time.
+ // Any target can send messages over the XPC connection.
+ // So lock access to all maps and state as they can change
+ // from any thread.
+ Lock m_mutex;
+
+ HashMap<unsigned, RemoteControllableTarget*> m_targetMap;
+ HashMap<unsigned, RetainPtr<NSDictionary>> m_targetListingMap;
+ HashMap<unsigned, RefPtr<RemoteConnectionToTarget>> m_targetConnectionMap;
+
+ RefPtr<RemoteInspectorXPCConnection> m_relayConnection;
+
+ RemoteInspector::Client* m_client { nullptr };
+
+ dispatch_queue_t m_xpcQueue;
+ unsigned m_nextAvailableTargetIdentifier { 1 };
+ int m_notifyToken { 0 };
+ bool m_enabled { false };
+ bool m_hasActiveDebugSession { false };
+ bool m_pushScheduled { false };
+
+ pid_t m_parentProcessIdentifier { 0 };
+ RetainPtr<CFDataRef> m_parentProcessAuditData;
+ bool m_shouldSendParentProcessInformation { false };
+ bool m_automaticInspectionEnabled { false };
+ bool m_automaticInspectionPaused { false };
+ unsigned m_automaticInspectionCandidateTargetIdentifier { 0 };
+};
+
+} // namespace Inspector
+
+#endif // RemoteInspector_h
+
+#endif // ENABLE(REMOTE_INSPECTOR)
diff --git a/Source/JavaScriptCore/inspector/remote/RemoteInspectorConstants.h b/Source/JavaScriptCore/inspector/remote/RemoteInspectorConstants.h
new file mode 100644
index 000000000..db1806c59
--- /dev/null
+++ b/Source/JavaScriptCore/inspector/remote/RemoteInspectorConstants.h
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2011, 2016 Apple Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef RemoteInspectorConstants_h
+#define RemoteInspectorConstants_h
+
+// WIRConstants are "Web Inspector Relay" constants shared between
+// the WebInspector framework on the OS X side, webinspectord, and
+// iOS WebKit on the device side.
+
+#define WIRSimulatorTCPPortNumber 27753
+#define WIRXPCMachPortName "com.apple.webinspector"
+#define WIRXPCDebuggerServiceName "com.apple.webinspector.debugger"
+#define WIRServiceAvailableNotification "com.apple.webinspectord.available"
+#define WIRServiceAvailabilityCheckNotification "com.apple.webinspectord.availability_check"
+#define WIRServiceEnabledNotification "com.apple.webinspectord.enabled"
+#define WIRServiceDisabledNotification "com.apple.webinspectord.disabled"
+#define WIRAutomaticInspectionEnabledState "com.apple.webinspectord.automatic_inspection_enabled"
+
+
+#define WIRApplicationIdentifierKey @"WIRApplicationIdentifierKey"
+#define WIRApplicationBundleIdentifierKey @"WIRApplicationBundleIdentifierKey"
+#define WIRApplicationNameKey @"WIRApplicationNameKey"
+#define WIRIsApplicationProxyKey @"WIRIsApplicationProxyKey"
+#define WIRIsApplicationActiveKey @"WIRIsApplicationActiveKey"
+#define WIRHostApplicationIdentifierKey @"WIRHostApplicationIdentifierKey"
+#define WIRHostApplicationNameKey @"WIRHostApplicationNameKey"
+#define WIRConnectionIdentifierKey @"WIRConnectionIdentifierKey"
+// COMPATABILITY(iOS 9): The key string is intentionally mismatched to support old relays.
+#define WIRTargetIdentifierKey @"WIRPageIdentifierKey"
+#define WIRHasLocalDebuggerKey @"WIRHasLocalDebuggerKey"
+#define WIRTitleKey @"WIRTitleKey"
+#define WIRURLKey @"WIRURLKey"
+#define WIRUserInfoKey @"WIRUserInfoKey"
+#define WIRApplicationDictionaryKey @"WIRApplicationDictionaryKey"
+#define WIRMessageDataKey @"WIRMessageDataKey"
+#define WIRApplicationGetListingMessage @"WIRApplicationGetListingMessage"
+#define WIRIndicateMessage @"WIRIndicateMessage"
+#define WIRIndicateEnabledKey @"WIRIndicateEnabledKey"
+#define WIRSenderKey @"WIRSenderKey"
+#define WIRSocketDataKey @"WIRSocketDataKey"
+#define WIRSocketDataMessage @"WIRSocketDataMessage"
+#define WIRSocketSetupMessage @"WIRSocketSetupMessage"
+#define WIRWebPageCloseMessage @"WIRWebPageCloseMessage"
+#define WIRRawDataMessage @"WIRRawDataMessage"
+#define WIRRawDataKey @"WIRRawDataKey"
+#define WIRListingMessage @"WIRListingMessage"
+#define WIRListingKey @"WIRListingKey"
+#define WIRRemoteAutomationEnabledKey @"WIRRemoteAutomationEnabledKey"
+#define WIRDestinationKey @"WIRDestinationKey"
+#define WIRConnectionDiedMessage @"WIRConnectionDiedMessage"
+#define WIRTypeKey @"WIRTypeKey"
+#define WIRTypeJavaScript @"WIRTypeJavaScript"
+#define WIRTypeWeb @"WIRTypeWeb"
+#define WIRTypeAutomation @"WIRTypeAutomation"
+#define WIRAutomaticallyPause @"WIRAutomaticallyPause"
+
+#define WIRAutomaticInspectionEnabledKey @"WIRAutomaticInspectionEnabledKey"
+#define WIRAutomaticInspectionSessionIdentifierKey @"WIRAutomaticInspectionSessionIdentifierKey"
+#define WIRAutomaticInspectionConfigurationMessage @"WIRAutomaticInspectionConfigurationMessage"
+#define WIRAutomaticInspectionRejectMessage @"WIRAutomaticInspectionRejectMessage"
+#define WIRAutomaticInspectionCandidateMessage @"WIRAutomaticInspectionCandidateMessage"
+
+#define WIRAutomationTargetIsPairedKey @"WIRAutomationTargetIsPairedKey"
+#define WIRSessionIdentifierKey @"WIRSessionIdentifierKey"
+#define WIRAutomationSessionRequestMessage @"WIRAutomationSessionRequestMessage"
+
+// These definitions are shared with a Simulator webinspectord and
+// OS X process communicating with it.
+
+#define WIRSimulatorBuildKey @"WIRSimulatorBuildKey"
+#define WIRSimulatorProductVersionKey @"WIRSimulatorProductVersionKey"
+#define WIRSimulatorNameKey @"WIRSimulatorNameKey"
+
+// These definitions are shared between webinspectord and WebKit.
+
+#define WIRPermissionDenied @"WIRPermissionDenied"
+#define WIRProxyApplicationParentPIDKey @"WIRProxyApplicationParentPID"
+#define WIRProxyApplicationParentAuditDataKey @"WIRProxyApplicationParentAuditData"
+#define WIRProxyApplicationSetupMessage @"WIRProxyApplicationSetupMessage"
+#define WIRProxyApplicationSetupResponseMessage @"WIRProxyApplicationSetupResponseMessage"
+
+#endif
diff --git a/Source/JavaScriptCore/inspector/remote/RemoteInspectorXPCConnection.h b/Source/JavaScriptCore/inspector/remote/RemoteInspectorXPCConnection.h
new file mode 100644
index 000000000..ef04c2341
--- /dev/null
+++ b/Source/JavaScriptCore/inspector/remote/RemoteInspectorXPCConnection.h
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if ENABLE(REMOTE_INSPECTOR)
+
+#ifndef RemoteInspectorXPCConnection_h
+#define RemoteInspectorXPCConnection_h
+
+#import <dispatch/dispatch.h>
+#import <wtf/Lock.h>
+#import <wtf/ThreadSafeRefCounted.h>
+#import <wtf/spi/darwin/XPCSPI.h>
+
+OBJC_CLASS NSDictionary;
+OBJC_CLASS NSString;
+
+namespace Inspector {
+
+class RemoteInspectorXPCConnection : public ThreadSafeRefCounted<RemoteInspectorXPCConnection> {
+public:
+ class Client {
+ public:
+ virtual ~Client() { }
+ virtual void xpcConnectionReceivedMessage(RemoteInspectorXPCConnection*, NSString *messageName, NSDictionary *userInfo) = 0;
+ virtual void xpcConnectionFailed(RemoteInspectorXPCConnection*) = 0;
+ virtual void xpcConnectionUnhandledMessage(RemoteInspectorXPCConnection*, xpc_object_t) = 0;
+ };
+
+ RemoteInspectorXPCConnection(xpc_connection_t, dispatch_queue_t, Client*);
+ virtual ~RemoteInspectorXPCConnection();
+
+ void close();
+ void closeFromMessage();
+ void sendMessage(NSString *messageName, NSDictionary *userInfo);
+
+private:
+ NSDictionary *deserializeMessage(xpc_object_t);
+ void handleEvent(xpc_object_t);
+ void closeOnQueue();
+
+ // We handle XPC events on the queue, but a client may call close() on any queue.
+ // We make sure that m_client is thread safe and immediately cleared in close().
+ Lock m_mutex;
+
+ xpc_connection_t m_connection;
+ dispatch_queue_t m_queue;
+ Client* m_client;
+ bool m_closed { false };
+#if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 100000)
+ bool m_validated { false };
+#endif
+};
+
+} // namespace Inspector
+
+#endif // RemoteInspectorXPCConnection_h
+
+#endif // ENABLE(REMOTE_INSPECTOR)