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