Elias Klim | 7d4fb119 | 2024-06-12 13:07:13 | [diff] [blame] | 1 | // 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 Luo | 63c5ea0 | 2024-11-07 14:34:47 | [diff] [blame] | 8 | #include "base/time/time.h" |
Elias Klim | 7d4fb119 | 2024-06-12 13:07:13 | [diff] [blame] | 9 | #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 Klim | 7d4fb119 | 2024-06-12 13:07:13 | [diff] [blame] | 12 | |
| 13 | namespace permissions { |
| 14 | |
Yifan Luo | f1f58a3 | 2024-11-22 15:55:06 | [diff] [blame] | 15 | enum class RequestTypeForUma; |
| 16 | |
Elias Klim | 7d4fb119 | 2024-06-12 13:07:13 | [diff] [blame] | 17 | class 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 Luo | f1f58a3 | 2024-11-22 15:55:06 | [diff] [blame] | 31 | // 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 Klim | 7d4fb119 | 2024-06-12 13:07:13 | [diff] [blame] | 36 | |
| 37 | // content::WebContentsObserver: |
| 38 | void WebContentsDestroyed() override; |
| 39 | void PrimaryPageChanged(content::Page& page) override; |
Yifan Luo | 63c5ea0 | 2024-11-07 14:34:47 | [diff] [blame] | 40 | void OnCapabilityTypesChanged( |
Patrick Monette | 15442a1 | 2025-01-22 20:09:31 | [diff] [blame] | 41 | content::WebContentsCapabilityType connection_type, |
Yifan Luo | 63c5ea0 | 2024-11-07 14:34:47 | [diff] [blame] | 42 | bool used) override; |
| 43 | |
| 44 | private: |
| 45 | void ClearData(); |
| 46 | |
Yifan Luo | f1f58a3 | 2024-11-22 15:55:06 | [diff] [blame] | 47 | std::map<RequestTypeForUma, std::optional<base::TimeTicks>> last_usage_time_; |
Elias Klim | 7d4fb119 | 2024-06-12 13:07:13 | [diff] [blame] | 48 | |
| 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_ |