2016-01-30 11:19:18 +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_ATOM_PERMISSION_MANAGER_H_
|
|
|
|
#define SHELL_BROWSER_ATOM_PERMISSION_MANAGER_H_
|
2016-01-30 11:19:18 +00:00
|
|
|
|
|
|
|
#include <map>
|
2018-09-13 00:25:56 +00:00
|
|
|
#include <memory>
|
2016-03-08 14:32:59 +00:00
|
|
|
#include <vector>
|
2016-01-30 11:19:18 +00:00
|
|
|
|
2016-01-31 21:35:34 +00:00
|
|
|
#include "base/callback.h"
|
2017-11-23 13:02:43 +00:00
|
|
|
#include "base/containers/id_map.h"
|
2017-11-11 03:27:30 +00:00
|
|
|
#include "base/values.h"
|
2018-10-02 21:53:10 +00:00
|
|
|
#include "content/public/browser/permission_controller_delegate.h"
|
2016-01-30 11:19:18 +00:00
|
|
|
|
2016-01-31 21:35:34 +00:00
|
|
|
namespace content {
|
|
|
|
class WebContents;
|
|
|
|
}
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
namespace electron {
|
2016-01-30 11:19:18 +00:00
|
|
|
|
2018-10-02 21:53:10 +00:00
|
|
|
class AtomPermissionManager : public content::PermissionControllerDelegate {
|
2016-01-30 11:19:18 +00:00
|
|
|
public:
|
|
|
|
AtomPermissionManager();
|
|
|
|
~AtomPermissionManager() override;
|
|
|
|
|
2019-05-03 18:30:48 +00:00
|
|
|
using StatusCallback =
|
|
|
|
base::OnceCallback<void(blink::mojom::PermissionStatus)>;
|
|
|
|
using StatusesCallback = base::OnceCallback<void(
|
|
|
|
const std::vector<blink::mojom::PermissionStatus>&)>;
|
2018-04-18 01:44:10 +00:00
|
|
|
using RequestHandler = base::Callback<void(content::WebContents*,
|
|
|
|
content::PermissionType,
|
2019-05-03 18:30:48 +00:00
|
|
|
StatusCallback,
|
2019-06-13 18:11:43 +00:00
|
|
|
const base::Value&)>;
|
2018-08-28 14:05:08 +00:00
|
|
|
using CheckHandler = base::Callback<bool(content::WebContents*,
|
|
|
|
content::PermissionType,
|
|
|
|
const GURL& requesting_origin,
|
2019-06-13 18:11:43 +00:00
|
|
|
const base::Value&)>;
|
2016-01-30 11:19:18 +00:00
|
|
|
|
2016-01-30 13:31:10 +00:00
|
|
|
// Handler to dispatch permission requests in JS.
|
2016-01-31 21:35:34 +00:00
|
|
|
void SetPermissionRequestHandler(const RequestHandler& handler);
|
2018-08-28 14:05:08 +00:00
|
|
|
void SetPermissionCheckHandler(const CheckHandler& handler);
|
2016-01-30 13:31:10 +00:00
|
|
|
|
2018-10-02 21:53:10 +00:00
|
|
|
// content::PermissionControllerDelegate:
|
2019-05-03 18:30:48 +00:00
|
|
|
int RequestPermission(content::PermissionType permission,
|
|
|
|
content::RenderFrameHost* render_frame_host,
|
|
|
|
const GURL& requesting_origin,
|
|
|
|
bool user_gesture,
|
|
|
|
StatusCallback callback) override;
|
2018-10-16 05:59:45 +00:00
|
|
|
int RequestPermissionWithDetails(content::PermissionType permission,
|
|
|
|
content::RenderFrameHost* render_frame_host,
|
|
|
|
const GURL& requesting_origin,
|
|
|
|
bool user_gesture,
|
|
|
|
const base::DictionaryValue* details,
|
2019-05-03 18:30:48 +00:00
|
|
|
StatusCallback callback);
|
2016-03-08 14:28:53 +00:00
|
|
|
int RequestPermissions(
|
|
|
|
const std::vector<content::PermissionType>& permissions,
|
|
|
|
content::RenderFrameHost* render_frame_host,
|
|
|
|
const GURL& requesting_origin,
|
2016-11-30 07:30:03 +00:00
|
|
|
bool user_gesture,
|
2019-05-03 18:30:48 +00:00
|
|
|
StatusesCallback callback) override;
|
2017-11-11 03:27:30 +00:00
|
|
|
int RequestPermissionsWithDetails(
|
|
|
|
const std::vector<content::PermissionType>& permissions,
|
|
|
|
content::RenderFrameHost* render_frame_host,
|
|
|
|
const GURL& requesting_origin,
|
|
|
|
bool user_gesture,
|
|
|
|
const base::DictionaryValue* details,
|
2019-05-03 18:30:48 +00:00
|
|
|
StatusesCallback callback);
|
2018-07-21 15:48:43 +00:00
|
|
|
blink::mojom::PermissionStatus GetPermissionStatusForFrame(
|
|
|
|
content::PermissionType permission,
|
|
|
|
content::RenderFrameHost* render_frame_host,
|
|
|
|
const GURL& requesting_origin) override;
|
2016-01-31 21:35:34 +00:00
|
|
|
|
2018-08-28 14:05:08 +00:00
|
|
|
bool CheckPermissionWithDetails(content::PermissionType permission,
|
|
|
|
content::RenderFrameHost* render_frame_host,
|
|
|
|
const GURL& requesting_origin,
|
|
|
|
const base::DictionaryValue* details) const;
|
|
|
|
|
2016-01-31 21:35:34 +00:00
|
|
|
protected:
|
|
|
|
void OnPermissionResponse(int request_id,
|
2016-12-19 23:12:16 +00:00
|
|
|
int permission_id,
|
2016-05-23 01:59:39 +00:00
|
|
|
blink::mojom::PermissionStatus status);
|
2016-01-31 21:35:34 +00:00
|
|
|
|
2018-10-02 21:53:10 +00:00
|
|
|
// content::PermissionControllerDelegate:
|
2016-01-30 11:19:18 +00:00
|
|
|
void ResetPermission(content::PermissionType permission,
|
|
|
|
const GURL& requesting_origin,
|
|
|
|
const GURL& embedding_origin) override;
|
2016-05-23 01:59:39 +00:00
|
|
|
blink::mojom::PermissionStatus GetPermissionStatus(
|
2016-01-30 11:19:18 +00:00
|
|
|
content::PermissionType permission,
|
|
|
|
const GURL& requesting_origin,
|
|
|
|
const GURL& embedding_origin) override;
|
|
|
|
int SubscribePermissionStatusChange(
|
|
|
|
content::PermissionType permission,
|
2018-10-25 15:45:51 +00:00
|
|
|
content::RenderFrameHost* render_frame_host,
|
2016-01-30 11:19:18 +00:00
|
|
|
const GURL& requesting_origin,
|
2019-05-03 18:30:48 +00:00
|
|
|
base::RepeatingCallback<void(blink::mojom::PermissionStatus)> callback)
|
2016-05-23 01:59:39 +00:00
|
|
|
override;
|
2016-01-30 11:19:18 +00:00
|
|
|
void UnsubscribePermissionStatusChange(int subscription_id) override;
|
|
|
|
|
|
|
|
private:
|
2016-12-19 23:12:16 +00:00
|
|
|
class PendingRequest;
|
2017-11-23 13:02:43 +00:00
|
|
|
using PendingRequestsMap = base::IDMap<std::unique_ptr<PendingRequest>>;
|
2016-02-01 09:43:49 +00:00
|
|
|
|
2016-01-31 21:35:34 +00:00
|
|
|
RequestHandler request_handler_;
|
2018-08-28 14:05:08 +00:00
|
|
|
CheckHandler check_handler_;
|
2016-01-30 11:19:18 +00:00
|
|
|
|
2016-12-19 23:12:16 +00:00
|
|
|
PendingRequestsMap pending_requests_;
|
2016-01-30 11:19:18 +00:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(AtomPermissionManager);
|
|
|
|
};
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
} // namespace electron
|
2016-01-30 11:19:18 +00:00
|
|
|
|
2019-06-19 20:56:58 +00:00
|
|
|
#endif // SHELL_BROWSER_ATOM_PERMISSION_MANAGER_H_
|