Bug 1513547, ensure selection objects created for autocopy are cleared as soon as possible, r=ehsan

--HG--
extra : rebase_source : 75b4aef031526d6f7c1517305f560bf60ca26b3f
This commit is contained in:
Olli Pettay 2018-12-13 15:07:19 +02:00
Родитель 82f86a7598
Коммит 206bc2b3f9
5 изменённых файлов: 10 добавлений и 9 удалений

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

@ -648,7 +648,9 @@ Selection::Selection(nsFrameSelection* aList)
mCalledByJS(false),
mNotifyAutoCopy(false) {}
Selection::~Selection() {
Selection::~Selection() { Disconnect(); }
void Selection::Disconnect() {
SetAnchorFocusRange(-1);
uint32_t count = mRanges.Length();
@ -725,7 +727,8 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Selection)
NS_INTERFACE_MAP_END
NS_IMPL_MAIN_THREAD_ONLY_CYCLE_COLLECTING_ADDREF(Selection)
NS_IMPL_MAIN_THREAD_ONLY_CYCLE_COLLECTING_RELEASE(Selection)
NS_IMPL_MAIN_THREAD_ONLY_CYCLE_COLLECTING_RELEASE_WITH_LAST_RELEASE(
Selection, Disconnect())
const RangeBoundary& Selection::AnchorRef() const {
if (!mAnchorFocusRange) {

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

@ -670,6 +670,8 @@ class Selection final : public nsSupportsWeakReference,
*/
Element* GetCommonEditingHostForAllRanges();
void Disconnect();
// These are the ranges inside this selection. They are kept sorted in order
// of DOM start position.
//

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

@ -184,7 +184,7 @@ class nsDocumentEncoder : public nsIDocumentEncoder {
};
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDocumentEncoder)
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsDocumentEncoder)
NS_IMPL_CYCLE_COLLECTING_RELEASE_WITH_LAST_RELEASE(nsDocumentEncoder, Clear())
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsDocumentEncoder)
NS_INTERFACE_MAP_ENTRY(nsIDocumentEncoder)

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

@ -344,11 +344,8 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsRange)
tmp->Reset();
// This needs to be unlinked after Reset() is called, as it controls
// the result of IsInSelection() which is used by tmp->Reset().
MOZ_DIAGNOSTIC_ASSERT(!tmp->isInList(),
"Shouldn't be registered now that we're unlinking");
NS_IMPL_CYCLE_COLLECTION_UNLINK(mSelection);
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsRange)
@ -356,7 +353,6 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsRange)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mStart)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mEnd)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mRoot)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSelection)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(nsRange)
@ -896,7 +892,7 @@ void nsRange::NotifySelectionListenersAfterRangeSet() {
mCalledByJS = false;
// Be aware, this range may be modified or stop being a range for selection
// after this call. Additionally, the selection instance may have gone.
RefPtr<Selection> selection = mSelection;
RefPtr<Selection> selection = mSelection.get();
selection->NotifySelectionListeners(calledByJSRestorer.SavedValue());
}
}

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

@ -490,7 +490,7 @@ class nsRange final : public nsStubMutationObserver,
// IsInSelection(). It's kept alive via mStartContainer/mEndContainer,
// because we update it any time those could become disconnected from it.
nsINode* MOZ_NON_OWNING_REF mRegisteredCommonAncestor;
RefPtr<mozilla::dom::Selection> mSelection;
mozilla::WeakPtr<mozilla::dom::Selection> mSelection;
// These raw pointers are used to remember a child that is about
// to be inserted between a CharacterData call and a subsequent