Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add V8CacheOptions webpreference #23867

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/api/browser-window.md
Expand Up @@ -387,6 +387,13 @@ It creates a new `BrowserWindow` with native properties as set by the `options`.
Default is `true`.
* `enableWebSQL` Boolean (optional) - Whether to enable the [WebSQL api](https://www.w3.org/TR/webdatabase/).
Default is `true`.
* `v8CacheOptions` String (optional) - Enforces the v8 code caching policy
used by blink. Accepted values are
* `none` - Disables code caching
* `code` - Heuristic based code caching
* `bypassHeatCheck` - Bypass code caching heuristics but with lazy compilation
* `bypassHeatCheckAndEagerCompile` - Same as above except compilation is eager.
Default policy is `code`.

When setting minimum or maximum window size with `minWidth`/`maxWidth`/
`minHeight`/`maxHeight`, it only constrains the users. It won't prevent you from
Expand Down
18 changes: 18 additions & 0 deletions shell/browser/web_contents_preferences.cc
Expand Up @@ -26,6 +26,7 @@
#include "shell/common/gin_converters/value_converter.h"
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/options_switches.h"
#include "third_party/blink/public/mojom/v8_cache_options.mojom.h"

#if defined(OS_WIN)
#include "ui/gfx/switches.h"
Expand Down Expand Up @@ -485,6 +486,23 @@ void WebContentsPreferences::OverrideWebkitPrefs(
std::string encoding;
if (GetAsString(&preference_, "defaultEncoding", &encoding))
prefs->default_encoding = encoding;

std::string v8_cache_options;
if (GetAsString(&preference_, "v8CacheOptions", &v8_cache_options)) {
if (v8_cache_options == "none") {
prefs->v8_cache_options = blink::mojom::V8CacheOptions::kNone;
} else if (v8_cache_options == "code") {
prefs->v8_cache_options = blink::mojom::V8CacheOptions::kCode;
} else if (v8_cache_options == "bypassHeatCheck") {
prefs->v8_cache_options =
blink::mojom::V8CacheOptions::kCodeWithoutHeatCheck;
} else if (v8_cache_options == "bypassHeatCheckAndEagerCompile") {
prefs->v8_cache_options =
blink::mojom::V8CacheOptions::kFullCodeWithoutHeatCheck;
} else {
prefs->v8_cache_options = blink::mojom::V8CacheOptions::kDefault;
}
}
}

WEB_CONTENTS_USER_DATA_KEY_IMPL(WebContentsPreferences)
Expand Down