Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" | |
| 14 #include "core/workers/WorkerLocation.h" | |
| 13 #include "modules/serviceworkers/ServiceWorkerError.h" | 15 #include "modules/serviceworkers/ServiceWorkerError.h" |
| 14 #include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h" | 16 #include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h" |
| 15 #include "public/platform/WebString.h" | 17 #include "public/platform/WebString.h" |
| 16 #include "wtf/RefPtr.h" | 18 #include "wtf/RefPtr.h" |
| 17 | 19 |
| 18 namespace blink { | 20 namespace blink { |
| 19 | 21 |
| 20 ServiceWorkerWindowClient* ServiceWorkerWindowClient::take(ScriptPromiseResolver *, ServiceWorkerWindowClient::WebType* webClientRaw) | 22 ServiceWorkerWindowClient* ServiceWorkerWindowClient::take(ScriptPromiseResolver *, ServiceWorkerWindowClient::WebType* webClientRaw) |
| 21 { | 23 { |
| 22 return ServiceWorkerWindowClient::create(*webClientRaw); | 24 return ServiceWorkerWindowClient::create(*webClientRaw); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 if (!scriptState->executionContext()->isWindowInteractionAllowed()) { | 58 if (!scriptState->executionContext()->isWindowInteractionAllowed()) { |
| 57 resolver->reject(DOMException::create(InvalidAccessError, "Not allowed t o focus a window.")); | 59 resolver->reject(DOMException::create(InvalidAccessError, "Not allowed t o focus a window.")); |
| 58 return promise; | 60 return promise; |
| 59 } | 61 } |
| 60 scriptState->executionContext()->consumeWindowInteraction(); | 62 scriptState->executionContext()->consumeWindowInteraction(); |
| 61 | 63 |
| 62 ServiceWorkerGlobalScopeClient::from(scriptState->executionContext())->focus (uuid(), new CallbackPromiseAdapter<ServiceWorkerWindowClient, ServiceWorkerErro r>(resolver)); | 64 ServiceWorkerGlobalScopeClient::from(scriptState->executionContext())->focus (uuid(), new CallbackPromiseAdapter<ServiceWorkerWindowClient, ServiceWorkerErro r>(resolver)); |
| 63 return promise; | 65 return promise; |
| 64 } | 66 } |
| 65 | 67 |
| 68 ScriptPromise ServiceWorkerWindowClient::navigate(ScriptState* scriptState, cons t String& url) | |
| 69 { | |
| 70 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState); | |
| 71 ScriptPromise promise = resolver->promise(); | |
| 72 // 1. Let url be the result of parsing url with entry settings object's API base URL. | |
| 73 ExecutionContext* context = scriptState->executionContext(); | |
| 74 | |
| 75 // 2. If url is failure, return a promise rejected with a TypeError. | |
| 76 KURL parsedUrl = KURL(toWorkerGlobalScope(context)->location()->url(), url); | |
| 77 if (!parsedUrl.isValid()) { | |
| 78 resolver->reject(DOMException::create(SyntaxError, "'" + url + "' is not a valid URL.")); | |
| 79 return promise; | |
| 80 } | |
| 81 | |
| 82 // 3. If url is about:blank, return a promise rejected with a TypeError. | |
| 83 // TODO | |
|
nhiroki
2015/06/23 01:18:13
Why don't you implement this in this CL?
zino
2015/06/23 03:42:15
Done.
| |
| 84 | |
| 85 // 4. If the context object's associated service worker client's active work er is not the incumbent | |
| 86 // settings object's global object's service worker, return a promise reject ed with a TypeError. | |
|
nhiroki
2015/06/23 01:18:13
We should check this in the browser-side.
zino
2015/06/23 03:42:14
I got it. Could you please review chromium side pa
| |
| 87 // TODO | |
|
nhiroki
2015/06/23 01:18:13
nit: TODO comment should be formatted as "TODO(nam
zino
2015/06/23 03:42:15
It's my mistake. I've just removed all the comment
| |
| 88 | |
| 89 ServiceWorkerGlobalScopeClient::from(context)->navigate(uuid(), parsedUrl, n ew CallbackPromiseAdapter<ServiceWorkerWindowClient, ServiceWorkerError>(resolve r)); | |
| 90 return promise; | |
| 91 } | |
| 92 | |
| 66 DEFINE_TRACE(ServiceWorkerWindowClient) | 93 DEFINE_TRACE(ServiceWorkerWindowClient) |
| 67 { | 94 { |
| 68 ServiceWorkerClient::trace(visitor); | 95 ServiceWorkerClient::trace(visitor); |
| 69 } | 96 } |
| 70 | 97 |
| 71 } // namespace blink | 98 } // namespace blink |
| OLD | NEW |