| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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_userChoice.isEmpty() && m_client) { |
| 53 ASSERT(m_requestId != -1); | 53 ASSERT(m_requestId != -1); |
| 54 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolv
er::create(scriptState); | 54 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptSt
ate); |
| 55 m_userChoice = resolver->promise(); | 55 m_userChoice = resolver->promise(); |
| 56 m_client->registerBannerCallbacks(m_requestId, new CallbackPromiseAdapte
r<AppBannerPromptResult, void>(resolver)); | 56 m_client->registerBannerCallbacks(m_requestId, new CallbackPromiseAdapte
r<AppBannerPromptResult, void>(resolver)); |
| 57 } | 57 } |
| 58 | 58 |
| 59 return m_userChoice; | 59 return m_userChoice; |
| 60 } | 60 } |
| 61 | 61 |
| 62 const AtomicString& BeforeInstallPromptEvent::interfaceName() const | 62 const AtomicString& BeforeInstallPromptEvent::interfaceName() const |
| 63 { | 63 { |
| 64 return EventNames::BeforeInstallPromptEvent; | 64 return EventNames::BeforeInstallPromptEvent; |
| 65 } | 65 } |
| 66 | 66 |
| 67 ScriptPromise BeforeInstallPromptEvent::prompt(ScriptState* scriptState) | 67 ScriptPromise BeforeInstallPromptEvent::prompt(ScriptState* scriptState) |
| 68 { | 68 { |
| 69 if (m_client && defaultPrevented() && !m_redispatched) { | 69 if (m_client && defaultPrevented() && !m_redispatched) { |
| 70 ASSERT(m_requestId != -1); | 70 ASSERT(m_requestId != -1); |
| 71 m_redispatched = true; | 71 m_redispatched = true; |
| 72 m_client->showAppBanner(m_requestId); | 72 m_client->showAppBanner(m_requestId); |
| 73 return ScriptPromise::cast(scriptState, v8::Undefined(scriptState->isola
te())); | 73 return ScriptPromise::cast(scriptState, v8::Undefined(scriptState->isola
te())); |
| 74 } | 74 } |
| 75 | 75 |
| 76 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::crea
te(InvalidStateError, "The prompt() method may only be called once, following pr
eventDefault().")); | 76 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::crea
te(InvalidStateError, "The prompt() method may only be called once, following pr
eventDefault().")); |
| 77 } | 77 } |
| 78 | 78 |
| 79 } // namespace blink | 79 } // namespace blink |
| OLD | NEW |