Bug 1664411 - Factor out a condition to unconditionally enable clipboard events in some documents. r=masayuki

This patch shouldn't introduce any behavior change.

Differential Revision: https://phabricator.services.mozilla.com/D89834
This commit is contained in:
Emilio Cobos Álvarez 2020-09-11 11:08:35 +00:00
Родитель f4aee8119a
Коммит 20252cfeaf
7 изменённых файлов: 26 добавлений и 20 удалений

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

@ -11790,6 +11790,10 @@ void Document::UnsuppressEventHandlingAndFireEvents(bool aFireEvents) {
}
}
bool Document::AreClipboardCommandsUnconditionallyEnabled() const {
return IsHTMLOrXHTML() && !nsContentUtils::IsChromeDoc(this);
}
void Document::AddSuspendedChannelEventQueue(net::ChannelEventQueue* aQueue) {
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(EventHandlingSuppressed());

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

@ -2713,6 +2713,13 @@ class Document : public nsINode,
UpdateFrameRequestCallbackSchedulingState();
}
/**
* Some clipboard commands are unconditionally enabled on some documents, so
* as to always dispatch copy / paste events even though you'd normally not be
* able to copy.
*/
bool AreClipboardCommandsUnconditionallyEnabled() const;
/**
* Note a ChannelEventQueue which has been suspended on the document's behalf
* to prevent XHRs from running content scripts while event handling is

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

@ -487,7 +487,7 @@ nsresult nsClipboardCommand::IsCommandEnabled(const char* aCommandName,
RefPtr<dom::Document> doc = window->GetExtantDoc();
NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE);
if (doc->IsHTMLOrXHTML() && !nsContentUtils::IsChromeDoc(doc)) {
if (doc->AreClipboardCommandsUnconditionallyEnabled()) {
// In HTML and XHTML documents, we always want the cut, copy and paste
// commands to be enabled, but if the document is chrome, let it control it.
*outCmdEnabled = true;

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

@ -2160,11 +2160,7 @@ static const char* textHtmlEditorFlavors[] = {kUnicodeMime, kHTMLMime,
kPNGImageMime, kGIFImageMime};
bool HTMLEditor::CanPaste(int32_t aClipboardType) const {
// Always enable the paste command when inside of a HTML or XHTML document,
// but if the document is chrome, let it control it.
Document* document = GetDocument();
if (document && document->IsHTMLOrXHTML() &&
!nsContentUtils::IsChromeDoc(document)) {
if (AreClipboardCommandsUnconditionallyEnabled()) {
return true;
}

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

@ -1200,17 +1200,18 @@ nsresult TextEditor::CutAsAction(nsIPrincipal* aPrincipal) {
return EditorBase::ToGenericNSResult(rv);
}
bool TextEditor::AreClipboardCommandsUnconditionallyEnabled() const {
Document* document = GetDocument();
return document && document->AreClipboardCommandsUnconditionallyEnabled();
}
bool TextEditor::IsCutCommandEnabled() const {
AutoEditActionDataSetter editActionData(*this, EditAction::eNotEditing);
if (NS_WARN_IF(!editActionData.CanHandle())) {
return false;
}
// Cut is always enabled in HTML documents, but if the document is chrome,
// let it control it.
Document* document = GetDocument();
if (document && document->IsHTMLOrXHTML() &&
!nsContentUtils::IsChromeDoc(document)) {
if (AreClipboardCommandsUnconditionallyEnabled()) {
return true;
}
@ -1236,11 +1237,7 @@ bool TextEditor::IsCopyCommandEnabled() const {
return false;
}
// Copy is always enabled in HTML documents, but if the document is chrome,
// let it control it.
Document* document = GetDocument();
if (document && document->IsHTMLOrXHTML() &&
!nsContentUtils::IsChromeDoc(document)) {
if (AreClipboardCommandsUnconditionallyEnabled()) {
return true;
}

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

@ -86,6 +86,11 @@ class TextEditor : public EditorBase, public nsITimerCallback, public nsINamed {
*/
MOZ_CAN_RUN_SCRIPT nsresult CutAsAction(nsIPrincipal* aPrincipal = nullptr);
/**
* See Document::AreClipboardCommandsUnconditionallyEnabled.
*/
bool AreClipboardCommandsUnconditionallyEnabled() const;
/**
* IsCutCommandEnabled() returns whether cut command can be enabled or
* disabled. This always returns true if we're in non-chrome HTML/XHTML

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

@ -664,10 +664,7 @@ nsresult TextEditor::PasteTransferableAsAction(nsITransferable* aTransferable,
}
bool TextEditor::CanPaste(int32_t aClipboardType) const {
// Always enable the paste command when inside of a HTML or XHTML document,
// but if the document is chrome, let it control it.
RefPtr<Document> doc = GetDocument();
if (doc && doc->IsHTMLOrXHTML() && !nsContentUtils::IsChromeDoc(doc)) {
if (AreClipboardCommandsUnconditionallyEnabled()) {
return true;
}