| OLD | NEW |
| 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 30 matching lines...) Expand all Loading... |
| 41 #include "core/dom/ExecutionContext.h" | 41 #include "core/dom/ExecutionContext.h" |
| 42 #include "core/dom/MessagePort.h" | 42 #include "core/dom/MessagePort.h" |
| 43 #include "core/events/MessageEvent.h" | 43 #include "core/events/MessageEvent.h" |
| 44 #include "core/frame/LocalDOMWindow.h" | 44 #include "core/frame/LocalDOMWindow.h" |
| 45 #include "modules/EventTargetModules.h" | 45 #include "modules/EventTargetModules.h" |
| 46 #include "modules/serviceworkers/ServiceWorker.h" | 46 #include "modules/serviceworkers/ServiceWorker.h" |
| 47 #include "modules/serviceworkers/ServiceWorkerContainerClient.h" | 47 #include "modules/serviceworkers/ServiceWorkerContainerClient.h" |
| 48 #include "modules/serviceworkers/ServiceWorkerError.h" | 48 #include "modules/serviceworkers/ServiceWorkerError.h" |
| 49 #include "modules/serviceworkers/ServiceWorkerRegistration.h" | 49 #include "modules/serviceworkers/ServiceWorkerRegistration.h" |
| 50 #include "platform/RuntimeEnabledFeatures.h" | 50 #include "platform/RuntimeEnabledFeatures.h" |
| 51 #include "platform/weborigin/SchemeRegistry.h" |
| 51 #include "public/platform/WebServiceWorker.h" | 52 #include "public/platform/WebServiceWorker.h" |
| 52 #include "public/platform/WebServiceWorkerProvider.h" | 53 #include "public/platform/WebServiceWorkerProvider.h" |
| 53 #include "public/platform/WebServiceWorkerRegistration.h" | 54 #include "public/platform/WebServiceWorkerRegistration.h" |
| 54 #include "public/platform/WebString.h" | 55 #include "public/platform/WebString.h" |
| 55 #include "public/platform/WebURL.h" | 56 #include "public/platform/WebURL.h" |
| 56 | 57 |
| 57 namespace blink { | 58 namespace blink { |
| 58 | 59 |
| 59 class RegistrationCallback : public WebServiceWorkerProvider::WebServiceWorkerRe
gistrationCallbacks { | 60 class RegistrationCallback : public WebServiceWorkerProvider::WebServiceWorkerRe
gistrationCallbacks { |
| 60 public: | 61 public: |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 return ScriptPromise(); | 213 return ScriptPromise(); |
| 213 | 214 |
| 214 RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin(); | 215 RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin(); |
| 215 String errorMessage; | 216 String errorMessage; |
| 216 if (!executionContext->isPrivilegedContext(errorMessage)) { | 217 if (!executionContext->isPrivilegedContext(errorMessage)) { |
| 217 resolver->reject(DOMException::create(NotSupportedError, errorMessage)); | 218 resolver->reject(DOMException::create(NotSupportedError, errorMessage)); |
| 218 return promise; | 219 return promise; |
| 219 } | 220 } |
| 220 | 221 |
| 221 KURL pageURL = KURL(KURL(), documentOrigin->toString()); | 222 KURL pageURL = KURL(KURL(), documentOrigin->toString()); |
| 222 if (!pageURL.protocolIsInHTTPFamily()) { | 223 if (!SchemeRegistry::shouldTreatURLSchemeAsAllowServiceWorkers(pageURL.proto
col())) { |
| 223 resolver->reject(DOMException::create(SecurityError, "Failed to register
a ServiceWorker: The URL protocol of the current origin ('" + documentOrigin->t
oString() + "') is not supported.")); | 224 resolver->reject(DOMException::create(SecurityError, "Failed to register
a ServiceWorker: The URL protocol of the current origin ('" + documentOrigin->t
oString() + "') is not supported.")); |
| 224 return promise; | 225 return promise; |
| 225 } | 226 } |
| 226 | 227 |
| 227 KURL scriptURL = callingExecutionContext(scriptState->isolate())->completeUR
L(url); | 228 KURL scriptURL = callingExecutionContext(scriptState->isolate())->completeUR
L(url); |
| 228 scriptURL.removeFragmentIdentifier(); | 229 scriptURL.removeFragmentIdentifier(); |
| 229 if (!documentOrigin->canRequest(scriptURL)) { | 230 if (!documentOrigin->canRequest(scriptURL)) { |
| 230 RefPtr<SecurityOrigin> scriptOrigin = SecurityOrigin::create(scriptURL); | 231 RefPtr<SecurityOrigin> scriptOrigin = SecurityOrigin::create(scriptURL); |
| 231 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() +
"').")); | 232 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() +
"').")); |
| 232 return promise; | 233 return promise; |
| 233 } | 234 } |
| 234 if (!scriptURL.protocolIsInHTTPFamily()) { | 235 if (!SchemeRegistry::shouldTreatURLSchemeAsAllowServiceWorkers(scriptURL.pro
tocol())) { |
| 235 resolver->reject(DOMException::create(SecurityError, "Failed to register
a ServiceWorker: The URL protocol of the script ('" + scriptURL.string() + "')
is not supported.")); | 236 resolver->reject(DOMException::create(SecurityError, "Failed to register
a ServiceWorker: The URL protocol of the script ('" + scriptURL.string() + "')
is not supported.")); |
| 236 return promise; | 237 return promise; |
| 237 } | 238 } |
| 238 | 239 |
| 239 KURL patternURL; | 240 KURL patternURL; |
| 240 if (options.scope().isNull()) | 241 if (options.scope().isNull()) |
| 241 patternURL = KURL(scriptURL, "./"); | 242 patternURL = KURL(scriptURL, "./"); |
| 242 else | 243 else |
| 243 patternURL = callingExecutionContext(scriptState->isolate())->completeUR
L(options.scope()); | 244 patternURL = callingExecutionContext(scriptState->isolate())->completeUR
L(options.scope()); |
| 244 patternURL.removeFragmentIdentifier(); | 245 patternURL.removeFragmentIdentifier(); |
| 245 | 246 |
| 246 if (!documentOrigin->canRequest(patternURL)) { | 247 if (!documentOrigin->canRequest(patternURL)) { |
| 247 RefPtr<SecurityOrigin> patternOrigin = SecurityOrigin::create(patternURL
); | 248 RefPtr<SecurityOrigin> patternOrigin = SecurityOrigin::create(patternURL
); |
| 248 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() + "'
).")); | 249 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() + "'
).")); |
| 249 return promise; | 250 return promise; |
| 250 } | 251 } |
| 251 if (!patternURL.protocolIsInHTTPFamily()) { | 252 if (!SchemeRegistry::shouldTreatURLSchemeAsAllowServiceWorkers(patternURL.pr
otocol())) { |
| 252 resolver->reject(DOMException::create(SecurityError, "Failed to register
a ServiceWorker: The URL protocol of the scope ('" + patternURL.string() + "')
is not supported.")); | 253 resolver->reject(DOMException::create(SecurityError, "Failed to register
a ServiceWorker: The URL protocol of the scope ('" + patternURL.string() + "')
is not supported.")); |
| 253 return promise; | 254 return promise; |
| 254 } | 255 } |
| 255 | 256 |
| 256 m_provider->registerServiceWorker(patternURL, scriptURL, new RegistrationCal
lback(resolver)); | 257 m_provider->registerServiceWorker(patternURL, scriptURL, new RegistrationCal
lback(resolver)); |
| 257 | 258 |
| 258 return promise; | 259 return promise; |
| 259 } | 260 } |
| 260 | 261 |
| 261 ScriptPromise ServiceWorkerContainer::getRegistration(ScriptState* scriptState,
const String& documentURL) | 262 ScriptPromise ServiceWorkerContainer::getRegistration(ScriptState* scriptState,
const String& documentURL) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 274 return ScriptPromise(); | 275 return ScriptPromise(); |
| 275 | 276 |
| 276 RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin(); | 277 RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin(); |
| 277 String errorMessage; | 278 String errorMessage; |
| 278 if (!executionContext->isPrivilegedContext(errorMessage)) { | 279 if (!executionContext->isPrivilegedContext(errorMessage)) { |
| 279 resolver->reject(DOMException::create(NotSupportedError, errorMessage)); | 280 resolver->reject(DOMException::create(NotSupportedError, errorMessage)); |
| 280 return promise; | 281 return promise; |
| 281 } | 282 } |
| 282 | 283 |
| 283 KURL pageURL = KURL(KURL(), documentOrigin->toString()); | 284 KURL pageURL = KURL(KURL(), documentOrigin->toString()); |
| 284 if (!pageURL.protocolIsInHTTPFamily()) { | 285 if (!SchemeRegistry::shouldTreatURLSchemeAsAllowServiceWorkers(pageURL.proto
col())) { |
| 285 resolver->reject(DOMException::create(SecurityError, "Failed to get a Se
rviceWorkerRegistration: The URL protocol of the current origin ('" + documentOr
igin->toString() + "') is not supported.")); | 286 resolver->reject(DOMException::create(SecurityError, "Failed to get a Se
rviceWorkerRegistration: The URL protocol of the current origin ('" + documentOr
igin->toString() + "') is not supported.")); |
| 286 return promise; | 287 return promise; |
| 287 } | 288 } |
| 288 | 289 |
| 289 KURL completedURL = callingExecutionContext(scriptState->isolate())->complet
eURL(documentURL); | 290 KURL completedURL = callingExecutionContext(scriptState->isolate())->complet
eURL(documentURL); |
| 290 completedURL.removeFragmentIdentifier(); | 291 completedURL.removeFragmentIdentifier(); |
| 291 if (!documentOrigin->canRequest(completedURL)) { | 292 if (!documentOrigin->canRequest(completedURL)) { |
| 292 RefPtr<SecurityOrigin> documentURLOrigin = SecurityOrigin::create(comple
tedURL); | 293 RefPtr<SecurityOrigin> documentURLOrigin = SecurityOrigin::create(comple
tedURL); |
| 293 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() + "').")); | 294 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() + "').")); |
| 294 return promise; | 295 return promise; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 310 | 311 |
| 311 ExecutionContext* executionContext = scriptState->executionContext(); | 312 ExecutionContext* executionContext = scriptState->executionContext(); |
| 312 RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin(); | 313 RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin(); |
| 313 String errorMessage; | 314 String errorMessage; |
| 314 if (!executionContext->isPrivilegedContext(errorMessage)) { | 315 if (!executionContext->isPrivilegedContext(errorMessage)) { |
| 315 resolver->reject(DOMException::create(NotSupportedError, errorMessage)); | 316 resolver->reject(DOMException::create(NotSupportedError, errorMessage)); |
| 316 return promise; | 317 return promise; |
| 317 } | 318 } |
| 318 | 319 |
| 319 KURL pageURL = KURL(KURL(), documentOrigin->toString()); | 320 KURL pageURL = KURL(KURL(), documentOrigin->toString()); |
| 320 if (!pageURL.protocolIsInHTTPFamily()) { | 321 if (!SchemeRegistry::shouldTreatURLSchemeAsAllowServiceWorkers(pageURL.proto
col())) { |
| 321 resolver->reject(DOMException::create(SecurityError, "Failed to get Serv
iceWorkerRegistration objects: The URL protocol of the current origin ('" + docu
mentOrigin->toString() + "') is not supported.")); | 322 resolver->reject(DOMException::create(SecurityError, "Failed to get Serv
iceWorkerRegistration objects: The URL protocol of the current origin ('" + docu
mentOrigin->toString() + "') is not supported.")); |
| 322 return promise; | 323 return promise; |
| 323 } | 324 } |
| 324 | 325 |
| 325 m_provider->getRegistrations(new GetRegistrationsCallback(resolver)); | 326 m_provider->getRegistrations(new GetRegistrationsCallback(resolver)); |
| 326 | 327 |
| 327 return promise; | 328 return promise; |
| 328 } | 329 } |
| 329 | 330 |
| 330 ServiceWorkerContainer::ReadyProperty* ServiceWorkerContainer::createReadyProper
ty() | 331 ServiceWorkerContainer::ReadyProperty* ServiceWorkerContainer::createReadyProper
ty() |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 return; | 397 return; |
| 397 | 398 |
| 398 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro
m(executionContext)) { | 399 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro
m(executionContext)) { |
| 399 m_provider = client->provider(); | 400 m_provider = client->provider(); |
| 400 if (m_provider) | 401 if (m_provider) |
| 401 m_provider->setClient(this); | 402 m_provider->setClient(this); |
| 402 } | 403 } |
| 403 } | 404 } |
| 404 | 405 |
| 405 } // namespace blink | 406 } // namespace blink |
| OLD | NEW |