OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef ServicePortCollection_h | 5 #ifndef ServicePortCollection_h |
6 #define ServicePortCollection_h | 6 #define ServicePortCollection_h |
7 | 7 |
8 #include "bindings/core/v8/ScriptPromise.h" | 8 #include "bindings/core/v8/ScriptPromise.h" |
9 #include "core/dom/ContextLifecycleObserver.h" | 9 #include "core/dom/ContextLifecycleObserver.h" |
10 #include "core/events/EventTarget.h" | 10 #include "core/events/EventTarget.h" |
11 #include "modules/ModulesExport.h" | 11 #include "modules/ModulesExport.h" |
| 12 #include "public/platform/modules/navigator_services/WebServicePortProvider.h" |
| 13 #include "public/platform/modules/navigator_services/WebServicePortProviderClien
t.h" |
12 #include "wtf/RefCounted.h" | 14 #include "wtf/RefCounted.h" |
| 15 #include "wtf/WeakPtr.h" |
13 | 16 |
14 namespace blink { | 17 namespace blink { |
15 | 18 |
| 19 class ServicePort; |
16 class ServicePortConnectOptions; | 20 class ServicePortConnectOptions; |
17 class ServicePortMatchOptions; | 21 class ServicePortMatchOptions; |
18 | 22 |
19 class MODULES_EXPORT ServicePortCollection final | 23 class MODULES_EXPORT ServicePortCollection final |
20 : public EventTargetWithInlineData | 24 : public EventTargetWithInlineData |
21 , public RefCountedWillBeNoBase<ServicePortCollection> | 25 , public RefCountedWillBeNoBase<ServicePortCollection> |
22 , public ContextLifecycleObserver { | 26 , public ContextLifecycleObserver |
| 27 , public WebServicePortProviderClient { |
23 DEFINE_WRAPPERTYPEINFO(); | 28 DEFINE_WRAPPERTYPEINFO(); |
24 REFCOUNTED_EVENT_TARGET(ServicePortCollection); | 29 REFCOUNTED_EVENT_TARGET(ServicePortCollection); |
25 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(ServicePortCollection); | 30 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(ServicePortCollection); |
26 WTF_MAKE_NONCOPYABLE(ServicePortCollection); | 31 WTF_MAKE_NONCOPYABLE(ServicePortCollection); |
27 public: | 32 public: |
28 static PassRefPtrWillBeRawPtr<ServicePortCollection> create(ExecutionContext
*); | 33 static PassRefPtrWillBeRawPtr<ServicePortCollection> create(ExecutionContext
*); |
29 virtual ~ServicePortCollection(); | 34 virtual ~ServicePortCollection(); |
30 | 35 |
| 36 // Adds a port to this collection to keep track of it and allow delivering |
| 37 // events related to it. |
| 38 void addPort(ServicePort*); |
| 39 |
| 40 // Called when a port is closed to signal the WebServicePortProvider as well |
| 41 // as remove the port from this collection. |
| 42 void closePort(ServicePort*); |
| 43 |
| 44 WebServicePortProvider* provider() { return m_provider.get(); } |
| 45 |
| 46 #if !ENABLE(OILPAN) |
| 47 WeakPtr<ServicePortCollection> weakPtr() { return m_weakFactory.createWeakPt
r(); } |
| 48 #endif |
| 49 |
31 // ServicePortCollection.idl | 50 // ServicePortCollection.idl |
32 ScriptPromise connect(ScriptState*, const String& url, const ServicePortConn
ectOptions&); | 51 ScriptPromise connect(ScriptState*, const String& url, const ServicePortConn
ectOptions&, ExceptionState&); |
33 ScriptPromise match(ScriptState*, const ServicePortMatchOptions&); | 52 ScriptPromise match(ScriptState*, const ServicePortMatchOptions&); |
34 ScriptPromise matchAll(ScriptState*, const ServicePortMatchOptions&); | 53 ScriptPromise matchAll(ScriptState*, const ServicePortMatchOptions&); |
35 DEFINE_ATTRIBUTE_EVENT_LISTENER(connect); | 54 DEFINE_ATTRIBUTE_EVENT_LISTENER(connect); |
36 DEFINE_ATTRIBUTE_EVENT_LISTENER(message); | 55 DEFINE_ATTRIBUTE_EVENT_LISTENER(message); |
37 DEFINE_ATTRIBUTE_EVENT_LISTENER(close); | 56 DEFINE_ATTRIBUTE_EVENT_LISTENER(close); |
38 | 57 |
39 // EventTarget overrides. | 58 // EventTarget overrides. |
40 const AtomicString& interfaceName() const override; | 59 const AtomicString& interfaceName() const override; |
41 ExecutionContext* executionContext() const override; | 60 ExecutionContext* executionContext() const override; |
42 | 61 |
| 62 // WebServicePortProviderClient overrides. |
| 63 void postMessage(WebServicePortID, const WebString&, const WebMessagePortCha
nnelArray&) override; |
| 64 |
43 DECLARE_VIRTUAL_TRACE(); | 65 DECLARE_VIRTUAL_TRACE(); |
44 | 66 |
45 private: | 67 private: |
46 explicit ServicePortCollection(ExecutionContext*); | 68 explicit ServicePortCollection(ExecutionContext*); |
| 69 |
| 70 OwnPtr<WebServicePortProvider> m_provider; |
| 71 PersistentHeapVectorWillBeHeapVector<Member<ServicePort>> m_ports; |
| 72 #if !ENABLE(OILPAN) |
| 73 WeakPtrFactory<ServicePortCollection> m_weakFactory; |
| 74 #endif |
47 }; | 75 }; |
48 | 76 |
49 } // namespace blink | 77 } // namespace blink |
50 | 78 |
51 #endif // ServicePortCollection_h | 79 #endif // ServicePortCollection_h |
OLD | NEW |