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/WebServiceWorkerProviderClient.h" | |
45 #include "public/platform/WebString.h" | 46 #include "public/platform/WebString.h" |
46 #include "public/platform/WebURL.h" | 47 #include "public/platform/WebURL.h" |
47 | 48 |
49 using WebKit::WebServiceWorkerProvider; | |
50 using WebKit::WebString; | |
51 | |
48 namespace WebCore { | 52 namespace WebCore { |
49 | 53 |
50 NavigatorServiceWorker::NavigatorServiceWorker(Navigator* navigator) | 54 NavigatorServiceWorker::NavigatorServiceWorker(Navigator* navigator) |
51 : m_navigator(navigator) | 55 : m_navigator(navigator) |
52 { | 56 { |
53 } | 57 } |
54 | 58 |
55 NavigatorServiceWorker::~NavigatorServiceWorker() | 59 NavigatorServiceWorker::~NavigatorServiceWorker() |
56 { | 60 { |
57 } | 61 } |
58 | 62 |
59 const char* NavigatorServiceWorker::supplementName() | 63 const char* NavigatorServiceWorker::supplementName() |
60 { | 64 { |
61 return "NavigatorServiceWorker"; | 65 return "NavigatorServiceWorker"; |
62 } | 66 } |
63 | 67 |
68 namespace { | |
69 | |
70 class ServiceWorkerProviderClientLogger : public WebKit::WebServiceWorkerProvide rClient { | |
71 public: | |
72 // WebServiceWorkerProviderClient implementation | |
73 virtual void didFailToStart(const WebString& message) OVERRIDE | |
74 { | |
75 // FIXME: Move this to a handler that can forward this to the dev consol e. | |
76 LOG_ERROR("Service worker failed to start: %s", message.utf8().data()); | |
77 } | |
78 }; | |
79 } // namespace | |
80 | |
81 WebServiceWorkerProvider* NavigatorServiceWorker::serviceWorkerProvider() | |
82 { | |
83 if (!m_provider) { | |
84 FrameLoaderClient* client = m_navigator->frame()->loader()->client(); | |
85 // FIXME: This is temporarily hooked up here until we hook up to the loa ding process. | |
86 m_provider = adoptPtr(client->createServiceWorkerProvider(new ServiceWor kerProviderClientLogger())); | |
michaeln
2013/10/07 21:08:06
The ownership doesn't look right. Who is responsib
| |
87 } | |
88 return m_provider.get(); | |
89 } | |
90 | |
64 NavigatorServiceWorker* NavigatorServiceWorker::from(Navigator* navigator) | 91 NavigatorServiceWorker* NavigatorServiceWorker::from(Navigator* navigator) |
65 { | 92 { |
66 NavigatorServiceWorker* supplement = toNavigatorServiceWorker(navigator); | 93 NavigatorServiceWorker* supplement = toNavigatorServiceWorker(navigator); |
67 if (!supplement) { | 94 if (!supplement) { |
68 supplement = new NavigatorServiceWorker(navigator); | 95 supplement = new NavigatorServiceWorker(navigator); |
69 provideTo(navigator, supplementName(), adoptPtr(supplement)); | 96 provideTo(navigator, supplementName(), adoptPtr(supplement)); |
70 } | 97 } |
71 return supplement; | 98 return supplement; |
72 } | 99 } |
73 | 100 |
74 ScriptPromise NavigatorServiceWorker::registerServiceWorker(ScriptExecutionConte xt* context, Navigator* navigator, const String& pattern, const String& url, Exc eptionState& es) | 101 ScriptPromise NavigatorServiceWorker::registerServiceWorker(ScriptExecutionConte xt* context, Navigator* navigator, const String& pattern, const String& url, Exc eptionState& es) |
75 { | 102 { |
76 return from(navigator)->registerServiceWorker(context, pattern, url, es); | 103 return from(navigator)->registerServiceWorker(context, pattern, url, es); |
77 } | 104 } |
78 | 105 |
79 | |
80 ScriptPromise NavigatorServiceWorker::registerServiceWorker(ScriptExecutionConte xt* scriptExecutionContext, const String& pattern, const String& scriptSrc, Exce ptionState& es) | 106 ScriptPromise NavigatorServiceWorker::registerServiceWorker(ScriptExecutionConte xt* scriptExecutionContext, const String& pattern, const String& scriptSrc, Exce ptionState& es) |
81 { | 107 { |
82 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); | 108 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); |
83 FrameLoaderClient* client = m_navigator->frame()->loader()->client(); | |
84 // WTF? Surely there's a better way to resolve a url? | 109 // WTF? Surely there's a better way to resolve a url? |
85 KURL scriptUrl = m_navigator->frame()->document()->completeURL(scriptSrc); | 110 KURL scriptUrl = m_navigator->frame()->document()->completeURL(scriptSrc); |
86 WebKit::WebServiceWorkerRegistry* peer = client->serviceWorkerRegistry(); | |
87 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tExecutionContext); | 111 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tExecutionContext); |
88 | 112 |
89 if (peer) | 113 WebKit::WebServiceWorkerProvider* provider = serviceWorkerProvider(); |
90 peer->registerServiceWorker(pattern, scriptUrl, new CallbackPromiseAdapt er(resolver, scriptExecutionContext)); | 114 if (provider) |
115 provider->registerServiceWorker(pattern, scriptUrl, new CallbackPromiseA dapter(resolver, scriptExecutionContext)); | |
91 else | 116 else |
92 resolver->reject(PassRefPtr<ServiceWorker>(0)); | 117 resolver->reject(PassRefPtr<ServiceWorker>(0)); |
93 // call here? | 118 // call here? |
94 return resolver->promise(); | 119 return resolver->promise(); |
95 } | 120 } |
96 | 121 |
97 ScriptPromise NavigatorServiceWorker::unregisterServiceWorker(ScriptExecutionCon text* context, Navigator* navigator, const String& pattern, ExceptionState& es) | 122 ScriptPromise NavigatorServiceWorker::unregisterServiceWorker(ScriptExecutionCon text* context, Navigator* navigator, const String& pattern, ExceptionState& es) |
98 { | 123 { |
99 return from(navigator)->unregisterServiceWorker(context, pattern, es); | 124 return from(navigator)->unregisterServiceWorker(context, pattern, es); |
100 } | 125 } |
101 | 126 |
102 ScriptPromise NavigatorServiceWorker::unregisterServiceWorker(ScriptExecutionCon text* scriptExecutionContext, const String& pattern, ExceptionState& es) | 127 ScriptPromise NavigatorServiceWorker::unregisterServiceWorker(ScriptExecutionCon text* scriptExecutionContext, const String& pattern, ExceptionState& es) |
103 { | 128 { |
104 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); | 129 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); |
105 FrameLoaderClient* client = m_navigator->frame()->loader()->client(); | 130 FrameLoaderClient* client = m_navigator->frame()->loader()->client(); |
106 WebKit::WebServiceWorkerRegistry* peer = client->serviceWorkerRegistry(); | 131 WebKit::WebServiceWorkerProvider* provider = serviceWorkerProvider(); |
107 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tExecutionContext); | 132 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tExecutionContext); |
108 if (peer) | 133 if (provider) |
109 peer->unregisterServiceWorker(pattern, new CallbackPromiseAdapter(resolv er, scriptExecutionContext)); | 134 provider->unregisterServiceWorker(pattern, new CallbackPromiseAdapter(re solver, scriptExecutionContext)); |
110 else | 135 else |
111 resolver->reject(PassRefPtr<ServiceWorker>(0)); | 136 resolver->reject(PassRefPtr<ServiceWorker>(0)); |
112 return resolver->promise(); | 137 return resolver->promise(); |
113 } | 138 } |
114 | 139 |
115 } // namespace WebCore | 140 } // namespace WebCore |
OLD | NEW |