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

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

Issue 1505023004: ServiceWorker: Early reject error if url is something wrong. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "config.h" 5 #include "config.h"
6 #include "modules/serviceworkers/ServiceWorkerClients.h" 6 #include "modules/serviceworkers/ServiceWorkerClients.h"
7 7
8 #include "bindings/core/v8/CallbackPromiseAdapter.h" 8 #include "bindings/core/v8/CallbackPromiseAdapter.h"
9 #include "bindings/core/v8/ScriptPromiseResolver.h" 9 #include "bindings/core/v8/ScriptPromiseResolver.h"
10 #include "core/dom/DOMException.h" 10 #include "core/dom/DOMException.h"
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 return promise; 105 return promise;
106 } 106 }
107 107
108 ScriptPromise ServiceWorkerClients::openWindow(ScriptState* scriptState, const S tring& url) 108 ScriptPromise ServiceWorkerClients::openWindow(ScriptState* scriptState, const S tring& url)
109 { 109 {
110 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; 110 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
111 ScriptPromise promise = resolver->promise(); 111 ScriptPromise promise = resolver->promise();
112 ExecutionContext* context = scriptState->executionContext(); 112 ExecutionContext* context = scriptState->executionContext();
113 113
114 KURL parsedUrl = KURL(toWorkerGlobalScope(context)->location()->url(), url); 114 KURL parsedUrl = KURL(toWorkerGlobalScope(context)->location()->url(), url);
115 if (!parsedUrl.isValid()) { 115 if (!parsedUrl.isValid() || !parsedUrl.protocolIsInHTTPFamily()) {
116 resolver->reject(V8ThrowException::createTypeError(scriptState->isolate( ), "'" + url + "' is not a valid URL.")); 116 resolver->reject(V8ThrowException::createTypeError(scriptState->isolate( ), "'" + url + "' is not a valid URL."));
117 return promise; 117 return promise;
118 } 118 }
119 119
120 if (!context->securityOrigin()->canDisplay(parsedUrl)) { 120 if (!context->securityOrigin()->canDisplay(parsedUrl)) {
121 resolver->reject(V8ThrowException::createTypeError(scriptState->isolate( ), "'" + parsedUrl.elidedString() + "' cannot be opened.")); 121 resolver->reject(V8ThrowException::createTypeError(scriptState->isolate( ), "'" + parsedUrl.elidedString() + "' cannot be opened."));
122 return promise; 122 return promise;
123 } 123 }
124 124
125 if (!context->isWindowInteractionAllowed()) { 125 if (!context->isWindowInteractionAllowed()) {
126 resolver->reject(DOMException::create(InvalidAccessError, "Not allowed t o open a window.")); 126 resolver->reject(DOMException::create(InvalidAccessError, "Not allowed t o open a window."));
127 return promise; 127 return promise;
128 } 128 }
129 context->consumeWindowInteraction(); 129 context->consumeWindowInteraction();
130 130
131 ServiceWorkerGlobalScopeClient::from(context)->openWindow(parsedUrl, new Nav igateClientCallback(resolver)); 131 ServiceWorkerGlobalScopeClient::from(context)->openWindow(parsedUrl, new Nav igateClientCallback(resolver));
132 return promise; 132 return promise;
133 } 133 }
134 134
135 } // namespace blink 135 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698