/* -*- Mode: C++; tab-width: 8; 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/. */
HTMLIFrameElement::HTMLIFrameElement(
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
FromParser aFromParser)
: 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);
}
void HTMLIFrameElement::MapAttributesIntoRule(
MappedDeclarationsBuilder& aBuilder) { // frameborder: 0 | 1 (| NO | YES in quirks mode) // If frameborder is 0 or No, set border to 0 // else leave it as the value set in html.css const nsAttrValue* value = aBuilder.GetAttr(nsGkAtoms::frameborder); if (value && value->Type() == nsAttrValue::eEnum) { auto frameborder = static_cast<FrameBorderProperty>(value->GetEnumValue()); if (FrameBorderProperty::No == frameborder ||
FrameBorderProperty::Zero == frameborder) {
aBuilder.SetPixelValueIfUnset(eCSSProperty_border_top_width, 0.0f);
aBuilder.SetPixelValueIfUnset(eCSSProperty_border_right_width, 0.0f);
aBuilder.SetPixelValueIfUnset(eCSSProperty_border_bottom_width, 0.0f);
aBuilder.SetPixelValueIfUnset(eCSSProperty_border_left_width, 0.0f);
}
}
if (aNameSpaceID == kNameSpaceID_None) { if (aName == nsGkAtoms::loading) { if (aValue && Loading(aValue->GetEnumValue()) == Loading::Lazy) {
SetLazyLoading();
} elseif (aOldValue &&
Loading(aOldValue->GetEnumValue()) == Loading::Lazy) {
StopLazyLoading();
}
}
// If lazy loading and src set, set lazy loading again as we are doing a new // load (lazy loading is unset after a load is complete). if ((aName == nsGkAtoms::src || aName == nsGkAtoms::srcdoc) &&
LoadingState() == Loading::Lazy) {
SetLazyLoading();
}
if (aName == nsGkAtoms::sandbox) { if (mFrameLoader) { // If we have an nsFrameLoader, apply the new sandbox flags. // Since this is called after the setter, the sandbox flags have // alreay been updated.
mFrameLoader->ApplySandboxFlags(GetSandboxFlags());
}
}
void HTMLIFrameElement::AfterMaybeChangeAttr(int32_t aNamespaceID,
nsAtom* aName, bool aNotify) { if (aNamespaceID == kNameSpaceID_None) { if (aName == nsGkAtoms::srcdoc) { // Don't propagate errors from LoadSrc. The attribute was successfully // set/unset, that's what we should reflect.
LoadSrc();
}
}
}
uint32_t HTMLIFrameElement::GetSandboxFlags() const { const nsAttrValue* sandboxAttr = GetParsedAttr(nsGkAtoms::sandbox); // No sandbox attribute, no sandbox flags. if (!sandboxAttr) { return SANDBOXED_NONE;
} return nsContentUtils::ParseSandboxAttributeToFlags(sandboxAttr);
}
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;
}
if (HasAttr(nsGkAtoms::srcdoc)) {
principal = NodePrincipal(); return principal.forget();
}
nsCOMPtr<nsIURI> nodeURI; if (GetURIAttr(nsGkAtoms::src, nullptr, getter_AddRefs(nodeURI)) && nodeURI) {
principal = BasePrincipal::CreateContentPrincipal(
nodeURI, BasePrincipal::Cast(NodePrincipal())->OriginAttributesRef());
}
if (!principal) {
principal = NodePrincipal();
}
return principal.forget();
}
void HTMLIFrameElement::RefreshFeaturePolicy(bool aParseAllowAttribute) { if (aParseAllowAttribute) {
mFeaturePolicy->ResetDeclaredPolicy();
// The origin can change if 'src' and 'srcdoc' attributes change.
nsCOMPtr<nsIPrincipal> origin = GetFeaturePolicyDefaultOrigin();
MOZ_ASSERT(origin);
mFeaturePolicy->SetDefaultOrigin(origin);
if (!allow.IsEmpty()) { // Set or reset the FeaturePolicy directives.
mFeaturePolicy->SetDeclaredPolicy(OwnerDoc(), allow, NodePrincipal(),
origin);
}
}
if (AllowFullscreen()) {
mFeaturePolicy->MaybeSetAllowedPolicy(u"fullscreen"_ns);
}
void HTMLIFrameElement::UpdateLazyLoadState() { // Store current base URI and referrer policy in the lazy load state.
mLazyLoadState.mBaseURI = GetBaseURI();
mLazyLoadState.mReferrerPolicy = GetReferrerPolicyAsEnum();
}
nsresult HTMLIFrameElement::BindToTree(BindContext& aContext,
nsINode& aParent) { // Update lazy load state on bind to tree again if lazy loading, as the // loading attribute could be set before others. if (mLazyLoading) {
UpdateLazyLoadState();
}
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.