| 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 } | 77 } |
| 78 | 78 |
| 79 | 79 |
| 80 ScriptPromise NavigatorServiceWorker::registerServiceWorker(ScriptExecutionConte
xt* scriptExecutionContext, const String& pattern, const String& scriptSrc, Exce
ptionState& es) | 80 ScriptPromise NavigatorServiceWorker::registerServiceWorker(ScriptExecutionConte
xt* scriptExecutionContext, const String& pattern, const String& scriptSrc, Exce
ptionState& es) |
| 81 { | 81 { |
| 82 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); | 82 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); |
| 83 FrameLoaderClient* client = m_navigator->frame()->loader()->client(); | 83 FrameLoaderClient* client = m_navigator->frame()->loader()->client(); |
| 84 // WTF? Surely there's a better way to resolve a url? | 84 // WTF? Surely there's a better way to resolve a url? |
| 85 KURL scriptUrl = m_navigator->frame()->document()->completeURL(scriptSrc); | 85 KURL scriptUrl = m_navigator->frame()->document()->completeURL(scriptSrc); |
| 86 WebKit::WebServiceWorkerRegistry* peer = client->serviceWorkerRegistry(); | 86 WebKit::WebServiceWorkerRegistry* peer = client->serviceWorkerRegistry(); |
| 87 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tExecutionContext); | 87 ScriptPromise promise = ScriptPromise::create(scriptExecutionContext); |
| 88 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(promi
se, scriptExecutionContext); |
| 88 | 89 |
| 89 if (peer) | 90 if (peer) |
| 90 peer->registerServiceWorker(pattern, scriptUrl, new CallbackPromiseAdapt
er(resolver, scriptExecutionContext)); | 91 peer->registerServiceWorker(pattern, scriptUrl, new CallbackPromiseAdapt
er(resolver, scriptExecutionContext)); |
| 91 else | 92 else |
| 92 resolver->reject(PassRefPtr<ServiceWorker>(0)); | 93 resolver->reject(PassRefPtr<ServiceWorker>(0)); |
| 93 // call here? | 94 // call here? |
| 94 return resolver->promise(); | 95 return promise; |
| 95 } | 96 } |
| 96 | 97 |
| 97 ScriptPromise NavigatorServiceWorker::unregisterServiceWorker(ScriptExecutionCon
text* context, Navigator* navigator, const String& pattern, ExceptionState& es) | 98 ScriptPromise NavigatorServiceWorker::unregisterServiceWorker(ScriptExecutionCon
text* context, Navigator* navigator, const String& pattern, ExceptionState& es) |
| 98 { | 99 { |
| 99 return from(navigator)->unregisterServiceWorker(context, pattern, es); | 100 return from(navigator)->unregisterServiceWorker(context, pattern, es); |
| 100 } | 101 } |
| 101 | 102 |
| 102 ScriptPromise NavigatorServiceWorker::unregisterServiceWorker(ScriptExecutionCon
text* scriptExecutionContext, const String& pattern, ExceptionState& es) | 103 ScriptPromise NavigatorServiceWorker::unregisterServiceWorker(ScriptExecutionCon
text* scriptExecutionContext, const String& pattern, ExceptionState& es) |
| 103 { | 104 { |
| 104 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); | 105 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); |
| 105 FrameLoaderClient* client = m_navigator->frame()->loader()->client(); | 106 FrameLoaderClient* client = m_navigator->frame()->loader()->client(); |
| 106 WebKit::WebServiceWorkerRegistry* peer = client->serviceWorkerRegistry(); | 107 WebKit::WebServiceWorkerRegistry* peer = client->serviceWorkerRegistry(); |
| 107 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tExecutionContext); | 108 ScriptPromise promise = ScriptPromise::create(scriptExecutionContext); |
| 109 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(promi
se, scriptExecutionContext); |
| 108 if (peer) | 110 if (peer) |
| 109 peer->unregisterServiceWorker(pattern, new CallbackPromiseAdapter(resolv
er, scriptExecutionContext)); | 111 peer->unregisterServiceWorker(pattern, new CallbackPromiseAdapter(resolv
er, scriptExecutionContext)); |
| 110 else | 112 else |
| 111 resolver->reject(PassRefPtr<ServiceWorker>(0)); | 113 resolver->reject(PassRefPtr<ServiceWorker>(0)); |
| 112 return resolver->promise(); | 114 return promise; |
| 113 } | 115 } |
| 114 | 116 |
| 115 } // namespace WebCore | 117 } // namespace WebCore |
| OLD | NEW |