| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "modules/serviceworkers/InstallEvent.h" | 5 #include "modules/serviceworkers/InstallEvent.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ScriptState.h" |
| 7 #include "core/dom/ExceptionCode.h" | 8 #include "core/dom/ExceptionCode.h" |
| 8 #include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h" | 9 #include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h" |
| 9 #include "public/platform/WebSecurityOrigin.h" | 10 #include "public/platform/WebSecurityOrigin.h" |
| 10 | 11 |
| 11 namespace blink { | 12 namespace blink { |
| 12 | 13 |
| 13 InstallEvent* InstallEvent::create(const AtomicString& type, | 14 InstallEvent* InstallEvent::create(const AtomicString& type, |
| 14 const ExtendableEventInit& eventInit) { | 15 const ExtendableEventInit& eventInit) { |
| 15 return new InstallEvent(type, eventInit); | 16 return new InstallEvent(type, eventInit); |
| 16 } | 17 } |
| 17 | 18 |
| 18 InstallEvent* InstallEvent::create(const AtomicString& type, | 19 InstallEvent* InstallEvent::create(const AtomicString& type, |
| 19 const ExtendableEventInit& eventInit, | 20 const ExtendableEventInit& eventInit, |
| 20 WaitUntilObserver* observer) { | 21 WaitUntilObserver* observer) { |
| 21 return new InstallEvent(type, eventInit, observer); | 22 return new InstallEvent(type, eventInit, observer); |
| 22 } | 23 } |
| 23 | 24 |
| 24 InstallEvent::~InstallEvent() {} | 25 InstallEvent::~InstallEvent() {} |
| 25 | 26 |
| 26 void InstallEvent::registerForeignFetch(ExecutionContext* executionContext, | 27 void InstallEvent::registerForeignFetch(ScriptState* scriptState, |
| 27 const ForeignFetchOptions& options, | 28 const ForeignFetchOptions& options, |
| 28 ExceptionState& exceptionState) { | 29 ExceptionState& exceptionState) { |
| 29 if (!isBeingDispatched()) { | 30 if (!isBeingDispatched()) { |
| 30 exceptionState.throwDOMException(InvalidStateError, | 31 exceptionState.throwDOMException(InvalidStateError, |
| 31 "The event handler is already finished."); | 32 "The event handler is already finished."); |
| 32 return; | 33 return; |
| 33 } | 34 } |
| 34 | 35 |
| 35 if (!options.hasOrigins() || options.origins().isEmpty()) { | 36 if (!options.hasOrigins() || options.origins().isEmpty()) { |
| 36 exceptionState.throwTypeError("At least one origin is required"); | 37 exceptionState.throwTypeError("At least one origin is required"); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 48 parsedOrigins[i] = SecurityOrigin::createFromString(originList[i]); | 49 parsedOrigins[i] = SecurityOrigin::createFromString(originList[i]); |
| 49 // Invalid URLs will result in a unique origin. And in general | 50 // Invalid URLs will result in a unique origin. And in general |
| 50 // unique origins should not be accepted. | 51 // unique origins should not be accepted. |
| 51 if (parsedOrigins[i]->isUnique()) { | 52 if (parsedOrigins[i]->isUnique()) { |
| 52 exceptionState.throwTypeError("Invalid origin URL: " + originList[i]); | 53 exceptionState.throwTypeError("Invalid origin URL: " + originList[i]); |
| 53 return; | 54 return; |
| 54 } | 55 } |
| 55 } | 56 } |
| 56 } | 57 } |
| 57 | 58 |
| 59 ExecutionContext* executionContext = scriptState->getExecutionContext(); |
| 58 ServiceWorkerGlobalScopeClient* client = | 60 ServiceWorkerGlobalScopeClient* client = |
| 59 ServiceWorkerGlobalScopeClient::from(executionContext); | 61 ServiceWorkerGlobalScopeClient::from(executionContext); |
| 60 | 62 |
| 61 String scopePath = static_cast<KURL>(client->scope()).path(); | 63 String scopePath = static_cast<KURL>(client->scope()).path(); |
| 62 RefPtr<SecurityOrigin> origin = executionContext->getSecurityOrigin(); | 64 RefPtr<SecurityOrigin> origin = executionContext->getSecurityOrigin(); |
| 63 | 65 |
| 64 if (!options.hasScopes() || options.scopes().isEmpty()) { | 66 if (!options.hasScopes() || options.scopes().isEmpty()) { |
| 65 exceptionState.throwTypeError("At least one scope is required"); | 67 exceptionState.throwTypeError("At least one scope is required"); |
| 66 return; | 68 return; |
| 67 } | 69 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 96 InstallEvent::InstallEvent(const AtomicString& type, | 98 InstallEvent::InstallEvent(const AtomicString& type, |
| 97 const ExtendableEventInit& initializer) | 99 const ExtendableEventInit& initializer) |
| 98 : ExtendableEvent(type, initializer) {} | 100 : ExtendableEvent(type, initializer) {} |
| 99 | 101 |
| 100 InstallEvent::InstallEvent(const AtomicString& type, | 102 InstallEvent::InstallEvent(const AtomicString& type, |
| 101 const ExtendableEventInit& initializer, | 103 const ExtendableEventInit& initializer, |
| 102 WaitUntilObserver* observer) | 104 WaitUntilObserver* observer) |
| 103 : ExtendableEvent(type, initializer, observer) {} | 105 : ExtendableEvent(type, initializer, observer) {} |
| 104 | 106 |
| 105 } // namespace blink | 107 } // namespace blink |
| OLD | NEW |