Bug 1327798 - Part 1. PasteNoFormatting shouldn't set text/html to clipboard event on paste. r=enndeakin

MozReview-Commit-ID: 8VMudiPiXcK

--HG--
extra : rebase_source : 2476f69296a60f6978f97da2daef021b90350dbf
This commit is contained in:
Makoto Kato 2017-02-22 18:34:45 +09:00
Родитель 5a13988731
Коммит 2dcf7753c2
5 изменённых файлов: 31 добавлений и 11 удалений

Просмотреть файл

@ -755,8 +755,13 @@ nsCopySupport::FireClipboardEvent(EventMessage aEventMessage,
*aActionTaken = false;
}
NS_ASSERTION(aEventMessage == eCut || aEventMessage == eCopy ||
aEventMessage == ePaste,
EventMessage originalEventMessage = aEventMessage;
if (originalEventMessage == ePasteNoFormatting) {
originalEventMessage = ePaste;
}
NS_ASSERTION(originalEventMessage == eCut || originalEventMessage == eCopy ||
originalEventMessage == ePaste,
"Invalid clipboard event type");
nsCOMPtr<nsIPresShell> presShell = aPresShell;
@ -813,10 +818,10 @@ nsCopySupport::FireClipboardEvent(EventMessage aEventMessage,
if (chromeShell || Preferences::GetBool("dom.event.clipboardevents.enabled", true)) {
clipboardData =
new DataTransfer(doc->GetScopeObject(), aEventMessage,
aEventMessage == ePaste, aClipboardType);
originalEventMessage == ePaste, aClipboardType);
nsEventStatus status = nsEventStatus_eIgnore;
InternalClipboardEvent evt(true, aEventMessage);
InternalClipboardEvent evt(true, originalEventMessage);
evt.mClipboardData = clipboardData;
EventDispatcher::Dispatch(content, presShell->GetPresContext(), &evt,
nullptr, &status);
@ -827,7 +832,7 @@ nsCopySupport::FireClipboardEvent(EventMessage aEventMessage,
// No need to do anything special during a paste. Either an event listener
// took care of it and cancelled the event, or the caller will handle it.
// Return true to indicate that the event wasn't cancelled.
if (aEventMessage == ePaste) {
if (originalEventMessage == ePaste) {
// Clear and mark the clipboardData as readonly. This prevents someone
// from reading the clipboard contents after the paste event has fired.
if (clipboardData) {
@ -867,7 +872,7 @@ nsCopySupport::FireClipboardEvent(EventMessage aEventMessage,
// when cutting non-editable content, do nothing
// XXX this is probably the wrong editable flag to check
if (aEventMessage != eCut || content->IsEditable()) {
if (originalEventMessage != eCut || content->IsEditable()) {
// get the data from the selection if any
bool isCollapsed;
sel->GetIsCollapsed(&isCollapsed);

Просмотреть файл

@ -105,8 +105,11 @@ DataTransfer::DataTransfer(nsISupports* aParent, EventMessage aEventMessage,
aEventMessage == eDragStart) {
mReadOnly = false;
} else if (mIsExternal) {
if (aEventMessage == ePaste) {
CacheExternalClipboardFormats();
if (aEventMessage == ePasteNoFormatting) {
mEventMessage = ePaste;
CacheExternalClipboardFormats(true);
} else if (aEventMessage == ePaste) {
CacheExternalClipboardFormats(false);
} else if (aEventMessage >= eDragDropEventFirst &&
aEventMessage <= eDragDropEventLast) {
CacheExternalDragFormats();
@ -1356,7 +1359,7 @@ DataTransfer::CacheExternalDragFormats()
}
void
DataTransfer::CacheExternalClipboardFormats()
DataTransfer::CacheExternalClipboardFormats(bool aPlainTextOnly)
{
NS_ASSERTION(mEventMessage == ePaste,
"caching clipboard data for invalid event");
@ -1375,6 +1378,17 @@ DataTransfer::CacheExternalClipboardFormats()
nsCOMPtr<nsIPrincipal> sysPrincipal;
ssm->GetSystemPrincipal(getter_AddRefs(sysPrincipal));
if (aPlainTextOnly) {
bool supported;
const char* unicodeMime[] = { kUnicodeMime };
clipboard->HasDataMatchingFlavors(unicodeMime, 1, mClipboardType,
&supported);
if (supported) {
CacheExternalData(kUnicodeMime, 0, sysPrincipal, false);
}
return;
}
// Check if the clipboard has any files
bool hasFileData = false;
const char *fileMime[] = { kFileMime };

Просмотреть файл

@ -307,7 +307,7 @@ protected:
void CacheExternalDragFormats();
// caches the formats that exist in the clipboard
void CacheExternalClipboardFormats();
void CacheExternalClipboardFormats(bool aPlainTextOnly);
FileList* GetFilesInternal(ErrorResult& aRv, nsIPrincipal* aSubjectPrincipal);
nsresult GetDataAtInternal(const nsAString& aFormat, uint32_t aIndex,

Просмотреть файл

@ -1495,7 +1495,7 @@ HTMLEditor::PasteTransferable(nsITransferable* aTransferable)
NS_IMETHODIMP
HTMLEditor::PasteNoFormatting(int32_t aSelectionType)
{
if (!FireClipboardEvent(ePaste, aSelectionType)) {
if (!FireClipboardEvent(ePasteNoFormatting, aSelectionType)) {
return NS_OK;
}

Просмотреть файл

@ -226,6 +226,7 @@ NS_EVENT_MESSAGE(eXULCommand)
NS_EVENT_MESSAGE(eCopy)
NS_EVENT_MESSAGE(eCut)
NS_EVENT_MESSAGE(ePaste)
NS_EVENT_MESSAGE(ePasteNoFormatting)
// Query for the selected text information, it return the selection offset,
// selection length and selected text.