fix: disable contextBridge object identity caching (#21803)
* fix: disable contextBridge object identity caching * cleanup * chore: make non-const references raw pointers * fix: zero-param constructors are not explicit * refactor: use base::LinkedList Co-authored-by: Jeremy Apthorp <nornagon@nornagon.net>
This commit is contained in:
parent
a53a2aaa45
commit
2563681583
10 changed files with 266 additions and 453 deletions
53
shell/renderer/api/context_bridge/object_cache.h
Normal file
53
shell/renderer/api/context_bridge/object_cache.h
Normal file
|
@ -0,0 +1,53 @@
|
|||
// Copyright (c) 2020 Slack Technologies, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef SHELL_RENDERER_API_CONTEXT_BRIDGE_OBJECT_CACHE_H_
|
||||
#define SHELL_RENDERER_API_CONTEXT_BRIDGE_OBJECT_CACHE_H_
|
||||
|
||||
#include <map>
|
||||
#include <utility>
|
||||
|
||||
#include "base/containers/linked_list.h"
|
||||
#include "content/public/renderer/render_frame.h"
|
||||
#include "content/public/renderer/render_frame_observer.h"
|
||||
#include "shell/renderer/electron_render_frame_observer.h"
|
||||
#include "third_party/blink/public/web/web_local_frame.h"
|
||||
|
||||
namespace electron {
|
||||
|
||||
namespace api {
|
||||
|
||||
namespace context_bridge {
|
||||
|
||||
using ObjectCachePair = std::pair<v8::Local<v8::Value>, v8::Local<v8::Value>>;
|
||||
|
||||
struct ObjectCachePairNode : public base::LinkNode<ObjectCachePairNode> {
|
||||
explicit ObjectCachePairNode(ObjectCachePair&& pair);
|
||||
~ObjectCachePairNode();
|
||||
|
||||
ObjectCachePair pair;
|
||||
};
|
||||
|
||||
class ObjectCache final {
|
||||
public:
|
||||
ObjectCache();
|
||||
~ObjectCache();
|
||||
|
||||
void CacheProxiedObject(v8::Local<v8::Value> from,
|
||||
v8::Local<v8::Value> proxy_value);
|
||||
v8::MaybeLocal<v8::Value> GetCachedProxiedObject(
|
||||
v8::Local<v8::Value> from) const;
|
||||
|
||||
private:
|
||||
// object_identity ==> [from_value, proxy_value]
|
||||
std::map<int, base::LinkedList<ObjectCachePairNode>> proxy_map_;
|
||||
};
|
||||
|
||||
} // namespace context_bridge
|
||||
|
||||
} // namespace api
|
||||
|
||||
} // namespace electron
|
||||
|
||||
#endif // SHELL_RENDERER_API_CONTEXT_BRIDGE_OBJECT_CACHE_H_
|
Loading…
Add table
Add a link
Reference in a new issue