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

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: 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/ScriptPromise.h"
9 #include "bindings/core/v8/ScriptPromiseResolver.h" 10 #include "bindings/core/v8/ScriptPromiseResolver.h"
11 #include "core/dom/DOMException.h"
12 #include "core/dom/ExceptionCode.h"
10 #include "modules/app_banner/AppBannerPromptResult.h" 13 #include "modules/app_banner/AppBannerPromptResult.h"
11 #include "modules/app_banner/BeforeInstallPromptEventInit.h" 14 #include "modules/app_banner/BeforeInstallPromptEventInit.h"
12 #include "public/platform/modules/app_banner/WebAppBannerClient.h" 15 #include "public/platform/modules/app_banner/WebAppBannerClient.h"
13 16
14 namespace blink { 17 namespace blink {
15 18
16 BeforeInstallPromptEvent::BeforeInstallPromptEvent() 19 BeforeInstallPromptEvent::BeforeInstallPromptEvent()
17 { 20 {
18 } 21 }
19 22
20 BeforeInstallPromptEvent::BeforeInstallPromptEvent(const AtomicString& name, con st Vector<String>& platforms, int requestId, WebAppBannerClient* client) 23 BeforeInstallPromptEvent::BeforeInstallPromptEvent(const AtomicString& name, con st Vector<String>& platforms, int requestId, WebAppBannerClient* client)
21 : Event(name, false, true) 24 : Event(name, false, true)
22 , m_platforms(platforms) 25 , m_platforms(platforms)
23 , m_requestId(requestId) 26 , m_requestId(requestId)
24 , m_client(client) 27 , m_client(client)
28 , m_redispatched(false)
25 { 29 {
26 } 30 }
27 31
28 BeforeInstallPromptEvent::BeforeInstallPromptEvent(const AtomicString& name, con st BeforeInstallPromptEventInit& init) 32 BeforeInstallPromptEvent::BeforeInstallPromptEvent(const AtomicString& name, con st BeforeInstallPromptEventInit& init)
29 : Event(name, false, true) 33 : Event(name, false, true)
30 , m_platforms(init.platforms()) 34 , m_platforms(init.platforms())
31 , m_requestId(-1) 35 , m_requestId(-1)
32 , m_client(nullptr) 36 , m_client(nullptr)
37 , m_redispatched(false)
33 { 38 {
34 } 39 }
35 40
36 BeforeInstallPromptEvent::~BeforeInstallPromptEvent() 41 BeforeInstallPromptEvent::~BeforeInstallPromptEvent()
37 { 42 {
38 } 43 }
39 44
40 Vector<String> BeforeInstallPromptEvent::platforms() const 45 Vector<String> BeforeInstallPromptEvent::platforms() const
41 { 46 {
42 return m_platforms; 47 return m_platforms;
43 } 48 }
44 49
45 ScriptPromise BeforeInstallPromptEvent::userChoice(ScriptState* scriptState) 50 ScriptPromise BeforeInstallPromptEvent::userChoice(ScriptState* scriptState)
46 { 51 {
47 if (m_userChoice.isEmpty() && m_client) { 52 if (m_userChoice.isEmpty() && m_client) {
48 ASSERT(m_requestId != -1); 53 ASSERT(m_requestId != -1);
49 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolv er::create(scriptState); 54 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolv er::create(scriptState);
50 m_userChoice = resolver->promise(); 55 m_userChoice = resolver->promise();
51 m_client->registerBannerCallbacks(m_requestId, new CallbackPromiseAdapte r<AppBannerPromptResult, void>(resolver)); 56 m_client->registerBannerCallbacks(m_requestId, new CallbackPromiseAdapte r<AppBannerPromptResult, void>(resolver));
52 } 57 }
53 58
54 return m_userChoice; 59 return m_userChoice;
55 } 60 }
56 61
57 const AtomicString& BeforeInstallPromptEvent::interfaceName() const 62 const AtomicString& BeforeInstallPromptEvent::interfaceName() const
58 { 63 {
59 return EventNames::BeforeInstallPromptEvent; 64 return EventNames::BeforeInstallPromptEvent;
60 } 65 }
61 66
67 ScriptPromise BeforeInstallPromptEvent::prompt(ScriptState* scriptState)
68 {
69 if (m_client && defaultPrevented() && !m_redispatched) {
70 ASSERT(m_requestId != -1);
71 m_redispatched = true;
72 m_client->showAppBanner(m_requestId);
73 return ScriptPromise::cast(scriptState, v8::Undefined(scriptState->isola te()));
74 }
75
76 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::crea te(InvalidStateError, "The prompt() method may only be called once, following pr eventDefault()."));
77 }
78
62 } // namespace blink 79 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/app_banner/BeforeInstallPromptEvent.h ('k') | Source/modules/app_banner/BeforeInstallPromptEvent.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698