Chromium Code Reviews| 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/dom/Document.h" |
| 9 #include "core/frame/LocalDOMWindow.h" | 9 #include "core/frame/LocalDOMWindow.h" |
| 10 #include "core/frame/LocalFrame.h" | 10 #include "core/frame/LocalFrame.h" |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 29 Navigator& navigator = *document.frame()->domWindow()->navigator(); | 29 Navigator& navigator = *document.frame()->domWindow()->navigator(); |
| 30 return &from(navigator); | 30 return &from(navigator); |
| 31 } | 31 } |
| 32 | 32 |
| 33 NavigatorServiceWorker& NavigatorServiceWorker::from(Navigator& navigator) | 33 NavigatorServiceWorker& NavigatorServiceWorker::from(Navigator& navigator) |
| 34 { | 34 { |
| 35 NavigatorServiceWorker* supplement = toNavigatorServiceWorker(navigator); | 35 NavigatorServiceWorker* supplement = toNavigatorServiceWorker(navigator); |
| 36 if (!supplement) { | 36 if (!supplement) { |
| 37 supplement = new NavigatorServiceWorker(navigator); | 37 supplement = new NavigatorServiceWorker(navigator); |
| 38 provideTo(navigator, supplementName(), supplement); | 38 provideTo(navigator, supplementName(), supplement); |
| 39 // Initialize ServiceWorkerContainer too. | 39 if (navigator.frame() && navigator.frame()->securityContext()->securityO rigin()->canAccessServiceWorkers()) { |
| 40 supplement->serviceWorker(); | 40 // Initialize ServiceWorkerContainer too. |
| 41 NonThrowableExceptionState exceptionState; | |
|
tkent
2015/06/24 06:22:17
probably |supplement->serviceWorker(ASSERT_NO_EXCE
horo
2015/06/24 06:31:02
Done.
| |
| 42 supplement->serviceWorker(exceptionState); | |
| 43 } | |
| 41 } | 44 } |
| 42 return *supplement; | 45 return *supplement; |
| 43 } | 46 } |
| 44 | 47 |
| 45 NavigatorServiceWorker* NavigatorServiceWorker::toNavigatorServiceWorker(Navigat or& navigator) | 48 NavigatorServiceWorker* NavigatorServiceWorker::toNavigatorServiceWorker(Navigat or& navigator) |
| 46 { | 49 { |
| 47 return static_cast<NavigatorServiceWorker*>(HeapSupplement<Navigator>::from( navigator, supplementName())); | 50 return static_cast<NavigatorServiceWorker*>(HeapSupplement<Navigator>::from( navigator, supplementName())); |
| 48 } | 51 } |
| 49 | 52 |
| 50 const char* NavigatorServiceWorker::supplementName() | 53 const char* NavigatorServiceWorker::supplementName() |
| 51 { | 54 { |
| 52 return "NavigatorServiceWorker"; | 55 return "NavigatorServiceWorker"; |
| 53 } | 56 } |
| 54 | 57 |
| 55 ServiceWorkerContainer* NavigatorServiceWorker::serviceWorker(Navigator& navigat or) | 58 ServiceWorkerContainer* NavigatorServiceWorker::serviceWorker(Navigator& navigat or, ExceptionState& exceptionState) |
| 56 { | 59 { |
| 57 return NavigatorServiceWorker::from(navigator).serviceWorker(); | 60 return NavigatorServiceWorker::from(navigator).serviceWorker(exceptionState) ; |
| 58 } | 61 } |
| 59 | 62 |
| 60 ServiceWorkerContainer* NavigatorServiceWorker::serviceWorker() | 63 ServiceWorkerContainer* NavigatorServiceWorker::serviceWorker(ExceptionState& ex ceptionState) |
| 61 { | 64 { |
| 65 if (frame() && !frame()->securityContext()->securityOrigin()->canAccessServi ceWorkers()) { | |
| 66 if (frame()->securityContext()->isSandboxed(SandboxOrigin)) | |
| 67 exceptionState.throwSecurityError("Service worker is disabled becaus e the context is sandboxed and lacks the 'allow-same-origin' flag."); | |
| 68 else | |
| 69 exceptionState.throwSecurityError("Access to service workers is deni ed in this document origin."); | |
| 70 return nullptr; | |
| 71 } | |
| 62 if (!m_serviceWorker && frame()) { | 72 if (!m_serviceWorker && frame()) { |
| 63 ASSERT(frame()->domWindow()); | 73 ASSERT(frame()->domWindow()); |
| 64 m_serviceWorker = ServiceWorkerContainer::create(frame()->domWindow()->e xecutionContext()); | 74 m_serviceWorker = ServiceWorkerContainer::create(frame()->domWindow()->e xecutionContext()); |
| 65 } | 75 } |
| 66 return m_serviceWorker.get(); | 76 return m_serviceWorker.get(); |
| 67 } | 77 } |
| 68 | 78 |
| 69 void NavigatorServiceWorker::willDetachGlobalObjectFromFrame() | 79 void NavigatorServiceWorker::willDetachGlobalObjectFromFrame() |
| 70 { | 80 { |
| 71 if (m_serviceWorker) { | 81 if (m_serviceWorker) { |
| 72 m_serviceWorker->willBeDetachedFromFrame(); | 82 m_serviceWorker->willBeDetachedFromFrame(); |
| 73 m_serviceWorker = nullptr; | 83 m_serviceWorker = nullptr; |
| 74 } | 84 } |
| 75 } | 85 } |
| 76 | 86 |
| 77 DEFINE_TRACE(NavigatorServiceWorker) | 87 DEFINE_TRACE(NavigatorServiceWorker) |
| 78 { | 88 { |
| 79 visitor->trace(m_serviceWorker); | 89 visitor->trace(m_serviceWorker); |
| 80 HeapSupplement<Navigator>::trace(visitor); | 90 HeapSupplement<Navigator>::trace(visitor); |
| 81 DOMWindowProperty::trace(visitor); | 91 DOMWindowProperty::trace(visitor); |
| 82 } | 92 } |
| 83 | 93 |
| 84 } // namespace blink | 94 } // namespace blink |
| OLD | NEW |