File: broadcast_channel.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (133 lines) | stat: -rw-r--r-- 5,007 bytes parent folder | download | duplicates (9)
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// Copyright 2016 The Chromium Authors
// 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_BROADCASTCHANNEL_BROADCAST_CHANNEL_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_BROADCASTCHANNEL_BROADCAST_CHANNEL_H_

#include "third_party/blink/public/mojom/broadcastchannel/broadcast_channel.mojom-blink.h"
#include "third_party/blink/renderer/bindings/core/v8/active_script_wrappable.h"
#include "third_party/blink/renderer/core/dom/events/event_target.h"
#include "third_party/blink/renderer/core/execution_context/execution_context_lifecycle_observer.h"
#include "third_party/blink/renderer/modules/modules_export.h"
#include "third_party/blink/renderer/platform/heap/prefinalizer.h"
#include "third_party/blink/renderer/platform/mojo/heap_mojo_associated_receiver.h"
#include "third_party/blink/renderer/platform/mojo/heap_mojo_associated_remote.h"
#include "third_party/blink/renderer/platform/scheduler/public/frame_or_worker_scheduler.h"

namespace blink {

class BroadcastChannelTester;
class ScriptValue;
class StorageAccessHandle;

class MODULES_EXPORT BroadcastChannel final
    : public EventTarget,
      public ActiveScriptWrappable<BroadcastChannel>,
      public ExecutionContextLifecycleObserver,
      public mojom::blink::BroadcastChannelClient {
  DEFINE_WRAPPERTYPEINFO();
  USING_PRE_FINALIZER(BroadcastChannel, Dispose);

 public:
  static BroadcastChannel* Create(ExecutionContext*,
                                  const String& name,
                                  ExceptionState&);

  BroadcastChannel(ExecutionContext*, const String& name);
  BroadcastChannel(base::PassKey<StorageAccessHandle>,
                   ExecutionContext* execution_context,
                   const String& name,
                   mojom::blink::BroadcastChannelProvider* provider);
  BroadcastChannel(
      base::PassKey<BroadcastChannelTester>,
      ExecutionContext*,
      const String& name,
      mojo::PendingAssociatedReceiver<mojom::blink::BroadcastChannelClient>
          receiver,
      mojo::PendingAssociatedRemote<mojom::blink::BroadcastChannelClient>
          remote);

  BroadcastChannel(const BroadcastChannel&) = delete;
  BroadcastChannel& operator=(const BroadcastChannel&) = delete;

  ~BroadcastChannel() override;
  void Dispose();

  // IDL
  String name() const { return name_; }
  void postMessage(const ScriptValue&, ExceptionState&);
  void close();
  DEFINE_ATTRIBUTE_EVENT_LISTENER(message, kMessage)
  DEFINE_ATTRIBUTE_EVENT_LISTENER(messageerror, kMessageerror)

  // EventTarget:
  const AtomicString& InterfaceName() const override;
  ExecutionContext* GetExecutionContext() const override {
    return ExecutionContextLifecycleObserver::GetExecutionContext();
  }

  // ScriptWrappable:
  bool HasPendingActivity() const override;

  // ExecutionContextLifecycleObserver:
  void ContextDestroyed() override;

  void Trace(Visitor*) const override;

  bool IsRemoteClientConnectedForTesting() const;

 private:
  BroadcastChannel(
      ExecutionContext*,
      const String& name,
      mojo::PendingAssociatedReceiver<mojom::blink::BroadcastChannelClient>
          receiver,
      mojo::PendingAssociatedRemote<mojom::blink::BroadcastChannelClient>
          remote);

  void SetupDisconnectHandlers();

  void PostMessageInternal(
      scoped_refptr<SerializedScriptValue> value,
      scoped_refptr<SecurityOrigin> sender_origin,
      const base::UnguessableToken sender_agent_cluster_id);

  // mojom::blink::BroadcastChannelClient:
  void OnMessage(BlinkCloneableMessage) override;

  // Called when the mojo binding disconnects.
  void OnError();

  // Close the mojo receivers and remotes.
  void CloseInternal();

  String name_;

  // Tracks whether this BroadcastChannel object has had close.
  bool explicitly_closed_ = false;

  // BroadcastChannelClient receiver for messages sent from the browser to
  // this channel and BroadcastChannelClient remote for messages sent from
  // this channel to the browser.
  HeapMojoAssociatedReceiver<mojom::blink::BroadcastChannelClient,
                             BroadcastChannel>
      receiver_;
  HeapMojoAssociatedRemote<mojom::blink::BroadcastChannelClient> remote_client_;

  // Notifies the scheduler that a broadcast channel is active.
  FrameOrWorkerScheduler::SchedulingAffectingFeatureHandle
      feature_handle_for_scheduler_;

  // When a BroadcastChannel is instantiated from a frame execution context,
  // `associated_remote_` holds the AssociatedRemote used to send
  // ConnectToChannel messages (with ordering preserved) to the
  // RenderFrameHostImpl associated with this frame. When a BroadcastChannel is
  // instantiated from a worker execution context, this member is not used.
  HeapMojoAssociatedRemote<mojom::blink::BroadcastChannelProvider>
      associated_remote_;
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_MODULES_BROADCASTCHANNEL_BROADCAST_CHANNEL_H_