-
Notifications
You must be signed in to change notification settings - Fork 15k
/
render_frame_function_store.cc
49 lines (35 loc) · 1.29 KB
/
render_frame_function_store.cc
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
// Copyright (c) 2019 Slack Technologies, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/renderer/api/context_bridge/render_frame_function_store.h"
#include <utility>
#include "shell/common/api/remote/object_life_monitor.h"
namespace electron {
namespace api {
namespace context_bridge {
std::map<int32_t, RenderFrameFunctionStore*>& GetStoreMap() {
static base::NoDestructor<std::map<int32_t, RenderFrameFunctionStore*>>
store_map;
return *store_map;
}
RenderFrameFunctionStore::RenderFrameFunctionStore(
content::RenderFrame* render_frame)
: content::RenderFrameObserver(render_frame),
routing_id_(render_frame->GetRoutingID()) {}
RenderFrameFunctionStore::~RenderFrameFunctionStore() = default;
void RenderFrameFunctionStore::OnDestruct() {
GetStoreMap().erase(routing_id_);
delete this;
}
void RenderFrameFunctionStore::WillReleaseScriptContext(
v8::Local<v8::Context> context,
int32_t world_id) {
base::EraseIf(functions_, [context](auto const& pair) {
v8::Local<v8::Context> func_owning_context =
std::get<1>(pair.second).Get(context->GetIsolate());
return func_owning_context == context;
});
}
} // namespace context_bridge
} // namespace api
} // namespace electron