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