summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/frame/navigation_rate_limiter.h
blob: 7ff7bc349ed49b1bfb1d4fbbe0498b87fbab391d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright (c) 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_FRAME_NAVIGATION_RATE_LIMITER_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_FRAME_NAVIGATION_RATE_LIMITER_H_

#include "base/time/time.h"
#include "third_party/blink/renderer/platform/heap/member.h"

namespace blink {
class Visitor;
class Frame;

// TODO(https://crbug.com/394296, https://crbug.com/882238)
// Prevent the renderer process to flood the browser process by sending IPC for
// same-document navigations.
// This is not the long-term fix to IPC flooding. However, it mitigate the
// immediate concern assuming the renderer has not been compromised.
class NavigationRateLimiter final {
  DISALLOW_NEW();

 public:
  explicit NavigationRateLimiter(Frame&);

  // Notify this object a new navigation is requested. Return true if this one
  // is allowed to proceed.
  bool CanProceed();

  void Trace(Visitor*) const;

 private:
  Member<Frame> frame_;
  base::TimeTicks time_first_count_;
  int count_ = 0;
  bool enabled;

  bool error_message_sent_ = false;
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_CORE_FRAME_NAVIGATION_RATE_LIMITER_H_