blob: 3c071ba548f4ad0956479052222f27b52af4f6aa [file] [log] [blame]
Avi Drissman8ba1bad2022-09-13 19:22:361// Copyright 2015 The Chromium Authors
mlamouridfbf5692015-06-06 18:53:412// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Clark DuVall484c2562020-01-23 22:05:095#ifndef COMPONENTS_PERMISSIONS_PERMISSION_REQUEST_ID_H_
6#define COMPONENTS_PERMISSIONS_PERMISSION_REQUEST_ID_H_
mlamouridfbf5692015-06-06 18:53:417
8#include <string>
9
Albert J. Wong1b6dc962021-07-09 18:06:5710#include "base/types/id_type.h"
Illia Klimov32c4b392022-10-31 17:29:5311#include "content/public/browser/global_routing_id.h"
mlamouridfbf5692015-06-06 18:53:4112#include "url/gurl.h"
13
mlamouri8b5ec902015-10-24 00:52:0314namespace content {
15class RenderFrameHost;
16} // namespace content
17
Clark DuVall484c2562020-01-23 22:05:0918namespace permissions {
19
mlamouridfbf5692015-06-06 18:53:4120// Uniquely identifies a particular permission request.
lalitmc886a2562015-09-10 10:20:0221// None of the different attributes (render_process_id, render_frame_id or
Balazs Engedye15473b2021-04-14 09:09:2122// request_local_id) is enough to compare two requests. In order to check if
mlamouridfbf5692015-06-06 18:53:4123// a request is the same as another one, consumers of this class should use
24// the operator== or operator!=.
25class PermissionRequestID {
26 public:
Balazs Engedye15473b2021-04-14 09:09:2127 // Uniquely identifies a request (at least) within a given frame.
Albert J. Wong1b6dc962021-07-09 18:06:5728 using RequestLocalId = base::IdType64<PermissionRequestID>;
Balazs Engedye15473b2021-04-14 09:09:2129
mlamouri8b5ec902015-10-24 00:52:0330 PermissionRequestID(content::RenderFrameHost* render_frame_host,
Balazs Engedye15473b2021-04-14 09:09:2131 RequestLocalId request_local_id);
Illia Klimov32c4b392022-10-31 17:29:5332 PermissionRequestID(content::GlobalRenderFrameHostId id,
Balazs Engedye15473b2021-04-14 09:09:2133 RequestLocalId request_local_id);
mlamouridfbf5692015-06-06 18:53:4134 ~PermissionRequestID();
35
Balazs Engedye15473b2021-04-14 09:09:2136 PermissionRequestID(const PermissionRequestID&);
37 PermissionRequestID& operator=(const PermissionRequestID&);
mlamouridfbf5692015-06-06 18:53:4138
Andy Paicu0a6d4b502023-08-29 15:13:0939 void set_global_render_frame_host_id(
40 const content::GlobalRenderFrameHostId& id) {
41 global_render_frame_host_id_ = id;
42 }
43
Illia Klimov32c4b392022-10-31 17:29:5344 const content::GlobalRenderFrameHostId& global_render_frame_host_id() const {
45 return global_render_frame_host_id_;
46 }
Balazs Engedye15473b2021-04-14 09:09:2147
48 // Deprecated. Only accessible for testing.
49 RequestLocalId request_local_id_for_testing() const {
50 return request_local_id_;
51 }
mlamouridfbf5692015-06-06 18:53:4152
Jan Keitelbbe27482025-05-08 10:45:5153 friend bool operator==(const PermissionRequestID&,
54 const PermissionRequestID&) = default;
mlamouridfbf5692015-06-06 18:53:4155
56 std::string ToString() const;
57
58 private:
Illia Klimov32c4b392022-10-31 17:29:5359 content::GlobalRenderFrameHostId global_render_frame_host_id_;
Balazs Engedye15473b2021-04-14 09:09:2160 RequestLocalId request_local_id_;
mlamouridfbf5692015-06-06 18:53:4161};
62
Clark DuVall484c2562020-01-23 22:05:0963} // namespace permissions
64
65#endif // COMPONENTS_PERMISSIONS_PERMISSION_REQUEST_ID_H_