blob: 83acb5fddba1044147e784ab69e5c90ffb5b08ff [file] [log] [blame]
joepeck@webkit.org88519292016-10-27 22:18:55 +00001/*
2 * Copyright (C) 2016 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. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#pragma once
27
pangle@apple.com10cecce2021-08-31 01:41:55 +000028#include <wtf/RefCounted.h>
drousso@apple.comc4efcd82020-05-04 19:51:30 +000029#include <wtf/RefPtr.h>
30#include <wtf/URL.h>
pangle@apple.com10cecce2021-08-31 01:41:55 +000031#include <wtf/WeakHashSet.h>
joepeck@webkit.org88519292016-10-27 22:18:55 +000032#include <wtf/text/WTFString.h>
33
34// All of these methods should be called on the Main Thread.
35// Used to send messages to the WorkerInspector on the WorkerThread.
36
37namespace WebCore {
38
39class ScriptExecutionContext;
40class WorkerThread;
41
drousso@apple.comc4efcd82020-05-04 19:51:30 +000042enum class WorkerThreadStartMode;
43
pangle@apple.com10cecce2021-08-31 01:41:55 +000044class WorkerInspectorProxy : public RefCounted<WorkerInspectorProxy>, public CanMakeWeakPtr<WorkerInspectorProxy> {
joepeck@webkit.org88519292016-10-27 22:18:55 +000045 WTF_MAKE_NONCOPYABLE(WorkerInspectorProxy);
46 WTF_MAKE_FAST_ALLOCATED;
47public:
pangle@apple.com10cecce2021-08-31 01:41:55 +000048 static Ref<WorkerInspectorProxy> create(const String& identifier)
49 {
50 return adoptRef(*new WorkerInspectorProxy(identifier));
51 }
52
joepeck@webkit.org88519292016-10-27 22:18:55 +000053 ~WorkerInspectorProxy();
54
55 // A Worker's inspector messages come in and go out through the Page's WorkerAgent.
56 class PageChannel {
57 public:
dbates@webkit.orgf21f3ae2017-10-19 23:48:45 +000058 virtual ~PageChannel() = default;
cdumez@apple.comc13cffc2022-03-10 19:43:15 +000059 virtual void sendMessageFromWorkerToFrontend(WorkerInspectorProxy&, String&&) = 0;
joepeck@webkit.org88519292016-10-27 22:18:55 +000060 };
61
pangle@apple.com10cecce2021-08-31 01:41:55 +000062 static WeakHashSet<WorkerInspectorProxy>& allWorkerInspectorProxies();
joepeck@webkit.org88519292016-10-27 22:18:55 +000063
64 const URL& url() const { return m_url; }
drousso@apple.comc4efcd82020-05-04 19:51:30 +000065 const String& name() const { return m_name; }
joepeck@webkit.org88519292016-10-27 22:18:55 +000066 const String& identifier() const { return m_identifier; }
67 ScriptExecutionContext* scriptExecutionContext() const { return m_scriptExecutionContext.get(); }
68
commit-queue@webkit.org8599a762016-11-01 21:42:51 +000069 WorkerThreadStartMode workerStartMode(ScriptExecutionContext&);
drousso@apple.comc4efcd82020-05-04 19:51:30 +000070 void workerStarted(ScriptExecutionContext*, WorkerThread*, const URL&, const String& name);
joepeck@webkit.org88519292016-10-27 22:18:55 +000071 void workerTerminated();
72
joepeck@webkit.org98861c82016-10-27 22:19:33 +000073 void resumeWorkerIfPaused();
drousso@apple.comc4efcd82020-05-04 19:51:30 +000074 void connectToWorkerInspectorController(PageChannel&);
joepeck@webkit.org88519292016-10-27 22:18:55 +000075 void disconnectFromWorkerInspectorController();
76 void sendMessageToWorkerInspectorController(const String&);
cdumez@apple.comc13cffc2022-03-10 19:43:15 +000077 void sendMessageFromWorkerToFrontend(String&&);
joepeck@webkit.org88519292016-10-27 22:18:55 +000078
79private:
pangle@apple.com10cecce2021-08-31 01:41:55 +000080 explicit WorkerInspectorProxy(const String& identifier);
81
joepeck@webkit.org88519292016-10-27 22:18:55 +000082 RefPtr<ScriptExecutionContext> m_scriptExecutionContext;
83 RefPtr<WorkerThread> m_workerThread;
84 String m_identifier;
85 URL m_url;
drousso@apple.comc4efcd82020-05-04 19:51:30 +000086 String m_name;
joepeck@webkit.org88519292016-10-27 22:18:55 +000087 PageChannel* m_pageChannel { nullptr };
88};
89
90} // namespace WebCore