Index: /CKEditor/branches/features/adobeair/_source/core/dom/document.js
===================================================================
--- /CKEditor/branches/features/adobeair/_source/core/dom/document.js	(revision 5632)
+++ /CKEditor/branches/features/adobeair/_source/core/dom/document.js	(revision 5633)
@@ -226,4 +226,10 @@
 	},
 
+	/**
+	 * Wrapper for document.write that works around certain security
+	 * limitation because of the closed stream when calling this method.
+	 * @param html
+	 * @param mode
+	 */
 	write : function( html, mode )
 	{
@@ -233,18 +239,21 @@
 		if ( CKEDITOR.env.air && this.getBody() )
 		{
+			// We're taking the below extra work only because innerHTML
+			// on <html> element doesn't work as expected.
 			var doc = this;
 
-			// Grab all the <link>s and <style>s.
+			// Grab all the <link> and <style>.
 			var styleSheetLinks = [],
 					styleTexts = [];
+
 			html.replace( /<style[^>]*>([\s\S]*?)<\/style>/gi, function ( match, styleText )
 			{
 				styleTexts.push( styleText );
-			} );
+			});
 
 			html.replace( /<link[^>]*?>/gi, function( linkHtml )
 			{
 				styleSheetLinks.push( linkHtml );
-			} );
+			});
 
 			if ( styleSheetLinks.length )
@@ -261,9 +270,9 @@
 			// Create style nodes for inline css.
 			// ( <style> content doesn't applied when setting via innerHTML )
-			var nums = styleTexts.length;
-			if ( nums )
+			var count = styleTexts.length;
+			if ( count )
 			{
 				var head = this.getHead( doc );
-				for ( var i = 0; i < nums; i++ )
+				for ( var i = 0; i < count; i++ )
 				{
 					var node = head.append( 'style' );
@@ -272,14 +281,15 @@
 				}
 			}
-
-			var bodyHtml = html.match( /<body[^>]*>([\s\S]*)<\/body>/i ),
-					bodyContent = bodyHtml && bodyHtml[ 1 ],
-					body = bodyHtml && CKEDITOR.htmlParser.fragment.fromHtml( bodyHtml[ 0 ] ).children[ 0 ],
-					bodyAttrs = body.attributes,
-					docBody = doc.getBody();
-
-			bodyContent && docBody.setHtml( bodyContent );
-			bodyAttrs && docBody.setAttributes( bodyAttrs );
 			
+			// Copy the entire <body>.  
+			doc.getBody().setAttributes( CKEDITOR.htmlParser.fragment.fromHtml(
+				// Separate body content and attributes.
+				html.replace( /(<body[^>]*>)([\s\S]*)(?=<\/body>)/i,
+					function( match, startTag, innerHTML )
+					{
+						doc.getBody().setHtml( innerHTML );
+						return startTag;
+					})
+				).children[ 0 ].attributes );
 		}
 		else
