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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 es.throwSecurityError("Can only register for patterns in the document's
origin."); | 112 es.throwSecurityError("Can only register for patterns in the document's
origin."); |
113 return ScriptPromise(); | 113 return ScriptPromise(); |
114 } | 114 } |
115 | 115 |
116 KURL scriptURL = executionContext->completeURL(scriptSrc); | 116 KURL scriptURL = executionContext->completeURL(scriptSrc); |
117 if (documentOrigin->canRequest(scriptURL)) { | 117 if (documentOrigin->canRequest(scriptURL)) { |
118 es.throwSecurityError("Script must be in document's origin."); | 118 es.throwSecurityError("Script must be in document's origin."); |
119 return ScriptPromise(); | 119 return ScriptPromise(); |
120 } | 120 } |
121 | 121 |
122 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(execu
tionContext); | 122 ScriptPromise promise = ScriptPromise::createPending(executionContext); |
| 123 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(promi
se, executionContext); |
123 ensureProvider()->registerServiceWorker(patternURL, scriptURL, new CallbackP
romiseAdapter(resolver, executionContext)); | 124 ensureProvider()->registerServiceWorker(patternURL, scriptURL, new CallbackP
romiseAdapter(resolver, executionContext)); |
124 return resolver->promise(); | 125 return promise; |
125 } | 126 } |
126 | 127 |
127 ScriptPromise NavigatorServiceWorker::unregisterServiceWorker(ExecutionContext*
context, Navigator* navigator, const String& pattern, ExceptionState& es) | 128 ScriptPromise NavigatorServiceWorker::unregisterServiceWorker(ExecutionContext*
context, Navigator* navigator, const String& pattern, ExceptionState& es) |
128 { | 129 { |
129 return from(navigator)->unregisterServiceWorker(context, pattern, es); | 130 return from(navigator)->unregisterServiceWorker(context, pattern, es); |
130 } | 131 } |
131 | 132 |
132 ScriptPromise NavigatorServiceWorker::unregisterServiceWorker(ExecutionContext*
executionContext, const String& pattern, ExceptionState& es) | 133 ScriptPromise NavigatorServiceWorker::unregisterServiceWorker(ExecutionContext*
executionContext, const String& pattern, ExceptionState& es) |
133 { | 134 { |
134 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); | 135 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); |
135 Frame* frame = m_navigator->frame(); | 136 Frame* frame = m_navigator->frame(); |
136 if (!frame) { | 137 if (!frame) { |
137 es.throwDOMException(InvalidStateError, "No document available."); | 138 es.throwDOMException(InvalidStateError, "No document available."); |
138 return ScriptPromise(); | 139 return ScriptPromise(); |
139 } | 140 } |
140 | 141 |
141 RefPtr<SecurityOrigin> documentOrigin = frame->document()->securityOrigin(); | 142 RefPtr<SecurityOrigin> documentOrigin = frame->document()->securityOrigin(); |
142 | 143 |
143 KURL patternURL = executionContext->completeURL(pattern); | 144 KURL patternURL = executionContext->completeURL(pattern); |
144 if (documentOrigin->canRequest(patternURL)) { | 145 if (documentOrigin->canRequest(patternURL)) { |
145 es.throwSecurityError("Can only unregister for patterns in the document'
s origin."); | 146 es.throwSecurityError("Can only unregister for patterns in the document'
s origin."); |
146 return ScriptPromise(); | 147 return ScriptPromise(); |
147 } | 148 } |
148 | 149 |
149 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(execu
tionContext); | 150 ScriptPromise promise = ScriptPromise::createPending(executionContext); |
| 151 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(promi
se, executionContext); |
150 ensureProvider()->unregisterServiceWorker(patternURL, new CallbackPromiseAda
pter(resolver, executionContext)); | 152 ensureProvider()->unregisterServiceWorker(patternURL, new CallbackPromiseAda
pter(resolver, executionContext)); |
151 return resolver->promise(); | 153 return promise; |
152 } | 154 } |
153 | 155 |
154 void NavigatorServiceWorker::willDetachGlobalObjectFromFrame() | 156 void NavigatorServiceWorker::willDetachGlobalObjectFromFrame() |
155 { | 157 { |
156 m_provider = nullptr; | 158 m_provider = nullptr; |
157 DOMWindowProperty::willDetachGlobalObjectFromFrame(); | 159 DOMWindowProperty::willDetachGlobalObjectFromFrame(); |
158 } | 160 } |
159 | 161 |
160 | 162 |
161 } // namespace WebCore | 163 } // namespace WebCore |
OLD | NEW |