1 // Copyright 2018 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 
5 #ifndef CONTENT_PUBLIC_BROWSER_PERMISSION_CONTROLLER_H_
6 #define CONTENT_PUBLIC_BROWSER_PERMISSION_CONTROLLER_H_
7 
8 #include "base/supports_user_data.h"
9 #include "content/common/content_export.h"
10 #include "content/public/browser/permission_type.h"
11 #include "third_party/blink/public/mojom/permissions/permission_status.mojom.h"
12 
13 class GURL;
14 
15 namespace content {
16 class RenderFrameHost;
17 
18 // This class allows the content layer to manipulate permissions. It's behavior
19 // is defined by the embedder via PermissionControllerDelegate implementation.
20 class CONTENT_EXPORT PermissionController
21     : public base::SupportsUserData::Data {
22  public:
23   // Constant retured when registering and subscribing if
24   // cancelling/unsubscribing at a later stage would have no effect.
25   static const int kNoPendingOperation = -1;
26 
~PermissionController()27   ~PermissionController() override {}
28 
29   // Returns the permission status of a given requesting_origin/embedding_origin
30   // tuple. This is not taking a RenderFrameHost because the call might happen
31   // outside of a frame context. Prefer GetPermissionStatusForFrame (below)
32   // whenever possible.
33   virtual blink::mojom::PermissionStatus GetPermissionStatus(
34       PermissionType permission,
35       const GURL& requesting_origin,
36       const GURL& embedding_origin) = 0;
37 
38   // Returns the permission status for a given frame. Use this over
39   // GetPermissionStatus whenever possible.
40   // TODO(raymes): Currently we still pass the |requesting_origin| as a separate
41   // parameter because we can't yet guarantee that it matches the last committed
42   // origin of the RenderFrameHost. See https://crbug.com/698985.
43   virtual blink::mojom::PermissionStatus GetPermissionStatusForFrame(
44       PermissionType permission,
45       RenderFrameHost* render_frame_host,
46       const GURL& requesting_origin) = 0;
47 };
48 
49 }  // namespace content
50 
51 #endif  // CONTENT_PUBLIC_BROWSER_PERMISSION_CONTROLLER_H_
52