mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-17 22:32:51 +00:00
Bug 802895 - Implement srcdoc attribute for iframe r=bz
This commit is contained in:
parent
74ed91b164
commit
97d9e25ced
@ -312,21 +312,28 @@ nsFrameLoader::LoadFrame()
|
||||
NS_ENSURE_TRUE(mOwnerContent, NS_ERROR_NOT_INITIALIZED);
|
||||
|
||||
nsAutoString src;
|
||||
GetURL(src);
|
||||
|
||||
src.Trim(" \t\n\r");
|
||||
bool isSrcdoc = mOwnerContent->IsHTML(nsGkAtoms::iframe) &&
|
||||
mOwnerContent->HasAttr(kNameSpaceID_None, nsGkAtoms::srcdoc);
|
||||
if (isSrcdoc) {
|
||||
src.AssignLiteral("about:srcdoc");
|
||||
}
|
||||
else {
|
||||
GetURL(src);
|
||||
|
||||
if (src.IsEmpty()) {
|
||||
// If the frame is a XUL element and has the attribute 'nodefaultsrc=true'
|
||||
// then we will not use 'about:blank' as fallback but return early without
|
||||
// starting a load if no 'src' attribute is given (or it's empty).
|
||||
if (mOwnerContent->IsXUL() &&
|
||||
mOwnerContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::nodefaultsrc,
|
||||
nsGkAtoms::_true, eCaseMatters)) {
|
||||
return NS_OK;
|
||||
src.Trim(" \t\n\r");
|
||||
|
||||
if (src.IsEmpty()) {
|
||||
// If the frame is a XUL element and has the attribute 'nodefaultsrc=true'
|
||||
// then we will not use 'about:blank' as fallback but return early without
|
||||
// starting a load if no 'src' attribute is given (or it's empty).
|
||||
if (mOwnerContent->IsXUL() &&
|
||||
mOwnerContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::nodefaultsrc,
|
||||
nsGkAtoms::_true, eCaseMatters)) {
|
||||
return NS_OK;
|
||||
}
|
||||
src.AssignLiteral("about:blank");
|
||||
}
|
||||
|
||||
src.AssignLiteral("about:blank");
|
||||
}
|
||||
|
||||
nsIDocument* doc = mOwnerContent->OwnerDoc();
|
||||
@ -472,8 +479,23 @@ nsFrameLoader::ReallyStartLoadingInternal()
|
||||
loadInfo->SetOwner(mOwnerContent->NodePrincipal());
|
||||
|
||||
nsCOMPtr<nsIURI> referrer;
|
||||
rv = mOwnerContent->NodePrincipal()->GetURI(getter_AddRefs(referrer));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsAutoString srcdoc;
|
||||
bool isSrcdoc = mOwnerContent->IsHTML(nsGkAtoms::iframe) &&
|
||||
mOwnerContent->GetAttr(kNameSpaceID_None, nsGkAtoms::srcdoc,
|
||||
srcdoc);
|
||||
|
||||
if (isSrcdoc) {
|
||||
nsAutoString referrerStr;
|
||||
mOwnerContent->OwnerDoc()->GetReferrer(referrerStr);
|
||||
rv = NS_NewURI(getter_AddRefs(referrer), referrerStr);
|
||||
|
||||
loadInfo->SetSrcdocData(srcdoc);
|
||||
}
|
||||
else {
|
||||
rv = mOwnerContent->NodePrincipal()->GetURI(getter_AddRefs(referrer));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
loadInfo->SetReferrer(referrer);
|
||||
|
||||
|
@ -993,6 +993,7 @@ GK_ATOM(splitmenu, "splitmenu")
|
||||
GK_ATOM(splitter, "splitter")
|
||||
GK_ATOM(spring, "spring")
|
||||
GK_ATOM(src, "src")
|
||||
GK_ATOM(srcdoc, "srcdoc")
|
||||
GK_ATOM(srclang, "srclang")
|
||||
GK_ATOM(stack, "stack")
|
||||
GK_ATOM(standalone, "standalone")
|
||||
|
@ -55,6 +55,7 @@ NS_IMPL_URI_ATTR(HTMLIFrameElement, Src, src)
|
||||
NS_IMPL_STRING_ATTR(HTMLIFrameElement, Width, width)
|
||||
NS_IMPL_BOOL_ATTR(HTMLIFrameElement, AllowFullscreen, allowfullscreen)
|
||||
NS_IMPL_STRING_ATTR(HTMLIFrameElement, Sandbox, sandbox)
|
||||
NS_IMPL_STRING_ATTR(HTMLIFrameElement, Srcdoc, srcdoc)
|
||||
|
||||
void
|
||||
HTMLIFrameElement::GetItemValueText(nsAString& aValue)
|
||||
@ -198,6 +199,24 @@ HTMLIFrameElement::GetAttributeMappingFunction() const
|
||||
return &MapAttributesIntoRule;
|
||||
}
|
||||
|
||||
nsresult
|
||||
HTMLIFrameElement::SetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
||||
nsIAtom* aPrefix, const nsAString& aValue,
|
||||
bool aNotify)
|
||||
{
|
||||
nsresult rv = nsGenericHTMLFrameElement::SetAttr(aNameSpaceID, aName,
|
||||
aPrefix, aValue, aNotify);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (aNameSpaceID == kNameSpaceID_None && aName == nsGkAtoms::srcdoc) {
|
||||
// Don't propagate error here. The attribute was successfully set, that's
|
||||
// what we should reflect.
|
||||
LoadSrc();
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
HTMLIFrameElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
||||
const nsAttrValue* aValue,
|
||||
@ -227,6 +246,23 @@ HTMLIFrameElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
||||
aNotify);
|
||||
}
|
||||
|
||||
nsresult
|
||||
HTMLIFrameElement::UnsetAttr(int32_t aNameSpaceID, nsIAtom* aAttribute,
|
||||
bool aNotify)
|
||||
{
|
||||
// Invoke on the superclass.
|
||||
nsresult rv = nsGenericHTMLFrameElement::UnsetAttr(aNameSpaceID, aAttribute, aNotify);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (aNameSpaceID == kNameSpaceID_None &&
|
||||
aAttribute == nsGkAtoms::srcdoc) {
|
||||
// Fall back to the src attribute, if any
|
||||
LoadSrc();
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
HTMLIFrameElement::GetSandboxFlags()
|
||||
{
|
||||
|
@ -49,9 +49,19 @@ public:
|
||||
virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const MOZ_OVERRIDE;
|
||||
virtual nsIDOMNode* AsDOMNode() MOZ_OVERRIDE { return this; }
|
||||
|
||||
nsresult SetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
||||
const nsAString& aValue, bool aNotify)
|
||||
{
|
||||
return SetAttr(aNameSpaceID, aName, nullptr, aValue, aNotify);
|
||||
}
|
||||
virtual nsresult SetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
||||
nsIAtom* aPrefix, const nsAString& aValue,
|
||||
bool aNotify) MOZ_OVERRIDE;
|
||||
virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
||||
const nsAttrValue* aValue,
|
||||
bool aNotify) MOZ_OVERRIDE;
|
||||
virtual nsresult UnsetAttr(int32_t aNameSpaceID, nsIAtom* aAttribute,
|
||||
bool aNotify) MOZ_OVERRIDE;
|
||||
|
||||
uint32_t GetSandboxFlags();
|
||||
|
||||
@ -61,6 +71,14 @@ public:
|
||||
{
|
||||
SetHTMLAttr(nsGkAtoms::src, aSrc, aError);
|
||||
}
|
||||
void GetSrcdoc(DOMString& aSrcdoc)
|
||||
{
|
||||
GetHTMLAttr(nsGkAtoms::srcdoc, aSrcdoc);
|
||||
}
|
||||
void SetSrcdoc(const nsAString& aSrcdoc, ErrorResult& aError)
|
||||
{
|
||||
SetHTMLAttr(nsGkAtoms::srcdoc, aSrcdoc, aError);
|
||||
}
|
||||
void GetName(DOMString& aName)
|
||||
{
|
||||
GetHTMLAttr(nsGkAtoms::name, aName);
|
||||
|
@ -229,7 +229,9 @@ nsGenericHTMLFrameElement::SetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
||||
aValue, aNotify);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (aNameSpaceID == kNameSpaceID_None && aName == nsGkAtoms::src) {
|
||||
if (aNameSpaceID == kNameSpaceID_None && aName == nsGkAtoms::src &&
|
||||
(Tag() != nsGkAtoms::iframe ||
|
||||
!HasAttr(kNameSpaceID_None,nsGkAtoms::srcdoc))) {
|
||||
// Don't propagate error here. The attribute was successfully set, that's
|
||||
// what we should reflect.
|
||||
LoadSrc();
|
||||
|
@ -16,7 +16,7 @@
|
||||
* http://www.whatwg.org/specs/web-apps/current-work/
|
||||
*/
|
||||
|
||||
[scriptable, uuid(21ffbe98-51f5-499e-8d6f-612ae798c1e1)]
|
||||
[scriptable, uuid(60D9BCF1-3B0C-4704-AE8C-5B6AC0180B2E)]
|
||||
interface nsIDOMHTMLIFrameElement : nsIDOMHTMLElement
|
||||
{
|
||||
attribute DOMString align;
|
||||
@ -28,6 +28,7 @@ interface nsIDOMHTMLIFrameElement : nsIDOMHTMLElement
|
||||
attribute DOMString name;
|
||||
attribute DOMString scrolling;
|
||||
attribute DOMString src;
|
||||
attribute DOMString srcdoc;
|
||||
attribute DOMString width;
|
||||
// Introduced in DOM Level 2:
|
||||
readonly attribute nsIDOMDocument contentDocument;
|
||||
|
@ -14,7 +14,8 @@
|
||||
interface HTMLIFrameElement : HTMLElement {
|
||||
[SetterThrows, Pure]
|
||||
attribute DOMString src;
|
||||
// attribute DOMString srcdoc;
|
||||
[SetterThrows, Pure]
|
||||
attribute DOMString srcdoc;
|
||||
[SetterThrows, Pure]
|
||||
attribute DOMString name;
|
||||
// [PutForwards=value] readonly attribute DOMSettableTokenList sandbox;
|
||||
|
Loading…
x
Reference in New Issue
Block a user