Commit 1fd74ae2 authored by Nate Chapin's avatar Nate Chapin Committed by Commit Bot

ExecutionContext post-migration cleanup - mdoules/ q-s

While migrating ExecutionContext to LocalDOMWindow, several helpers
were introduced on Document (From(), DynamicFrom(),
ToExecutionContext()). This CL removes usage of these types from this
directory.

From() and DynamicFrom() are replaced with the standard
downcast helpers for LocalDOMWindow. ToExecutionContext() is replaced
with a direct path to the LocalDOMWindow, or Node::GetExecutionContext(),
or Document::GetExecutionContext(), whichever is most direct from the
callsite.

Bug: 1029822
Change-Id: I2f027d0fa2553367195e71359234b9a455c599a9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2112988
Commit-Queue: Nate Chapin <japhet@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#762075}
parent 6748e60e
......@@ -21,7 +21,7 @@ DeviceOrientationInspectorAgent::DeviceOrientationInspectorAgent(
InspectedFrames* inspected_frames)
: inspected_frames_(inspected_frames),
sensor_agent_(MakeGarbageCollected<SensorInspectorAgent>(
inspected_frames->Root()->GetDocument())),
inspected_frames->Root()->DomWindow())),
enabled_(&agent_state_, /*default_value=*/false),
alpha_(&agent_state_, /*default_value=*/0.0),
beta_(&agent_state_, /*default_value=*/0.0),
......
......@@ -38,7 +38,6 @@
#include "third_party/blink/renderer/bindings/modules/v8/v8_storage_estimate.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_storage_quota_callback.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_storage_usage_callback.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/frame/web_feature.h"
#include "third_party/blink/renderer/modules/quota/dom_error.h"
......@@ -188,9 +187,7 @@ void DeprecatedStorageQuota::requestQuota(
WTF::Bind(&RequestStorageQuotaCallback, WrapPersistent(success_callback),
WrapPersistent(error_callback));
Document& document = Document::From(*execution_context);
const SecurityOrigin* security_origin = document.GetSecurityOrigin();
if (security_origin->IsOpaque()) {
if (execution_context->GetSecurityOrigin()->IsOpaque()) {
// Unique origins cannot store persistent state.
std::move(callback).Run(mojom::blink::QuotaStatusCode::kErrorAbort, 0, 0);
return;
......
......@@ -10,10 +10,10 @@
#include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_storage_estimate.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_storage_usage_details.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/dom_exception.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/frame/frame.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/web_feature.h"
#include "third_party/blink/renderer/modules/permissions/permission_utils.h"
......@@ -90,23 +90,19 @@ StorageManager::StorageManager(ContextLifecycleNotifier* notifier)
ScriptPromise StorageManager::persist(ScriptState* script_state) {
auto* resolver = MakeGarbageCollected<ScriptPromiseResolver>(script_state);
ScriptPromise promise = resolver->Promise();
ExecutionContext* execution_context = ExecutionContext::From(script_state);
DCHECK(execution_context->IsSecureContext()); // [SecureContext] in IDL
const SecurityOrigin* security_origin =
execution_context->GetSecurityOrigin();
if (security_origin->IsOpaque()) {
LocalDOMWindow* window = LocalDOMWindow::From(script_state);
DCHECK(window->IsSecureContext()); // [SecureContext] in IDL
if (window->GetSecurityOrigin()->IsOpaque()) {
resolver->Reject(V8ThrowException::CreateTypeError(
script_state->GetIsolate(), kUniqueOriginErrorMessage));
return promise;
}
Document* doc = Document::From(execution_context);
GetPermissionService(ExecutionContext::From(script_state))
->RequestPermission(
CreatePermissionDescriptor(PermissionName::DURABLE_STORAGE),
LocalFrame::HasTransientUserActivation(doc->GetFrame()),
WTF::Bind(&StorageManager::PermissionRequestComplete,
WrapPersistent(this), WrapPersistent(resolver)));
GetPermissionService(window)->RequestPermission(
CreatePermissionDescriptor(PermissionName::DURABLE_STORAGE),
LocalFrame::HasTransientUserActivation(window->GetFrame()),
WTF::Bind(&StorageManager::PermissionRequestComplete,
WrapPersistent(this), WrapPersistent(resolver)));
return promise;
}
......
......@@ -9,6 +9,7 @@
#include "third_party/blink/renderer/bindings/modules/v8/v8_task_signal.h"
#include "third_party/blink/renderer/core/dom/dom_exception.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/modules/scheduler/dom_task.h"
#include "third_party/blink/renderer/modules/scheduler/dom_task_signal.h"
#include "third_party/blink/renderer/platform/scheduler/public/frame_scheduler.h"
......@@ -23,7 +24,7 @@ static ScriptPromise RejectPromiseImmediately(ExceptionState& exception_state) {
// The bindings layer implicitly converts thrown exceptions in
// promise-returning functions to promise rejections.
exception_state.ThrowDOMException(DOMExceptionCode::kNotSupportedError,
"Current document is detached");
"Current window is detached");
return ScriptPromise();
}
......@@ -31,23 +32,24 @@ static ScriptPromise RejectPromiseImmediately(ExceptionState& exception_state) {
const char DOMScheduler::kSupplementName[] = "DOMScheduler";
DOMScheduler* DOMScheduler::From(Document& document) {
DOMScheduler* scheduler = Supplement<Document>::From<DOMScheduler>(document);
DOMScheduler* DOMScheduler::From(LocalDOMWindow& window) {
DOMScheduler* scheduler =
Supplement<LocalDOMWindow>::From<DOMScheduler>(window);
if (!scheduler) {
scheduler = MakeGarbageCollected<DOMScheduler>(&document);
Supplement<Document>::ProvideTo(document, scheduler);
scheduler = MakeGarbageCollected<DOMScheduler>(&window);
Supplement<LocalDOMWindow>::ProvideTo(window, scheduler);
}
return scheduler;
}
DOMScheduler::DOMScheduler(Document* document)
: ExecutionContextLifecycleObserver(document),
Supplement<Document>(*document) {
if (document->IsContextDestroyed())
DOMScheduler::DOMScheduler(LocalDOMWindow* window)
: ExecutionContextLifecycleObserver(window),
Supplement<LocalDOMWindow>(*window) {
if (window->IsContextDestroyed())
return;
DCHECK(document->GetScheduler());
DCHECK(document->GetScheduler()->ToFrameScheduler());
CreateGlobalTaskQueues(document);
DCHECK(window->GetScheduler());
DCHECK(window->GetScheduler()->ToFrameScheduler());
CreateGlobalTaskQueues(window);
}
void DOMScheduler::ContextDestroyed() {
......@@ -57,7 +59,7 @@ void DOMScheduler::ContextDestroyed() {
void DOMScheduler::Trace(Visitor* visitor) {
ScriptWrappable::Trace(visitor);
ExecutionContextLifecycleObserver::Trace(visitor);
Supplement<Document>::Trace(visitor);
Supplement<LocalDOMWindow>::Trace(visitor);
}
ScriptPromise DOMScheduler::postTask(ScriptState* script_state,
......@@ -130,8 +132,8 @@ base::SingleThreadTaskRunner* DOMScheduler::GetTaskRunnerFor(
return global_task_queues_[static_cast<int>(priority)]->GetTaskRunner().get();
}
void DOMScheduler::CreateGlobalTaskQueues(Document* document) {
FrameScheduler* scheduler = document->GetScheduler()->ToFrameScheduler();
void DOMScheduler::CreateGlobalTaskQueues(LocalDOMWindow* window) {
FrameScheduler* scheduler = window->GetScheduler()->ToFrameScheduler();
for (size_t i = 0; i < kWebSchedulingPriorityCount; i++) {
global_task_queues_.push_back(scheduler->CreateWebSchedulingTaskQueue(
static_cast<WebSchedulingPriority>(i)));
......
......@@ -27,22 +27,22 @@ class WebSchedulingTaskQueue;
class MODULES_EXPORT DOMScheduler : public ScriptWrappable,
public ExecutionContextLifecycleObserver,
public Supplement<Document> {
public Supplement<LocalDOMWindow> {
DEFINE_WRAPPERTYPEINFO();
USING_GARBAGE_COLLECTED_MIXIN(DOMScheduler);
public:
static const char kSupplementName[];
static DOMScheduler* From(Document&);
static DOMScheduler* From(LocalDOMWindow&);
explicit DOMScheduler(Document*);
explicit DOMScheduler(LocalDOMWindow*);
// postTask creates and queues a DOMTask and returns a Promise that will
// resolve when it completes. The task will be scheduled in the queue
// corresponding to the priority in the SchedulerPostTaskOptions, or in a
// queue associated with the given DOMTaskSignal if one is provided. If the
// underlying context is destroyed, e.g. for detached documents, this will
// underlying context is destroyed, e.g. for detached windows, this will
// return a rejected promise.
ScriptPromise postTask(ScriptState*,
V8Function*,
......@@ -73,10 +73,10 @@ class MODULES_EXPORT DOMScheduler : public ScriptWrappable,
static constexpr size_t kWebSchedulingPriorityCount =
static_cast<size_t>(WebSchedulingPriority::kLastPriority) + 1;
void CreateGlobalTaskQueues(Document*);
void CreateGlobalTaskQueues(LocalDOMWindow*);
// |global_task_queues_| is initialized with one entry per priority, indexed
// by priority. This will be empty when the document is detached.
// by priority. This will be empty when the window is detached.
Vector<std::unique_ptr<WebSchedulingTaskQueue>, kWebSchedulingPriorityCount>
global_task_queues_;
};
......
......@@ -4,25 +4,25 @@
#include "third_party/blink/renderer/modules/scheduler/dom_task_controller.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/modules/scheduler/dom_task_signal.h"
namespace blink {
// static
DOMTaskController* DOMTaskController::Create(Document& document,
DOMTaskController* DOMTaskController::Create(ExecutionContext* context,
const AtomicString& priority) {
return MakeGarbageCollected<DOMTaskController>(
document, WebSchedulingPriorityFromString(priority));
context, WebSchedulingPriorityFromString(priority));
}
DOMTaskController::DOMTaskController(Document& document,
DOMTaskController::DOMTaskController(ExecutionContext* context,
WebSchedulingPriority priority)
: AbortController(MakeGarbageCollected<DOMTaskSignal>(
&document,
context,
priority,
DOMTaskSignal::Type::kCreatedByController)) {
DCHECK(!document.IsContextDestroyed());
DCHECK(!context->IsContextDestroyed());
}
void DOMTaskController::setPriority(const AtomicString& priority) {
......
......@@ -13,14 +13,15 @@
namespace blink {
class DOMTaskSignal;
class Document;
class ExecutionContext;
class MODULES_EXPORT DOMTaskController final : public AbortController {
DEFINE_WRAPPERTYPEINFO();
public:
static DOMTaskController* Create(Document&, const AtomicString& priority);
DOMTaskController(Document&, WebSchedulingPriority);
static DOMTaskController* Create(ExecutionContext*,
const AtomicString& priority);
DOMTaskController(ExecutionContext*, WebSchedulingPriority);
void setPriority(const AtomicString& priority);
......
......@@ -7,8 +7,8 @@
#include <utility>
#include "base/callback.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/events/event.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/modules/scheduler/dom_scheduler.h"
#include "third_party/blink/renderer/platform/heap/persistent.h"
#include "third_party/blink/renderer/platform/heap/visitor.h"
......@@ -19,14 +19,14 @@
namespace blink {
DOMTaskSignal::DOMTaskSignal(Document* document,
DOMTaskSignal::DOMTaskSignal(ExecutionContext* context,
WebSchedulingPriority priority,
Type type)
: AbortSignal(document->ToExecutionContext()),
ExecutionContextLifecycleObserver(document),
: AbortSignal(context),
ExecutionContextLifecycleObserver(context),
priority_(priority) {
if (type == Type::kCreatedByController) {
web_scheduling_task_queue_ = document->GetScheduler()
web_scheduling_task_queue_ = context->GetScheduler()
->ToFrameScheduler()
->CreateWebSchedulingTaskQueue(priority_);
}
......@@ -53,13 +53,13 @@ void DOMTaskSignal::SignalPriorityChange(WebSchedulingPriority priority) {
}
base::SingleThreadTaskRunner* DOMTaskSignal::GetTaskRunner() {
auto* document =
Document::From(ExecutionContextLifecycleObserver::GetExecutionContext());
if (!document)
auto* window = To<LocalDOMWindow>(
ExecutionContextLifecycleObserver::GetExecutionContext());
if (!window)
return nullptr;
if (web_scheduling_task_queue_)
return web_scheduling_task_queue_->GetTaskRunner().get();
return DOMScheduler::From(*document)->GetTaskRunnerFor(priority_);
return DOMScheduler::From(*window)->GetTaskRunnerFor(priority_);
}
void DOMTaskSignal::Trace(Visitor* visitor) {
......
......@@ -16,7 +16,7 @@ class SingleThreadTaskRunner;
}
namespace blink {
class Document;
class ExecutionContext;
class WebSchedulingTaskQueue;
class MODULES_EXPORT DOMTaskSignal final
......@@ -37,7 +37,7 @@ class MODULES_EXPORT DOMTaskSignal final
kMaxValue = kPriorityHasChanged
};
DOMTaskSignal(Document*, WebSchedulingPriority, Type);
DOMTaskSignal(ExecutionContext*, WebSchedulingPriority, Type);
~DOMTaskSignal() override;
// task_signal.idl
......
......@@ -11,7 +11,7 @@
MeasureAs=TaskControllerConstructor,
RuntimeEnabled=WebScheduler
] interface TaskController : AbortController {
[CallWith=Document] constructor(optional TaskPriority priority = "user-visible");
[CallWith=ExecutionContext] constructor(optional TaskPriority priority = "user-visible");
[MeasureAs=TaskControllerSetPriority] void setPriority(TaskPriority priority);
};
......@@ -10,10 +10,7 @@
namespace blink {
DOMScheduler* WindowScheduler::scheduler(LocalDOMWindow& window) {
if (Document* document = window.document()) {
return DOMScheduler::From(*document);
}
return nullptr;
return DOMScheduler::From(window);
}
} // namespace blink
......@@ -11,7 +11,6 @@
#include "third_party/blink/public/common/screen_orientation/web_screen_orientation_type.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/dom_exception.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/modules/event_target_modules.h"
......@@ -129,9 +128,7 @@ const WTF::AtomicString& ScreenOrientation::InterfaceName() const {
}
ExecutionContext* ScreenOrientation::GetExecutionContext() const {
if (!GetFrame())
return nullptr;
return GetFrame()->GetDocument()->ToExecutionContext();
return ExecutionContextClient::GetExecutionContext();
}
String ScreenOrientation::type() const {
......@@ -153,19 +150,17 @@ void ScreenOrientation::SetAngle(uint16_t angle) {
ScriptPromise ScreenOrientation::lock(ScriptState* state,
const AtomicString& lock_string,
ExceptionState& exception_state) {
Document* document = GetFrame() ? GetFrame()->GetDocument() : nullptr;
if (!document || !Controller()) {
if (!state->ContextIsValid() || !Controller()) {
exception_state.ThrowDOMException(
DOMExceptionCode::kInvalidStateError,
"The object is no longer associated to a document.");
"The object is no longer associated to a window.");
return ScriptPromise();
}
if (document->IsSandboxed(
if (GetExecutionContext()->IsSandboxed(
network::mojom::blink::WebSandboxFlags::kOrientationLock)) {
exception_state.ThrowSecurityError(
"The document is sandboxed and lacks the "
"The window is sandboxed and lacks the "
"'allow-orientation-lock' flag.");
return ScriptPromise();
}
......
......@@ -9,6 +9,7 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/core/dom/dom_exception.h"
#include "third_party/blink/renderer/core/event_type_names.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/modules/sensor/sensor_provider_proxy.h"
#include "third_party/blink/renderer/modules/sensor/sensor_test_utils.h"
......@@ -99,7 +100,8 @@ TEST(AmbientLightSensorTest, IlluminanceRounding) {
// the order that each observer is notified is arbitrary, we know that by the
// time we get to the next call here all observers will have been called.
auto* sensor_proxy =
SensorProviderProxy::From(Document::From(context.GetExecutionContext()))
SensorProviderProxy::From(
To<LocalDOMWindow>(context.GetExecutionContext()))
->GetSensorProxy(device::mojom::blink::SensorType::AMBIENT_LIGHT);
ASSERT_NE(sensor_proxy, nullptr);
auto* mock_observer = MakeGarbageCollected<MockSensorProxyObserver>();
......@@ -169,7 +171,8 @@ TEST(AmbientLightSensorTest, PlatformSensorReadingsBeforeActivation) {
sensor->start();
auto* sensor_proxy =
SensorProviderProxy::From(Document::From(context.GetExecutionContext()))
SensorProviderProxy::From(
To<LocalDOMWindow>(context.GetExecutionContext()))
->GetSensorProxy(device::mojom::blink::SensorType::AMBIENT_LIGHT);
ASSERT_NE(sensor_proxy, nullptr);
auto* mock_observer = MakeGarbageCollected<MockSensorProxyObserver>();
......
......@@ -10,7 +10,6 @@
#include "services/device/public/mojom/sensor.mojom-blink.h"
#include "third_party/blink/public/mojom/feature_policy/feature_policy.mojom-blink.h"
#include "third_party/blink/public/platform/task_type.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/inspector/console_message.h"
#include "third_party/blink/renderer/core/timing/dom_window_performance.h"
......@@ -26,11 +25,11 @@ namespace {
const double kWaitingIntervalThreshold = 0.01;
bool AreFeaturesEnabled(
Document* document,
ExecutionContext* context,
const Vector<mojom::blink::FeaturePolicyFeature>& features) {
return std::all_of(features.begin(), features.end(),
[document](mojom::blink::FeaturePolicyFeature feature) {
return document->IsFeatureEnabled(
[context](mojom::blink::FeaturePolicyFeature feature) {
return context->IsFeatureEnabled(
feature, ReportOptions::kReportOnFailure);
});
}
......@@ -50,9 +49,8 @@ Sensor::Sensor(ExecutionContext* execution_context,
// [SecureContext] in idl.
DCHECK(execution_context->IsSecureContext());
DCHECK(!features.IsEmpty());
Document* document = Document::From(execution_context);
if (!AreFeaturesEnabled(document, features)) {
if (!AreFeaturesEnabled(execution_context, features)) {
exception_state.ThrowSecurityError(
"Access to sensor features is disallowed by feature policy");
return;
......@@ -177,15 +175,14 @@ void Sensor::InitSensorProxyIfNeeded() {
if (sensor_proxy_)
return;
Document* document = Document::From(GetExecutionContext());
if (!document || !document->GetFrame())
return;
auto* provider = SensorProviderProxy::From(document);
LocalDOMWindow* window = To<LocalDOMWindow>(GetExecutionContext());
auto* provider = SensorProviderProxy::From(window);
sensor_proxy_ = provider->GetSensorProxy(type_);
if (!sensor_proxy_)
sensor_proxy_ = provider->CreateSensorProxy(type_, document->GetPage());
if (!sensor_proxy_) {
sensor_proxy_ =
provider->CreateSensorProxy(type_, window->GetFrame()->GetPage());
}
}
void Sensor::ContextDestroyed() {
......
......@@ -4,7 +4,7 @@
#include "third_party/blink/renderer/modules/sensor/sensor_inspector_agent.h"
#include "third_party/blink/renderer/core/dom/document.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/inspector/console_message.h"
#include "third_party/blink/renderer/modules/sensor/sensor_provider_proxy.h"
......@@ -14,8 +14,8 @@
namespace blink {
SensorInspectorAgent::SensorInspectorAgent(Document* document)
: provider_(SensorProviderProxy::From(document)) {}
SensorInspectorAgent::SensorInspectorAgent(LocalDOMWindow* window)
: provider_(SensorProviderProxy::From(window)) {}
void SensorInspectorAgent::Trace(Visitor* visitor) {
visitor->Trace(provider_);
......@@ -62,14 +62,14 @@ const char kInspectorConsoleMessage[] =
} // namespace
void SensorInspectorAgent::DidCommitLoadForLocalFrame(LocalFrame* frame) {
Document* current_document = provider_->GetSupplementable();
Document* new_document = frame->GetDocument();
if (current_document != new_document) {
LocalDOMWindow* current_window = provider_->GetSupplementable();
LocalDOMWindow* new_window = frame->DomWindow();
if (current_window != new_window) {
// We need to manually reset |provider_| to drop the strong reference it
// has to an old document that would otherwise be prevented from being
// has to an old window that would otherwise be prevented from being
// deleted.
bool inspector_mode = provider_->inspector_mode();
provider_ = SensorProviderProxy::From(new_document);
provider_ = SensorProviderProxy::From(new_window);
provider_->set_inspector_mode(inspector_mode);
}
}
......@@ -78,12 +78,11 @@ void SensorInspectorAgent::SetOrientationSensorOverride(double alpha,
double beta,
double gamma) {
if (!provider_->inspector_mode()) {
Document* document = provider_->GetSupplementable();
if (document) {
if (LocalDOMWindow* window = provider_->GetSupplementable()) {
auto* console_message = MakeGarbageCollected<ConsoleMessage>(
mojom::ConsoleMessageSource::kJavaScript,
mojom::ConsoleMessageLevel::kInfo, kInspectorConsoleMessage);
document->AddConsoleMessage(console_message);
window->AddConsoleMessage(console_message);
}
provider_->set_inspector_mode(true);
}
......
......@@ -9,13 +9,13 @@
namespace blink {
class Document;
class LocalDOMWindow;
class LocalFrame;
class SensorProviderProxy;
class SensorInspectorAgent : public GarbageCollected<SensorInspectorAgent> {
public:
explicit SensorInspectorAgent(Document* document);
explicit SensorInspectorAgent(LocalDOMWindow* window);
virtual void Trace(Visitor*);
void DidCommitLoadForLocalFrame(LocalFrame* frame);
......
......@@ -12,9 +12,9 @@
namespace blink {
// SensorProviderProxy
SensorProviderProxy::SensorProviderProxy(Document& document)
: Supplement<Document>(document),
sensor_provider_(document.ToExecutionContext()),
SensorProviderProxy::SensorProviderProxy(LocalDOMWindow& window)
: Supplement<LocalDOMWindow>(window),
sensor_provider_(&window),
inspector_mode_(false) {}
void SensorProviderProxy::InitializeIfNeeded() {
......@@ -33,13 +33,13 @@ void SensorProviderProxy::InitializeIfNeeded() {
const char SensorProviderProxy::kSupplementName[] = "SensorProvider";
// static
SensorProviderProxy* SensorProviderProxy::From(Document* document) {
DCHECK(document);
SensorProviderProxy* SensorProviderProxy::From(LocalDOMWindow* window) {
DCHECK(window);
SensorProviderProxy* provider_proxy =
Supplement<Document>::From<SensorProviderProxy>(*document);
Supplement<LocalDOMWindow>::From<SensorProviderProxy>(*window);
if (!provider_proxy) {
provider_proxy = MakeGarbageCollected<SensorProviderProxy>(*document);
Supplement<Document>::ProvideTo(*document, provider_proxy);
provider_proxy = MakeGarbageCollected<SensorProviderProxy>(*window);
Supplement<LocalDOMWindow>::ProvideTo(*window, provider_proxy);
}
provider_proxy->InitializeIfNeeded();
return provider_proxy;
......@@ -50,7 +50,7 @@ SensorProviderProxy::~SensorProviderProxy() = default;
void SensorProviderProxy::Trace(Visitor* visitor) {
visitor->Trace(sensor_proxies_);
visitor->Trace(sensor_provider_);
Supplement<Document>::Trace(visitor);
Supplement<LocalDOMWindow>::Trace(visitor);
}
SensorProxy* SensorProviderProxy::CreateSensorProxy(
......
......@@ -8,7 +8,7 @@
#include "base/macros.h"
#include "services/device/public/mojom/sensor.mojom-blink-forward.h"
#include "services/device/public/mojom/sensor_provider.mojom-blink.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/modules/modules_export.h"
#include "third_party/blink/renderer/platform/heap/handle.h"
#include "third_party/blink/renderer/platform/mojo/heap_mojo_remote.h"
......@@ -23,15 +23,15 @@ class SensorProxy;
// 'SensorProxy' instances.
class MODULES_EXPORT SensorProviderProxy final
: public GarbageCollected<SensorProviderProxy>,
public Supplement<Document> {
public Supplement<LocalDOMWindow> {
USING_GARBAGE_COLLECTED_MIXIN(SensorProviderProxy);
public:
static const char kSupplementName[];
static SensorProviderProxy* From(Document*);
static SensorProviderProxy* From(LocalDOMWindow*);
explicit SensorProviderProxy(Document&);
explicit SensorProviderProxy(LocalDOMWindow&);
~SensorProviderProxy();
SensorProxy* CreateSensorProxy(device::mojom::blink::SensorType, Page*);
......
......@@ -4,8 +4,7 @@
#include "third_party/blink/renderer/modules/serial/navigator_serial.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/modules/serial/serial.h"
namespace blink {
......@@ -33,10 +32,8 @@ void NavigatorSerial::Trace(Visitor* visitor) {
NavigatorSerial::NavigatorSerial(Navigator& navigator)
: Supplement<Navigator>(navigator) {
if (navigator.GetFrame()) {
DCHECK(navigator.GetFrame()->GetDocument());
serial_ = MakeGarbageCollected<Serial>(
*navigator.GetFrame()->GetDocument()->ToExecutionContext());
if (navigator.DomWindow()) {
serial_ = MakeGarbageCollected<Serial>(*navigator.DomWindow());
}
}
......
......@@ -109,8 +109,7 @@ ServiceWorkerContainer* NavigatorServiceWorker::GetOrCreateContainer(
WebFeature::kFileAccessedServiceWorker);
}
return ServiceWorkerContainer::From(
Document::From(frame->DomWindow()->GetExecutionContext()));
return ServiceWorkerContainer::From(frame->GetDocument());
}
void NavigatorServiceWorker::Trace(Visitor* visitor) {
......
......@@ -42,6 +42,7 @@
#include "third_party/blink/renderer/bindings/core/v8/v8_post_message_options.h"
#include "third_party/blink/renderer/core/dom/events/event.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/messaging/blink_transferable_message.h"
#include "third_party/blink/renderer/core/messaging/message_port.h"
#include "third_party/blink/renderer/modules/event_target_modules.h"
......@@ -165,7 +166,7 @@ ServiceWorker* ServiceWorker::From(ExecutionContext* context,
return scope->GetOrCreateServiceWorker(std::move(info));
}
return ServiceWorkerContainer::From(Document::From(context))
return ServiceWorkerContainer::From(To<LocalDOMWindow>(context)->document())
->GetOrCreateServiceWorker(std::move(info));
}
......
......@@ -79,12 +79,12 @@ namespace {
void MaybeRecordThirdPartyServiceWorkerUsage(
ExecutionContext* execution_context) {
DCHECK(execution_context);
// ServiceWorkerContainer is only supported on documents.
Document* document = Document::From(execution_context);
DCHECK(document);
// ServiceWorkerContainer is only supported on windows.
LocalDOMWindow* window = To<LocalDOMWindow>(execution_context);
DCHECK(window);
if (document->IsCrossSiteSubframe())
UseCounter::Count(document, WebFeature::kThirdPartyServiceWorker);
if (window->document()->IsCrossSiteSubframe())
UseCounter::Count(window, WebFeature::kThirdPartyServiceWorker);
}
bool HasFiredDomContentLoaded(const Document& document) {
......@@ -143,7 +143,7 @@ class ServiceWorkerContainer::DomContentLoadedListener final
void Invoke(ExecutionContext* execution_context, Event* event) override {
DCHECK_EQ(event->type(), "DOMContentLoaded");
Document& document = *Document::From(execution_context);
Document& document = *To<LocalDOMWindow>(execution_context)->document();
DCHECK(HasFiredDomContentLoaded(document));
auto* container =
......@@ -507,11 +507,11 @@ void ServiceWorkerContainer::SetController(
void ServiceWorkerContainer::ReceiveMessage(WebServiceWorkerObjectInfo source,
TransferableMessage message) {
auto* context = GetExecutionContext();
if (!context || !context->ExecutingWindow())
auto* window = DynamicTo<LocalDOMWindow>(GetExecutionContext());
if (!window)
return;
// ServiceWorkerContainer is only supported on documents.
auto* document = Document::DynamicFrom(context);
auto* document = window->document();
DCHECK(document);
if (!is_client_message_queue_enabled_) {
......@@ -555,7 +555,7 @@ void ServiceWorkerContainer::CountFeature(mojom::WebFeature feature) {
}
ExecutionContext* ServiceWorkerContainer::GetExecutionContext() const {
return GetSupplementable()->ToExecutionContext();
return GetSupplementable()->GetExecutionContext();
}
const AtomicString& ServiceWorkerContainer::InterfaceName() const {
......@@ -588,7 +588,7 @@ ServiceWorkerContainer::GetOrCreateServiceWorkerRegistration(
}
registration = MakeGarbageCollected<ServiceWorkerRegistration>(
GetSupplementable()->ToExecutionContext(), std::move(info));
GetSupplementable()->GetExecutionContext(), std::move(info));
service_worker_registration_objects_.Set(info.registration_id, registration);
return registration;
}
......@@ -599,7 +599,7 @@ ServiceWorker* ServiceWorkerContainer::GetOrCreateServiceWorker(
return nullptr;
ServiceWorker* worker = service_worker_objects_.at(info.version_id);
if (!worker) {
worker = ServiceWorker::Create(GetSupplementable()->ToExecutionContext(),
worker = ServiceWorker::Create(GetSupplementable()->GetExecutionContext(),
std::move(info));
service_worker_objects_.Set(info.version_id, worker);
}
......@@ -680,7 +680,7 @@ void ServiceWorkerContainer::OnGetRegistrationForReady(
!ready_->GetExecutionContext()->IsContextDestroyed()) {
ready_->Resolve(
ServiceWorkerContainer::From(
Document::From(ready_->GetExecutionContext()))
To<LocalDOMWindow>(ready_->GetExecutionContext())->document())
->GetOrCreateServiceWorkerRegistration(std::move(info)));
}
}
......
......@@ -17,6 +17,7 @@
#include "third_party/blink/renderer/core/dom/dom_exception.h"
#include "third_party/blink/renderer/core/dom/events/event.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/modules/event_target_modules.h"
#include "third_party/blink/renderer/modules/service_worker/service_worker_container.h"
#include "third_party/blink/renderer/modules/service_worker/service_worker_error.h"
......@@ -131,7 +132,7 @@ ServiceWorkerRegistration* ServiceWorkerRegistration::Take(
ScriptPromiseResolver* resolver,
WebServiceWorkerRegistrationObjectInfo info) {
return ServiceWorkerContainer::From(
Document::From(resolver->GetExecutionContext()))
To<LocalDOMWindow>(resolver->GetExecutionContext())->document())
->GetOrCreateServiceWorkerRegistration(std::move(info));
}
......
......@@ -25,7 +25,6 @@
#include "third_party/blink/renderer/modules/speech/speech_grammar.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
namespace blink {
......@@ -39,8 +38,7 @@ SpeechGrammar* SpeechGrammar::Create(const KURL& src, double weight) {
}
void SpeechGrammar::setSrc(ScriptState* script_state, const String& src) {
Document* document = Document::From(ExecutionContext::From(script_state));
src_ = document->CompleteURL(src);
src_ = ExecutionContext::From(script_state)->CompleteURL(src);
}
SpeechGrammar::SpeechGrammar() : weight_(1.0) {}
......
......@@ -25,7 +25,6 @@
#include "third_party/blink/renderer/modules/speech/speech_grammar_list.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/platform/bindings/script_state.h"
......@@ -45,9 +44,8 @@ SpeechGrammar* SpeechGrammarList::item(unsigned index) const {
void SpeechGrammarList::addFromUri(ScriptState* script_state,
const String& src,
double weight) {
Document* document = Document::From(ExecutionContext::From(script_state));
grammars_.push_back(
SpeechGrammar::Create(document->CompleteURL(src), weight));
ExecutionContext* context = ExecutionContext::From(script_state);
grammars_.push_back(SpeechGrammar::Create(context->CompleteURL(src), weight));
}
void SpeechGrammarList::addFromString(const String& string, double weight) {
......
......@@ -29,7 +29,7 @@
#include "build/build_config.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "third_party/blink/renderer/core/dom/document.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/page/page.h"
#include "third_party/blink/renderer/modules/speech/speech_recognition_controller.h"
......@@ -41,8 +41,8 @@
namespace blink {
SpeechRecognition* SpeechRecognition::Create(ExecutionContext* context) {
Document& document = Document::From(*context);
return MakeGarbageCollected<SpeechRecognition>(document.GetFrame(), context);
LocalDOMWindow* window = To<LocalDOMWindow>(context);
return MakeGarbageCollected<SpeechRecognition>(window->GetFrame(), context);
}
void SpeechRecognition::start(ExceptionState& exception_state) {
......
......@@ -34,6 +34,7 @@
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/frame/deprecation.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/html/media/autoplay_policy.h"
#include "third_party/blink/renderer/core/timing/dom_window_performance.h"
#include "third_party/blink/renderer/core/timing/performance.h"
......@@ -104,20 +105,21 @@ bool SpeechSynthesis::paused() const {
return is_paused_;
}
void SpeechSynthesis::speak(SpeechSynthesisUtterance* utterance) {
void SpeechSynthesis::speak(ScriptState* script_state,
SpeechSynthesisUtterance* utterance) {
DCHECK(utterance);
Document* document = Document::From(GetExecutionContext());
if (!document)
if (!script_state->ContextIsValid())
return;
// Note: Non-UseCounter based TTS metrics are of the form TextToSpeech.* and
// are generally global, whereas these are scoped to a single page load.
UseCounter::Count(document, WebFeature::kTextToSpeech_Speak);
document->CountUseOnlyInCrossOriginIframe(
LocalDOMWindow* window = To<LocalDOMWindow>(GetExecutionContext());
UseCounter::Count(window, WebFeature::kTextToSpeech_Speak);
window->document()->CountUseOnlyInCrossOriginIframe(
WebFeature::kTextToSpeech_SpeakCrossOrigin);
if (!IsAllowedToStartByAutoplay()) {
Deprecation::CountDeprecation(
document, WebFeature::kTextToSpeech_SpeakDisallowedByAutoplay);
window, WebFeature::kTextToSpeech_SpeakDisallowedByAutoplay);
FireErrorEvent(utterance, 0 /* char_index */, "not-allowed");
return;
}
......@@ -299,19 +301,16 @@ void SpeechSynthesis::Trace(Visitor* visitor) {
bool SpeechSynthesis::GetElapsedTimeMillis(double* millis) {
if (!GetExecutionContext())
return false;
Document* delegate_document = Document::From(GetExecutionContext());
if (!delegate_document || delegate_document->IsStopped())
return false;
LocalDOMWindow* delegate_dom_window = delegate_document->domWindow();
if (!delegate_dom_window)
LocalDOMWindow* window = To<LocalDOMWindow>(GetExecutionContext());
if (window->document()->IsStopped())
return false;
*millis = DOMWindowPerformance::performance(*delegate_dom_window)->now();
*millis = DOMWindowPerformance::performance(*window)->now();
return true;
}
bool SpeechSynthesis::IsAllowedToStartByAutoplay() const {
Document* document = Document::From(GetExecutionContext());
Document* document = To<LocalDOMWindow>(GetExecutionContext())->document();
DCHECK(document);
// Note: could check the utterance->volume here, but that could be overriden
......
......@@ -58,7 +58,7 @@ class MODULES_EXPORT SpeechSynthesis final
bool speaking() const;
bool paused() const;
void speak(SpeechSynthesisUtterance*);
void speak(ScriptState*, SpeechSynthesisUtterance*);
void cancel();
void pause();
void resume();
......
......@@ -32,7 +32,7 @@
readonly attribute boolean speaking;
readonly attribute boolean paused;
[Measure] void speak(SpeechSynthesisUtterance utterance);
[CallWith=ScriptState, Measure] void speak(SpeechSynthesisUtterance utterance);
void cancel();
void pause();
void resume();
......
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