Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(301)

Side by Side Diff: third_party/WebKit/Source/modules/serviceworkers/ServiceWorkerContainer.cpp

Issue 2433773006: Remove ExecutionContext::activeDOMObjectsAreStopped()
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 #include "modules/serviceworkers/ServiceWorkerRegistration.h" 51 #include "modules/serviceworkers/ServiceWorkerRegistration.h"
52 #include "platform/RuntimeEnabledFeatures.h" 52 #include "platform/RuntimeEnabledFeatures.h"
53 #include "platform/weborigin/SchemeRegistry.h" 53 #include "platform/weborigin/SchemeRegistry.h"
54 #include "public/platform/WebString.h" 54 #include "public/platform/WebString.h"
55 #include "public/platform/WebURL.h" 55 #include "public/platform/WebURL.h"
56 #include "public/platform/modules/serviceworker/WebServiceWorker.h" 56 #include "public/platform/modules/serviceworker/WebServiceWorker.h"
57 #include "public/platform/modules/serviceworker/WebServiceWorkerProvider.h" 57 #include "public/platform/modules/serviceworker/WebServiceWorkerProvider.h"
58 #include "public/platform/modules/serviceworker/WebServiceWorkerRegistration.h" 58 #include "public/platform/modules/serviceworker/WebServiceWorkerRegistration.h"
59 #include "wtf/PtrUtil.h" 59 #include "wtf/PtrUtil.h"
60 #include <memory> 60 #include <memory>
61 #include <utility>
61 62
62 namespace blink { 63 namespace blink {
63 64
64 class RegistrationCallback 65 class RegistrationCallback
65 : public WebServiceWorkerProvider::WebServiceWorkerRegistrationCallbacks { 66 : public WebServiceWorkerProvider::WebServiceWorkerRegistrationCallbacks {
66 public: 67 public:
67 explicit RegistrationCallback(ScriptPromiseResolver* resolver) 68 explicit RegistrationCallback(ScriptPromiseResolver* resolver)
68 : m_resolver(resolver) {} 69 : m_resolver(resolver) {}
69 ~RegistrationCallback() override {} 70 ~RegistrationCallback() override {}
70 71
71 void onSuccess( 72 void onSuccess(
72 std::unique_ptr<WebServiceWorkerRegistration::Handle> handle) override { 73 std::unique_ptr<WebServiceWorkerRegistration::Handle> handle) override {
73 if (!m_resolver->getExecutionContext() || 74 if (!m_resolver->getExecutionContext())
74 m_resolver->getExecutionContext()->activeDOMObjectsAreStopped())
75 return; 75 return;
76 m_resolver->resolve(ServiceWorkerRegistration::getOrCreate( 76 m_resolver->resolve(ServiceWorkerRegistration::getOrCreate(
77 m_resolver->getExecutionContext(), wrapUnique(handle.release()))); 77 m_resolver->getExecutionContext(), std::move(handle)));
78 } 78 }
79 79
80 void onError(const WebServiceWorkerError& error) override { 80 void onError(const WebServiceWorkerError& error) override {
81 if (!m_resolver->getExecutionContext() || 81 if (!m_resolver->getExecutionContext())
82 m_resolver->getExecutionContext()->activeDOMObjectsAreStopped())
83 return; 82 return;
84 ScriptState::Scope scope(m_resolver->getScriptState()); 83 ScriptState::Scope scope(m_resolver->getScriptState());
85 if (error.errorType == WebServiceWorkerError::ErrorTypeType) { 84 if (error.errorType == WebServiceWorkerError::ErrorTypeType) {
86 m_resolver->reject(V8ThrowException::createTypeError( 85 m_resolver->reject(V8ThrowException::createTypeError(
87 m_resolver->getScriptState()->isolate(), error.message)); 86 m_resolver->getScriptState()->isolate(), error.message));
88 } else { 87 } else {
89 m_resolver->reject( 88 m_resolver->reject(
90 ServiceWorkerErrorForUpdate::take(m_resolver.get(), error)); 89 ServiceWorkerErrorForUpdate::take(m_resolver.get(), error));
91 } 90 }
92 } 91 }
93 92
94 private: 93 private:
95 Persistent<ScriptPromiseResolver> m_resolver; 94 Persistent<ScriptPromiseResolver> m_resolver;
96 WTF_MAKE_NONCOPYABLE(RegistrationCallback); 95 WTF_MAKE_NONCOPYABLE(RegistrationCallback);
97 }; 96 };
98 97
99 class GetRegistrationCallback : public WebServiceWorkerProvider:: 98 class GetRegistrationCallback : public WebServiceWorkerProvider::
100 WebServiceWorkerGetRegistrationCallbacks { 99 WebServiceWorkerGetRegistrationCallbacks {
101 public: 100 public:
102 explicit GetRegistrationCallback(ScriptPromiseResolver* resolver) 101 explicit GetRegistrationCallback(ScriptPromiseResolver* resolver)
103 : m_resolver(resolver) {} 102 : m_resolver(resolver) {}
104 ~GetRegistrationCallback() override {} 103 ~GetRegistrationCallback() override {}
105 104
106 void onSuccess(std::unique_ptr<WebServiceWorkerRegistration::Handle> 105 void onSuccess(std::unique_ptr<WebServiceWorkerRegistration::Handle>
107 webPassHandle) override { 106 webPassHandle) override {
108 std::unique_ptr<WebServiceWorkerRegistration::Handle> handle = 107 std::unique_ptr<WebServiceWorkerRegistration::Handle> handle =
109 wrapUnique(webPassHandle.release()); 108 std::move(webPassHandle);
110 if (!m_resolver->getExecutionContext() || 109 if (!m_resolver->getExecutionContext())
111 m_resolver->getExecutionContext()->activeDOMObjectsAreStopped())
112 return; 110 return;
113 if (!handle) { 111 if (!handle) {
114 // Resolve the promise with undefined. 112 // Resolve the promise with undefined.
115 m_resolver->resolve(); 113 m_resolver->resolve();
116 return; 114 return;
117 } 115 }
118 m_resolver->resolve(ServiceWorkerRegistration::getOrCreate( 116 m_resolver->resolve(ServiceWorkerRegistration::getOrCreate(
119 m_resolver->getExecutionContext(), std::move(handle))); 117 m_resolver->getExecutionContext(), std::move(handle)));
120 } 118 }
121 119
122 void onError(const WebServiceWorkerError& error) override { 120 void onError(const WebServiceWorkerError& error) override {
123 if (!m_resolver->getExecutionContext() || 121 if (!m_resolver->getExecutionContext())
124 m_resolver->getExecutionContext()->activeDOMObjectsAreStopped())
125 return; 122 return;
126 m_resolver->reject(ServiceWorkerError::take(m_resolver.get(), error)); 123 m_resolver->reject(ServiceWorkerError::take(m_resolver.get(), error));
127 } 124 }
128 125
129 private: 126 private:
130 Persistent<ScriptPromiseResolver> m_resolver; 127 Persistent<ScriptPromiseResolver> m_resolver;
131 WTF_MAKE_NONCOPYABLE(GetRegistrationCallback); 128 WTF_MAKE_NONCOPYABLE(GetRegistrationCallback);
132 }; 129 };
133 130
134 class GetRegistrationsCallback : public WebServiceWorkerProvider:: 131 class GetRegistrationsCallback : public WebServiceWorkerProvider::
135 WebServiceWorkerGetRegistrationsCallbacks { 132 WebServiceWorkerGetRegistrationsCallbacks {
136 public: 133 public:
137 explicit GetRegistrationsCallback(ScriptPromiseResolver* resolver) 134 explicit GetRegistrationsCallback(ScriptPromiseResolver* resolver)
138 : m_resolver(resolver) {} 135 : m_resolver(resolver) {}
139 ~GetRegistrationsCallback() override {} 136 ~GetRegistrationsCallback() override {}
140 137
141 void onSuccess( 138 void onSuccess(
142 std::unique_ptr<WebVector<WebServiceWorkerRegistration::Handle*>> 139 std::unique_ptr<WebVector<WebServiceWorkerRegistration::Handle*>>
143 webPassRegistrations) override { 140 webPassRegistrations) override {
144 Vector<std::unique_ptr<WebServiceWorkerRegistration::Handle>> handles; 141 Vector<std::unique_ptr<WebServiceWorkerRegistration::Handle>> handles;
145 std::unique_ptr<WebVector<WebServiceWorkerRegistration::Handle*>> 142 std::unique_ptr<WebVector<WebServiceWorkerRegistration::Handle*>>
146 webRegistrations = wrapUnique(webPassRegistrations.release()); 143 webRegistrations = std::move(webPassRegistrations);
147 for (auto& handle : *webRegistrations) { 144 for (auto& handle : *webRegistrations) {
148 handles.append(wrapUnique(handle)); 145 handles.append(wrapUnique(handle));
149 } 146 }
150 147
151 if (!m_resolver->getExecutionContext() || 148 if (!m_resolver->getExecutionContext())
152 m_resolver->getExecutionContext()->activeDOMObjectsAreStopped())
153 return; 149 return;
154 m_resolver->resolve( 150 m_resolver->resolve(
155 ServiceWorkerRegistrationArray::take(m_resolver.get(), &handles)); 151 ServiceWorkerRegistrationArray::take(m_resolver.get(), &handles));
156 } 152 }
157 153
158 void onError(const WebServiceWorkerError& error) override { 154 void onError(const WebServiceWorkerError& error) override {
159 if (!m_resolver->getExecutionContext() || 155 if (!m_resolver->getExecutionContext())
160 m_resolver->getExecutionContext()->activeDOMObjectsAreStopped())
161 return; 156 return;
162 m_resolver->reject(ServiceWorkerError::take(m_resolver.get(), error)); 157 m_resolver->reject(ServiceWorkerError::take(m_resolver.get(), error));
163 } 158 }
164 159
165 private: 160 private:
166 Persistent<ScriptPromiseResolver> m_resolver; 161 Persistent<ScriptPromiseResolver> m_resolver;
167 WTF_MAKE_NONCOPYABLE(GetRegistrationsCallback); 162 WTF_MAKE_NONCOPYABLE(GetRegistrationsCallback);
168 }; 163 };
169 164
170 class ServiceWorkerContainer::GetRegistrationForReadyCallback 165 class ServiceWorkerContainer::GetRegistrationForReadyCallback
171 : public WebServiceWorkerProvider:: 166 : public WebServiceWorkerProvider::
172 WebServiceWorkerGetRegistrationForReadyCallbacks { 167 WebServiceWorkerGetRegistrationForReadyCallbacks {
173 public: 168 public:
174 explicit GetRegistrationForReadyCallback(ReadyProperty* ready) 169 explicit GetRegistrationForReadyCallback(ReadyProperty* ready)
175 : m_ready(ready) {} 170 : m_ready(ready) {}
176 ~GetRegistrationForReadyCallback() override {} 171 ~GetRegistrationForReadyCallback() override {}
177 172
178 void onSuccess( 173 void onSuccess(
179 std::unique_ptr<WebServiceWorkerRegistration::Handle> handle) override { 174 std::unique_ptr<WebServiceWorkerRegistration::Handle> handle) override {
180 ASSERT(m_ready->getState() == ReadyProperty::Pending); 175 ASSERT(m_ready->getState() == ReadyProperty::Pending);
181 176
182 if (m_ready->getExecutionContext() && 177 if (m_ready->getExecutionContext()) {
183 !m_ready->getExecutionContext()->activeDOMObjectsAreStopped())
184 m_ready->resolve(ServiceWorkerRegistration::getOrCreate( 178 m_ready->resolve(ServiceWorkerRegistration::getOrCreate(
185 m_ready->getExecutionContext(), wrapUnique(handle.release()))); 179 m_ready->getExecutionContext(), std::move(handle)));
180 }
186 } 181 }
187 182
188 private: 183 private:
189 Persistent<ReadyProperty> m_ready; 184 Persistent<ReadyProperty> m_ready;
190 WTF_MAKE_NONCOPYABLE(GetRegistrationForReadyCallback); 185 WTF_MAKE_NONCOPYABLE(GetRegistrationForReadyCallback);
191 }; 186 };
192 187
193 ServiceWorkerContainer* ServiceWorkerContainer::create( 188 ServiceWorkerContainer* ServiceWorkerContainer::create(
194 ExecutionContext* executionContext) { 189 ExecutionContext* executionContext) {
195 return new ServiceWorkerContainer(executionContext); 190 return new ServiceWorkerContainer(executionContext);
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 522
528 if (ServiceWorkerContainerClient* client = 523 if (ServiceWorkerContainerClient* client =
529 ServiceWorkerContainerClient::from(executionContext)) { 524 ServiceWorkerContainerClient::from(executionContext)) {
530 m_provider = client->provider(); 525 m_provider = client->provider();
531 if (m_provider) 526 if (m_provider)
532 m_provider->setClient(this); 527 m_provider->setClient(this);
533 } 528 }
534 } 529 }
535 530
536 } // namespace blink 531 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698