Bug 1352882 - Part 1. Add releasing nsIDocument option to recycle nsIDocumentEncoder. r=smaug

Editor uses weak reference for nsIDocument.  But nsDocumentEncoder has strong reference of nsIDocument. So to recycle nsIDocumentEncoder, editor wants the option that nsIDocumentEncoder releases nsIDocument into nsDocumentEncoder after EncodeTo* is called.

MozReview-Commit-ID: K3E9XhgD8FY

--HG--
extra : rebase_source : d37983705d574a2443c8f7504c7f5e3f35470ef1
This commit is contained in:
Makoto Kato 2017-04-17 19:49:52 +09:00
Родитель 41e55cb57d
Коммит da147c947a
2 изменённых файлов: 28 добавлений и 0 удалений

Просмотреть файл

@ -142,6 +142,25 @@ protected:
virtual bool IncludeInContext(nsINode *aNode);
class MOZ_STACK_CLASS AutoReleaseDocumentIfNeeded final
{
public:
explicit AutoReleaseDocumentIfNeeded(nsDocumentEncoder* aEncoder)
: mEncoder(aEncoder)
{
}
~AutoReleaseDocumentIfNeeded()
{
if (mEncoder->mFlags & RequiresReinitAfterOutput) {
mEncoder->mDocument = nullptr;
}
}
private:
nsDocumentEncoder* mEncoder;
};
nsCOMPtr<nsIDocument> mDocument;
nsCOMPtr<nsISelection> mSelection;
RefPtr<nsRange> mRange;
@ -1009,6 +1028,8 @@ nsDocumentEncoder::EncodeToStringWithMaxLength(uint32_t aMaxLength,
if (!mDocument)
return NS_ERROR_NOT_INITIALIZED;
AutoReleaseDocumentIfNeeded autoReleaseDocument(this);
aOutputString.Truncate();
nsString output;

Просмотреть файл

@ -247,6 +247,13 @@ interface nsIDocumentEncoder : nsISupports
*/
const unsigned long OutputDisallowLineBreaking = (1 << 27);
/**
* Release reference of nsIDocument after using encodeTo* method to recycle
* this encoder without holding nsIDocument. To use this encoder again,
* we have to call init again.
*/
const unsigned long RequiresReinitAfterOutput = (1 << 28);
/**
* Initialize with a pointer to the document and the mime type.
* @param aDocument Document to encode.