Index: CKEditor/releases/latest/_source/plugins/pastetext/plugin.js
===================================================================
--- CKEditor/releases/latest/_source/plugins/pastetext/plugin.js	(revision 4213)
+++ CKEditor/releases/latest/_source/plugins/pastetext/plugin.js	(revision 4887)
@@ -1,4 +1,4 @@
 ﻿/*
-Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
+Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
 For licensing, see LICENSE.html or http://ckeditor.com/license
 */
@@ -15,15 +15,57 @@
 		exec : function( editor )
 		{
-			// We use getClipboardData just to test if the clipboard access has
-			// been granted by the user.
-			if ( CKEDITOR.getClipboardData() === false || !window.clipboardData )
+			var clipboardText = CKEDITOR.tools.tryThese(
+				function()
+				{
+					var clipboardText = window.clipboardData.getData( 'Text' );
+					if ( !clipboardText )
+						throw 0;
+					return clipboardText;
+				},
+				function()
+				{
+					window.netscape.security.PrivilegeManager.enablePrivilege( "UniversalXPConnect" );
+
+					var clip = window.Components.classes[ "@mozilla.org/widget/clipboard;1" ]
+							.getService( window.Components.interfaces.nsIClipboard );
+					var trans = window.Components.classes[ "@mozilla.org/widget/transferable;1" ]
+							.createInstance( window.Components.interfaces.nsITransferable );
+					trans.addDataFlavor( "text/unicode" );
+					clip.getData( trans, clip.kGlobalClipboard );
+
+					var str = {}, strLength = {}, clipboardText;
+					trans.getTransferData( "text/unicode", str, strLength );
+					str = str.value.QueryInterface( window.Components.interfaces.nsISupportsString );
+					clipboardText = str.data.substring( 0, strLength.value / 2 );
+					return clipboardText;
+				}
+				// Any other approach that's working...
+				);
+
+			if ( !clipboardText )   // Clipboard access privilege is not granted.
 			{
 				editor.openDialog( 'pastetext' );
-				return;
+				return false;
 			}
+			else
+				editor.fire( 'paste', { 'text' : clipboardText } );
 
-			editor.insertText( window.clipboardData.getData( 'Text' ) );
+			return true;
 		}
 	};
+
+	function doInsertText( doc, text )
+	{
+		// Native text insertion.
+		if( CKEDITOR.env.ie )
+		{
+			var selection = doc.selection;
+			if ( selection.type == 'Control' )
+				selection.clear();
+			selection.createRange().pasteHTML( text );
+		}
+		else
+			doc.execCommand( 'inserthtml', false, text );
+	}
 
 	// Register the plugin.
@@ -45,89 +87,67 @@
 			if ( editor.config.forcePasteAsPlainText )
 			{
-				editor.on( 'beforePaste', function( event )
+				// Intercept the default pasting process.
+				editor.on( 'beforeCommandExec', function ( evt )
+				{
+					if ( evt.data.name == 'paste' )
 					{
-						if ( editor.mode == "wysiwyg" )
-						{
-							setTimeout( function() { command.exec(); }, 0 );
-							event.cancel();
-						}
-					},
-					null, null, 20 );
+						editor.execCommand( 'pastetext' );
+						evt.cancel();
+					}
+				}, null, null, 0 );
 			}
 		},
+
 		requires : [ 'clipboard' ]
 	});
 
-	var clipboardDiv;
+	function doEnter( editor, mode, times, forceMode )
+	{
+		while ( times-- )
+		{
+			CKEDITOR.plugins.enterkey[ mode == CKEDITOR.ENTER_BR ? 'enterBr' : 'enterBlock' ]
+					( editor, mode, null, forceMode );
+		}
+	}
 
-	CKEDITOR.getClipboardData = function()
+	CKEDITOR.editor.prototype.insertText = function( text )
 	{
-		if ( !CKEDITOR.env.ie )
-			return false;
+		this.focus();
+		this.fire( 'saveSnapshot' );
 
-		var doc = CKEDITOR.document,
-			body = doc.getBody();
+		var mode = this.getSelection().getStartElement().hasAscendant( 'pre', true ) ? CKEDITOR.ENTER_BR : this.config.enterMode,
+			isEnterBrMode = mode == CKEDITOR.ENTER_BR,
+			doc = this.document.$,
+			self = this,
+			line;
 
-		if ( !clipboardDiv )
-		{
-			clipboardDiv = doc.createElement( 'div',
-				{
-					attributes :
-						{
-							id: 'cke_hiddenDiv'
-						},
-					styles :
-						{
-							position : 'absolute',
-							visibility : 'hidden',
-							overflow : 'hidden',
-							width : '1px',
-							height : '1px'
-						}
-				});
+		text = CKEDITOR.tools.htmlEncode( text.replace( /\r\n|\r/g, '\n' ) );
 
-			clipboardDiv.setHtml( '' );
+		var startIndex = 0;
+		text.replace( /\n+/g, function( match, lastIndex )
+		 {
+			line = text.substring( startIndex, lastIndex );
+			startIndex = lastIndex + match.length;
+			line.length && doInsertText( doc, line );
 
-			clipboardDiv.appendTo( body );
-		}
+			var lineBreakNums = match.length,
+				// Duo consequence line-break as a enter block.
+				enterBlockTimes = isEnterBrMode ? 0 : Math.floor( lineBreakNums / 2 ),
+				// Per link-break as a enter br.
+				enterBrTimes = isEnterBrMode ? lineBreakNums : lineBreakNums % 2;
 
-		// The "enabled" flag is used to check whether the paste operation has
-		// been completed (the onpaste event has been fired).
-		var	enabled = false;
-		var setEnabled = function()
-		{
-			enabled = true;
-		};
+			// Line-breaks are converted to editor enter key strokes.
+			doEnter( self, mode, enterBlockTimes );
+			doEnter( self, CKEDITOR.ENTER_BR, enterBrTimes, isEnterBrMode ? false : true );
+		 });
 
-		body.on( 'paste', setEnabled );
+		// Insert the last text line of text.
+		line = text.substring( startIndex, text.length );
+		line.length && doInsertText( doc, line );
 
-		// Create a text range and move it inside the div.
-		var textRange = body.$.createTextRange();
-		textRange.moveToElementText( clipboardDiv.$ );
-
-		// The execCommand in will fire the "onpaste", only if the
-		// security settings are enabled.
-		textRange.execCommand( 'Paste' );
-
-		// Get the DIV html and reset it.
-		var html = clipboardDiv.getHtml();
-		clipboardDiv.setHtml( '' );
-
-		body.removeListener( 'paste', setEnabled );
-
-		// Return the HTML or false if not enabled.
-		return enabled && html;
+		this.fire( 'saveSnapshot' );
 	};
 })();
 
-CKEDITOR.editor.prototype.insertText = function( text )
-{
-	text = CKEDITOR.tools.htmlEncode( text );
-
-	// TODO: Replace the following with fill line break processing (see V2).
-	text = text.replace( /(?:\r\n)|\n|\r/g, '<br>' );
-
-	this.insertHtml( text );
-};
 
 /**
@@ -135,4 +155,5 @@
  * editor, loosing any formatting information possibly available in the source
  * text.
+ * @name CKEDITOR.config.forcePasteAsPlainText
  * @type Boolean
  * @default false
@@ -140,3 +161,2 @@
  * config.forcePasteAsPlainText = true;
  */
-CKEDITOR.config.forcePasteAsPlainText = false;
