summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/modules/app_banner/before_install_prompt_event.h
blob: 9c890fb83e8693ce00c9aa4146080e2088b70814 (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// 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 THIRD_PARTY_BLINK_RENDERER_MODULES_APP_BANNER_BEFORE_INSTALL_PROMPT_EVENT_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_APP_BANNER_BEFORE_INSTALL_PROMPT_EVENT_H_

#include <utility>
#include "third_party/blink/public/mojom/app_banner/app_banner.mojom-blink.h"
#include "third_party/blink/renderer/bindings/core/v8/active_script_wrappable.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_property.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_app_banner_prompt_result.h"
#include "third_party/blink/renderer/core/execution_context/execution_context_lifecycle_observer.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/modules/event_modules.h"
#include "third_party/blink/renderer/platform/mojo/heap_mojo_receiver.h"
#include "third_party/blink/renderer/platform/mojo/heap_mojo_remote.h"
#include "third_party/blink/renderer/platform/mojo/heap_mojo_wrapper_mode.h"

namespace blink {

class BeforeInstallPromptEvent;
class BeforeInstallPromptEventInit;
class ExceptionState;

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

class BeforeInstallPromptEvent final
    : public Event,
      public mojom::blink::AppBannerEvent,
      public ActiveScriptWrappable<BeforeInstallPromptEvent>,
      public ExecutionContextClient {
  DEFINE_WRAPPERTYPEINFO();
  USING_GARBAGE_COLLECTED_MIXIN(BeforeInstallPromptEvent);

 public:
  BeforeInstallPromptEvent(const AtomicString& name,
                           LocalFrame&,
                           mojo::PendingRemote<mojom::blink::AppBannerService>,
                           mojo::PendingReceiver<mojom::blink::AppBannerEvent>,
                           const Vector<String>& platforms);
  BeforeInstallPromptEvent(ExecutionContext*,
                           const AtomicString& name,
                           const BeforeInstallPromptEventInit*);
  ~BeforeInstallPromptEvent() override;

  static BeforeInstallPromptEvent* Create(
      const AtomicString& name,
      LocalFrame& frame,
      mojo::PendingRemote<mojom::blink::AppBannerService> service_remote,
      mojo::PendingReceiver<mojom::blink::AppBannerEvent> event_receiver,
      const Vector<String>& platforms) {
    return MakeGarbageCollected<BeforeInstallPromptEvent>(
        name, frame, std::move(service_remote), std::move(event_receiver),
        platforms);
  }

  static BeforeInstallPromptEvent* Create(
      ExecutionContext* execution_context,
      const AtomicString& name,
      const BeforeInstallPromptEventInit* init) {
    return MakeGarbageCollected<BeforeInstallPromptEvent>(execution_context,
                                                          name, init);
  }

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

  const AtomicString& InterfaceName() const override;
  void preventDefault() override;

  // ScriptWrappable
  bool HasPendingActivity() const override;

  void Trace(Visitor*) const override;

 private:
  // mojom::blink::AppBannerEvent methods:
  void BannerAccepted(const String& platform) override;
  void BannerDismissed() override;

  HeapMojoRemote<mojom::blink::AppBannerService,
                 HeapMojoWrapperMode::kWithoutContextObserver>
      banner_service_remote_;
  HeapMojoReceiver<mojom::blink::AppBannerEvent,
                   BeforeInstallPromptEvent,
                   HeapMojoWrapperMode::kWithoutContextObserver>
      receiver_;
  Vector<String> platforms_;
  Member<UserChoiceProperty> user_choice_;
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_MODULES_APP_BANNER_BEFORE_INSTALL_PROMPT_EVENT_H_