blob: 398cfe916edd6736a8069a3ac0e0f19648ad2a87 [file] [log] [blame]
mlamouri4e372022015-03-29 14:51:061// Copyright 2015 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Clark DuVall6b73c742020-03-11 19:00:155#ifndef COMPONENTS_PERMISSIONS_PERMISSION_MANAGER_H_
6#define COMPONENTS_PERMISSIONS_PERMISSION_MANAGER_H_
mlamouri4e372022015-03-29 14:51:067
raymese3afee6b2016-04-18 02:00:508#include <unordered_map>
9
mlamouri4e372022015-03-29 14:51:0610#include "base/callback_forward.h"
James Hollyerd281a7312021-04-29 21:07:5911#include "base/containers/flat_map.h"
Brett Wilsonf976d3f2017-08-18 17:23:3912#include "base/containers/id_map.h"
mlamouri4e372022015-03-29 14:51:0613#include "base/macros.h"
mlamouri23957a22015-04-01 10:37:5614#include "components/content_settings/core/browser/content_settings_observer.h"
lalitm27583e92015-10-02 11:34:1715#include "components/content_settings/core/common/content_settings.h"
mlamouri4e372022015-03-29 14:51:0616#include "components/keyed_service/core/keyed_service.h"
James Hollyerd281a7312021-04-29 21:07:5917#include "components/permissions/permission_context_base.h"
Balazs Engedye15473b2021-04-14 09:09:2118#include "components/permissions/permission_request_id.h"
Clark DuVall732778e2020-01-27 18:13:5819#include "components/permissions/permission_util.h"
Andrey Lushnikovf3500102018-07-16 19:55:2220#include "content/public/browser/permission_controller_delegate.h"
Pavel Feldman73b22022018-11-02 02:55:3021#include "content/public/browser/permission_type.h"
Rohan Pavonefaf64572019-07-30 17:50:2022#include "url/origin.h"
mlamouri4e372022015-03-29 14:51:0623
Clark DuVall6b73c742020-03-11 19:00:1524namespace content {
25class BrowserContext;
26}
27
Clark DuVall484c2562020-01-23 22:05:0928namespace permissions {
Clark DuValla11361ad32020-02-20 22:14:2729class PermissionContextBase;
timlohc6911802017-03-01 05:37:0330struct PermissionResult;
mlamouri4e372022015-03-29 14:51:0631
mlamouri4e372022015-03-29 14:51:0632class PermissionManager : public KeyedService,
Andrey Lushnikovf3500102018-07-16 19:55:2233 public content::PermissionControllerDelegate,
James Hollyerd281a7312021-04-29 21:07:5934 public permissions::Observer {
mlamouri4e372022015-03-29 14:51:0635 public:
Clark DuVall6b73c742020-03-11 19:00:1536 using PermissionContextMap =
37 std::unordered_map<ContentSettingsType,
38 std::unique_ptr<PermissionContextBase>,
39 ContentSettingsTypeHash>;
40 PermissionManager(content::BrowserContext* browser_context,
41 PermissionContextMap permission_contexts);
mlamouri4e372022015-03-29 14:51:0642 ~PermissionManager() override;
43
Marc Treib9e4bd922017-09-25 08:32:1344 // Converts from |url|'s actual origin to the "canonical origin" that should
45 // be used for the purpose of requesting/storing permissions. For example, the
Raymes Khouryb474c642018-02-28 06:16:2846 // origin of the local NTP gets mapped to the Google base URL instead. With
47 // Permission Delegation it will transform the requesting origin into
48 // the embedding origin because all permission checks happen on the top level
49 // origin.
50 //
51 // All the public methods below, such as RequestPermission or
52 // GetPermissionStatus, take the actual origin and do the canonicalization
53 // internally. You only need to call this directly if you do something else
54 // with the origin, such as display it in the UI.
Balazs Engedyf39e22b2019-07-30 11:16:2455 GURL GetCanonicalOrigin(ContentSettingsType permission,
56 const GURL& requesting_origin,
Raymes Khouryb474c642018-02-28 06:16:2857 const GURL& embedding_origin) const;
Marc Treib9e4bd922017-09-25 08:32:1358
timloh9a180ad2017-02-20 07:15:2359 // Callers from within chrome/ should use the methods which take the
60 // ContentSettingsType enum. The methods which take PermissionType values
Andrey Lushnikovf3500102018-07-16 19:55:22