Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(219)

Side by Side Diff: Source/modules/app_banner/BeforeInstallPromptEvent.cpp

Issue 1160413004: Add hooks for BeforeInstallPromptEvent to be redispatched. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Making prompt() return a promise Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 ScriptPromise BeforeInstallPromptEvent::prompt(ScriptState* scriptState)
65 {
66 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState);
67 ScriptPromise promise = resolver->promise();
mlamouri (slow - plz ping) 2015/06/11 00:42:17 You probably don't need a |resolver| or a |promise
68 if (m_client && defaultPrevented() && !m_redispatched) {
69 ASSERT(m_requestId != -1);
70 m_redispatched = true;
71 m_client->resolveEventRedispatch(m_requestId);
72 resolver->resolve();
73 userChoice(scriptState);
mlamouri (slow - plz ping) 2015/06/11 00:42:17 Why do you call that?
74 } else {
75 resolver->reject();
mlamouri (slow - plz ping) 2015/06/11 00:42:17 I think you should reject with an InvalidState err
76 }
77 return promise;
78 }
79
62 } // namespace blink 80 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698