summaryrefslogtreecommitdiff
path: root/docshell/base/nsDocShell.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'docshell/base/nsDocShell.cpp')
-rw-r--r--docshell/base/nsDocShell.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp
index f2c7443656..b07cb15ff1 100644
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -821,6 +821,8 @@ nsDocShell::nsDocShell()
, mTouchEventsOverride(nsIDocShell::TOUCHEVENTS_OVERRIDE_NONE)
, mStateFloodGuardCount(0)
, mStateFloodGuardReported(false)
+ , mReloadFloodGuardCount(0)
+ , mReloadFloodGuardReported(false)
{
AssertOriginAttributesMatchPrivateBrowsing();
mHistoryID = ++gDocshellIDCounter;
@@ -5299,6 +5301,25 @@ nsDocShell::LoadErrorPage(nsIURI* aURI, const char16_t* aURL,
nullptr);
}
+bool
+nsDocShell::IsReloadFlooding()
+{
+ if (mReloadFloodGuardCount > kReloadLimit) {
+ TimeStamp now = TimeStamp::Now();
+
+ if (now - mReloadFloodGuardUpdated > TimeDuration::FromSeconds(kReloadTimeSecs)) {
+ mReloadFloodGuardCount = 0;
+ mReloadFloodGuardUpdated = now;
+ mReloadFloodGuardReported = false;
+ return false;
+ }
+ return true;
+ }
+
+ mReloadFloodGuardCount++;
+ return false;
+}
+
NS_IMETHODIMP
nsDocShell::Reload(uint32_t aReloadFlags)
{
@@ -5323,6 +5344,24 @@ nsDocShell::Reload(uint32_t aReloadFlags)
if (rootSH) {
shistInt->NotifyOnHistoryReload(mCurrentURI, aReloadFlags, &canReload);
}
+
+ // If we're being flooded with reload requests, we should abort early
+ // from the reload logic.
+ if (IsReloadFlooding()) {
+ // Report a warning to the console to tell developers why their reload
+ // failed.
+ // Do this only if not yet marked reported so we only report it once per
+ // flood interval.
+ if (!mReloadFloodGuardReported) {
+ nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
+ NS_LITERAL_CSTRING("Reload"),
+ GetDocument(),
+ nsContentUtils::eDOM_PROPERTIES,
+ "ReloadFloodingPrevented");
+ mReloadFloodGuardReported = true;
+ }
+ return NS_OK;
+ }
if (!canReload) {
return NS_OK;