OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 #include "public/platform/modules/serviceworker/WebServiceWorkerRegistration.h" | 57 #include "public/platform/modules/serviceworker/WebServiceWorkerRegistration.h" |
58 | 58 |
59 namespace blink { | 59 namespace blink { |
60 | 60 |
61 class RegistrationCallback : public WebServiceWorkerProvider::WebServiceWorkerRe
gistrationCallbacks { | 61 class RegistrationCallback : public WebServiceWorkerProvider::WebServiceWorkerRe
gistrationCallbacks { |
62 public: | 62 public: |
63 explicit RegistrationCallback(ScriptPromiseResolver* resolver) | 63 explicit RegistrationCallback(ScriptPromiseResolver* resolver) |
64 : m_resolver(resolver) { } | 64 : m_resolver(resolver) { } |
65 ~RegistrationCallback() override { } | 65 ~RegistrationCallback() override { } |
66 | 66 |
67 // Takes ownership of |registrationRaw|. | 67 void onSuccess(WebPassOwnPtr<WebServiceWorkerRegistration> registration) ove
rride |
68 void onSuccess(WebServiceWorkerRegistration* registrationRaw) override | |
69 { | 68 { |
70 OwnPtr<WebServiceWorkerRegistration> registration = adoptPtr(registratio
nRaw); | |
71 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) | 69 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) |
72 return; | 70 return; |
73 m_resolver->resolve(ServiceWorkerRegistration::create(m_resolver->execut
ionContext(), registration.release())); | 71 m_resolver->resolve(ServiceWorkerRegistration::create(m_resolver->execut
ionContext(), registration.release())); |
74 } | 72 } |
75 | 73 |
76 // Takes ownership of |errorRaw|. | 74 void onError(const WebServiceWorkerError& error) override |
77 void onError(WebServiceWorkerError* errorRaw) override | |
78 { | 75 { |
79 OwnPtr<WebServiceWorkerError> error = adoptPtr(errorRaw); | |
80 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) | 76 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) |
81 return; | 77 return; |
82 m_resolver->reject(ServiceWorkerError::take(m_resolver.get(), *error)); | 78 m_resolver->reject(ServiceWorkerError::take(m_resolver.get(), error)); |
83 } | 79 } |
84 | 80 |
85 private: | 81 private: |
86 Persistent<ScriptPromiseResolver> m_resolver; | 82 Persistent<ScriptPromiseResolver> m_resolver; |
87 WTF_MAKE_NONCOPYABLE(RegistrationCallback); | 83 WTF_MAKE_NONCOPYABLE(RegistrationCallback); |
88 }; | 84 }; |
89 | 85 |
90 class GetRegistrationCallback : public WebServiceWorkerProvider::WebServiceWorke
rGetRegistrationCallbacks { | 86 class GetRegistrationCallback : public WebServiceWorkerProvider::WebServiceWorke
rGetRegistrationCallbacks { |
91 public: | 87 public: |
92 explicit GetRegistrationCallback(ScriptPromiseResolver* resolver) | 88 explicit GetRegistrationCallback(ScriptPromiseResolver* resolver) |
93 : m_resolver(resolver) { } | 89 : m_resolver(resolver) { } |
94 ~GetRegistrationCallback() override { } | 90 ~GetRegistrationCallback() override { } |
95 | 91 |
96 // Takes ownership of |registrationRaw|. | 92 void onSuccess(WebPassOwnPtr<WebServiceWorkerRegistration> r) override |
97 void onSuccess(WebServiceWorkerRegistration* registrationRaw) override | |
98 { | 93 { |
99 OwnPtr<WebServiceWorkerRegistration> registration = adoptPtr(registratio
nRaw); | 94 OwnPtr<WebServiceWorkerRegistration> registration = r.release(); |
100 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) | 95 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) |
101 return; | 96 return; |
102 if (!registration) { | 97 if (!registration) { |
103 // Resolve the promise with undefined. | 98 // Resolve the promise with undefined. |
104 m_resolver->resolve(); | 99 m_resolver->resolve(); |
105 return; | 100 return; |
106 } | 101 } |
107 m_resolver->resolve(ServiceWorkerRegistration::create(m_resolver->execut
ionContext(), registration.release())); | 102 m_resolver->resolve(ServiceWorkerRegistration::create(m_resolver->execut
ionContext(), registration.release())); |
108 } | 103 } |
109 | 104 |
110 // Takes ownership of |errorRaw|. | 105 void onError(const WebServiceWorkerError& error) override |
111 void onError(WebServiceWorkerError* errorRaw) override | |
112 { | 106 { |
113 OwnPtr<WebServiceWorkerError> error = adoptPtr(errorRaw); | |
114 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) | 107 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) |
115 return; | 108 return; |
116 m_resolver->reject(ServiceWorkerError::take(m_resolver.get(), *error)); | 109 m_resolver->reject(ServiceWorkerError::take(m_resolver.get(), error)); |
117 } | 110 } |
118 | 111 |
119 private: | 112 private: |
120 Persistent<ScriptPromiseResolver> m_resolver; | 113 Persistent<ScriptPromiseResolver> m_resolver; |
121 WTF_MAKE_NONCOPYABLE(GetRegistrationCallback); | 114 WTF_MAKE_NONCOPYABLE(GetRegistrationCallback); |
122 }; | 115 }; |
123 | 116 |
124 class GetRegistrationsCallback : public WebServiceWorkerProvider::WebServiceWork
erGetRegistrationsCallbacks { | 117 class GetRegistrationsCallback : public WebServiceWorkerProvider::WebServiceWork
erGetRegistrationsCallbacks { |
125 public: | 118 public: |
126 explicit GetRegistrationsCallback(ScriptPromiseResolver* resolver) | 119 explicit GetRegistrationsCallback(ScriptPromiseResolver* resolver) |
127 : m_resolver(resolver) { } | 120 : m_resolver(resolver) { } |
128 ~GetRegistrationsCallback() override { } | 121 ~GetRegistrationsCallback() override { } |
129 | 122 |
130 // Takes ownership of |registrationsRaw|. | 123 void onSuccess(WebPassOwnPtr<WebVector<WebServiceWorkerRegistration*>> webPa
ssRegistrations) override |
131 void onSuccess(WebVector<WebServiceWorkerRegistration*>* registrationsRaw) o
verride | |
132 { | 124 { |
133 OwnPtr<WebVector<WebServiceWorkerRegistration*>> registrations = adoptPt
r(registrationsRaw); | 125 Vector<OwnPtr<WebServiceWorkerRegistration>> registrations; |
| 126 OwnPtr<WebVector<WebServiceWorkerRegistration*>> webRegistrations = webP
assRegistrations.release(); |
| 127 for (auto& registration : *webRegistrations) { |
| 128 registrations.append(adoptPtr(registration)); |
| 129 } |
| 130 |
134 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) | 131 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) |
135 return; | 132 return; |
136 m_resolver->resolve(ServiceWorkerRegistrationArray::take(m_resolver.get(
), registrations.release())); | 133 m_resolver->resolve(ServiceWorkerRegistrationArray::take(m_resolver.get(
), ®istrations)); |
137 } | 134 } |
138 | 135 |
139 // Takes ownership of |errorRaw|. | 136 void onError(const WebServiceWorkerError& error) override |
140 void onError(WebServiceWorkerError* errorRaw) override | |
141 { | 137 { |
142 OwnPtr<WebServiceWorkerError> error = adoptPtr(errorRaw); | |
143 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) | 138 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) |
144 return; | 139 return; |
145 m_resolver->reject(ServiceWorkerError::take(m_resolver.get(), *error)); | 140 m_resolver->reject(ServiceWorkerError::take(m_resolver.get(), error)); |
146 } | 141 } |
147 | 142 |
148 private: | 143 private: |
149 Persistent<ScriptPromiseResolver> m_resolver; | 144 Persistent<ScriptPromiseResolver> m_resolver; |
150 WTF_MAKE_NONCOPYABLE(GetRegistrationsCallback); | 145 WTF_MAKE_NONCOPYABLE(GetRegistrationsCallback); |
151 }; | 146 }; |
152 | 147 |
153 class ServiceWorkerContainer::GetRegistrationForReadyCallback : public WebServic
eWorkerProvider::WebServiceWorkerGetRegistrationForReadyCallbacks { | 148 class ServiceWorkerContainer::GetRegistrationForReadyCallback : public WebServic
eWorkerProvider::WebServiceWorkerGetRegistrationForReadyCallbacks { |
154 public: | 149 public: |
155 explicit GetRegistrationForReadyCallback(ReadyProperty* ready) | 150 explicit GetRegistrationForReadyCallback(ReadyProperty* ready) |
156 : m_ready(ready) { } | 151 : m_ready(ready) { } |
157 ~GetRegistrationForReadyCallback() { } | 152 ~GetRegistrationForReadyCallback() override { } |
158 | 153 |
159 // Takes ownership of |registrationRaw|. | 154 void onSuccess(WebPassOwnPtr<WebServiceWorkerRegistration> registration) ove
rride |
160 void onSuccess(WebServiceWorkerRegistration* registrationRaw) override | |
161 { | 155 { |
162 ASSERT(registrationRaw); | |
163 ASSERT(m_ready->state() == ReadyProperty::Pending); | 156 ASSERT(m_ready->state() == ReadyProperty::Pending); |
164 | 157 |
165 OwnPtr<WebServiceWorkerRegistration> registration = adoptPtr(registratio
nRaw); | |
166 if (m_ready->executionContext() && !m_ready->executionContext()->activeD
OMObjectsAreStopped()) | 158 if (m_ready->executionContext() && !m_ready->executionContext()->activeD
OMObjectsAreStopped()) |
167 m_ready->resolve(ServiceWorkerRegistration::create(m_ready->executio
nContext(), registration.release())); | 159 m_ready->resolve(ServiceWorkerRegistration::create(m_ready->executio
nContext(), registration.release())); |
168 } | 160 } |
169 | 161 |
170 private: | 162 private: |
171 Persistent<ReadyProperty> m_ready; | 163 Persistent<ReadyProperty> m_ready; |
172 WTF_MAKE_NONCOPYABLE(GetRegistrationForReadyCallback); | 164 WTF_MAKE_NONCOPYABLE(GetRegistrationForReadyCallback); |
173 }; | 165 }; |
174 | 166 |
175 ServiceWorkerContainer* ServiceWorkerContainer::create(ExecutionContext* executi
onContext) | 167 ServiceWorkerContainer* ServiceWorkerContainer::create(ExecutionContext* executi
onContext) |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 return; | 398 return; |
407 | 399 |
408 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro
m(executionContext)) { | 400 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro
m(executionContext)) { |
409 m_provider = client->provider(); | 401 m_provider = client->provider(); |
410 if (m_provider) | 402 if (m_provider) |
411 m_provider->setClient(this); | 403 m_provider->setClient(this); |
412 } | 404 } |
413 } | 405 } |
414 | 406 |
415 } // namespace blink | 407 } // namespace blink |
OLD | NEW |