Commit 359f932b authored by Nate Chapin's avatar Nate Chapin Committed by Commit Bot

ExecutionContext post-migration cleanup - modules/{a*,b*}

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: I208d233652916cbb19b06e24090289995012611c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2111066
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@{#761100}
parent 609ec592
......@@ -129,8 +129,8 @@ AXObjectCacheImpl::AXObjectCacheImpl(Document& document)
validation_message_axid_(0),
relation_cache_(std::make_unique<AXRelationCache>(this)),
accessibility_event_permission_(mojom::blink::PermissionStatus::ASK),
permission_service_(document.ToExecutionContext()),
permission_observer_receiver_(this, document.ToExecutionContext()) {
permission_service_(document.GetExecutionContext()),
permission_observer_receiver_(this, document.GetExecutionContext()) {
if (document_->LoadEventFinished())
AddPermissionStatusListener();
documents_.insert(&document);
......
......@@ -7,6 +7,7 @@
#include "base/atomic_sequence_num.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.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/page/chrome_client.h"
#include "third_party/blink/renderer/core/workers/worker_clients.h"
#include "third_party/blink/renderer/modules/animationworklet/animation_worklet_messaging_proxy.h"
......@@ -41,7 +42,7 @@ WorkletGlobalScopeProxy* AnimationWorklet::CreateGlobalScope() {
// initialization can move to the constructor. Currently, initialization
// in the constructor leads to test failures as the document frame has not
// been initialized at the time of the constructor call.
Document* document = Document::From(GetExecutionContext());
Document* document = To<LocalDOMWindow>(GetExecutionContext())->document();
proxy_client_ =
AnimationWorkletProxyClient::FromDocument(document, worklet_id_);
}
......
......@@ -214,7 +214,7 @@ WorkletAnimation* WorkletAnimation::Create(
return nullptr;
}
Document& document = *Document::From(ExecutionContext::From(script_state));
Document& document = *LocalDOMWindow::From(script_state)->document();
if (!document.GetWorkletAnimationController().IsAnimatorRegistered(
animator_name)) {
exception_state.ThrowDOMException(
......
......@@ -8,6 +8,7 @@
#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/local_dom_window.h"
#include "third_party/blink/renderer/core/frame/web_feature.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/heap/heap.h"
......@@ -28,8 +29,8 @@ BeforeInstallPromptEvent::BeforeInstallPromptEvent(
std::move(event_receiver),
frame.GetTaskRunner(TaskType::kApplicationLifeCycle)),
platforms_(platforms),
user_choice_(MakeGarbageCollected<UserChoiceProperty>(
frame.GetDocument()->ToExecutionContext())) {
user_choice_(
MakeGarbageCollected<UserChoiceProperty>(frame.DomWindow())) {
DCHECK(banner_service_remote_);
DCHECK(receiver_.is_bound());
UseCounter::Count(frame.GetDocument(), WebFeature::kBeforeInstallPromptEvent);
......@@ -81,18 +82,16 @@ ScriptPromise BeforeInstallPromptEvent::prompt(
return ScriptPromise();
}
ExecutionContext* context = ExecutionContext::From(script_state);
Document* doc = Document::From(context);
if (!LocalFrame::ConsumeTransientUserActivation(doc ? doc->GetFrame()
: nullptr)) {
LocalDOMWindow* window = LocalDOMWindow::From(script_state);
if (!LocalFrame::ConsumeTransientUserActivation(window ? window->GetFrame()
: nullptr)) {
exception_state.ThrowDOMException(
DOMExceptionCode::kNotAllowedError,
"The prompt() method must be called with a user gesture");
return ScriptPromise();
}
UseCounter::Count(context, WebFeature::kBeforeInstallPromptEventPrompt);
UseCounter::Count(window, WebFeature::kBeforeInstallPromptEventPrompt);
banner_service_remote_->DisplayAppBanner();
return user_choice_->Promise(script_state->World());
}
......
......@@ -12,9 +12,9 @@
#include "third_party/blink/public/platform/web_set_sink_id_callbacks.h"
#include "third_party/blink/public/web/web_local_frame_client.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/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/frame/web_local_frame_impl.h"
#include "third_party/blink/renderer/platform/bindings/script_state.h"
#include "third_party/blink/renderer/platform/heap/heap.h"
......@@ -116,11 +116,9 @@ void SetSinkIdResolver::DoSetSinkId() {
return;
}
// This is associated with an HTML element, so the context must be a Document.
auto& document = Document::From(*context);
WebLocalFrameImpl* web_frame =
WebLocalFrameImpl::FromFrame(document.GetFrame());
if (web_frame && web_frame->Client()) {
// This is associated with an HTML element, so the context must be a window.
if (WebLocalFrameImpl* web_frame = WebLocalFrameImpl::FromFrame(
To<LocalDOMWindow>(context)->GetFrame())) {
web_frame->Client()->CheckIfAudioSinkExistsAndIsAuthorized(
sink_id_, std::move(set_sink_id_completion_callback));
} else {
......
......@@ -10,6 +10,7 @@
#include "third_party/blink/public/platform/web_url_loader_mock_factory.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_image_resource.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/testing/page_test_base.h"
#include "third_party/blink/renderer/platform/heap/persistent.h"
#include "third_party/blink/renderer/platform/testing/testing_platform_support.h"
......@@ -115,9 +116,7 @@ class BackgroundFetchIconLoaderTest : public PageTestBase {
maximum_size);
}
ExecutionContext* GetContext() const {
return GetDocument().ToExecutionContext();
}
ExecutionContext* GetContext() const { return GetFrame().DomWindow(); }
protected:
ScopedTestingPlatformSupport<TestingPlatformSupport> platform_;
......
......@@ -5,10 +5,10 @@
#include "third_party/blink/renderer/modules/battery/battery_manager.h"
#include "third_party/blink/public/mojom/frame/lifecycle.mojom-blink.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/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/battery/battery_dispatcher.h"
#include "third_party/blink/renderer/platform/wtf/assertions.h"
......@@ -25,7 +25,7 @@ BatteryManager::~BatteryManager() = default;
BatteryManager::BatteryManager(ExecutionContext* context)
: ExecutionContextLifecycleStateObserver(context),
PlatformEventController(Document::From(context)) {}
PlatformEventController(To<LocalDOMWindow>(context)->document()) {}
ScriptPromise BatteryManager::StartRequest(ScriptState* script_state) {
if (!battery_property_) {
......@@ -71,10 +71,11 @@ void BatteryManager::DidUpdateData() {
return;
}
Document* document = Document::From(GetExecutionContext());
DCHECK(document);
if (document->IsContextPaused() || document->IsContextDestroyed())
DCHECK(GetExecutionContext());
if (GetExecutionContext()->IsContextPaused() ||
GetExecutionContext()->IsContextDestroyed()) {
return;
}
if (battery_status_.Charging() != old_status.Charging())
DispatchEvent(*Event::Create(event_type_names::kChargingchange));
......
......@@ -4,8 +4,8 @@
#include "third_party/blink/renderer/modules/battery/navigator_battery.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/local_dom_window.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/modules/battery/battery_manager.h"
#include "third_party/blink/renderer/platform/instrumentation/use_counter.h"
......@@ -21,15 +21,14 @@ ScriptPromise NavigatorBattery::getBattery(ScriptState* script_state,
}
ScriptPromise NavigatorBattery::getBattery(ScriptState* script_state) {
ExecutionContext* context = ExecutionContext::From(script_state);
LocalDOMWindow* window = LocalDOMWindow::From(script_state);
// Check to see if this request would be blocked according to the Battery
// Status API specification.
if (auto* document = Document::From(context)) {
LocalFrame* frame = document->GetFrame();
if (frame) {
if (!context->IsSecureContext())
UseCounter::Count(document, WebFeature::kBatteryStatusInsecureOrigin);
if (window) {
if (LocalFrame* frame = window->GetFrame()) {
if (!window->IsSecureContext())
UseCounter::Count(window, WebFeature::kBatteryStatusInsecureOrigin);
frame->CountUseIfFeatureWouldBeBlockedByFeaturePolicy(
WebFeature::kBatteryStatusCrossOrigin,
WebFeature::kBatteryStatusSameOriginABA);
......@@ -37,7 +36,7 @@ ScriptPromise NavigatorBattery::getBattery(ScriptState* script_state) {
}
if (!battery_manager_)
battery_manager_ = BatteryManager::Create(context);
battery_manager_ = BatteryManager::Create(window);
return battery_manager_->StartRequest(script_state);
}
......
......@@ -18,11 +18,11 @@
#include "third_party/blink/renderer/bindings/modules/v8/v8_bluetooth_advertising_event_init.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_bluetooth_le_scan_options.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_request_device_options.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/events/event.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/inspector/console_message.h"
#include "third_party/blink/renderer/modules/bluetooth/bluetooth_advertising_event.h"
......@@ -255,8 +255,7 @@ ScriptPromise Bluetooth::requestDevice(ScriptState* script_state,
// If the algorithm is not allowed to show a popup, reject promise with a
// SecurityError and abort these steps.
auto& doc = *Document::From(context);
auto* frame = doc.GetFrame();
auto* frame = To<LocalDOMWindow>(context)->GetFrame();
if (!frame) {
exception_state.ThrowTypeError(kInactiveDocumentError);
return ScriptPromise();
......@@ -367,8 +366,7 @@ ScriptPromise Bluetooth::requestLEScan(ScriptState* script_state,
// If the algorithm is not allowed to show a popup, reject promise with a
// SecurityError and abort these steps.
auto& doc = *Document::From(context);
auto* frame = doc.GetFrame();
auto* frame = To<LocalDOMWindow>(context)->GetFrame();
if (!frame) {
exception_state.ThrowTypeError(kInactiveDocumentError);
return ScriptPromise();
......@@ -476,7 +474,8 @@ void Bluetooth::Trace(Visitor* visitor) {
Bluetooth::Bluetooth(ExecutionContext* context)
: ExecutionContextLifecycleObserver(context),
PageVisibilityObserver(Document::From(context)->GetPage()) {}
PageVisibilityObserver(
To<LocalDOMWindow>(context)->GetFrame()->GetPage()) {}
Bluetooth::~Bluetooth() {
DCHECK(client_receivers_.empty());
......
......@@ -11,6 +11,7 @@
#include "third_party/blink/renderer/bindings/core/v8/serialization/serialized_script_value.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/events/message_event.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/platform/mojo/mojo_helper.h"
#include "third_party/blink/renderer/platform/wtf/functional.h"
......@@ -41,9 +42,9 @@ GetThreadSpecificProvider() {
BroadcastChannel* BroadcastChannel::Create(ExecutionContext* execution_context,
const String& name,
ExceptionState& exception_state) {
Document* document = Document::DynamicFrom(execution_context);
if (document && document->IsCrossSiteSubframe())
UseCounter::Count(document, WebFeature::kThirdPartyBroadcastChannel);
LocalDOMWindow* window = DynamicTo<LocalDOMWindow>(execution_context);
if (window && window->document()->IsCrossSiteSubframe())
UseCounter::Count(window, WebFeature::kThirdPartyBroadcastChannel);
if (execution_context->GetSecurityOrigin()->IsOpaque()) {
// TODO(mek): Decide what to do here depending on
......
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