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.
|
|
|
|
|
2019-06-19 13:56:58 -07:00
|
|
|
#ifndef SHELL_BROWSER_WEB_CONTENTS_PERMISSION_HELPER_H_
|
|
|
|
#define SHELL_BROWSER_WEB_CONTENTS_PERMISSION_HELPER_H_
|
2016-01-23 18:59:47 +05:30
|
|
|
|
2019-01-21 21:58:04 +05:30
|
|
|
#include "content/public/browser/media_stream_request.h"
|
2016-01-30 16:49:18 +05:30
|
|
|
#include "content/public/browser/permission_type.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"
|
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;
|
|
|
|
|
2016-02-01 15:13:49 +05:30
|
|
|
enum class PermissionType {
|
|
|
|
POINTER_LOCK = static_cast<int>(content::PermissionType::NUM) + 1,
|
2016-04-20 22:25:15 +05:30
|
|
|
FULLSCREEN,
|
|
|
|
OPEN_EXTERNAL,
|
2020-09-28 12:22:03 -04:00
|
|
|
SERIAL
|
2016-02-01 15:13:49 +05:30
|
|
|
};
|
|
|
|
|
2018-08-29 02:05:08 +12:00
|
|
|
// Asynchronous Requests
|
2019-05-29 13:02:15 -07:00
|
|
|
void RequestFullscreenPermission(base::OnceCallback<void(bool)> callback);
|
2018-10-15 22:59:45 -07:00
|
|
|
void RequestMediaAccessPermission(const content::MediaStreamRequest& request,
|
|
|
|
content::MediaResponseCallback callback);
|
2016-01-25 22:07:15 +05:30
|
|
|
void RequestWebNotificationPermission(
|
2019-05-29 13:02:15 -07:00
|
|
|
base::OnceCallback<void(bool)> callback);
|
2016-02-01 15:13:49 +05:30
|
|
|
void RequestPointerLockPermission(bool user_gesture);
|
2019-05-29 13:02:15 -07:00
|
|
|
void RequestOpenExternalPermission(base::OnceCallback<void(bool)> callback,
|
|
|
|
bool user_gesture,
|
|
|
|
const GURL& url);
|
2016-01-23 18:59:47 +05:30
|
|
|
|
2018-08-29 02:05:08 +12:00
|
|
|
// Synchronous Checks
|
|
|
|
bool CheckMediaAccessPermission(const GURL& 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>;
|
|
|
|
|
2018-04-17 21:44:10 -04:00
|
|
|
void RequestPermission(content::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,
|
|
|
|
const base::DictionaryValue* details = nullptr);
|
2016-01-23 18:59:47 +05:30
|
|
|
|
2018-08-29 02:05:08 +12:00
|
|
|
bool CheckPermission(content::PermissionType permission,
|
|
|
|
const base::DictionaryValue* details) const;
|
|
|
|
|
2016-01-30 16:49:18 +05:30
|
|
|
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
|
|
|
DISALLOW_COPY_AND_ASSIGN(WebContentsPermissionHelper);
|
|
|
|
};
|
|
|
|
|
2019-06-19 14:23:04 -07:00
|
|
|
} // namespace electron
|
2016-01-23 18:59:47 +05:30
|
|
|
|
2019-06-19 13:56:58 -07:00
|
|
|
#endif // SHELL_BROWSER_WEB_CONTENTS_PERMISSION_HELPER_H_
|