Commit 2e0d8da7 authored by Hiroshige Hayashizaki's avatar Hiroshige Hayashizaki Committed by Commit Bot

Introduce ExecutionContext::GetV8CacheOptions()

To unify how V8CacheOptions is set across
classic script evaluation code paths.

Bug: 1111134
Change-Id: Ie84d896775951a2eb31bfaa23251c99fe3372ea8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2541362Reviewed-by: default avatarYuki Shiino <yukishiino@chromium.org>
Commit-Queue: Hiroshige Hayashizaki <hiroshige@chromium.org>
Cr-Commit-Position: refs/heads/master@{#829907}
parent 50ea97c7
...@@ -36,8 +36,6 @@ ...@@ -36,8 +36,6 @@
#include <utility> #include <utility>
#include "base/callback_helpers.h" #include "base/callback_helpers.h"
#include "third_party/blink/public/mojom/v8_cache_options.mojom-blink.h"
#include "third_party/blink/public/web/web_settings.h"
#include "third_party/blink/renderer/bindings/core/v8/script_evaluation_result.h" #include "third_party/blink/renderer/bindings/core/v8/script_evaluation_result.h"
#include "third_party/blink/renderer/bindings/core/v8/script_source_code.h" #include "third_party/blink/renderer/bindings/core/v8/script_source_code.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h" #include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h"
...@@ -51,7 +49,6 @@ ...@@ -51,7 +49,6 @@
#include "third_party/blink/renderer/core/frame/local_dom_window.h" #include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/frame/local_frame.h" #include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/local_frame_client.h" #include "third_party/blink/renderer/core/frame/local_frame_client.h"
#include "third_party/blink/renderer/core/frame/settings.h"
#include "third_party/blink/renderer/core/html/html_plugin_element.h" #include "third_party/blink/renderer/core/html/html_plugin_element.h"
#include "third_party/blink/renderer/core/inspector/console_message.h" #include "third_party/blink/renderer/core/inspector/console_message.h"
#include "third_party/blink/renderer/core/inspector/inspector_trace_events.h" #include "third_party/blink/renderer/core/inspector/inspector_trace_events.h"
...@@ -91,15 +88,9 @@ v8::Local<v8::Value> ScriptController::ExecuteScriptAndReturnValue( ...@@ -91,15 +88,9 @@ v8::Local<v8::Value> ScriptController::ExecuteScriptAndReturnValue(
const KURL& base_url, const KURL& base_url,
SanitizeScriptErrors sanitize_script_errors, SanitizeScriptErrors sanitize_script_errors,
const ScriptFetchOptions& fetch_options) { const ScriptFetchOptions& fetch_options) {
mojom::blink::V8CacheOptions v8_cache_options =
mojom::blink::V8CacheOptions::kDefault;
if (const Settings* settings = window_->GetFrame()->GetSettings())
v8_cache_options = settings->GetV8CacheOptions();
ScriptEvaluationResult result = V8ScriptRunner::CompileAndRunScript( ScriptEvaluationResult result = V8ScriptRunner::CompileAndRunScript(
GetIsolate(), ScriptState::From(context), window_.Get(), source, GetIsolate(), ScriptState::From(context), window_.Get(), source,
base_url, sanitize_script_errors, fetch_options, base_url, sanitize_script_errors, fetch_options,
std::move(v8_cache_options),
V8ScriptRunner::RethrowErrorsOption::DoNotRethrow()); V8ScriptRunner::RethrowErrorsOption::DoNotRethrow());
if (result.GetResultType() == ScriptEvaluationResult::ResultType::kSuccess) if (result.GetResultType() == ScriptEvaluationResult::ResultType::kSuccess)
......
...@@ -377,7 +377,6 @@ ScriptEvaluationResult V8ScriptRunner::CompileAndRunScript( ...@@ -377,7 +377,6 @@ ScriptEvaluationResult V8ScriptRunner::CompileAndRunScript(
const KURL& base_url, const KURL& base_url,
SanitizeScriptErrors sanitize_script_errors, SanitizeScriptErrors sanitize_script_errors,
const ScriptFetchOptions& fetch_options, const ScriptFetchOptions& fetch_options,
mojom::blink::V8CacheOptions v8_cache_options,
RethrowErrorsOption rethrow_errors) { RethrowErrorsOption rethrow_errors) {
DCHECK_EQ(isolate, script_state->GetIsolate()); DCHECK_EQ(isolate, script_state->GetIsolate());
...@@ -432,7 +431,8 @@ ScriptEvaluationResult V8ScriptRunner::CompileAndRunScript( ...@@ -432,7 +431,8 @@ ScriptEvaluationResult V8ScriptRunner::CompileAndRunScript(
V8CodeCache::ProduceCacheOptions produce_cache_options; V8CodeCache::ProduceCacheOptions produce_cache_options;
v8::ScriptCompiler::NoCacheReason no_cache_reason; v8::ScriptCompiler::NoCacheReason no_cache_reason;
std::tie(compile_options, produce_cache_options, no_cache_reason) = std::tie(compile_options, produce_cache_options, no_cache_reason) =
V8CodeCache::GetCompileOptions(v8_cache_options, source); V8CodeCache::GetCompileOptions(execution_context->GetV8CacheOptions(),
source);
v8::MaybeLocal<v8::Value> maybe_result; v8::MaybeLocal<v8::Value> maybe_result;
if (V8ScriptRunner::CompileScript(script_state, source, if (V8ScriptRunner::CompileScript(script_state, source,
......
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_BINDINGS_CORE_V8_V8_SCRIPT_RUNNER_H_ #ifndef THIRD_PARTY_BLINK_RENDERER_BINDINGS_CORE_V8_V8_SCRIPT_RUNNER_H_
#define THIRD_PARTY_BLINK_RENDERER_BINDINGS_CORE_V8_V8_SCRIPT_RUNNER_H_ #define THIRD_PARTY_BLINK_RENDERER_BINDINGS_CORE_V8_V8_SCRIPT_RUNNER_H_
#include "third_party/blink/public/mojom/v8_cache_options.mojom-blink.h"
#include "third_party/blink/renderer/bindings/core/v8/sanitize_script_errors.h" #include "third_party/blink/renderer/bindings/core/v8/sanitize_script_errors.h"
#include "third_party/blink/renderer/core/core_export.h" #include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h" #include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
...@@ -129,7 +128,6 @@ class CORE_EXPORT V8ScriptRunner final { ...@@ -129,7 +128,6 @@ class CORE_EXPORT V8ScriptRunner final {
const KURL&, const KURL&,
SanitizeScriptErrors, SanitizeScriptErrors,
const ScriptFetchOptions&, const ScriptFetchOptions&,
mojom::blink::V8CacheOptions,
RethrowErrorsOption); RethrowErrorsOption);
static v8::MaybeLocal<v8::Value> CompileAndRunInternalScript( static v8::MaybeLocal<v8::Value> CompileAndRunInternalScript(
v8::Isolate*, v8::Isolate*,
......
...@@ -316,7 +316,6 @@ void WorkerOrWorkletScriptController::DisableEvalInternal( ...@@ -316,7 +316,6 @@ void WorkerOrWorkletScriptController::DisableEvalInternal(
ScriptEvaluationResult WorkerOrWorkletScriptController::EvaluateAndReturnValue( ScriptEvaluationResult WorkerOrWorkletScriptController::EvaluateAndReturnValue(
const ScriptSourceCode& source_code, const ScriptSourceCode& source_code,
SanitizeScriptErrors sanitize_script_errors, SanitizeScriptErrors sanitize_script_errors,
mojom::blink::V8CacheOptions v8_cache_options,
V8ScriptRunner::RethrowErrorsOption rethrow_errors) { V8ScriptRunner::RethrowErrorsOption rethrow_errors) {
if (IsExecutionForbidden()) if (IsExecutionForbidden())
return ScriptEvaluationResult::FromClassicNotRun(); return ScriptEvaluationResult::FromClassicNotRun();
...@@ -333,8 +332,7 @@ ScriptEvaluationResult WorkerOrWorkletScriptController::EvaluateAndReturnValue( ...@@ -333,8 +332,7 @@ ScriptEvaluationResult WorkerOrWorkletScriptController::EvaluateAndReturnValue(
// TODO(crbug/1114989): Plumb ScriptFetchOptions from ClassicScript. // TODO(crbug/1114989): Plumb ScriptFetchOptions from ClassicScript.
ScriptEvaluationResult result = V8ScriptRunner::CompileAndRunScript( ScriptEvaluationResult result = V8ScriptRunner::CompileAndRunScript(
isolate_, script_state_, global_scope_, source_code, base_url, isolate_, script_state_, global_scope_, source_code, base_url,
sanitize_script_errors, ScriptFetchOptions(), v8_cache_options, sanitize_script_errors, ScriptFetchOptions(), std::move(rethrow_errors));
std::move(rethrow_errors));
if (result.GetResultType() == ScriptEvaluationResult::ResultType::kAborted) if (result.GetResultType() == ScriptEvaluationResult::ResultType::kAborted)
ForbidExecution(); ForbidExecution();
......
...@@ -32,7 +32,6 @@ ...@@ -32,7 +32,6 @@
#define THIRD_PARTY_BLINK_RENDERER_BINDINGS_CORE_V8_WORKER_OR_WORKLET_SCRIPT_CONTROLLER_H_ #define THIRD_PARTY_BLINK_RENDERER_BINDINGS_CORE_V8_WORKER_OR_WORKLET_SCRIPT_CONTROLLER_H_
#include "base/macros.h" #include "base/macros.h"
#include "third_party/blink/public/mojom/v8_cache_options.mojom-blink.h"
#include "third_party/blink/renderer/bindings/core/v8/rejected_promises.h" #include "third_party/blink/renderer/bindings/core/v8/rejected_promises.h"
#include "third_party/blink/renderer/bindings/core/v8/sanitize_script_errors.h" #include "third_party/blink/renderer/bindings/core/v8/sanitize_script_errors.h"
#include "third_party/blink/renderer/bindings/core/v8/script_evaluation_result.h" #include "third_party/blink/renderer/bindings/core/v8/script_evaluation_result.h"
...@@ -62,7 +61,6 @@ class CORE_EXPORT WorkerOrWorkletScriptController final ...@@ -62,7 +61,6 @@ class CORE_EXPORT WorkerOrWorkletScriptController final
ScriptEvaluationResult EvaluateAndReturnValue( ScriptEvaluationResult EvaluateAndReturnValue(
const ScriptSourceCode&, const ScriptSourceCode&,
SanitizeScriptErrors sanitize_script_errors, SanitizeScriptErrors sanitize_script_errors,
mojom::blink::V8CacheOptions = mojom::blink::V8CacheOptions::kDefault,
V8ScriptRunner::RethrowErrorsOption = V8ScriptRunner::RethrowErrorsOption =
V8ScriptRunner::RethrowErrorsOption::DoNotRethrow()); V8ScriptRunner::RethrowErrorsOption::DoNotRethrow());
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
#include "third_party/blink/public/mojom/feature_policy/feature_policy_feature.mojom-blink-forward.h" #include "third_party/blink/public/mojom/feature_policy/feature_policy_feature.mojom-blink-forward.h"
#include "third_party/blink/public/mojom/feature_policy/policy_disposition.mojom-blink-forward.h" #include "third_party/blink/public/mojom/feature_policy/policy_disposition.mojom-blink-forward.h"
#include "third_party/blink/public/mojom/frame/lifecycle.mojom-blink-forward.h" #include "third_party/blink/public/mojom/frame/lifecycle.mojom-blink-forward.h"
#include "third_party/blink/public/mojom/v8_cache_options.mojom-blink.h"
#include "third_party/blink/renderer/bindings/core/v8/sanitize_script_errors.h" #include "third_party/blink/renderer/bindings/core/v8/sanitize_script_errors.h"
#include "third_party/blink/renderer/core/core_export.h" #include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/execution_context/execution_context_lifecycle_observer.h" #include "third_party/blink/renderer/core/execution_context/execution_context_lifecycle_observer.h"
...@@ -212,6 +213,9 @@ class CORE_EXPORT ExecutionContext : public Supplementable<ExecutionContext>, ...@@ -212,6 +213,9 @@ class CORE_EXPORT ExecutionContext : public Supplementable<ExecutionContext>,
virtual bool CanExecuteScripts(ReasonForCallingCanExecuteScripts) { virtual bool CanExecuteScripts(ReasonForCallingCanExecuteScripts) {
return false; return false;
} }
virtual mojom::blink::V8CacheOptions GetV8CacheOptions() const {
return mojom::blink::V8CacheOptions::kDefault;
}
void DispatchErrorEvent(ErrorEvent*, SanitizeScriptErrors); void DispatchErrorEvent(ErrorEvent*, SanitizeScriptErrors);
......
...@@ -239,6 +239,15 @@ LocalDOMWindow* LocalDOMWindow::From(const ScriptState* script_state) { ...@@ -239,6 +239,15 @@ LocalDOMWindow* LocalDOMWindow::From(const ScriptState* script_state) {
return blink::ToLocalDOMWindow(script_state->GetContext()); return blink::ToLocalDOMWindow(script_state->GetContext());
} }
mojom::blink::V8CacheOptions LocalDOMWindow::GetV8CacheOptions() const {
if (LocalFrame* frame = GetFrame()) {
if (const Settings* settings = frame->GetSettings())
return settings->GetV8CacheOptions();
}
return mojom::blink::V8CacheOptions::kDefault;
}
bool LocalDOMWindow::IsContextThread() const { bool LocalDOMWindow::IsContextThread() const {
return IsMainThread(); return IsMainThread();
} }
......
...@@ -128,6 +128,8 @@ class CORE_EXPORT LocalDOMWindow final : public DOMWindow, ...@@ -128,6 +128,8 @@ class CORE_EXPORT LocalDOMWindow final : public DOMWindow,
void ResetWindowAgent(WindowAgent*); void ResetWindowAgent(WindowAgent*);
mojom::blink::V8CacheOptions GetV8CacheOptions() const override;
// Bind Content Security Policy to this window. This will cause the // Bind Content Security Policy to this window. This will cause the
// CSP to resolve the 'self' attribute and all policies will then be // CSP to resolve the 'self' attribute and all policies will then be
// applied to this document. // applied to this document.
......
...@@ -58,8 +58,7 @@ bool ClassicScript::RunScriptOnWorkerOrWorklet( ...@@ -58,8 +58,7 @@ bool ClassicScript::RunScriptOnWorkerOrWorklet(
ScriptState::Scope scope(global_scope.ScriptController()->GetScriptState()); ScriptState::Scope scope(global_scope.ScriptController()->GetScriptState());
ScriptEvaluationResult result = ScriptEvaluationResult result =
global_scope.ScriptController()->EvaluateAndReturnValue( global_scope.ScriptController()->EvaluateAndReturnValue(
GetScriptSourceCode(), sanitize_script_errors_, GetScriptSourceCode(), sanitize_script_errors_);
global_scope.GetV8CacheOptions());
return result.GetResultType() == ScriptEvaluationResult::ResultType::kSuccess; return result.GetResultType() == ScriptEvaluationResult::ResultType::kSuccess;
} }
......
...@@ -339,7 +339,7 @@ void WorkerGlobalScope::ImportScriptsInternal(const Vector<String>& urls) { ...@@ -339,7 +339,7 @@ void WorkerGlobalScope::ImportScriptsInternal(const Vector<String>& urls) {
handler, handler,
ScriptSourceCode::UsePostRedirectURL() ? response_url ScriptSourceCode::UsePostRedirectURL() ? response_url
: complete_url), : complete_url),
sanitize_script_errors, GetV8CacheOptions(), sanitize_script_errors,
V8ScriptRunner::RethrowErrorsOption::Rethrow(error_message)); V8ScriptRunner::RethrowErrorsOption::Rethrow(error_message));
// Step 5.2: "If an exception was thrown or if the script was prematurely // Step 5.2: "If an exception was thrown or if the script was prematurely
......
...@@ -140,7 +140,7 @@ class CORE_EXPORT WorkerOrWorkletGlobalScope : public EventTargetWithInlineData, ...@@ -140,7 +140,7 @@ class CORE_EXPORT WorkerOrWorkletGlobalScope : public EventTargetWithInlineData,
WorkerOrWorkletScriptController* ScriptController() { WorkerOrWorkletScriptController* ScriptController() {
return script_controller_.Get(); return script_controller_.Get();
} }
mojom::blink::V8CacheOptions GetV8CacheOptions() const { mojom::blink::V8CacheOptions GetV8CacheOptions() const override {
return v8_cache_options_; return v8_cache_options_;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment