Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 : /* This Source Code Form is subject to the terms of the Mozilla Public
4 : * License, v. 2.0. If a copy of the MPL was not distributed with this
5 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : #include "mozilla/dom/HTMLIFrameElement.h"
8 : #include "mozilla/dom/HTMLIFrameElementBinding.h"
9 : #include "mozilla/GenericSpecifiedValuesInlines.h"
10 : #include "nsMappedAttributes.h"
11 : #include "nsAttrValueInlines.h"
12 : #include "nsError.h"
13 : #include "nsStyleConsts.h"
14 : #include "nsContentUtils.h"
15 : #include "nsSandboxFlags.h"
16 :
17 0 : NS_IMPL_NS_NEW_HTML_ELEMENT_CHECK_PARSER(IFrame)
18 :
19 : namespace mozilla {
20 : namespace dom {
21 :
22 : // static
23 : const DOMTokenListSupportedToken HTMLIFrameElement::sSupportedSandboxTokens[] = {
24 : #define SANDBOX_KEYWORD(string, atom, flags) string,
25 : #include "IframeSandboxKeywordList.h"
26 : #undef SANDBOX_KEYWORD
27 : nullptr
28 : };
29 :
30 0 : HTMLIFrameElement::HTMLIFrameElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo,
31 0 : FromParser aFromParser)
32 0 : : nsGenericHTMLFrameElement(aNodeInfo, aFromParser)
33 : {
34 0 : }
35 :
36 0 : HTMLIFrameElement::~HTMLIFrameElement()
37 : {
38 0 : }
39 :
40 0 : NS_IMPL_ISUPPORTS_INHERITED(HTMLIFrameElement, nsGenericHTMLFrameElement,
41 : nsIDOMHTMLIFrameElement)
42 :
43 0 : NS_IMPL_ELEMENT_CLONE(HTMLIFrameElement)
44 :
45 0 : NS_IMPL_STRING_ATTR(HTMLIFrameElement, Align, align)
46 0 : NS_IMPL_STRING_ATTR(HTMLIFrameElement, FrameBorder, frameborder)
47 0 : NS_IMPL_STRING_ATTR(HTMLIFrameElement, Height, height)
48 0 : NS_IMPL_URI_ATTR(HTMLIFrameElement, LongDesc, longdesc)
49 0 : NS_IMPL_STRING_ATTR(HTMLIFrameElement, MarginHeight, marginheight)
50 0 : NS_IMPL_STRING_ATTR(HTMLIFrameElement, MarginWidth, marginwidth)
51 0 : NS_IMPL_STRING_ATTR(HTMLIFrameElement, Name, name)
52 0 : NS_IMPL_STRING_ATTR(HTMLIFrameElement, Scrolling, scrolling)
53 0 : NS_IMPL_URI_ATTR(HTMLIFrameElement, Src, src)
54 0 : NS_IMPL_STRING_ATTR(HTMLIFrameElement, Width, width)
55 0 : NS_IMPL_BOOL_ATTR(HTMLIFrameElement, AllowFullscreen, allowfullscreen)
56 0 : NS_IMPL_STRING_ATTR(HTMLIFrameElement, Srcdoc, srcdoc)
57 :
58 : NS_IMETHODIMP
59 0 : HTMLIFrameElement::GetContentDocument(nsIDOMDocument** aContentDocument)
60 : {
61 0 : return nsGenericHTMLFrameElement::GetContentDocument(aContentDocument);
62 : }
63 :
64 : bool
65 0 : HTMLIFrameElement::ParseAttribute(int32_t aNamespaceID,
66 : nsIAtom* aAttribute,
67 : const nsAString& aValue,
68 : nsAttrValue& aResult)
69 : {
70 0 : if (aNamespaceID == kNameSpaceID_None) {
71 0 : if (aAttribute == nsGkAtoms::marginwidth) {
72 0 : return aResult.ParseSpecialIntValue(aValue);
73 : }
74 0 : if (aAttribute == nsGkAtoms::marginheight) {
75 0 : return aResult.ParseSpecialIntValue(aValue);
76 : }
77 0 : if (aAttribute == nsGkAtoms::width) {
78 0 : return aResult.ParseSpecialIntValue(aValue);
79 : }
80 0 : if (aAttribute == nsGkAtoms::height) {
81 0 : return aResult.ParseSpecialIntValue(aValue);
82 : }
83 0 : if (aAttribute == nsGkAtoms::frameborder) {
84 0 : return ParseFrameborderValue(aValue, aResult);
85 : }
86 0 : if (aAttribute == nsGkAtoms::scrolling) {
87 0 : return ParseScrollingValue(aValue, aResult);
88 : }
89 0 : if (aAttribute == nsGkAtoms::align) {
90 0 : return ParseAlignValue(aValue, aResult);
91 : }
92 0 : if (aAttribute == nsGkAtoms::sandbox) {
93 0 : aResult.ParseAtomArray(aValue);
94 0 : return true;
95 : }
96 : }
97 :
98 0 : return nsGenericHTMLFrameElement::ParseAttribute(aNamespaceID, aAttribute,
99 0 : aValue, aResult);
100 : }
101 :
102 : void
103 0 : HTMLIFrameElement::MapAttributesIntoRule(const nsMappedAttributes* aAttributes,
104 : GenericSpecifiedValues* aData)
105 : {
106 0 : if (aData->ShouldComputeStyleStruct(NS_STYLE_INHERIT_BIT(Border))) {
107 : // frameborder: 0 | 1 (| NO | YES in quirks mode)
108 : // If frameborder is 0 or No, set border to 0
109 : // else leave it as the value set in html.css
110 0 : const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::frameborder);
111 0 : if (value && value->Type() == nsAttrValue::eEnum) {
112 0 : int32_t frameborder = value->GetEnumValue();
113 0 : if (NS_STYLE_FRAME_0 == frameborder ||
114 0 : NS_STYLE_FRAME_NO == frameborder ||
115 : NS_STYLE_FRAME_OFF == frameborder) {
116 0 : aData->SetPixelValueIfUnset(eCSSProperty_border_top_width, 0.0f);
117 0 : aData->SetPixelValueIfUnset(eCSSProperty_border_right_width, 0.0f);
118 0 : aData->SetPixelValueIfUnset(eCSSProperty_border_bottom_width, 0.0f);
119 0 : aData->SetPixelValueIfUnset(eCSSProperty_border_left_width, 0.0f);
120 : }
121 : }
122 : }
123 :
124 0 : nsGenericHTMLElement::MapImageSizeAttributesInto(aAttributes, aData);
125 0 : nsGenericHTMLElement::MapImageAlignAttributeInto(aAttributes, aData);
126 0 : nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aData);
127 0 : }
128 :
129 : NS_IMETHODIMP_(bool)
130 0 : HTMLIFrameElement::IsAttributeMapped(const nsIAtom* aAttribute) const
131 : {
132 : static const MappedAttributeEntry attributes[] = {
133 : { &nsGkAtoms::width },
134 : { &nsGkAtoms::height },
135 : { &nsGkAtoms::frameborder },
136 : { nullptr },
137 : };
138 :
139 : static const MappedAttributeEntry* const map[] = {
140 : attributes,
141 : sImageAlignAttributeMap,
142 : sCommonAttributeMap,
143 : };
144 :
145 0 : return FindAttributeDependence(aAttribute, map);
146 : }
147 :
148 :
149 :
150 : nsMapRuleToAttributesFunc
151 0 : HTMLIFrameElement::GetAttributeMappingFunction() const
152 : {
153 0 : return &MapAttributesIntoRule;
154 : }
155 :
156 : nsresult
157 0 : HTMLIFrameElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
158 : const nsAttrValue* aValue,
159 : const nsAttrValue* aOldValue, bool aNotify)
160 : {
161 0 : AfterMaybeChangeAttr(aNameSpaceID, aName, aNotify);
162 :
163 0 : if (aNameSpaceID == kNameSpaceID_None) {
164 0 : if (aName == nsGkAtoms::sandbox) {
165 0 : if (mFrameLoader) {
166 : // If we have an nsFrameLoader, apply the new sandbox flags.
167 : // Since this is called after the setter, the sandbox flags have
168 : // alreay been updated.
169 0 : mFrameLoader->ApplySandboxFlags(GetSandboxFlags());
170 : }
171 : }
172 : }
173 0 : return nsGenericHTMLFrameElement::AfterSetAttr(aNameSpaceID, aName, aValue,
174 0 : aOldValue, aNotify);
175 : }
176 :
177 : nsresult
178 0 : HTMLIFrameElement::OnAttrSetButNotChanged(int32_t aNamespaceID, nsIAtom* aName,
179 : const nsAttrValueOrString& aValue,
180 : bool aNotify)
181 : {
182 0 : AfterMaybeChangeAttr(aNamespaceID, aName, aNotify);
183 :
184 0 : return nsGenericHTMLFrameElement::OnAttrSetButNotChanged(aNamespaceID, aName,
185 0 : aValue, aNotify);
186 : }
187 :
188 : void
189 0 : HTMLIFrameElement::AfterMaybeChangeAttr(int32_t aNamespaceID,
190 : nsIAtom* aName,
191 : bool aNotify)
192 : {
193 0 : if (aNamespaceID == kNameSpaceID_None) {
194 0 : if (aName == nsGkAtoms::srcdoc) {
195 : // Don't propagate errors from LoadSrc. The attribute was successfully
196 : // set/unset, that's what we should reflect.
197 0 : LoadSrc();
198 : }
199 : }
200 0 : }
201 :
202 : uint32_t
203 0 : HTMLIFrameElement::GetSandboxFlags()
204 : {
205 0 : const nsAttrValue* sandboxAttr = GetParsedAttr(nsGkAtoms::sandbox);
206 : // No sandbox attribute, no sandbox flags.
207 0 : if (!sandboxAttr) {
208 0 : return SANDBOXED_NONE;
209 : }
210 0 : return nsContentUtils::ParseSandboxAttributeToFlags(sandboxAttr);
211 : }
212 :
213 : JSObject*
214 0 : HTMLIFrameElement::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
215 : {
216 0 : return HTMLIFrameElementBinding::Wrap(aCx, this, aGivenProto);
217 : }
218 :
219 : } // namespace dom
220 : } // namespace mozilla
|