| 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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 if (!documentOrigin->canRequest(scriptURL)) { | 117 if (!documentOrigin->canRequest(scriptURL)) { |
| 118 resolver->reject(DOMException::create(SecurityError, "The origin of the
script must match the current origin.")); | 118 resolver->reject(DOMException::create(SecurityError, "The origin of the
script must match the current origin.")); |
| 119 return promise; | 119 return promise; |
| 120 } | 120 } |
| 121 | 121 |
| 122 m_provider->registerServiceWorker(patternURL, scriptURL, new CallbackPromise
Adapter<ServiceWorkerRegistration, ServiceWorkerError>(resolver)); | 122 m_provider->registerServiceWorker(patternURL, scriptURL, new CallbackPromise
Adapter<ServiceWorkerRegistration, ServiceWorkerError>(resolver)); |
| 123 | 123 |
| 124 return promise; | 124 return promise; |
| 125 } | 125 } |
| 126 | 126 |
| 127 #ifdef DISABLE_SERVICEWORKER_UNREGISTER_RESOLVE_TO_BOOLEAN | |
| 128 class UndefinedValue { | |
| 129 public: | |
| 130 typedef WebServiceWorkerRegistration WebType; | |
| 131 static V8UndefinedType take(ScriptPromiseResolver* resolver, WebType* regist
ration) | |
| 132 { | |
| 133 ASSERT(!registration); // Anything passed here will be leaked. | |
| 134 return V8UndefinedType(); | |
| 135 } | |
| 136 static void dispose(WebType* registration) | |
| 137 { | |
| 138 ASSERT(!registration); // Anything passed here will be leaked. | |
| 139 } | |
| 140 | |
| 141 private: | |
| 142 UndefinedValue(); | |
| 143 }; | |
| 144 #else | |
| 145 class BooleanValue { | 127 class BooleanValue { |
| 146 public: | 128 public: |
| 147 typedef bool WebType; | 129 typedef bool WebType; |
| 148 static bool take(ScriptPromiseResolver* resolver, WebType* boolean) | 130 static bool take(ScriptPromiseResolver* resolver, WebType* boolean) |
| 149 { | 131 { |
| 150 return *boolean; | 132 return *boolean; |
| 151 } | 133 } |
| 152 static void dispose(WebType* boolean) { } | 134 static void dispose(WebType* boolean) { } |
| 153 | 135 |
| 154 private: | 136 private: |
| 155 BooleanValue(); | 137 BooleanValue(); |
| 156 }; | 138 }; |
| 157 #endif | |
| 158 | 139 |
| 159 ScriptPromise ServiceWorkerContainer::unregisterServiceWorker(ScriptState* scrip
tState, const String& pattern) | 140 ScriptPromise ServiceWorkerContainer::unregisterServiceWorker(ScriptState* scrip
tState, const String& pattern) |
| 160 { | 141 { |
| 161 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); | 142 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); |
| 162 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tState); | 143 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tState); |
| 163 ScriptPromise promise = resolver->promise(); | 144 ScriptPromise promise = resolver->promise(); |
| 164 | 145 |
| 165 if (!m_provider) { | 146 if (!m_provider) { |
| 166 resolver->reject(DOMException::create(InvalidStateError, "No associated
provider is available")); | 147 resolver->reject(DOMException::create(InvalidStateError, "No associated
provider is available")); |
| 167 return promise; | 148 return promise; |
| 168 } | 149 } |
| 169 | 150 |
| 170 // FIXME: This should use the container's execution context, not | 151 // FIXME: This should use the container's execution context, not |
| 171 // the callers. | 152 // the callers. |
| 172 RefPtr<SecurityOrigin> documentOrigin = scriptState->executionContext()->sec
urityOrigin(); | 153 RefPtr<SecurityOrigin> documentOrigin = scriptState->executionContext()->sec
urityOrigin(); |
| 173 String errorMessage; | 154 String errorMessage; |
| 174 if (!documentOrigin->canAccessFeatureRequiringSecureOrigin(errorMessage)) { | 155 if (!documentOrigin->canAccessFeatureRequiringSecureOrigin(errorMessage)) { |
| 175 resolver->reject(DOMException::create(NotSupportedError, errorMessage)); | 156 resolver->reject(DOMException::create(NotSupportedError, errorMessage)); |
| 176 return promise; | 157 return promise; |
| 177 } | 158 } |
| 178 | 159 |
| 179 KURL patternURL = scriptState->executionContext()->completeURL(pattern); | 160 KURL patternURL = scriptState->executionContext()->completeURL(pattern); |
| 180 patternURL.removeFragmentIdentifier(); | 161 patternURL.removeFragmentIdentifier(); |
| 181 if (!pattern.isEmpty() && !documentOrigin->canRequest(patternURL)) { | 162 if (!pattern.isEmpty() && !documentOrigin->canRequest(patternURL)) { |
| 182 resolver->reject(DOMException::create(SecurityError, "The scope must mat
ch the current origin.")); | 163 resolver->reject(DOMException::create(SecurityError, "The scope must mat
ch the current origin.")); |
| 183 return promise; | 164 return promise; |
| 184 } | 165 } |
| 185 #ifdef DISABLE_SERVICEWORKER_UNREGISTER_RESOLVE_TO_BOOLEAN | |
| 186 m_provider->unregisterServiceWorker(patternURL, new CallbackPromiseAdapter<U
ndefinedValue, ServiceWorkerError>(resolver)); | |
| 187 #else | |
| 188 m_provider->unregisterServiceWorker(patternURL, new CallbackPromiseAdapter<B
ooleanValue, ServiceWorkerError>(resolver)); | 166 m_provider->unregisterServiceWorker(patternURL, new CallbackPromiseAdapter<B
ooleanValue, ServiceWorkerError>(resolver)); |
| 189 #endif | |
| 190 return promise; | 167 return promise; |
| 191 } | 168 } |
| 192 | 169 |
| 193 ServiceWorkerContainer::ReadyProperty* ServiceWorkerContainer::createReadyProper
ty() | 170 ServiceWorkerContainer::ReadyProperty* ServiceWorkerContainer::createReadyProper
ty() |
| 194 { | 171 { |
| 195 return new ReadyProperty(executionContext(), this, ReadyProperty::Ready); | 172 return new ReadyProperty(executionContext(), this, ReadyProperty::Ready); |
| 196 } | 173 } |
| 197 | 174 |
| 198 ScriptPromise ServiceWorkerContainer::ready(ScriptState* callerState) | 175 ScriptPromise ServiceWorkerContainer::ready(ScriptState* callerState) |
| 199 { | 176 { |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 m_ready = createReadyProperty(); | 272 m_ready = createReadyProperty(); |
| 296 | 273 |
| 297 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro
m(executionContext)) { | 274 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro
m(executionContext)) { |
| 298 m_provider = client->provider(); | 275 m_provider = client->provider(); |
| 299 if (m_provider) | 276 if (m_provider) |
| 300 m_provider->setClient(this); | 277 m_provider->setClient(this); |
| 301 } | 278 } |
| 302 } | 279 } |
| 303 | 280 |
| 304 } // namespace blink | 281 } // namespace blink |
| OLD | NEW |