// Copyright 2014 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef COMPONENTS_PERMISSIONS_PERMISSION_CONTEXT_BASE_H_ #define COMPONENTS_PERMISSIONS_PERMISSION_CONTEXT_BASE_H_ #include <memory> #include <unordered_map> #include "base/functional/callback_forward.h" #include "base/memory/raw_ptr.h" #include "base/memory/weak_ptr.h" #include "base/observer_list.h" #include "base/time/time.h" #include "build/build_config.h" #include "components/content_settings/core/browser/content_settings_observer.h" #include "components/content_settings/core/common/content_settings.h" #include "components/content_settings/core/common/content_settings_types.h" #include "components/permissions/permission_request.h" #include "components/permissions/permission_request_data.h" #include "content/public/browser/permission_result.h" #include "third_party/blink/public/mojom/permissions_policy/permissions_policy_feature.mojom-forward.h" class GURL; namespace permissions { class PermissionRequestID; } namespace content { class BrowserContext; class RenderFrameHost; class WebContents; } // namespace content namespace permissions { class Observer : public base::CheckedObserver { … }; // A one time grant will never last longer than this value. static constexpr base::TimeDelta kOneTimePermissionMaximumLifetime = …; BrowserPermissionCallback; // This base class contains common operations for granting permissions. // It offers the following functionality: // - Creates a permission request when needed. // - If accepted/denied the permission is saved in content settings for // future uses (for the domain that requested it). // - If dismissed the permission is not saved but it's considered denied for // this one request // - In any case the BrowserPermissionCallback is executed once a decision // about the permission is made by the user. // The bare minimum you need to create a new permission request is // - Define your new permission in the ContentSettingsType enum. // - Create a class that inherits from PermissionContextBase and passes the // new permission. // - Edit the PermissionRequest methods to add the new text. // - Make sure to update // third_party/blink/public/devtools_protocol/browser_protocol.pdl // even if you don't intend to do anything DevTools-specific; you will // run into problems with generated code otherwise. // - Hit several asserts for the missing plumbing and fix them :) // After this you can override several other methods to customize behavior, // in particular it is advised to override UpdateTabContext in order to manage // the permission from the omnibox. // See midi_permission_context.h/cc or push_permission_context.cc/h for some // examples. class PermissionContextBase : public content_settings::Observer { … }; } // namespace permissions #endif // COMPONENTS_PERMISSIONS_PERMISSION_CONTEXT_BASE_H_