MDL-49671 atto: Any pastes that don't have html should clean everything

Browsers may not provide html content in the clipboard object event
though it will really be pasted as such. This includes Firefox on
Windows, Internet Explorer, and some niche cases in Safari.

Because of this, we need to scrub the entire editor anytime we can't
intercept a paste event.

In some magical day in the future when there is better cross browser
support, we can undo this.
This commit is contained in:
Eric Merrill 2015-03-26 23:31:05 -04:00
parent 20d38830ae
commit 73e144334b
4 changed files with 27 additions and 63 deletions

View File

@ -1160,28 +1160,15 @@ EditorClean.prototype = {
var event = sourceEvent._event;
// Check if we have a valid clipboardData object in the event.
// IE has a clipboard object at window.clipboardData, but as of IE 11, it does not provide HTML content access.
if (event && event.clipboardData && event.clipboardData.getData) {
// Check if there is HTML type to be pasted, this is all we care about.
if (event && event.clipboardData && event.clipboardData.getData && event.clipboardData.types) {
// Check if there is HTML type to be pasted, if we can get it, we want to scrub before insert.
var types = event.clipboardData.types;
var isHTML = false;
// Different browsers use different things to hold the types, so test various functions.
if (!types) {
isHTML = false;
} else if (typeof types.contains === 'function') {
// Different browsers use different containers to hold the types, so test various functions.
if (typeof types.contains === 'function') {
isHTML = types.contains('text/html');
} else if (typeof types.indexOf === 'function') {
isHTML = (types.indexOf('text/html') > -1);
if (!isHTML) {
if ((types.indexOf('com.apple.webarchive') > -1) || (types.indexOf('com.apple.iWork.TSPNativeData') > -1)) {
// This is going to be a specialized Apple paste paste. We cannot capture this, so clean everything.
this.fallbackPasteCleanupDelayed();
return true;
}
}
} else {
// We don't know how to handle the clipboard info, so wait for the clipboard event to finish then fallback.
this.fallbackPasteCleanupDelayed();
return true;
}
if (isHTML) {
@ -1216,13 +1203,14 @@ EditorClean.prototype = {
this.updateOriginal();
return false;
} else {
// This is a non-html paste event, we can just let this continue on and call updateOriginalDelayed.
this.updateOriginalDelayed();
// Due to poor cross browser clipboard compatibility, the failure to find html doesn't mean it isn't there.
// Wait for the clipboard event to finish then fallback clean the entire editor.
this.fallbackPasteCleanupDelayed();
return true;
}
} else {
// If we reached a here, this probably means the browser has limited (or no) clipboard support.
// Wait for the clipboard event to finish then fallback.
// Wait for the clipboard event to finish then fallback clean the entire editor.
this.fallbackPasteCleanupDelayed();
return true;
}

File diff suppressed because one or more lines are too long

View File

@ -1150,28 +1150,15 @@ EditorClean.prototype = {
var event = sourceEvent._event;
// Check if we have a valid clipboardData object in the event.
// IE has a clipboard object at window.clipboardData, but as of IE 11, it does not provide HTML content access.
if (event && event.clipboardData && event.clipboardData.getData) {
// Check if there is HTML type to be pasted, this is all we care about.
if (event && event.clipboardData && event.clipboardData.getData && event.clipboardData.types) {
// Check if there is HTML type to be pasted, if we can get it, we want to scrub before insert.
var types = event.clipboardData.types;
var isHTML = false;
// Different browsers use different things to hold the types, so test various functions.
if (!types) {
isHTML = false;
} else if (typeof types.contains === 'function') {
// Different browsers use different containers to hold the types, so test various functions.
if (typeof types.contains === 'function') {
isHTML = types.contains('text/html');
} else if (typeof types.indexOf === 'function') {
isHTML = (types.indexOf('text/html') > -1);
if (!isHTML) {
if ((types.indexOf('com.apple.webarchive') > -1) || (types.indexOf('com.apple.iWork.TSPNativeData') > -1)) {
// This is going to be a specialized Apple paste paste. We cannot capture this, so clean everything.
this.fallbackPasteCleanupDelayed();
return true;
}
}
} else {
// We don't know how to handle the clipboard info, so wait for the clipboard event to finish then fallback.
this.fallbackPasteCleanupDelayed();
return true;
}
if (isHTML) {
@ -1206,13 +1193,14 @@ EditorClean.prototype = {
this.updateOriginal();
return false;
} else {
// This is a non-html paste event, we can just let this continue on and call updateOriginalDelayed.
this.updateOriginalDelayed();
// Due to poor cross browser clipboard compatibility, the failure to find html doesn't mean it isn't there.
// Wait for the clipboard event to finish then fallback clean the entire editor.
this.fallbackPasteCleanupDelayed();
return true;
}
} else {
// If we reached a here, this probably means the browser has limited (or no) clipboard support.
// Wait for the clipboard event to finish then fallback.
// Wait for the clipboard event to finish then fallback clean the entire editor.
this.fallbackPasteCleanupDelayed();
return true;
}

View File

@ -135,28 +135,15 @@ EditorClean.prototype = {
var event = sourceEvent._event;
// Check if we have a valid clipboardData object in the event.
// IE has a clipboard object at window.clipboardData, but as of IE 11, it does not provide HTML content access.
if (event && event.clipboardData && event.clipboardData.getData) {
// Check if there is HTML type to be pasted, this is all we care about.
if (event && event.clipboardData && event.clipboardData.getData && event.clipboardData.types) {
// Check if there is HTML type to be pasted, if we can get it, we want to scrub before insert.
var types = event.clipboardData.types;
var isHTML = false;
// Different browsers use different things to hold the types, so test various functions.
if (!types) {
isHTML = false;
} else if (typeof types.contains === 'function') {
// Different browsers use different containers to hold the types, so test various functions.
if (typeof types.contains === 'function') {
isHTML = types.contains('text/html');
} else if (typeof types.indexOf === 'function') {
isHTML = (types.indexOf('text/html') > -1);
if (!isHTML) {
if ((types.indexOf('com.apple.webarchive') > -1) || (types.indexOf('com.apple.iWork.TSPNativeData') > -1)) {
// This is going to be a specialized Apple paste paste. We cannot capture this, so clean everything.
this.fallbackPasteCleanupDelayed();
return true;
}
}
} else {
// We don't know how to handle the clipboard info, so wait for the clipboard event to finish then fallback.
this.fallbackPasteCleanupDelayed();
return true;
}
if (isHTML) {
@ -191,13 +178,14 @@ EditorClean.prototype = {
this.updateOriginal();
return false;
} else {
// This is a non-html paste event, we can just let this continue on and call updateOriginalDelayed.
this.updateOriginalDelayed();
// Due to poor cross browser clipboard compatibility, the failure to find html doesn't mean it isn't there.
// Wait for the clipboard event to finish then fallback clean the entire editor.
this.fallbackPasteCleanupDelayed();
return true;
}
} else {
// If we reached a here, this probably means the browser has limited (or no) clipboard support.
// Wait for the clipboard event to finish then fallback.
// Wait for the clipboard event to finish then fallback clean the entire editor.
this.fallbackPasteCleanupDelayed();
return true;
}