2016-01-23 16:29:47 +03: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.
|
|
|
|
|
|
|
|
#ifndef ATOM_BROWSER_WEB_CONTENTS_PERMISSION_HELPER_H_
|
|
|
|
#define ATOM_BROWSER_WEB_CONTENTS_PERMISSION_HELPER_H_
|
|
|
|
|
2019-01-21 19:28:04 +03:00
|
|
|
#include "content/public/browser/media_stream_request.h"
|
2016-01-30 14:19:18 +03:00
|
|
|
#include "content/public/browser/permission_type.h"
|
2016-01-23 16:29:47 +03:00
|
|
|
#include "content/public/browser/web_contents_user_data.h"
|
2019-01-21 19:28:04 +03:00
|
|
|
#include "third_party/blink/public/common/mediastream/media_stream_request.h"
|
2016-01-23 16:29:47 +03:00
|
|
|
|
|
|
|
namespace atom {
|
|
|
|
|
|
|
|
// Applies the permission requested for WebContents.
|
|
|
|
class WebContentsPermissionHelper
|
|
|
|
: public content::WebContentsUserData<WebContentsPermissionHelper> {
|
|
|
|
public:
|
|
|
|
~WebContentsPermissionHelper() override;
|
|
|
|
|
2016-02-01 12:43:49 +03:00
|
|
|
enum class PermissionType {
|
|
|
|
POINTER_LOCK = static_cast<int>(content::PermissionType::NUM) + 1,
|
2016-04-20 19:55:15 +03:00
|
|
|
FULLSCREEN,
|
|
|
|
OPEN_EXTERNAL,
|
2016-02-01 12:43:49 +03:00
|
|
|
};
|
|
|
|
|
2018-08-28 17:05:08 +03:00
|
|
|
// Asynchronous Requests
|
2018-04-18 04:44:10 +03:00
|
|
|
void RequestFullscreenPermission(const base::Callback<void(bool)>& callback);
|
2018-10-16 08:59:45 +03:00
|
|
|
void RequestMediaAccessPermission(const content::MediaStreamRequest& request,
|
|
|
|
content::MediaResponseCallback callback);
|
2016-01-25 19:37:15 +03:00
|
|
|
void RequestWebNotificationPermission(
|
|
|
|
const base::Callback<void(bool)>& callback);
|
2016-02-01 12:43:49 +03:00
|
|
|
void RequestPointerLockPermission(bool user_gesture);
|
2018-04-18 04:44:10 +03:00
|
|
|
void RequestOpenExternalPermission(const base::Callback<void(bool)>& callback,
|
|
|
|
bool user_gesture,
|
|
|
|
const GURL& url);
|
2016-01-23 16:29:47 +03:00
|
|
|
|
2018-08-28 17:05:08 +03:00
|
|
|
// Synchronous Checks
|
|
|
|
bool CheckMediaAccessPermission(const GURL& security_origin,
|
2019-01-21 19:28:04 +03:00
|
|
|
blink::MediaStreamType type) const;
|
2018-08-28 17:05:08 +03:00
|
|
|
|
2016-01-23 16:29:47 +03:00
|
|
|
private:
|
2016-01-30 14:19:18 +03:00
|
|
|
explicit WebContentsPermissionHelper(content::WebContents* web_contents);
|
2016-01-23 16:29:47 +03:00
|
|
|
friend class content::WebContentsUserData<WebContentsPermissionHelper>;
|
|
|
|
|
2018-04-18 04:44:10 +03:00
|
|
|
void RequestPermission(content::PermissionType permission,
|
|
|
|
const base::Callback<void(bool)>& callback,
|
|
|
|
bool user_gesture = false,
|
|
|
|
const base::DictionaryValue* details = nullptr);
|
2016-01-23 16:29:47 +03:00
|
|
|
|
2018-08-28 17:05:08 +03:00
|
|
|
bool CheckPermission(content::PermissionType permission,
|
|
|
|
const base::DictionaryValue* details) const;
|
|
|
|
|
2016-01-30 14:19:18 +03:00
|
|
|
content::WebContents* web_contents_;
|
2016-01-23 16:29:47 +03:00
|
|
|
|
2019-01-21 19:56:54 +03:00
|
|
|
WEB_CONTENTS_USER_DATA_KEY_DECL();
|
|
|
|
|
2016-01-23 16:29:47 +03:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(WebContentsPermissionHelper);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace atom
|
|
|
|
|
|
|
|
#endif // ATOM_BROWSER_WEB_CONTENTS_PERMISSION_HELPER_H_
|