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

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

Issue 1191793003: [Service Worker Registration] removed protocolIsInHTTPFamily and replaced with SchemeRegistry check (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: added shouldAllowServiceWorkers in SchemeRegistry. Used instead of isSecure in ServiceWorkerContai… 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 /* 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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 return ScriptPromise(); 138 return ScriptPromise();
139 139
140 RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin(); 140 RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin();
141 String errorMessage; 141 String errorMessage;
142 if (!executionContext->isPrivilegedContext(errorMessage)) { 142 if (!executionContext->isPrivilegedContext(errorMessage)) {
143 resolver->reject(DOMException::create(NotSupportedError, errorMessage)); 143 resolver->reject(DOMException::create(NotSupportedError, errorMessage));
144 return promise; 144 return promise;
145 } 145 }
146 146
147 KURL pageURL = KURL(KURL(), documentOrigin->toString()); 147 KURL pageURL = KURL(KURL(), documentOrigin->toString());
148 if (!pageURL.protocolIsInHTTPFamily()) { 148 if (!SchemeRegistry::shouldAllowServiceWorkers(pageURL)) {
149 resolver->reject(DOMException::create(SecurityError, "Failed to register a ServiceWorker: The URL protocol of the current origin ('" + documentOrigin->t oString() + "') is not supported.")); 149 resolver->reject(DOMException::create(SecurityError, "Failed to register a ServiceWorker: The URL protocol of the current origin ('" + documentOrigin->t oString() + "') is not supported."));
150 return promise; 150 return promise;
151 } 151 }
152 152
153 KURL scriptURL = callingExecutionContext(scriptState->isolate())->completeUR L(url); 153 KURL scriptURL = callingExecutionContext(scriptState->isolate())->completeUR L(url);
154 scriptURL.removeFragmentIdentifier(); 154 scriptURL.removeFragmentIdentifier();
155 if (!documentOrigin->canRequest(scriptURL)) { 155 if (!documentOrigin->canRequest(scriptURL)) {
156 RefPtr<SecurityOrigin> scriptOrigin = SecurityOrigin::create(scriptURL); 156 RefPtr<SecurityOrigin> scriptOrigin = SecurityOrigin::create(scriptURL);
157 resolver->reject(DOMException::create(SecurityError, "Failed to register a ServiceWorker: The origin of the provided scriptURL ('" + scriptOrigin->toStr ing() + "') does not match the current origin ('" + documentOrigin->toString() + "').")); 157 resolver->reject(DOMException::create(SecurityError, "Failed to register a ServiceWorker: The origin of the provided scriptURL ('" + scriptOrigin->toStr ing() + "') does not match the current origin ('" + documentOrigin->toString() + "')."));
158 return promise; 158 return promise;
159 } 159 }
160 if (!scriptURL.protocolIsInHTTPFamily()) { 160 if (!SchemeRegistry::shouldAllowServiceWorkers(scriptURL)) {
161 resolver->reject(DOMException::create(SecurityError, "Failed to register a ServiceWorker: The URL protocol of the script ('" + scriptURL.string() + "') is not supported.")); 161 resolver->reject(DOMException::create(SecurityError, "Failed to register a ServiceWorker: The URL protocol of the script ('" + scriptURL.string() + "') is not supported."));
162 return promise; 162 return promise;
163 } 163 }
164 164
165 KURL patternURL; 165 KURL patternURL;
166 if (options.scope().isNull()) 166 if (options.scope().isNull())
167 patternURL = KURL(scriptURL, "./"); 167 patternURL = KURL(scriptURL, "./");
168 else 168 else
169 patternURL = callingExecutionContext(scriptState->isolate())->completeUR L(options.scope()); 169 patternURL = callingExecutionContext(scriptState->isolate())->completeUR L(options.scope());
170 patternURL.removeFragmentIdentifier(); 170 patternURL.removeFragmentIdentifier();
171 171
172 if (!documentOrigin->canRequest(patternURL)) { 172 if (!documentOrigin->canRequest(patternURL)) {
173 RefPtr<SecurityOrigin> patternOrigin = SecurityOrigin::create(patternURL ); 173 RefPtr<SecurityOrigin> patternOrigin = SecurityOrigin::create(patternURL );
174 resolver->reject(DOMException::create(SecurityError, "Failed to register a ServiceWorker: The origin of the provided scope ('" + patternOrigin->toString () + "') does not match the current origin ('" + documentOrigin->toString() + "' ).")); 174 resolver->reject(DOMException::create(SecurityError, "Failed to register a ServiceWorker: The origin of the provided scope ('" + patternOrigin->toString () + "') does not match the current origin ('" + documentOrigin->toString() + "' )."));
175 return promise; 175 return promise;
176 } 176 }
177 if (!patternURL.protocolIsInHTTPFamily()) { 177 if (!SchemeRegistry::shouldAllowServiceWorkers(patternURL)) {
178 resolver->reject(DOMException::create(SecurityError, "Failed to register a ServiceWorker: The URL protocol of the scope ('" + patternURL.string() + "') is not supported.")); 178 resolver->reject(DOMException::create(SecurityError, "Failed to register a ServiceWorker: The URL protocol of the scope ('" + patternURL.string() + "') is not supported."));
179 return promise; 179 return promise;
180 } 180 }
181 181
182 m_provider->registerServiceWorker(patternURL, scriptURL, new CallbackPromise Adapter<ServiceWorkerRegistration, ServiceWorkerError>(resolver)); 182 m_provider->registerServiceWorker(patternURL, scriptURL, new CallbackPromise Adapter<ServiceWorkerRegistration, ServiceWorkerError>(resolver));
183 183
184 return promise; 184 return promise;
185 } 185 }
186 186
187 ScriptPromise ServiceWorkerContainer::getRegistration(ScriptState* scriptState, const String& documentURL) 187 ScriptPromise ServiceWorkerContainer::getRegistration(ScriptState* scriptState, const String& documentURL)
(...skipping 12 matching lines...) Expand all
200 return ScriptPromise(); 200 return ScriptPromise();
201 201
202 RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin(); 202 RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin();
203 String errorMessage; 203 String errorMessage;
204 if (!executionContext->isPrivilegedContext(errorMessage)) { 204 if (!executionContext->isPrivilegedContext(errorMessage)) {
205 resolver->reject(DOMException::create(NotSupportedError, errorMessage)); 205 resolver->reject(DOMException::create(NotSupportedError, errorMessage));
206 return promise; 206 return promise;
207 } 207 }
208 208
209 KURL pageURL = KURL(KURL(), documentOrigin->toString()); 209 KURL pageURL = KURL(KURL(), documentOrigin->toString());
210 if (!pageURL.protocolIsInHTTPFamily()) { 210 if (!SchemeRegistry::shouldAllowServiceWorkers(pageURL)) {
211 resolver->reject(DOMException::create(SecurityError, "Failed to get a Se rviceWorkerRegistration: The URL protocol of the current origin ('" + documentOr igin->toString() + "') is not supported.")); 211 resolver->reject(DOMException::create(SecurityError, "Failed to get a Se rviceWorkerRegistration: The URL protocol of the current origin ('" + documentOr igin->toString() + "') is not supported."));
212 return promise; 212 return promise;
213 } 213 }
214 214
215 KURL completedURL = callingExecutionContext(scriptState->isolate())->complet eURL(documentURL); 215 KURL completedURL = callingExecutionContext(scriptState->isolate())->complet eURL(documentURL);
216 completedURL.removeFragmentIdentifier(); 216 completedURL.removeFragmentIdentifier();
217 if (!documentOrigin->canRequest(completedURL)) { 217 if (!documentOrigin->canRequest(completedURL)) {
218 RefPtr<SecurityOrigin> documentURLOrigin = SecurityOrigin::create(comple tedURL); 218 RefPtr<SecurityOrigin> documentURLOrigin = SecurityOrigin::create(comple tedURL);
219 resolver->reject(DOMException::create(SecurityError, "Failed to get a Se rviceWorkerRegistration: The origin of the provided documentURL ('" + documentUR LOrigin->toString() + "') does not match the current origin ('" + documentOrigin ->toString() + "').")); 219 resolver->reject(DOMException::create(SecurityError, "Failed to get a Se rviceWorkerRegistration: The origin of the provided documentURL ('" + documentUR LOrigin->toString() + "') does not match the current origin ('" + documentOrigin ->toString() + "')."));
220 return promise; 220 return promise;
(...skipping 15 matching lines...) Expand all
236 236
237 ExecutionContext* executionContext = scriptState->executionContext(); 237 ExecutionContext* executionContext = scriptState->executionContext();
238 RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin(); 238 RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin();
239 String errorMessage; 239 String errorMessage;
240 if (!executionContext->isPrivilegedContext(errorMessage)) { 240 if (!executionContext->isPrivilegedContext(errorMessage)) {
241 resolver->reject(DOMException::create(NotSupportedError, errorMessage)); 241 resolver->reject(DOMException::create(NotSupportedError, errorMessage));
242 return promise; 242 return promise;
243 } 243 }
244 244
245 KURL pageURL = KURL(KURL(), documentOrigin->toString()); 245 KURL pageURL = KURL(KURL(), documentOrigin->toString());
246 if (!pageURL.protocolIsInHTTPFamily()) { 246 if (!SchemeRegistry::shouldAllowServiceWorkers(pageURL)) {
247 resolver->reject(DOMException::create(SecurityError, "Failed to get Serv iceWorkerRegistration objects: The URL protocol of the current origin ('" + docu mentOrigin->toString() + "') is not supported.")); 247 resolver->reject(DOMException::create(SecurityError, "Failed to get Serv iceWorkerRegistration objects: The URL protocol of the current origin ('" + docu mentOrigin->toString() + "') is not supported."));
248 return promise; 248 return promise;
249 } 249 }
250 250
251 m_provider->getRegistrations(new CallbackPromiseAdapter<ServiceWorkerRegistr ationArray, ServiceWorkerError>(resolver)); 251 m_provider->getRegistrations(new CallbackPromiseAdapter<ServiceWorkerRegistr ationArray, ServiceWorkerError>(resolver));
252 252
253 return promise; 253 return promise;
254 } 254 }
255 255
256 ServiceWorkerContainer::ReadyProperty* ServiceWorkerContainer::createReadyProper ty() 256 ServiceWorkerContainer::ReadyProperty* ServiceWorkerContainer::createReadyProper ty()
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 return; 322 return;
323 323
324 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro m(executionContext)) { 324 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro m(executionContext)) {
325 m_provider = client->provider(); 325 m_provider = client->provider();
326 if (m_provider) 326 if (m_provider)
327 m_provider->setClient(this); 327 m_provider->setClient(this);
328 } 328 }
329 } 329 }
330 330
331 } // namespace blink 331 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | Source/platform/weborigin/SchemeRegistry.h » ('j') | Source/platform/weborigin/SchemeRegistry.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698