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

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

Issue 835673006: Use caller's document url to resolve scriptURL/patternURL in registerServiceWorker/getRegistration (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 11 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 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 { 110 {
111 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); 111 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled());
112 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState); 112 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState);
113 ScriptPromise promise = resolver->promise(); 113 ScriptPromise promise = resolver->promise();
114 114
115 if (!m_provider) { 115 if (!m_provider) {
116 resolver->reject(DOMException::create(InvalidStateError, "The document i s in an invalid state.")); 116 resolver->reject(DOMException::create(InvalidStateError, "The document i s in an invalid state."));
117 return promise; 117 return promise;
118 } 118 }
119 119
120 // FIXME: This should use the container's execution context, not 120 // FIXME: This should use the container's execution context, not
dominicc (has gone to gerrit) 2015/01/19 03:19:08 This FIXME is essentially what you're fixing here,
121 // the callers. 121 // the callers.
122 ExecutionContext* executionContext = scriptState->executionContext(); 122 ExecutionContext* executionContext = scriptState->executionContext();
123 RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin(); 123 RefPtr<SecurityOrigin> documentOrigin = m_executionContext->securityOrigin() ;
124 String errorMessage; 124 String errorMessage;
125 if (!documentOrigin->canAccessFeatureRequiringSecureOrigin(errorMessage)) { 125 if (!documentOrigin->canAccessFeatureRequiringSecureOrigin(errorMessage)) {
126 resolver->reject(DOMException::create(NotSupportedError, errorMessage)); 126 resolver->reject(DOMException::create(NotSupportedError, errorMessage));
127 return promise; 127 return promise;
128 } 128 }
129 129
130 KURL pageURL = KURL(KURL(), documentOrigin->toString()); 130 KURL pageURL = KURL(KURL(), documentOrigin->toString());
131 if (!pageURL.protocolIsInHTTPFamily()) { 131 if (!pageURL.protocolIsInHTTPFamily()) {
132 resolver->reject(DOMException::create(SecurityError, "The URL protocol o f the current origin is not supported: " + pageURL.protocol())); 132 resolver->reject(DOMException::create(SecurityError, "The URL protocol o f the current origin is not supported: " + pageURL.protocol()));
133 return promise; 133 return promise;
134 } 134 }
135 135
136 KURL patternURL = executionContext->completeURL(options.scope()); 136 KURL patternURL = executionContext->completeURL(options.scope());
137
137 patternURL.removeFragmentIdentifier(); 138 patternURL.removeFragmentIdentifier();
138 if (!documentOrigin->canRequest(patternURL)) { 139 if (!documentOrigin->canRequest(patternURL)) {
139 resolver->reject(DOMException::create(SecurityError, "The scope must mat ch the current origin.")); 140 resolver->reject(DOMException::create(SecurityError, "The scope must mat ch the current origin."));
140 return promise; 141 return promise;
141 } 142 }
142 143
143 KURL scriptURL = executionContext->completeURL(url); 144 KURL scriptURL = executionContext->completeURL(url);
145
144 scriptURL.removeFragmentIdentifier(); 146 scriptURL.removeFragmentIdentifier();
145 if (!documentOrigin->canRequest(scriptURL)) { 147 if (!documentOrigin->canRequest(scriptURL)) {
146 resolver->reject(DOMException::create(SecurityError, "The origin of the script must match the current origin.")); 148 resolver->reject(DOMException::create(SecurityError, "The origin of the script must match the current origin."));
147 return promise; 149 return promise;
148 } 150 }
149 151
150 if (!patternURL.string().startsWith(scriptURL.baseAsString())) { 152 if (!patternURL.string().startsWith(scriptURL.baseAsString())) {
151 resolver->reject(DOMException::create(SecurityError, "The scope must be under the directory of the script URL.")); 153 resolver->reject(DOMException::create(SecurityError, "The scope must be under the directory of the script URL."));
152 return promise; 154 return promise;
153 } 155 }
(...skipping 23 matching lines...) Expand all
177 ScriptPromise promise = resolver->promise(); 179 ScriptPromise promise = resolver->promise();
178 180
179 if (!m_provider) { 181 if (!m_provider) {
180 resolver->reject(DOMException::create(InvalidStateError, "The document i s in an invalid state.")); 182 resolver->reject(DOMException::create(InvalidStateError, "The document i s in an invalid state."));
181 return promise; 183 return promise;
182 } 184 }
183 185
184 // FIXME: This should use the container's execution context, not 186 // FIXME: This should use the container's execution context, not
185 // the callers. 187 // the callers.
186 ExecutionContext* executionContext = scriptState->executionContext(); 188 ExecutionContext* executionContext = scriptState->executionContext();
187 RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin(); 189 RefPtr<SecurityOrigin> documentOrigin = m_executionContext->securityOrigin() ;
188 String errorMessage; 190 String errorMessage;
189 if (!documentOrigin->canAccessFeatureRequiringSecureOrigin(errorMessage)) { 191 if (!documentOrigin->canAccessFeatureRequiringSecureOrigin(errorMessage)) {
190 resolver->reject(DOMException::create(NotSupportedError, errorMessage)); 192 resolver->reject(DOMException::create(NotSupportedError, errorMessage));
191 return promise; 193 return promise;
192 } 194 }
193 195
194 KURL pageURL = KURL(KURL(), documentOrigin->toString()); 196 KURL pageURL = KURL(KURL(), documentOrigin->toString());
195 if (!pageURL.protocolIsInHTTPFamily()) { 197 if (!pageURL.protocolIsInHTTPFamily()) {
196 resolver->reject(DOMException::create(SecurityError, "The URL protocol o f the current origin is not supported: " + pageURL.protocol())); 198 resolver->reject(DOMException::create(SecurityError, "The URL protocol o f the current origin is not supported: " + pageURL.protocol()));
197 return promise; 199 return promise;
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 else if (document->frame()->isMainFrame()) 299 else if (document->frame()->isMainFrame())
298 info->frameType = WebURLRequest::FrameTypeTopLevel; 300 info->frameType = WebURLRequest::FrameTypeTopLevel;
299 else 301 else
300 info->frameType = WebURLRequest::FrameTypeNested; 302 info->frameType = WebURLRequest::FrameTypeNested;
301 return true; 303 return true;
302 } 304 }
303 305
304 ServiceWorkerContainer::ServiceWorkerContainer(ExecutionContext* executionContex t) 306 ServiceWorkerContainer::ServiceWorkerContainer(ExecutionContext* executionContex t)
305 : ContextLifecycleObserver(executionContext) 307 : ContextLifecycleObserver(executionContext)
306 , m_provider(0) 308 , m_provider(0)
309 , m_executionContext(executionContext)
307 { 310 {
308 311
309 if (!executionContext) 312 if (!executionContext)
310 return; 313 return;
311 314
312 m_ready = createReadyProperty(); 315 m_ready = createReadyProperty();
313 316
314 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro m(executionContext)) { 317 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro m(executionContext)) {
315 m_provider = client->provider(); 318 m_provider = client->provider();
316 if (m_provider) 319 if (m_provider)
317 m_provider->setClient(this); 320 m_provider->setClient(this);
318 } 321 }
319 } 322 }
320 323
321 } // namespace blink 324 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698