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

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

Issue 2388023002: service worker: navigation preload basic setters/getters and flag
Patch Set: idl 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 13 matching lines...) Expand all
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "modules/serviceworkers/ServiceWorker.h" 31 #include "modules/serviceworkers/ServiceWorker.h"
32 32
33 #include "bindings/core/v8/ExceptionState.h" 33 #include "bindings/core/v8/ExceptionState.h"
34 #include "bindings/core/v8/ScriptPromiseResolver.h"
35 #include "core/dom/DOMException.h"
34 #include "core/dom/ExceptionCode.h" 36 #include "core/dom/ExceptionCode.h"
35 #include "core/dom/MessagePort.h" 37 #include "core/dom/MessagePort.h"
36 #include "core/events/Event.h" 38 #include "core/events/Event.h"
37 #include "core/inspector/ConsoleMessage.h" 39 #include "core/inspector/ConsoleMessage.h"
38 #include "modules/EventTargetModules.h" 40 #include "modules/EventTargetModules.h"
41 #include "modules/serviceworkers/NavigationPreloadOptions.h"
39 #include "modules/serviceworkers/ServiceWorkerContainerClient.h" 42 #include "modules/serviceworkers/ServiceWorkerContainerClient.h"
43 #include "modules/serviceworkers/ServiceWorkerError.h"
40 #include "public/platform/WebMessagePortChannel.h" 44 #include "public/platform/WebMessagePortChannel.h"
41 #include "public/platform/WebSecurityOrigin.h" 45 #include "public/platform/WebSecurityOrigin.h"
42 #include "public/platform/WebString.h" 46 #include "public/platform/WebString.h"
43 #include "public/platform/modules/serviceworker/WebServiceWorkerState.h" 47 #include "public/platform/modules/serviceworker/WebServiceWorkerState.h"
44 #include <memory> 48 #include <memory>
45 49
46 namespace blink { 50 namespace blink {
47 51
52 namespace {
53
54 class SetNavigationPreloadCallbacks
55 : public WebServiceWorker::WebSetNavigationPreloadCallbacks {
56 public:
57 explicit SetNavigationPreloadCallbacks(ScriptPromiseResolver* resolver)
58 : m_resolver(resolver) {}
59 ~SetNavigationPreloadCallbacks() override {}
60
61 void onSuccess() override { m_resolver->resolve(); }
62
63 void onError(const WebServiceWorkerError& error) override {
64 if (!m_resolver->getExecutionContext() ||
65 m_resolver->getExecutionContext()->activeDOMObjectsAreStopped())
66 return;
67 m_resolver->reject(ServiceWorkerError::take(m_resolver.get(), error));
68 }
69
70 private:
71 Persistent<ScriptPromiseResolver> m_resolver;
72 WTF_MAKE_NONCOPYABLE(SetNavigationPreloadCallbacks);
73 };
74
75 class GetNavigationPreloadCallbacks
76 : public WebServiceWorker::WebGetNavigationPreloadCallbacks {
77 public:
78 explicit GetNavigationPreloadCallbacks(ScriptPromiseResolver* resolver)
79 : m_resolver(resolver) {}
80 ~GetNavigationPreloadCallbacks() override {}
81
82 void onSuccess(const WebString& value) override {
83 NavigationPreloadOptions options;
84 options.setValue(value);
85 m_resolver->resolve(options);
86 }
87
88 void onError(const WebServiceWorkerError& error) override {
89 if (!m_resolver->getExecutionContext() ||
90 m_resolver->getExecutionContext()->activeDOMObjectsAreStopped())
91 return;
92 m_resolver->reject(ServiceWorkerError::take(m_resolver.get(), error));
93 }
94
95 private:
96 Persistent<ScriptPromiseResolver> m_resolver;
97 WTF_MAKE_NONCOPYABLE(GetNavigationPreloadCallbacks);
98 };
99
100 } // namespace
101
48 const AtomicString& ServiceWorker::interfaceName() const { 102 const AtomicString& ServiceWorker::interfaceName() const {
49 return EventTargetNames::ServiceWorker; 103 return EventTargetNames::ServiceWorker;
50 } 104 }
51 105
52 void ServiceWorker::postMessage(ExecutionContext* context, 106 void ServiceWorker::postMessage(ExecutionContext* context,
53 PassRefPtr<SerializedScriptValue> message, 107 PassRefPtr<SerializedScriptValue> message,
54 const MessagePortArray& ports, 108 const MessagePortArray& ports,
55 ExceptionState& exceptionState) { 109 ExceptionState& exceptionState) {
56 ServiceWorkerContainerClient* client = 110 ServiceWorkerContainerClient* client =
57 ServiceWorkerContainerClient::from(getExecutionContext()); 111 ServiceWorkerContainerClient::from(getExecutionContext());
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 bool ServiceWorker::hasPendingActivity() const { 185 bool ServiceWorker::hasPendingActivity() const {
132 if (m_wasStopped) 186 if (m_wasStopped)
133 return false; 187 return false;
134 return m_handle->serviceWorker()->state() != WebServiceWorkerStateRedundant; 188 return m_handle->serviceWorker()->state() != WebServiceWorkerStateRedundant;
135 } 189 }
136 190
137 void ServiceWorker::stop() { 191 void ServiceWorker::stop() {
138 m_wasStopped = true; 192 m_wasStopped = true;
139 } 193 }
140 194
195 ScriptPromise ServiceWorker::setNavigationPreload(
196 ScriptState* scriptState,
197 const NavigationPreloadOptions& options) {
198 LOG(ERROR) << "setNavP";
199 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
200 ScriptPromise promise = resolver->promise();
201 m_handle->serviceWorker()->setNavigationPreload(
202 options.value(), new SetNavigationPreloadCallbacks(resolver));
203 return promise;
204 }
205
206 ScriptPromise ServiceWorker::getNavigationPreload(ScriptState* scriptState) {
207 LOG(ERROR) << "getNavP";
208 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
209 ScriptPromise promise = resolver->promise();
210 m_handle->serviceWorker()->getNavigationPreload(
211 new GetNavigationPreloadCallbacks(resolver));
212 return promise;
213 }
214
141 ServiceWorker* ServiceWorker::getOrCreate( 215 ServiceWorker* ServiceWorker::getOrCreate(
142 ExecutionContext* executionContext, 216 ExecutionContext* executionContext,
143 std::unique_ptr<WebServiceWorker::Handle> handle) { 217 std::unique_ptr<WebServiceWorker::Handle> handle) {
144 if (!handle) 218 if (!handle)
145 return nullptr; 219 return nullptr;
146 220
147 ServiceWorker* existingWorker = 221 ServiceWorker* existingWorker =
148 static_cast<ServiceWorker*>(handle->serviceWorker()->proxy()); 222 static_cast<ServiceWorker*>(handle->serviceWorker()->proxy());
149 if (existingWorker) { 223 if (existingWorker) {
150 ASSERT(existingWorker->getExecutionContext() == executionContext); 224 ASSERT(existingWorker->getExecutionContext() == executionContext);
(...skipping 16 matching lines...) Expand all
167 m_handle->serviceWorker()->setProxy(this); 241 m_handle->serviceWorker()->setProxy(this);
168 } 242 }
169 243
170 ServiceWorker::~ServiceWorker() {} 244 ServiceWorker::~ServiceWorker() {}
171 245
172 DEFINE_TRACE(ServiceWorker) { 246 DEFINE_TRACE(ServiceWorker) {
173 AbstractWorker::trace(visitor); 247 AbstractWorker::trace(visitor);
174 } 248 }
175 249
176 } // namespace blink 250 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698