| 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/dom/Document.h" | |
| 9 #include "core/frame/DOMWindow.h" | 8 #include "core/frame/DOMWindow.h" |
| 10 #include "core/frame/LocalFrame.h" | 9 #include "core/frame/LocalFrame.h" |
| 11 #include "core/frame/Navigator.h" | 10 #include "core/frame/Navigator.h" |
| 12 #include "modules/serviceworkers/ServiceWorkerContainer.h" | 11 #include "modules/serviceworkers/ServiceWorkerContainer.h" |
| 13 | 12 |
| 14 namespace WebCore { | 13 namespace WebCore { |
| 15 | 14 |
| 16 NavigatorServiceWorker::NavigatorServiceWorker(Navigator& navigator) | 15 NavigatorServiceWorker::NavigatorServiceWorker(Navigator& navigator) |
| 17 : DOMWindowProperty(navigator.frame()) | 16 : DOMWindowProperty(navigator.frame()) |
| 18 { | 17 { |
| 19 } | 18 } |
| 20 | 19 |
| 21 NavigatorServiceWorker::~NavigatorServiceWorker() | 20 NavigatorServiceWorker::~NavigatorServiceWorker() |
| 22 { | 21 { |
| 23 } | 22 } |
| 24 | 23 |
| 25 NavigatorServiceWorker* NavigatorServiceWorker::from(Document& document) | |
| 26 { | |
| 27 if (!document.frame() || !document.frame()->domWindow()) | |
| 28 return 0; | |
| 29 Navigator& navigator = document.frame()->domWindow()->navigator(); | |
| 30 return &from(navigator); | |
| 31 } | |
| 32 | |
| 33 NavigatorServiceWorker& NavigatorServiceWorker::from(Navigator& navigator) | 24 NavigatorServiceWorker& NavigatorServiceWorker::from(Navigator& navigator) |
| 34 { | 25 { |
| 35 NavigatorServiceWorker* supplement = toNavigatorServiceWorker(navigator); | 26 NavigatorServiceWorker* supplement = toNavigatorServiceWorker(navigator); |
| 36 if (!supplement) { | 27 if (!supplement) { |
| 37 supplement = new NavigatorServiceWorker(navigator); | 28 supplement = new NavigatorServiceWorker(navigator); |
| 38 provideTo(navigator, supplementName(), adoptPtrWillBeNoop(supplement)); | 29 provideTo(navigator, supplementName(), adoptPtrWillBeNoop(supplement)); |
| 39 // Initialize ServiceWorkerContainer too. | |
| 40 supplement->serviceWorker(); | |
| 41 } | 30 } |
| 42 return *supplement; | 31 return *supplement; |
| 43 } | 32 } |
| 44 | 33 |
| 45 NavigatorServiceWorker* NavigatorServiceWorker::toNavigatorServiceWorker(Navigat
or& navigator) | 34 NavigatorServiceWorker* NavigatorServiceWorker::toNavigatorServiceWorker(Navigat
or& navigator) |
| 46 { | 35 { |
| 47 return static_cast<NavigatorServiceWorker*>(WillBeHeapSupplement<Navigator>:
:from(navigator, supplementName())); | 36 return static_cast<NavigatorServiceWorker*>(WillBeHeapSupplement<Navigator>:
:from(navigator, supplementName())); |
| 48 } | 37 } |
| 49 | 38 |
| 50 const char* NavigatorServiceWorker::supplementName() | 39 const char* NavigatorServiceWorker::supplementName() |
| (...skipping 17 matching lines...) Expand all Loading... |
| 68 | 57 |
| 69 void NavigatorServiceWorker::willDetachGlobalObjectFromFrame() | 58 void NavigatorServiceWorker::willDetachGlobalObjectFromFrame() |
| 70 { | 59 { |
| 71 if (m_serviceWorker) { | 60 if (m_serviceWorker) { |
| 72 m_serviceWorker->detachClient(); | 61 m_serviceWorker->detachClient(); |
| 73 m_serviceWorker = nullptr; | 62 m_serviceWorker = nullptr; |
| 74 } | 63 } |
| 75 } | 64 } |
| 76 | 65 |
| 77 } // namespace WebCore | 66 } // namespace WebCore |
| OLD | NEW |