2016-01-23 13:29:47 +00:00
|
|
|
// Copyright (c) 2016 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-06-19 20:56:58 +00:00
|
|
|
#ifndef SHELL_BROWSER_WEB_CONTENTS_PERMISSION_HELPER_H_
|
|
|
|
#define SHELL_BROWSER_WEB_CONTENTS_PERMISSION_HELPER_H_
|
2016-01-23 13:29:47 +00:00
|
|
|
|
2021-07-26 16:02:16 +00:00
|
|
|
#include "base/values.h"
|
2019-01-21 16:28:04 +00:00
|
|
|
#include "content/public/browser/media_stream_request.h"
|
2016-01-30 11:19:18 +00:00
|
|
|
#include "content/public/browser/permission_type.h"
|
2016-01-23 13:29:47 +00:00
|
|
|
#include "content/public/browser/web_contents_user_data.h"
|
2019-01-21 16:28:04 +00:00
|
|
|
#include "third_party/blink/public/common/mediastream/media_stream_request.h"
|
2016-01-23 13:29:47 +00:00
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
namespace electron {
|
2016-01-23 13:29:47 +00:00
|
|
|
|
|
|
|
// Applies the permission requested for WebContents.
|
|
|
|
class WebContentsPermissionHelper
|
|
|
|
: public content::WebContentsUserData<WebContentsPermissionHelper> {
|
|
|
|
public:
|
|
|
|
~WebContentsPermissionHelper() override;
|
|
|
|
|
2021-11-03 11:41:45 +00:00
|
|
|
// disable copy
|
|
|
|
WebContentsPermissionHelper(const WebContentsPermissionHelper&) = delete;
|
|
|
|
WebContentsPermissionHelper& operator=(const WebContentsPermissionHelper&) =
|
|
|
|
delete;
|
|
|
|
|
2016-02-01 09:43:49 +00:00
|
|
|
enum class PermissionType {
|
|
|
|
POINTER_LOCK = static_cast<int>(content::PermissionType::NUM) + 1,
|
2016-04-20 16:55:15 +00:00
|
|
|
FULLSCREEN,
|
|
|
|
OPEN_EXTERNAL,
|
2021-09-23 11:00:11 +00:00
|
|
|
SERIAL,
|
|
|
|
HID
|
2016-02-01 09:43:49 +00:00
|
|
|
};
|
|
|
|
|
2018-08-28 14:05:08 +00:00
|
|
|
// Asynchronous Requests
|
2019-05-29 20:02:15 +00:00
|
|
|
void RequestFullscreenPermission(base::OnceCallback<void(bool)> callback);
|
2018-10-16 05:59:45 +00:00
|
|
|
void RequestMediaAccessPermission(const content::MediaStreamRequest& request,
|
|
|
|
content::MediaResponseCallback callback);
|
2016-01-25 16:37:15 +00:00
|
|
|
void RequestWebNotificationPermission(
|
2019-05-29 20:02:15 +00:00
|
|
|
base::OnceCallback<void(bool)> callback);
|
2016-02-01 09:43:49 +00:00
|
|
|
void RequestPointerLockPermission(bool user_gesture);
|
2019-05-29 20:02:15 +00:00
|
|
|
void RequestOpenExternalPermission(base::OnceCallback<void(bool)> callback,
|
|
|
|
bool user_gesture,
|
|
|
|
const GURL& url);
|
2016-01-23 13:29:47 +00:00
|
|
|
|
2018-08-28 14:05:08 +00:00
|
|
|
// Synchronous Checks
|
|
|
|
bool CheckMediaAccessPermission(const GURL& security_origin,
|
2019-07-03 01:22:09 +00:00
|
|
|
blink::mojom::MediaStreamType type) const;
|
2020-09-28 16:22:03 +00:00
|
|
|
bool CheckSerialAccessPermission(const url::Origin& embedding_origin) const;
|
2021-10-06 20:18:00 +00:00
|
|
|
bool CheckSerialPortPermission(
|
|
|
|
const url::Origin& origin,
|
|
|
|
base::Value device,
|
|
|
|
content::RenderFrameHost* render_frame_host) const;
|
|
|
|
void GrantSerialPortPermission(
|
|
|
|
const url::Origin& origin,
|
|
|
|
base::Value device,
|
|
|
|
content::RenderFrameHost* render_frame_host) const;
|
2021-09-23 11:00:11 +00:00
|
|
|
bool CheckHIDAccessPermission(const url::Origin& embedding_origin) const;
|
|
|
|
bool CheckHIDDevicePermission(
|
|
|
|
const url::Origin& origin,
|
|
|
|
base::Value device,
|
|
|
|
content::RenderFrameHost* render_frame_host) const;
|
|
|
|
void GrantHIDDevicePermission(
|
|
|
|
const url::Origin& origin,
|
|
|
|
base::Value device,
|
|
|
|
content::RenderFrameHost* render_frame_host) const;
|
2018-08-28 14:05:08 +00:00
|
|
|
|
2016-01-23 13:29:47 +00:00
|
|
|
private:
|
2016-01-30 11:19:18 +00:00
|
|
|
explicit WebContentsPermissionHelper(content::WebContents* web_contents);
|
2016-01-23 13:29:47 +00:00
|
|
|
friend class content::WebContentsUserData<WebContentsPermissionHelper>;
|
|
|
|
|
2018-04-18 01:44:10 +00:00
|
|
|
void RequestPermission(content::PermissionType permission,
|
2019-05-29 20:02:15 +00:00
|
|
|
base::OnceCallback<void(bool)> callback,
|
2018-04-18 01:44:10 +00:00
|
|
|
bool user_gesture = false,
|
|
|
|
const base::DictionaryValue* details = nullptr);
|
2016-01-23 13:29:47 +00:00
|
|
|
|
2018-08-28 14:05:08 +00:00
|
|
|
bool CheckPermission(content::PermissionType permission,
|
|
|
|
const base::DictionaryValue* details) const;
|
|
|
|
|
2021-09-23 11:00:11 +00:00
|
|
|
bool CheckDevicePermission(content::PermissionType permission,
|
|
|
|
const url::Origin& origin,
|
|
|
|
const base::Value* device,
|
|
|
|
content::RenderFrameHost* render_frame_host) const;
|
|
|
|
|
|
|
|
void GrantDevicePermission(content::PermissionType permission,
|
|
|
|
const url::Origin& origin,
|
|
|
|
const base::Value* device,
|
|
|
|
content::RenderFrameHost* render_frame_host) const;
|
|
|
|
|
2016-01-30 11:19:18 +00:00
|
|
|
content::WebContents* web_contents_;
|
2016-01-23 13:29:47 +00:00
|
|
|
|
2019-01-21 16:56:54 +00:00
|
|
|
WEB_CONTENTS_USER_DATA_KEY_DECL();
|
2016-01-23 13:29:47 +00:00
|
|
|
};
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
} // namespace electron
|
2016-01-23 13:29:47 +00:00
|
|
|
|
2019-06-19 20:56:58 +00:00
|
|
|
#endif // SHELL_BROWSER_WEB_CONTENTS_PERMISSION_HELPER_H_
|