540d88f809
* chore: bump chromium in DEPS to 126.0.6468.2 * chore: bump chromium in DEPS to 126.0.6478.4 * chore: bump chromium in DEPS to 126.0.6478.9 * chore: bump chromium in DEPS to 126.0.6478.8 * 5492605: Migrate TODOs referencing old crbug IDs to the new issue tracker IDs | https://chromium-review.googlesource.com/c/chromium/src/+/5492605 (cherry picked from commit 01bbc6b9609954e6f5e8ed2d7c5864e6f2a7929b) * 5513277: Move subresource-filter-ruleset to GCS | https://chromium-review.googlesource.com/c/chromium/src/+/5513277 (cherry picked from commit 284bbbdf86d640cfbe27831524a7cefa1f0ec344) * 5512656: Remove CustomizeChromeSupportsChromeRefresh2023 | https://chromium-review.googlesource.com/c/chromium/src/+/5512656 (cherry picked from commit 41acddd97e2f4f79dba13a3916c1af46d47fa6f5) * 5516009: Accept mouse events in inactive window for Top Chrome WebUIs | https://chromium-review.googlesource.com/c/chromium/src/+/5516009 (cherry picked from commit ffc88b3b2a7bee830a1e78b64afb6dfe6aff7347) * 5376861: Change references to RWHVB in RWHIER and RenderWidgetTargeter to RWHVI. | https://chromium-review.googlesource.com/c/chromium/src/+/5376861 (cherry picked from commit 5a48cf6952f0c3fde8a4d2b717ac5b2d50d13671) * 5490530: Use partition_alloc PA_BUILDFLAG(...) outside PA. #cleanup | https://chromium-review.googlesource.com/c/chromium/src/+/5490530 (cherry picked from commit 8deba32e729d3ded310be6645a27a78458046d69) * 5296870: network: Allow trusted loaders to learn the sent request cookies. | https://chromium-review.googlesource.com/c/chromium/src/+/5296870 (cherry picked from commit 7aef2f0ad890bb778fa8843bd262daf6909c5f52) * 5453438: Delegate delegated ink trails to RWHI from RWHIER. | https://chromium-review.googlesource.com/c/chromium/src/+/5453438 (cherry picked from commit 368eb3924a3b9b58430c7340b930254a3db6f1a3) * chore: update patches (cherry picked from commit 9d6dac074b0f173e43d8e587edbe7de1565de3d6) * chore: update patches (cherry picked from commit fb4134d68204ea85a095d496b31216905f801878) * update patches (cherry picked from commit 6f6fff5b0b08c4cccdbc98950f8cbb399caf6340) * only disable enterprise_cloud_content_analysis (cherry picked from commit 5426d227ee5f4ce60ed3f1c863fe506ee706e78b) * 5403888: [api] support v8::Data in v8::TracedReference and v8::EmbedderGraph https://chromium-review.googlesource.com/c/v8/v8/+/5403888 (cherry picked from commit 2030447cf5bbce26b73e2e9b054dee38438f9fdd) * chore: update patches * chore: fixup patch * 5465511: [api] Mark v8::ObjectTemplate::SetAccessor(..) for deprecation https://chromium-review.googlesource.com/c/v8/v8/+/5465511 * 5513528: Move service_provider_config files to components/enterprise/connectors/ https://chromium-review.googlesource.com/c/chromium/src/+/5513528 * chore: bump chromium in DEPS to 126.0.6478.17 * chore: bump chromium in DEPS to 126.0.6478.26 * chore: update patches * build: use Sha256Sum in script/sysroots.json Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5506275 (cherry picked from commit fccef2b6ba8769da9d8b1bd81fda5cc61b2086e0) * fixup! build: use Sha256Sum in script/sysroots.json `sync` succeeds now (cherry picked from commit e71852729fbf3575d1bc37774deadddfebdeefb4) * chore: cherry-pick Node.js patch for V8 API removal fix Node.js PR: https://github.com/nodejs/node/pull/52996 V8 API Removal CL: https://chromium-review.googlesource.com/c/v8/v8/+/5539888 See the patch description for more details. (cherry picked from commit ef0c441dbaa97478828ad481a39d0c2c93748729) * chore: revert v8 deprecation See patch message for more details. https://chromium-review.googlesource.com/c/v8/v8/+/5526611 (cherry picked from commit 6f03785eadea8d8629970c24393f0900fc3fa4af) * chore: revert v8 removal https://chromium-review.googlesource.com/c/v8/v8/+/5497515 See patch message for more details. (cherry picked from commit 4fd7f5bbb603b0461482fee027de7bfdbf02ceac) * 5522321: [devtools] Support saving base64 encoded files via host bindings https://chromium-review.googlesource.com/c/chromium/src/+/5522321 (cherry picked from commit 4b5f43d7838062834de6d634033fe10af2f9d01a) * fixup! 5465511: [api] Mark v8::ObjectTemplate::SetAccessor(..) for deprecation https://chromium-review.googlesource.com/c/v8/v8/+/5465511 (cherry picked from commit 368005f2b2f9195bcffb5325041e3ff1041a3830) * 5514687: Reland "Add a secret handshake to the base::Feature constructor" https://chromium-review.googlesource.com/c/chromium/src/+/5514687 (cherry picked from commit 142c6e16b10496b3fffddc9924001fb94096852e) * 5512176: Remove OnEnvironmentEstimationComplete() https://chromium-review.googlesource.com/c/chromium/src/+/5512176 (cherry picked from commit 1e20ffb24ef6d0b0aeec8c314393cb77631ab279) * 5539888: [api] Remove several APIs deprecated in version 12.6 https://chromium-review.googlesource.com/c/v8/v8/+/5539888 This commit essentially only removes the `only_terminate_in_safe_scope` isolate creation parameter. This undoes some work that was originally done in #35766. (cherry picked from commit ceb6182b199e2471c64700203bf42b73052a38c6) * 5492183: Extensions: CodeHealth: Give enums some class https://chromium-review.googlesource.com/c/chromium/src/+/5492183 (cherry picked from commit a11b8e637cdc0868b6152dd5b0ed3b582f446aa7) * 5483406: [PEPC] Make PEPC permission subscription take into account device status https://chromium-review.googlesource.com/c/chromium/src/+/5483406 (cherry picked from commit fc93c876b481a988a6c1d5eb69d97035dc5ad64a) * 5463431: iwa: Only create IsolatedWebAppURLLoaderFactory for subresources in IWAs https://chromium-review.googlesource.com/c/chromium/src/+/5463431 (cherry picked from commit fbfe3c998c8251f28b76c2703a3212b5b0175a84) * 5502081: Migrate OnDisplayRemoved to OnDisplaysRemoved https://chromium-review.googlesource.com/c/chromium/src/+/5502081 (cherry picked from commit ccf9a5137efdf2ca18d9ee9851388338c26d036e) * 5376861: Change references to RWHVB in RWHIER and RenderWidgetTargeter to RWHVI. https://chromium-review.googlesource.com/c/chromium/src/+/5376861 (cherry picked from commit fd3e6ce148b3c5ab27e234d28b9405933ba32b14) * fixup! 5530163: [media] Use VideoFrame::Plane typed enum instead of nameless enum https://chromium-review.googlesource.com/c/chromium/src/+/5530163 (cherry picked from commit 9a900e734a8c08e534317ca4d7411bfadd9087f5) * 5530163: [media] Use VideoFrame::Plane typed enum instead of nameless enum https://chromium-review.googlesource.com/c/chromium/src/+/5530163 (cherry picked from commit fd94de9736125c3121aed99f50f2702fc430ba26) * 5466238: PDF Viewer: add metrics to record if PDF is opened with a11y https://chromium-review.googlesource.com/c/chromium/src/+/5466238 (cherry picked from commit 2abb5d1737083241b6b6a4c05d5982693e956a22) * 5513740: Reland "[Extensions] Restructure extensions::ProcessMap" https://chromium-review.googlesource.com/c/chromium/src/+/5513740 (cherry picked from commit 11905a9840f1e8dce21cfdda1a23f328e8ff6a6a) * 5498236: Make browser_tests force full async initialization for OSCrypt Async https://chromium-review.googlesource.com/c/chromium/src/+/5498236 (cherry picked from commit e00faacb58545c37cfbf8a38a0cbe4ccb9f9df06) * fixup: only disable enterprise_cloud_content_analysis The original commita5480accc2
, was due to this CL 5527572: Move Connectors prefs files to components/enterprise/connectors/ | https://chromium-review.googlesource.com/c/chromium/src/+/5527572 (cherry picked from commit b0e2a7eab6c0decf982f913a892d5dfdb2501084) * chore: update patches * fixup: 5539888: [api] Remove several APIs deprecated in version 12.6 (cherry picked from commit ae65fea668baad44cac7073cbe0a64bca36bccac) * views: use CalculatePreferredSize(SizeBounds) in '/chrome/browser/ui/views/[frame, infobars, /test]'. https://chromium-review.googlesource.com/c/chromium/src/+/5493169 Needed because of 5504212: views: remove CalculatePreferredSize() | https://chromium-review.googlesource.com/c/chromium/src/+/5504212 * fixup: views: use CalculatePreferredSize(SizeBounds) * 5499157: Enable kBlockMidiByDefault by default https://chromium-review.googlesource.com/c/chromium/src/+/5499157 * 5518756: Reland^2: [heap] Add shared trusted spaces | https://chromium-review.googlesource.com/c/v8/v8/+/5518756ececfe7aea
* chore: bump chromium in DEPS to 126.0.6478.36 * chore: update patches * chore: add currently-unused should_include_device_status arg to GetPermissionStatusForCurrentDocument() Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5545382 (cherry picked from commit bc35c93efd2d3301e33116d2dd09abaf8eddbf70) --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: Keeley Hammond <khammond@slack-corp.com> Co-authored-by: VerteDinde <vertedinde@electronjs.org> Co-authored-by: Jeremy Rose <nornagon@nornagon.net> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: Charles Kerr <charles@charleskerr.com> Co-authored-by: clavin <clavin@electronjs.org> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com>
432 lines
15 KiB
C++
432 lines
15 KiB
C++
// Copyright (c) 2016 GitHub, Inc.
|
|
// Use of this source code is governed by the MIT license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "shell/browser/electron_permission_manager.h"
|
|
|
|
#include <memory>
|
|
#include <utility>
|
|
#include <vector>
|
|
|
|
#include "base/values.h"
|
|
#include "content/browser/permissions/permission_util.h" // nogncheck
|
|
#include "content/public/browser/child_process_security_policy.h"
|
|
#include "content/public/browser/global_routing_id.h"
|
|
#include "content/public/browser/permission_controller.h"
|
|
#include "content/public/browser/render_frame_host.h"
|
|
#include "content/public/browser/render_process_host.h"
|
|
#include "content/public/browser/render_view_host.h"
|
|
#include "content/public/browser/web_contents.h"
|
|
#include "gin/data_object_builder.h"
|
|
#include "shell/browser/api/electron_api_web_contents.h"
|
|
#include "shell/browser/electron_browser_client.h"
|
|
#include "shell/browser/electron_browser_main_parts.h"
|
|
#include "shell/browser/web_contents_permission_helper.h"
|
|
#include "shell/browser/web_contents_preferences.h"
|
|
#include "shell/common/gin_converters/content_converter.h"
|
|
#include "shell/common/gin_converters/frame_converter.h"
|
|
#include "shell/common/gin_converters/usb_protected_classes_converter.h"
|
|
#include "shell/common/gin_converters/value_converter.h"
|
|
#include "shell/common/gin_helper/event_emitter_caller.h"
|
|
#include "third_party/blink/public/common/permissions/permission_utils.h"
|
|
|
|
namespace electron {
|
|
|
|
namespace {
|
|
|
|
bool WebContentsDestroyed(content::RenderFrameHost* rfh) {
|
|
content::WebContents* web_contents =
|
|
content::WebContents::FromRenderFrameHost(rfh);
|
|
if (!web_contents)
|
|
return true;
|
|
return web_contents->IsBeingDestroyed();
|
|
}
|
|
|
|
void PermissionRequestResponseCallbackWrapper(
|
|
ElectronPermissionManager::StatusCallback callback,
|
|
const std::vector<blink::mojom::PermissionStatus>& vector) {
|
|
std::move(callback).Run(vector[0]);
|
|
}
|
|
|
|
} // namespace
|
|
|
|
class ElectronPermissionManager::PendingRequest {
|
|
public:
|
|
PendingRequest(content::RenderFrameHost* render_frame_host,
|
|
const std::vector<blink::PermissionType>& permissions,
|
|
StatusesCallback callback)
|
|
: render_frame_host_id_(render_frame_host->GetGlobalId()),
|
|
callback_(std::move(callback)),
|
|
permissions_(permissions),
|
|
results_(permissions.size(), blink::mojom::PermissionStatus::DENIED),
|
|
remaining_results_(permissions.size()) {}
|
|
|
|
void SetPermissionStatus(int permission_id,
|
|
blink::mojom::PermissionStatus status) {
|
|
DCHECK(!IsComplete());
|
|
|
|
if (status == blink::mojom::PermissionStatus::GRANTED) {
|
|
const auto permission = permissions_[permission_id];
|
|
if (permission == blink::PermissionType::MIDI_SYSEX) {
|
|
content::ChildProcessSecurityPolicy::GetInstance()
|
|
->GrantSendMidiSysExMessage(render_frame_host_id_.child_id);
|
|
} else if (permission == blink::PermissionType::GEOLOCATION) {
|
|
ElectronBrowserMainParts::Get()
|
|
->GetGeolocationControl()
|
|
->UserDidOptIntoLocationServices();
|
|
}
|
|
}
|
|
|
|
results_[permission_id] = status;
|
|
--remaining_results_;
|
|
}
|
|
|
|
content::RenderFrameHost* GetRenderFrameHost() {
|
|
return content::RenderFrameHost::FromID(render_frame_host_id_);
|
|
}
|
|
|
|
bool IsComplete() const { return remaining_results_ == 0; }
|
|
|
|
void RunCallback() {
|
|
if (!callback_.is_null()) {
|
|
std::move(callback_).Run(results_);
|
|
}
|
|
}
|
|
|
|
private:
|
|
content::GlobalRenderFrameHostId render_frame_host_id_;
|
|
StatusesCallback callback_;
|
|
std::vector<blink::PermissionType> permissions_;
|
|
std::vector<blink::mojom::PermissionStatus> results_;
|
|
size_t remaining_results_;
|
|
};
|
|
|
|
ElectronPermissionManager::ElectronPermissionManager() = default;
|
|
|
|
ElectronPermissionManager::~ElectronPermissionManager() = default;
|
|
|
|
void ElectronPermissionManager::SetPermissionRequestHandler(
|
|
const RequestHandler& handler) {
|
|
if (handler.is_null() && !pending_requests_.IsEmpty()) {
|
|
for (PendingRequestsMap::iterator iter(&pending_requests_); !iter.IsAtEnd();
|
|
iter.Advance()) {
|
|
auto* request = iter.GetCurrentValue();
|
|
if (!WebContentsDestroyed(request->GetRenderFrameHost()))
|
|
request->RunCallback();
|
|
}
|
|
pending_requests_.Clear();
|
|
}
|
|
request_handler_ = handler;
|
|
}
|
|
|
|
void ElectronPermissionManager::SetPermissionCheckHandler(
|
|
const CheckHandler& handler) {
|
|
check_handler_ = handler;
|
|
}
|
|
|
|
void ElectronPermissionManager::SetDevicePermissionHandler(
|
|
const DeviceCheckHandler& handler) {
|
|
device_permission_handler_ = handler;
|
|
}
|
|
|
|
void ElectronPermissionManager::SetProtectedUSBHandler(
|
|
const ProtectedUSBHandler& handler) {
|
|
protected_usb_handler_ = handler;
|
|
}
|
|
|
|
void ElectronPermissionManager::SetBluetoothPairingHandler(
|
|
const BluetoothPairingHandler& handler) {
|
|
bluetooth_pairing_handler_ = handler;
|
|
}
|
|
|
|
void ElectronPermissionManager::RequestPermissionWithDetails(
|
|
blink::PermissionType permission,
|
|
content::RenderFrameHost* render_frame_host,
|
|
const GURL& requesting_origin,
|
|
bool user_gesture,
|
|
base::Value::Dict details,
|
|
StatusCallback response_callback) {
|
|
if (render_frame_host->IsNestedWithinFencedFrame()) {
|
|
std::move(response_callback).Run(blink::mojom::PermissionStatus::DENIED);
|
|
return;
|
|
}
|
|
|
|
RequestPermissionsWithDetails(
|
|
render_frame_host,
|
|
content::PermissionRequestDescription(permission, user_gesture,
|
|
requesting_origin),
|
|
std::move(details),
|
|
base::BindOnce(PermissionRequestResponseCallbackWrapper,
|
|
std::move(response_callback)));
|
|
}
|
|
|
|
void ElectronPermissionManager::RequestPermissions(
|
|
content::RenderFrameHost* render_frame_host,
|
|
const content::PermissionRequestDescription& request_description,
|
|
StatusesCallback callback) {
|
|
if (render_frame_host->IsNestedWithinFencedFrame()) {
|
|
std::move(callback).Run(std::vector<blink::mojom::PermissionStatus>(
|
|
request_description.permissions.size(),
|
|
blink::mojom::PermissionStatus::DENIED));
|
|
return;
|
|
}
|
|
|
|
RequestPermissionsWithDetails(render_frame_host, request_description, {},
|
|
std::move(callback));
|
|
}
|
|
|
|
void ElectronPermissionManager::RequestPermissionsWithDetails(
|
|
content::RenderFrameHost* render_frame_host,
|
|
const content::PermissionRequestDescription& request_description,
|
|
base::Value::Dict details,
|
|
StatusesCallback response_callback) {
|
|
auto& permissions = request_description.permissions;
|
|
if (permissions.empty()) {
|
|
std::move(response_callback).Run({});
|
|
return;
|
|
}
|
|
|
|
if (request_handler_.is_null()) {
|
|
std::vector<blink::mojom::PermissionStatus> statuses;
|
|
for (auto& permission : permissions) {
|
|
if (permission == blink::PermissionType::MIDI_SYSEX) {
|
|
content::ChildProcessSecurityPolicy::GetInstance()
|
|
->GrantSendMidiSysExMessage(
|
|
render_frame_host->GetProcess()->GetID());
|
|
} else if (permission == blink::PermissionType::GEOLOCATION) {
|
|
ElectronBrowserMainParts::Get()
|
|
->GetGeolocationControl()
|
|
->UserDidOptIntoLocationServices();
|
|
}
|
|
statuses.push_back(blink::mojom::PermissionStatus::GRANTED);
|
|
}
|
|
std::move(response_callback).Run(statuses);
|
|
return;
|
|
}
|
|
|
|
auto* web_contents =
|
|
content::WebContents::FromRenderFrameHost(render_frame_host);
|
|
int request_id = pending_requests_.Add(std::make_unique<PendingRequest>(
|
|
render_frame_host, permissions, std::move(response_callback)));
|
|
|
|
details.Set("requestingUrl", render_frame_host->GetLastCommittedURL().spec());
|
|
details.Set("isMainFrame", render_frame_host->GetParent() == nullptr);
|
|
base::Value dict_value(std::move(details));
|
|
|
|
for (size_t i = 0; i < permissions.size(); ++i) {
|
|
auto permission = permissions[i];
|
|
const auto callback =
|
|
base::BindRepeating(&ElectronPermissionManager::OnPermissionResponse,
|
|
base::Unretained(this), request_id, i);
|
|
request_handler_.Run(web_contents, permission, callback, dict_value);
|
|
}
|
|
}
|
|
|
|
void ElectronPermissionManager::OnPermissionResponse(
|
|
int request_id,
|
|
int permission_id,
|
|
blink::mojom::PermissionStatus status) {
|
|
auto* pending_request = pending_requests_.Lookup(request_id);
|
|
if (!pending_request)
|
|
return;
|
|
|
|
pending_request->SetPermissionStatus(permission_id, status);
|
|
if (pending_request->IsComplete()) {
|
|
pending_request->RunCallback();
|
|
pending_requests_.Remove(request_id);
|
|
}
|
|
}
|
|
|
|
void ElectronPermissionManager::ResetPermission(
|
|
blink::PermissionType permission,
|
|
const GURL& requesting_origin,
|
|
const GURL& embedding_origin) {}
|
|
|
|
void ElectronPermissionManager::RequestPermissionsFromCurrentDocument(
|
|
content::RenderFrameHost* render_frame_host,
|
|
const content::PermissionRequestDescription& request_description,
|
|
base::OnceCallback<void(const std::vector<blink::mojom::PermissionStatus>&)>
|
|
callback) {
|
|
if (render_frame_host->IsNestedWithinFencedFrame()) {
|
|
std::move(callback).Run(std::vector<blink::mojom::PermissionStatus>(
|
|
request_description.permissions.size(),
|
|
blink::mojom::PermissionStatus::DENIED));
|
|
return;
|
|
}
|
|
|
|
RequestPermissionsWithDetails(render_frame_host, request_description, {},
|
|
std::move(callback));
|
|
}
|
|
|
|
blink::mojom::PermissionStatus ElectronPermissionManager::GetPermissionStatus(
|
|
blink::PermissionType permission,
|
|
const GURL& requesting_origin,
|
|
const GURL& embedding_origin) {
|
|
base::Value::Dict details;
|
|
details.Set("embeddingOrigin", embedding_origin.spec());
|
|
bool granted = CheckPermissionWithDetails(permission, {}, requesting_origin,
|
|
std::move(details));
|
|
return granted ? blink::mojom::PermissionStatus::GRANTED
|
|
: blink::mojom::PermissionStatus::DENIED;
|
|
}
|
|
|
|
content::PermissionResult
|
|
ElectronPermissionManager::GetPermissionResultForOriginWithoutContext(
|
|
blink::PermissionType permission,
|
|
const url::Origin& requesting_origin,
|
|
const url::Origin& embedding_origin) {
|
|
blink::mojom::PermissionStatus status = GetPermissionStatus(
|
|
permission, requesting_origin.GetURL(), embedding_origin.GetURL());
|
|
return content::PermissionResult(
|
|
status, content::PermissionStatusSource::UNSPECIFIED);
|
|
}
|
|
|
|
void ElectronPermissionManager::CheckBluetoothDevicePair(
|
|
gin_helper::Dictionary details,
|
|
PairCallback pair_callback) const {
|
|
if (bluetooth_pairing_handler_.is_null()) {
|
|
base::Value::Dict response;
|
|
response.Set("confirmed", false);
|
|
std::move(pair_callback).Run(std::move(response));
|
|
} else {
|
|
bluetooth_pairing_handler_.Run(details, std::move(pair_callback));
|
|
}
|
|
}
|
|
|
|
bool ElectronPermissionManager::CheckPermissionWithDetails(
|
|
blink::PermissionType permission,
|
|
content::RenderFrameHost* render_frame_host,
|
|
const GURL& requesting_origin,
|
|
base::Value::Dict details) const {
|
|
if (check_handler_.is_null())
|
|
return true;
|
|
|
|
auto* web_contents =
|
|
render_frame_host
|
|
? content::WebContents::FromRenderFrameHost(render_frame_host)
|
|
: nullptr;
|
|
if (render_frame_host) {
|
|
details.Set("requestingUrl",
|
|
render_frame_host->GetLastCommittedURL().spec());
|
|
}
|
|
details.Set("isMainFrame",
|
|
render_frame_host && render_frame_host->GetParent() == nullptr);
|
|
switch (permission) {
|
|
case blink::PermissionType::AUDIO_CAPTURE:
|
|
details.Set("mediaType", "audio");
|
|
break;
|
|
case blink::PermissionType::VIDEO_CAPTURE:
|
|
details.Set("mediaType", "video");
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
return check_handler_.Run(web_contents, permission, requesting_origin,
|
|
base::Value(std::move(details)));
|
|
}
|
|
|
|
bool ElectronPermissionManager::CheckDevicePermission(
|
|
blink::PermissionType permission,
|
|
const url::Origin& origin,
|
|
const base::Value& device,
|
|
ElectronBrowserContext* browser_context) const {
|
|
if (device_permission_handler_.is_null())
|
|
return browser_context->CheckDevicePermission(origin, device, permission);
|
|
|
|
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
|
v8::HandleScope scope(isolate);
|
|
v8::Local<v8::Object> details = gin::DataObjectBuilder(isolate)
|
|
.Set("deviceType", permission)
|
|
.Set("origin", origin.Serialize())
|
|
.Set("device", device.Clone())
|
|
.Build();
|
|
return device_permission_handler_.Run(details);
|
|
}
|
|
|
|
void ElectronPermissionManager::GrantDevicePermission(
|
|
blink::PermissionType permission,
|
|
const url::Origin& origin,
|
|
const base::Value& device,
|
|
ElectronBrowserContext* browser_context) const {
|
|
if (device_permission_handler_.is_null()) {
|
|
browser_context->GrantDevicePermission(origin, device, permission);
|
|
}
|
|
}
|
|
|
|
void ElectronPermissionManager::RevokeDevicePermission(
|
|
blink::PermissionType permission,
|
|
const url::Origin& origin,
|
|
const base::Value& device,
|
|
ElectronBrowserContext* browser_context) const {
|
|
browser_context->RevokeDevicePermission(origin, device, permission);
|
|
}
|
|
|
|
ElectronPermissionManager::USBProtectedClasses
|
|
ElectronPermissionManager::CheckProtectedUSBClasses(
|
|
const USBProtectedClasses& classes) const {
|
|
if (protected_usb_handler_.is_null())
|
|
return classes;
|
|
|
|
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
|
v8::HandleScope scope(isolate);
|
|
v8::Local<v8::Object> details =
|
|
gin::DataObjectBuilder(isolate).Set("protectedClasses", classes).Build();
|
|
return protected_usb_handler_.Run(details);
|
|
}
|
|
|
|
blink::mojom::PermissionStatus
|
|
ElectronPermissionManager::GetPermissionStatusForCurrentDocument(
|
|
blink::PermissionType permission,
|
|
content::RenderFrameHost* render_frame_host,
|
|
bool /*should_include_device_status*/) {
|
|
if (render_frame_host->IsNestedWithinFencedFrame())
|
|
return blink::mojom::PermissionStatus::DENIED;
|
|
|
|
base::Value::Dict details;
|
|
details.Set("embeddingOrigin",
|
|
content::PermissionUtil::GetLastCommittedOriginAsURL(
|
|
render_frame_host->GetMainFrame())
|
|
.spec());
|
|
bool granted = CheckPermissionWithDetails(
|
|
permission, render_frame_host,
|
|
render_frame_host->GetLastCommittedOrigin().GetURL(), std::move(details));
|
|
return granted ? blink::mojom::PermissionStatus::GRANTED
|
|
: blink::mojom::PermissionStatus::DENIED;
|
|
}
|
|
|
|
blink::mojom::PermissionStatus
|
|
ElectronPermissionManager::GetPermissionStatusForWorker(
|
|
blink::PermissionType permission,
|
|
content::RenderProcessHost* render_process_host,
|
|
const GURL& worker_origin) {
|
|
return GetPermissionStatus(permission, worker_origin, worker_origin);
|
|
}
|
|
|
|
blink::mojom::PermissionStatus
|
|
ElectronPermissionManager::GetPermissionStatusForEmbeddedRequester(
|
|
blink::PermissionType permission,
|
|
content::RenderFrameHost* render_frame_host,
|
|
const url::Origin& overridden_origin) {
|
|
if (render_frame_host->IsNestedWithinFencedFrame())
|
|
return blink::mojom::PermissionStatus::DENIED;
|
|
|
|
return GetPermissionStatus(
|
|
permission, overridden_origin.GetURL(),
|
|
render_frame_host->GetLastCommittedOrigin().GetURL());
|
|
}
|
|
|
|
ElectronPermissionManager::SubscriptionId
|
|
ElectronPermissionManager::SubscribeToPermissionStatusChange(
|
|
blink::PermissionType permission,
|
|
content::RenderProcessHost* render_process_host,
|
|
content::RenderFrameHost* render_frame_host,
|
|
const GURL& requesting_origin,
|
|
bool should_include_device_status,
|
|
base::RepeatingCallback<void(blink::mojom::PermissionStatus)> callback) {
|
|
return SubscriptionId();
|
|
}
|
|
|
|
void ElectronPermissionManager::UnsubscribeFromPermissionStatusChange(
|
|
SubscriptionId id) {}
|
|
|
|
} // namespace electron
|