OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/app_banner/BeforeInstallPromptEvent.h" | 6 #include "modules/app_banner/BeforeInstallPromptEvent.h" |
7 | 7 |
8 #include "bindings/core/v8/CallbackPromiseAdapter.h" | 8 #include "bindings/core/v8/CallbackPromiseAdapter.h" |
9 #include "bindings/core/v8/ScriptPromise.h" | 9 #include "bindings/core/v8/ScriptPromise.h" |
10 #include "bindings/core/v8/ScriptPromiseResolver.h" | 10 #include "bindings/core/v8/ScriptPromiseResolver.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 { | 42 { |
43 } | 43 } |
44 | 44 |
45 Vector<String> BeforeInstallPromptEvent::platforms() const | 45 Vector<String> BeforeInstallPromptEvent::platforms() const |
46 { | 46 { |
47 return m_platforms; | 47 return m_platforms; |
48 } | 48 } |
49 | 49 |
50 ScriptPromise BeforeInstallPromptEvent::userChoice(ScriptState* scriptState) | 50 ScriptPromise BeforeInstallPromptEvent::userChoice(ScriptState* scriptState) |
51 { | 51 { |
52 if (m_userChoice.isEmpty() && m_client) { | 52 if (!m_resolver) { |
53 ASSERT(m_requestId != -1); | 53 m_resolver = ScriptPromiseResolver::create(scriptState); |
54 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolv
er::create(scriptState); | 54 if (m_client) { |
55 m_userChoice = resolver->promise(); | 55 ASSERT(m_requestId != -1); |
56 m_client->registerBannerCallbacks(m_requestId, new CallbackPromiseAdapte
r<AppBannerPromptResult, void>(resolver)); | 56 m_client->registerBannerCallbacks(m_requestId, new CallbackPromiseAd
apter<AppBannerPromptResult, void>(m_resolver)); |
| 57 } |
57 } | 58 } |
58 | 59 |
59 return m_userChoice; | 60 return m_resolver->promise(); |
60 } | 61 } |
61 | 62 |
62 const AtomicString& BeforeInstallPromptEvent::interfaceName() const | 63 const AtomicString& BeforeInstallPromptEvent::interfaceName() const |
63 { | 64 { |
64 return EventNames::BeforeInstallPromptEvent; | 65 return EventNames::BeforeInstallPromptEvent; |
65 } | 66 } |
66 | 67 |
67 ScriptPromise BeforeInstallPromptEvent::prompt(ScriptState* scriptState) | 68 ScriptPromise BeforeInstallPromptEvent::prompt(ScriptState* scriptState) |
68 { | 69 { |
69 if (m_client && defaultPrevented() && !m_redispatched) { | 70 if (m_client && defaultPrevented() && !m_redispatched) { |
70 ASSERT(m_requestId != -1); | 71 ASSERT(m_requestId != -1); |
71 m_redispatched = true; | 72 m_redispatched = true; |
72 m_client->showAppBanner(m_requestId); | 73 m_client->showAppBanner(m_requestId); |
73 return ScriptPromise::cast(scriptState, v8::Undefined(scriptState->isola
te())); | 74 return ScriptPromise::cast(scriptState, v8::Undefined(scriptState->isola
te())); |
74 } | 75 } |
75 | 76 |
76 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::crea
te(InvalidStateError, "The prompt() method may only be called once, following pr
eventDefault().")); | 77 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::crea
te(InvalidStateError, "The prompt() method may only be called once, following pr
eventDefault().")); |
77 } | 78 } |
78 | 79 |
79 } // namespace blink | 80 } // namespace blink |
OLD | NEW |