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

Side by Side Diff: third_party/WebKit/Source/modules/serviceworkers/InstallEvent.cpp

Issue 1656933003: Add origins argument to registerForeignFetchScopes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments Created 4 years, 10 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 // 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 }
49
50 // The origins parameter is either just a "*" to indicate all origins, or an
51 // explicit list of origins as absolute URLs. Internally an empty list of
52 // origins is used to represent the "*" case though.
53 Vector<KURL> originURLs;
54 if (originList.size() != 1 || originList[0] != "*") {
55 originURLs.resize(originList.size());
56 for (size_t i = 0; i < originList.size(); ++i) {
57 originURLs[i] = KURL(KURL(), originList[i]);
58 if (!originURLs[i].isValid()) {
59 exceptionState.throwTypeError("Invalid origin URL: " + originLis t[i]);
60 return;
61 }
62 }
63 }
64
38 ServiceWorkerGlobalScopeClient* client = ServiceWorkerGlobalScopeClient::fro m(executionContext); 65 ServiceWorkerGlobalScopeClient* client = ServiceWorkerGlobalScopeClient::fro m(executionContext);
39 66
40 String scopePath = static_cast<KURL>(client->scope()).path(); 67 String scopePath = static_cast<KURL>(client->scope()).path();
41 RefPtr<SecurityOrigin> origin = executionContext->securityOrigin(); 68 RefPtr<SecurityOrigin> origin = executionContext->securityOrigin();
42 69
43 Vector<KURL> subScopeURLs(subScopes.size()); 70 Vector<KURL> subScopeURLs(subScopes.size());
44 for (size_t i = 0; i < subScopes.size(); ++i) { 71 for (size_t i = 0; i < subScopes.size(); ++i) {
45 subScopeURLs[i] = executionContext->completeURL(subScopes[i]); 72 subScopeURLs[i] = executionContext->completeURL(subScopes[i]);
46 if (!subScopeURLs[i].isValid()) { 73 if (!subScopeURLs[i].isValid()) {
47 exceptionState.throwTypeError("Invalid URL: " + subScopes[i]); 74 exceptionState.throwTypeError("Invalid subscope URL: " + subScopes[i ]);
48 return; 75 return;
49 } 76 }
50 subScopeURLs[i].removeFragmentIdentifier(); 77 subScopeURLs[i].removeFragmentIdentifier();
51 if (!origin->canRequest(subScopeURLs[i])) { 78 if (!origin->canRequest(subScopeURLs[i])) {
52 exceptionState.throwTypeError("URL is not within scope: " + subScope s[i]); 79 exceptionState.throwTypeError("Subscope URL is not within scope: " + subScopes[i]);
53 return; 80 return;
54 } 81 }
55 String subScopePath = subScopeURLs[i].path(); 82 String subScopePath = subScopeURLs[i].path();
56 if (!subScopePath.startsWith(scopePath)) { 83 if (!subScopePath.startsWith(scopePath)) {
57 exceptionState.throwTypeError("URL is not within scope: " + subScope s[i]); 84 exceptionState.throwTypeError("Subscope URL is not within scope: " + subScopes[i]);
58 return; 85 return;
59 } 86 }
60 } 87 }
61 client->registerForeignFetchScopes(subScopeURLs); 88 client->registerForeignFetchScopes(subScopeURLs, originURLs);
62 } 89 }
63 90
64 const AtomicString& InstallEvent::interfaceName() const 91 const AtomicString& InstallEvent::interfaceName() const
65 { 92 {
66 return EventNames::InstallEvent; 93 return EventNames::InstallEvent;
67 } 94 }
68 95
69 InstallEvent::InstallEvent() 96 InstallEvent::InstallEvent()
70 { 97 {
71 } 98 }
72 99
73 InstallEvent::InstallEvent(const AtomicString& type, const ExtendableEventInit& initializer) 100 InstallEvent::InstallEvent(const AtomicString& type, const ExtendableEventInit& initializer)
74 : ExtendableEvent(type, initializer) 101 : ExtendableEvent(type, initializer)
75 { 102 {
76 } 103 }
77 104
78 InstallEvent::InstallEvent(const AtomicString& type, const ExtendableEventInit& initializer, WaitUntilObserver* observer) 105 InstallEvent::InstallEvent(const AtomicString& type, const ExtendableEventInit& initializer, WaitUntilObserver* observer)
79 : ExtendableEvent(type, initializer, observer) 106 : ExtendableEvent(type, initializer, observer)
80 { 107 {
81 } 108 }
82 109
83 } // namespace blink 110 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698