electron/shell/browser/javascript_environment.h

75 lines
1.9 KiB
C
Raw Normal View History

// Copyright (c) 2013 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef ELECTRON_SHELL_BROWSER_JAVASCRIPT_ENVIRONMENT_H_
#define ELECTRON_SHELL_BROWSER_JAVASCRIPT_ENVIRONMENT_H_
#include <memory>
2014-09-01 08:41:26 +00:00
#include "gin/public/isolate_holder.h"
#include "uv.h" // NOLINT(build/include_directory)
chore: bump chromium to 95.0.4629.0 (main) (#30676) * chore: bump chromium in DEPS to 95.0.4620.0 * chore: update patches * 3076261: Move args_ to private in ExtensionFunction https://chromium-review.googlesource.com/c/chromium/src/+/3076261 * [GURL -> SiteForCookies] content/public/browser/content_browser_client.h https://chromium-review.googlesource.com/c/chromium/src/+/3107759 * chore: fix -Wunreachable-code-return in node * Tracing to diagnose ContentScriptTracker-related bad message reports https://chromium-review.googlesource.com/c/chromium/src/+/3057922 * chore: bump chromium in DEPS to 95.0.4621.0 * chore: update patches * Remove title from the URL format on Windows. https://chromium-review.googlesource.com/c/chromium/src/+/3108445 * chore: bump chromium in DEPS to 95.0.4623.0 * Revert "chore: disable v8 oilpan" This reverts commit 5d255cf1d8e8efbb906047937a713279e5f800d0. (cherry picked from commit ba5cde4da2428020d99b7fb603c702878f95da78) * Change file paths in network context params to be relative. https://chromium-review.googlesource.com/c/chromium/src/+/3092927 * Code Health: Rename/replace content::WebUI::RegisterMessageCallback(). https://chromium-review.googlesource.com/c/chromium/src/+/3104691 * Migrate CanExecuteContentScriptSync to Mojo https://chromium-review.googlesource.com/c/chromium/src/+/3108452 * chore: update patches * remove unreachable code * Revert "Revert "chore: disable v8 oilpan"" This reverts commit fef495c0294e21760df51bddb5f7bf1ec9ed5f1e. * fixup mas patch * Reland "[include] Split out v8.h" https://chromium-review.googlesource.com/c/v8/v8/+/3113629 * chore: bump chromium in DEPS to 95.0.4624.0 * chore: bump chromium in DEPS to 95.0.4625.0 * chore: bump chromium in DEPS to 95.0.4626.0 * 3033504: Pass NavigationDownloadPolicy in CreateNewWindowParams https://chromium-review.googlesource.com/c/chromium/src/+/3033504 * 3058038: Introduce TestPrintingContext & test UpdatePrintSettings https://chromium-review.googlesource.com/c/chromium/src/+/3058038 * 3114943: [Conditional Focus][#4] Add tests and remove flag gating https://chromium-review.googlesource.com/c/chromium/src/+/3114943 * chore: update patch indices * chore: bump chromium in DEPS to 95.0.4627.0 * chore: update patches * 3093591: ozone: webpagepopups: calculate anchor for menu bounds. 4/* https://chromium-review.googlesource.com/c/chromium/src/+/3093591 * 3110414: [PA] Remove the leading cookie https://chromium-review.googlesource.com/c/chromium/src/+/3110414 * chore: update patches * 3076261: Move args_ to private in ExtensionFunction https://chromium-review.googlesource.com/c/chromium/src/+/3076261 * 3113629: Reland "[include] Split out v8.h" https://chromium-review.googlesource.com/c/v8/v8/+/3113629 * chore: bump chromium in DEPS to 95.0.4628.0 * chore: update patches * chore: bump chromium in DEPS to 95.0.4629.0 * chore: update patches * Fix chrome root store codegen for cross-compile builds. https://chromium-review.googlesource.com/c/chromium/src/+/3133701 Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: deepak1556 <hop2deep@gmail.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
2021-09-01 19:55:07 +00:00
#include "v8/include/v8-locker.h"
namespace node {
class Environment;
class MultiIsolatePlatform;
2018-04-18 01:44:10 +00:00
} // namespace node
namespace electron {
class MicrotasksRunner;
// Manage the V8 isolate and context automatically.
class JavascriptEnvironment {
public:
explicit JavascriptEnvironment(uv_loop_t* event_loop);
~JavascriptEnvironment();
// disable copy
JavascriptEnvironment(const JavascriptEnvironment&) = delete;
JavascriptEnvironment& operator=(const JavascriptEnvironment&) = delete;
void OnMessageLoopCreated();
void OnMessageLoopDestroying();
node::MultiIsolatePlatform* platform() const { return platform_; }
v8::Isolate* isolate() const { return isolate_; }
v8::Local<v8::Context> context() const {
return v8::Local<v8::Context>::New(isolate_, context_);
}
static v8::Isolate* GetIsolate();
private:
v8::Isolate* Initialize(uv_loop_t* event_loop);
2017-12-08 00:23:17 +00:00
// Leaked on exit.
node::MultiIsolatePlatform* platform_;
2017-12-08 00:23:17 +00:00
v8::Isolate* isolate_;
gin::IsolateHolder isolate_holder_;
v8::Locker locker_;
v8::Global<v8::Context> context_;
std::unique_ptr<MicrotasksRunner> microtasks_runner_;
};
// Manage the Node Environment automatically.
class NodeEnvironment {
public:
2017-03-02 08:26:15 +00:00
explicit NodeEnvironment(node::Environment* env);
~NodeEnvironment();
// disable copy
NodeEnvironment(const NodeEnvironment&) = delete;
NodeEnvironment& operator=(const NodeEnvironment&) = delete;
node::Environment* env() { return env_; }
private:
node::Environment* env_;
};
} // namespace electron
#endif // ELECTRON_SHELL_BROWSER_JAVASCRIPT_ENVIRONMENT_H_