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 #include "modules/serviceworkers/ServiceWorkerClients.h" | 5 #include "modules/serviceworkers/ServiceWorkerClients.h" |
6 | 6 |
7 #include "bindings/core/v8/CallbackPromiseAdapter.h" | 7 #include "bindings/core/v8/CallbackPromiseAdapter.h" |
8 #include "bindings/core/v8/ScriptPromiseResolver.h" | 8 #include "bindings/core/v8/ScriptPromiseResolver.h" |
9 #include "core/dom/DOMException.h" | 9 #include "core/dom/DOMException.h" |
10 #include "core/dom/ExceptionCode.h" | 10 #include "core/dom/ExceptionCode.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
53 if (type == "worker") | 53 if (type == "worker") |
54 return WebServiceWorkerClientTypeWorker; | 54 return WebServiceWorkerClientTypeWorker; |
55 if (type == "sharedworker") | 55 if (type == "sharedworker") |
56 return WebServiceWorkerClientTypeSharedWorker; | 56 return WebServiceWorkerClientTypeSharedWorker; |
57 if (type == "all") | 57 if (type == "all") |
58 return WebServiceWorkerClientTypeAll; | 58 return WebServiceWorkerClientTypeAll; |
59 ASSERT_NOT_REACHED(); | 59 ASSERT_NOT_REACHED(); |
60 return WebServiceWorkerClientTypeWindow; | 60 return WebServiceWorkerClientTypeWindow; |
61 } | 61 } |
62 | 62 |
63 class GetCallback : public WebServiceWorkerClientCallbacks { | |
64 public: | |
65 explicit GetCallback(ScriptPromiseResolver* resolver) | |
66 : m_resolver(resolver) { } | |
67 ~GetCallback() override { } | |
68 | |
69 void onSuccess(WebPassOwnPtr<WebServiceWorkerClientInfo> webClient) override | |
70 { | |
71 OwnPtr<WebServiceWorkerClientInfo> client = webClient.release(); | |
72 if (!m_resolver->executionContext() || m_resolver->executionContext()->a ctiveDOMObjectsAreStopped()) | |
73 return; | |
74 if (!client || client->uuid.isEmpty()) { | |
nhiroki
2016/02/22 15:59:09
According to the assertion newly added at line 897
jungkees
2016/02/22 23:08:25
Yes, that's right. I removed the latter condition.
| |
75 // Resolve the promise with undefined. | |
76 m_resolver->resolve(); | |
77 return; | |
78 } | |
79 m_resolver->resolve(ServiceWorkerClient::take(m_resolver, client.release ())); | |
80 } | |
81 | |
82 void onError(const WebServiceWorkerError& error) override | |
83 { | |
84 if (!m_resolver->executionContext() || m_resolver->executionContext()->a ctiveDOMObjectsAreStopped()) | |
85 return; | |
86 m_resolver->reject(ServiceWorkerError::take(m_resolver.get(), error)); | |
87 } | |
88 | |
89 private: | |
90 Persistent<ScriptPromiseResolver> m_resolver; | |
91 WTF_MAKE_NONCOPYABLE(GetCallback); | |
92 }; | |
93 | |
63 } // namespace | 94 } // namespace |
64 | 95 |
65 ServiceWorkerClients* ServiceWorkerClients::create() | 96 ServiceWorkerClients* ServiceWorkerClients::create() |
66 { | 97 { |
67 return new ServiceWorkerClients(); | 98 return new ServiceWorkerClients(); |
68 } | 99 } |
69 | 100 |
70 ServiceWorkerClients::ServiceWorkerClients() | 101 ServiceWorkerClients::ServiceWorkerClients() |
71 { | 102 { |
72 } | 103 } |
73 | 104 |
105 ScriptPromise ServiceWorkerClients::get(ScriptState* scriptState, const String& id) | |
106 { | |
107 ExecutionContext* executionContext = scriptState->executionContext(); | |
108 // TODO(jungkees): May be null due to worker termination: http://crbug.com/4 13518. | |
109 if (!executionContext) | |
110 return ScriptPromise(); | |
111 | |
112 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; | |
113 ScriptPromise promise = resolver->promise(); | |
114 | |
115 ServiceWorkerGlobalScopeClient::from(executionContext)->getClient(id, new Ge tCallback(resolver)); | |
116 return promise; | |
117 } | |
118 | |
74 ScriptPromise ServiceWorkerClients::matchAll(ScriptState* scriptState, const Cli entQueryOptions& options) | 119 ScriptPromise ServiceWorkerClients::matchAll(ScriptState* scriptState, const Cli entQueryOptions& options) |
75 { | 120 { |
76 ExecutionContext* executionContext = scriptState->executionContext(); | 121 ExecutionContext* executionContext = scriptState->executionContext(); |
77 // FIXME: May be null due to worker termination: http://crbug.com/413518. | 122 // FIXME: May be null due to worker termination: http://crbug.com/413518. |
78 if (!executionContext) | 123 if (!executionContext) |
79 return ScriptPromise(); | 124 return ScriptPromise(); |
80 | 125 |
81 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; | 126 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; |
82 ScriptPromise promise = resolver->promise(); | 127 ScriptPromise promise = resolver->promise(); |
83 | 128 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
125 resolver->reject(DOMException::create(InvalidAccessError, "Not allowed t o open a window.")); | 170 resolver->reject(DOMException::create(InvalidAccessError, "Not allowed t o open a window.")); |
126 return promise; | 171 return promise; |
127 } | 172 } |
128 context->consumeWindowInteraction(); | 173 context->consumeWindowInteraction(); |
129 | 174 |
130 ServiceWorkerGlobalScopeClient::from(context)->openWindow(parsedUrl, new Nav igateClientCallback(resolver)); | 175 ServiceWorkerGlobalScopeClient::from(context)->openWindow(parsedUrl, new Nav igateClientCallback(resolver)); |
131 return promise; | 176 return promise; |
132 } | 177 } |
133 | 178 |
134 } // namespace blink | 179 } // namespace blink |
OLD | NEW |