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