Commit ec442739 authored by Hiroshige Hayashizaki's avatar Hiroshige Hayashizaki Committed by Commit Bot

Introduce Modulator::IsScriptingDisabled()

Preparation for
https://chromium-review.googlesource.com/c/chromium/src/+/1065061/.

Bug: 845285, 841466
Change-Id: I502d296c05ad27a8d974daae5a004fbf58f8791d
Reviewed-on: https://chromium-review.googlesource.com/1100537Reviewed-by: default avatarHiroki Nakagawa <nhiroki@chromium.org>
Reviewed-by: default avatarKouhei Ueno <kouhei@chromium.org>
Commit-Queue: Hiroshige Hayashizaki <hiroshige@chromium.org>
Cr-Commit-Position: refs/heads/master@{#567313}
parent dbeecf95
......@@ -91,6 +91,10 @@ class CORE_EXPORT Modulator : public GarbageCollectedFinalized<Modulator>,
virtual ScriptState* GetScriptState() = 0;
// https://html.spec.whatwg.org/multipage/webappapis.html#concept-bc-noscript
// "scripting is disabled for settings's responsible browsing context"
virtual bool IsScriptingDisabled() const = 0;
// https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-module-script-tree
// https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-module-worker-script-tree
// Note that |this| is the "module map settings object" used in the "fetch a
......
......@@ -40,6 +40,10 @@ ModulatorImplBase::ModulatorImplBase(scoped_refptr<ScriptState> script_state)
ModulatorImplBase::~ModulatorImplBase() {}
bool ModulatorImplBase::IsScriptingDisabled() const {
return !GetExecutionContext()->CanExecuteScripts(kAboutToExecuteScript);
}
// [fetch-a-module-script-tree]
// https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-module-script-tree
// [fetch-a-module-worker-script-tree]
......@@ -200,7 +204,7 @@ ScriptModule ModulatorImplBase::CompileModule(
// object's responsible browsing context, then let script source be the empty
// string. Otherwise, let script source be the provided script source.
String script_source;
if (GetExecutionContext()->CanExecuteScripts(kAboutToExecuteScript))
if (!IsScriptingDisabled())
script_source = provided_source;
// Step 5. Let result be ParseModule(script source, realm, script).
......@@ -242,7 +246,7 @@ ScriptValue ModulatorImplBase::ExecuteModule(
// Step 3. "Check if we can run script with settings.
// If this returns "do not run" then return." [spec text]
if (!GetExecutionContext()->CanExecuteScripts(kAboutToExecuteScript))
if (IsScriptingDisabled())
return ScriptValue();
// Step 4. "Prepare to run script given settings." [spec text]
......
......@@ -40,6 +40,8 @@ class ModulatorImplBase : public Modulator {
private:
// Implements Modulator
bool IsScriptingDisabled() const override;
ScriptModuleResolver* GetScriptModuleResolver() override {
return script_module_resolver_.Get();
}
......
......@@ -49,6 +49,10 @@ ScriptState* DummyModulator::GetScriptState() {
return nullptr;
}
bool DummyModulator::IsScriptingDisabled() const {
return false;
}
ScriptModuleResolver* DummyModulator::GetScriptModuleResolver() {
return resolver_.Get();
}
......
......@@ -32,6 +32,7 @@ class DummyModulator : public Modulator {
ScriptModuleResolver* GetScriptModuleResolver() override;
base::SingleThreadTaskRunner* TaskRunner() override;
ScriptState* GetScriptState() override;
bool IsScriptingDisabled() const override;
void FetchTree(
const KURL&,
......
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