diff --git a/content/base/src/nsImageLoadingContent.h b/content/base/src/nsImageLoadingContent.h index 31323400435..dc1e80d4e7b 100644 --- a/content/base/src/nsImageLoadingContent.h +++ b/content/base/src/nsImageLoadingContent.h @@ -151,6 +151,9 @@ protected: */ void DestroyImageLoadingContent(); + void ClearBrokenState() { mBroken = PR_FALSE; } + + PRBool LoadingEnabled() { return mLoadingEnabled; } private: /** * Struct used to manage the image observers. diff --git a/content/base/src/nsStyleLinkElement.h b/content/base/src/nsStyleLinkElement.h index d8a0603d115..aef7640b990 100644 --- a/content/base/src/nsStyleLinkElement.h +++ b/content/base/src/nsStyleLinkElement.h @@ -82,6 +82,7 @@ public: static void ParseLinkTypes(const nsAString& aTypes, nsTArray& aResult); + void UpdateStyleSheetInternal() { UpdateStyleSheetInternal(nsnull); } protected: /** * @param aOldDocument should be non-null only if we're updating because we diff --git a/content/html/content/src/nsHTMLImageElement.cpp b/content/html/content/src/nsHTMLImageElement.cpp index b85af372228..eac60c08a79 100644 --- a/content/html/content/src/nsHTMLImageElement.cpp +++ b/content/html/content/src/nsHTMLImageElement.cpp @@ -148,6 +148,7 @@ public: virtual PRInt32 IntrinsicState() const; virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const; + void MaybeLoadImage(); protected: nsPoint GetXY(); nsSize GetWidthHeight(); @@ -550,18 +551,30 @@ nsHTMLImageElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent, aCompileEventHandlers); NS_ENSURE_SUCCESS(rv, rv); - // Our base URI may have changed; claim that our URI changed, and the - // nsImageLoadingContent will decide whether a new image load is warranted. - nsAutoString uri; - if (GetAttr(kNameSpaceID_None, nsGkAtoms::src, uri)) { - // Note: no need to notify here; since we're just now being bound - // we don't have any frames or anything yet. - LoadImage(uri, PR_FALSE, PR_FALSE); + if (HasAttr(kNameSpaceID_None, nsGkAtoms::src)) { + ClearBrokenState(); + nsContentUtils::AddScriptRunner( + new nsRunnableMethod(this, + &nsHTMLImageElement::MaybeLoadImage)); } return rv; } +void +nsHTMLImageElement::MaybeLoadImage() +{ + // Our base URI may have changed; claim that our URI changed, and the + // nsImageLoadingContent will decide whether a new image load is warranted. + // Note, check LoadingEnabled() after LoadImage call. + nsAutoString uri; + if (GetAttr(kNameSpaceID_None, nsGkAtoms::src, uri) && + (NS_FAILED(LoadImage(uri, PR_FALSE, PR_TRUE)) || + !LoadingEnabled())) { + CancelImageRequests(PR_TRUE); + } +} + PRInt32 nsHTMLImageElement::IntrinsicState() const { diff --git a/content/html/content/src/nsHTMLInputElement.cpp b/content/html/content/src/nsHTMLInputElement.cpp index bcfa8e08b36..3de9f4b6448 100644 --- a/content/html/content/src/nsHTMLInputElement.cpp +++ b/content/html/content/src/nsHTMLInputElement.cpp @@ -316,6 +316,7 @@ public: NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_NO_UNLINK(nsHTMLInputElement, nsGenericHTMLFormElement) + void MaybeLoadImage(); protected: // Helper method nsresult SetValueInternal(const nsAString& aValue, @@ -1966,6 +1967,19 @@ nsHTMLInputElement::PostHandleEvent(nsEventChainPostVisitor& aVisitor) return rv; } +void +nsHTMLInputElement::MaybeLoadImage() +{ + // Our base URI may have changed; claim that our URI changed, and the + // nsImageLoadingContent will decide whether a new image load is warranted. + nsAutoString uri; + if (mType == NS_FORM_INPUT_IMAGE && + GetAttr(kNameSpaceID_None, nsGkAtoms::src, uri) && + (NS_FAILED(LoadImage(uri, PR_FALSE, PR_TRUE)) || + !LoadingEnabled())) { + CancelImageRequests(PR_TRUE); + } +} nsresult nsHTMLInputElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent, @@ -1980,11 +1994,11 @@ nsHTMLInputElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent, if (mType == NS_FORM_INPUT_IMAGE) { // Our base URI may have changed; claim that our URI changed, and the // nsImageLoadingContent will decide whether a new image load is warranted. - nsAutoString uri; - if (GetAttr(kNameSpaceID_None, nsGkAtoms::src, uri)) { - // Note: no need to notify here; since we're just now being bound - // we don't have any frames or anything yet. - LoadImage(uri, PR_FALSE, PR_FALSE); + if (HasAttr(kNameSpaceID_None, nsGkAtoms::src)) { + ClearBrokenState(); + nsContentUtils::AddScriptRunner( + new nsRunnableMethod(this, + &nsHTMLInputElement::MaybeLoadImage)); } } diff --git a/content/html/content/src/nsHTMLLinkElement.cpp b/content/html/content/src/nsHTMLLinkElement.cpp index 26689a9060d..03c7d91ae8a 100644 --- a/content/html/content/src/nsHTMLLinkElement.cpp +++ b/content/html/content/src/nsHTMLLinkElement.cpp @@ -209,7 +209,9 @@ nsHTMLLinkElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent, aCompileEventHandlers); NS_ENSURE_SUCCESS(rv, rv); - UpdateStyleSheetInternal(nsnull); + nsContentUtils::AddScriptRunner( + new nsRunnableMethod(this, + &nsHTMLLinkElement::UpdateStyleSheetInternal)); CreateAndDispatchEvent(aDocument, NS_LITERAL_STRING("DOMLinkAdded")); diff --git a/content/html/content/src/nsHTMLObjectElement.cpp b/content/html/content/src/nsHTMLObjectElement.cpp index 77c145f666c..216d367ec4f 100644 --- a/content/html/content/src/nsHTMLObjectElement.cpp +++ b/content/html/content/src/nsHTMLObjectElement.cpp @@ -124,6 +124,8 @@ public: virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const; + void StartObjectLoad() { StartObjectLoad(PR_TRUE); } + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_NO_UNLINK(nsHTMLObjectElement, nsGenericHTMLFormElement) @@ -224,9 +226,9 @@ nsHTMLObjectElement::BindToTree(nsIDocument *aDocument, // If we already have all the children, start the load. if (mIsDoneAddingChildren) { - // Don't need to notify: We have no frames yet, since we weren't in a - // document - StartObjectLoad(PR_FALSE); + nsContentUtils::AddScriptRunner( + new nsRunnableMethod(this, + &nsHTMLObjectElement::StartObjectLoad)); } return NS_OK; diff --git a/content/html/content/src/nsHTMLSharedObjectElement.cpp b/content/html/content/src/nsHTMLSharedObjectElement.cpp index aa715e4919d..3ecc832df15 100644 --- a/content/html/content/src/nsHTMLSharedObjectElement.cpp +++ b/content/html/content/src/nsHTMLSharedObjectElement.cpp @@ -44,6 +44,7 @@ #include "nsIDOMDocument.h" #include "nsIDOMHTMLAppletElement.h" #include "nsIDOMHTMLEmbedElement.h" +#include "nsThreadUtils.h" #ifdef MOZ_SVG #include "nsIDOMGetSVGDocument.h" #include "nsIDOMSVGDocument.h" @@ -129,6 +130,8 @@ public: virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const; + void StartObjectLoad() { StartObjectLoad(PR_TRUE); } + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_NO_UNLINK(nsHTMLSharedObjectElement, nsGenericHTMLElement) @@ -252,9 +255,9 @@ nsHTMLSharedObjectElement::BindToTree(nsIDocument *aDocument, // If we already have all the children, start the load. if (mIsDoneAddingChildren) { - // Don't need to notify: We have no frames yet, since we weren't in a - // document - StartObjectLoad(PR_FALSE); + nsContentUtils::AddScriptRunner( + new nsRunnableMethod(this, + &nsHTMLSharedObjectElement::StartObjectLoad)); } return NS_OK; diff --git a/content/html/content/src/nsHTMLStyleElement.cpp b/content/html/content/src/nsHTMLStyleElement.cpp index 8c624506962..39047d08975 100644 --- a/content/html/content/src/nsHTMLStyleElement.cpp +++ b/content/html/content/src/nsHTMLStyleElement.cpp @@ -241,7 +241,9 @@ nsHTMLStyleElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent, aCompileEventHandlers); NS_ENSURE_SUCCESS(rv, rv); - UpdateStyleSheetInternal(nsnull); + nsContentUtils::AddScriptRunner( + new nsRunnableMethod(this, + &nsHTMLStyleElement::UpdateStyleSheetInternal)); return rv; } diff --git a/content/svg/content/src/nsSVGFilters.cpp b/content/svg/content/src/nsSVGFilters.cpp index ae0486e6959..e7b2f3b104a 100644 --- a/content/svg/content/src/nsSVGFilters.cpp +++ b/content/svg/content/src/nsSVGFilters.cpp @@ -5197,6 +5197,7 @@ public: NS_IMETHOD OnStartContainer(imgIRequest *aRequest, imgIContainer *aContainer); + void MaybeLoadSVGImage(); private: // Invalidate users of the filter containing this element. void Invalidate(); @@ -5301,6 +5302,16 @@ nsSVGFEImageElement::AfterSetAttr(PRInt32 aNamespaceID, nsIAtom* aName, aValue, aNotify); } +void +nsSVGFEImageElement::MaybeLoadSVGImage() +{ + if (HasAttr(kNameSpaceID_XLink, nsGkAtoms::href) && + (NS_FAILED(LoadSVGImage(PR_FALSE, PR_TRUE)) || + !LoadingEnabled())) { + CancelImageRequests(PR_TRUE); + } +} + nsresult nsSVGFEImageElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent, nsIContent* aBindingParent, @@ -5312,11 +5323,10 @@ nsSVGFEImageElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent, NS_ENSURE_SUCCESS(rv, rv); if (HasAttr(kNameSpaceID_XLink, nsGkAtoms::href)) { - // Our base URI may have changed; claim that our URI changed, and the - // nsImageLoadingContent will decide whether a new image load is warranted. - // Note: no need to notify here; since we're just now being bound - // we don't have any frames or anything yet. - LoadSVGImage(PR_FALSE, PR_FALSE); + ClearBrokenState(); + nsContentUtils::AddScriptRunner( + new nsRunnableMethod(this, + &nsSVGFEImageElement::MaybeLoadSVGImage)); } return rv; diff --git a/content/svg/content/src/nsSVGImageElement.cpp b/content/svg/content/src/nsSVGImageElement.cpp index 8bc342afa92..7990ab8e5c1 100644 --- a/content/svg/content/src/nsSVGImageElement.cpp +++ b/content/svg/content/src/nsSVGImageElement.cpp @@ -181,6 +181,16 @@ nsSVGImageElement::AfterSetAttr(PRInt32 aNamespaceID, nsIAtom* aName, aValue, aNotify); } +void +nsSVGImageElement::MaybeLoadSVGImage() +{ + if (HasAttr(kNameSpaceID_XLink, nsGkAtoms::href) && + (NS_FAILED(LoadSVGImage(PR_FALSE, PR_TRUE)) || + !LoadingEnabled())) { + CancelImageRequests(PR_TRUE); + } +} + nsresult nsSVGImageElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent, nsIContent* aBindingParent, @@ -192,11 +202,10 @@ nsSVGImageElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent, NS_ENSURE_SUCCESS(rv, rv); if (HasAttr(kNameSpaceID_XLink, nsGkAtoms::href)) { - // Our base URI may have changed; claim that our URI changed, and the - // nsImageLoadingContent will decide whether a new image load is warranted. - // Note: no need to notify here; since we're just now being bound - // we don't have any frames or anything yet. - LoadSVGImage(PR_FALSE, PR_FALSE); + ClearBrokenState(); + nsContentUtils::AddScriptRunner( + new nsRunnableMethod(this, + &nsSVGImageElement::MaybeLoadSVGImage)); } return rv; diff --git a/content/svg/content/src/nsSVGImageElement.h b/content/svg/content/src/nsSVGImageElement.h index 8d56ffb5d87..6b527d47748 100644 --- a/content/svg/content/src/nsSVGImageElement.h +++ b/content/svg/content/src/nsSVGImageElement.h @@ -90,6 +90,7 @@ public: virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const; + void MaybeLoadSVGImage(); protected: nsresult LoadSVGImage(PRBool aForce, PRBool aNotify); diff --git a/content/svg/content/src/nsSVGStyleElement.cpp b/content/svg/content/src/nsSVGStyleElement.cpp index f870b72b4e4..1d5516b2793 100644 --- a/content/svg/content/src/nsSVGStyleElement.cpp +++ b/content/svg/content/src/nsSVGStyleElement.cpp @@ -161,7 +161,9 @@ nsSVGStyleElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent, aCompileEventHandlers); NS_ENSURE_SUCCESS(rv, rv); - UpdateStyleSheetInternal(nsnull); + nsContentUtils::AddScriptRunner( + new nsRunnableMethod(this, + &nsSVGStyleElement::UpdateStyleSheetInternal)); return rv; } diff --git a/content/xml/content/src/nsXMLStylesheetPI.cpp b/content/xml/content/src/nsXMLStylesheetPI.cpp index c475b8877b0..50a63aa6c69 100644 --- a/content/xml/content/src/nsXMLStylesheetPI.cpp +++ b/content/xml/content/src/nsXMLStylesheetPI.cpp @@ -47,6 +47,7 @@ #include "nsUnicharUtils.h" #include "nsParserUtils.h" #include "nsGkAtoms.h" +#include "nsThreadUtils.h" class nsXMLStylesheetPI : public nsXMLProcessingInstruction, public nsStyleLinkElement @@ -123,7 +124,9 @@ nsXMLStylesheetPI::BindToTree(nsIDocument* aDocument, nsIContent* aParent, aCompileEventHandlers); NS_ENSURE_SUCCESS(rv, rv); - UpdateStyleSheetInternal(nsnull); + nsContentUtils::AddScriptRunner( + new nsRunnableMethod(this, + &nsXMLStylesheetPI::UpdateStyleSheetInternal)); return rv; } diff --git a/layout/reftests/image/invalid-url-image-1-ref.html b/layout/reftests/image/invalid-url-image-1-ref.html new file mode 100644 index 00000000000..6a008811bad --- /dev/null +++ b/layout/reftests/image/invalid-url-image-1-ref.html @@ -0,0 +1,6 @@ + + + + + + diff --git a/layout/reftests/image/invalid-url-image-1.html b/layout/reftests/image/invalid-url-image-1.html new file mode 100644 index 00000000000..e9f99b03954 --- /dev/null +++ b/layout/reftests/image/invalid-url-image-1.html @@ -0,0 +1,6 @@ + + + + + + diff --git a/layout/reftests/image/reftest.list b/layout/reftests/image/reftest.list index ae5111e5d7d..0e0ff47bb53 100644 --- a/layout/reftests/image/reftest.list +++ b/layout/reftests/image/reftest.list @@ -1,2 +1,3 @@ == background-image-zoom-1.html background-image-zoom-1-ref.html == image-zoom-1.html image-zoom-1-ref.html +== invalid-url-image-1.html invalid-url-image-1-ref.html