Skip to content

Commit

Permalink
Bug 1549925 - Mark all methods of nsIDocumentStateListener as can_run…
Browse files Browse the repository at this point in the history
…_script r=m_kato

`nsIDocumentStateListener` is a scriptable interface and each method may run
any script.  So, we should mark them as `can_run_script`.  Then, we need to
mark a lot of editing methods because we need to mark
`EditorBase::EndTransactionInternal()` and `EditorBase::DoTransactionInternal()`
as `MOZ_CAN_RUN_SCRIPT`.

Differential Revision: https://phabricator.services.mozilla.com/D30360
  • Loading branch information
masayuki-nakano committed May 9, 2019
1 parent f3218c9 commit 8074b96
Show file tree
Hide file tree
Showing 24 changed files with 207 additions and 149 deletions.
7 changes: 4 additions & 3 deletions docshell/base/nsDocShellEditorData.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ class nsDocShellEditorData {
explicit nsDocShellEditorData(nsIDocShell* aOwningDocShell);
~nsDocShellEditorData();

nsresult MakeEditable(bool aWaitForUriLoad);
MOZ_CAN_RUN_SCRIPT_BOUNDARY nsresult MakeEditable(bool aWaitForUriLoad);
bool GetEditable();
nsEditingSession* GetEditingSession();
mozilla::HTMLEditor* GetHTMLEditor() const { return mHTMLEditor; }
nsresult SetHTMLEditor(mozilla::HTMLEditor* aHTMLEditor);
void TearDownEditor();
MOZ_CAN_RUN_SCRIPT_BOUNDARY nsresult
SetHTMLEditor(mozilla::HTMLEditor* aHTMLEditor);
MOZ_CAN_RUN_SCRIPT_BOUNDARY void TearDownEditor();
nsresult DetachFromWindow();
nsresult ReattachToWindow(nsIDocShell* aDocShell);
bool WaitingForLoad() const { return mMakeEditable; }
Expand Down
7 changes: 5 additions & 2 deletions dom/base/nsFrameLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,11 @@ class nsFrameLoader final : public nsStubMutationObserver,
* Called from the layout frame associated with this frame loader;
* this notifies us to hook up with the widget and view.
*/
bool Show(int32_t marginWidth, int32_t marginHeight, int32_t scrollbarPrefX,
int32_t scrollbarPrefY, nsSubDocumentFrame* frame);
MOZ_CAN_RUN_SCRIPT_BOUNDARY bool Show(int32_t marginWidth,
int32_t marginHeight,
int32_t scrollbarPrefX,
int32_t scrollbarPrefY,
nsSubDocumentFrame* frame);

void MaybeShowFrame();

Expand Down
9 changes: 5 additions & 4 deletions dom/html/nsTextEditorState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1234,11 +1234,11 @@ nsresult nsTextEditorState::BindToFrame(nsTextControlFrame* aFrame) {
return NS_OK;
}

struct PreDestroyer {
struct MOZ_STACK_CLASS PreDestroyer {
void Init(TextEditor* aTextEditor) { mTextEditor = aTextEditor; }
~PreDestroyer() {
MOZ_CAN_RUN_SCRIPT ~PreDestroyer() {
if (mTextEditor) {
mTextEditor->PreDestroy(true);
MOZ_KnownLive(mTextEditor)->PreDestroy(true);
}
}
void Swap(RefPtr<TextEditor>& aTextEditor) {
Expand Down Expand Up @@ -1917,7 +1917,8 @@ HTMLInputElement* nsTextEditorState::GetParentNumberControl(
void nsTextEditorState::DestroyEditor() {
// notify the editor that we are going away
if (mEditorInitialized) {
mTextEditor->PreDestroy(true);
RefPtr<TextEditor> textEditor = mTextEditor;
textEditor->PreDestroy(true);
mEditorInitialized = false;
}
}
Expand Down
8 changes: 4 additions & 4 deletions dom/html/nsTextEditorState.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ class nsTextEditorState : public mozilla::SupportsWeakPtr<nsTextEditorState> {
explicit nsTextEditorState(nsITextControlElement* aOwningElement);
static nsTextEditorState* Construct(nsITextControlElement* aOwningElement,
nsTextEditorState** aReusedState);
~nsTextEditorState();
MOZ_CAN_RUN_SCRIPT_BOUNDARY ~nsTextEditorState();

void Traverse(nsCycleCollectionTraversalCallback& cb);
void Unlink();
MOZ_CAN_RUN_SCRIPT_BOUNDARY void Unlink();

void PrepareForReuse() {
Unlink();
Expand Down Expand Up @@ -377,8 +377,8 @@ class nsTextEditorState : public mozilla::SupportsWeakPtr<nsTextEditorState> {

void ValueWasChanged(bool aNotify);

void DestroyEditor();
void Clear();
MOZ_CAN_RUN_SCRIPT void DestroyEditor();
MOZ_CAN_RUN_SCRIPT void Clear();

nsresult InitializeRootNode();

Expand Down
3 changes: 2 additions & 1 deletion editor/composer/nsEditingSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,8 @@ nsEditingSession::SetupEditorOnWindow(mozIDOMWindowProxy* aWindow) {
NS_ENSURE_SUCCESS(rv, rv);

if (mEditorStatus != eEditorCreationInProgress) {
mComposerCommandsUpdater->NotifyDocumentCreated();
RefPtr<ComposerCommandsUpdater> updater = mComposerCommandsUpdater;
updater->NotifyDocumentCreated();
return NS_ERROR_FAILURE;
}

Expand Down
5 changes: 3 additions & 2 deletions editor/libeditor/CSSEditUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -812,8 +812,9 @@ int32_t CSSEditUtils::SetCSSEquivalentToHTMLStyle(Element* aElement,
// set the individual CSS inline styles
size_t count = cssPropertyArray.Length();
for (size_t index = 0; index < count; index++) {
nsresult rv = SetCSSProperty(*aElement, *cssPropertyArray[index],
cssValueArray[index], aSuppressTransaction);
nsresult rv =
SetCSSProperty(*aElement, MOZ_KnownLive(*cssPropertyArray[index]),
cssValueArray[index], aSuppressTransaction);
if (NS_WARN_IF(NS_FAILED(rv))) {
return 0;
}
Expand Down
26 changes: 14 additions & 12 deletions editor/libeditor/CSSEditUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,17 @@ class CSSEditUtils final {
* @param aSuppressTransaction [IN] A boolean indicating, when true,
* that no transaction should be recorded.
*/
nsresult SetCSSProperty(dom::Element& aElement, nsAtom& aProperty,
const nsAString& aValue, bool aSuppressTxn = false);
nsresult SetCSSPropertyPixels(dom::Element& aElement, nsAtom& aProperty,
int32_t aIntValue);
MOZ_CAN_RUN_SCRIPT
nsresult RemoveCSSProperty(dom::Element& aElement, nsAtom& aProperty,
const nsAString& aPropertyValue,
bool aSuppressTxn = false);
MOZ_CAN_RUN_SCRIPT nsresult SetCSSProperty(dom::Element& aElement,
nsAtom& aProperty,
const nsAString& aValue,
bool aSuppressTxn = false);
MOZ_CAN_RUN_SCRIPT nsresult SetCSSPropertyPixels(dom::Element& aElement,
nsAtom& aProperty,
int32_t aIntValue);
MOZ_CAN_RUN_SCRIPT nsresult RemoveCSSProperty(dom::Element& aElement,
nsAtom& aProperty,
const nsAString& aPropertyValue,
bool aSuppressTxn = false);

/**
* Gets the specified/computed style value of a CSS property for a given
Expand Down Expand Up @@ -244,10 +247,9 @@ class CSSEditUtils final {
*
* @return The number of CSS properties set by the call.
*/
int32_t SetCSSEquivalentToHTMLStyle(dom::Element* aElement, nsAtom* aProperty,
nsAtom* aAttribute,
const nsAString* aValue,
bool aSuppressTransaction);
MOZ_CAN_RUN_SCRIPT int32_t SetCSSEquivalentToHTMLStyle(
dom::Element* aElement, nsAtom* aProperty, nsAtom* aAttribute,
const nsAString* aValue, bool aSuppressTransaction);

/**
* Removes from the node the CSS inline styles equivalent to the HTML style.
Expand Down
8 changes: 5 additions & 3 deletions editor/libeditor/EditorBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,9 @@ nsresult EditorBase::DoTransactionInternal(nsITransaction* aTxn) {
MOZ_ASSERT(mSelState.isNothing());

// We will recurse, but will not hit this case in the nested call
DoTransactionInternal(mPlaceholderTransaction);
RefPtr<PlaceholderTransaction> placeholderTransaction =
mPlaceholderTransaction;
DoTransactionInternal(placeholderTransaction);

if (mTransactionManager) {
nsCOMPtr<nsITransaction> topTransaction =
Expand Down Expand Up @@ -3878,8 +3880,8 @@ void EditorBase::EndUpdateViewBatch() {
// to a document may result in multiple events, some of them quite hard
// to listen too (in particular when an ancestor of the selection is
// changed but the selection itself is not changed).
DebugOnly<nsresult> rv = htmlEditor->RefereshEditingUI();
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "RefereshEditingUI() failed");
DebugOnly<nsresult> rv = MOZ_KnownLive(htmlEditor)->RefreshEditingUI();
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "RefreshEditingUI() failed");
}

TextComposition* EditorBase::GetComposition() const { return mComposition; }
Expand Down
36 changes: 20 additions & 16 deletions editor/libeditor/EditorBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class EditorBase : public nsIEditor,
* PostCreate should be called after Init, and is the time that the editor
* tells its documentStateObservers that the document has been created.
*/
nsresult PostCreate();
MOZ_CAN_RUN_SCRIPT nsresult PostCreate();

/**
* PreDestroy is called before the editor goes away, and gives the editor a
Expand All @@ -189,7 +189,7 @@ class EditorBase : public nsIEditor,
* are being destroyed (so there is no need to modify any nsISelections,
* nor is it safe to do so)
*/
virtual void PreDestroy(bool aDestroyingFrames);
MOZ_CAN_RUN_SCRIPT virtual void PreDestroy(bool aDestroyingFrames);

bool IsInitialized() const { return !!mDocument; }
bool Destroyed() const { return mDidPreDestroy; }
Expand Down Expand Up @@ -1405,7 +1405,7 @@ class EditorBase : public nsIEditor,
EditorDOMPoint JoinNodesDeepWithTransaction(nsIContent& aLeftNode,
nsIContent& aRightNode);

nsresult DoTransactionInternal(nsITransaction* aTxn);
MOZ_CAN_RUN_SCRIPT nsresult DoTransactionInternal(nsITransaction* aTxn);

virtual bool IsBlockNode(nsINode* aNode);

Expand Down Expand Up @@ -1783,7 +1783,7 @@ class EditorBase : public nsIEditor,
void EndPlaceholderTransaction();

void BeginUpdateViewBatch();
void EndUpdateViewBatch();
MOZ_CAN_RUN_SCRIPT void EndUpdateViewBatch();

/**
* Used by AutoTransactionBatch. After calling BeginTransactionInternal(),
Expand All @@ -1793,7 +1793,7 @@ class EditorBase : public nsIEditor,
* use it instead?
*/
void BeginTransactionInternal();
void EndTransactionInternal();
MOZ_CAN_RUN_SCRIPT void EndTransactionInternal();

protected: // Shouldn't be used by friend classes
/**
Expand Down Expand Up @@ -1860,18 +1860,18 @@ class EditorBase : public nsIEditor,
/**
* Called after a transaction is done successfully.
*/
void DoAfterDoTransaction(nsITransaction* aTxn);
MOZ_CAN_RUN_SCRIPT void DoAfterDoTransaction(nsITransaction* aTxn);

/**
* Called after a transaction is undone successfully.
*/

void DoAfterUndoTransaction();
MOZ_CAN_RUN_SCRIPT void DoAfterUndoTransaction();

/**
* Called after a transaction is redone successfully.
*/
void DoAfterRedoTransaction();
MOZ_CAN_RUN_SCRIPT void DoAfterRedoTransaction();

/**
* Tell the doc state listeners that the doc state has changed.
Expand All @@ -1881,8 +1881,8 @@ class EditorBase : public nsIEditor,
eDocumentToBeDestroyed,
eDocumentStateChanged
};
nsresult NotifyDocumentListeners(
TDocumentListenerNotification aNotificationType);
MOZ_CAN_RUN_SCRIPT nsresult
NotifyDocumentListeners(TDocumentListenerNotification aNotificationType);

/**
* Make the given selection span the entire document.
Expand Down Expand Up @@ -2048,17 +2048,19 @@ class EditorBase : public nsIEditor,
*/
class MOZ_RAII AutoTransactionBatch final {
public:
explicit AutoTransactionBatch(
MOZ_CAN_RUN_SCRIPT explicit AutoTransactionBatch(
EditorBase& aEditorBase MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
: mEditorBase(aEditorBase) {
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
mEditorBase->BeginTransactionInternal();
mEditorBase.BeginTransactionInternal();
}

~AutoTransactionBatch() { mEditorBase->EndTransactionInternal(); }
MOZ_CAN_RUN_SCRIPT ~AutoTransactionBatch() {
MOZ_KnownLive(mEditorBase).EndTransactionInternal();
}

protected:
OwningNonNull<EditorBase> mEditorBase;
EditorBase& mEditorBase;
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
};

Expand Down Expand Up @@ -2185,14 +2187,16 @@ class EditorBase : public nsIEditor,
*/
class MOZ_RAII AutoUpdateViewBatch final {
public:
explicit AutoUpdateViewBatch(
MOZ_CAN_RUN_SCRIPT explicit AutoUpdateViewBatch(
EditorBase& aEditorBase MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
: mEditorBase(aEditorBase) {
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
mEditorBase.BeginUpdateViewBatch();
}

~AutoUpdateViewBatch() { mEditorBase.EndUpdateViewBatch(); }
MOZ_CAN_RUN_SCRIPT ~AutoUpdateViewBatch() {
MOZ_KnownLive(mEditorBase).EndUpdateViewBatch();
}

protected:
EditorBase& mEditorBase;
Expand Down
16 changes: 9 additions & 7 deletions editor/libeditor/EditorUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -406,19 +406,21 @@ class MOZ_STACK_CLASS SplitRangeOffFromNodeResult final {
* methods.
***************************************************************************/
class MOZ_RAII AutoTransactionBatchExternal final {
private:
OwningNonNull<EditorBase> mEditorBase;
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER

public:
explicit AutoTransactionBatchExternal(
MOZ_CAN_RUN_SCRIPT explicit AutoTransactionBatchExternal(
EditorBase& aEditorBase MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
: mEditorBase(aEditorBase) {
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
mEditorBase->BeginTransaction();
mEditorBase.BeginTransaction();
}

~AutoTransactionBatchExternal() { mEditorBase->EndTransaction(); }
MOZ_CAN_RUN_SCRIPT ~AutoTransactionBatchExternal() {
MOZ_KnownLive(mEditorBase).EndTransaction();
}

private:
EditorBase& mEditorBase;
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
};

class MOZ_STACK_CLASS AutoRangeArray final {
Expand Down
18 changes: 12 additions & 6 deletions editor/libeditor/HTMLAbsPositionEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,9 @@ nsresult HTMLEditor::RefreshGrabberInternal() {
return rv;
}

RefPtr<Element> grabber = mGrabber.get();
SetAnonymousElementPosition(mPositionedObjectX + 12, mPositionedObjectY - 14,
mGrabber);
grabber);
return NS_OK;
}

Expand Down Expand Up @@ -364,18 +365,23 @@ nsresult HTMLEditor::StartMoving() {
NS_WARN_IF(!mAbsolutelyPositionedObject)) {
return NS_ERROR_FAILURE;
}
RefPtr<Element> positioningShadow = mPositioningShadow.get();
RefPtr<Element> absolutelyPositionedObject = mAbsolutelyPositionedObject;
nsresult rv =
SetShadowPosition(*mPositioningShadow, *mAbsolutelyPositionedObject,
SetShadowPosition(*positioningShadow, *absolutelyPositionedObject,
mPositionedObjectX, mPositionedObjectY);
NS_ENSURE_SUCCESS(rv, rv);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}

// make the shadow appear
mPositioningShadow->UnsetAttr(kNameSpaceID_None, nsGkAtoms::_class, true);

// position it
mCSSEditUtils->SetCSSPropertyPixels(*mPositioningShadow, *nsGkAtoms::width,
positioningShadow = mPositioningShadow.get();
mCSSEditUtils->SetCSSPropertyPixels(*positioningShadow, *nsGkAtoms::width,
mPositionedObjectWidth);
mCSSEditUtils->SetCSSPropertyPixels(*mPositioningShadow, *nsGkAtoms::height,
mCSSEditUtils->SetCSSPropertyPixels(*positioningShadow, *nsGkAtoms::height,
mPositionedObjectHeight);

mIsMoving = true;
Expand Down Expand Up @@ -424,7 +430,7 @@ nsresult HTMLEditor::EndMoving() {

mGrabberClicked = false;
mIsMoving = false;
nsresult rv = RefereshEditingUI();
nsresult rv = RefreshEditingUI();
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
Expand Down
4 changes: 2 additions & 2 deletions editor/libeditor/HTMLAnonymousNodeEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,14 +314,14 @@ HTMLEditor::CheckSelectionStateForAnonymousButtons() {
return NS_ERROR_NOT_INITIALIZED;
}

nsresult rv = RefereshEditingUI();
nsresult rv = RefreshEditingUI();
if (NS_WARN_IF(NS_FAILED(rv))) {
return EditorBase::ToGenericNSResult(rv);
}
return NS_OK;
}

nsresult HTMLEditor::RefereshEditingUI() {
nsresult HTMLEditor::RefreshEditingUI() {
MOZ_ASSERT(IsEditActionDataAvailable());

// First, we need to remove unnecessary editing UI now since some of them
Expand Down
Loading

0 comments on commit 8074b96

Please sign in to comment.