electron/shell/renderer/service_worker_data.h
trop[bot] f2d14ca29d
refactor: avoid deprecated v8::Context::GetIsolate() calls pt 3 context get isolate pt 3 (#47910)
* refactor: add a v8::Isolate* arg to RendererClientBase::IsWebViewFrame()

Needed for creating gin dictionaries

refactor: add a v8::Isolate* arg to ShouldLoadPreload()

Needed for calling IsWebViewFrame()

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* refactor: add a v8::Isolate* arg to electron::util::CompileAndCall()

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* refactor: add a v8::Isolate* arg to OnCreatePreloadableV8Context()

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* refactor: add a v8::Isolate* arg to InvokeEmitProcessEvent()

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* refactor: add a v8::Isolate* arg to ServiceWorkerData's constructor

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* refactor: add a v8::Isolate* arg to RendererClientBase::SetupMainWorldOverrides()

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* refactor: add a v8::Isolate* arg to RendererClientBase::WilLReleaseScriptContext()

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* docs: update docs to avoid v8::Context::GetIsolate()

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* refactor: add a v8::Isolate* arg to ElectronSandboxedRendererClient::InitializeBindings()

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* refactor: avoid v8::Context::GetIsolate() call in PromiseBase::SettleScope::~SettleScope()

Co-authored-by: Charles Kerr <charles@charleskerr.com>

---------

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Charles Kerr <charles@charleskerr.com>
2025-07-31 14:19:10 -05:00

69 lines
2.4 KiB
C++

// Copyright (c) 2025 Salesforce, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef ELECTRON_SHELL_RENDERER_SERVICE_WORKER_DATA_H_
#define ELECTRON_SHELL_RENDERER_SERVICE_WORKER_DATA_H_
#include <string>
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "electron/shell/common/api/api.mojom.h"
#include "mojo/public/cpp/bindings/associated_receiver.h"
#include "mojo/public/cpp/bindings/associated_remote.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "third_party/blink/public/web/modules/service_worker/web_service_worker_context_proxy.h"
#include "v8/include/v8-context.h"
#include "v8/include/v8-forward.h"
namespace electron {
// Per ServiceWorker data in worker thread.
class ServiceWorkerData : public mojom::ElectronRenderer {
public:
ServiceWorkerData(blink::WebServiceWorkerContextProxy* proxy,
int64_t service_worker_version_id,
v8::Isolate* const isolate,
const v8::Local<v8::Context>& v8_context);
~ServiceWorkerData() override;
// disable copy
ServiceWorkerData(const ServiceWorkerData&) = delete;
ServiceWorkerData& operator=(const ServiceWorkerData&) = delete;
int64_t service_worker_version_id() const {
return service_worker_version_id_;
}
blink::WebServiceWorkerContextProxy* proxy() const { return proxy_; }
// mojom::ElectronRenderer
void Message(bool internal,
const std::string& channel,
blink::CloneableMessage arguments) override;
void ReceivePostMessage(const std::string& channel,
blink::TransferableMessage message) override;
void TakeHeapSnapshot(mojo::ScopedHandle file,
TakeHeapSnapshotCallback callback) override;
private:
void OnElectronRendererRequest(
mojo::PendingAssociatedReceiver<mojom::ElectronRenderer> receiver);
raw_ptr<blink::WebServiceWorkerContextProxy> proxy_;
const int64_t service_worker_version_id_;
// The v8 context the bindings are accessible to.
raw_ptr<v8::Isolate> isolate_;
v8::Global<v8::Context> v8_context_;
mojo::AssociatedReceiver<mojom::ElectronRenderer> receiver_{this};
base::WeakPtrFactory<ServiceWorkerData> weak_ptr_factory_{this};
};
} // namespace electron
#endif // ELECTRON_SHELL_RENDERER_SERVICE_WORKER_DATA_H_