2016-01-23 18:59:47 +05:30
|
|
|
// Copyright (c) 2016 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2021-11-22 08:34:31 +01:00
|
|
|
#ifndef ELECTRON_SHELL_BROWSER_WEB_CONTENTS_PERMISSION_HELPER_H_
|
|
|
|
#define ELECTRON_SHELL_BROWSER_WEB_CONTENTS_PERMISSION_HELPER_H_
|
2016-01-23 18:59:47 +05:30
|
|
|
|
2023-05-11 16:07:39 -04:00
|
|
|
#include "base/memory/raw_ptr.h"
|
2021-07-26 09:02:16 -07:00
|
|
|
#include "base/values.h"
|
2019-01-21 21:58:04 +05:30
|
|
|
#include "content/public/browser/media_stream_request.h"
|
2016-01-23 18:59:47 +05:30
|
|
|
#include "content/public/browser/web_contents_user_data.h"
|
2019-01-21 21:58:04 +05:30
|
|
|
#include "third_party/blink/public/common/mediastream/media_stream_request.h"
|
2022-05-17 12:48:40 -04:00
|
|
|
#include "third_party/blink/public/common/permissions/permission_utils.h"
|
2016-01-23 18:59:47 +05:30
|
|
|
|
2019-06-19 14:23:04 -07:00
|
|
|
namespace electron {
|
2016-01-23 18:59:47 +05:30
|
|
|
|
|
|
|
// Applies the permission requested for WebContents.
|
|
|
|
class WebContentsPermissionHelper
|
|
|
|
: public content::WebContentsUserData<WebContentsPermissionHelper> {
|
|
|
|
public:
|
|
|
|
~WebContentsPermissionHelper() override;
|
|
|
|
|
2021-11-03 12:41:45 +01:00
|
|
|
// disable copy
|
|
|
|
WebContentsPermissionHelper(const WebContentsPermissionHelper&) = delete;
|
|
|
|
WebContentsPermissionHelper& operator=(const WebContentsPermissionHelper&) =
|
|
|
|
delete;
|
|
|
|
|
2016-02-01 15:13:49 +05:30
|
|
|
enum class PermissionType {
|
2024-03-13 09:44:49 +01:00
|
|
|
FULLSCREEN = static_cast<int>(blink::PermissionType::NUM) + 1,
|
2016-04-20 22:25:15 +05:30
|
|
|
OPEN_EXTERNAL,
|
2021-09-23 07:00:11 -04:00
|
|
|
SERIAL,
|
2022-11-22 16:50:32 -05:00
|
|
|
HID,
|
2024-04-10 22:06:47 +02:00
|
|
|
USB,
|
|
|
|
KEYBOARD_LOCK,
|
|
|
|
FILE_SYSTEM
|
2016-02-01 15:13:49 +05:30
|
|
|
};
|
|
|
|
|
2018-08-29 02:05:08 +12:00
|
|
|
// Asynchronous Requests
|
2022-08-26 03:31:33 -07:00
|
|
|
void RequestFullscreenPermission(content::RenderFrameHost* requesting_frame,
|
|
|
|
base::OnceCallback<void(bool)> callback);
|
2018-10-15 22:59:45 -07:00
|
|
|
void RequestMediaAccessPermission(const content::MediaStreamRequest& request,
|
|
|
|
content::MediaResponseCallback callback);
|
2022-02-09 10:40:50 +01:00
|
|
|
void RequestPointerLockPermission(
|
|
|
|
bool user_gesture,
|
|
|
|
bool last_unlocked_by_target,
|
|
|
|
base::OnceCallback<void(content::WebContents*, bool, bool, bool)>
|
|
|
|
callback);
|
2023-11-06 11:54:31 -08:00
|
|
|
void RequestKeyboardLockPermission(
|
|
|
|
bool esc_key_locked,
|
|
|
|
base::OnceCallback<void(content::WebContents*, bool, bool)> callback);
|
2016-01-25 22:07:15 +05:30
|
|
|
void RequestWebNotificationPermission(
|
2022-08-26 03:31:33 -07:00
|
|
|
content::RenderFrameHost* requesting_frame,
|
2019-05-29 13:02:15 -07:00
|
|
|
base::OnceCallback<void(bool)> callback);
|
2022-08-26 03:31:33 -07:00
|
|
|
void RequestOpenExternalPermission(content::RenderFrameHost* requesting_frame,
|
|
|
|
base::OnceCallback<void(bool)> callback,
|
2019-05-29 13:02:15 -07:00
|
|
|
bool user_gesture,
|
|
|
|
const GURL& url);
|
2016-01-23 18:59:47 +05:30
|
|
|
|
2018-08-29 02:05:08 +12:00
|
|
|
// Synchronous Checks
|
2023-11-28 13:40:12 -08:00
|
|
|
bool CheckMediaAccessPermission(const url::Origin& security_origin,
|
2019-07-02 18:22:09 -07:00
|
|
|
blink::mojom::MediaStreamType type) const;
|
2020-09-28 12:22:03 -04:00
|
|
|
bool CheckSerialAccessPermission(const url::Origin& embedding_origin) const;
|
2018-08-29 02:05:08 +12:00
|
|
|
|
2016-01-23 18:59:47 +05:30
|
|
|
private:
|
2016-01-30 16:49:18 +05:30
|
|
|
explicit WebContentsPermissionHelper(content::WebContents* web_contents);
|
2016-01-23 18:59:47 +05:30
|
|
|
friend class content::WebContentsUserData<WebContentsPermissionHelper>;
|
|
|
|
|
2022-08-26 03:31:33 -07:00
|
|
|
void RequestPermission(content::RenderFrameHost* requesting_frame,
|
|
|
|
blink::PermissionType permission,
|
2019-05-29 13:02:15 -07:00
|
|
|
base::OnceCallback<void(bool)> callback,
|
2018-04-17 21:44:10 -04:00
|
|
|
bool user_gesture = false,
|
2022-06-29 10:09:48 -07:00
|
|
|
base::Value::Dict details = {});
|
2016-01-23 18:59:47 +05:30
|
|
|
|
2022-05-17 12:48:40 -04:00
|
|
|
bool CheckPermission(blink::PermissionType permission,
|
2022-06-29 10:09:48 -07:00
|
|
|
base::Value::Dict details) const;
|
2018-08-29 02:05:08 +12:00
|
|
|
|
2022-01-10 17:31:39 -05:00
|
|
|
// TODO(clavin): refactor to use the WebContents provided by the
|
|
|
|
// WebContentsUserData base class instead of storing a duplicate ref
|
2023-05-11 16:07:39 -04:00
|
|
|
raw_ptr<content::WebContents> web_contents_;
|
2016-01-23 18:59:47 +05:30
|
|
|
|
2019-01-21 22:26:54 +05:30
|
|
|
WEB_CONTENTS_USER_DATA_KEY_DECL();
|
2016-01-23 18:59:47 +05:30
|
|
|
};
|
|
|
|
|
2019-06-19 14:23:04 -07:00
|
|
|
} // namespace electron
|
2016-01-23 18:59:47 +05:30
|
|
|
|
2021-11-22 08:34:31 +01:00
|
|
|
#endif // ELECTRON_SHELL_BROWSER_WEB_CONTENTS_PERMISSION_HELPER_H_
|