mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 21:31:04 +00:00
Bug 1453869 part 4. Remove nsIDOMParser::ParseFromString. r=mrbkap
MozReview-Commit-ID: CoepOZNb0DU
This commit is contained in:
parent
4527d58c1c
commit
af62ed5dc8
@ -57,70 +57,49 @@ StringFromSupportedType(SupportedType aType)
|
||||
|
||||
already_AddRefed<nsIDocument>
|
||||
DOMParser::ParseFromString(const nsAString& aStr, SupportedType aType,
|
||||
ErrorResult& rv)
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
nsCOMPtr<nsIDOMDocument> domDocument;
|
||||
rv = ParseFromString(aStr,
|
||||
StringFromSupportedType(aType),
|
||||
getter_AddRefs(domDocument));
|
||||
nsCOMPtr<nsIDocument> document(do_QueryInterface(domDocument));
|
||||
return document.forget();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
DOMParser::ParseFromString(const char16_t *str,
|
||||
const char *contentType,
|
||||
nsIDOMDocument **aResult)
|
||||
{
|
||||
NS_ENSURE_ARG(str);
|
||||
// Converting a string to an enum value manually is a bit of a pain,
|
||||
// so let's just use a helper that takes a content-type string.
|
||||
return ParseFromString(nsDependentString(str), contentType, aResult);
|
||||
}
|
||||
|
||||
nsresult
|
||||
DOMParser::ParseFromString(const nsAString& str,
|
||||
const char *contentType,
|
||||
nsIDOMDocument **aResult)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aResult);
|
||||
|
||||
nsresult rv;
|
||||
|
||||
if (!nsCRT::strcmp(contentType, "text/html")) {
|
||||
nsCOMPtr<nsIDOMDocument> domDocument;
|
||||
rv = SetUpDocument(DocumentFlavorHTML, getter_AddRefs(domDocument));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsCOMPtr<nsIDocument> document = do_QueryInterface(domDocument);
|
||||
if (aType == SupportedType::Text_html) {
|
||||
nsCOMPtr<nsIDocument> document;
|
||||
nsresult rv = SetUpDocument(DocumentFlavorHTML, getter_AddRefs(document));
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
aRv.Throw(rv);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Keep the XULXBL state in sync with the XML case.
|
||||
|
||||
if (mForceEnableXULXBL) {
|
||||
document->ForceEnableXULXBL();
|
||||
}
|
||||
|
||||
rv = nsContentUtils::ParseDocumentHTML(str, document, false);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = nsContentUtils::ParseDocumentHTML(aStr, document, false);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
aRv.Throw(rv);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
domDocument.forget(aResult);
|
||||
return rv;
|
||||
return document.forget();
|
||||
}
|
||||
|
||||
nsAutoCString utf8str;
|
||||
// Convert from UTF16 to UTF8 using fallible allocations
|
||||
if (!AppendUTF16toUTF8(str, utf8str, mozilla::fallible)) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
if (!AppendUTF16toUTF8(aStr, utf8str, mozilla::fallible)) {
|
||||
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// The new stream holds a reference to the buffer
|
||||
nsCOMPtr<nsIInputStream> stream;
|
||||
rv = NS_NewByteInputStream(getter_AddRefs(stream),
|
||||
utf8str.get(), utf8str.Length(),
|
||||
NS_ASSIGNMENT_DEPEND);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
nsresult rv = NS_NewByteInputStream(getter_AddRefs(stream),
|
||||
utf8str.get(), utf8str.Length(),
|
||||
NS_ASSIGNMENT_DEPEND);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
aRv.Throw(rv);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return ParseFromStream(stream, "UTF-8", utf8str.Length(), contentType, aResult);
|
||||
return ParseFromStream(stream, NS_LITERAL_STRING("UTF-8"),
|
||||
utf8str.Length(), aType, aRv);
|
||||
}
|
||||
|
||||
already_AddRefed<nsIDocument>
|
||||
@ -231,9 +210,9 @@ DOMParser::ParseFromStream(nsIInputStream* aStream,
|
||||
stream = bufferedStream;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMDocument> domDocument;
|
||||
nsCOMPtr<nsIDocument> document;
|
||||
rv = SetUpDocument(svg ? DocumentFlavorSVG : DocumentFlavorLegacyGuess,
|
||||
getter_AddRefs(domDocument));
|
||||
getter_AddRefs(document));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// Create a fake channel
|
||||
@ -254,18 +233,14 @@ DOMParser::ParseFromStream(nsIInputStream* aStream,
|
||||
// Tell the document to start loading
|
||||
nsCOMPtr<nsIStreamListener> listener;
|
||||
|
||||
// Have to pass false for reset here, else the reset will remove
|
||||
// our event listener. Should that listener addition move to later
|
||||
// than this call?
|
||||
nsCOMPtr<nsIDocument> document(do_QueryInterface(domDocument));
|
||||
if (!document) return NS_ERROR_FAILURE;
|
||||
|
||||
// Keep the XULXBL state in sync with the HTML case
|
||||
|
||||
if (mForceEnableXULXBL) {
|
||||
document->ForceEnableXULXBL();
|
||||
}
|
||||
|
||||
// Have to pass false for reset here, else the reset will remove
|
||||
// our event listener. Should that listener addition move to later
|
||||
// than this call?
|
||||
rv = document->StartDocumentLoad(kLoadAsData, parserChannel,
|
||||
nullptr, nullptr,
|
||||
getter_AddRefs(listener),
|
||||
@ -299,9 +274,7 @@ DOMParser::ParseFromStream(nsIInputStream* aStream,
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
domDocument.swap(*aResult);
|
||||
|
||||
return NS_OK;
|
||||
return CallQueryInterface(document, aResult);
|
||||
}
|
||||
|
||||
nsresult
|
||||
@ -411,7 +384,7 @@ DOMParser::InitInternal(nsISupports* aOwner, nsIPrincipal* prin,
|
||||
}
|
||||
|
||||
nsresult
|
||||
DOMParser::SetUpDocument(DocumentFlavor aFlavor, nsIDOMDocument** aResult)
|
||||
DOMParser::SetUpDocument(DocumentFlavor aFlavor, nsIDocument** aResult)
|
||||
{
|
||||
// We should really QI to nsIGlobalObject here, but nsDocument gets confused
|
||||
// if we pass it a scriptHandlingObject that doesn't QI to
|
||||
@ -434,10 +407,13 @@ DOMParser::SetUpDocument(DocumentFlavor aFlavor, nsIDOMDocument** aResult)
|
||||
NS_ASSERTION(mPrincipal, "Must have principal by now");
|
||||
NS_ASSERTION(mDocumentURI, "Must have document URI by now");
|
||||
|
||||
return NS_NewDOMDocument(aResult, EmptyString(), EmptyString(), nullptr,
|
||||
mDocumentURI, mBaseURI,
|
||||
mPrincipal,
|
||||
true,
|
||||
scriptHandlingObject,
|
||||
aFlavor);
|
||||
nsCOMPtr<nsIDOMDocument> domDoc;
|
||||
rv = NS_NewDOMDocument(getter_AddRefs(domDoc), EmptyString(), EmptyString(),
|
||||
nullptr, mDocumentURI, mBaseURI, mPrincipal,
|
||||
true, scriptHandlingObject, aFlavor);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
|
||||
doc.forget(aResult);
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -45,8 +45,7 @@ public:
|
||||
mozilla::ErrorResult& rv);
|
||||
|
||||
already_AddRefed<nsIDocument>
|
||||
ParseFromString(const nsAString& aStr, mozilla::dom::SupportedType aType,
|
||||
mozilla::ErrorResult& rv);
|
||||
ParseFromString(const nsAString& aStr, SupportedType aType, ErrorResult& aRv);
|
||||
|
||||
already_AddRefed<nsIDocument>
|
||||
ParseFromBuffer(const mozilla::dom::Sequence<uint8_t>& aBuf,
|
||||
@ -116,11 +115,7 @@ private:
|
||||
nsresult InitInternal(nsISupports* aOwner, nsIPrincipal* prin,
|
||||
nsIURI* documentURI, nsIURI* baseURI);
|
||||
|
||||
nsresult SetUpDocument(DocumentFlavor aFlavor, nsIDOMDocument** aResult);
|
||||
|
||||
// Helper for ParseFromString
|
||||
nsresult ParseFromString(const nsAString& str, const char *contentType,
|
||||
nsIDOMDocument **aResult);
|
||||
nsresult SetUpDocument(DocumentFlavor aFlavor, nsIDocument** aResult);
|
||||
|
||||
class AttemptedInitMarker {
|
||||
public:
|
||||
|
@ -22,16 +22,6 @@ interface nsIGlobalObject;
|
||||
[shim(DOMParser), uuid(70b9600e-8622-4c93-9ad8-22c28058dc44)]
|
||||
interface nsIDOMParser : nsISupports
|
||||
{
|
||||
/**
|
||||
* The string passed in is parsed into a DOM document.
|
||||
*
|
||||
* @param str The UTF16 string to be parsed
|
||||
* @param contentType The content type of the string (see parseFromStream)
|
||||
* @returns The DOM document created as a result of parsing the
|
||||
* string
|
||||
*/
|
||||
nsIDOMDocument parseFromString(in wstring str, in string contentType);
|
||||
|
||||
/**
|
||||
* The buffer is parsed into a DOM document.
|
||||
* The charset is determined from the xml entity decl.
|
||||
|
Loading…
Reference in New Issue
Block a user