OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 ServiceWorkerRegistration_h | 5 #ifndef ServiceWorkerRegistration_h |
6 #define ServiceWorkerRegistration_h | 6 #define ServiceWorkerRegistration_h |
7 | 7 |
8 #include "bindings/core/v8/ActiveScriptWrappable.h" | 8 #include "bindings/core/v8/ActiveScriptWrappable.h" |
9 #include "bindings/core/v8/ScriptPromiseResolver.h" | 9 #include "bindings/core/v8/ScriptPromiseResolver.h" |
10 #include "core/dom/ActiveDOMObject.h" | 10 #include "core/dom/ActiveDOMObject.h" |
11 #include "core/events/EventTarget.h" | 11 #include "core/events/EventTarget.h" |
12 #include "modules/serviceworkers/ServiceWorker.h" | 12 #include "modules/serviceworkers/ServiceWorker.h" |
13 #include "modules/serviceworkers/ServiceWorkerRegistration.h" | 13 #include "modules/serviceworkers/ServiceWorkerRegistration.h" |
14 #include "platform/Supplementable.h" | 14 #include "platform/Supplementable.h" |
15 #include "public/platform/modules/serviceworker/WebServiceWorkerRegistration.h" | 15 #include "public/platform/modules/serviceworker/WebServiceWorkerRegistration.h" |
16 #include "public/platform/modules/serviceworker/WebServiceWorkerRegistrationProx
y.h" | 16 #include "public/platform/modules/serviceworker/WebServiceWorkerRegistrationProx
y.h" |
17 #include "wtf/Forward.h" | 17 #include "wtf/Forward.h" |
18 #include <memory> | 18 #include "wtf/OwnPtr.h" |
19 | 19 |
20 namespace blink { | 20 namespace blink { |
21 | 21 |
22 class ScriptPromise; | 22 class ScriptPromise; |
23 class ScriptState; | 23 class ScriptState; |
24 class WebServiceWorkerProvider; | 24 class WebServiceWorkerProvider; |
25 | 25 |
26 // The implementation of a service worker registration object in Blink. Actual | 26 // The implementation of a service worker registration object in Blink. Actual |
27 // registration representation is in the embedder and this class accesses it | 27 // registration representation is in the embedder and this class accesses it |
28 // via WebServiceWorkerRegistration::Handle object. | 28 // via WebServiceWorkerRegistration::Handle object. |
(...skipping 12 matching lines...) Expand all Loading... |
41 ExecutionContext* getExecutionContext() const override { return ActiveDOMObj
ect::getExecutionContext(); } | 41 ExecutionContext* getExecutionContext() const override { return ActiveDOMObj
ect::getExecutionContext(); } |
42 | 42 |
43 // WebServiceWorkerRegistrationProxy overrides. | 43 // WebServiceWorkerRegistrationProxy overrides. |
44 void dispatchUpdateFoundEvent() override; | 44 void dispatchUpdateFoundEvent() override; |
45 void setInstalling(std::unique_ptr<WebServiceWorker::Handle>) override; | 45 void setInstalling(std::unique_ptr<WebServiceWorker::Handle>) override; |
46 void setWaiting(std::unique_ptr<WebServiceWorker::Handle>) override; | 46 void setWaiting(std::unique_ptr<WebServiceWorker::Handle>) override; |
47 void setActive(std::unique_ptr<WebServiceWorker::Handle>) override; | 47 void setActive(std::unique_ptr<WebServiceWorker::Handle>) override; |
48 | 48 |
49 // Returns an existing registration object for the handle if it exists. | 49 // Returns an existing registration object for the handle if it exists. |
50 // Otherwise, returns a new registration object. | 50 // Otherwise, returns a new registration object. |
51 static ServiceWorkerRegistration* getOrCreate(ExecutionContext*, std::unique
_ptr<WebServiceWorkerRegistration::Handle>); | 51 static ServiceWorkerRegistration* getOrCreate(ExecutionContext*, PassOwnPtr<
WebServiceWorkerRegistration::Handle>); |
52 | 52 |
53 ServiceWorker* installing() { return m_installing; } | 53 ServiceWorker* installing() { return m_installing; } |
54 ServiceWorker* waiting() { return m_waiting; } | 54 ServiceWorker* waiting() { return m_waiting; } |
55 ServiceWorker* active() { return m_active; } | 55 ServiceWorker* active() { return m_active; } |
56 | 56 |
57 String scope() const; | 57 String scope() const; |
58 | 58 |
59 WebServiceWorkerRegistration* webRegistration() { return m_handle->registrat
ion(); } | 59 WebServiceWorkerRegistration* webRegistration() { return m_handle->registrat
ion(); } |
60 | 60 |
61 ScriptPromise update(ScriptState*); | 61 ScriptPromise update(ScriptState*); |
62 ScriptPromise unregister(ScriptState*); | 62 ScriptPromise unregister(ScriptState*); |
63 | 63 |
64 DEFINE_ATTRIBUTE_EVENT_LISTENER(updatefound); | 64 DEFINE_ATTRIBUTE_EVENT_LISTENER(updatefound); |
65 | 65 |
66 ~ServiceWorkerRegistration() override; | 66 ~ServiceWorkerRegistration() override; |
67 | 67 |
68 DECLARE_VIRTUAL_TRACE(); | 68 DECLARE_VIRTUAL_TRACE(); |
69 | 69 |
70 private: | 70 private: |
71 ServiceWorkerRegistration(ExecutionContext*, std::unique_ptr<WebServiceWorke
rRegistration::Handle>); | 71 ServiceWorkerRegistration(ExecutionContext*, PassOwnPtr<WebServiceWorkerRegi
stration::Handle>); |
72 void dispose(); | 72 void dispose(); |
73 | 73 |
74 // ActiveScriptWrappable overrides. | 74 // ActiveScriptWrappable overrides. |
75 bool hasPendingActivity() const final; | 75 bool hasPendingActivity() const final; |
76 | 76 |
77 // ActiveDOMObject overrides. | 77 // ActiveDOMObject overrides. |
78 void stop() override; | 78 void stop() override; |
79 | 79 |
80 // A handle to the registration representation in the embedder. | 80 // A handle to the registration representation in the embedder. |
81 std::unique_ptr<WebServiceWorkerRegistration::Handle> m_handle; | 81 OwnPtr<WebServiceWorkerRegistration::Handle> m_handle; |
82 | 82 |
83 Member<ServiceWorker> m_installing; | 83 Member<ServiceWorker> m_installing; |
84 Member<ServiceWorker> m_waiting; | 84 Member<ServiceWorker> m_waiting; |
85 Member<ServiceWorker> m_active; | 85 Member<ServiceWorker> m_active; |
86 | 86 |
87 bool m_stopped; | 87 bool m_stopped; |
88 }; | 88 }; |
89 | 89 |
90 class ServiceWorkerRegistrationArray { | 90 class ServiceWorkerRegistrationArray { |
91 STATIC_ONLY(ServiceWorkerRegistrationArray); | 91 STATIC_ONLY(ServiceWorkerRegistrationArray); |
92 public: | 92 public: |
93 static HeapVector<Member<ServiceWorkerRegistration>> take(ScriptPromiseResol
ver* resolver, Vector<std::unique_ptr<WebServiceWorkerRegistration::Handle>>* we
bServiceWorkerRegistrations) | 93 static HeapVector<Member<ServiceWorkerRegistration>> take(ScriptPromiseResol
ver* resolver, Vector<OwnPtr<WebServiceWorkerRegistration::Handle>>* webServiceW
orkerRegistrations) |
94 { | 94 { |
95 HeapVector<Member<ServiceWorkerRegistration>> registrations; | 95 HeapVector<Member<ServiceWorkerRegistration>> registrations; |
96 for (auto& registration : *webServiceWorkerRegistrations) | 96 for (auto& registration : *webServiceWorkerRegistrations) |
97 registrations.append(ServiceWorkerRegistration::getOrCreate(resolver
->getExecutionContext(), std::move(registration))); | 97 registrations.append(ServiceWorkerRegistration::getOrCreate(resolver
->getExecutionContext(), std::move(registration))); |
98 return registrations; | 98 return registrations; |
99 } | 99 } |
100 }; | 100 }; |
101 | 101 |
102 } // namespace blink | 102 } // namespace blink |
103 | 103 |
104 #endif // ServiceWorkerRegistration_h | 104 #endif // ServiceWorkerRegistration_h |
OLD | NEW |