OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 #include "modules/serviceworkers/NavigatorServiceWorker.h" | 6 #include "modules/serviceworkers/NavigatorServiceWorker.h" |
7 | 7 |
8 #include "core/frame/Navigator.h" | 8 #include "core/frame/Navigator.h" |
9 #include "modules/serviceworkers/ServiceWorkerContainer.h" | 9 #include "modules/serviceworkers/ServiceWorkerContainer.h" |
10 | 10 |
11 namespace WebCore { | 11 namespace WebCore { |
12 | 12 |
13 NavigatorServiceWorker::NavigatorServiceWorker(Navigator& navigator) | 13 NavigatorServiceWorker::NavigatorServiceWorker(Navigator& navigator) |
14 : DOMWindowProperty(navigator.frame()) | 14 : DOMWindowProperty(navigator.frame()) |
15 { | 15 { |
16 } | 16 } |
17 | 17 |
18 NavigatorServiceWorker::~NavigatorServiceWorker() | 18 NavigatorServiceWorker::~NavigatorServiceWorker() |
19 { | 19 { |
20 } | 20 } |
21 | 21 |
22 NavigatorServiceWorker& NavigatorServiceWorker::from(Navigator& navigator) | 22 NavigatorServiceWorker& NavigatorServiceWorker::from(Navigator& navigator) |
23 { | 23 { |
24 NavigatorServiceWorker* supplement = toNavigatorServiceWorker(navigator); | 24 NavigatorServiceWorker* supplement = toNavigatorServiceWorker(navigator); |
25 if (!supplement) { | 25 if (!supplement) { |
26 supplement = new NavigatorServiceWorker(navigator); | 26 supplement = new NavigatorServiceWorker(navigator); |
27 provideTo(navigator, supplementName(), adoptPtr(supplement)); | 27 provideTo(navigator, supplementName(), adoptPtrWillBeNoop(supplement)); |
28 } | 28 } |
29 return *supplement; | 29 return *supplement; |
30 } | 30 } |
31 | 31 |
| 32 NavigatorServiceWorker* NavigatorServiceWorker::toNavigatorServiceWorker(Navigat
or& navigator) |
| 33 { |
| 34 return static_cast<NavigatorServiceWorker*>(WillBeHeapSupplement<Navigator>:
:from(navigator, supplementName())); |
| 35 } |
| 36 |
32 const char* NavigatorServiceWorker::supplementName() | 37 const char* NavigatorServiceWorker::supplementName() |
33 { | 38 { |
34 return "NavigatorServiceWorker"; | 39 return "NavigatorServiceWorker"; |
35 } | 40 } |
36 | 41 |
37 ServiceWorkerContainer* NavigatorServiceWorker::serviceWorker(ExecutionContext*
executionContext, Navigator& navigator) | 42 ServiceWorkerContainer* NavigatorServiceWorker::serviceWorker(ExecutionContext*
executionContext, Navigator& navigator) |
38 { | 43 { |
39 return NavigatorServiceWorker::from(navigator).serviceWorker(executionContex
t); | 44 return NavigatorServiceWorker::from(navigator).serviceWorker(executionContex
t); |
40 } | 45 } |
41 | 46 |
42 ServiceWorkerContainer* NavigatorServiceWorker::serviceWorker(ExecutionContext*
executionContext) | 47 ServiceWorkerContainer* NavigatorServiceWorker::serviceWorker(ExecutionContext*
executionContext) |
43 { | 48 { |
44 if (!m_serviceWorker && frame()) | 49 if (!m_serviceWorker && frame()) |
45 m_serviceWorker = ServiceWorkerContainer::create(executionContext); | 50 m_serviceWorker = ServiceWorkerContainer::create(executionContext); |
46 return m_serviceWorker.get(); | 51 return m_serviceWorker.get(); |
47 } | 52 } |
48 | 53 |
49 void NavigatorServiceWorker::willDetachGlobalObjectFromFrame() | 54 void NavigatorServiceWorker::willDetachGlobalObjectFromFrame() |
50 { | 55 { |
51 m_serviceWorker->detachClient(); | 56 m_serviceWorker->detachClient(); |
52 m_serviceWorker = nullptr; | 57 m_serviceWorker = nullptr; |
53 } | 58 } |
54 | 59 |
55 } // namespace WebCore | 60 } // namespace WebCore |
OLD | NEW |