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