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

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

Issue 1481523006: ServiceWorker: Should throw TypeError instead of Unknown/SecurityError. (Closed) 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/ServiceWorkerWindowClient.h" 6 #include "modules/serviceworkers/ServiceWorkerWindowClient.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"
11 #include "core/dom/ExceptionCode.h" 11 #include "core/dom/ExceptionCode.h"
12 #include "core/page/PageVisibilityState.h" 12 #include "core/page/PageVisibilityState.h"
13 #include "core/workers/WorkerGlobalScope.h" 13 #include "core/workers/WorkerGlobalScope.h"
14 #include "core/workers/WorkerLocation.h" 14 #include "core/workers/WorkerLocation.h"
15 #include "modules/serviceworkers/ServiceWorkerError.h" 15 #include "modules/serviceworkers/ServiceWorkerError.h"
16 #include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h" 16 #include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h"
17 #include "modules/serviceworkers/ServiceWorkerWindowClientCallback.h"
17 #include "public/platform/WebString.h" 18 #include "public/platform/WebString.h"
18 #include "wtf/RefPtr.h" 19 #include "wtf/RefPtr.h"
19 20
20 namespace blink { 21 namespace blink {
21 22
22 ServiceWorkerWindowClient* ServiceWorkerWindowClient::take(ScriptPromiseResolver *, PassOwnPtr<WebServiceWorkerClientInfo> webClient) 23 ServiceWorkerWindowClient* ServiceWorkerWindowClient::take(ScriptPromiseResolver *, PassOwnPtr<WebServiceWorkerClientInfo> webClient)
23 { 24 {
24 return webClient ? ServiceWorkerWindowClient::create(*webClient) : nullptr; 25 return webClient ? ServiceWorkerWindowClient::create(*webClient) : nullptr;
25 } 26 }
26 27
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; 66 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
66 ScriptPromise promise = resolver->promise(); 67 ScriptPromise promise = resolver->promise();
67 ExecutionContext* context = scriptState->executionContext(); 68 ExecutionContext* context = scriptState->executionContext();
68 69
69 KURL parsedUrl = KURL(toWorkerGlobalScope(context)->location()->url(), url); 70 KURL parsedUrl = KURL(toWorkerGlobalScope(context)->location()->url(), url);
70 if (!parsedUrl.isValid() || parsedUrl.protocolIsAbout()) { 71 if (!parsedUrl.isValid() || parsedUrl.protocolIsAbout()) {
71 resolver->reject(V8ThrowException::createTypeError(scriptState->isolate( ), "'" + url + "' is not a valid URL.")); 72 resolver->reject(V8ThrowException::createTypeError(scriptState->isolate( ), "'" + url + "' is not a valid URL."));
72 return promise; 73 return promise;
73 } 74 }
74 if (!context->securityOrigin()->canDisplay(parsedUrl)) { 75 if (!context->securityOrigin()->canDisplay(parsedUrl)) {
75 resolver->reject(DOMException::create(SecurityError, "'" + parsedUrl.eli dedString() + "' cannot navigate.")); 76 resolver->reject(V8ThrowException::createTypeError(scriptState->isolate( ), "'" + parsedUrl.elidedString() + "' cannot navigate."));
76 return promise; 77 return promise;
77 } 78 }
78 79
79 ServiceWorkerGlobalScopeClient::from(context)->navigate(uuid(), parsedUrl, n ew CallbackPromiseAdapter<ServiceWorkerWindowClient, ServiceWorkerError>(resolve r)); 80 ServiceWorkerGlobalScopeClient::from(context)->navigate(uuid(), parsedUrl, n ew NavigateClientCallback(resolver));
80 return promise; 81 return promise;
81 } 82 }
82 83
83 DEFINE_TRACE(ServiceWorkerWindowClient) 84 DEFINE_TRACE(ServiceWorkerWindowClient)
84 { 85 {
85 ServiceWorkerClient::trace(visitor); 86 ServiceWorkerClient::trace(visitor);
86 } 87 }
87 88
88 } // namespace blink 89 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698