mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
* feat: add a new contextBridge module (#20307)
* feat: add a new contextBridge module
* chore: fix docs linting
* feat: add support for function arguments being proxied
* chore: ensure that contextBridge can only be used when contextIsolation is enabled
* docs: getReverseBinding can be null
* docs: fix broken links in md file
* feat: add support for promises in function parameters
* fix: linting failure for explicit constructor
* Update atom_api_context_bridge.cc
* chore: update docs and API design as per feedback
* refactor: remove reverse bindings and handle GC'able functions across the bridge
* chore: only expose debugGC in testing builds
* fix: do not proxy promises as objects
* spec: add complete spec coverage for contextBridge
* spec: add tests for null/undefined and the anti-overwrite logic
* chore: fix linting
* spec: add complex nested back-and-forth function calling
* fix: expose contextBridge in sandboxed renderers
* refactor: improve security of default_app using the new contextBridge module
* s/bindAPIInMainWorld/exposeInMainWorld
* chore: sorry for this commit, its a big one, I fixed like everything and refactored a lot
* chore: remove PassedValueCache as it is unused now
Values transferred from context A to context B are now cachde in the RenderFramePersistenceStore
* chore: move to anonymous namespace
* refactor: remove PassValueToOtherContextWithCache
* chore: remove commented unused code blocks
* chore: remove .only
* chore: remote commented code
* refactor: extract RenderFramePersistenceStore
* spec: ensure it works with numbered keys
* fix: handle number keys correctly
* fix: sort out the linter
* spec: update default_app asar spec for removed file
* refactor: change signatures to return v8 objects directly rather than the mate dictionary handle
* refactor: use the v8 serializer to support cloneable buffers and other object types
* chore: fix linting
* fix: handle hash collisions with a linked list in the map
* fix: enforce a recursion limit on the context bridge
* chore: fix linting
* chore: remove TODO
* chore: adapt for PR feedback
* chore: remove .only
* chore: clean up docs and clean up the proxy map when objects are released
* chore: ensure we cache object values that are cloned through the V8 serializer
* docs: mark contextBridge as experimental (#20638)
* docs: mark contextBridge as experimental
This commit didn't make it to the original PR, quick addition here
* Update context-bridge.md
* chore: update for 7-0-x differences
* chore: update callback header
* chore: add v8 serializer converter, cherry picked from 2fad53e66b
* chore: update for 7-0-x differences
107 lines
2.8 KiB
C++
107 lines
2.8 KiB
C++
// Copyright 2013 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.chromium file.
|
|
|
|
#ifndef NATIVE_MATE_NATIVE_MATE_ARGUMENTS_H_
|
|
#define NATIVE_MATE_NATIVE_MATE_ARGUMENTS_H_
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "base/macros.h"
|
|
#include "base/optional.h"
|
|
#include "native_mate/converter.h"
|
|
|
|
namespace mate {
|
|
|
|
// Arguments is a wrapper around v8::FunctionCallbackInfo that integrates
|
|
// with Converter to make it easier to marshall arguments and return values
|
|
// between V8 and C++.
|
|
class Arguments {
|
|
public:
|
|
Arguments();
|
|
explicit Arguments(const v8::FunctionCallbackInfo<v8::Value>& info);
|
|
~Arguments();
|
|
|
|
v8::Local<v8::Object> GetHolder() const { return info_->Holder(); }
|
|
|
|
template <typename T>
|
|
bool GetHolder(T* out) {
|
|
return mate::ConvertFromV8(isolate_, info_->Holder(), out);
|
|
}
|
|
|
|
template <typename T>
|
|
bool GetData(T* out) {
|
|
return ConvertFromV8(isolate_, info_->Data(), out);
|
|
}
|
|
|
|
template <typename T>
|
|
bool GetNext(base::Optional<T>* out) {
|
|
if (next_ >= info_->Length())
|
|
return true;
|
|
v8::Local<v8::Value> val = (*info_)[next_];
|
|
bool success = ConvertFromV8(isolate_, val, out);
|
|
if (success)
|
|
next_++;
|
|
return success;
|
|
}
|
|
|
|
template <typename T>
|
|
bool GetNext(T* out) {
|
|
if (next_ >= info_->Length()) {
|
|
insufficient_arguments_ = true;
|
|
return false;
|
|
}
|
|
v8::Local<v8::Value> val = (*info_)[next_];
|
|
bool success = mate::ConvertFromV8(isolate_, val, out);
|
|
if (success)
|
|
next_++;
|
|
return success;
|
|
}
|
|
|
|
template <typename T>
|
|
bool GetRemaining(std::vector<T>* out) {
|
|
if (next_ >= info_->Length()) {
|
|
insufficient_arguments_ = true;
|
|
return false;
|
|
}
|
|
int remaining = info_->Length() - next_;
|
|
out->resize(remaining);
|
|
for (int i = 0; i < remaining; ++i) {
|
|
v8::Local<v8::Value> val = (*info_)[next_++];
|
|
if (!ConvertFromV8(isolate_, val, &out->at(i)))
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
v8::Local<v8::Object> GetThis() { return info_->This(); }
|
|
|
|
bool IsConstructCall() const { return info_->IsConstructCall(); }
|
|
|
|
int Length() const { return info_->Length(); }
|
|
|
|
template <typename T>
|
|
void Return(const T& val) {
|
|
info_->GetReturnValue().Set(ConvertToV8(isolate_, val));
|
|
}
|
|
|
|
v8::Local<v8::Value> PeekNext() const;
|
|
|
|
v8::Local<v8::Value> ThrowError() const;
|
|
v8::Local<v8::Value> ThrowError(const std::string& message) const;
|
|
v8::Local<v8::Value> ThrowTypeError(const std::string& message) const;
|
|
|
|
v8::Isolate* isolate() const { return isolate_; }
|
|
|
|
private:
|
|
v8::Isolate* isolate_;
|
|
const v8::FunctionCallbackInfo<v8::Value>* info_;
|
|
int next_;
|
|
bool insufficient_arguments_;
|
|
};
|
|
|
|
} // namespace mate
|
|
|
|
#endif // NATIVE_MATE_NATIVE_MATE_ARGUMENTS_H_
|