mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
refactor: make api::WebRequest inherit from gin::Wrappable (#48762)
* refactor: make api::WebRequest inherit from gin::Wrappable refactor: remove unused v8::Isolate* arg from WebRequest ctor refactor: make electron::api::Session::web_request_ a cppgc::Member<api::WebRequest> refactor: allocate api::WebRequest on cpp heap refactor: modify Create(), Find(), and FindOrCreate() to return a WebRequest* * refactor: ProxyingURLLoaderFactory takes a concrete api::WebRequest instead of a WebRequestAPI Experimental commit to ensure `ProxyingURLLoaderFactory::web_request_api_` won't be a dangling pointer. * chore: fix doc shear * refactor: use cppgc::WeakPersistent<> in ProxyingURLLoaderFactory * refactor: make ProxyingURLLoaderFactory::web_request_ const * refactor: make ProxyingWebSocket::web_request_ a cppgc::WeakPersistent<> * add a gin::WeakCellFactory to api::WebRequest * refactor: use a gin::WeakCell for the bound WebRequest argument in HandleOnBeforeRequestResponseEvent() * chore: update patches
This commit is contained in:
@@ -10,9 +10,10 @@
|
||||
#include <string>
|
||||
|
||||
#include "base/types/pass_key.h"
|
||||
#include "gin/weak_cell.h"
|
||||
#include "gin/wrappable.h"
|
||||
#include "net/base/completion_once_callback.h"
|
||||
#include "services/network/public/cpp/resource_request.h"
|
||||
#include "shell/common/gin_helper/wrappable.h"
|
||||
|
||||
class URLPattern;
|
||||
|
||||
@@ -38,7 +39,7 @@ namespace electron::api {
|
||||
|
||||
class Session;
|
||||
|
||||
class WebRequest final : public gin_helper::DeprecatedWrappable<WebRequest> {
|
||||
class WebRequest final : public gin::Wrappable<WebRequest> {
|
||||
public:
|
||||
using BeforeSendHeadersCallback =
|
||||
base::OnceCallback<void(const std::set<std::string>& removed_headers,
|
||||
@@ -65,21 +66,29 @@ class WebRequest final : public gin_helper::DeprecatedWrappable<WebRequest> {
|
||||
// Convenience wrapper around api::Session::FromOrCreate()->WebRequest().
|
||||
// Creates the Session and WebRequest if they don't already exist.
|
||||
// Note that the WebRequest is owned by the session, not by the caller.
|
||||
static gin_helper::Handle<WebRequest> FromOrCreate(
|
||||
v8::Isolate* isolate,
|
||||
content::BrowserContext* browser_context);
|
||||
static WebRequest* FromOrCreate(v8::Isolate* isolate,
|
||||
content::BrowserContext* browser_context);
|
||||
|
||||
// Return a new WebRequest object. This can only be called by api::Session.
|
||||
static gin_helper::Handle<WebRequest> Create(base::PassKey<Session>,
|
||||
v8::Isolate* isolate);
|
||||
static WebRequest* Create(v8::Isolate* isolate, base::PassKey<Session>);
|
||||
|
||||
// Make public for cppgc::MakeGarbageCollected.
|
||||
explicit WebRequest(base::PassKey<Session>);
|
||||
~WebRequest() override;
|
||||
|
||||
// disable copy
|
||||
WebRequest(const WebRequest&) = delete;
|
||||
WebRequest& operator=(const WebRequest&) = delete;
|
||||
|
||||
static const char* GetClassName() { return "WebRequest"; }
|
||||
|
||||
// gin_helper::Wrappable:
|
||||
static gin::DeprecatedWrapperInfo kWrapperInfo;
|
||||
// gin::Wrappable:
|
||||
static const gin::WrapperInfo kWrapperInfo;
|
||||
void Trace(cppgc::Visitor*) const override;
|
||||
const gin::WrapperInfo* wrapper_info() const override;
|
||||
const char* GetHumanReadableName() const override;
|
||||
gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
|
||||
v8::Isolate* isolate) override;
|
||||
const char* GetTypeName() override;
|
||||
|
||||
bool HasListener() const;
|
||||
int OnBeforeRequest(extensions::WebRequestInfo* info,
|
||||
@@ -118,9 +127,6 @@ class WebRequest final : public gin_helper::DeprecatedWrappable<WebRequest> {
|
||||
void OnRequestWillBeDestroyed(extensions::WebRequestInfo* info);
|
||||
|
||||
private:
|
||||
explicit WebRequest(base::PassKey<Session>);
|
||||
~WebRequest() override;
|
||||
|
||||
// Contains info about requests that are blocked waiting for a response from
|
||||
// the user.
|
||||
struct BlockedRequest;
|
||||
@@ -235,6 +241,8 @@ class WebRequest final : public gin_helper::DeprecatedWrappable<WebRequest> {
|
||||
std::map<SimpleEvent, SimpleListenerInfo> simple_listeners_;
|
||||
std::map<ResponseEvent, ResponseListenerInfo> response_listeners_;
|
||||
std::map<uint64_t, BlockedRequest> blocked_requests_;
|
||||
|
||||
gin::WeakCellFactory<WebRequest> weak_factory_{this};
|
||||
};
|
||||
|
||||
} // namespace electron::api
|
||||
|
||||
Reference in New Issue
Block a user