OLD | NEW |
1 /* | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 * Copyright (C) 2008, 2010 Apple Inc. All Rights Reserved. | 2 // Use of this source code is governed by a BSD-style license that can be |
3 * | 3 // found in the LICENSE file. |
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 COMPUTER, 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 COMPUTER, 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 | 4 |
27 #ifndef Worker_h | 5 #ifndef Worker_h |
28 #define Worker_h | 6 #define Worker_h |
29 | 7 |
30 #include "core/CoreExport.h" | 8 #include "core/workers/InProcessWorkerBase.h" |
31 #include "core/dom/ActiveDOMObject.h" | |
32 #include "core/dom/MessagePort.h" | |
33 #include "core/events/EventListener.h" | |
34 #include "core/events/EventTarget.h" | |
35 #include "core/workers/AbstractWorker.h" | |
36 #include "core/workers/WorkerScriptLoaderClient.h" | |
37 #include "platform/heap/Handle.h" | |
38 #include "wtf/Forward.h" | |
39 #include "wtf/PassRefPtr.h" | |
40 #include "wtf/RefPtr.h" | |
41 #include "wtf/text/AtomicStringHash.h" | |
42 | 9 |
43 namespace blink { | 10 namespace blink { |
44 | 11 |
45 class ExceptionState; | 12 class ExceptionState; |
46 class ExecutionContext; | 13 class ExecutionContext; |
47 class WorkerGlobalScopeProxy; | 14 class WorkerGlobalScopeProxy; |
48 class WorkerScriptLoader; | |
49 | 15 |
50 class CORE_EXPORT Worker : public AbstractWorker, private WorkerScriptLoaderClie
nt { | 16 class CORE_EXPORT Worker final : public InProcessWorkerBase { |
51 DEFINE_WRAPPERTYPEINFO(); | 17 DEFINE_WRAPPERTYPEINFO(); |
52 public: | 18 public: |
53 static PassRefPtrWillBeRawPtr<Worker> create(ExecutionContext*, const String
& url, ExceptionState&); | 19 static PassRefPtrWillBeRawPtr<Worker> create(ExecutionContext*, const String
& url, ExceptionState&); |
54 virtual ~Worker(); | 20 virtual ~Worker(); |
55 | 21 |
56 virtual const AtomicString& interfaceName() const override; | |
57 | |
58 void postMessage(ExecutionContext*, PassRefPtr<SerializedScriptValue> messag
e, const MessagePortArray*, ExceptionState&); | |
59 | |
60 bool initialize(ExecutionContext*, const String&, ExceptionState&); | |
61 void terminate(); | |
62 | |
63 virtual void stop() override; | |
64 virtual bool hasPendingActivity() const override; | |
65 | |
66 DEFINE_ATTRIBUTE_EVENT_LISTENER(message); | |
67 | |
68 DECLARE_VIRTUAL_TRACE(); | |
69 | |
70 protected: | 22 protected: |
71 explicit Worker(ExecutionContext*); | 23 explicit Worker(ExecutionContext*); |
72 | 24 |
73 virtual WorkerGlobalScopeProxy* createWorkerGlobalScopeProxy(ExecutionContex
t*); | 25 WorkerGlobalScopeProxy* createWorkerGlobalScopeProxy(ExecutionContext*) over
ride; |
74 | 26 const AtomicString& interfaceName() const override; |
75 private: | |
76 // WorkerScriptLoaderClient callbacks | |
77 virtual void didReceiveResponse(unsigned long identifier, const ResourceResp
onse&) override; | |
78 virtual void notifyFinished() override; | |
79 | |
80 RefPtr<WorkerScriptLoader> m_scriptLoader; | |
81 WorkerGlobalScopeProxy* m_contextProxy; // The proxy outlives the worker to
perform thread shutdown. | |
82 }; | 27 }; |
83 | 28 |
84 } // namespace blink | 29 } // namespace blink |
85 | 30 |
86 #endif // Worker_h | 31 #endif // Worker_h |
OLD | NEW |