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
|
// Copyright 2019 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_REMOTE_OBJECTS_REMOTE_OBJECT_GATEWAY_IMPL_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_REMOTE_OBJECTS_REMOTE_OBJECT_GATEWAY_IMPL_H_
#include "base/types/pass_key.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "third_party/blink/public/mojom/remote_objects/remote_objects.mojom-blink.h"
#include "third_party/blink/renderer/modules/modules_export.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/heap/persistent.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"
#include "third_party/blink/renderer/platform/supplementable.h"
namespace blink {
class LocalFrame;
class RemoteObject;
class MODULES_EXPORT RemoteObjectGatewayImpl
: public GarbageCollected<RemoteObjectGatewayImpl>,
public Supplement<LocalFrame>,
public mojom::blink::RemoteObjectGateway {
public:
static const char kSupplementName[];
RemoteObjectGatewayImpl(
base::PassKey<RemoteObjectGatewayImpl>,
LocalFrame&,
mojo::PendingReceiver<mojom::blink::RemoteObjectGateway>,
mojo::PendingRemote<mojom::blink::RemoteObjectHost>);
// Not copyable or movable
RemoteObjectGatewayImpl(const RemoteObjectGatewayImpl&) = delete;
RemoteObjectGatewayImpl& operator=(const RemoteObjectGatewayImpl&) = delete;
~RemoteObjectGatewayImpl() override = default;
static void BindMojoReceiver(
LocalFrame*,
mojo::PendingRemote<mojom::blink::RemoteObjectHost>,
mojo::PendingReceiver<mojom::blink::RemoteObjectGateway>);
// This supplement is only installed if the RemoteObjectGateway mojom
// interface is requested to be bound (currently only for Android WebView).
static RemoteObjectGatewayImpl* From(LocalFrame&);
void OnClearWindowObjectInMainWorld();
void Trace(Visitor* visitor) const override;
void BindRemoteObjectReceiver(
int32_t object_id,
mojo::PendingReceiver<mojom::blink::RemoteObject>);
void ReleaseObject(int32_t object_id, RemoteObject* remote_object);
RemoteObject* GetRemoteObject(v8::Isolate* isolate, int32_t object_id);
private:
// mojom::blink::RemoteObjectGateway
void AddNamedObject(const WTF::String& name, int32_t id) override;
void RemoveNamedObject(const WTF::String& name) override;
void InjectNamed(const WTF::String& object_name, int32_t object_id);
HashMap<String, int32_t> named_objects_;
HashMap<int32_t, RemoteObject*, IntWithZeroKeyHashTraits<int32_t>>
remote_objects_;
HeapMojoReceiver<mojom::blink::RemoteObjectGateway,
RemoteObjectGatewayImpl,
HeapMojoWrapperMode::kForceWithoutContextObserver>
receiver_;
HeapMojoRemote<mojom::blink::RemoteObjectHost,
HeapMojoWrapperMode::kForceWithoutContextObserver>
object_host_;
};
class RemoteObjectGatewayFactoryImpl
: public GarbageCollected<RemoteObjectGatewayFactoryImpl>,
public mojom::blink::RemoteObjectGatewayFactory,
public Supplement<LocalFrame> {
public:
static const char kSupplementName[];
explicit RemoteObjectGatewayFactoryImpl(
base::PassKey<RemoteObjectGatewayFactoryImpl>,
LocalFrame& frame,
mojo::PendingReceiver<mojom::blink::RemoteObjectGatewayFactory> receiver);
// This supplement is only installed if the RemoteObjectGatewayFactory mojom
// interface is requested to be bound (currently only for Android WebView).
static RemoteObjectGatewayFactoryImpl* From(LocalFrame&);
static void Bind(
LocalFrame* frame,
mojo::PendingReceiver<mojom::blink::RemoteObjectGatewayFactory> receiver);
void Trace(Visitor* visitor) const override;
private:
// Not copyable or movable
RemoteObjectGatewayFactoryImpl(const RemoteObjectGatewayFactoryImpl&) =
delete;
RemoteObjectGatewayFactoryImpl& operator=(
const RemoteObjectGatewayFactoryImpl&) = delete;
// mojom::blink::RemoteObjectGatewayFactory
void CreateRemoteObjectGateway(
mojo::PendingRemote<mojom::blink::RemoteObjectHost> host,
mojo::PendingReceiver<mojom::blink::RemoteObjectGateway> receiver)
override;
HeapMojoReceiver<mojom::blink::RemoteObjectGatewayFactory,
RemoteObjectGatewayFactoryImpl,
HeapMojoWrapperMode::kForceWithoutContextObserver>
receiver_;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_REMOTE_OBJECTS_REMOTE_OBJECT_GATEWAY_IMPL_H_
|