Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(194)

Side by Side Diff: Source/modules/serviceworkers/NavigatorServiceWorker.cpp

Issue 1199183002: Throw a SecurityError when navigator.serviceWorker is accessed in a sandboxed iframe. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: incorporated nhiroki's comment Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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;
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 worker is denie d.");
falken 2015/06/24 04:40:44 Can we make this message more detailed? A develope
horo 2015/06/24 05:58:31 Done.
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
OLDNEW
« no previous file with comments | « Source/modules/serviceworkers/NavigatorServiceWorker.h ('k') | Source/modules/serviceworkers/NavigatorServiceWorker.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698