Index: FCKeditor/trunk/editor/_source/internals/fckdocumentprocessor.js
===================================================================
--- FCKeditor/trunk/editor/_source/internals/fckdocumentprocessor.js	(revision 1565)
+++ FCKeditor/trunk/editor/_source/internals/fckdocumentprocessor.js	(revision 1790)
@@ -34,12 +34,15 @@
 FCKDocumentProcessor.Process = function( document )
 {
+	var bIsDirty = FCK.IsDirty() ;
 	var oProcessor, i = 0 ;
 	while( ( oProcessor = this._Items[i++] ) )
 		oProcessor.ProcessDocument( document ) ;
+	if ( !bIsDirty )
+		FCK.ResetIsDirty() ;
 }
 
 var FCKDocumentProcessor_CreateFakeImage = function( fakeClass, realElement )
 {
-	var oImg = FCK.EditorDocument.createElement( 'IMG' ) ;
+	var oImg = FCKTools.GetElementDocument( realElement ).createElement( 'IMG' ) ;
 	oImg.className = fakeClass ;
 	oImg.src = FCKConfig.FullBasePath + 'images/spacer.gif' ;
@@ -119,54 +122,60 @@
 }
 
-// Flash Embeds.
-var FCKFlashProcessor = FCKDocumentProcessor.AppendNew() ;
-FCKFlashProcessor.ProcessDocument = function( document )
-{
-	/*
-	Sample code:
-	This is some <embed src="/UserFiles/Flash/Yellow_Runners.swf"></embed><strong>sample text</strong>. You are&nbsp;<a name="fred"></a> using <a href="http://www.fckeditor.net/">FCKeditor</a>.
-	*/
-
-	var bIsDirty = FCK.IsDirty() ;
-
-	var aEmbeds = document.getElementsByTagName( 'EMBED' ) ;
-
-	var oEmbed ;
-	var i = aEmbeds.length - 1 ;
-	while ( i >= 0 && ( oEmbed = aEmbeds[i--] ) )
-	{
-		// IE doesn't return the type attribute with oEmbed.type or oEmbed.getAttribute("type")
-		// But it turns out that after accessing it then it doesn't gets copied later
-		var oType = oEmbed.attributes[ 'type' ] ;
-
-		// Check the extension and the type. Now it should be enough with just the type
-		// Opera doesn't return oEmbed.src so oEmbed.src.EndsWith will fail
-		if ( (oEmbed.src && oEmbed.src.EndsWith( '.swf', true )) || ( oType && oType.nodeValue == 'application/x-shockwave-flash' ) )
-		{
-			var oCloned = oEmbed.cloneNode( true ) ;
-
-			var oImg = FCKDocumentProcessor_CreateFakeImage( 'FCK__Flash', oCloned ) ;
-			oImg.setAttribute( '_fckflash', 'true', 0 ) ;
-
-			FCKFlashProcessor.RefreshView( oImg, oEmbed ) ;
-
-			oEmbed.parentNode.insertBefore( oImg, oEmbed ) ;
-			oEmbed.parentNode.removeChild( oEmbed ) ;
-		}
-	}
-
-	// Fix the IsDirty state (#1406).
-	if ( !bIsDirty )
-		FCK.ResetIsDirty() ;
-}
-
-FCKFlashProcessor.RefreshView = function( placeHolderImage, originalEmbed )
-{
-	if ( originalEmbed.getAttribute( 'width' ) > 0 )
-		placeHolderImage.style.width = FCKTools.ConvertHtmlSizeToStyle( originalEmbed.getAttribute( 'width' ) ) ;
-
-	if ( originalEmbed.getAttribute( 'height' ) > 0 )
-		placeHolderImage.style.height = FCKTools.ConvertHtmlSizeToStyle( originalEmbed.getAttribute( 'height' ) ) ;
-}
+// EMBED and OBJECT tags.
+FCKEmbedAndObjectProcessor = (function()
+{
+	var customProcessors = [] ;
+
+	var processElement = function( el )
+	{
+		var clone = el.cloneNode( true ) ;
+		var replaceElement ;
+		var fakeImg = replaceElement = FCKDocumentProcessor_CreateFakeImage( 'FCK__UnknownObject', clone ) ;
+		FCKEmbedAndObjectProcessor.RefreshView( fakeImg, el ) ;
+
+		for ( var i = 0 ; i < customProcessors.length ; i++ )
+			replaceElement = customProcessors[i]( el, replaceElement ) || replaceElement ;
+
+		if ( replaceElement != fakeImg )
+			FCKTempBin.RemoveElement( fakeImg.getAttribute( '_fckrealelement' ) ) ;
+
+		el.parentNode.replaceChild( replaceElement, el ) ;
+	}
+
+	return FCKTools.Merge( FCKDocumentProcessor.AppendNew(),
+		       {
+				ProcessDocument : function( doc )
+				{
+					// Firefox 3 would sometimes throw an unknown exception while accessing EMBEDs and OBJECTs
+					// without the setTimeout().
+					FCKTools.RunFunction( function()
+						{
+							// Process OBJECTs first, since EMBEDs can sometimes go inside OBJECTS (e.g. Flash).
+							var aObjects = doc.getElementsByTagName( 'object' );
+							for ( var i = aObjects.length - 1 ; i >= 0 ; i-- )
+								processElement( aObjects[i] ) ;
+
+							// Now process any EMBEDs left.
+							var aEmbeds = doc.getElementsByTagName( 'embed' ) ;
+							for ( var i = aEmbeds.length - 1 ; i >= 0 ; i-- )
+								processElement( aEmbeds[i] ) ;
+						} ) ;
+				},
+
+				RefreshView : function( placeHolder, original )
+				{
+					if ( original.getAttribute( 'width' ) > 0 )
+						placeHolder.style.width = FCKTools.ConvertHtmlSizeToStyle( original.getAttribute( 'width' ) ) ;
+
+					if ( original.getAttribute( 'height' ) > 0 )
+						placeHolder.style.height = FCKTools.ConvertHtmlSizeToStyle( original.getAttribute( 'height' ) ) ;
+				},
+
+				AddCustomHandler : function( func )
+				{
+					customProcessors.push( func ) ;
+				}
+			} ) ;
+} )() ;
 
 FCK.GetRealElement = function( fakeElement )
@@ -230,2 +239,11 @@
 	}
 }
+
+// Flash handler.
+FCKEmbedAndObjectProcessor.AddCustomHandler( function( el, fakeImg )
+	{
+		if ( ! ( el.nodeName.IEquals( 'embed' ) && ( el.type == 'application/x-shockwave-flash' || /\.swf($|#|\?)/i.test( el.src ) ) ) )
+			return ;
+		fakeImg.className = 'FCK__Flash' ;
+		fakeImg.setAttribute( '_fckflash', 'true', 0 ); 
+	} ) ;
