Bug 758589 - Make Selection.toString() return early (with empty result string) if the shell is destroyed. r=smaug
☠☠ backed out by cf9f2ec36992 ☠ ☠
authorMats Palmgren <matspal@gmail.com>
Tue, 29 May 2012 02:50:42 +0200
changeset 95134 6d605438199cf30d64ee530986668e182292f6b1
parent 95133 deac5d31bc126203fcc50c9ff8f62baf4611cbe7
child 95135 57819b266920075e840a976ef14fd1f439eb488e
push id9960
push usermpalmgren@mozilla.com
push dateTue, 29 May 2012 00:50:36 +0000
treeherdermozilla-inbound@6d605438199c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs758589
milestone15.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 758589 - Make Selection.toString() return early (with empty result string) if the shell is destroyed. r=smaug
layout/generic/nsSelection.cpp
--- a/layout/generic/nsSelection.cpp
+++ b/layout/generic/nsSelection.cpp
@@ -1088,20 +1088,21 @@ nsFrameSelection::MoveCaret(PRUint32    
 
 NS_IMETHODIMP
 nsTypedSelection::ToString(PRUnichar **aReturn)
 {
   if (!aReturn) {
     return NS_ERROR_NULL_POINTER;
   }
   // We need Flush_Style here to make sure frames have been created for
-  // the selected content.
-  nsCOMPtr<nsIPresShell> shell;
-  nsresult rv = GetPresShell(getter_AddRefs(shell));
-  if (NS_FAILED(rv) || !shell) {
+  // the selected content.  Use mFrameSelection->GetShell() which returns
+  // null if the Selection has been disconnected (the shell is Destroyed).
+  nsCOMPtr<nsIPresShell> shell =
+    mFrameSelection ? mFrameSelection->GetShell() : nsnull;
+  if (!shell) {
     *aReturn = ToNewUnicode(EmptyString());
     return NS_OK;
   }
   shell->FlushPendingNotifications(Flush_Style);
 
   return ToStringWithFormat("text/plain",
                             nsIDocumentEncoder::SkipInvisibleContent,
                             0, aReturn);