Commit 35f73854 authored by Nate Chapin's avatar Nate Chapin Committed by Commit Bot

Remove the final usage of the LocalFrame* ExecutionContextClient constructor variant

Change-Id: I8c19316f71a74160d470cbc9cd0fd5073b25435b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2491001
Auto-Submit: Nate Chapin <japhet@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Nate Chapin <japhet@chromium.org>
Cr-Commit-Position: refs/heads/master@{#819896}
parent 0840d914
...@@ -14,9 +14,6 @@ ExecutionContextClient::ExecutionContextClient( ...@@ -14,9 +14,6 @@ ExecutionContextClient::ExecutionContextClient(
ExecutionContext* execution_context) ExecutionContext* execution_context)
: execution_context_(execution_context) {} : execution_context_(execution_context) {}
ExecutionContextClient::ExecutionContextClient(LocalFrame* frame)
: execution_context_(frame ? frame->DomWindow() : nullptr) {}
ExecutionContext* ExecutionContextClient::GetExecutionContext() const { ExecutionContext* ExecutionContextClient::GetExecutionContext() const {
return execution_context_ && !execution_context_->IsContextDestroyed() return execution_context_ && !execution_context_->IsContextDestroyed()
? execution_context_.Get() ? execution_context_.Get()
...@@ -53,8 +50,12 @@ void ExecutionContextLifecycleObserver::SetExecutionContext( ...@@ -53,8 +50,12 @@ void ExecutionContextLifecycleObserver::SetExecutionContext(
SetContextLifecycleNotifier(execution_context); SetContextLifecycleNotifier(execution_context);
} }
LocalDOMWindow* ExecutionContextLifecycleObserver::DomWindow() const {
return DynamicTo<LocalDOMWindow>(GetExecutionContext());
}
LocalFrame* ExecutionContextLifecycleObserver::GetFrame() const { LocalFrame* ExecutionContextLifecycleObserver::GetFrame() const {
auto* window = DynamicTo<LocalDOMWindow>(GetExecutionContext()); auto* window = DomWindow();
return window ? window->GetFrame() : nullptr; return window ? window->GetFrame() : nullptr;
} }
......
...@@ -81,7 +81,6 @@ class CORE_EXPORT ExecutionContextClient : public GarbageCollectedMixin { ...@@ -81,7 +81,6 @@ class CORE_EXPORT ExecutionContextClient : public GarbageCollectedMixin {
protected: protected:
explicit ExecutionContextClient(ExecutionContext*); explicit ExecutionContextClient(ExecutionContext*);
explicit ExecutionContextClient(LocalFrame*);
private: private:
WeakMember<ExecutionContext> execution_context_; WeakMember<ExecutionContext> execution_context_;
...@@ -111,6 +110,10 @@ class CORE_EXPORT ExecutionContextLifecycleObserver ...@@ -111,6 +110,10 @@ class CORE_EXPORT ExecutionContextLifecycleObserver
ExecutionContext* GetExecutionContext() const; ExecutionContext* GetExecutionContext() const;
virtual void SetExecutionContext(ExecutionContext*); virtual void SetExecutionContext(ExecutionContext*);
// If the execution context is a window, returns it. Returns nullptr if the
// execution context is not a window or if it has been detached.
LocalDOMWindow* DomWindow() const;
// If associated with a live document, returns the associated frame. // If associated with a live document, returns the associated frame.
// Returns null otherwise. // Returns null otherwise.
LocalFrame* GetFrame() const; LocalFrame* GetFrame() const;
......
...@@ -36,7 +36,7 @@ void AppBannerController::BannerPromptRequest( ...@@ -36,7 +36,7 @@ void AppBannerController::BannerPromptRequest(
const Vector<String>& platforms, const Vector<String>& platforms,
BannerPromptRequestCallback callback) { BannerPromptRequestCallback callback) {
// TODO(hajimehoshi): Add tests for the case the frame is detached. // TODO(hajimehoshi): Add tests for the case the frame is detached.
if (!frame_ || !frame_->GetDocument() || !frame_->IsAttached()) { if (!frame_ || !frame_->DomWindow() || !frame_->IsAttached()) {
std::move(callback).Run(mojom::blink::AppBannerPromptReply::NONE); std::move(callback).Run(mojom::blink::AppBannerPromptReply::NONE);
return; return;
} }
...@@ -50,7 +50,7 @@ void AppBannerController::BannerPromptRequest( ...@@ -50,7 +50,7 @@ void AppBannerController::BannerPromptRequest(
mojom::AppBannerPromptReply reply = mojom::AppBannerPromptReply reply =
frame_->DomWindow()->DispatchEvent(*BeforeInstallPromptEvent::Create( frame_->DomWindow()->DispatchEvent(*BeforeInstallPromptEvent::Create(
event_type_names::kBeforeinstallprompt, *frame_, event_type_names::kBeforeinstallprompt, *frame_->DomWindow(),
std::move(service_remote), std::move(event_receiver), platforms)) == std::move(service_remote), std::move(event_receiver), platforms)) ==
DispatchEventResult::kNotCanceled DispatchEventResult::kNotCanceled
? mojom::AppBannerPromptReply::NONE ? mojom::AppBannerPromptReply::NONE
......
...@@ -18,25 +18,24 @@ namespace blink { ...@@ -18,25 +18,24 @@ namespace blink {
BeforeInstallPromptEvent::BeforeInstallPromptEvent( BeforeInstallPromptEvent::BeforeInstallPromptEvent(
const AtomicString& name, const AtomicString& name,
LocalFrame& frame, ExecutionContext& context,
mojo::PendingRemote<mojom::blink::AppBannerService> service_remote, mojo::PendingRemote<mojom::blink::AppBannerService> service_remote,
mojo::PendingReceiver<mojom::blink::AppBannerEvent> event_receiver, mojo::PendingReceiver<mojom::blink::AppBannerEvent> event_receiver,
const Vector<String>& platforms) const Vector<String>& platforms)
: Event(name, Bubbles::kNo, Cancelable::kYes), : Event(name, Bubbles::kNo, Cancelable::kYes),
ExecutionContextClient(&frame), ExecutionContextClient(&context),
banner_service_remote_(frame.DomWindow()), banner_service_remote_(&context),
receiver_(this, frame.DomWindow()), receiver_(this, &context),
platforms_(platforms), platforms_(platforms),
user_choice_( user_choice_(MakeGarbageCollected<UserChoiceProperty>(&context)) {
MakeGarbageCollected<UserChoiceProperty>(frame.DomWindow())) {
banner_service_remote_.Bind( banner_service_remote_.Bind(
std::move(service_remote), std::move(service_remote),
frame.GetTaskRunner(TaskType::kApplicationLifeCycle)); context.GetTaskRunner(TaskType::kApplicationLifeCycle));
receiver_.Bind(std::move(event_receiver), receiver_.Bind(std::move(event_receiver),
frame.GetTaskRunner(TaskType::kApplicationLifeCycle)); context.GetTaskRunner(TaskType::kApplicationLifeCycle));
DCHECK(banner_service_remote_.is_bound()); DCHECK(banner_service_remote_.is_bound());
DCHECK(receiver_.is_bound()); DCHECK(receiver_.is_bound());
UseCounter::Count(frame.GetDocument(), WebFeature::kBeforeInstallPromptEvent); UseCounter::Count(context, WebFeature::kBeforeInstallPromptEvent);
} }
BeforeInstallPromptEvent::BeforeInstallPromptEvent( BeforeInstallPromptEvent::BeforeInstallPromptEvent(
......
...@@ -22,7 +22,6 @@ namespace blink { ...@@ -22,7 +22,6 @@ namespace blink {
class BeforeInstallPromptEvent; class BeforeInstallPromptEvent;
class BeforeInstallPromptEventInit; class BeforeInstallPromptEventInit;
class ExceptionState; class ExceptionState;
class LocalFrame;
using UserChoiceProperty = ScriptPromiseProperty<Member<AppBannerPromptResult>, using UserChoiceProperty = ScriptPromiseProperty<Member<AppBannerPromptResult>,
ToV8UndefinedGenerator>; ToV8UndefinedGenerator>;
...@@ -36,7 +35,7 @@ class BeforeInstallPromptEvent final ...@@ -36,7 +35,7 @@ class BeforeInstallPromptEvent final
public: public:
BeforeInstallPromptEvent(const AtomicString& name, BeforeInstallPromptEvent(const AtomicString& name,
LocalFrame&, ExecutionContext&,
mojo::PendingRemote<mojom::blink::AppBannerService>, mojo::PendingRemote<mojom::blink::AppBannerService>,
mojo::PendingReceiver<mojom::blink::AppBannerEvent>, mojo::PendingReceiver<mojom::blink::AppBannerEvent>,
const Vector<String>& platforms); const Vector<String>& platforms);
...@@ -47,7 +46,7 @@ class BeforeInstallPromptEvent final ...@@ -47,7 +46,7 @@ class BeforeInstallPromptEvent final
static BeforeInstallPromptEvent* Create( static BeforeInstallPromptEvent* Create(
const AtomicString& name, const AtomicString& name,
LocalFrame& frame, ExecutionContext& frame,
mojo::PendingRemote<mojom::blink::AppBannerService> service_remote, mojo::PendingRemote<mojom::blink::AppBannerService> service_remote,
mojo::PendingReceiver<mojom::blink::AppBannerEvent> event_receiver, mojo::PendingReceiver<mojom::blink::AppBannerEvent> event_receiver,
const Vector<String>& platforms) { const Vector<String>& platforms) {
......
...@@ -5,14 +5,13 @@ ...@@ -5,14 +5,13 @@
#include "third_party/blink/renderer/modules/netinfo/navigator_network_information.h" #include "third_party/blink/renderer/modules/netinfo/navigator_network_information.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/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/navigator.h" #include "third_party/blink/renderer/core/frame/navigator.h"
#include "third_party/blink/renderer/modules/netinfo/network_information.h" #include "third_party/blink/renderer/modules/netinfo/network_information.h"
namespace blink { namespace blink {
NavigatorNetworkInformation::NavigatorNetworkInformation(Navigator& navigator) NavigatorNetworkInformation::NavigatorNetworkInformation(Navigator& navigator)
: ExecutionContextClient(navigator.GetFrame()) {} : ExecutionContextClient(navigator.DomWindow()) {}
NavigatorNetworkInformation& NavigatorNetworkInformation::From( NavigatorNetworkInformation& NavigatorNetworkInformation::From(
Navigator& navigator) { Navigator& navigator) {
...@@ -40,11 +39,8 @@ NetworkInformation* NavigatorNetworkInformation::connection( ...@@ -40,11 +39,8 @@ NetworkInformation* NavigatorNetworkInformation::connection(
} }
NetworkInformation* NavigatorNetworkInformation::connection() { NetworkInformation* NavigatorNetworkInformation::connection() {
if (!connection_ && GetFrame()) { if (!connection_ && DomWindow())
DCHECK(GetFrame()->DomWindow()); connection_ = MakeGarbageCollected<NetworkInformation>(DomWindow());
connection_ = MakeGarbageCollected<NetworkInformation>(
GetFrame()->DomWindow()->GetExecutionContext());
}
return connection_.Get(); return connection_.Get();
} }
......
...@@ -31,9 +31,9 @@ ...@@ -31,9 +31,9 @@
namespace blink { namespace blink {
DOMMimeType::DOMMimeType(LocalFrame* frame, DOMMimeType::DOMMimeType(LocalDOMWindow* window,
const MimeClassInfo& mime_class_info) const MimeClassInfo& mime_class_info)
: ExecutionContextClient(frame), mime_class_info_(&mime_class_info) {} : ExecutionContextClient(window), mime_class_info_(&mime_class_info) {}
void DOMMimeType::Trace(Visitor* visitor) const { void DOMMimeType::Trace(Visitor* visitor) const {
visitor->Trace(mime_class_info_); visitor->Trace(mime_class_info_);
...@@ -65,11 +65,12 @@ DOMPlugin* DOMMimeType::enabledPlugin() const { ...@@ -65,11 +65,12 @@ DOMPlugin* DOMMimeType::enabledPlugin() const {
// FIXME: allowPlugins is just a client call. We should not need // FIXME: allowPlugins is just a client call. We should not need
// to bounce through the loader to get there. // to bounce through the loader to get there.
// Something like: frame()->page()->client()->allowPlugins(). // Something like: frame()->page()->client()->allowPlugins().
if (!GetFrame() || if (!DomWindow() || !DomWindow()->GetFrame()->Loader().AllowPlugins(
!GetFrame()->Loader().AllowPlugins(kNotAboutToInstantiatePlugin)) kNotAboutToInstantiatePlugin)) {
return nullptr; return nullptr;
}
return NavigatorPlugins::plugins(*GetFrame()->DomWindow()->navigator()) return NavigatorPlugins::plugins(*DomWindow()->navigator())
->namedItem(AtomicString(mime_class_info_->Plugin()->Name())); ->namedItem(AtomicString(mime_class_info_->Plugin()->Name()));
} }
......
...@@ -30,14 +30,14 @@ ...@@ -30,14 +30,14 @@
namespace blink { namespace blink {
class DOMPlugin; class DOMPlugin;
class LocalFrame; class LocalDOMWindow;
class DOMMimeType final : public ScriptWrappable, class DOMMimeType final : public ScriptWrappable,
public ExecutionContextClient { public ExecutionContextClient {
DEFINE_WRAPPERTYPEINFO(); DEFINE_WRAPPERTYPEINFO();
public: public:
DOMMimeType(LocalFrame*, const MimeClassInfo&); DOMMimeType(LocalDOMWindow*, const MimeClassInfo&);
const String& type() const; const String& type() const;
String suffixes() const; String suffixes() const;
......
...@@ -29,9 +29,9 @@ ...@@ -29,9 +29,9 @@
namespace blink { namespace blink {
DOMMimeTypeArray::DOMMimeTypeArray(LocalFrame* frame) DOMMimeTypeArray::DOMMimeTypeArray(LocalDOMWindow* window)
: ExecutionContextLifecycleObserver(frame ? frame->DomWindow() : nullptr), : ExecutionContextLifecycleObserver(window),
PluginsChangedObserver(frame ? frame->GetPage() : nullptr) { PluginsChangedObserver(window ? window->GetFrame()->GetPage() : nullptr) {
UpdatePluginData(); UpdatePluginData();
} }
...@@ -50,7 +50,7 @@ DOMMimeType* DOMMimeTypeArray::item(unsigned index) { ...@@ -50,7 +50,7 @@ DOMMimeType* DOMMimeTypeArray::item(unsigned index) {
return nullptr; return nullptr;
if (!dom_mime_types_[index]) { if (!dom_mime_types_[index]) {
dom_mime_types_[index] = MakeGarbageCollected<DOMMimeType>( dom_mime_types_[index] = MakeGarbageCollected<DOMMimeType>(
GetFrame(), *GetPluginData()->Mimes()[index]); DomWindow(), *GetPluginData()->Mimes()[index]);
} }
return dom_mime_types_[index]; return dom_mime_types_[index];
...@@ -90,9 +90,9 @@ bool DOMMimeTypeArray::NamedPropertyQuery(const AtomicString& property_name, ...@@ -90,9 +90,9 @@ bool DOMMimeTypeArray::NamedPropertyQuery(const AtomicString& property_name,
} }
PluginData* DOMMimeTypeArray::GetPluginData() const { PluginData* DOMMimeTypeArray::GetPluginData() const {
if (!GetFrame()) if (!DomWindow())
return nullptr; return nullptr;
return GetFrame()->GetPluginData(); return DomWindow()->GetFrame()->GetPluginData();
} }
void DOMMimeTypeArray::UpdatePluginData() { void DOMMimeTypeArray::UpdatePluginData() {
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
namespace blink { namespace blink {
class ExceptionState; class ExceptionState;
class LocalFrame; class LocalDOMWindow;
class PluginData; class PluginData;
class DOMMimeTypeArray final : public ScriptWrappable, class DOMMimeTypeArray final : public ScriptWrappable,
...@@ -40,7 +40,7 @@ class DOMMimeTypeArray final : public ScriptWrappable, ...@@ -40,7 +40,7 @@ class DOMMimeTypeArray final : public ScriptWrappable,
DEFINE_WRAPPERTYPEINFO(); DEFINE_WRAPPERTYPEINFO();
public: public:
explicit DOMMimeTypeArray(LocalFrame*); explicit DOMMimeTypeArray(LocalDOMWindow*);
void UpdatePluginData(); void UpdatePluginData();
......
...@@ -19,14 +19,15 @@ ...@@ -19,14 +19,15 @@
#include "third_party/blink/renderer/modules/plugins/dom_plugin.h" #include "third_party/blink/renderer/modules/plugins/dom_plugin.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/page/plugin_data.h" #include "third_party/blink/renderer/core/page/plugin_data.h"
#include "third_party/blink/renderer/platform/heap/heap.h" #include "third_party/blink/renderer/platform/heap/heap.h"
#include "third_party/blink/renderer/platform/wtf/text/atomic_string.h" #include "third_party/blink/renderer/platform/wtf/text/atomic_string.h"
namespace blink { namespace blink {
DOMPlugin::DOMPlugin(LocalFrame* frame, const PluginInfo& plugin_info) DOMPlugin::DOMPlugin(LocalDOMWindow* window, const PluginInfo& plugin_info)
: ExecutionContextClient(frame), plugin_info_(&plugin_info) {} : ExecutionContextClient(window), plugin_info_(&plugin_info) {}
void DOMPlugin::Trace(Visitor* visitor) const { void DOMPlugin::Trace(Visitor* visitor) const {
visitor->Trace(plugin_info_); visitor->Trace(plugin_info_);
...@@ -56,7 +57,7 @@ DOMMimeType* DOMPlugin::item(unsigned index) { ...@@ -56,7 +57,7 @@ DOMMimeType* DOMPlugin::item(unsigned index) {
if (!mime) if (!mime)
return nullptr; return nullptr;
return MakeGarbageCollected<DOMMimeType>(GetFrame(), *mime); return MakeGarbageCollected<DOMMimeType>(DomWindow(), *mime);
} }
DOMMimeType* DOMPlugin::namedItem(const AtomicString& property_name) { DOMMimeType* DOMPlugin::namedItem(const AtomicString& property_name) {
...@@ -65,7 +66,7 @@ DOMMimeType* DOMPlugin::namedItem(const AtomicString& property_name) { ...@@ -65,7 +66,7 @@ DOMMimeType* DOMPlugin::namedItem(const AtomicString& property_name) {
if (!mime) if (!mime)
return nullptr; return nullptr;
return MakeGarbageCollected<DOMMimeType>(GetFrame(), *mime); return MakeGarbageCollected<DOMMimeType>(DomWindow(), *mime);
} }
void DOMPlugin::NamedPropertyEnumerator(Vector<String>& property_names, void DOMPlugin::NamedPropertyEnumerator(Vector<String>& property_names,
......
...@@ -35,7 +35,7 @@ class DOMPlugin final : public ScriptWrappable, public ExecutionContextClient { ...@@ -35,7 +35,7 @@ class DOMPlugin final : public ScriptWrappable, public ExecutionContextClient {
DEFINE_WRAPPERTYPEINFO(); DEFINE_WRAPPERTYPEINFO();
public: public:
DOMPlugin(LocalFrame*, const PluginInfo&); DOMPlugin(LocalDOMWindow*, const PluginInfo&);
String name() const; String name() const;
String filename() const; String filename() const;
......
...@@ -33,9 +33,9 @@ ...@@ -33,9 +33,9 @@
namespace blink { namespace blink {
DOMPluginArray::DOMPluginArray(LocalFrame* frame) DOMPluginArray::DOMPluginArray(LocalDOMWindow* window)
: ExecutionContextLifecycleObserver(frame ? frame->DomWindow() : nullptr), : ExecutionContextLifecycleObserver(window),
PluginsChangedObserver(frame ? frame->GetPage() : nullptr) { PluginsChangedObserver(window ? window->GetFrame()->GetPage() : nullptr) {
UpdatePluginData(); UpdatePluginData();
} }
...@@ -56,7 +56,7 @@ DOMPlugin* DOMPluginArray::item(unsigned index) { ...@@ -56,7 +56,7 @@ DOMPlugin* DOMPluginArray::item(unsigned index) {
if (!dom_plugins_[index]) { if (!dom_plugins_[index]) {
dom_plugins_[index] = MakeGarbageCollected<DOMPlugin>( dom_plugins_[index] = MakeGarbageCollected<DOMPlugin>(
GetFrame(), *GetPluginData()->Plugins()[index]); DomWindow(), *GetPluginData()->Plugins()[index]);
} }
return dom_plugins_[index]; return dom_plugins_[index];
...@@ -96,14 +96,14 @@ bool DOMPluginArray::NamedPropertyQuery(const AtomicString& property_name, ...@@ -96,14 +96,14 @@ bool DOMPluginArray::NamedPropertyQuery(const AtomicString& property_name,
} }
void DOMPluginArray::refresh(bool reload) { void DOMPluginArray::refresh(bool reload) {
if (!GetFrame()) if (!DomWindow())
return; return;
PluginData::RefreshBrowserSidePluginCache(); PluginData::RefreshBrowserSidePluginCache();
if (PluginData* data = GetPluginData()) if (PluginData* data = GetPluginData())
data->ResetPluginData(); data->ResetPluginData();
for (Frame* frame = GetFrame()->GetPage()->MainFrame(); frame; for (Frame* frame = DomWindow()->GetFrame()->GetPage()->MainFrame(); frame;
frame = frame->Tree().TraverseNext()) { frame = frame->Tree().TraverseNext()) {
auto* local_frame = DynamicTo<LocalFrame>(frame); auto* local_frame = DynamicTo<LocalFrame>(frame);
if (!local_frame) if (!local_frame)
...@@ -114,13 +114,11 @@ void DOMPluginArray::refresh(bool reload) { ...@@ -114,13 +114,11 @@ void DOMPluginArray::refresh(bool reload) {
} }
if (reload) if (reload)
GetFrame()->Reload(WebFrameLoadType::kReload); DomWindow()->GetFrame()->Reload(WebFrameLoadType::kReload);
} }
PluginData* DOMPluginArray::GetPluginData() const { PluginData* DOMPluginArray::GetPluginData() const {
if (!GetFrame()) return DomWindow() ? DomWindow()->GetFrame()->GetPluginData() : nullptr;
return nullptr;
return GetFrame()->GetPluginData();
} }
void DOMPluginArray::UpdatePluginData() { void DOMPluginArray::UpdatePluginData() {
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
namespace blink { namespace blink {
class LocalFrame; class LocalDOMWindow;
class PluginData; class PluginData;
class DOMPluginArray final : public ScriptWrappable, class DOMPluginArray final : public ScriptWrappable,
...@@ -40,7 +40,7 @@ class DOMPluginArray final : public ScriptWrappable, ...@@ -40,7 +40,7 @@ class DOMPluginArray final : public ScriptWrappable,
DEFINE_WRAPPERTYPEINFO(); DEFINE_WRAPPERTYPEINFO();
public: public:
explicit DOMPluginArray(LocalFrame*); explicit DOMPluginArray(LocalDOMWindow*);
void UpdatePluginData(); void UpdatePluginData();
......
...@@ -7,9 +7,8 @@ ...@@ -7,9 +7,8 @@
#include "third_party/blink/public/common/privacy_budget/identifiability_metric_builder.h" #include "third_party/blink/public/common/privacy_budget/identifiability_metric_builder.h"
#include "third_party/blink/public/common/privacy_budget/identifiability_study_settings.h" #include "third_party/blink/public/common/privacy_budget/identifiability_study_settings.h"
#include "third_party/blink/public/common/privacy_budget/identifiable_token_builder.h" #include "third_party/blink/public/common/privacy_budget/identifiable_token_builder.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/core/frame/navigator.h" #include "third_party/blink/renderer/core/frame/navigator.h"
#include "third_party/blink/renderer/core/frame/settings.h"
#include "third_party/blink/renderer/modules/plugins/dom_mime_type.h" #include "third_party/blink/renderer/modules/plugins/dom_mime_type.h"
#include "third_party/blink/renderer/modules/plugins/dom_mime_type_array.h" #include "third_party/blink/renderer/modules/plugins/dom_mime_type_array.h"
#include "third_party/blink/renderer/modules/plugins/dom_plugin_array.h" #include "third_party/blink/renderer/modules/plugins/dom_plugin_array.h"
...@@ -40,12 +39,12 @@ const char NavigatorPlugins::kSupplementName[] = "NavigatorPlugins"; ...@@ -40,12 +39,12 @@ const char NavigatorPlugins::kSupplementName[] = "NavigatorPlugins";
// static // static
DOMPluginArray* NavigatorPlugins::plugins(Navigator& navigator) { DOMPluginArray* NavigatorPlugins::plugins(Navigator& navigator) {
return NavigatorPlugins::From(navigator).plugins(navigator.GetFrame()); return NavigatorPlugins::From(navigator).plugins(navigator.DomWindow());
} }
// static // static
DOMMimeTypeArray* NavigatorPlugins::mimeTypes(Navigator& navigator) { DOMMimeTypeArray* NavigatorPlugins::mimeTypes(Navigator& navigator) {
return NavigatorPlugins::From(navigator).mimeTypes(navigator.GetFrame()); return NavigatorPlugins::From(navigator).mimeTypes(navigator.DomWindow());
} }
// static // static
...@@ -55,13 +54,12 @@ bool NavigatorPlugins::javaEnabled(Navigator& navigator) { ...@@ -55,13 +54,12 @@ bool NavigatorPlugins::javaEnabled(Navigator& navigator) {
namespace { namespace {
void RecordPlugins(LocalFrame* frame, DOMPluginArray* plugins) { void RecordPlugins(LocalDOMWindow* window, DOMPluginArray* plugins) {
if (!IdentifiabilityStudySettings::Get()->IsWebFeatureAllowed( if (!IdentifiabilityStudySettings::Get()->IsWebFeatureAllowed(
WebFeature::kNavigatorPlugins) || WebFeature::kNavigatorPlugins) ||
!frame) { !window) {
return; return;
} }
if (Document* document = frame->GetDocument()) {
IdentifiableTokenBuilder builder; IdentifiableTokenBuilder builder;
for (unsigned i = 0; i < plugins->length(); i++) { for (unsigned i = 0; i < plugins->length(); i++) {
DOMPlugin* plugin = plugins->item(i); DOMPlugin* plugin = plugins->item(i);
...@@ -73,46 +71,24 @@ void RecordPlugins(LocalFrame* frame, DOMPluginArray* plugins) { ...@@ -73,46 +71,24 @@ void RecordPlugins(LocalFrame* frame, DOMPluginArray* plugins) {
builder.AddToken(IdentifiabilityBenignStringToken(mimeType->type())); builder.AddToken(IdentifiabilityBenignStringToken(mimeType->type()));
builder.AddToken( builder.AddToken(
IdentifiabilityBenignStringToken(mimeType->description())); IdentifiabilityBenignStringToken(mimeType->description()));
builder.AddToken( builder.AddToken(IdentifiabilityBenignStringToken(mimeType->suffixes()));
IdentifiabilityBenignStringToken(mimeType->suffixes()));
} }
} }
IdentifiabilityMetricBuilder(document->UkmSourceID()) IdentifiabilityMetricBuilder(window->UkmSourceID())
.SetWebfeature(WebFeature::kNavigatorPlugins, builder.GetToken()) .SetWebfeature(WebFeature::kNavigatorPlugins, builder.GetToken())
.Record(document->UkmRecorder()); .Record(window->UkmRecorder());
}
}
} // namespace
DOMPluginArray* NavigatorPlugins::plugins(LocalFrame* frame) const {
if (!plugins_)
plugins_ = MakeGarbageCollected<DOMPluginArray>(frame);
DOMPluginArray* result = plugins_.Get();
RecordPlugins(frame, result);
return result;
}
DOMMimeTypeArray* NavigatorPlugins::mimeTypes(LocalFrame* frame) const {
if (!mime_types_) {
mime_types_ = MakeGarbageCollected<DOMMimeTypeArray>(frame);
RecordMimeTypes(frame);
}
return mime_types_.Get();
} }
void NavigatorPlugins::RecordMimeTypes(LocalFrame* frame) const { void RecordMimeTypes(LocalDOMWindow* window, DOMMimeTypeArray* mime_types) {
constexpr IdentifiableSurface surface = IdentifiableSurface::FromTypeAndToken( constexpr IdentifiableSurface surface = IdentifiableSurface::FromTypeAndToken(
IdentifiableSurface::Type::kWebFeature, WebFeature::kNavigatorMimeTypes); IdentifiableSurface::Type::kWebFeature, WebFeature::kNavigatorMimeTypes);
if (!IdentifiabilityStudySettings::Get()->IsSurfaceAllowed(surface) || !frame) if (!IdentifiabilityStudySettings::Get()->IsSurfaceAllowed(surface) ||
return; !window) {
Document* document = frame->GetDocument();
if (!document)
return; return;
}
IdentifiableTokenBuilder builder; IdentifiableTokenBuilder builder;
for (unsigned i = 0; i < mime_types_->length(); i++) { for (unsigned i = 0; i < mime_types->length(); i++) {
DOMMimeType* mime_type = mime_types_->item(i); DOMMimeType* mime_type = mime_types->item(i);
builder.AddToken(IdentifiabilityBenignStringToken(mime_type->type())); builder.AddToken(IdentifiabilityBenignStringToken(mime_type->type()));
builder.AddToken( builder.AddToken(
IdentifiabilityBenignStringToken(mime_type->description())); IdentifiabilityBenignStringToken(mime_type->description()));
...@@ -124,9 +100,28 @@ void NavigatorPlugins::RecordMimeTypes(LocalFrame* frame) const { ...@@ -124,9 +100,28 @@ void NavigatorPlugins::RecordMimeTypes(LocalFrame* frame) const {
builder.AddToken(IdentifiabilityBenignStringToken(plugin->description())); builder.AddToken(IdentifiabilityBenignStringToken(plugin->description()));
} }
} }
IdentifiabilityMetricBuilder(document->UkmSourceID()) IdentifiabilityMetricBuilder(window->UkmSourceID())
.Set(surface, builder.GetToken()) .Set(surface, builder.GetToken())
.Record(document->UkmRecorder()); .Record(window->UkmRecorder());
}
} // namespace
DOMPluginArray* NavigatorPlugins::plugins(LocalDOMWindow* window) const {
if (!plugins_)
plugins_ = MakeGarbageCollected<DOMPluginArray>(window);
DOMPluginArray* result = plugins_.Get();
RecordPlugins(window, result);
return result;
}
DOMMimeTypeArray* NavigatorPlugins::mimeTypes(LocalDOMWindow* window) const {
if (!mime_types_) {
mime_types_ = MakeGarbageCollected<DOMMimeTypeArray>(window);
RecordMimeTypes(window, mime_types_.Get());
}
return mime_types_.Get();
} }
void NavigatorPlugins::Trace(Visitor* visitor) const { void NavigatorPlugins::Trace(Visitor* visitor) const {
......
...@@ -12,7 +12,7 @@ namespace blink { ...@@ -12,7 +12,7 @@ namespace blink {
class DOMMimeTypeArray; class DOMMimeTypeArray;
class DOMPluginArray; class DOMPluginArray;
class LocalFrame; class LocalDOMWindow;
class Navigator; class Navigator;
class NavigatorPlugins final : public GarbageCollected<NavigatorPlugins>, class NavigatorPlugins final : public GarbageCollected<NavigatorPlugins>,
...@@ -32,10 +32,8 @@ class NavigatorPlugins final : public GarbageCollected<NavigatorPlugins>, ...@@ -32,10 +32,8 @@ class NavigatorPlugins final : public GarbageCollected<NavigatorPlugins>,
void Trace(Visitor*) const override; void Trace(Visitor*) const override;
private: private:
DOMPluginArray* plugins(LocalFrame*) const; DOMPluginArray* plugins(LocalDOMWindow*) const;
DOMMimeTypeArray* mimeTypes(LocalFrame*) const; DOMMimeTypeArray* mimeTypes(LocalDOMWindow*) const;
void RecordMimeTypes(LocalFrame*) const;
mutable Member<DOMPluginArray> plugins_; mutable Member<DOMPluginArray> plugins_;
mutable Member<DOMMimeTypeArray> mime_types_; mutable Member<DOMMimeTypeArray> mime_types_;
......
...@@ -93,7 +93,7 @@ StorageArea* DOMWindowStorage::sessionStorage( ...@@ -93,7 +93,7 @@ StorageArea* DOMWindowStorage::sessionStorage(
auto storage_area = auto storage_area =
storage_namespace->GetCachedArea(window->GetSecurityOrigin()); storage_namespace->GetCachedArea(window->GetSecurityOrigin());
session_storage_ = session_storage_ =
StorageArea::Create(window->GetFrame(), std::move(storage_area), StorageArea::Create(window, std::move(storage_area),
StorageArea::StorageType::kSessionStorage); StorageArea::StorageType::kSessionStorage);
if (!session_storage_->CanAccessStorage()) { if (!session_storage_->CanAccessStorage()) {
...@@ -137,8 +137,7 @@ StorageArea* DOMWindowStorage::localStorage( ...@@ -137,8 +137,7 @@ StorageArea* DOMWindowStorage::localStorage(
return nullptr; return nullptr;
auto storage_area = StorageController::GetInstance()->GetLocalStorageArea( auto storage_area = StorageController::GetInstance()->GetLocalStorageArea(
window->GetSecurityOrigin()); window->GetSecurityOrigin());
local_storage_ = local_storage_ = StorageArea::Create(window, std::move(storage_area),
StorageArea::Create(window->GetFrame(), std::move(storage_area),
StorageArea::StorageType::kLocalStorage); StorageArea::StorageType::kLocalStorage);
if (!local_storage_->CanAccessStorage()) { if (!local_storage_->CanAccessStorage()) {
......
...@@ -224,7 +224,7 @@ Response InspectorDOMStorageAgent::FindStorageArea( ...@@ -224,7 +224,7 @@ Response InspectorDOMStorageAgent::FindStorageArea(
"Security origin cannot access local storage"); "Security origin cannot access local storage");
} }
storage_area = StorageArea::CreateForInspectorAgent( storage_area = StorageArea::CreateForInspectorAgent(
frame, frame->DomWindow(),
StorageController::GetInstance()->GetLocalStorageArea( StorageController::GetInstance()->GetLocalStorageArea(
frame->DomWindow()->GetSecurityOrigin()), frame->DomWindow()->GetSecurityOrigin()),
StorageArea::StorageType::kLocalStorage); StorageArea::StorageType::kLocalStorage);
...@@ -242,7 +242,7 @@ Response InspectorDOMStorageAgent::FindStorageArea( ...@@ -242,7 +242,7 @@ Response InspectorDOMStorageAgent::FindStorageArea(
DCHECK(session_namespace->IsSessionStorage()); DCHECK(session_namespace->IsSessionStorage());
storage_area = StorageArea::CreateForInspectorAgent( storage_area = StorageArea::CreateForInspectorAgent(
frame, frame->DomWindow(),
session_namespace->GetCachedArea(frame->DomWindow()->GetSecurityOrigin()), session_namespace->GetCachedArea(frame->DomWindow()->GetSecurityOrigin()),
StorageArea::StorageType::kSessionStorage); StorageArea::StorageType::kSessionStorage);
return Response::Success(); return Response::Success();
......
...@@ -44,32 +44,32 @@ ...@@ -44,32 +44,32 @@
namespace blink { namespace blink {
StorageArea* StorageArea::Create(LocalFrame* frame, StorageArea* StorageArea::Create(LocalDOMWindow* window,
scoped_refptr<CachedStorageArea> storage_area, scoped_refptr<CachedStorageArea> storage_area,
StorageType storage_type) { StorageType storage_type) {
return MakeGarbageCollected<StorageArea>(frame, std::move(storage_area), return MakeGarbageCollected<StorageArea>(window, std::move(storage_area),
storage_type, storage_type,
/* should_enqueue_events */ true); /* should_enqueue_events */ true);
} }
StorageArea* StorageArea::CreateForInspectorAgent( StorageArea* StorageArea::CreateForInspectorAgent(
LocalFrame* frame, LocalDOMWindow* window,
scoped_refptr<CachedStorageArea> storage_area, scoped_refptr<CachedStorageArea> storage_area,
StorageType storage_type) { StorageType storage_type) {
return MakeGarbageCollected<StorageArea>(frame, std::move(storage_area), return MakeGarbageCollected<StorageArea>(window, std::move(storage_area),
storage_type, storage_type,
/* should_enqueue_events */ false); /* should_enqueue_events */ false);
} }
StorageArea::StorageArea(LocalFrame* frame, StorageArea::StorageArea(LocalDOMWindow* window,
scoped_refptr<CachedStorageArea> storage_area, scoped_refptr<CachedStorageArea> storage_area,
StorageType storage_type, StorageType storage_type,
bool should_enqueue_events) bool should_enqueue_events)
: ExecutionContextClient(frame), : ExecutionContextClient(window),
cached_area_(std::move(storage_area)), cached_area_(std::move(storage_area)),
storage_type_(storage_type), storage_type_(storage_type),
should_enqueue_events_(should_enqueue_events) { should_enqueue_events_(should_enqueue_events) {
DCHECK(frame); DCHECK(window);
DCHECK(cached_area_); DCHECK(cached_area_);
cached_area_->RegisterSource(this); cached_area_->RegisterSource(this);
} }
...@@ -179,22 +179,21 @@ void StorageArea::Trace(Visitor* visitor) const { ...@@ -179,22 +179,21 @@ void StorageArea::Trace(Visitor* visitor) const {
} }
bool StorageArea::CanAccessStorage() const { bool StorageArea::CanAccessStorage() const {
LocalFrame* frame = GetFrame(); if (!DomWindow())
if (!frame || !frame->GetPage())
return false; return false;
if (did_check_can_access_storage_) if (did_check_can_access_storage_)
return can_access_storage_cached_result_; return can_access_storage_cached_result_;
can_access_storage_cached_result_ = can_access_storage_cached_result_ = StorageController::CanAccessStorageArea(
StorageController::CanAccessStorageArea(frame, storage_type_); DomWindow()->GetFrame(), storage_type_);
did_check_can_access_storage_ = true; did_check_can_access_storage_ = true;
return can_access_storage_cached_result_; return can_access_storage_cached_result_;
} }
void StorageArea::RecordModificationInMetrics() { void StorageArea::RecordModificationInMetrics() {
TRACE_EVENT0("blink", "StorageArea::RecordModificationInMetrics"); TRACE_EVENT0("blink", "StorageArea::RecordModificationInMetrics");
if (!GetFrame() || !GetFrame()->GetPage() || if (!DomWindow() ||
!GetFrame()->GetPage()->DispatchedPagehideAndStillHidden()) { !DomWindow()->GetFrame()->GetPage()->DispatchedPagehideAndStillHidden()) {
return; return;
} }
// The storage modification is done after the pagehide event got dispatched // The storage modification is done after the pagehide event got dispatched
...@@ -205,8 +204,8 @@ void StorageArea::RecordModificationInMetrics() { ...@@ -205,8 +204,8 @@ void StorageArea::RecordModificationInMetrics() {
// should track this case to measure how often this is happening, except for // should track this case to measure how often this is happening, except for
// when the unload event is currently in progress, which means the page is not // when the unload event is currently in progress, which means the page is not
// actually stored in the back-forward cache and this behavior is ok. // actually stored in the back-forward cache and this behavior is ok.
if (GetFrame()->GetDocument() && if (DomWindow()->document() &&
GetFrame()->GetDocument()->UnloadEventInProgress()) { DomWindow()->document()->UnloadEventInProgress()) {
return; return;
} }
UMA_HISTOGRAM_ENUMERATION( UMA_HISTOGRAM_ENUMERATION(
...@@ -217,10 +216,7 @@ void StorageArea::RecordModificationInMetrics() { ...@@ -217,10 +216,7 @@ void StorageArea::RecordModificationInMetrics() {
} }
KURL StorageArea::GetPageUrl() const { KURL StorageArea::GetPageUrl() const {
LocalFrame* frame = GetFrame(); return DomWindow() ? DomWindow()->Url() : KURL();
if (!frame)
return KURL();
return GetFrame()->GetDocument()->Url();
} }
bool StorageArea::EnqueueStorageEvent(const String& key, bool StorageArea::EnqueueStorageEvent(const String& key,
...@@ -229,12 +225,9 @@ bool StorageArea::EnqueueStorageEvent(const String& key, ...@@ -229,12 +225,9 @@ bool StorageArea::EnqueueStorageEvent(const String& key,
const String& url) { const String& url) {
if (!should_enqueue_events_) if (!should_enqueue_events_)
return true; return true;
if (!GetExecutionContext()) if (!DomWindow())
return false; return false;
LocalFrame* frame = GetFrame(); DomWindow()->EnqueueWindowEvent(
if (!frame)
return true;
frame->DomWindow()->EnqueueWindowEvent(
*StorageEvent::Create(event_type_names::kStorage, key, old_value, *StorageEvent::Create(event_type_names::kStorage, key, old_value,
new_value, url, this), new_value, url, this),
TaskType::kDOMManipulation); TaskType::kDOMManipulation);
...@@ -244,11 +237,12 @@ bool StorageArea::EnqueueStorageEvent(const String& key, ...@@ -244,11 +237,12 @@ bool StorageArea::EnqueueStorageEvent(const String& key,
blink::WebScopedVirtualTimePauser StorageArea::CreateWebScopedVirtualTimePauser( blink::WebScopedVirtualTimePauser StorageArea::CreateWebScopedVirtualTimePauser(
const char* name, const char* name,
WebScopedVirtualTimePauser::VirtualTaskDuration duration) { WebScopedVirtualTimePauser::VirtualTaskDuration duration) {
LocalFrame* frame = GetFrame(); if (!DomWindow())
if (!frame)
return blink::WebScopedVirtualTimePauser(); return blink::WebScopedVirtualTimePauser();
return frame->GetFrameScheduler()->CreateWebScopedVirtualTimePauser(name, return DomWindow()
duration); ->GetFrame()
->GetFrameScheduler()
->CreateWebScopedVirtualTimePauser(name, duration);
} }
} // namespace blink } // namespace blink
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
namespace blink { namespace blink {
class ExceptionState; class ExceptionState;
class LocalFrame; class LocalDOMWindow;
class StorageArea final : public ScriptWrappable, class StorageArea final : public ScriptWrappable,
public ExecutionContextClient, public ExecutionContextClient,
...@@ -47,17 +47,17 @@ class StorageArea final : public ScriptWrappable, ...@@ -47,17 +47,17 @@ class StorageArea final : public ScriptWrappable,
public: public:
enum class StorageType { kLocalStorage, kSessionStorage }; enum class StorageType { kLocalStorage, kSessionStorage };
static StorageArea* Create(LocalFrame*, static StorageArea* Create(LocalDOMWindow*,
scoped_refptr<CachedStorageArea>, scoped_refptr<CachedStorageArea>,
StorageType); StorageType);
// This storage area doesn't enqueue any events. This avoids duplicate event // This storage area doesn't enqueue any events. This avoids duplicate event
// dispatch when an inspector agent is present. // dispatch when an inspector agent is present.
static StorageArea* CreateForInspectorAgent(LocalFrame*, static StorageArea* CreateForInspectorAgent(LocalDOMWindow*,
scoped_refptr<CachedStorageArea>, scoped_refptr<CachedStorageArea>,
StorageType); StorageType);
StorageArea(LocalFrame*, StorageArea(LocalDOMWindow*,
scoped_refptr<CachedStorageArea>, scoped_refptr<CachedStorageArea>,
StorageType, StorageType,
bool should_enqueue_events); bool should_enqueue_events);
......
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