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

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

Issue 1307883002: Add cross origin access check to navigator.serviceWorker. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 4 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 NavigatorServiceWorker* NavigatorServiceWorker::toNavigatorServiceWorker(Navigat or& navigator) 47 NavigatorServiceWorker* NavigatorServiceWorker::toNavigatorServiceWorker(Navigat or& navigator)
48 { 48 {
49 return static_cast<NavigatorServiceWorker*>(HeapSupplement<Navigator>::from( navigator, supplementName())); 49 return static_cast<NavigatorServiceWorker*>(HeapSupplement<Navigator>::from( navigator, supplementName()));
50 } 50 }
51 51
52 const char* NavigatorServiceWorker::supplementName() 52 const char* NavigatorServiceWorker::supplementName()
53 { 53 {
54 return "NavigatorServiceWorker"; 54 return "NavigatorServiceWorker";
55 } 55 }
56 56
57 ServiceWorkerContainer* NavigatorServiceWorker::serviceWorker(Navigator& navigat or, ExceptionState& exceptionState) 57 ServiceWorkerContainer* NavigatorServiceWorker::serviceWorker(ExecutionContext* executionContext, Navigator& navigator, ExceptionState& exceptionState)
58 { 58 {
59 if (navigator.frame() && !executionContext->securityOrigin()->canAccessCheck Suborigins(navigator.frame()->securityContext()->securityOrigin())) {
60 exceptionState.throwSecurityError("Access to cross-origin service worker s is denied.");
jww 2015/08/21 18:43:26 Even given https://codereview.chromium.org/1308723
horo 2015/09/04 08:24:16 Yes, we should so. Created a CL. https://coderevie
61 return nullptr;
62 }
59 return NavigatorServiceWorker::from(navigator).serviceWorker(exceptionState) ; 63 return NavigatorServiceWorker::from(navigator).serviceWorker(exceptionState) ;
60 } 64 }
61 65
62 ServiceWorkerContainer* NavigatorServiceWorker::serviceWorker(ExceptionState& ex ceptionState) 66 ServiceWorkerContainer* NavigatorServiceWorker::serviceWorker(ExceptionState& ex ceptionState)
63 { 67 {
64 if (frame() && !frame()->securityContext()->securityOrigin()->canAccessServi ceWorkers()) { 68 if (frame() && !frame()->securityContext()->securityOrigin()->canAccessServi ceWorkers()) {
65 if (frame()->securityContext()->isSandboxed(SandboxOrigin)) 69 if (frame()->securityContext()->isSandboxed(SandboxOrigin))
66 exceptionState.throwSecurityError("Service worker is disabled becaus e the context is sandboxed and lacks the 'allow-same-origin' flag."); 70 exceptionState.throwSecurityError("Service worker is disabled becaus e the context is sandboxed and lacks the 'allow-same-origin' flag.");
67 else 71 else
68 exceptionState.throwSecurityError("Access to service workers is deni ed in this document origin."); 72 exceptionState.throwSecurityError("Access to service workers is deni ed in this document origin.");
(...skipping 15 matching lines...) Expand all
84 } 88 }
85 89
86 DEFINE_TRACE(NavigatorServiceWorker) 90 DEFINE_TRACE(NavigatorServiceWorker)
87 { 91 {
88 visitor->trace(m_serviceWorker); 92 visitor->trace(m_serviceWorker);
89 HeapSupplement<Navigator>::trace(visitor); 93 HeapSupplement<Navigator>::trace(visitor);
90 DOMWindowProperty::trace(visitor); 94 DOMWindowProperty::trace(visitor);
91 } 95 }
92 96
93 } // namespace blink 97 } // 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