Skip to content

Commit

Permalink
Bug 1534370 part 3. Mark InsertFromTransferable as MOZ_CAN_RUN_SCRIPT…
Browse files Browse the repository at this point in the history
…. r=masayuki

Differential Revision: https://phabricator.services.mozilla.com/D23042

--HG--
extra : moz-landing-system : lando
  • Loading branch information
bzbarsky committed Mar 12, 2019
1 parent 6d1f77b commit 9a4ba73
Show file tree
Hide file tree
Showing 17 changed files with 47 additions and 15 deletions.
3 changes: 2 additions & 1 deletion accessible/atk/nsMaiInterfaceEditableText.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,11 @@ static void deleteTextCB(AtkEditableText* aText, gint aStartPos, gint aEndPos) {
}
}

MOZ_CAN_RUN_SCRIPT_BOUNDARY
static void pasteTextCB(AtkEditableText* aText, gint aPosition) {
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
if (accWrap) {
HyperTextAccessible* text = accWrap->AsHyperText();
RefPtr<HyperTextAccessible> text = accWrap->AsHyperText();
if (!text || !text->IsTextRole()) {
return;
}
Expand Down
1 change: 1 addition & 0 deletions accessible/generic/HyperTextAccessible.h
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ class HyperTextAccessible : public AccessibleWrap {
void CopyText(int32_t aStartPos, int32_t aEndPos);
void CutText(int32_t aStartPos, int32_t aEndPos);
void DeleteText(int32_t aStartPos, int32_t aEndPos);
MOZ_CAN_RUN_SCRIPT
void PasteText(int32_t aPosition);

/**
Expand Down
1 change: 1 addition & 0 deletions accessible/interfaces/nsIAccessibleEditableText.idl
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,6 @@ interface nsIAccessibleEditableText : nsISupports
* @param position - index at which to insert the text from the system
* clipboard into the text represented by this object.
*/
[can_run_script]
void pasteText(in long position);
};
2 changes: 1 addition & 1 deletion accessible/ipc/other/DocAccessibleChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ mozilla::ipc::IPCResult DocAccessibleChild::RecvDeleteText(

mozilla::ipc::IPCResult DocAccessibleChild::RecvPasteText(
const uint64_t& aID, const int32_t& aPosition, bool* aValid) {
HyperTextAccessible* acc = IdToHyperTextAccessible(aID);
RefPtr<HyperTextAccessible> acc = IdToHyperTextAccessible(aID);
if (acc && acc->IsTextRole()) {
*aValid = acc->IsValidOffset(aPosition);
acc->PasteText(aPosition);
Expand Down
1 change: 1 addition & 0 deletions accessible/ipc/other/DocAccessibleChild.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ class DocAccessibleChild : public DocAccessibleChildBase {
const int32_t& aEndPos,
bool* aValid) override;

MOZ_CAN_RUN_SCRIPT_BOUNDARY
virtual mozilla::ipc::IPCResult RecvPasteText(const uint64_t& aID,
const int32_t& aPosition,
bool* aValid) override;
Expand Down
3 changes: 2 additions & 1 deletion accessible/windows/ia2/ia2AccessibleEditableText.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ STDMETHODIMP
ia2AccessibleEditableText::pasteText(long aOffset) {
MOZ_ASSERT(!HyperTextProxyFor(this));

HyperTextAccessible* textAcc = static_cast<HyperTextAccessibleWrap*>(this);
RefPtr<HyperTextAccessible> textAcc =
static_cast<HyperTextAccessibleWrap*>(this);
if (textAcc->IsDefunct()) return CO_E_OBJNOTCONNECTED;

if (!textAcc->IsValidOffset(aOffset)) return E_INVALIDARG;
Expand Down
1 change: 1 addition & 0 deletions accessible/windows/ia2/ia2AccessibleEditableText.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class ia2AccessibleEditableText : public IAccessibleEditableText {
/* [in] */ long startOffset,
/* [in] */ long endOffset);

MOZ_CAN_RUN_SCRIPT_BOUNDARY
virtual HRESULT STDMETHODCALLTYPE pasteText(
/* [in] */ long offset);

Expand Down
3 changes: 2 additions & 1 deletion accessible/xpcom/xpcAccessibleHyperText.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,8 @@ xpcAccessibleHyperText::PasteText(int32_t aOffset) {
if (mIntl.IsNull()) return NS_ERROR_FAILURE;

if (mIntl.IsAccessible()) {
Intl()->PasteText(aOffset);
RefPtr<HyperTextAccessible> acc = Intl();
acc->PasteText(aOffset);
} else {
#if defined(XP_WIN)
return NS_ERROR_NOT_IMPLEMENTED;
Expand Down
4 changes: 3 additions & 1 deletion editor/libeditor/EditorBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1138,7 +1138,9 @@ EditorBase::CanDelete(bool* aCanDelete) { return NS_ERROR_NOT_IMPLEMENTED; }

NS_IMETHODIMP
EditorBase::Paste(int32_t aClipboardType) {
nsresult rv = AsTextEditor()->PasteAsAction(aClipboardType, true);
// MOZ_KnownLive because we know "this" must be alive.
nsresult rv =
MOZ_KnownLive(AsTextEditor())->PasteAsAction(aClipboardType, true);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
Expand Down
20 changes: 14 additions & 6 deletions editor/libeditor/EditorCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,9 @@ PasteCommand::DoCommand(const char* aCommandName, nsISupports* aCommandRefCon) {
}
TextEditor* textEditor = editor->AsTextEditor();
MOZ_ASSERT(textEditor);
return textEditor->PasteAsAction(nsIClipboard::kGlobalClipboard, true);
// MOZ_KnownLive because we are holding a stack ref in "editor".
return MOZ_KnownLive(textEditor)
->PasteAsAction(nsIClipboard::kGlobalClipboard, true);
}

NS_IMETHODIMP
Expand Down Expand Up @@ -469,7 +471,9 @@ PasteTransferableCommand::DoCommandParams(const char* aCommandName,

TextEditor* textEditor = editor->AsTextEditor();
MOZ_ASSERT(textEditor);
nsresult rv = textEditor->PasteTransferable(trans);
// We know textEditor is known-live here because we are holding a ref to it
// via "editor".
nsresult rv = MOZ_KnownLive(textEditor)->PasteTransferable(trans);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
Expand Down Expand Up @@ -1091,8 +1095,10 @@ PasteQuotationCommand::DoCommand(const char* aCommandName,
}
TextEditor* textEditor = editor->AsTextEditor();
MOZ_ASSERT(textEditor);
nsresult rv = textEditor->PasteAsQuotationAsAction(
nsIClipboard::kGlobalClipboard, true);
// MOZ_KnownLive because we are holding a stack ref in "editor".
nsresult rv =
MOZ_KnownLive(textEditor)
->PasteAsQuotationAsAction(nsIClipboard::kGlobalClipboard, true);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
Expand All @@ -1109,8 +1115,10 @@ PasteQuotationCommand::DoCommandParams(const char* aCommandName,
}
TextEditor* textEditor = editor->AsTextEditor();
MOZ_ASSERT(textEditor);
nsresult rv = textEditor->PasteAsQuotationAsAction(
nsIClipboard::kGlobalClipboard, true);
// MOZ_KnownLive because we are holding a stack ref in "editor".
nsresult rv =
MOZ_KnownLive(textEditor)
->PasteAsQuotationAsAction(nsIClipboard::kGlobalClipboard, true);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
Expand Down
3 changes: 3 additions & 0 deletions editor/libeditor/EditorCommands.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class EditorCommandBase : public nsIControllerCommand {
NS_IMETHOD IsCommandEnabled(const char* aCommandName,
nsISupports* aCommandRefCon,
bool* aIsEnabled) override = 0;
MOZ_CAN_RUN_SCRIPT
NS_IMETHOD DoCommand(const char* aCommandName,
nsISupports* aCommandRefCon) override = 0;

Expand All @@ -44,8 +45,10 @@ class EditorCommandBase : public nsIControllerCommand {
NS_IMETHOD IsCommandEnabled(const char* aCommandName, \
nsISupports* aCommandRefCon, \
bool* aIsEnabled) override; \
MOZ_CAN_RUN_SCRIPT \
NS_IMETHOD DoCommand(const char* aCommandName, \
nsISupports* aCommandRefCon) override; \
MOZ_CAN_RUN_SCRIPT \
NS_IMETHOD DoCommandParams(const char* aCommandName, \
nsICommandParams* aParams, \
nsISupports* aCommandRefCon) override; \
Expand Down
5 changes: 4 additions & 1 deletion editor/libeditor/HTMLEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class HTMLEditor final : public TextEditor,

NS_IMETHOD CanPaste(int32_t aSelectionType, bool* aCanPaste) override;

MOZ_CAN_RUN_SCRIPT
NS_IMETHOD PasteTransferable(nsITransferable* aTransferable) override;

NS_IMETHOD DeleteNode(nsINode* aNode) override;
Expand All @@ -160,6 +161,7 @@ class HTMLEditor final : public TextEditor,
* @param aDispatchPasteEvent true if this should dispatch ePaste event
* before pasting. Otherwise, false.
*/
MOZ_CAN_RUN_SCRIPT
virtual nsresult PasteAsQuotationAsAction(int32_t aClipboardType,
bool aDispatchPasteEvent) override;

Expand Down Expand Up @@ -1410,6 +1412,7 @@ class HTMLEditor final : public TextEditor,
* @param aDispatchPasteEvent true if this should dispatch ePaste event
* before pasting. Otherwise, false.
*/
MOZ_CAN_RUN_SCRIPT
nsresult PasteInternal(int32_t aClipboardType, bool aDispatchPasteEvent);

/**
Expand Down Expand Up @@ -1950,7 +1953,7 @@ class HTMLEditor final : public TextEditor,
// (drag&drop or clipboard)
virtual nsresult PrepareTransferable(nsITransferable** transferable) override;
nsresult PrepareHTMLTransferable(nsITransferable** transferable);
MOZ_CAN_RUN_SCRIPT_BOUNDARY
MOZ_CAN_RUN_SCRIPT
nsresult InsertFromTransferable(nsITransferable* transferable,
Document* aSourceDoc,
const nsAString& aContextStr,
Expand Down
4 changes: 3 additions & 1 deletion editor/libeditor/HTMLEditorCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ PasteNoFormattingCommand::DoCommand(const char* aCommandName,
if (NS_WARN_IF(!htmlEditor)) {
return NS_ERROR_FAILURE;
}
return htmlEditor->PasteNoFormatting(nsIClipboard::kGlobalClipboard);
// Known live because we hold a ref above in "editor"
return MOZ_KnownLive(htmlEditor)
->PasteNoFormatting(nsIClipboard::kGlobalClipboard);
}

NS_IMETHODIMP
Expand Down
3 changes: 3 additions & 0 deletions editor/libeditor/TextEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class TextEditor : public EditorBase, public nsIPlaintextEditor {
NS_IMETHOD CanCopy(bool* aCanCopy) override;
NS_IMETHOD CanDelete(bool* aCanDelete) override;
NS_IMETHOD CanPaste(int32_t aSelectionType, bool* aCanPaste) override;
MOZ_CAN_RUN_SCRIPT
NS_IMETHOD PasteTransferable(nsITransferable* aTransferable) override;

NS_IMETHOD OutputToString(const nsAString& aFormatType, uint32_t aFlags,
Expand Down Expand Up @@ -119,6 +120,7 @@ class TextEditor : public EditorBase, public nsIPlaintextEditor {
* @param aDispatchPasteEvent true if this should dispatch ePaste event
* before pasting. Otherwise, false.
*/
MOZ_CAN_RUN_SCRIPT
nsresult PasteAsAction(int32_t aClipboardType, bool aDispatchPasteEvent);

/**
Expand All @@ -141,6 +143,7 @@ class TextEditor : public EditorBase, public nsIPlaintextEditor {
* @param aDispatchPasteEvent true if this should dispatch ePaste event
* before pasting. Otherwise, false.
*/
MOZ_CAN_RUN_SCRIPT
virtual nsresult PasteAsQuotationAsAction(int32_t aClipboardType,
bool aDispatchPasteEvent);

Expand Down
5 changes: 3 additions & 2 deletions editor/libeditor/TextEditorDataTransfer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,9 @@ nsresult TextEditor::PasteAsAction(int32_t aClipboardType,
if (AsHTMLEditor()) {
editActionData.InitializeDataTransferWithClipboard(
SettingDataTransfer::eWithFormat, aClipboardType);
nsresult rv =
AsHTMLEditor()->PasteInternal(aClipboardType, aDispatchPasteEvent);
// MOZ_KnownLive because we know "this" must be alive.
nsresult rv = MOZ_KnownLive(AsHTMLEditor())
->PasteInternal(aClipboardType, aDispatchPasteEvent);
if (NS_WARN_IF(NS_FAILED(rv))) {
return EditorBase::ToGenericNSResult(rv);
}
Expand Down
2 changes: 2 additions & 0 deletions editor/nsIEditor.idl
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,13 @@ interface nsIEditor : nsISupports
/** paste the text in the OS clipboard at the cursor position, replacing
* the selected text (if any)
*/
[can_run_script]
void paste(in long aSelectionType);

/** Paste the text in |aTransferable| at the cursor position, replacing the
* selected text (if any).
*/
[can_run_script]
void pasteTransferable(in nsITransferable aTransferable);

/** Can we paste? True if the doc is modifiable, and we have
Expand Down
1 change: 1 addition & 0 deletions editor/nsIHTMLEditor.idl
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ interface nsIHTMLEditor : nsISupports
* Paste the text in the OS clipboard at the cursor position, replacing
* the selected text (if any), but strip out any HTML styles and formatting
*/
[can_run_script]
void pasteNoFormatting(in long aSelectionType);

/**
Expand Down

0 comments on commit 9a4ba73

Please sign in to comment.