/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// Particular type of permissions to care about. We decide cases by case and // give various types of controls over each of these. staticconst DelegateInfo sPermissionsMap[] = { // Permissions API map. All permission names have to be in lowercase.
{"geo", u"geolocation", DelegatePolicy::eDelegateUseFeaturePolicy}, // The same with geo, but we support both to save some conversions between // "geo" and "geolocation"
{"geolocation", u"geolocation", DelegatePolicy::eDelegateUseFeaturePolicy},
{"desktop-notification", nullptr,
DelegatePolicy::ePersistDeniedCrossOrigin},
{"persistent-storage", nullptr, DelegatePolicy::ePersistDeniedCrossOrigin},
{"vibration", nullptr, DelegatePolicy::ePersistDeniedCrossOrigin},
{"midi", nullptr, DelegatePolicy::eDelegateUseIframeOrigin}, // Like "midi" but with sysex support.
{"midi-sysex", nullptr, DelegatePolicy::eDelegateUseIframeOrigin},
{"storage-access", nullptr, DelegatePolicy::eDelegateUseIframeOrigin},
{"camera", u"camera", DelegatePolicy::eDelegateUseFeaturePolicy},
{"microphone", u"microphone", DelegatePolicy::eDelegateUseFeaturePolicy},
{"screen", u"display-capture", DelegatePolicy::eDelegateUseFeaturePolicy},
{"xr", u"xr-spatial-tracking", DelegatePolicy::eDelegateUseFeaturePolicy},
{"screen-wake-lock", u"screen-wake-lock",
DelegatePolicy::eDelegateUseFeaturePolicy}};
static_assert(PermissionDelegateHandler::DELEGATED_PERMISSION_COUNT ==
(sizeof(sPermissionsMap) / sizeof(DelegateInfo)), "The PermissionDelegateHandler::DELEGATED_PERMISSION_COUNT must " "match to the " "length of sPermissionsMap. Please update it.");
RefPtr<BrowsingContext> bc = aDocument->GetBrowsingContext(); if (!bc) { returntrue;
}
RefPtr<BrowsingContext> topBC = bc->Top();
// In Fission, we can know if it is cross-origin by checking whether both // contexts in the same process. So, If they are not in the same process, we // can say that it's cross-origin. if (!topBC->IsInProcess()) { returntrue;
}
RefPtr<Document> topDoc = topBC->GetDocument(); if (!topDoc) { returntrue;
}
nsIPrincipal* principal = mPrincipal; // If we cannot get the browsing context from the document, we fallback to use // the prinicpal of the document to test the permission.
RefPtr<BrowsingContext> bc = mDocument->GetBrowsingContext();
if (topWC && topWC->IsInProcess()) { // If the top-level window context is in the same process, we directly get // the node principal from the top-level document to test the permission. // We cannot check the lists in the window context in this case since the // 'perm-changed' could be notified in the iframe before the top-level in // certain cases, for example, request permissions in first-party iframes. // In this case, the list in window context hasn't gotten updated, so it // would has an out-dated value until the top-level window get the // observer. So, we have to test permission manager directly if we can.
RefPtr<Document> topDoc = topWC->GetBrowsingContext()->GetDocument();
if (topDoc) {
principal = topDoc->NodePrincipal();
}
} elseif (topWC) { // Get the delegated permissions from the top-level window context.
DelegatedPermissionList list =
aExactHostMatch ? topWC->GetDelegatedExactHostMatchPermissions()
: topWC->GetDelegatedPermissions();
size_t idx = std::distance(sPermissionsMap, info);
*aPermission = list.mPermissions[idx]; return NS_OK;
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.