joepeck@webkit.org | 8851929 | 2016-10-27 22:18:55 +0000 | [diff] [blame] | 1 | /* |
| 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.com | 10cecce | 2021-08-31 01:41:55 +0000 | [diff] [blame] | 28 | #include <wtf/RefCounted.h> |
drousso@apple.com | c4efcd8 | 2020-05-04 19:51:30 +0000 | [diff] [blame] | 29 | #include <wtf/RefPtr.h> |
| 30 | #include <wtf/URL.h> |
pangle@apple.com | 10cecce | 2021-08-31 01:41:55 +0000 | [diff] [blame] | 31 | #include <wtf/WeakHashSet.h> |
joepeck@webkit.org | 8851929 | 2016-10-27 22:18:55 +0000 | [diff] [blame] | 32 | #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 | |
| 37 | namespace WebCore { |
| 38 | |
| 39 | class ScriptExecutionContext; |
| 40 | class WorkerThread; |
| 41 | |
drousso@apple.com | c4efcd8 | 2020-05-04 19:51:30 +0000 | [diff] [blame] | 42 | enum class WorkerThreadStartMode; |
| 43 | |
pangle@apple.com | 10cecce | 2021-08-31 01:41:55 +0000 | [diff] [blame] | 44 | class WorkerInspectorProxy : public RefCounted<WorkerInspectorProxy>, public CanMakeWeakPtr<WorkerInspectorProxy> { |
joepeck@webkit.org | 8851929 | 2016-10-27 22:18:55 +0000 | [diff] [blame] | 45 | WTF_MAKE_NONCOPYABLE(WorkerInspectorProxy); |
| 46 | WTF_MAKE_FAST_ALLOCATED; |
| 47 | public: |
pangle@apple.com | 10cecce | 2021-08-31 01:41:55 +0000 | [diff] [blame] | 48 | static Ref<WorkerInspectorProxy> create(const String& identifier) |
| 49 | { |
| 50 | return adoptRef(*new WorkerInspectorProxy(identifier)); |
| 51 | } |
| 52 | |
joepeck@webkit.org | 8851929 | 2016-10-27 22:18:55 +0000 | [diff] [blame] | 53 | ~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.org | f21f3ae | 2017-10-19 23:48:45 +0000 | [diff] [blame] | 58 | virtual ~PageChannel() = default; |
cdumez@apple.com | c13cffc | 2022-03-10 19:43:15 +0000 | [diff] [blame] | 59 | virtual void sendMessageFromWorkerToFrontend(WorkerInspectorProxy&, String&&) = 0; |
joepeck@webkit.org | 8851929 | 2016-10-27 22:18:55 +0000 | [diff] [blame] | 60 | }; |
| 61 | |
pangle@apple.com | 10cecce | 2021-08-31 01:41:55 +0000 | [diff] [blame] | 62 | static WeakHashSet<WorkerInspectorProxy>& allWorkerInspectorProxies(); |
joepeck@webkit.org | 8851929 | 2016-10-27 22:18:55 +0000 | [diff] [blame] | 63 | |
| 64 | const URL& url() const { return m_url; } |
drousso@apple.com | c4efcd8 | 2020-05-04 19:51:30 +0000 | [diff] [blame] | 65 | const String& name() const { return m_name; } |
joepeck@webkit.org | 8851929 | 2016-10-27 22:18:55 +0000 | [diff] [blame] | 66 | const String& identifier() const { return m_identifier; } |
| 67 | ScriptExecutionContext* scriptExecutionContext() const { return m_scriptExecutionContext.get(); } |
| 68 | |
commit-queue@webkit.org | 8599a76 | 2016-11-01 21:42:51 +0000 | [diff] [blame] | 69 | WorkerThreadStartMode workerStartMode(ScriptExecutionContext&); |
drousso@apple.com | c4efcd8 | 2020-05-04 19:51:30 +0000 | [diff] [blame] | 70 | void workerStarted(ScriptExecutionContext*, WorkerThread*, const URL&, const String& name); |
joepeck@webkit.org | 8851929 | 2016-10-27 22:18:55 +0000 | [diff] [blame] | 71 | void workerTerminated(); |
| 72 | |
joepeck@webkit.org | 98861c8 | 2016-10-27 22:19:33 +0000 | [diff] [blame] | 73 | void resumeWorkerIfPaused(); |
drousso@apple.com | c4efcd8 | 2020-05-04 19:51:30 +0000 | [diff] [blame] | 74 | void connectToWorkerInspectorController(PageChannel&); |
joepeck@webkit.org | 8851929 | 2016-10-27 22:18:55 +0000 | [diff] [blame] | 75 | void disconnectFromWorkerInspectorController(); |
| 76 | void sendMessageToWorkerInspectorController(const String&); |
cdumez@apple.com | c13cffc | 2022-03-10 19:43:15 +0000 | [diff] [blame] | 77 | void sendMessageFromWorkerToFrontend(String&&); |
joepeck@webkit.org | 8851929 | 2016-10-27 22:18:55 +0000 | [diff] [blame] | 78 | |
| 79 | private: |
pangle@apple.com | 10cecce | 2021-08-31 01:41:55 +0000 | [diff] [blame] | 80 | explicit WorkerInspectorProxy(const String& identifier); |
| 81 | |
joepeck@webkit.org | 8851929 | 2016-10-27 22:18:55 +0000 | [diff] [blame] | 82 | RefPtr<ScriptExecutionContext> m_scriptExecutionContext; |
| 83 | RefPtr<WorkerThread> m_workerThread; |
| 84 | String m_identifier; |
| 85 | URL m_url; |
drousso@apple.com | c4efcd8 | 2020-05-04 19:51:30 +0000 | [diff] [blame] | 86 | String m_name; |
joepeck@webkit.org | 8851929 | 2016-10-27 22:18:55 +0000 | [diff] [blame] | 87 | PageChannel* m_pageChannel { nullptr }; |
| 88 | }; |
| 89 | |
| 90 | } // namespace WebCore |