mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 05:41:12 +00:00
Bug 857102 part 5 - Make NS_NewDocumentFragment etc. infallible; r=bz
This commit is contained in:
parent
337756f144
commit
329a95c725
@ -1951,7 +1951,7 @@ public:
|
||||
const nsAString& aQualifiedName,
|
||||
mozilla::ErrorResult& rv);
|
||||
already_AddRefed<mozilla::dom::DocumentFragment>
|
||||
CreateDocumentFragment(mozilla::ErrorResult& rv) const;
|
||||
CreateDocumentFragment() const;
|
||||
already_AddRefed<nsTextNode> CreateTextNode(const nsAString& aData) const;
|
||||
already_AddRefed<mozilla::dom::Comment>
|
||||
CreateComment(const nsAString& aData) const;
|
||||
@ -2493,14 +2493,6 @@ NS_NewImageDocument(nsIDocument** aInstancePtrResult);
|
||||
nsresult
|
||||
NS_NewVideoDocument(nsIDocument** aInstancePtrResult);
|
||||
|
||||
already_AddRefed<mozilla::dom::DocumentFragment>
|
||||
NS_NewDocumentFragment(nsNodeInfoManager* aNodeInfoManager,
|
||||
mozilla::ErrorResult& aRv);
|
||||
|
||||
nsresult
|
||||
NS_NewDocumentFragment(nsIDOMDocumentFragment** aInstancePtrResult,
|
||||
nsNodeInfoManager *aNodeInfoManager);
|
||||
|
||||
// Note: it's the caller's responsibility to create or get aPrincipal as needed
|
||||
// -- this method will not attempt to get a principal based on aDocumentURI.
|
||||
// Also, both aDocumentURI and aBaseURI must not be null.
|
||||
|
@ -18,50 +18,9 @@
|
||||
#include "nsContentUtils.h"
|
||||
#include "mozilla/dom/DocumentFragmentBinding.h"
|
||||
|
||||
nsresult
|
||||
NS_NewDocumentFragment(nsIDOMDocumentFragment** aInstancePtrResult,
|
||||
nsNodeInfoManager *aNodeInfoManager)
|
||||
{
|
||||
mozilla::ErrorResult rv;
|
||||
*aInstancePtrResult = NS_NewDocumentFragment(aNodeInfoManager, rv).get();
|
||||
return rv.ErrorCode();
|
||||
}
|
||||
|
||||
already_AddRefed<mozilla::dom::DocumentFragment>
|
||||
NS_NewDocumentFragment(nsNodeInfoManager* aNodeInfoManager,
|
||||
mozilla::ErrorResult& aRv)
|
||||
{
|
||||
using namespace mozilla::dom;
|
||||
|
||||
if (!aNodeInfoManager) {
|
||||
aRv.Throw(NS_ERROR_INVALID_ARG);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsINodeInfo> nodeInfo =
|
||||
aNodeInfoManager->GetNodeInfo(nsGkAtoms::documentFragmentNodeName,
|
||||
nullptr, kNameSpaceID_None,
|
||||
nsIDOMNode::DOCUMENT_FRAGMENT_NODE);
|
||||
|
||||
nsRefPtr<DocumentFragment> it = new DocumentFragment(nodeInfo.forget());
|
||||
return it.forget();
|
||||
}
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
DocumentFragment::DocumentFragment(already_AddRefed<nsINodeInfo> aNodeInfo)
|
||||
: FragmentOrElement(aNodeInfo), mHost(nullptr)
|
||||
{
|
||||
NS_ABORT_IF_FALSE(mNodeInfo->NodeType() ==
|
||||
nsIDOMNode::DOCUMENT_FRAGMENT_NODE &&
|
||||
mNodeInfo->Equals(nsGkAtoms::documentFragmentNodeName,
|
||||
kNameSpaceID_None),
|
||||
"Bad NodeType in aNodeInfo");
|
||||
|
||||
SetIsDOMBinding();
|
||||
}
|
||||
|
||||
JSObject*
|
||||
DocumentFragment::WrapNode(JSContext *aCx, JSObject *aScope)
|
||||
{
|
||||
|
@ -37,7 +37,35 @@ public:
|
||||
// interface nsIDOMDocumentFragment
|
||||
// NS_DECL_NSIDOCUMENTFRAGMENT Empty
|
||||
|
||||
DocumentFragment(already_AddRefed<nsINodeInfo> aNodeInfo);
|
||||
private:
|
||||
void Init()
|
||||
{
|
||||
NS_ABORT_IF_FALSE(mNodeInfo->NodeType() ==
|
||||
nsIDOMNode::DOCUMENT_FRAGMENT_NODE &&
|
||||
mNodeInfo->Equals(nsGkAtoms::documentFragmentNodeName,
|
||||
kNameSpaceID_None),
|
||||
"Bad NodeType in aNodeInfo");
|
||||
|
||||
SetIsDOMBinding();
|
||||
}
|
||||
|
||||
public:
|
||||
DocumentFragment(already_AddRefed<nsINodeInfo> aNodeInfo)
|
||||
: FragmentOrElement(aNodeInfo), mHost(nullptr)
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
DocumentFragment(nsNodeInfoManager* aNodeInfoManager)
|
||||
: FragmentOrElement(aNodeInfoManager->GetNodeInfo(
|
||||
nsGkAtoms::documentFragmentNodeName,
|
||||
nullptr, kNameSpaceID_None,
|
||||
nsIDOMNode::DOCUMENT_FRAGMENT_NODE)),
|
||||
mHost(nullptr)
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
virtual ~DocumentFragment()
|
||||
{
|
||||
}
|
||||
|
@ -129,6 +129,7 @@
|
||||
#include "nsXBLService.h"
|
||||
#include "nsContentCID.h"
|
||||
#include "nsITextControlElement.h"
|
||||
#include "mozilla/dom/DocumentFragment.h"
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::dom;
|
||||
@ -3393,13 +3394,8 @@ Element::SetOuterHTML(const nsAString& aOuterHTML, ErrorResult& aError)
|
||||
localName = nsGkAtoms::body;
|
||||
namespaceID = kNameSpaceID_XHTML;
|
||||
}
|
||||
nsCOMPtr<nsIDOMDocumentFragment> df;
|
||||
aError = NS_NewDocumentFragment(getter_AddRefs(df),
|
||||
OwnerDoc()->NodeInfoManager());
|
||||
if (aError.Failed()) {
|
||||
return;
|
||||
}
|
||||
nsCOMPtr<nsIContent> fragment = do_QueryInterface(df);
|
||||
nsRefPtr<DocumentFragment> fragment =
|
||||
new DocumentFragment(OwnerDoc()->NodeInfoManager());
|
||||
nsContentUtils::ParseFragmentHTML(aOuterHTML,
|
||||
fragment,
|
||||
localName,
|
||||
|
@ -4153,7 +4153,7 @@ nsContentUtils::CreateContextualFragment(nsINode* aContextNode,
|
||||
|
||||
if (isHTML) {
|
||||
nsRefPtr<DocumentFragment> frag =
|
||||
NS_NewDocumentFragment(document->NodeInfoManager(), aRv);
|
||||
new DocumentFragment(document->NodeInfoManager());
|
||||
|
||||
nsCOMPtr<nsIContent> contextAsContent = do_QueryInterface(aContextNode);
|
||||
if (contextAsContent && !contextAsContent->IsElement()) {
|
||||
|
@ -4791,21 +4791,15 @@ nsIDocument::CreateTextNode(const nsAString& aData) const
|
||||
NS_IMETHODIMP
|
||||
nsDocument::CreateDocumentFragment(nsIDOMDocumentFragment** aReturn)
|
||||
{
|
||||
ErrorResult rv;
|
||||
*aReturn = nsIDocument::CreateDocumentFragment(rv).get();
|
||||
return rv.ErrorCode();
|
||||
*aReturn = nsIDocument::CreateDocumentFragment().get();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
already_AddRefed<DocumentFragment>
|
||||
nsIDocument::CreateDocumentFragment(ErrorResult& rv) const
|
||||
nsIDocument::CreateDocumentFragment() const
|
||||
{
|
||||
nsCOMPtr<nsIDOMDocumentFragment> frag;
|
||||
nsresult res = NS_NewDocumentFragment(getter_AddRefs(frag), mNodeInfoManager);
|
||||
if (NS_FAILED(res)) {
|
||||
rv.Throw(res);
|
||||
return nullptr;
|
||||
}
|
||||
return static_cast<DocumentFragment*>(frag.forget().get());
|
||||
nsRefPtr<DocumentFragment> frag = new DocumentFragment(mNodeInfoManager);
|
||||
return frag.forget();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -1796,9 +1796,7 @@ nsRange::CutContents(dom::DocumentFragment** aFragment)
|
||||
// If aFragment isn't null, create a temporary fragment to hold our return.
|
||||
nsRefPtr<dom::DocumentFragment> retval;
|
||||
if (aFragment) {
|
||||
ErrorResult error;
|
||||
retval = NS_NewDocumentFragment(doc->NodeInfoManager(), error);
|
||||
NS_ENSURE_SUCCESS(error.ErrorCode(), error.ErrorCode());
|
||||
retval = new dom::DocumentFragment(doc->NodeInfoManager());
|
||||
}
|
||||
nsCOMPtr<nsIDOMNode> commonCloneAncestor = retval.get();
|
||||
|
||||
@ -2239,10 +2237,7 @@ nsRange::CloneContents(ErrorResult& aRv)
|
||||
nsCOMPtr<nsIDocument> doc(do_QueryInterface(document));
|
||||
|
||||
nsRefPtr<dom::DocumentFragment> clonedFrag =
|
||||
NS_NewDocumentFragment(doc->NodeInfoManager(), aRv);
|
||||
if (aRv.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
new dom::DocumentFragment(doc->NodeInfoManager());
|
||||
|
||||
nsCOMPtr<nsIDOMNode> commonCloneAncestor = clonedFrag.get();
|
||||
if (!commonCloneAncestor) {
|
||||
|
@ -50,11 +50,7 @@ HTMLTemplateElement::Init()
|
||||
NS_ENSURE_TRUE(contentsOwner, NS_ERROR_UNEXPECTED);
|
||||
}
|
||||
|
||||
ErrorResult rv;
|
||||
mContent = contentsOwner->CreateDocumentFragment(rv);
|
||||
if (rv.Failed()) {
|
||||
return rv.ErrorCode();
|
||||
}
|
||||
mContent = contentsOwner->CreateDocumentFragment();
|
||||
mContent->SetHost(this);
|
||||
|
||||
return NS_OK;
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "nsIDocShell.h"
|
||||
#include "nsScriptLoader.h"
|
||||
#include "mozilla/css/Loader.h"
|
||||
#include "mozilla/dom/DocumentFragment.h"
|
||||
#include "mozilla/dom/ProcessingInstruction.h"
|
||||
|
||||
using namespace mozilla::dom;
|
||||
@ -158,13 +159,9 @@ nsXMLFragmentContentSink::WillBuildModel(nsDTDMode aDTDMode)
|
||||
|
||||
NS_ASSERTION(mTargetDocument, "Need a document!");
|
||||
|
||||
nsCOMPtr<nsIDOMDocumentFragment> frag;
|
||||
nsresult rv = NS_NewDocumentFragment(getter_AddRefs(frag), mNodeInfoManager);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
mRoot = do_QueryInterface(frag);
|
||||
mRoot = new DocumentFragment(mNodeInfoManager);
|
||||
|
||||
return rv;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -23,8 +23,10 @@
|
||||
#include "nsIDOMDocumentFragment.h"
|
||||
#include "txMozillaXMLOutput.h"
|
||||
#include "nsTextNode.h"
|
||||
#include "mozilla/dom/DocumentFragment.h"
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::dom;
|
||||
|
||||
class txStylesheetCompilerState;
|
||||
|
||||
@ -46,15 +48,13 @@ convertRtfToNode(txIEvalContext *aContext, txResultTreeFragment *aRtf)
|
||||
const txXPathNode& document = es->getSourceDocument();
|
||||
|
||||
nsIDocument *doc = txXPathNativeNode::getDocument(document);
|
||||
nsCOMPtr<nsIDOMDocumentFragment> domFragment;
|
||||
nsresult rv = NS_NewDocumentFragment(getter_AddRefs(domFragment),
|
||||
doc->NodeInfoManager());
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsCOMPtr<nsIDOMDocumentFragment> domFragment =
|
||||
new DocumentFragment(doc->NodeInfoManager());
|
||||
|
||||
txOutputFormat format;
|
||||
txMozillaXMLOutput mozHandler(&format, domFragment, true);
|
||||
|
||||
rv = aRtf->flushToHandler(&mozHandler);
|
||||
nsresult rv = aRtf->flushToHandler(&mozHandler);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = mozHandler.closePrevious(true);
|
||||
@ -96,25 +96,23 @@ createTextNode(txIEvalContext *aContext, nsString& aValue,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static nsresult
|
||||
createDocFragment(txIEvalContext *aContext, nsIContent** aResult)
|
||||
static already_AddRefed<DocumentFragment>
|
||||
createDocFragment(txIEvalContext *aContext)
|
||||
{
|
||||
txExecutionState* es =
|
||||
static_cast<txExecutionState*>(aContext->getPrivateContext());
|
||||
if (!es) {
|
||||
NS_ERROR("Need txExecutionState!");
|
||||
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const txXPathNode& document = es->getSourceDocument();
|
||||
nsIDocument *doc = txXPathNativeNode::getDocument(document);
|
||||
nsCOMPtr<nsIDOMDocumentFragment> domFragment;
|
||||
nsresult rv = NS_NewDocumentFragment(getter_AddRefs(domFragment),
|
||||
doc->NodeInfoManager());
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsRefPtr<DocumentFragment> fragment =
|
||||
new DocumentFragment(doc->NodeInfoManager());
|
||||
|
||||
return CallQueryInterface(domFragment, aResult);
|
||||
return fragment.forget();
|
||||
}
|
||||
|
||||
static nsresult
|
||||
@ -490,9 +488,8 @@ txEXSLTFunctionCall::evaluate(txIEvalContext *aContext,
|
||||
}
|
||||
|
||||
// Set up holders for the result
|
||||
nsCOMPtr<nsIContent> docFrag;
|
||||
rv = createDocFragment(aContext, getter_AddRefs(docFrag));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsRefPtr<DocumentFragment> docFrag = createDocFragment(aContext);
|
||||
NS_ENSURE_STATE(docFrag);
|
||||
|
||||
nsRefPtr<txNodeSet> resultSet;
|
||||
rv = aContext->recycler()->getNodeSet(getter_AddRefs(resultSet));
|
||||
|
@ -46,7 +46,7 @@ interface Document : Node {
|
||||
Element createElement(DOMString localName);
|
||||
[Creator, Throws]
|
||||
Element createElementNS(DOMString? namespace, DOMString qualifiedName);
|
||||
[Creator, Throws]
|
||||
[Creator]
|
||||
DocumentFragment createDocumentFragment();
|
||||
[Creator]
|
||||
Text createTextNode(DOMString data);
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "mozilla/dom/DocumentFragment.h"
|
||||
#include "mozilla/Base64.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
#include "mozilla/Selection.h"
|
||||
@ -92,6 +93,7 @@ class nsILoadContext;
|
||||
class nsISupports;
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::dom;
|
||||
|
||||
const PRUnichar nbsp = 160;
|
||||
|
||||
@ -2281,10 +2283,8 @@ nsresult nsHTMLEditor::ParseFragment(const nsAString & aFragStr,
|
||||
{
|
||||
nsAutoScriptBlockerSuppressNodeRemoved autoBlocker;
|
||||
|
||||
nsCOMPtr<nsIDOMDocumentFragment> frag;
|
||||
NS_NewDocumentFragment(getter_AddRefs(frag),
|
||||
aTargetDocument->NodeInfoManager());
|
||||
nsCOMPtr<nsIContent> fragment = do_QueryInterface(frag);
|
||||
nsRefPtr<DocumentFragment> fragment =
|
||||
new DocumentFragment(aTargetDocument->NodeInfoManager());
|
||||
nsresult rv = nsContentUtils::ParseFragmentHTML(aFragStr,
|
||||
fragment,
|
||||
aContextLocalName ?
|
||||
@ -2298,7 +2298,7 @@ nsresult nsHTMLEditor::ParseFragment(const nsAString & aFragStr,
|
||||
nsIParserUtils::SanitizerAllowComments);
|
||||
sanitizer.Sanitize(fragment);
|
||||
}
|
||||
*outNode = do_QueryInterface(frag);
|
||||
*outNode = fragment.forget();
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
@ -35,9 +35,12 @@
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsTreeSanitizer.h"
|
||||
#include "nsHtml5Module.h"
|
||||
#include "mozilla/dom/DocumentFragment.h"
|
||||
|
||||
#define XHTML_DIV_TAG "div xmlns=\"http://www.w3.org/1999/xhtml\""
|
||||
|
||||
using namespace mozilla::dom;
|
||||
|
||||
NS_IMPL_ISUPPORTS2(nsParserUtils,
|
||||
nsIScriptableUnescapeHTML,
|
||||
nsIParserUtils)
|
||||
@ -192,8 +195,7 @@ nsParserUtils::ParseFragment(const nsAString& aFragment,
|
||||
aReturn);
|
||||
fragment = do_QueryInterface(*aReturn);
|
||||
} else {
|
||||
NS_NewDocumentFragment(aReturn,
|
||||
document->NodeInfoManager());
|
||||
NS_ADDREF(*aReturn = new DocumentFragment(document->NodeInfoManager()));
|
||||
fragment = do_QueryInterface(*aReturn);
|
||||
rv = nsContentUtils::ParseFragmentHTML(aFragment,
|
||||
fragment,
|
||||
|
Loading…
Reference in New Issue
Block a user