OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/NavigationPreloadManager.h" | 5 #include "modules/serviceworkers/NavigationPreloadManager.h" |
6 | 6 |
| 7 #include "core/dom/DOMException.h" |
7 #include "modules/serviceworkers/NavigationPreloadCallbacks.h" | 8 #include "modules/serviceworkers/NavigationPreloadCallbacks.h" |
| 9 #include "modules/serviceworkers/ServiceWorkerContainerClient.h" |
8 #include "modules/serviceworkers/ServiceWorkerRegistration.h" | 10 #include "modules/serviceworkers/ServiceWorkerRegistration.h" |
9 | 11 |
10 namespace blink { | 12 namespace blink { |
11 | 13 |
12 ScriptPromise NavigationPreloadManager::enable(ScriptState* scriptState) { | 14 ScriptPromise NavigationPreloadManager::enable(ScriptState* scriptState) { |
13 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 15 return setEnabled(true, scriptState); |
14 ScriptPromise promise = resolver->promise(); | |
15 m_registration->webRegistration()->enableNavigationPreload( | |
16 new EnableNavigationPreloadCallbacks(resolver)); | |
17 return promise; | |
18 } | 16 } |
19 | 17 |
20 ScriptPromise NavigationPreloadManager::disable(ScriptState* scriptState) { | 18 ScriptPromise NavigationPreloadManager::disable(ScriptState* scriptState) { |
21 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 19 return setEnabled(false, scriptState); |
22 ScriptPromise promise = resolver->promise(); | |
23 m_registration->webRegistration()->disableNavigationPreload( | |
24 new DisableNavigationPreloadCallbacks(resolver)); | |
25 return promise; | |
26 } | 20 } |
27 | 21 |
28 ScriptPromise NavigationPreloadManager::setHeaderValue(ScriptState*, | 22 ScriptPromise NavigationPreloadManager::setHeaderValue(ScriptState*, |
29 const String& value) { | 23 const String& value) { |
30 NOTIMPLEMENTED(); | 24 NOTIMPLEMENTED(); |
31 return ScriptPromise(); | 25 return ScriptPromise(); |
32 } | 26 } |
33 | 27 |
34 ScriptPromise NavigationPreloadManager::getState(ScriptState*) { | 28 ScriptPromise NavigationPreloadManager::getState(ScriptState*) { |
35 NOTIMPLEMENTED(); | 29 NOTIMPLEMENTED(); |
36 return ScriptPromise(); | 30 return ScriptPromise(); |
37 } | 31 } |
38 | 32 |
39 NavigationPreloadManager::NavigationPreloadManager( | 33 NavigationPreloadManager::NavigationPreloadManager( |
40 ServiceWorkerRegistration* registration) | 34 ServiceWorkerRegistration* registration) |
41 : m_registration(registration) {} | 35 : m_registration(registration) {} |
42 | 36 |
| 37 ScriptPromise NavigationPreloadManager::setEnabled(bool enable, |
| 38 ScriptState* scriptState) { |
| 39 ServiceWorkerContainerClient* client = |
| 40 ServiceWorkerContainerClient::from(m_registration->getExecutionContext()); |
| 41 if (!client || !client->provider()) { |
| 42 return ScriptPromise::rejectWithDOMException( |
| 43 scriptState, DOMException::create(InvalidStateError, "No provider.")); |
| 44 } |
| 45 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| 46 ScriptPromise promise = resolver->promise(); |
| 47 m_registration->webRegistration()->enableNavigationPreload( |
| 48 enable, client->provider(), |
| 49 wrapUnique(new EnableNavigationPreloadCallbacks(resolver))); |
| 50 return promise; |
| 51 } |
| 52 |
43 DEFINE_TRACE(NavigationPreloadManager) { | 53 DEFINE_TRACE(NavigationPreloadManager) { |
44 visitor->trace(m_registration); | 54 visitor->trace(m_registration); |
45 } | 55 } |
46 | 56 |
47 } // namespace blink | 57 } // namespace blink |
OLD | NEW |