Bug 1270648 part 2 - Merge nsContentUtils::ParseSandboxAttributeToFlags into HTMLIFrameElement::GetSandboxFlags. r?smaug
nsContentUtils::ParseSandboxAttributeToFlags is not used anywhere else,
and given that sandbox flags would also be affected by allowfullscreen
attribute, this function alone could be misused.
MozReview-Commit-ID: EzlGQ7iY8WG
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -1341,42 +1341,16 @@ nsContentUtils::GetParserService()
if (NS_FAILED(rv)) {
sParserService = nullptr;
}
}
return sParserService;
}
-/**
- * A helper function that parses a sandbox attribute (of an <iframe> or
- * a CSP directive) and converts it to the set of flags used internally.
- *
- * @param sandboxAttr the sandbox attribute
- * @return the set of flags (0 if sandboxAttr is null)
- */
-uint32_t
-nsContentUtils::ParseSandboxAttributeToFlags(const nsAttrValue* sandboxAttr)
-{
- // No sandbox attribute, no sandbox flags.
- if (!sandboxAttr) { return 0; }
-
- // Start off by setting all the restriction flags.
- uint32_t out = SANDBOX_ALL_FLAGS;
-
-// Macro for updating the flag according to the keywords
-#define SANDBOX_KEYWORD(string, atom, flags) \
- if (sandboxAttr->Contains(nsGkAtoms::atom, eIgnoreCase)) { out &= ~(flags); }
-
-#include "IframeSandboxKeywordList.h"
-
- return out;
-#undef SANDBOX_KEYWORD
-}
-
nsIBidiKeyboard*
nsContentUtils::GetBidiKeyboard()
{
if (!sBidiKeyboard) {
nsresult rv = CallGetService("@mozilla.org/widget/bidikeyboard;1", &sBidiKeyboard);
if (NS_FAILED(rv)) {
sBidiKeyboard = nullptr;
}
--- a/dom/base/nsContentUtils.h
+++ b/dom/base/nsContentUtils.h
@@ -903,25 +903,16 @@ public:
/**
* Get the localized string named |aKey| in properties file |aFile|.
*/
static nsresult GetLocalizedString(PropertiesFile aFile,
const char* aKey,
nsXPIDLString& aResult);
/**
- * A helper function that parses a sandbox attribute (of an <iframe> or
- * a CSP directive) and converts it to the set of flags used internally.
- *
- * @param sandboxAttr the sandbox attribute
- * @return the set of flags (0 if sandboxAttr is null)
- */
- static uint32_t ParseSandboxAttributeToFlags(const nsAttrValue* sandboxAttr);
-
- /**
* Helper function that generates a UUID.
*/
static nsresult GenerateUUIDInPlace(nsID& aUUID);
static bool PrefetchEnabled(nsIDocShell* aDocShell);
/**
* Fill (with the parameters given) the localized string named |aKey| in
--- a/dom/html/HTMLIFrameElement.cpp
+++ b/dom/html/HTMLIFrameElement.cpp
@@ -242,17 +242,32 @@ HTMLIFrameElement::UnsetAttr(int32_t aNa
return NS_OK;
}
uint32_t
HTMLIFrameElement::GetSandboxFlags()
{
const nsAttrValue* sandboxAttr = GetParsedAttr(nsGkAtoms::sandbox);
- return nsContentUtils::ParseSandboxAttributeToFlags(sandboxAttr);
+ // No sandbox attribute, no sandbox flags.
+ if (!sandboxAttr) {
+ return 0;
+ }
+
+ // Start off by setting all the restriction flags.
+ uint32_t out = SANDBOX_ALL_FLAGS;
+
+// Macro for updating the flag according to the keywords
+#define SANDBOX_KEYWORD(string, atom, flags) \
+ if (sandboxAttr->Contains(nsGkAtoms::atom, eIgnoreCase)) { out &= ~(flags); }
+
+#include "IframeSandboxKeywordList.h"
+
+ return out;
+#undef SANDBOX_KEYWORD
}
JSObject*
HTMLIFrameElement::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
{
return HTMLIFrameElementBinding::Wrap(aCx, this, aGivenProto);
}