Chromium Code Reviews| 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/modules/v8/UnionTypesModules.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 | 10 |
| 10 namespace blink { | 11 namespace blink { |
| 11 | 12 |
| 12 PassRefPtrWillBeRawPtr<InstallEvent> InstallEvent::create() | 13 PassRefPtrWillBeRawPtr<InstallEvent> InstallEvent::create() |
| 13 { | 14 { |
| 14 return adoptRefWillBeNoop(new InstallEvent()); | 15 return adoptRefWillBeNoop(new InstallEvent()); |
| 15 } | 16 } |
| 16 | 17 |
| 17 PassRefPtrWillBeRawPtr<InstallEvent> InstallEvent::create(const AtomicString& ty pe, const ExtendableEventInit& eventInit) | 18 PassRefPtrWillBeRawPtr<InstallEvent> InstallEvent::create(const AtomicString& ty pe, const ExtendableEventInit& eventInit) |
| 18 { | 19 { |
| 19 return adoptRefWillBeNoop(new InstallEvent(type, eventInit)); | 20 return adoptRefWillBeNoop(new InstallEvent(type, eventInit)); |
| 20 } | 21 } |
| 21 | 22 |
| 22 PassRefPtrWillBeRawPtr<InstallEvent> InstallEvent::create(const AtomicString& ty pe, const ExtendableEventInit& eventInit, WaitUntilObserver* observer) | 23 PassRefPtrWillBeRawPtr<InstallEvent> InstallEvent::create(const AtomicString& ty pe, const ExtendableEventInit& eventInit, WaitUntilObserver* observer) |
| 23 { | 24 { |
| 24 return adoptRefWillBeNoop(new InstallEvent(type, eventInit, observer)); | 25 return adoptRefWillBeNoop(new InstallEvent(type, eventInit, observer)); |
| 25 } | 26 } |
| 26 | 27 |
| 27 InstallEvent::~InstallEvent() | 28 InstallEvent::~InstallEvent() |
| 28 { | 29 { |
| 29 } | 30 } |
| 30 | 31 |
| 31 void InstallEvent::registerForeignFetchScopes(ExecutionContext* executionContext , const Vector<String>& subScopes, ExceptionState& exceptionState) | 32 void InstallEvent::registerForeignFetchScopes(ExecutionContext* executionContext , const Vector<String>& subScopes, const USVStringOrUSVStringSequence& origins, ExceptionState& exceptionState) |
| 32 { | 33 { |
| 33 if (!isBeingDispatched()) { | 34 if (!isBeingDispatched()) { |
| 34 exceptionState.throwDOMException(InvalidStateError, "The event handler i s already finished."); | 35 exceptionState.throwDOMException(InvalidStateError, "The event handler i s already finished."); |
| 35 return; | 36 return; |
| 36 } | 37 } |
| 37 | 38 |
| 39 Vector<String> originList; | |
| 40 if (origins.isUSVString()) { | |
| 41 originList.append(origins.getAsUSVString()); | |
| 42 } else if (origins.isUSVStringSequence()) { | |
| 43 originList = origins.getAsUSVStringSequence(); | |
| 44 } | |
| 45 if (originList.isEmpty()) { | |
| 46 exceptionState.throwTypeError("At least one origin is required"); | |
| 47 return; | |
| 48 } | |
|
falken
2016/02/03 02:17:32
I'm not sure but would ['*'] and '*' arguments hav
Marijn Kruisselbrink
2016/02/03 17:53:31
Hmm, yeah. I think I would prefer to treat those t
| |
| 49 | |
| 50 Vector<KURL> originURLs; | |
| 51 if (originList.size() != 1 || originList[0] != "*") { | |
|
falken
2016/02/03 02:17:32
The '*' special case and how it translates to the
Marijn Kruisselbrink
2016/02/03 17:53:31
I added a comment to try to explain this.
| |
| 52 originURLs.resize(originList.size()); | |
| 53 for (size_t i = 0; i < originList.size(); ++i) { | |
| 54 originURLs[i] = KURL(KURL(), originList[i]); | |
| 55 if (!originURLs[i].isValid()) { | |
| 56 exceptionState.throwTypeError("Invalid Origin URL: " + originLis t[i]); | |
|
falken
2016/02/03 02:17:32
nit: should be consistent about origin vs Origin i
Marijn Kruisselbrink
2016/02/03 17:53:31
Done
| |
| 57 return; | |
| 58 } | |
| 59 } | |
| 60 } | |
| 61 | |
| 38 ServiceWorkerGlobalScopeClient* client = ServiceWorkerGlobalScopeClient::fro m(executionContext); | 62 ServiceWorkerGlobalScopeClient* client = ServiceWorkerGlobalScopeClient::fro m(executionContext); |
| 39 | 63 |
| 40 String scopePath = static_cast<KURL>(client->scope()).path(); | 64 String scopePath = static_cast<KURL>(client->scope()).path(); |
| 41 RefPtr<SecurityOrigin> origin = executionContext->securityOrigin(); | 65 RefPtr<SecurityOrigin> origin = executionContext->securityOrigin(); |
| 42 | 66 |
| 43 Vector<KURL> subScopeURLs(subScopes.size()); | 67 Vector<KURL> subScopeURLs(subScopes.size()); |
| 44 for (size_t i = 0; i < subScopes.size(); ++i) { | 68 for (size_t i = 0; i < subScopes.size(); ++i) { |
| 45 subScopeURLs[i] = executionContext->completeURL(subScopes[i]); | 69 subScopeURLs[i] = executionContext->completeURL(subScopes[i]); |
| 46 if (!subScopeURLs[i].isValid()) { | 70 if (!subScopeURLs[i].isValid()) { |
| 47 exceptionState.throwTypeError("Invalid URL: " + subScopes[i]); | 71 exceptionState.throwTypeError("Invalid URL: " + subScopes[i]); |
|
falken
2016/02/03 02:17:32
nit: here too maybe it should say "Invalid subscop
Marijn Kruisselbrink
2016/02/03 17:53:30
Done
| |
| 48 return; | 72 return; |
| 49 } | 73 } |
| 50 subScopeURLs[i].removeFragmentIdentifier(); | 74 subScopeURLs[i].removeFragmentIdentifier(); |
| 51 if (!origin->canRequest(subScopeURLs[i])) { | 75 if (!origin->canRequest(subScopeURLs[i])) { |
| 52 exceptionState.throwTypeError("URL is not within scope: " + subScope s[i]); | 76 exceptionState.throwTypeError("URL is not within scope: " + subScope s[i]); |
| 53 return; | 77 return; |
| 54 } | 78 } |
| 55 String subScopePath = subScopeURLs[i].path(); | 79 String subScopePath = subScopeURLs[i].path(); |
| 56 if (!subScopePath.startsWith(scopePath)) { | 80 if (!subScopePath.startsWith(scopePath)) { |
| 57 exceptionState.throwTypeError("URL is not within scope: " + subScope s[i]); | 81 exceptionState.throwTypeError("URL is not within scope: " + subScope s[i]); |
| 58 return; | 82 return; |
| 59 } | 83 } |
| 60 } | 84 } |
| 61 client->registerForeignFetchScopes(subScopeURLs); | 85 client->registerForeignFetchScopes(subScopeURLs, originURLs); |
| 62 } | 86 } |
| 63 | 87 |
| 64 const AtomicString& InstallEvent::interfaceName() const | 88 const AtomicString& InstallEvent::interfaceName() const |
| 65 { | 89 { |
| 66 return EventNames::InstallEvent; | 90 return EventNames::InstallEvent; |
| 67 } | 91 } |
| 68 | 92 |
| 69 InstallEvent::InstallEvent() | 93 InstallEvent::InstallEvent() |
| 70 { | 94 { |
| 71 } | 95 } |
| 72 | 96 |
| 73 InstallEvent::InstallEvent(const AtomicString& type, const ExtendableEventInit& initializer) | 97 InstallEvent::InstallEvent(const AtomicString& type, const ExtendableEventInit& initializer) |
| 74 : ExtendableEvent(type, initializer) | 98 : ExtendableEvent(type, initializer) |
| 75 { | 99 { |
| 76 } | 100 } |
| 77 | 101 |
| 78 InstallEvent::InstallEvent(const AtomicString& type, const ExtendableEventInit& initializer, WaitUntilObserver* observer) | 102 InstallEvent::InstallEvent(const AtomicString& type, const ExtendableEventInit& initializer, WaitUntilObserver* observer) |
| 79 : ExtendableEvent(type, initializer, observer) | 103 : ExtendableEvent(type, initializer, observer) |
| 80 { | 104 { |
| 81 } | 105 } |
| 82 | 106 |
| 83 } // namespace blink | 107 } // namespace blink |
| OLD | NEW |