| 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 NavigatorServiceWorker* NavigatorServiceWorker::from(Navigator* navigator) | 85 NavigatorServiceWorker* NavigatorServiceWorker::from(Navigator* navigator) |
| 86 { | 86 { |
| 87 NavigatorServiceWorker* supplement = toNavigatorServiceWorker(navigator); | 87 NavigatorServiceWorker* supplement = toNavigatorServiceWorker(navigator); |
| 88 if (!supplement) { | 88 if (!supplement) { |
| 89 supplement = new NavigatorServiceWorker(navigator); | 89 supplement = new NavigatorServiceWorker(navigator); |
| 90 provideTo(navigator, supplementName(), adoptPtr(supplement)); | 90 provideTo(navigator, supplementName(), adoptPtr(supplement)); |
| 91 } | 91 } |
| 92 return supplement; | 92 return supplement; |
| 93 } | 93 } |
| 94 | 94 |
| 95 ScriptPromise NavigatorServiceWorker::registerServiceWorker(ExecutionContext* co
ntext, Navigator* navigator, const String& pattern, const String& url, Exception
State& es) | 95 ScriptPromise NavigatorServiceWorker::registerServiceWorker(ExecutionContext* co
ntext, Navigator* navigator, const String& pattern, const String& url, Exception
State& exceptionState) |
| 96 { | 96 { |
| 97 return from(navigator)->registerServiceWorker(context, pattern, url, es); | 97 return from(navigator)->registerServiceWorker(context, pattern, url, excepti
onState); |
| 98 } | 98 } |
| 99 | 99 |
| 100 ScriptPromise NavigatorServiceWorker::registerServiceWorker(ExecutionContext* ex
ecutionContext, const String& pattern, const String& scriptSrc, ExceptionState&
es) | 100 ScriptPromise NavigatorServiceWorker::registerServiceWorker(ExecutionContext* ex
ecutionContext, const String& pattern, const String& scriptSrc, ExceptionState&
exceptionState) |
| 101 { | 101 { |
| 102 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); | 102 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); |
| 103 ScriptPromise promise = ScriptPromise::createPending(executionContext); | 103 ScriptPromise promise = ScriptPromise::createPending(executionContext); |
| 104 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(promi
se, executionContext); | 104 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(promi
se, executionContext); |
| 105 | 105 |
| 106 Frame* frame = m_navigator->frame(); | 106 Frame* frame = m_navigator->frame(); |
| 107 if (!frame) { | 107 if (!frame) { |
| 108 resolver->reject(DOMError::create(InvalidStateError, "No document availa
ble.")); | 108 resolver->reject(DOMError::create(InvalidStateError, "No document availa
ble.")); |
| 109 return promise; | 109 return promise; |
| 110 } | 110 } |
| 111 | 111 |
| 112 RefPtr<SecurityOrigin> documentOrigin = frame->document()->securityOrigin(); | 112 RefPtr<SecurityOrigin> documentOrigin = frame->document()->securityOrigin(); |
| 113 | 113 |
| 114 KURL patternURL = executionContext->completeURL(pattern); | 114 KURL patternURL = executionContext->completeURL(pattern); |
| 115 if (!documentOrigin->canRequest(patternURL)) { | 115 if (!documentOrigin->canRequest(patternURL)) { |
| 116 resolver->reject(DOMError::create(SecurityError, "Can only register for
patterns in the document's origin.")); | 116 resolver->reject(DOMError::create(SecurityError, "Can only register for
patterns in the document's origin.")); |
| 117 return promise; | 117 return promise; |
| 118 } | 118 } |
| 119 | 119 |
| 120 KURL scriptURL = executionContext->completeURL(scriptSrc); | 120 KURL scriptURL = executionContext->completeURL(scriptSrc); |
| 121 if (!documentOrigin->canRequest(scriptURL)) { | 121 if (!documentOrigin->canRequest(scriptURL)) { |
| 122 resolver->reject(DOMError::create(SecurityError, "Script must be in docu
ment's origin.")); | 122 resolver->reject(DOMError::create(SecurityError, "Script must be in docu
ment's origin.")); |
| 123 return promise; | 123 return promise; |
| 124 } | 124 } |
| 125 | 125 |
| 126 ensureProvider()->registerServiceWorker(patternURL, scriptURL, new CallbackP
romiseAdapter<ServiceWorker, ServiceWorkerError>(resolver, executionContext)); | 126 ensureProvider()->registerServiceWorker(patternURL, scriptURL, new CallbackP
romiseAdapter<ServiceWorker, ServiceWorkerError>(resolver, executionContext)); |
| 127 return promise; | 127 return promise; |
| 128 } | 128 } |
| 129 | 129 |
| 130 ScriptPromise NavigatorServiceWorker::unregisterServiceWorker(ExecutionContext*
context, Navigator* navigator, const String& pattern, ExceptionState& es) | 130 ScriptPromise NavigatorServiceWorker::unregisterServiceWorker(ExecutionContext*
context, Navigator* navigator, const String& pattern, ExceptionState& exceptionS
tate) |
| 131 { | 131 { |
| 132 return from(navigator)->unregisterServiceWorker(context, pattern, es); | 132 return from(navigator)->unregisterServiceWorker(context, pattern, exceptionS
tate); |
| 133 } | 133 } |
| 134 | 134 |
| 135 ScriptPromise NavigatorServiceWorker::unregisterServiceWorker(ExecutionContext*
executionContext, const String& pattern, ExceptionState& es) | 135 ScriptPromise NavigatorServiceWorker::unregisterServiceWorker(ExecutionContext*
executionContext, const String& pattern, ExceptionState& exceptionState) |
| 136 { | 136 { |
| 137 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); | 137 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); |
| 138 ScriptPromise promise = ScriptPromise::createPending(executionContext); | 138 ScriptPromise promise = ScriptPromise::createPending(executionContext); |
| 139 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(promi
se, executionContext); | 139 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(promi
se, executionContext); |
| 140 | 140 |
| 141 Frame* frame = m_navigator->frame(); | 141 Frame* frame = m_navigator->frame(); |
| 142 if (!frame) { | 142 if (!frame) { |
| 143 resolver->reject(DOMError::create(InvalidStateError, "No document availa
ble.")); | 143 resolver->reject(DOMError::create(InvalidStateError, "No document availa
ble.")); |
| 144 return promise; | 144 return promise; |
| 145 } | 145 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 158 } | 158 } |
| 159 | 159 |
| 160 void NavigatorServiceWorker::willDetachGlobalObjectFromFrame() | 160 void NavigatorServiceWorker::willDetachGlobalObjectFromFrame() |
| 161 { | 161 { |
| 162 m_provider = nullptr; | 162 m_provider = nullptr; |
| 163 DOMWindowProperty::willDetachGlobalObjectFromFrame(); | 163 DOMWindowProperty::willDetachGlobalObjectFromFrame(); |
| 164 } | 164 } |
| 165 | 165 |
| 166 | 166 |
| 167 } // namespace WebCore | 167 } // namespace WebCore |
| OLD | NEW |