summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/frame/user_activation.cc
blob: 8aaaacc2a6d7fdccf739dc57c3ee9ff319fddf4d (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
43
44
45
46
47
// Copyright 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.

#include "third_party/blink/renderer/core/frame/user_activation.h"

#include "third_party/blink/renderer/core/frame/local_dom_window.h"

namespace blink {

UserActivation* UserActivation::CreateSnapshot(LocalDOMWindow* window) {
  LocalFrame* frame = window->GetFrame();
  return new UserActivation(frame ? frame->HasBeenActivated() : false,
                            Frame::HasTransientUserActivation(frame));
}

UserActivation* UserActivation::CreateLive(LocalDOMWindow* window) {
  return new UserActivation(window);
}

UserActivation::UserActivation(bool has_been_active, bool is_active)
    : has_been_active_(has_been_active), is_active_(is_active) {}

UserActivation::UserActivation(LocalDOMWindow* window) : window_(window) {}

UserActivation::~UserActivation() = default;

void UserActivation::Trace(blink::Visitor* visitor) {
  visitor->Trace(window_);
  ScriptWrappable::Trace(visitor);
}

bool UserActivation::hasBeenActive() const {
  LocalFrame* frame = window_ ? window_->GetFrame() : nullptr;
  if (!frame)
    return has_been_active_;
  return frame->HasBeenActivated();
}

bool UserActivation::isActive() const {
  LocalFrame* frame = window_ ? window_->GetFrame() : nullptr;
  if (!frame)
    return is_active_;
  return Frame::HasTransientUserActivation(frame);
}

}  // namespace blink