Chromium Code Reviews| 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/ScriptPromiseResolver.h" | 9 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 10 #include "modules/app_banner/AppBannerPromptResult.h" | 10 #include "modules/app_banner/AppBannerPromptResult.h" |
| 11 #include "modules/app_banner/BeforeInstallPromptEventInit.h" | 11 #include "modules/app_banner/BeforeInstallPromptEventInit.h" |
| 12 #include "public/platform/modules/app_banner/WebAppBannerClient.h" | 12 #include "public/platform/modules/app_banner/WebAppBannerClient.h" |
| 13 | 13 |
| 14 namespace blink { | 14 namespace blink { |
| 15 | 15 |
| 16 BeforeInstallPromptEvent::BeforeInstallPromptEvent() | 16 BeforeInstallPromptEvent::BeforeInstallPromptEvent() |
| 17 { | 17 { |
| 18 } | 18 } |
| 19 | 19 |
| 20 BeforeInstallPromptEvent::BeforeInstallPromptEvent(const AtomicString& name, con st Vector<String>& platforms, int requestId, WebAppBannerClient* client) | 20 BeforeInstallPromptEvent::BeforeInstallPromptEvent(const AtomicString& name, con st Vector<String>& platforms, int requestId, WebAppBannerClient* client) |
| 21 : Event(name, false, true) | 21 : Event(name, false, true) |
| 22 , m_platforms(platforms) | 22 , m_platforms(platforms) |
| 23 , m_requestId(requestId) | 23 , m_requestId(requestId) |
| 24 , m_client(client) | 24 , m_client(client) |
| 25 , m_redispatched(false) | |
| 25 { | 26 { |
| 26 } | 27 } |
| 27 | 28 |
| 28 BeforeInstallPromptEvent::BeforeInstallPromptEvent(const AtomicString& name, con st BeforeInstallPromptEventInit& init) | 29 BeforeInstallPromptEvent::BeforeInstallPromptEvent(const AtomicString& name, con st BeforeInstallPromptEventInit& init) |
| 29 : Event(name, false, true) | 30 : Event(name, false, true) |
| 30 , m_platforms(init.platforms()) | 31 , m_platforms(init.platforms()) |
| 31 , m_requestId(-1) | 32 , m_requestId(-1) |
| 32 , m_client(nullptr) | 33 , m_client(nullptr) |
| 34 , m_redispatched(false) | |
| 33 { | 35 { |
| 34 } | 36 } |
| 35 | 37 |
| 36 BeforeInstallPromptEvent::~BeforeInstallPromptEvent() | 38 BeforeInstallPromptEvent::~BeforeInstallPromptEvent() |
| 37 { | 39 { |
| 38 } | 40 } |
| 39 | 41 |
| 40 Vector<String> BeforeInstallPromptEvent::platforms() const | 42 Vector<String> BeforeInstallPromptEvent::platforms() const |
| 41 { | 43 { |
| 42 return m_platforms; | 44 return m_platforms; |
| 43 } | 45 } |
| 44 | 46 |
| 45 ScriptPromise BeforeInstallPromptEvent::userChoice(ScriptState* scriptState) | 47 ScriptPromise BeforeInstallPromptEvent::userChoice(ScriptState* scriptState) |
| 46 { | 48 { |
| 47 if (m_userChoice.isEmpty() && m_client) { | 49 if (m_userChoice.isEmpty() && m_client) { |
| 48 ASSERT(m_requestId != -1); | 50 ASSERT(m_requestId != -1); |
| 49 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolv er::create(scriptState); | 51 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolv er::create(scriptState); |
| 50 m_userChoice = resolver->promise(); | 52 m_userChoice = resolver->promise(); |
| 51 m_client->registerBannerCallbacks(m_requestId, new CallbackPromiseAdapte r<AppBannerPromptResult, void>(resolver)); | 53 m_client->registerBannerCallbacks(m_requestId, new CallbackPromiseAdapte r<AppBannerPromptResult, void>(resolver)); |
| 52 } | 54 } |
| 53 | 55 |
| 54 return m_userChoice; | 56 return m_userChoice; |
| 55 } | 57 } |
| 56 | 58 |
| 57 const AtomicString& BeforeInstallPromptEvent::interfaceName() const | 59 const AtomicString& BeforeInstallPromptEvent::interfaceName() const |
| 58 { | 60 { |
| 59 return EventNames::BeforeInstallPromptEvent; | 61 return EventNames::BeforeInstallPromptEvent; |
| 60 } | 62 } |
| 61 | 63 |
| 64 void BeforeInstallPromptEvent::prompt() | |
| 65 { | |
| 66 // This will silently fail if preventDefault() has not previously been | |
| 67 // called (the event cannot be redispatched if it has not been stopped). | |
| 68 // It will also silently fail if the event has already been redispatched. | |
|
mlamouri (slow - plz ping)
2015/06/06 21:40:55
Why silently failing? Why not having prompt() retu
| |
| 69 if (m_client && defaultPrevented() && !m_redispatched) { | |
| 70 ASSERT(m_requestId != -1); | |
| 71 m_redispatched = true; | |
| 72 m_client->resolveEventRedispatch(m_requestId); | |
| 73 } | |
| 74 } | |
| 75 | |
| 62 } // namespace blink | 76 } // namespace blink |
| OLD | NEW |