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

Unified 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: add url::Origin::operator== to make tests simpler 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/serviceworkers/InstallEvent.cpp
diff --git a/third_party/WebKit/Source/modules/serviceworkers/InstallEvent.cpp b/third_party/WebKit/Source/modules/serviceworkers/InstallEvent.cpp
index 1cd134969c6b8998180c25147ea56a350991b341..051f4a8172f1f644e5c576ed1283059aa16231a6 100644
--- a/third_party/WebKit/Source/modules/serviceworkers/InstallEvent.cpp
+++ b/third_party/WebKit/Source/modules/serviceworkers/InstallEvent.cpp
@@ -4,8 +4,10 @@
#include "modules/serviceworkers/InstallEvent.h"
+#include "bindings/modules/v8/UnionTypesModules.h"
#include "core/dom/ExceptionCode.h"
#include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h"
+#include "public/platform/WebSecurityOrigin.h"
namespace blink {
@@ -28,13 +30,41 @@ InstallEvent::~InstallEvent()
{
}
-void InstallEvent::registerForeignFetchScopes(ExecutionContext* executionContext, const Vector<String>& subScopes, ExceptionState& exceptionState)
+void InstallEvent::registerForeignFetchScopes(ExecutionContext* executionContext, const Vector<String>& subScopes, const USVStringOrUSVStringSequence& origins, ExceptionState& exceptionState)
{
if (!isBeingDispatched()) {
exceptionState.throwDOMException(InvalidStateError, "The event handler is already finished.");
return;
}
+ Vector<String> originList;
+ if (origins.isUSVString()) {
+ originList.append(origins.getAsUSVString());
+ } else if (origins.isUSVStringSequence()) {
+ originList = origins.getAsUSVStringSequence();
+ }
+ if (originList.isEmpty()) {
+ exceptionState.throwTypeError("At least one origin is required");
+ return;
+ }
+
+ // The origins parameter is either just a "*" to indicate all origins, or an
+ // explicit list of origins as absolute URLs. Internally an empty list of
+ // origins is used to represent the "*" case though.
+ Vector<RefPtr<SecurityOrigin>> parsedOrigins;
+ if (originList.size() != 1 || originList[0] != "*") {
+ parsedOrigins.resize(originList.size());
+ for (size_t i = 0; i < originList.size(); ++i) {
+ parsedOrigins[i] = SecurityOrigin::createFromString(originList[i]);
+ // Invalid URLs will result in a unique origin. And in general
+ // unique origins should not be accepted.
+ if (parsedOrigins[i]->isUnique()) {
+ exceptionState.throwTypeError("Invalid origin URL: " + originList[i]);
+ return;
+ }
+ }
+ }
+
ServiceWorkerGlobalScopeClient* client = ServiceWorkerGlobalScopeClient::from(executionContext);
String scopePath = static_cast<KURL>(client->scope()).path();
@@ -44,21 +74,21 @@ void InstallEvent::registerForeignFetchScopes(ExecutionContext* executionContext
for (size_t i = 0; i < subScopes.size(); ++i) {
subScopeURLs[i] = executionContext->completeURL(subScopes[i]);
if (!subScopeURLs[i].isValid()) {
- exceptionState.throwTypeError("Invalid URL: " + subScopes[i]);
+ exceptionState.throwTypeError("Invalid subscope URL: " + subScopes[i]);
return;
}
subScopeURLs[i].removeFragmentIdentifier();
if (!origin->canRequest(subScopeURLs[i])) {
- exceptionState.throwTypeError("URL is not within scope: " + subScopes[i]);
+ exceptionState.throwTypeError("Subscope URL is not within scope: " + subScopes[i]);
return;
}
String subScopePath = subScopeURLs[i].path();
if (!subScopePath.startsWith(scopePath)) {
- exceptionState.throwTypeError("URL is not within scope: " + subScopes[i]);
+ exceptionState.throwTypeError("Subscope URL is not within scope: " + subScopes[i]);
return;
}
}
- client->registerForeignFetchScopes(subScopeURLs);
+ client->registerForeignFetchScopes(subScopeURLs, parsedOrigins);
}
const AtomicString& InstallEvent::interfaceName() const

Powered by Google App Engine
This is Rietveld 408576698