Backed out changeset ae33b9c001e5 (bug 1580462) for build bustages on nsWindow.cpp. CLOSED TREE

This commit is contained in:
Razvan Maries 2019-10-23 11:07:00 +03:00
Родитель a220530f6b
Коммит 7fb625f8cf
17 изменённых файлов: 30 добавлений и 436 удалений

Просмотреть файл

@ -14,7 +14,6 @@
#include "mozilla/dom/BindingDeclarations.h"
#include "mozilla/dom/LoadURIOptionsBinding.h"
#include "mozilla/dom/LocationBase.h"
#include "mozilla/dom/FeaturePolicyUtils.h"
#include "mozilla/dom/UserActivation.h"
#include "nsCOMPtr.h"
#include "nsCycleCollectionParticipant.h"

Просмотреть файл

@ -36,5 +36,4 @@ MOZ_BC_FIELD(UserActivationState, UserActivation::State)
// on top level browsing contexts only.
MOZ_BC_FIELD(Muted, bool)
MOZ_BC_FIELD(FeaturePolicy, RefPtr<mozilla::dom::FeaturePolicy>)
#undef MOZ_BC_FIELD

Просмотреть файл

@ -94,7 +94,6 @@
#include "mozilla/dom/Attr.h"
#include "mozilla/dom/BindingDeclarations.h"
#include "mozilla/dom/BrowsingContext.h"
#include "mozilla/dom/ContentChild.h"
#include "mozilla/dom/CSPDictionariesBinding.h"
#include "mozilla/dom/Element.h"
@ -3282,40 +3281,6 @@ nsresult Document::InitCSP(nsIChannel* aChannel) {
return NS_OK;
}
already_AddRefed<mozilla::dom::FeaturePolicy>
Document::GetParentFeaturePolicy() {
if (!mDocumentContainer) {
return nullptr;
}
nsPIDOMWindowOuter* containerWindow = mDocumentContainer->GetWindow();
if (!containerWindow) {
return nullptr;
}
BrowsingContext* context = containerWindow->GetBrowsingContext();
if (!context) {
return nullptr;
}
RefPtr<mozilla::dom::FeaturePolicy> parentPolicy;
if (context->IsContentSubframe() && !context->GetParent()->IsInProcess()) {
// We are in cross process, so try to get feature policy from
// container's BrowsingContext
parentPolicy = context->GetFeaturePolicy();
return parentPolicy.forget();
}
nsCOMPtr<nsINode> node = containerWindow->GetFrameElementInternal();
HTMLIFrameElement* iframe = HTMLIFrameElement::FromNodeOrNull(node);
if (!iframe) {
return nullptr;
}
parentPolicy = iframe->FeaturePolicy();
return parentPolicy.forget();
}
nsresult Document::InitFeaturePolicy(nsIChannel* aChannel) {
MOZ_ASSERT(mFeaturePolicy, "we should only call init once");
@ -3327,7 +3292,18 @@ nsresult Document::InitFeaturePolicy(nsIChannel* aChannel) {
mFeaturePolicy->SetDefaultOrigin(NodePrincipal());
RefPtr<mozilla::dom::FeaturePolicy> parentPolicy = GetParentFeaturePolicy();
RefPtr<mozilla::dom::FeaturePolicy> parentPolicy = nullptr;
if (mDocumentContainer) {
nsPIDOMWindowOuter* containerWindow = mDocumentContainer->GetWindow();
if (containerWindow) {
nsCOMPtr<nsINode> node = containerWindow->GetFrameElementInternal();
HTMLIFrameElement* iframe = HTMLIFrameElement::FromNodeOrNull(node);
if (iframe) {
parentPolicy = iframe->FeaturePolicy();
}
}
}
if (parentPolicy) {
// Let's inherit the policy from the parent HTMLIFrameElement if it exists.
mFeaturePolicy->InheritPolicy(parentPolicy);

Просмотреть файл

@ -52,6 +52,7 @@
#include "ReferrerInfo.h"
#include "mozilla/Attributes.h"
#include "mozilla/CORSMode.h"
#include "mozilla/dom/BrowsingContext.h"
#include "mozilla/dom/ContentBlockingLog.h"
#include "mozilla/dom/DispatcherTrait.h"
#include "mozilla/dom/DocumentOrShadowRoot.h"
@ -89,7 +90,6 @@ class imgIRequest;
class nsBindingManager;
#endif
class nsCachableElementsByNameNodeList;
class nsCommandManager;
class nsContentList;
class nsIDocShell;
class nsDocShell;
@ -221,8 +221,6 @@ class XPathEvaluator;
class XPathExpression;
class XPathNSResolver;
class XPathResult;
class BrowsingContext;
template <typename>
class Sequence;
@ -4051,10 +4049,6 @@ class Document : public nsINode,
// Returns true if there is any valid scale value in the |aViewportMetaData|.
bool ParseScalesInViewportMetaData(const ViewportMetaData& aViewportMetaData);
// Get parent FeaturePolicy from container. The parent FeaturePolicy is
// stored in parent iframe or container's browsingContext (cross process)
already_AddRefed<mozilla::dom::FeaturePolicy> GetParentFeaturePolicy();
// Returns a ViewportMetaData for this document.
ViewportMetaData GetViewportMetaData() const;

Просмотреть файл

@ -490,7 +490,7 @@ bool WebGLContext::CreateAndInitGL(
auto powerPref = mOptions.powerPreference;
// If "Use hardware acceleration when available" option is disabled:
if (!gfxConfig::IsEnabled(gfx::Feature::HW_COMPOSITING)) {
if (!gfxConfig::IsEnabled(Feature::HW_COMPOSITING)) {
powerPref = dom::WebGLPowerPreference::Low_power;
}

Просмотреть файл

@ -57,6 +57,7 @@ HTMLIFrameElement::HTMLIFrameElement(
: nsGenericHTMLFrameElement(std::move(aNodeInfo), aFromParser) {
// We always need a featurePolicy, even if not exposed.
mFeaturePolicy = new mozilla::dom::FeaturePolicy(this);
nsCOMPtr<nsIPrincipal> origin = GetFeaturePolicyDefaultOrigin();
MOZ_ASSERT(origin);
mFeaturePolicy->SetDefaultOrigin(origin);
@ -229,42 +230,6 @@ mozilla::dom::FeaturePolicy* HTMLIFrameElement::FeaturePolicy() const {
return mFeaturePolicy;
}
void HTMLIFrameElement::MaybeStoreCrossOriginFeaturePolicy() {
if (!mFrameLoader) {
return;
}
// If the browsingContext is not ready (because docshell is dead), don't try
// to create one.
if (!mFrameLoader->IsRemoteFrame() && !mFrameLoader->GetExistingDocShell()) {
return;
}
RefPtr<BrowsingContext> browsingContext = mFrameLoader->GetBrowsingContext();
if (!browsingContext || !browsingContext->IsContentSubframe()) {
return;
}
// If we are in subframe cross origin, store the featurePolicy to
// browsingContext
nsPIDOMWindowOuter* topWindow = browsingContext->Top()->GetDOMWindow();
if (NS_WARN_IF(!topWindow)) {
return;
}
Document* topLevelDocument = topWindow->GetExtantDoc();
if (NS_WARN_IF(!topLevelDocument)) {
return;
}
if (!NS_SUCCEEDED(nsContentUtils::CheckSameOrigin(topLevelDocument, this))) {
return;
}
browsingContext->SetFeaturePolicy(mFeaturePolicy);
}
already_AddRefed<nsIPrincipal>
HTMLIFrameElement::GetFeaturePolicyDefaultOrigin() const {
nsCOMPtr<nsIPrincipal> principal;
@ -317,8 +282,6 @@ void HTMLIFrameElement::RefreshFeaturePolicy(bool aParseAllowAttribute) {
if (AllowFullscreen()) {
mFeaturePolicy->MaybeSetAllowedPolicy(NS_LITERAL_STRING("fullscreen"));
}
MaybeStoreCrossOriginFeaturePolicy();
}
} // namespace dom

Просмотреть файл

@ -200,12 +200,6 @@ class HTMLIFrameElement final : public nsGenericHTMLFrameElement {
*/
void AfterMaybeChangeAttr(int32_t aNamespaceID, nsAtom* aName, bool aNotify);
/**
* Feature policy inheritance is broken in cross process model, so we may
* have to store feature policy in browsingContext when neccesary.
*/
void MaybeStoreCrossOriginFeaturePolicy();
RefPtr<dom::FeaturePolicy> mFeaturePolicy;
RefPtr<nsDOMTokenList> mSandbox;
};

Просмотреть файл

@ -115,15 +115,6 @@ struct FrameScriptInfo
bool runInGlobalScope;
};
struct FeaturePolicyInfo
{
nsString[] inheritedDeniedFeatureNames;
nsString declaredString;
nsIPrincipal defaultOrigin;
nsIPrincipal selfOrigin;
nsIPrincipal srcOrigin;
};
/**
* The information required to complete a window creation request.
*/

Просмотреть файл

@ -14,7 +14,7 @@
namespace mozilla {
namespace dom {
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(FeaturePolicy)
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(FeaturePolicy, mParentNode)
NS_IMPL_CYCLE_COLLECTING_ADDREF(FeaturePolicy)
NS_IMPL_CYCLE_COLLECTING_RELEASE(FeaturePolicy)
@ -82,20 +82,11 @@ void FeaturePolicy::SetDeclaredPolicy(Document* aDocument,
nsIPrincipal* aSrcOrigin) {
ResetDeclaredPolicy();
mDeclaredString = aPolicyString;
mSelfOrigin = aSelfOrigin;
mSrcOrigin = aSrcOrigin;
Unused << NS_WARN_IF(!FeaturePolicyParser::ParseString(
aPolicyString, aDocument, aSelfOrigin, aSrcOrigin, mFeatures));
}
void FeaturePolicy::ResetDeclaredPolicy() {
mFeatures.Clear();
mDeclaredString.Truncate();
mSelfOrigin = nullptr;
mSrcOrigin = nullptr;
}
void FeaturePolicy::ResetDeclaredPolicy() { mFeatures.Clear(); }
JSObject* FeaturePolicy::WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) {

Просмотреть файл

@ -120,22 +120,6 @@ class FeaturePolicy final : public nsISupports, public nsWrapperCache {
void GetAllowlistForFeature(const nsAString& aFeatureName,
nsTArray<nsString>& aList) const;
void GetInheritedDeniedFeatureNames(
nsTArray<nsString>& aInheritedDeniedFeatureNames) {
aInheritedDeniedFeatureNames = mInheritedDeniedFeatureNames;
}
void SetInheritedDeniedFeatureNames(
const nsTArray<nsString>& aInheritedDeniedFeatureNames) {
mInheritedDeniedFeatureNames = aInheritedDeniedFeatureNames;
}
void GetDeclaredString(nsAString& aDeclaredString) {
aDeclaredString = mDeclaredString;
}
nsIPrincipal* GetSelfOrigin() const { return mSelfOrigin; }
nsIPrincipal* GetSrcOrigin() const { return mSrcOrigin; }
private:
~FeaturePolicy() = default;
@ -153,7 +137,7 @@ class FeaturePolicy final : public nsISupports, public nsWrapperCache {
// This returns true if we have a declared feature policy for aFeatureName.
bool HasDeclaredFeature(const nsAString& aFeatureName) const;
nsINode* mParentNode;
nsCOMPtr<nsINode> mParentNode;
// This is set in sub-contexts when the parent blocks some feature for the
// current context.
@ -162,12 +146,7 @@ class FeaturePolicy final : public nsISupports, public nsWrapperCache {
// Feature policy for the current context.
nsTArray<Feature> mFeatures;
// Declared string represents Feature policy.
nsString mDeclaredString;
nsCOMPtr<nsIPrincipal> mDefaultOrigin;
nsCOMPtr<nsIPrincipal> mSelfOrigin;
nsCOMPtr<nsIPrincipal> mSrcOrigin;
};
} // namespace dom

Просмотреть файл

@ -20,10 +20,6 @@ namespace {
void ReportToConsoleUnsupportedFeature(Document* aDocument,
const nsString& aFeatureName) {
if (!aDocument) {
return;
}
AutoTArray<nsString, 1> params = {aFeatureName};
nsContentUtils::ReportToConsole(
@ -34,10 +30,6 @@ void ReportToConsoleUnsupportedFeature(Document* aDocument,
void ReportToConsoleInvalidEmptyAllowValue(Document* aDocument,
const nsString& aFeatureName) {
if (!aDocument) {
return;
}
AutoTArray<nsString, 1> params = {aFeatureName};
nsContentUtils::ReportToConsole(
@ -48,10 +40,6 @@ void ReportToConsoleInvalidEmptyAllowValue(Document* aDocument,
void ReportToConsoleInvalidAllowValue(Document* aDocument,
const nsString& aValue) {
if (!aDocument) {
return;
}
AutoTArray<nsString, 1> params = {aValue};
nsContentUtils::ReportToConsole(

Просмотреть файл

@ -5,14 +5,12 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "FeaturePolicyUtils.h"
#include "nsIURIFixup.h"
#include "mozilla/dom/DOMTypes.h"
#include "mozilla/ipc/IPDLParamTraits.h"
#include "mozilla/dom/FeaturePolicy.h"
#include "mozilla/dom/FeaturePolicyViolationReportBody.h"
#include "mozilla/dom/ReportingUtils.h"
#include "mozilla/StaticPrefs_dom.h"
#include "mozilla/dom/Document.h"
#include "nsIURIFixup.h"
namespace mozilla {
namespace dom {
@ -164,64 +162,4 @@ void FeaturePolicyUtils::ReportViolation(Document* aDocument,
}
} // namespace dom
namespace ipc {
void IPDLParamTraits<dom::FeaturePolicy*>::Write(IPC::Message* aMsg,
IProtocol* aActor,
dom::FeaturePolicy* aParam) {
if (!aParam) {
WriteIPDLParam(aMsg, aActor, false);
return;
}
WriteIPDLParam(aMsg, aActor, true);
dom::FeaturePolicyInfo info;
info.defaultOrigin() = aParam->DefaultOrigin();
info.selfOrigin() = aParam->GetSelfOrigin();
info.srcOrigin() = aParam->GetSrcOrigin();
aParam->GetDeclaredString(info.declaredString());
aParam->GetInheritedDeniedFeatureNames(info.inheritedDeniedFeatureNames());
WriteIPDLParam(aMsg, aActor, info);
}
bool IPDLParamTraits<dom::FeaturePolicy*>::Read(
const IPC::Message* aMsg, PickleIterator* aIter, IProtocol* aActor,
RefPtr<dom::FeaturePolicy>* aResult) {
*aResult = nullptr;
bool notnull = false;
if (!ReadIPDLParam(aMsg, aIter, aActor, &notnull)) {
return false;
}
if (!notnull) {
return true;
}
dom::FeaturePolicyInfo info;
if (!ReadIPDLParam(aMsg, aIter, aActor, &info)) {
return false;
}
// Note that we only do IPC for feature policy to inherit poicy from parent
// to child document. That does not need to bind feature policy with a node.
RefPtr<dom::FeaturePolicy> featurePolicy = new dom::FeaturePolicy(nullptr);
featurePolicy->SetDefaultOrigin(info.defaultOrigin());
featurePolicy->SetInheritedDeniedFeatureNames(
info.inheritedDeniedFeatureNames());
nsString declaredString = info.declaredString();
if (declaredString.IsEmpty() || !info.selfOrigin()) {
*aResult = featurePolicy.forget();
return true;
}
featurePolicy->SetDeclaredPolicy(nullptr, declaredString, info.selfOrigin(),
info.srcOrigin());
*aResult = featurePolicy.forget();
return true;
}
} // namespace ipc
} // namespace mozilla

Просмотреть файл

@ -10,8 +10,6 @@
#include "nsString.h"
#include <functional>
#include "mozilla/dom/FeaturePolicy.h"
namespace mozilla {
namespace dom {
@ -52,23 +50,6 @@ class FeaturePolicyUtils final {
};
} // namespace dom
namespace ipc {
class IProtocol;
template <typename T>
struct IPDLParamTraits;
template <>
struct IPDLParamTraits<mozilla::dom::FeaturePolicy*> {
static void Write(IPC::Message* aMsg, IProtocol* aActor,
mozilla::dom::FeaturePolicy* aParam);
static bool Read(const IPC::Message* aMsg, PickleIterator* aIter,
IProtocol* aActor,
RefPtr<mozilla::dom::FeaturePolicy>* aResult);
};
} // namespace ipc
} // namespace mozilla
#endif // mozilla_dom_FeaturePolicyUtils_h

Просмотреть файл

@ -7,13 +7,10 @@
</head>
<body>
<iframe src="empty.html" id="ifr"></iframe>
<iframe src="http://example.org/tests/dom/security/featurePolicy/test/mochitest/empty.html" id="cross_ifr"></iframe>
<script type="text/javascript">
SimpleTest.waitForExplicitFinish();
const CROSS_ORIGIN = "http://example.org";
function test_document() {
info("Checking document.featurePolicy");
ok("featurePolicy" in document, "We have document.featurePolicy");
@ -200,206 +197,11 @@ function test_iframe_contentDocument() {
document.body.appendChild(ifr);
}
function test_cross_iframe_without_allow() {
info("Checking cross HTMLIFrameElement.featurePolicy no allow");
let ifr = document.getElementById("cross_ifr");
ok("featurePolicy" in ifr, "HTMLIFrameElement.featurePolicy exists");
ok(!ifr.featurePolicy.allowsFeature("foobar"), "Random feature");
ok(!ifr.featurePolicy.allowsFeature("foobar", "http://www.something.net"), "Random feature");
ok(ifr.featurePolicy.allowsFeature("camera"), "Camera is allowed for self");
ok(ifr.featurePolicy.allowsFeature("camera", CROSS_ORIGIN), "Camera is allowed for self");
ok(!ifr.featurePolicy.allowsFeature("camera", "http://foo.bar"), "Camera is not allowed for a random URL");
let allowed = ifr.featurePolicy.getAllowlistForFeature("camera");
is(allowed.length, 1, "Only 1 entry in allowlist for camera");
is(allowed[0], CROSS_ORIGIN, "allowlist is 'self'");
ok(!ifr.featurePolicy.allowsFeature("geolocation"), "Geolocation is not allowed for self");
ok(!ifr.featurePolicy.allowsFeature("geolocation", CROSS_ORIGIN),
"Geolocation is not allowed for self");
ok(!ifr.featurePolicy.allowsFeature("geolocation", "http://foo.bar"), "Geolocation is not allowed for any random URL");
allowed = ifr.featurePolicy.getAllowlistForFeature("geolocation");
is(allowed.length, 0, "No allowlist for geolocation");
ok(ifr.featurePolicy.allowsFeature("microphone"), "Microphone is enabled for self");
ok(ifr.featurePolicy.allowsFeature("microphone", CROSS_ORIGIN), "Microphone is enabled for self");
ok(!ifr.featurePolicy.allowsFeature("microphone", "http://foo.bar"), "Microphone is disabled for foo.bar");
ok(!ifr.featurePolicy.allowsFeature("microphone", "http://example.com"), "Microphone is disabled for example.com");
allowed = ifr.featurePolicy.getAllowlistForFeature("microphone");
is(allowed.length, 1, "Only 1 entry in allowlist for microphone");
is(allowed[0], CROSS_ORIGIN, "allowlist is self");
ok(!ifr.featurePolicy.allowsFeature("vr"), "Vibrate is disabled for self");
ok(!ifr.featurePolicy.allowsFeature("vr", CROSS_ORIGIN), "Vibrate is disabled for self");
ok(!ifr.featurePolicy.allowsFeature("vr", "http://foo.bar"), "Vibrate is disabled for foo.bar");
allowed = ifr.featurePolicy.getAllowlistForFeature("vr");
is(allowed.length, 0, "No allowlist for vr");
ok(ifr.featurePolicy.allowedFeatures().includes("camera"), "Camera is allowed");
ok(!ifr.featurePolicy.allowedFeatures().includes("geolocation"), "Geolocation is not allowed");
// microphone is enabled for this origin
ok(ifr.featurePolicy.allowedFeatures().includes("microphone"), "microphone is allowed");
// vr is disabled everywhere.
ok(!ifr.featurePolicy.allowedFeatures().includes("vr"), "VR is not allowed");
next();
}
function test_cross_iframe_with_allow() {
info("Checking cross HTMLIFrameElement.featurePolicy with allow");
let ifr = document.getElementById("cross_ifr");
ok("featurePolicy" in ifr, "HTMLIFrameElement.featurePolicy exists");
ifr.setAttribute("allow", "geolocation; camera 'none'");
ok(!ifr.featurePolicy.allowsFeature("foobar"), "Random feature");
ok(!ifr.featurePolicy.allowsFeature("foobar", "http://www.something.net"), "Random feature");
ok(!ifr.featurePolicy.allowsFeature("camera"), "Camera is not allowed");
let allowed = ifr.featurePolicy.getAllowlistForFeature("camera");
is(allowed.length, 0, "Camera has an empty allowlist");
ok(ifr.featurePolicy.allowsFeature("geolocation"), "Geolocation is allowed for self");
ok(ifr.featurePolicy.allowsFeature("geolocation", CROSS_ORIGIN), "Geolocation is allowed for self");
ok(!ifr.featurePolicy.allowsFeature("geolocation", "http://foo.bar"), "Geolocation is not allowed for any random URL");
allowed = ifr.featurePolicy.getAllowlistForFeature("geolocation");
is(allowed.length, 1, "Only 1 entry in allowlist for geolocation");
is(allowed[0], CROSS_ORIGIN, "allowlist is '*'");
ok(ifr.featurePolicy.allowsFeature("microphone"), "Microphone is enabled for self");
ok(ifr.featurePolicy.allowsFeature("microphone", CROSS_ORIGIN), "Microphone is enabled for self");
ok(!ifr.featurePolicy.allowsFeature("microphone", "http://foo.bar"), "Microphone is disabled for foo.bar");
ok(!ifr.featurePolicy.allowsFeature("microphone", "http://example.com"), "Microphone is disabled for example.com");
allowed = ifr.featurePolicy.getAllowlistForFeature("microphone");
is(allowed.length, 1, "Only 1 entry in allowlist for microphone");
is(allowed[0], CROSS_ORIGIN, "allowlist is self");
ok(!ifr.featurePolicy.allowsFeature("vr"), "Vibrate is disabled for self");
ok(!ifr.featurePolicy.allowsFeature("vr", CROSS_ORIGIN), "Vibrate is disabled for self");
ok(!ifr.featurePolicy.allowsFeature("vr", "http://foo.bar"), "Vibrate is disabled for foo.bar");
allowed = ifr.featurePolicy.getAllowlistForFeature("vr");
is(allowed.length, 0, "No allowlist for vr");
ok(ifr.featurePolicy.allowedFeatures().includes("geolocation"), "Geolocation is allowed only for self");
// microphone is enabled for this origin
ok(ifr.featurePolicy.allowedFeatures().includes("microphone"), "microphone is allowed");
next();
}
function test_cross_iframe_contentDocument_no_allow() {
info("Checking cross iframe document.featurePolicy no allow");
let ifr = document.createElement("iframe");
ifr.setAttribute("src", "http://example.org/tests/dom/security/featurePolicy/test/mochitest/empty.html");
ifr.onload = async function() {
await SpecialPowers.spawn(ifr, [], () => {
/* import-globals-from ../../../../../testing/modules/Assert.jsm */
Assert.ok("featurePolicy" in this.content.document, "We have this.content.document.featurePolicy");
Assert.ok(!this.content.document.featurePolicy.allowsFeature("foobar"), "Random feature");
Assert.ok(!this.content.document.featurePolicy.allowsFeature("foobar", "http://www.something.net"), "Random feature");
Assert.ok(this.content.document.featurePolicy.allowsFeature("camera"), "Camera is allowed for self");
Assert.ok(this.content.document.featurePolicy.allowsFeature("camera", "http://example.org"), "Camera is allowed for self");
Assert.ok(!this.content.document.featurePolicy.allowsFeature("camera", "http://foo.bar"), "Camera is not allowed for a random URL");
let allowed = this.content.document.featurePolicy.getAllowlistForFeature("camera");
Assert.equal(allowed.length, 1, "Only 1 entry in allowlist for camera");
Assert.equal(allowed[0], "http://example.org", "allowlist is 'self'");
Assert.ok(!this.content.document.featurePolicy.allowsFeature("geolocation"), "Geolocation is not allowed for self");
Assert.ok(!this.content.document.featurePolicy.allowsFeature("geolocation", "http://example.org"),
"Geolocation is not allowed for self");
Assert.ok(!this.content.document.featurePolicy.allowsFeature("geolocation", "http://foo.bar"), "Geolocation is not allowed for any random URL");
allowed = this.content.document.featurePolicy.getAllowlistForFeature("geolocation");
Assert.equal(allowed.length, 0, "No allowlist for geolocation");
Assert.ok(this.content.document.featurePolicy.allowsFeature("microphone"), "Microphone is enabled for self");
Assert.ok(this.content.document.featurePolicy.allowsFeature("microphone", "http://example.org"), "Microphone is enabled for self");
Assert.ok(!this.content.document.featurePolicy.allowsFeature("microphone", "http://foo.bar"), "Microphone is disabled for foo.bar");
Assert.ok(!this.content.document.featurePolicy.allowsFeature("microphone", "http://example.com"), "Microphone is disabled for example.com");
allowed = this.content.document.featurePolicy.getAllowlistForFeature("microphone");
Assert.equal(allowed.length, 1, "Only 1 entry in allowlist for microphone");
Assert.equal(allowed[0], "http://example.org", "allowlist is self");
Assert.ok(!this.content.document.featurePolicy.allowsFeature("vr"), "Vibrate is disabled for self");
Assert.ok(!this.content.document.featurePolicy.allowsFeature("vr", "http://example.org"), "Vibrate is disabled for self");
Assert.ok(!this.content.document.featurePolicy.allowsFeature("vr", "http://foo.bar"), "Vibrate is disabled for foo.bar");
allowed = this.content.document.featurePolicy.getAllowlistForFeature("vr");
Assert.equal(allowed.length, 0, "No allowlist for vr");
Assert.ok(this.content.document.featurePolicy.allowedFeatures().includes("camera"), "Camera is allowed");
Assert.ok(!this.content.document.featurePolicy.allowedFeatures().includes("geolocation"), "Geolocation is not allowed");
// microphone is enabled for this origin
Assert.ok(this.content.document.featurePolicy.allowedFeatures().includes("microphone"), "microphone is allowed");
// vr is disabled everywhere.
Assert.ok(!this.content.document.featurePolicy.allowedFeatures().includes("vr"), "VR is not allowed");
});
next();
};
document.body.appendChild(ifr);
}
function test_cross_iframe_contentDocument_allow() {
info("Checking cross iframe document.featurePolicy with allow");
let ifr = document.createElement("iframe");
ifr.setAttribute("src", "http://example.org/tests/dom/security/featurePolicy/test/mochitest/empty.html");
ifr.setAttribute("allow", "geolocation; camera 'none'");
ifr.onload = async function() {
await SpecialPowers.spawn(ifr, [], () => {
Assert.ok("featurePolicy" in this.content.document, "We have this.content.document.featurePolicy");
Assert.ok(!this.content.document.featurePolicy.allowsFeature("foobar"), "Random feature");
Assert.ok(!this.content.document.featurePolicy.allowsFeature("foobar", "http://www.something.net"), "Random feature");
Assert.ok(!this.content.document.featurePolicy.allowsFeature("camera"), "Camera is not allowed");
let allowed = this.content.document.featurePolicy.getAllowlistForFeature("camera");
Assert.equal(allowed.length, 0, "Camera has an empty allowlist");
Assert.ok(this.content.document.featurePolicy.allowsFeature("geolocation"), "Geolocation is allowed for self");
Assert.ok(this.content.document.featurePolicy.allowsFeature("geolocation", "http://example.org"), "Geolocation is allowed for self");
Assert.ok(!this.content.document.featurePolicy.allowsFeature("geolocation", "http://foo.bar"), "Geolocation is not allowed for any random URL");
allowed = this.content.document.featurePolicy.getAllowlistForFeature("geolocation");
Assert.equal(allowed.length, 1, "Only 1 entry in allowlist for geolocation");
Assert.equal(allowed[0], "http://example.org", "allowlist is '*'");
Assert.ok(this.content.document.featurePolicy.allowsFeature("microphone"), "Microphone is enabled for self");
Assert.ok(this.content.document.featurePolicy.allowsFeature("microphone", "http://example.org"), "Microphone is enabled for self");
Assert.ok(!this.content.document.featurePolicy.allowsFeature("microphone", "http://foo.bar"), "Microphone is disabled for foo.bar");
Assert.ok(!this.content.document.featurePolicy.allowsFeature("microphone", "http://example.com"), "Microphone is disabled for example.com");
allowed = this.content.document.featurePolicy.getAllowlistForFeature("microphone");
Assert.equal(allowed.length, 1, "Only 1 entry in allowlist for microphone");
Assert.equal(allowed[0], "http://example.org", "allowlist is self");
Assert.ok(!this.content.document.featurePolicy.allowsFeature("vr"), "Vibrate is disabled for self");
Assert.ok(!this.content.document.featurePolicy.allowsFeature("vr", "http://example.org"), "Vibrate is disabled for self");
Assert.ok(!this.content.document.featurePolicy.allowsFeature("vr", "http://foo.bar"), "Vibrate is disabled for foo.bar");
allowed = this.content.document.featurePolicy.getAllowlistForFeature("vr");
Assert.equal(allowed.length, 0, "No allowlist for vr");
Assert.ok(this.content.document.featurePolicy.allowedFeatures().includes("geolocation"), "Geolocation is allowed only for self");
// microphone is enabled for this origin
Assert.ok(this.content.document.featurePolicy.allowedFeatures().includes("microphone"), "microphone is allowed");
});
next();
};
document.body.appendChild(ifr);
}
var tests = [
test_document,
test_iframe_without_allow,
test_iframe_with_allow,
test_iframe_contentDocument,
test_cross_iframe_without_allow,
test_cross_iframe_with_allow,
test_cross_iframe_contentDocument_no_allow,
test_cross_iframe_contentDocument_allow
];
function next() {

Просмотреть файл

@ -21,6 +21,7 @@ prefs =
[test_clearWatch_invalid.html]
[test_crossorigin_iframe.html]
support-files = crossorigin_iframe.html
skip-if = fission #Bug 1580074
[test_errorcheck.html]
[test_geolocation_is_undefined_when_pref_is_off.html]
support-files = test_geolocation_is_undefined_when_pref_is_off_iframe.html

Просмотреть файл

@ -1390,20 +1390,19 @@ bool GfxInfoBase::BuildFeatureStateLog(JSContext* aCx,
void GfxInfoBase::DescribeFeatures(JSContext* aCx, JS::Handle<JSObject*> aObj) {
JS::Rooted<JSObject*> obj(aCx);
gfx::FeatureStatus gpuProcess =
gfxConfig::GetValue(gfx::Feature::GPU_PROCESS);
gfx::FeatureStatus gpuProcess = gfxConfig::GetValue(Feature::GPU_PROCESS);
InitFeatureObject(aCx, aObj, "gpuProcess", gpuProcess, &obj);
gfx::FeatureStatus wrQualified =
gfxConfig::GetValue(gfx::Feature::WEBRENDER_QUALIFIED);
gfxConfig::GetValue(Feature::WEBRENDER_QUALIFIED);
InitFeatureObject(aCx, aObj, "wrQualified", wrQualified, &obj);
gfx::FeatureStatus webrender = gfxConfig::GetValue(gfx::Feature::WEBRENDER);
gfx::FeatureStatus webrender = gfxConfig::GetValue(Feature::WEBRENDER);
InitFeatureObject(aCx, aObj, "webrender", webrender, &obj);
// Only include AL if the platform attempted to use it.
gfx::FeatureStatus advancedLayers =
gfxConfig::GetValue(gfx::Feature::ADVANCED_LAYERS);
gfxConfig::GetValue(Feature::ADVANCED_LAYERS);
if (advancedLayers != FeatureStatus::Unused) {
InitFeatureObject(aCx, aObj, "advancedLayers", advancedLayers, &obj);
@ -1489,14 +1488,14 @@ GfxInfoBase::GetContentUsesTiling(bool* aUsesTiling) {
NS_IMETHODIMP
GfxInfoBase::GetOffMainThreadPaintEnabled(bool* aOffMainThreadPaintEnabled) {
*aOffMainThreadPaintEnabled = gfxConfig::IsEnabled(gfx::Feature::OMTP);
*aOffMainThreadPaintEnabled = gfxConfig::IsEnabled(Feature::OMTP);
return NS_OK;
}
NS_IMETHODIMP
GfxInfoBase::GetOffMainThreadPaintWorkerCount(
int32_t* aOffMainThreadPaintWorkerCount) {
if (gfxConfig::IsEnabled(gfx::Feature::OMTP)) {
if (gfxConfig::IsEnabled(Feature::OMTP)) {
*aOffMainThreadPaintWorkerCount =
layers::PaintThread::CalculatePaintWorkerCount();
} else {
@ -1561,13 +1560,13 @@ GfxInfoBase::ControlGPUProcessForXPCShell(bool aEnable, bool* _retval) {
GPUProcessManager* gpm = GPUProcessManager::Get();
if (aEnable) {
if (!gfxConfig::IsEnabled(gfx::Feature::GPU_PROCESS)) {
gfxConfig::UserForceEnable(gfx::Feature::GPU_PROCESS, "xpcshell-test");
if (!gfxConfig::IsEnabled(Feature::GPU_PROCESS)) {
gfxConfig::UserForceEnable(Feature::GPU_PROCESS, "xpcshell-test");
}
gpm->LaunchGPUProcess();
gpm->EnsureGPUReady();
} else {
gfxConfig::UserDisable(gfx::Feature::GPU_PROCESS, "xpcshell-test");
gfxConfig::UserDisable(Feature::GPU_PROCESS, "xpcshell-test");
gpm->KillProcess();
}

Просмотреть файл

@ -41,7 +41,6 @@
#include "mozilla/StartupTimeline.h"
#include "mozilla/StaticPrefs_fission.h"
#include "mozilla/intl/LocaleService.h"
#include "mozilla/dom/BrowsingContext.h"
#include "nsEmbedCID.h"
#include "nsIWebBrowser.h"