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 23 matching lines...) Expand all Loading... |
34 #include "V8ServiceWorker.h" | 34 #include "V8ServiceWorker.h" |
35 #include "bindings/v8/ScriptPromiseResolver.h" | 35 #include "bindings/v8/ScriptPromiseResolver.h" |
36 #include "core/dom/Document.h" | 36 #include "core/dom/Document.h" |
37 #include "core/loader/DocumentLoader.h" | 37 #include "core/loader/DocumentLoader.h" |
38 #include "core/loader/FrameLoaderClient.h" | 38 #include "core/loader/FrameLoaderClient.h" |
39 #include "core/page/Frame.h" | 39 #include "core/page/Frame.h" |
40 #include "core/page/Navigator.h" | 40 #include "core/page/Navigator.h" |
41 #include "core/workers/SharedWorker.h" | 41 #include "core/workers/SharedWorker.h" |
42 #include "modules/serviceworkers/CallbackPromiseAdapter.h" | 42 #include "modules/serviceworkers/CallbackPromiseAdapter.h" |
43 #include "modules/serviceworkers/ServiceWorker.h" | 43 #include "modules/serviceworkers/ServiceWorker.h" |
44 #include "public/platform/WebServiceWorkerRegistry.h" | 44 #include "public/platform/WebServiceWorkerProvider.h" |
45 #include "public/platform/WebString.h" | 45 #include "public/platform/WebString.h" |
46 #include "public/platform/WebURL.h" | 46 #include "public/platform/WebURL.h" |
47 | 47 |
| 48 using WebKit::WebServiceWorkerProvider; |
| 49 |
48 namespace WebCore { | 50 namespace WebCore { |
49 | 51 |
50 NavigatorServiceWorker::NavigatorServiceWorker(Navigator* navigator) | 52 NavigatorServiceWorker::NavigatorServiceWorker(Navigator* navigator) |
51 : m_navigator(navigator) | 53 : m_navigator(navigator) |
52 { | 54 { |
53 } | 55 } |
54 | 56 |
55 NavigatorServiceWorker::~NavigatorServiceWorker() | 57 NavigatorServiceWorker::~NavigatorServiceWorker() |
56 { | 58 { |
57 } | 59 } |
58 | 60 |
59 const char* NavigatorServiceWorker::supplementName() | 61 const char* NavigatorServiceWorker::supplementName() |
60 { | 62 { |
61 return "NavigatorServiceWorker"; | 63 return "NavigatorServiceWorker"; |
62 } | 64 } |
63 | 65 |
| 66 WebServiceWorkerProvider* NavigatorServiceWorker::serviceWorkerProvider() |
| 67 { |
| 68 if (!m_provider) { |
| 69 FrameLoaderClient* client = m_navigator->frame()->loader()->client(); |
| 70 m_provider = adoptPtr(client->createServiceWorkerProvider(this)); |
| 71 } |
| 72 return m_provider.get(); |
| 73 } |
| 74 |
64 NavigatorServiceWorker* NavigatorServiceWorker::from(Navigator* navigator) | 75 NavigatorServiceWorker* NavigatorServiceWorker::from(Navigator* navigator) |
65 { | 76 { |
66 NavigatorServiceWorker* supplement = toNavigatorServiceWorker(navigator); | 77 NavigatorServiceWorker* supplement = toNavigatorServiceWorker(navigator); |
67 if (!supplement) { | 78 if (!supplement) { |
68 supplement = new NavigatorServiceWorker(navigator); | 79 supplement = new NavigatorServiceWorker(navigator); |
69 provideTo(navigator, supplementName(), adoptPtr(supplement)); | 80 provideTo(navigator, supplementName(), adoptPtr(supplement)); |
70 } | 81 } |
71 return supplement; | 82 return supplement; |
72 } | 83 } |
73 | 84 |
74 ScriptPromise NavigatorServiceWorker::registerServiceWorker(ScriptExecutionConte
xt* context, Navigator* navigator, const String& pattern, const String& url, Exc
eptionState& es) | 85 ScriptPromise NavigatorServiceWorker::registerServiceWorker(ScriptExecutionConte
xt* context, Navigator* navigator, const String& pattern, const String& url, Exc
eptionState& es) |
75 { | 86 { |
76 return from(navigator)->registerServiceWorker(context, pattern, url, es); | 87 return from(navigator)->registerServiceWorker(context, pattern, url, es); |
77 } | 88 } |
78 | 89 |
79 | 90 |
80 ScriptPromise NavigatorServiceWorker::registerServiceWorker(ScriptExecutionConte
xt* scriptExecutionContext, const String& pattern, const String& scriptSrc, Exce
ptionState& es) | 91 ScriptPromise NavigatorServiceWorker::registerServiceWorker(ScriptExecutionConte
xt* scriptExecutionContext, const String& pattern, const String& scriptSrc, Exce
ptionState& es) |
81 { | 92 { |
82 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); | 93 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); |
83 FrameLoaderClient* client = m_navigator->frame()->loader()->client(); | |
84 // WTF? Surely there's a better way to resolve a url? | 94 // WTF? Surely there's a better way to resolve a url? |
85 KURL scriptUrl = m_navigator->frame()->document()->completeURL(scriptSrc); | 95 KURL scriptUrl = m_navigator->frame()->document()->completeURL(scriptSrc); |
86 WebKit::WebServiceWorkerRegistry* peer = client->serviceWorkerRegistry(); | |
87 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tExecutionContext); | 96 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tExecutionContext); |
88 | 97 |
89 if (peer) | 98 WebKit::WebServiceWorkerProvider* provider = serviceWorkerProvider(); |
90 peer->registerServiceWorker(pattern, scriptUrl, new CallbackPromiseAdapt
er(resolver, scriptExecutionContext)); | 99 if (provider) |
| 100 provider->registerServiceWorker(pattern, scriptUrl, new CallbackPromiseA
dapter(resolver, scriptExecutionContext)); |
91 else | 101 else |
92 resolver->reject(PassRefPtr<ServiceWorker>(0)); | 102 resolver->reject(PassRefPtr<ServiceWorker>(0)); |
93 // call here? | 103 // call here? |
94 return resolver->promise(); | 104 return resolver->promise(); |
95 } | 105 } |
96 | 106 |
97 ScriptPromise NavigatorServiceWorker::unregisterServiceWorker(ScriptExecutionCon
text* context, Navigator* navigator, const String& pattern, ExceptionState& es) | 107 ScriptPromise NavigatorServiceWorker::unregisterServiceWorker(ScriptExecutionCon
text* context, Navigator* navigator, const String& pattern, ExceptionState& es) |
98 { | 108 { |
99 return from(navigator)->unregisterServiceWorker(context, pattern, es); | 109 return from(navigator)->unregisterServiceWorker(context, pattern, es); |
100 } | 110 } |
101 | 111 |
102 ScriptPromise NavigatorServiceWorker::unregisterServiceWorker(ScriptExecutionCon
text* scriptExecutionContext, const String& pattern, ExceptionState& es) | 112 ScriptPromise NavigatorServiceWorker::unregisterServiceWorker(ScriptExecutionCon
text* scriptExecutionContext, const String& pattern, ExceptionState& es) |
103 { | 113 { |
104 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); | 114 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); |
105 FrameLoaderClient* client = m_navigator->frame()->loader()->client(); | 115 FrameLoaderClient* client = m_navigator->frame()->loader()->client(); |
106 WebKit::WebServiceWorkerRegistry* peer = client->serviceWorkerRegistry(); | 116 WebKit::WebServiceWorkerProvider* provider = serviceWorkerProvider(); |
107 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tExecutionContext); | 117 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tExecutionContext); |
108 if (peer) | 118 if (provider) |
109 peer->unregisterServiceWorker(pattern, new CallbackPromiseAdapter(resolv
er, scriptExecutionContext)); | 119 provider->unregisterServiceWorker(pattern, new CallbackPromiseAdapter(re
solver, scriptExecutionContext)); |
110 else | 120 else |
111 resolver->reject(PassRefPtr<ServiceWorker>(0)); | 121 resolver->reject(PassRefPtr<ServiceWorker>(0)); |
112 return resolver->promise(); | 122 return resolver->promise(); |
113 } | 123 } |
114 | 124 |
115 } // namespace WebCore | 125 } // namespace WebCore |
OLD | NEW |