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.
|
|
|
|
|
|
|
|
#ifndef ATOM_BROWSER_ATOM_PERMISSION_MANAGER_H_
|
|
|
|
#define ATOM_BROWSER_ATOM_PERMISSION_MANAGER_H_
|
|
|
|
|
|
|
|
#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;
|
|
|
|
}
|
|
|
|
|
2016-01-30 11:19:18 +00:00
|
|
|
namespace atom {
|
|
|
|
|
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;
|
|
|
|
|
2018-04-18 01:44:10 +00:00
|
|
|
using StatusCallback = base::Callback<void(blink::mojom::PermissionStatus)>;
|
2016-12-19 23:12:16 +00:00
|
|
|
using StatusesCallback =
|
|
|
|
base::Callback<void(const std::vector<blink::mojom::PermissionStatus>&)>;
|
2018-04-18 01:44:10 +00:00
|
|
|
using RequestHandler = base::Callback<void(content::WebContents*,
|
|
|
|
content::PermissionType,
|
|
|
|
const StatusCallback&,
|
|
|
|
const base::DictionaryValue&)>;
|
2018-08-28 14:05:08 +00:00
|
|
|
using CheckHandler = base::Callback<bool(content::WebContents*,
|
|
|
|
content::PermissionType,
|
|
|
|
const GURL& requesting_origin,
|
|
|
|
const base::DictionaryValue&)>;
|
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:
|
2016-01-30 11:19:18 +00:00
|
|
|
int RequestPermission(
|
|
|
|
content::PermissionType permission,
|
|
|
|
content::RenderFrameHost* render_frame_host,
|
|
|
|
const GURL& requesting_origin,
|
2016-11-30 07:30:03 +00:00
|
|
|
bool user_gesture,
|
|
|
|
const base::Callback<void(blink::mojom::PermissionStatus)>& callback)
|
|
|
|
override;
|
2017-11-11 03:27:30 +00:00
|
|
|
int RequestPermissionWithDetails(
|
|
|
|
content::PermissionType permission,
|
|
|
|
content::RenderFrameHost* render_frame_host,
|
|
|
|
const GURL& requesting_origin,
|
|
|
|
bool user_gesture,
|
|
|
|
const base::DictionaryValue* details,
|
2018-10-02 18:09:25 +00:00
|
|
|
const 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,
|
2018-04-18 01:44:10 +00:00
|
|
|
const base::Callback<
|
|
|
|
void(const std::vector<blink::mojom::PermissionStatus>&)>& callback)
|
2016-11-30 07:30:03 +00:00
|
|
|
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,
|
2018-04-18 01:44:10 +00:00
|
|
|
const base::Callback<
|
|
|
|
void(const std::vector<blink::mojom::PermissionStatus>&)>& 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,
|
|
|
|
const GURL& requesting_origin,
|
|
|
|
const GURL& embedding_origin,
|
2016-05-23 01:59:39 +00:00
|
|
|
const base::Callback<void(blink::mojom::PermissionStatus)>& callback)
|
|
|
|
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);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace atom
|
|
|
|
|
|
|
|
#endif // ATOM_BROWSER_ATOM_PERMISSION_MANAGER_H_
|