blob: 576f2d354020a450c0626a3025544e66d87991dd [file] [log] [blame]
Elias Klim7d4fb1192024-06-12 13:07:131// Copyright 2024 The Chromium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef COMPONENTS_PERMISSIONS_PERMISSION_INDICATORS_TAB_DATA_H_
6#define COMPONENTS_PERMISSIONS_PERMISSION_INDICATORS_TAB_DATA_H_
7
Yifan Luo63c5ea02024-11-07 14:34:478#include "base/time/time.h"
Elias Klim7d4fb1192024-06-12 13:07:139#include "components/content_settings/core/common/content_settings.h"
10#include "components/content_settings/core/common/content_settings_types.h"
11#include "content/public/browser/web_contents_observer.h"
Elias Klim7d4fb1192024-06-12 13:07:1312
13namespace permissions {
14
Yifan Luof1f58a32024-11-22 15:55:0615enum class RequestTypeForUma;
16
Elias Klim7d4fb1192024-06-12 13:07:1317class PermissionIndicatorsTabData : public content::WebContentsObserver {
18 public:
19 // LHS indicators type. Currently only camera and mic are supported.
20 enum class IndicatorsType { kMediaStream };
21
22 explicit PermissionIndicatorsTabData(content::WebContents* web_contents);
23
24 ~PermissionIndicatorsTabData() override;
25
26 // Returns `true` if the LHS verbose indicator is allowed in a tab.
27 bool IsVerboseIndicatorAllowed(IndicatorsType type) const;
28 // Mark that the LHS verbose indicator was already displayed.
29 void SetVerboseIndicatorDisplayed(IndicatorsType type);
30
Yifan Luof1f58a32024-11-22 15:55:0631 // Record when an activity starts.
32 void RecordActivity(RequestTypeForUma request_type);
33
34 // Capture the microphone and camera change.
35 void OnMediaCaptureChanged(RequestTypeForUma request_type, bool used);
Elias Klim7d4fb1192024-06-12 13:07:1336
37 // content::WebContentsObserver:
38 void WebContentsDestroyed() override;
39 void PrimaryPageChanged(content::Page& page) override;
Yifan Luo63c5ea02024-11-07 14:34:4740 void OnCapabilityTypesChanged(
Patrick Monette15442a12025-01-22 20:09:3141 content::WebContentsCapabilityType connection_type,
Yifan Luo63c5ea02024-11-07 14:34:4742 bool used) override;
43
44 private:
45 void ClearData();
46
Yifan Luof1f58a32024-11-22 15:55:0647 std::map<RequestTypeForUma, std::optional<base::TimeTicks>> last_usage_time_;
Elias Klim7d4fb1192024-06-12 13:07:1348
49 std::optional<url::Origin> origin_;
50
51 std::set<IndicatorsType> displayed_indicators_;
52};
53
54} // namespace permissions
55
56#endif // COMPONENTS_PERMISSIONS_PERMISSION_INDICATORS_TAB_DATA_H_