Files
electron/shell/browser/extensions/api/scripting/scripting_api.h
electron-roller[bot] 76c5257fea chore: bump chromium to 149.0.7811.0 (main) (#51300)
* chore: bump chromium in DEPS to 149.0.7809.0

* chore: bump chromium in DEPS to 149.0.7810.2

* chore: bump chromium in DEPS to 149.0.7811.0

* chore: revert [OSCrypt] Remove sync backend

Electron still depends on the synchronous os_crypt API.
Revert upstream CL 7765593 until migration to async is complete.

Followup: https://github.com/electron/electron/issues/51301
Ref: https://chromium-review.googlesource.com/c/chromium/src/+/7765593

Co-Authored-By: GitHub Copilot (Claude Opus 4.6)

* fix(patch): UAF fix in OnMouseRange

Ref: https://chromium-review.googlesource.com/c/chromium/src/+/7780978

Co-Authored-By: GitHub Copilot (Claude Opus 4.6)

* fix(patch): kGlicTrustFirstOnboarding references removed

Ref: https://chromium-review.googlesource.com/c/chromium/src/+/7773143

Co-Authored-By: GitHub Copilot (Claude Opus 4.6)

* chore: update patches (trivial only)

* fix(patch): SubtlePassKey and profile methods updates

Re-add OSCryptImpl as a friend of crypto::SubtlePassKey (removed by
https://chromium-review.googlesource.com/c/chromium/src/+/7759877)
since Electron still uses the sync backend.

Followup: https://github.com/electron/electron/issues/51301

Co-Authored-By: GitHub Copilot (Claude Opus 4.6)

* fix(patch): exclude upstream scripting API

CL 7784831 moved the Scripting API from //chrome to //extensions,
which caused duplicate symbols with Electron's own implementation.

Ref: https://chromium-review.googlesource.com/c/chromium/src/+/7784831

Co-Authored-By: GitHub Copilot (Claude Opus 4.6)

* 7748618: [extensions] Move MimeHandlerStreamManager

Ref: https://chromium-review.googlesource.com/c/chromium/src/+/7748618

Co-Authored-By: GitHub Copilot (Claude Opus 4.6)

* 7713176: Move GetURLLoaderFactory from Profile to BrowserContext

Ref: https://chromium-review.googlesource.com/c/chromium/src/+/7713176

Co-Authored-By: GitHub Copilot (Claude Opus 4.6)

* 7755340: Refactor CaptureHandle storage to PageImpl

Ref: https://chromium-review.googlesource.com/c/chromium/src/+/7755340

Co-Authored-By: GitHub Copilot (Claude Opus 4.6)

* 7765593: [OSCrypt] Remove sync backend

No replacement code is needed: Electron already uses the async path.
CookieEncryptionProviderImpl (backed by OSCryptAsync) supplies
encryption to the network service via the cookie_encryption_provider
NetworkContext param, making SetEncryptionKey redundant.

Ref: https://chromium-review.googlesource.com/c/chromium/src/+/7765593

Co-Authored-By: GitHub Copilot (Claude Opus 4.6)

* chore: stop disabling enterprise_cloud_content_analysis

CL 7757742 moved cloud_content_scanning from unconditional deps into
a conditional block gated on enterprise_cloud_content_analysis,
safe_browsing_mode, or is_android. Since Electron sets
safe_browsing_mode = 1, the dep is still included regardless, but
explicitly overriding enterprise_cloud_content_analysis to false now
causes other targets (e.g. chrome/browser/download) to omit enterprise
connectors code that the rest of the build expects to find.

It is simpler to let it default to true than to patch around it.
Electron does not use this feature — our PerformContentAnalysisIfNeeded
is a no-op passthrough that skips straight to NotifyListenerAndEnd.

Ref: https://chromium-review.googlesource.com/c/chromium/src/+/7757742

Co-Authored-By: GitHub Copilot (Claude Opus 4.6)

* chore: update patches (trivial only)

* chore: update filenames.libcxx.gni

* chore: add GPU libraries to chromedriver zip manifests

Chromedriver now has transitive runtime dependencies on libEGL,
libGLESv2, and vk_swiftshader on macOS and Windows. These are
transitive deps pulled through chromedriver_server's dependency
on //mojo/core/embedder and //net.

* fix: add MicrotasksScope for worker exit emit in ContextWillDestroy

a39108c5a4 (#47244) replaced gin_helper::EmitEvent with a direct
`v8::Function::Call()` in `WebWorkerObserver::ContextWillDestroy`
to avoid re-entering the microtask checkpoint during worker teardown.

V8 `DCHECK()`s that a policy is set. Under the old code path, this
happened with a node::CallbackScope. Under the new code path, it's
possible for a policy to not be set, causing that `DCHECK()` to fail.

This PR copies a39108c5a4's changes in `ShareEnvironmentWithContext()`:
it explicitly adds a `kDoNotRunMicrotasks` scope.

* chore: override CreateChromeMetadataPacketRecorder in tracing delegate

https://chromium-review.googlesource.com/c/chromium/src/+/7770189
product-version, os-name, and channel metadata from the legacy
ChromeEventBundle path to a new ChromeMetadataPacket recorder callback.
Override the new TracingDelegate virtual so Electron still emits these fields.

---------

Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com>
Co-authored-by: Charles Kerr <charles@charleskerr.com>
2026-04-27 19:41:19 -05:00

204 lines
7.1 KiB
C++

// Copyright 2023 Microsoft, GmbH
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef ELECTRON_SHELL_BROWSER_EXTENSIONS_API_SCRIPTING_SCRIPTING_API_H_
#define ELECTRON_SHELL_BROWSER_EXTENSIONS_API_SCRIPTING_SCRIPTING_API_H_
#include <memory>
#include <optional>
#include <set>
#include <string>
#include <vector>
#include "extensions/browser/extension_function.h"
#include "extensions/browser/script_executor.h"
#include "extensions/browser/scripting_utils.h"
#include "extensions/common/api/scripting.h"
#include "extensions/common/mojom/code_injection.mojom.h"
#include "extensions/common/user_script.h"
namespace extensions {
class ScriptingExecuteScriptFunction : public ExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("scripting.executeScript", SCRIPTING_EXECUTESCRIPT)
ScriptingExecuteScriptFunction();
ScriptingExecuteScriptFunction(const ScriptingExecuteScriptFunction&) =
delete;
ScriptingExecuteScriptFunction& operator=(
const ScriptingExecuteScriptFunction&) = delete;
// ExtensionFunction:
ResponseAction Run() override;
private:
~ScriptingExecuteScriptFunction() override;
// Called when the resource files to be injected has been loaded.
void DidLoadResources(std::vector<scripting::InjectedFileSource> file_sources,
std::optional<std::string> load_error);
// Triggers the execution of `sources` in the appropriate context.
// Returns true on success; on failure, populates `error`.
bool Execute(std::vector<mojom::JSSourcePtr> sources, std::string* error);
// Invoked when script execution is complete.
void OnScriptExecuted(std::vector<ScriptExecutor::FrameResult> frame_results);
api::scripting::ScriptInjection injection_;
};
class ScriptingInsertCSSFunction : public ExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("scripting.insertCSS", SCRIPTING_INSERTCSS)
ScriptingInsertCSSFunction();
ScriptingInsertCSSFunction(const ScriptingInsertCSSFunction&) = delete;
ScriptingInsertCSSFunction& operator=(const ScriptingInsertCSSFunction&) =
delete;
// ExtensionFunction:
ResponseAction Run() override;
private:
~ScriptingInsertCSSFunction() override;
// Called when the resource files to be injected has been loaded.
void DidLoadResources(std::vector<scripting::InjectedFileSource> file_sources,
std::optional<std::string> load_error);
// Triggers the execution of `sources` in the appropriate context.
// Returns true on success; on failure, populates `error`.
bool Execute(std::vector<mojom::CSSSourcePtr> sources, std::string* error);
// Called when the CSS insertion is complete.
void OnCSSInserted(std::vector<ScriptExecutor::FrameResult> results);
api::scripting::CSSInjection injection_;
};
class ScriptingRemoveCSSFunction : public ExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("scripting.removeCSS", SCRIPTING_REMOVECSS)
ScriptingRemoveCSSFunction();
ScriptingRemoveCSSFunction(const ScriptingRemoveCSSFunction&) = delete;
ScriptingRemoveCSSFunction& operator=(const ScriptingRemoveCSSFunction&) =
delete;
// ExtensionFunction:
ResponseAction Run() override;
private:
~ScriptingRemoveCSSFunction() override;
// Called when the CSS removal is complete.
void OnCSSRemoved(std::vector<ScriptExecutor::FrameResult> results);
};
class ScriptingRegisterContentScriptsFunction : public ExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("scripting.registerContentScripts",
SCRIPTING_REGISTERCONTENTSCRIPTS)
ScriptingRegisterContentScriptsFunction();
ScriptingRegisterContentScriptsFunction(
const ScriptingRegisterContentScriptsFunction&) = delete;
ScriptingRegisterContentScriptsFunction& operator=(
const ScriptingRegisterContentScriptsFunction&) = delete;
// ExtensionFunction:
ResponseAction Run() override;
private:
~ScriptingRegisterContentScriptsFunction() override;
// Called when script files have been checked.
void OnContentScriptFilesValidated(
std::set<std::string> persistent_script_ids,
scripting::ValidateScriptsResult result);
// Called when content scripts have been registered.
void OnContentScriptsRegistered(const std::optional<std::string>& error);
};
class ScriptingGetRegisteredContentScriptsFunction : public ExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("scripting.getRegisteredContentScripts",
SCRIPTING_GETREGISTEREDCONTENTSCRIPTS)
ScriptingGetRegisteredContentScriptsFunction();
ScriptingGetRegisteredContentScriptsFunction(
const ScriptingGetRegisteredContentScriptsFunction&) = delete;
ScriptingGetRegisteredContentScriptsFunction& operator=(
const ScriptingGetRegisteredContentScriptsFunction&) = delete;
// ExtensionFunction:
ResponseAction Run() override;
private:
~ScriptingGetRegisteredContentScriptsFunction() override;
};
class ScriptingUnregisterContentScriptsFunction : public ExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("scripting.unregisterContentScripts",
SCRIPTING_UNREGISTERCONTENTSCRIPTS)
ScriptingUnregisterContentScriptsFunction();
ScriptingUnregisterContentScriptsFunction(
const ScriptingUnregisterContentScriptsFunction&) = delete;
ScriptingUnregisterContentScriptsFunction& operator=(
const ScriptingUnregisterContentScriptsFunction&) = delete;
// ExtensionFunction:
ResponseAction Run() override;
private:
~ScriptingUnregisterContentScriptsFunction() override;
// Called when content scripts have been unregistered.
void OnContentScriptsUnregistered(const std::optional<std::string>& error);
};
class ScriptingUpdateContentScriptsFunction : public ExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("scripting.updateContentScripts",
SCRIPTING_UPDATECONTENTSCRIPTS)
ScriptingUpdateContentScriptsFunction();
ScriptingUpdateContentScriptsFunction(
const ScriptingUpdateContentScriptsFunction&) = delete;
ScriptingUpdateContentScriptsFunction& operator=(
const ScriptingUpdateContentScriptsFunction&) = delete;
// ExtensionFunction:
ResponseAction Run() override;
private:
~ScriptingUpdateContentScriptsFunction() override;
// Returns a UserScript object by updating the `original_script` with the
// `new_script` given delta. If the updated script cannot be parsed, populates
// `parse_error` and returns nullptr.
std::unique_ptr<UserScript> ApplyUpdate(
std::set<std::string>* script_ids_to_persist,
api::scripting::RegisteredContentScript& new_script,
api::scripting::RegisteredContentScript& original_script,
std::u16string* parse_error);
// Called when script files have been checked.
void OnContentScriptFilesValidated(
std::set<std::string> persistent_script_ids,
scripting::ValidateScriptsResult result);
// Called when content scripts have been updated.
void OnContentScriptsUpdated(const std::optional<std::string>& error);
};
} // namespace extensions
#endif // ELECTRON_SHELL_BROWSER_EXTENSIONS_API_SCRIPTING_SCRIPTING_API_H_