168168#include " nsSVGFeatures.h"
169169#include " MediaDecoder.h"
170170#include " DecoderTraits.h"
171+ #include " mozilla/dom/DocumentFragment.h"
171172
172173#include " nsWrapperCacheInlines.h"
173174#include " nsViewportInfo.h"
@@ -1588,6 +1589,15 @@ nsContentUtils::CanCallerAccess(nsIPrincipal* aSubjectPrincipal,
15881589// static
15891590bool
15901591nsContentUtils::CanCallerAccess (nsIDOMNode *aNode)
1592+ {
1593+ nsCOMPtr<nsINode> node = do_QueryInterface (aNode);
1594+ NS_ENSURE_TRUE (node, false );
1595+ return CanCallerAccess (node);
1596+ }
1597+
1598+ // static
1599+ bool
1600+ nsContentUtils::CanCallerAccess (nsINode* aNode)
15911601{
15921602 // XXXbz why not check the IsCapabilityEnabled thing up front, and not bother
15931603 // with the system principal games? But really, there should be a simpler
@@ -1602,10 +1612,7 @@ nsContentUtils::CanCallerAccess(nsIDOMNode *aNode)
16021612 return true ;
16031613 }
16041614
1605- nsCOMPtr<nsINode> node = do_QueryInterface (aNode);
1606- NS_ENSURE_TRUE (node, false );
1607-
1608- return CanCallerAccess (subjectPrincipal, node->NodePrincipal ());
1615+ return CanCallerAccess (subjectPrincipal, aNode->NodePrincipal ());
16091616}
16101617
16111618// static
@@ -4045,8 +4052,22 @@ nsContentUtils::CreateContextualFragment(nsINode* aContextNode,
40454052 bool aPreventScriptExecution,
40464053 nsIDOMDocumentFragment** aReturn)
40474054{
4048- *aReturn = nullptr ;
4049- NS_ENSURE_ARG (aContextNode);
4055+ ErrorResult rv;
4056+ *aReturn = CreateContextualFragment (aContextNode, aFragment,
4057+ aPreventScriptExecution, rv).get ();
4058+ return rv.ErrorCode ();
4059+ }
4060+
4061+ already_AddRefed<DocumentFragment>
4062+ nsContentUtils::CreateContextualFragment (nsINode* aContextNode,
4063+ const nsAString& aFragment,
4064+ bool aPreventScriptExecution,
4065+ ErrorResult& aRv)
4066+ {
4067+ if (!aContextNode) {
4068+ aRv.Throw (NS_ERROR_INVALID_ARG );
4069+ return nullptr ;
4070+ }
40504071
40514072 // If we don't have a document here, we can't get the right security context
40524073 // for compiling event handlers... so just bail out.
@@ -4058,8 +4079,8 @@ nsContentUtils::CreateContextualFragment(nsINode* aContextNode,
40584079#endif
40594080
40604081 if (isHTML) {
4061- nsCOMPtr<nsIDOMDocumentFragment > frag;
4062- NS_NewDocumentFragment (getter_AddRefs(frag), document->NodeInfoManager());
4082+ nsRefPtr<DocumentFragment > frag =
4083+ NS_NewDocumentFragment (document->NodeInfoManager (), aRv );
40634084
40644085 nsCOMPtr<nsIContent> contextAsContent = do_QueryInterface(aContextNode);
40654086 if (contextAsContent && !contextAsContent->IsElement ()) {
@@ -4070,28 +4091,23 @@ nsContentUtils::CreateContextualFragment(nsINode* aContextNode,
40704091 }
40714092 }
40724093
4073- nsresult rv;
4074- nsCOMPtr<nsIContent> fragment = do_QueryInterface (frag);
40754094 if (contextAsContent && !contextAsContent->IsHTML (nsGkAtoms::html)) {
4076- rv = ParseFragmentHTML (aFragment,
4077- fragment,
4078- contextAsContent->Tag (),
4079- contextAsContent->GetNameSpaceID (),
4080- (document->GetCompatibilityMode () ==
4095+ aRv = ParseFragmentHTML (aFragment, frag,
4096+ contextAsContent->Tag (),
4097+ contextAsContent->GetNameSpaceID (),
4098+ (document->GetCompatibilityMode () ==
40814099 eCompatibility_NavQuirks),
4082- aPreventScriptExecution);
4100+ aPreventScriptExecution);
40834101 } else {
4084- rv = ParseFragmentHTML (aFragment,
4085- fragment,
4086- nsGkAtoms::body,
4087- kNameSpaceID_XHTML ,
4088- (document->GetCompatibilityMode () ==
4102+ aRv = ParseFragmentHTML (aFragment, frag,
4103+ nsGkAtoms::body,
4104+ kNameSpaceID_XHTML ,
4105+ (document->GetCompatibilityMode () ==
40894106 eCompatibility_NavQuirks),
4090- aPreventScriptExecution);
4107+ aPreventScriptExecution);
40914108 }
40924109
4093- frag.forget (aReturn);
4094- return rv;
4110+ return frag.forget ();
40954111 }
40964112
40974113 nsAutoTArray<nsString, 32 > tagStack;
@@ -4103,7 +4119,10 @@ nsContentUtils::CreateContextualFragment(nsINode* aContextNode,
41034119
41044120 while (content && content->IsElement ()) {
41054121 nsString& tagName = *tagStack.AppendElement ();
4106- NS_ENSURE_TRUE (&tagName, NS_ERROR_OUT_OF_MEMORY );
4122+ if (!&tagName) {
4123+ aRv.Throw (NS_ERROR_OUT_OF_MEMORY );
4124+ return nullptr ;
4125+ }
41074126
41084127 tagName = content->NodeInfo ()->QualifiedName ();
41094128
@@ -4149,11 +4168,10 @@ nsContentUtils::CreateContextualFragment(nsINode* aContextNode,
41494168 content = content->GetParent ();
41504169 }
41514170
4152- return ParseFragmentXML (aFragment,
4153- document,
4154- tagStack,
4155- aPreventScriptExecution,
4156- aReturn);
4171+ nsCOMPtr<nsIDOMDocumentFragment> frag;
4172+ aRv = ParseFragmentXML (aFragment, document, tagStack,
4173+ aPreventScriptExecution, getter_AddRefs (frag));
4174+ return static_cast <DocumentFragment*>(frag.forget ().get ());
41574175}
41584176
41594177/* static */
0 commit comments