Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/html/HTMLIFrameElement.cpp
Line
Count
Source (jump to first uncovered line)
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/MappedDeclarations.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
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
HTMLIFrameElement::HTMLIFrameElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
31
                                     FromParser aFromParser)
32
  : nsGenericHTMLFrameElement(std::move(aNodeInfo), aFromParser)
33
0
{
34
0
}
35
36
HTMLIFrameElement::~HTMLIFrameElement()
37
0
{
38
0
}
39
40
NS_IMPL_ELEMENT_CLONE(HTMLIFrameElement)
41
42
bool
43
HTMLIFrameElement::ParseAttribute(int32_t aNamespaceID,
44
                                  nsAtom* aAttribute,
45
                                  const nsAString& aValue,
46
                                  nsIPrincipal* aMaybeScriptedPrincipal,
47
                                  nsAttrValue& aResult)
48
0
{
49
0
  if (aNamespaceID == kNameSpaceID_None) {
50
0
    if (aAttribute == nsGkAtoms::marginwidth) {
51
0
      return aResult.ParseSpecialIntValue(aValue);
52
0
    }
53
0
    if (aAttribute == nsGkAtoms::marginheight) {
54
0
      return aResult.ParseSpecialIntValue(aValue);
55
0
    }
56
0
    if (aAttribute == nsGkAtoms::width) {
57
0
      return aResult.ParseSpecialIntValue(aValue);
58
0
    }
59
0
    if (aAttribute == nsGkAtoms::height) {
60
0
      return aResult.ParseSpecialIntValue(aValue);
61
0
    }
62
0
    if (aAttribute == nsGkAtoms::frameborder) {
63
0
      return ParseFrameborderValue(aValue, aResult);
64
0
    }
65
0
    if (aAttribute == nsGkAtoms::scrolling) {
66
0
      return ParseScrollingValue(aValue, aResult);
67
0
    }
68
0
    if (aAttribute == nsGkAtoms::align) {
69
0
      return ParseAlignValue(aValue, aResult);
70
0
    }
71
0
    if (aAttribute == nsGkAtoms::sandbox) {
72
0
      aResult.ParseAtomArray(aValue);
73
0
      return true;
74
0
    }
75
0
  }
76
0
77
0
  return nsGenericHTMLFrameElement::ParseAttribute(aNamespaceID, aAttribute,
78
0
                                                   aValue,
79
0
                                                   aMaybeScriptedPrincipal,
80
0
                                                   aResult);
81
0
}
82
83
void
84
HTMLIFrameElement::MapAttributesIntoRule(const nsMappedAttributes* aAttributes,
85
                                         MappedDeclarations& aDecls)
86
0
{
87
0
  // frameborder: 0 | 1 (| NO | YES in quirks mode)
88
0
  // If frameborder is 0 or No, set border to 0
89
0
  // else leave it as the value set in html.css
90
0
  const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::frameborder);
91
0
  if (value && value->Type() == nsAttrValue::eEnum) {
92
0
    int32_t frameborder = value->GetEnumValue();
93
0
    if (NS_STYLE_FRAME_0 == frameborder ||
94
0
        NS_STYLE_FRAME_NO == frameborder ||
95
0
        NS_STYLE_FRAME_OFF == frameborder) {
96
0
      aDecls.SetPixelValueIfUnset(eCSSProperty_border_top_width, 0.0f);
97
0
      aDecls.SetPixelValueIfUnset(eCSSProperty_border_right_width, 0.0f);
98
0
      aDecls.SetPixelValueIfUnset(eCSSProperty_border_bottom_width, 0.0f);
99
0
      aDecls.SetPixelValueIfUnset(eCSSProperty_border_left_width, 0.0f);
100
0
    }
101
0
  }
102
0
103
0
  nsGenericHTMLElement::MapImageSizeAttributesInto(aAttributes, aDecls);
104
0
  nsGenericHTMLElement::MapImageAlignAttributeInto(aAttributes, aDecls);
105
0
  nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aDecls);
106
0
}
107
108
NS_IMETHODIMP_(bool)
109
HTMLIFrameElement::IsAttributeMapped(const nsAtom* aAttribute) const
110
0
{
111
0
  static const MappedAttributeEntry attributes[] = {
112
0
    { &nsGkAtoms::width },
113
0
    { &nsGkAtoms::height },
114
0
    { &nsGkAtoms::frameborder },
115
0
    { nullptr },
116
0
  };
117
0
118
0
  static const MappedAttributeEntry* const map[] = {
119
0
    attributes,
120
0
    sImageAlignAttributeMap,
121
0
    sCommonAttributeMap,
122
0
  };
123
0
124
0
  return FindAttributeDependence(aAttribute, map);
125
0
}
126
127
128
129
nsMapRuleToAttributesFunc
130
HTMLIFrameElement::GetAttributeMappingFunction() const
131
0
{
132
0
  return &MapAttributesIntoRule;
133
0
}
134
135
nsresult
136
HTMLIFrameElement::AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
137
                                const nsAttrValue* aValue,
138
                                const nsAttrValue* aOldValue,
139
                                nsIPrincipal* aMaybeScriptedPrincipal,
140
                                bool aNotify)
141
0
{
142
0
  AfterMaybeChangeAttr(aNameSpaceID, aName, aNotify);
143
0
144
0
  if (aNameSpaceID == kNameSpaceID_None) {
145
0
    if (aName == nsGkAtoms::sandbox) {
146
0
      if (mFrameLoader) {
147
0
        // If we have an nsFrameLoader, apply the new sandbox flags.
148
0
        // Since this is called after the setter, the sandbox flags have
149
0
        // alreay been updated.
150
0
        mFrameLoader->ApplySandboxFlags(GetSandboxFlags());
151
0
      }
152
0
    }
153
0
  }
154
0
  return nsGenericHTMLFrameElement::AfterSetAttr(aNameSpaceID, aName,
155
0
                                                 aValue, aOldValue,
156
0
                                                 aMaybeScriptedPrincipal,
157
0
                                                 aNotify);
158
0
}
159
160
nsresult
161
HTMLIFrameElement::OnAttrSetButNotChanged(int32_t aNamespaceID, nsAtom* aName,
162
                                          const nsAttrValueOrString& aValue,
163
                                          bool aNotify)
164
0
{
165
0
  AfterMaybeChangeAttr(aNamespaceID, aName, aNotify);
166
0
167
0
  return nsGenericHTMLFrameElement::OnAttrSetButNotChanged(aNamespaceID, aName,
168
0
                                                           aValue, aNotify);
169
0
}
170
171
void
172
HTMLIFrameElement::AfterMaybeChangeAttr(int32_t aNamespaceID,
173
                                        nsAtom* aName,
174
                                        bool aNotify)
175
0
{
176
0
  if (aNamespaceID == kNameSpaceID_None) {
177
0
    if (aName == nsGkAtoms::srcdoc) {
178
0
      // Don't propagate errors from LoadSrc. The attribute was successfully
179
0
      // set/unset, that's what we should reflect.
180
0
      LoadSrc();
181
0
    }
182
0
  }
183
0
}
184
185
uint32_t
186
HTMLIFrameElement::GetSandboxFlags()
187
0
{
188
0
  const nsAttrValue* sandboxAttr = GetParsedAttr(nsGkAtoms::sandbox);
189
0
  // No sandbox attribute, no sandbox flags.
190
0
  if (!sandboxAttr) {
191
0
    return SANDBOXED_NONE;
192
0
  }
193
0
  return nsContentUtils::ParseSandboxAttributeToFlags(sandboxAttr);
194
0
}
195
196
JSObject*
197
HTMLIFrameElement::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
198
0
{
199
0
  return HTMLIFrameElement_Binding::Wrap(aCx, this, aGivenProto);
200
0
}
201
202
} // namespace dom
203
} // namespace mozilla