| 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 "modules/serviceworkers/NavigatorServiceWorker.h" | 5 #include "modules/serviceworkers/NavigatorServiceWorker.h" |
| 6 | 6 |
| 7 #include "core/dom/Document.h" | 7 #include "core/dom/Document.h" |
| 8 #include "core/frame/LocalDOMWindow.h" | 8 #include "core/frame/LocalDOMWindow.h" |
| 9 #include "core/frame/LocalFrame.h" | 9 #include "core/frame/LocalFrame.h" |
| 10 #include "core/frame/Navigator.h" | 10 #include "core/frame/Navigator.h" |
| 11 #include "modules/serviceworkers/ServiceWorkerContainer.h" | 11 #include "modules/serviceworkers/ServiceWorkerContainer.h" |
| 12 | 12 |
| 13 namespace blink { | 13 namespace blink { |
| 14 | 14 |
| 15 NavigatorServiceWorker::NavigatorServiceWorker(Navigator& navigator) {} | 15 NavigatorServiceWorker::NavigatorServiceWorker(Navigator& navigator) {} |
| 16 | 16 |
| 17 NavigatorServiceWorker* NavigatorServiceWorker::from(Document& document) { | 17 NavigatorServiceWorker* NavigatorServiceWorker::from(Document& document) { |
| 18 if (!document.frame() || !document.frame()->domWindow()) | 18 if (!document.frame() || !document.frame()->domWindow()) |
| 19 return nullptr; | 19 return nullptr; |
| 20 Navigator& navigator = *document.frame()->domWindow()->navigator(); | 20 Navigator& navigator = *document.frame()->domWindow()->navigator(); |
| 21 return &from(navigator); | 21 return &from(navigator); |
| 22 } | 22 } |
| 23 | 23 |
| 24 NavigatorServiceWorker& NavigatorServiceWorker::from(Navigator& navigator) { | 24 NavigatorServiceWorker& NavigatorServiceWorker::from(Navigator& navigator) { |
| 25 NavigatorServiceWorker* supplement = toNavigatorServiceWorker(navigator); | 25 NavigatorServiceWorker* supplement = toNavigatorServiceWorker(navigator); |
| 26 if (!supplement) { | 26 if (!supplement) { |
| 27 supplement = new NavigatorServiceWorker(navigator); | 27 supplement = new NavigatorServiceWorker(navigator); |
| 28 provideTo(navigator, supplementName(), supplement); | 28 provideTo(navigator, supplementName(), supplement); |
| 29 if (navigator.frame() && | 29 } |
| 30 navigator.frame() | 30 if (navigator.frame() && |
| 31 ->securityContext() | 31 navigator.frame() |
| 32 ->getSecurityOrigin() | 32 ->securityContext() |
| 33 ->canAccessServiceWorkers()) { | 33 ->getSecurityOrigin() |
| 34 // Initialize ServiceWorkerContainer too. | 34 ->canAccessServiceWorkers()) { |
| 35 supplement->serviceWorker(navigator.frame(), ASSERT_NO_EXCEPTION); | 35 // Ensure ServiceWorkerContainer. It can be cleared regardless of |
| 36 } | 36 // |supplement|. See comments in NavigatorServiceWorker::serviceWorker() for |
| 37 // details. |
| 38 supplement->serviceWorker(navigator.frame(), ASSERT_NO_EXCEPTION); |
| 37 } | 39 } |
| 38 return *supplement; | 40 return *supplement; |
| 39 } | 41 } |
| 40 | 42 |
| 41 NavigatorServiceWorker* NavigatorServiceWorker::toNavigatorServiceWorker( | 43 NavigatorServiceWorker* NavigatorServiceWorker::toNavigatorServiceWorker( |
| 42 Navigator& navigator) { | 44 Navigator& navigator) { |
| 43 return static_cast<NavigatorServiceWorker*>( | 45 return static_cast<NavigatorServiceWorker*>( |
| 44 Supplement<Navigator>::from(navigator, supplementName())); | 46 Supplement<Navigator>::from(navigator, supplementName())); |
| 45 } | 47 } |
| 46 | 48 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 void NavigatorServiceWorker::clearServiceWorker() { | 118 void NavigatorServiceWorker::clearServiceWorker() { |
| 117 m_serviceWorker = nullptr; | 119 m_serviceWorker = nullptr; |
| 118 } | 120 } |
| 119 | 121 |
| 120 DEFINE_TRACE(NavigatorServiceWorker) { | 122 DEFINE_TRACE(NavigatorServiceWorker) { |
| 121 visitor->trace(m_serviceWorker); | 123 visitor->trace(m_serviceWorker); |
| 122 Supplement<Navigator>::trace(visitor); | 124 Supplement<Navigator>::trace(visitor); |
| 123 } | 125 } |
| 124 | 126 |
| 125 } // namespace blink | 127 } // namespace blink |
| OLD | NEW |