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" |
| 10 #include "public/platform/WebSecurityOrigin.h" |
9 | 11 |
10 namespace blink { | 12 namespace blink { |
11 | 13 |
12 PassRefPtrWillBeRawPtr<InstallEvent> InstallEvent::create() | 14 PassRefPtrWillBeRawPtr<InstallEvent> InstallEvent::create() |
13 { | 15 { |
14 return adoptRefWillBeNoop(new InstallEvent()); | 16 return adoptRefWillBeNoop(new InstallEvent()); |
15 } | 17 } |
16 | 18 |
17 PassRefPtrWillBeRawPtr<InstallEvent> InstallEvent::create(const AtomicString& ty
pe, const ExtendableEventInit& eventInit) | 19 PassRefPtrWillBeRawPtr<InstallEvent> InstallEvent::create(const AtomicString& ty
pe, const ExtendableEventInit& eventInit) |
18 { | 20 { |
19 return adoptRefWillBeNoop(new InstallEvent(type, eventInit)); | 21 return adoptRefWillBeNoop(new InstallEvent(type, eventInit)); |
20 } | 22 } |
21 | 23 |
22 PassRefPtrWillBeRawPtr<InstallEvent> InstallEvent::create(const AtomicString& ty
pe, const ExtendableEventInit& eventInit, WaitUntilObserver* observer) | 24 PassRefPtrWillBeRawPtr<InstallEvent> InstallEvent::create(const AtomicString& ty
pe, const ExtendableEventInit& eventInit, WaitUntilObserver* observer) |
23 { | 25 { |
24 return adoptRefWillBeNoop(new InstallEvent(type, eventInit, observer)); | 26 return adoptRefWillBeNoop(new InstallEvent(type, eventInit, observer)); |
25 } | 27 } |
26 | 28 |
27 InstallEvent::~InstallEvent() | 29 InstallEvent::~InstallEvent() |
28 { | 30 { |
29 } | 31 } |
30 | 32 |
31 void InstallEvent::registerForeignFetchScopes(ExecutionContext* executionContext
, const Vector<String>& subScopes, ExceptionState& exceptionState) | 33 void InstallEvent::registerForeignFetchScopes(ExecutionContext* executionContext
, const Vector<String>& subScopes, const USVStringOrUSVStringSequence& origins,
ExceptionState& exceptionState) |
32 { | 34 { |
33 if (!isBeingDispatched()) { | 35 if (!isBeingDispatched()) { |
34 exceptionState.throwDOMException(InvalidStateError, "The event handler i
s already finished."); | 36 exceptionState.throwDOMException(InvalidStateError, "The event handler i
s already finished."); |
35 return; | 37 return; |
36 } | 38 } |
37 | 39 |
| 40 Vector<String> originList; |
| 41 if (origins.isUSVString()) { |
| 42 originList.append(origins.getAsUSVString()); |
| 43 } else if (origins.isUSVStringSequence()) { |
| 44 originList = origins.getAsUSVStringSequence(); |
| 45 } |
| 46 if (originList.isEmpty()) { |
| 47 exceptionState.throwTypeError("At least one origin is required"); |
| 48 return; |
| 49 } |
| 50 |
| 51 // The origins parameter is either just a "*" to indicate all origins, or an |
| 52 // explicit list of origins as absolute URLs. Internally an empty list of |
| 53 // origins is used to represent the "*" case though. |
| 54 Vector<RefPtr<SecurityOrigin>> parsedOrigins; |
| 55 if (originList.size() != 1 || originList[0] != "*") { |
| 56 parsedOrigins.resize(originList.size()); |
| 57 for (size_t i = 0; i < originList.size(); ++i) { |
| 58 parsedOrigins[i] = SecurityOrigin::createFromString(originList[i]); |
| 59 // Invalid URLs will result in a unique origin. And in general |
| 60 // unique origins should not be accepted. |
| 61 if (parsedOrigins[i]->isUnique()) { |
| 62 exceptionState.throwTypeError("Invalid origin URL: " + originLis
t[i]); |
| 63 return; |
| 64 } |
| 65 } |
| 66 } |
| 67 |
38 ServiceWorkerGlobalScopeClient* client = ServiceWorkerGlobalScopeClient::fro
m(executionContext); | 68 ServiceWorkerGlobalScopeClient* client = ServiceWorkerGlobalScopeClient::fro
m(executionContext); |
39 | 69 |
40 String scopePath = static_cast<KURL>(client->scope()).path(); | 70 String scopePath = static_cast<KURL>(client->scope()).path(); |
41 RefPtr<SecurityOrigin> origin = executionContext->securityOrigin(); | 71 RefPtr<SecurityOrigin> origin = executionContext->securityOrigin(); |
42 | 72 |
43 Vector<KURL> subScopeURLs(subScopes.size()); | 73 Vector<KURL> subScopeURLs(subScopes.size()); |
44 for (size_t i = 0; i < subScopes.size(); ++i) { | 74 for (size_t i = 0; i < subScopes.size(); ++i) { |
45 subScopeURLs[i] = executionContext->completeURL(subScopes[i]); | 75 subScopeURLs[i] = executionContext->completeURL(subScopes[i]); |
46 if (!subScopeURLs[i].isValid()) { | 76 if (!subScopeURLs[i].isValid()) { |
47 exceptionState.throwTypeError("Invalid URL: " + subScopes[i]); | 77 exceptionState.throwTypeError("Invalid subscope URL: " + subScopes[i
]); |
48 return; | 78 return; |
49 } | 79 } |
50 subScopeURLs[i].removeFragmentIdentifier(); | 80 subScopeURLs[i].removeFragmentIdentifier(); |
51 if (!origin->canRequest(subScopeURLs[i])) { | 81 if (!origin->canRequest(subScopeURLs[i])) { |
52 exceptionState.throwTypeError("URL is not within scope: " + subScope
s[i]); | 82 exceptionState.throwTypeError("Subscope URL is not within scope: " +
subScopes[i]); |
53 return; | 83 return; |
54 } | 84 } |
55 String subScopePath = subScopeURLs[i].path(); | 85 String subScopePath = subScopeURLs[i].path(); |
56 if (!subScopePath.startsWith(scopePath)) { | 86 if (!subScopePath.startsWith(scopePath)) { |
57 exceptionState.throwTypeError("URL is not within scope: " + subScope
s[i]); | 87 exceptionState.throwTypeError("Subscope URL is not within scope: " +
subScopes[i]); |
58 return; | 88 return; |
59 } | 89 } |
60 } | 90 } |
61 client->registerForeignFetchScopes(subScopeURLs); | 91 client->registerForeignFetchScopes(subScopeURLs, parsedOrigins); |
62 } | 92 } |
63 | 93 |
64 const AtomicString& InstallEvent::interfaceName() const | 94 const AtomicString& InstallEvent::interfaceName() const |
65 { | 95 { |
66 return EventNames::InstallEvent; | 96 return EventNames::InstallEvent; |
67 } | 97 } |
68 | 98 |
69 InstallEvent::InstallEvent() | 99 InstallEvent::InstallEvent() |
70 { | 100 { |
71 } | 101 } |
72 | 102 |
73 InstallEvent::InstallEvent(const AtomicString& type, const ExtendableEventInit&
initializer) | 103 InstallEvent::InstallEvent(const AtomicString& type, const ExtendableEventInit&
initializer) |
74 : ExtendableEvent(type, initializer) | 104 : ExtendableEvent(type, initializer) |
75 { | 105 { |
76 } | 106 } |
77 | 107 |
78 InstallEvent::InstallEvent(const AtomicString& type, const ExtendableEventInit&
initializer, WaitUntilObserver* observer) | 108 InstallEvent::InstallEvent(const AtomicString& type, const ExtendableEventInit&
initializer, WaitUntilObserver* observer) |
79 : ExtendableEvent(type, initializer, observer) | 109 : ExtendableEvent(type, initializer, observer) |
80 { | 110 { |
81 } | 111 } |
82 | 112 |
83 } // namespace blink | 113 } // namespace blink |
OLD | NEW |