summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/Source/modules/app_banner/BeforeInstallPromptEvent.h
blob: 9da892fd7490e441fd65f6cd15390d3b1de96de3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef BeforeInstallPromptEvent_h
#define BeforeInstallPromptEvent_h

#include "bindings/core/v8/ScriptPromise.h"
#include "bindings/core/v8/ScriptPromiseProperty.h"
#include "modules/EventModules.h"
#include "modules/app_banner/AppBannerPromptResult.h"
#include "platform/heap/Handle.h"

namespace blink {

class BeforeInstallPromptEvent;
class BeforeInstallPromptEventInit;
class WebAppBannerClient;

using UserChoiceProperty = ScriptPromiseProperty<RawPtrWillBeMember<BeforeInstallPromptEvent>, Member<AppBannerPromptResult>, ToV8UndefinedGenerator>;

class BeforeInstallPromptEvent final : public Event {
    DEFINE_WRAPPERTYPEINFO();
public:
    ~BeforeInstallPromptEvent() override;

    // For EventModules.cpp
    static PassRefPtrWillBeRawPtr<BeforeInstallPromptEvent> create()
    {
        return adoptRefWillBeNoop(new BeforeInstallPromptEvent());
    }

    static PassRefPtrWillBeRawPtr<BeforeInstallPromptEvent> create(const AtomicString& name, ExecutionContext* executionContext, const Vector<String>& platforms, int requestId, WebAppBannerClient* client)
    {
        return adoptRefWillBeNoop(new BeforeInstallPromptEvent(name, executionContext, platforms, requestId, client));
    }

    static PassRefPtrWillBeRawPtr<BeforeInstallPromptEvent> create(const AtomicString& name, const BeforeInstallPromptEventInit& init)
    {
        return adoptRefWillBeNoop(new BeforeInstallPromptEvent(name, init));
    }

    Vector<String> platforms() const;
    ScriptPromise userChoice(ScriptState*);
    ScriptPromise prompt(ScriptState*);

    const AtomicString& interfaceName() const override;

    DECLARE_VIRTUAL_TRACE();

private:
    BeforeInstallPromptEvent();
    BeforeInstallPromptEvent(const AtomicString& name, ExecutionContext*, const Vector<String>& platforms, int requestId, WebAppBannerClient*);
    BeforeInstallPromptEvent(const AtomicString& name, const BeforeInstallPromptEventInit&);

    Vector<String> m_platforms;

    int m_requestId;
    WebAppBannerClient* m_client;
    PersistentWillBeMember<UserChoiceProperty> m_userChoice;
    bool m_registered;
};

DEFINE_TYPE_CASTS(BeforeInstallPromptEvent, Event, event, event->interfaceName() == EventNames::BeforeInstallPromptEvent, event.interfaceName() == EventNames::BeforeInstallPromptEvent);

} // namespace blink

#endif // BeforeInstallPromptEvent_h