| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 } | 63 } |
| 64 } | 64 } |
| 65 | 65 |
| 66 ScriptPromise ServiceWorkerContainer::registerServiceWorker(ExecutionContext* ex
ecutionContext, const String& url, const Dictionary& dictionary) | 66 ScriptPromise ServiceWorkerContainer::registerServiceWorker(ExecutionContext* ex
ecutionContext, const String& url, const Dictionary& dictionary) |
| 67 { | 67 { |
| 68 RegistrationOptionList options(dictionary); | 68 RegistrationOptionList options(dictionary); |
| 69 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); | 69 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); |
| 70 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(execu
tionContext); | 70 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(execu
tionContext); |
| 71 ScriptPromise promise = resolver->promise(); | 71 ScriptPromise promise = resolver->promise(); |
| 72 | 72 |
| 73 if (!m_provider) { |
| 74 resolver->reject(DOMError::create(InvalidStateError, "No associated prov
ider is available")); |
| 75 return promise; |
| 76 } |
| 77 |
| 73 RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin(); | 78 RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin(); |
| 74 KURL patternURL = executionContext->completeURL(options.scope); | 79 KURL patternURL = executionContext->completeURL(options.scope); |
| 75 if (!documentOrigin->canRequest(patternURL)) { | 80 if (!documentOrigin->canRequest(patternURL)) { |
| 76 resolver->reject(DOMError::create(SecurityError, "Can only register for
patterns in the document's origin.")); | 81 resolver->reject(DOMError::create(SecurityError, "Can only register for
patterns in the document's origin.")); |
| 77 return promise; | 82 return promise; |
| 78 } | 83 } |
| 79 | 84 |
| 80 KURL scriptURL = executionContext->completeURL(url); | 85 KURL scriptURL = executionContext->completeURL(url); |
| 81 if (!documentOrigin->canRequest(scriptURL)) { | 86 if (!documentOrigin->canRequest(scriptURL)) { |
| 82 resolver->reject(DOMError::create(SecurityError, "Script must be in docu
ment's origin.")); | 87 resolver->reject(DOMError::create(SecurityError, "Script must be in docu
ment's origin.")); |
| 83 return promise; | 88 return promise; |
| 84 } | 89 } |
| 85 | 90 |
| 86 m_provider->registerServiceWorker(patternURL, scriptURL, new CallbackPromise
Adapter<ServiceWorker, ServiceWorkerError>(resolver, executionContext)); | 91 m_provider->registerServiceWorker(patternURL, scriptURL, new CallbackPromise
Adapter<ServiceWorker, ServiceWorkerError>(resolver, executionContext)); |
| 87 return promise; | 92 return promise; |
| 88 } | 93 } |
| 89 | 94 |
| 90 ScriptPromise ServiceWorkerContainer::unregisterServiceWorker(ExecutionContext*
executionContext, const String& pattern) | 95 ScriptPromise ServiceWorkerContainer::unregisterServiceWorker(ExecutionContext*
executionContext, const String& pattern) |
| 91 { | 96 { |
| 92 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); | 97 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); |
| 93 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(execu
tionContext); | 98 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(execu
tionContext); |
| 94 ScriptPromise promise = resolver->promise(); | 99 ScriptPromise promise = resolver->promise(); |
| 95 | 100 |
| 101 if (!m_provider) { |
| 102 resolver->reject(DOMError::create(InvalidStateError, "No associated prov
ider is available")); |
| 103 return promise; |
| 104 } |
| 105 |
| 96 RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin(); | 106 RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin(); |
| 97 KURL patternURL = executionContext->completeURL(pattern); | 107 KURL patternURL = executionContext->completeURL(pattern); |
| 98 if (!pattern.isEmpty() && !documentOrigin->canRequest(patternURL)) { | 108 if (!pattern.isEmpty() && !documentOrigin->canRequest(patternURL)) { |
| 99 resolver->reject(DOMError::create(SecurityError, "Can only unregister fo
r patterns in the document's origin.")); | 109 resolver->reject(DOMError::create(SecurityError, "Can only unregister fo
r patterns in the document's origin.")); |
| 100 | |
| 101 return promise; | 110 return promise; |
| 102 } | 111 } |
| 103 | 112 |
| 104 m_provider->unregisterServiceWorker(patternURL, new CallbackPromiseAdapter<S
erviceWorker, ServiceWorkerError>(resolver, executionContext)); | 113 m_provider->unregisterServiceWorker(patternURL, new CallbackPromiseAdapter<S
erviceWorker, ServiceWorkerError>(resolver, executionContext)); |
| 105 return promise; | 114 return promise; |
| 106 } | 115 } |
| 107 | 116 |
| 108 ServiceWorkerContainer::ServiceWorkerContainer(ExecutionContext* executionContex
t) | 117 ServiceWorkerContainer::ServiceWorkerContainer(ExecutionContext* executionContex
t) |
| 109 : m_provider(ServiceWorkerContainerClient::from(executionContext)->provider(
)) | 118 : m_provider(0) |
| 110 { | 119 { |
| 111 ScriptWrappable::init(this); | 120 ScriptWrappable::init(this); |
| 112 m_provider->setClient(this); | 121 |
| 122 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro
m(executionContext)) { |
| 123 m_provider = client->provider(); |
| 124 if (m_provider) |
| 125 m_provider->setClient(this); |
| 126 } |
| 113 } | 127 } |
| 114 | 128 |
| 115 } // namespace WebCore | 129 } // namespace WebCore |
| OLD | NEW |