Bug 1549925 - Mark all methods of nsIDocumentStateListener as can_run_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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Masayuki Nakano 2019-05-09 07:37:51 +00:00
Родитель d75677fa6d
Коммит 19fbb1a392
24 изменённых файлов: 207 добавлений и 149 удалений

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

@ -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; }

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

@ -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();

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

@ -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) {
@ -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;
}
}

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

@ -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();
@ -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();

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

@ -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;
}

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

@ -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;
}

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

@ -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
@ -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.

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

@ -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 =
@ -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; }

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

@ -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
@ -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; }
@ -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);
@ -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(),
@ -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
/**
@ -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.
@ -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.
@ -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
};
@ -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;

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

@ -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 {

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

@ -277,8 +277,9 @@ nsresult HTMLEditor::RefreshGrabberInternal() {
return rv;
}
RefPtr<Element> grabber = mGrabber.get();
SetAnonymousElementPosition(mPositionedObjectX + 12, mPositionedObjectY - 14,
mGrabber);
grabber);
return NS_OK;
}
@ -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;
@ -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;
}

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

@ -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

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

@ -6170,8 +6170,8 @@ nsresult HTMLEditRules::AlignContentsAtSelection(const nsAString& aAlignType) {
}
if (useCSS) {
HTMLEditorRef().mCSSEditUtils->SetCSSEquivalentToHTMLStyle(
curNode->AsElement(), nullptr, nsGkAtoms::align, &aAlignType,
false);
MOZ_KnownLive(curNode->AsElement()), nullptr, nsGkAtoms::align,
&aAlignType, false);
if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED;
}
@ -10466,7 +10466,8 @@ nsresult HTMLEditRules::ChangeMarginStart(Element& aElement, bool aIncrease) {
nsAtom& marginProperty = MarginPropertyAtomForIndent(aElement);
nsAutoString value;
CSSEditUtils::GetSpecifiedProperty(aElement, marginProperty, value);
CSSEditUtils::GetSpecifiedProperty(aElement, MOZ_KnownLive(marginProperty),
value);
if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED;
}
@ -10503,8 +10504,8 @@ nsresult HTMLEditRules::ChangeMarginStart(Element& aElement, bool aIncrease) {
nsAutoString newValue;
newValue.AppendFloat(f);
newValue.Append(nsDependentAtomString(unit));
HTMLEditorRef().mCSSEditUtils->SetCSSProperty(aElement, marginProperty,
newValue);
HTMLEditorRef().mCSSEditUtils->SetCSSProperty(
aElement, MOZ_KnownLive(marginProperty), newValue);
if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED;
}
@ -10938,8 +10939,8 @@ nsresult HTMLEditRules::WillRelativeChangeZIndex(int32_t aChange, bool* aCancel,
AutoSelectionRestorer restoreSelectionLater(HTMLEditorRef());
int32_t zIndex;
nsresult rv =
HTMLEditorRef().RelativeChangeElementZIndex(*element, aChange, &zIndex);
nsresult rv = MOZ_KnownLive(HTMLEditorRef())
.RelativeChangeElementZIndex(*element, aChange, &zIndex);
if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED;
}

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

@ -362,7 +362,7 @@ HTMLEditor::NotifySelectionChanged(Document* aDocument, Selection* aSelection,
typeInState->OnSelectionChange(*aSelection);
// We used a class which derived from nsISelectionListener to call
// HTMLEditor::RefereshEditingUI(). The lifetime of the class was
// HTMLEditor::RefreshEditingUI(). The lifetime of the class was
// exactly same as mTypeInState. So, call it only when mTypeInState
// is not nullptr.
if ((aReason & (nsISelectionListener::MOUSEDOWN_REASON |
@ -374,8 +374,8 @@ HTMLEditor::NotifySelectionChanged(Document* aDocument, Selection* aSelection,
// FYI: This is an XPCOM method. So, the caller, Selection, guarantees
// the lifetime of this instance. So, don't need to grab this with
// local variable.
DebugOnly<nsresult> rv = RefereshEditingUI();
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "RefereshEditingUI() failed");
DebugOnly<nsresult> rv = RefreshEditingUI();
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "RefreshEditingUI() failed");
}
}
@ -4380,9 +4380,9 @@ nsresult HTMLEditor::SetCSSBackgroundColorWithTransaction(
} else if (startNode == endNode &&
startNode->IsHTMLElement(nsGkAtoms::body) && isCollapsed) {
// No block in the document, let's apply the background to the body
mCSSEditUtils->SetCSSEquivalentToHTMLStyle(startNode->AsElement(),
nullptr, nsGkAtoms::bgcolor,
&aColor, false);
mCSSEditUtils->SetCSSEquivalentToHTMLStyle(
MOZ_KnownLive(startNode->AsElement()), nullptr, nsGkAtoms::bgcolor,
&aColor, false);
} else if (startNode == endNode && (endOffset - startOffset == 1 ||
(!startOffset && !endOffset))) {
// A unique node is selected, let's also apply the background color to

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

@ -121,7 +121,7 @@ class HTMLEditor final : public TextEditor,
nsHTMLDocument* GetHTMLDocument() const;
virtual void PreDestroy(bool aDestroyingFrames) override;
MOZ_CAN_RUN_SCRIPT virtual void PreDestroy(bool aDestroyingFrames) override;
bool GetReturnInParagraphCreatesNewParagraph();
@ -218,8 +218,9 @@ class HTMLEditor final : public TextEditor,
* @param aTarget [IN] the element triggering the event
* @param aMouseEvent [IN] the event
*/
nsresult OnMouseDown(int32_t aX, int32_t aY, Element* aTarget,
dom::Event* aMouseEvent);
MOZ_CAN_RUN_SCRIPT nsresult OnMouseDown(int32_t aX, int32_t aY,
Element* aTarget,
dom::Event* aMouseEvent);
/**
* event callback when a mouse button is released
@ -227,8 +228,8 @@ class HTMLEditor final : public TextEditor,
* @param aY [IN] vertical position of the pointer
* @param aTarget [IN] the element triggering the event
*/
MOZ_CAN_RUN_SCRIPT
nsresult OnMouseUp(int32_t aX, int32_t aY, Element* aTarget);
MOZ_CAN_RUN_SCRIPT nsresult OnMouseUp(int32_t aX, int32_t aY,
Element* aTarget);
/**
* event callback when the mouse pointer is moved
@ -251,7 +252,7 @@ class HTMLEditor final : public TextEditor,
* Enable/disable object resizers for <img> elements, <table> elements,
* absolute positioned elements (required absolute position editor enabled).
*/
void EnableObjectResizer(bool aEnable) {
MOZ_CAN_RUN_SCRIPT void EnableObjectResizer(bool aEnable) {
if (mIsObjectResizingEnabled == aEnable) {
return;
}
@ -263,7 +264,7 @@ class HTMLEditor final : public TextEditor,
}
mIsObjectResizingEnabled = aEnable;
RefereshEditingUI();
RefreshEditingUI();
}
bool IsObjectResizerEnabled() const { return mIsObjectResizingEnabled; }
@ -271,7 +272,7 @@ class HTMLEditor final : public TextEditor,
* Enable/disable inline table editor, e.g., adding new row or column,
* removing existing row or column.
*/
void EnableInlineTableEditor(bool aEnable) {
MOZ_CAN_RUN_SCRIPT void EnableInlineTableEditor(bool aEnable) {
if (mIsInlineTableEditingEnabled == aEnable) {
return;
}
@ -283,7 +284,7 @@ class HTMLEditor final : public TextEditor,
}
mIsInlineTableEditingEnabled = aEnable;
RefereshEditingUI();
RefreshEditingUI();
}
bool IsInlineTableEditorEnabled() const {
return mIsInlineTableEditingEnabled;
@ -294,7 +295,7 @@ class HTMLEditor final : public TextEditor,
* elements (required object resizers enabled) or positioning them with
* dragging grabber.
*/
void EnableAbsolutePositionEditor(bool aEnable) {
MOZ_CAN_RUN_SCRIPT void EnableAbsolutePositionEditor(bool aEnable) {
if (mIsAbsolutelyPositioningEnabled == aEnable) {
return;
}
@ -306,7 +307,7 @@ class HTMLEditor final : public TextEditor,
}
mIsAbsolutelyPositioningEnabled = aEnable;
RefereshEditingUI();
RefreshEditingUI();
}
bool IsAbsolutePositionEditorEnabled() const {
return mIsAbsolutelyPositioningEnabled;
@ -692,8 +693,9 @@ class HTMLEditor final : public TextEditor,
* the element
* @param aReturn [OUT] the new z-index of the element
*/
nsresult RelativeChangeElementZIndex(Element& aElement, int32_t aChange,
int32_t* aReturn);
MOZ_CAN_RUN_SCRIPT nsresult RelativeChangeElementZIndex(Element& aElement,
int32_t aChange,
int32_t* aReturn);
virtual bool IsBlockNode(nsINode* aNode) override;
using EditorBase::IsBlockNode;
@ -1545,6 +1547,7 @@ class HTMLEditor final : public TextEditor,
* This sets background on the appropriate container element (table, cell,)
* or calls into nsTextEditor to set the page background.
*/
MOZ_CAN_RUN_SCRIPT
nsresult SetCSSBackgroundColorWithTransaction(const nsAString& aColor);
MOZ_CAN_RUN_SCRIPT
nsresult SetHTMLBackgroundColorWithTransaction(const nsAString& aColor);
@ -2160,7 +2163,8 @@ class HTMLEditor final : public TextEditor,
* @param aX [IN] the x position in pixels.
* @param aY [IN] the y position in pixels.
*/
void SetTopAndLeft(Element& aElement, int32_t aX, int32_t aY);
MOZ_CAN_RUN_SCRIPT void SetTopAndLeft(Element& aElement, int32_t aX,
int32_t aY);
/**
* Reset a selected cell or collapsed selection (the caret) after table
@ -2193,11 +2197,11 @@ class HTMLEditor final : public TextEditor,
void DeleteRefToAnonymousNode(ManualNACPtr aContent, PresShell* aPresShell);
/**
* RefereshEditingUI() may refresh editing UIs for current Selection, focus,
* RefreshEditingUI() may refresh editing UIs for current Selection, focus,
* etc. If this shows or hides some UIs, it causes reflow. So, this is
* not safe method.
*/
nsresult RefereshEditingUI();
MOZ_CAN_RUN_SCRIPT nsresult RefreshEditingUI();
/**
* Returns the offset of an element's frame to its absolute containing block.
@ -2218,13 +2222,13 @@ class HTMLEditor final : public TextEditor,
* while this is running, this returns error. So, callers shouldn't
* keep handling the resizers if this returns error.
*/
nsresult SetAllResizersPosition();
MOZ_CAN_RUN_SCRIPT nsresult SetAllResizersPosition();
/**
* Shows active resizers around an element's frame
* @param aResizedElement [IN] a DOM Element
*/
nsresult ShowResizersInternal(Element& aResizedElement);
MOZ_CAN_RUN_SCRIPT nsresult ShowResizersInternal(Element& aResizedElement);
/**
* Hide resizers if they are visible. If this is called while there is no
@ -2236,10 +2240,11 @@ class HTMLEditor final : public TextEditor,
* RefreshResizersInternal() moves resizers to proper position. This does
* nothing if there is no resizing target.
*/
nsresult RefreshResizersInternal();
MOZ_CAN_RUN_SCRIPT nsresult RefreshResizersInternal();
ManualNACPtr CreateResizer(int16_t aLocation, nsIContent& aParentContent);
void SetAnonymousElementPosition(int32_t aX, int32_t aY, Element* aResizer);
MOZ_CAN_RUN_SCRIPT void SetAnonymousElementPosition(int32_t aX, int32_t aY,
Element* aResizer);
ManualNACPtr CreateShadow(nsIContent& aParentContent,
Element& aOriginalObject);
@ -2252,12 +2257,14 @@ class HTMLEditor final : public TextEditor,
* @param aElementX Left of aElement.
* @param aElementY Top of aElement.
*/
nsresult SetShadowPosition(Element& aShadowElement, Element& aElement,
int32_t aElementLeft, int32_t aElementTop);
MOZ_CAN_RUN_SCRIPT nsresult SetShadowPosition(Element& aShadowElement,
Element& aElement,
int32_t aElementLeft,
int32_t aElementTop);
ManualNACPtr CreateResizingInfo(nsIContent& aParentContent);
nsresult SetResizingInfoPosition(int32_t aX, int32_t aY, int32_t aW,
int32_t aH);
MOZ_CAN_RUN_SCRIPT nsresult SetResizingInfoPosition(int32_t aX, int32_t aY,
int32_t aW, int32_t aH);
enum class ResizeAt {
eX,
@ -2267,14 +2274,13 @@ class HTMLEditor final : public TextEditor,
};
int32_t GetNewResizingIncrement(int32_t aX, int32_t aY, ResizeAt aResizeAt);
nsresult StartResizing(Element* aHandle);
MOZ_CAN_RUN_SCRIPT nsresult StartResizing(Element* aHandle);
int32_t GetNewResizingX(int32_t aX, int32_t aY);
int32_t GetNewResizingY(int32_t aX, int32_t aY);
int32_t GetNewResizingWidth(int32_t aX, int32_t aY);
int32_t GetNewResizingHeight(int32_t aX, int32_t aY);
void HideShadowAndInfo();
MOZ_CAN_RUN_SCRIPT
void SetFinalSize(int32_t aX, int32_t aY);
MOZ_CAN_RUN_SCRIPT void SetFinalSize(int32_t aX, int32_t aY);
void SetResizeIncrements(int32_t aX, int32_t aY, int32_t aW, int32_t aH,
bool aPreserveRatio);
@ -2295,7 +2301,7 @@ class HTMLEditor final : public TextEditor,
* @param aElement [IN] the element
* @param aZorder [IN] the z-index
*/
void SetZIndex(Element& aElement, int32_t aZorder);
MOZ_CAN_RUN_SCRIPT void SetZIndex(Element& aElement, int32_t aZorder);
/**
* shows a grabber attached to an arbitrary element. The grabber is an image
@ -2304,7 +2310,7 @@ class HTMLEditor final : public TextEditor,
* document. See chrome://editor/content/images/grabber.gif
* @param aElement [IN] the element
*/
nsresult ShowGrabberInternal(Element& aElement);
MOZ_CAN_RUN_SCRIPT nsresult ShowGrabberInternal(Element& aElement);
/**
* Setting grabber to proper position for current mAbsolutelyPositionedObject.
@ -2312,7 +2318,7 @@ class HTMLEditor final : public TextEditor,
* or repositioned by script or something. Then, you need to reset grabber
* position with this.
*/
nsresult RefreshGrabberInternal();
MOZ_CAN_RUN_SCRIPT nsresult RefreshGrabberInternal();
/**
* hide the grabber if it shown.
@ -2327,12 +2333,12 @@ class HTMLEditor final : public TextEditor,
*/
bool CreateGrabberInternal(nsIContent& aParentContent);
nsresult StartMoving();
nsresult SetFinalPosition(int32_t aX, int32_t aY);
MOZ_CAN_RUN_SCRIPT nsresult StartMoving();
MOZ_CAN_RUN_SCRIPT nsresult SetFinalPosition(int32_t aX, int32_t aY);
void AddPositioningOffset(int32_t& aX, int32_t& aY);
void SnapToGrid(int32_t& newX, int32_t& newY);
nsresult GrabberClicked();
nsresult EndMoving();
MOZ_CAN_RUN_SCRIPT nsresult EndMoving();
nsresult GetTemporaryStyleForFocusedPositionedElement(Element& aElement,
nsAString& aReturn);
@ -2344,7 +2350,8 @@ class HTMLEditor final : public TextEditor,
*
* @param aCellElement Must be an <td> or <th> element.
*/
nsresult ShowInlineTableEditingUIInternal(Element& aCellElement);
MOZ_CAN_RUN_SCRIPT nsresult
ShowInlineTableEditingUIInternal(Element& aCellElement);
/**
* Hide all inline table editing UI.
@ -2356,7 +2363,7 @@ class HTMLEditor final : public TextEditor,
* proper position. This returns error if the UI is hidden or replaced
* during moving.
*/
nsresult RefreshInlineTableEditingUIInternal();
MOZ_CAN_RUN_SCRIPT nsresult RefreshInlineTableEditingUIInternal();
/**
* IsEmptyTextNode() returns true if aNode is a text node and does not have
@ -2364,12 +2371,13 @@ class HTMLEditor final : public TextEditor,
*/
bool IsEmptyTextNode(nsINode& aNode);
bool IsSimpleModifiableNode(nsIContent* aContent, nsAtom* aProperty,
nsAtom* aAttribute, const nsAString* aValue);
MOZ_CAN_RUN_SCRIPT
nsresult SetInlinePropertyOnNodeImpl(nsIContent& aNode, nsAtom& aProperty,
nsAtom* aAttribute,
const nsAString& aValue);
MOZ_CAN_RUN_SCRIPT bool IsSimpleModifiableNode(nsIContent* aContent,
nsAtom* aProperty,
nsAtom* aAttribute,
const nsAString* aValue);
MOZ_CAN_RUN_SCRIPT nsresult
SetInlinePropertyOnNodeImpl(nsIContent& aNode, nsAtom& aProperty,
nsAtom* aAttribute, const nsAString& aValue);
typedef enum { eInserted, eAppended } InsertedOrAppended;
void DoContentInserted(nsIContent* aChild, InsertedOrAppended);

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

@ -174,7 +174,7 @@ nsresult SetDocumentStateCommand::DoCommandParams(
if (NS_WARN_IF(error.Failed())) {
return error.StealNSResult();
}
htmlEditor->EnableObjectResizer(enabled);
MOZ_KnownLive(htmlEditor)->EnableObjectResizer(enabled);
return NS_OK;
}
case Command::ToggleInlineTableEditor: {
@ -187,7 +187,7 @@ nsresult SetDocumentStateCommand::DoCommandParams(
if (NS_WARN_IF(error.Failed())) {
return error.StealNSResult();
}
htmlEditor->EnableInlineTableEditor(enabled);
MOZ_KnownLive(htmlEditor)->EnableInlineTableEditor(enabled);
return NS_OK;
}
case Command::ToggleAbsolutePositionEditor: {
@ -200,7 +200,7 @@ nsresult SetDocumentStateCommand::DoCommandParams(
if (NS_WARN_IF(error.Failed())) {
return error.StealNSResult();
}
htmlEditor->EnableAbsolutePositionEditor(enabled);
MOZ_KnownLive(htmlEditor)->EnableAbsolutePositionEditor(enabled);
return NS_OK;
}
default:

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

@ -147,38 +147,45 @@ nsresult HTMLEditor::SetAllResizersPosition() {
// We're may be in hot path if user resizes an element a lot. So,
// we should just add-ref mTopLeftHandle.
RefPtr<Element> topLeftHandle = mTopLeftHandle.get();
SetAnonymousElementPosition(x - rw, y - rh, mTopLeftHandle);
SetAnonymousElementPosition(x - rw, y - rh, topLeftHandle);
if (NS_WARN_IF(topLeftHandle != mTopLeftHandle)) {
return NS_ERROR_FAILURE;
}
SetAnonymousElementPosition(x + w / 2 - rw, y - rh, mTopHandle);
RefPtr<Element> topHandle = mTopHandle.get();
SetAnonymousElementPosition(x + w / 2 - rw, y - rh, topHandle);
if (NS_WARN_IF(topLeftHandle != mTopLeftHandle)) {
return NS_ERROR_FAILURE;
}
SetAnonymousElementPosition(x + w - rw - 1, y - rh, mTopRightHandle);
RefPtr<Element> topRightHandle = mTopRightHandle.get();
SetAnonymousElementPosition(x + w - rw - 1, y - rh, topRightHandle);
if (NS_WARN_IF(topLeftHandle != mTopLeftHandle)) {
return NS_ERROR_FAILURE;
}
SetAnonymousElementPosition(x - rw, y + h / 2 - rh, mLeftHandle);
RefPtr<Element> leftHandle = mLeftHandle.get();
SetAnonymousElementPosition(x - rw, y + h / 2 - rh, leftHandle);
if (NS_WARN_IF(topLeftHandle != mTopLeftHandle)) {
return NS_ERROR_FAILURE;
}
SetAnonymousElementPosition(x + w - rw - 1, y + h / 2 - rh, mRightHandle);
RefPtr<Element> rightHandle = mRightHandle.get();
SetAnonymousElementPosition(x + w - rw - 1, y + h / 2 - rh, rightHandle);
if (NS_WARN_IF(topLeftHandle != mTopLeftHandle)) {
return NS_ERROR_FAILURE;
}
SetAnonymousElementPosition(x - rw, y + h - rh - 1, mBottomLeftHandle);
RefPtr<Element> bottomLeftHandle = mBottomLeftHandle.get();
SetAnonymousElementPosition(x - rw, y + h - rh - 1, bottomLeftHandle);
if (NS_WARN_IF(topLeftHandle != mTopLeftHandle)) {
return NS_ERROR_FAILURE;
}
SetAnonymousElementPosition(x + w / 2 - rw, y + h - rh - 1, mBottomHandle);
RefPtr<Element> bottomHandle = mBottomHandle.get();
SetAnonymousElementPosition(x + w / 2 - rw, y + h - rh - 1, bottomHandle);
if (NS_WARN_IF(topLeftHandle != mTopLeftHandle)) {
return NS_ERROR_FAILURE;
}
RefPtr<Element> bottomRightHandle = mBottomRightHandle.get();
SetAnonymousElementPosition(x + w - rw - 1, y + h - rh - 1,
mBottomRightHandle);
bottomRightHandle);
if (NS_WARN_IF(topLeftHandle != mTopLeftHandle)) {
return NS_ERROR_FAILURE;
}
@ -224,7 +231,9 @@ nsresult HTMLEditor::RefreshResizersInternal() {
MOZ_ASSERT(
mResizingShadow,
"SetAllResizersPosition() should return error if resizers are hidden");
rv = SetShadowPosition(*mResizingShadow, *mResizedObject, mResizedObjectX,
RefPtr<Element> resizingShadow = mResizingShadow.get();
RefPtr<Element> resizedObject = mResizedObject;
rv = SetShadowPosition(*resizingShadow, *resizedObject, mResizedObjectX,
mResizedObjectY);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
@ -379,7 +388,8 @@ nsresult HTMLEditor::ShowResizersInternal(Element& aResizedElement) {
mResizingShadow = std::move(newShadow);
// and set its position
rv = SetShadowPosition(*mResizingShadow, aResizedElement, mResizedObjectX,
RefPtr<Element> resizingShadow = mResizingShadow.get();
rv = SetShadowPosition(*resizingShadow, aResizedElement, mResizedObjectX,
mResizedObjectY);
if (NS_WARN_IF(NS_FAILED(rv))) {
if (NS_WARN_IF(mBottomRightHandle.get() != createdBottomRightNalde)) {
@ -587,9 +597,10 @@ nsresult HTMLEditor::StartResizing(Element* aHandle) {
mResizingShadow->UnsetAttr(kNameSpaceID_None, nsGkAtoms::_class, true);
// position it
mCSSEditUtils->SetCSSPropertyPixels(*mResizingShadow, *nsGkAtoms::width,
RefPtr<Element> resizingShadow = mResizingShadow.get();
mCSSEditUtils->SetCSSPropertyPixels(*resizingShadow, *nsGkAtoms::width,
mResizedObjectWidth);
mCSSEditUtils->SetCSSPropertyPixels(*mResizingShadow, *nsGkAtoms::height,
mCSSEditUtils->SetCSSPropertyPixels(*resizingShadow, *nsGkAtoms::height,
mResizedObjectHeight);
// add a mouse move listener to the editor
@ -725,9 +736,10 @@ nsresult HTMLEditor::SetResizingInfoPosition(int32_t aX, int32_t aY, int32_t aW,
// Offset info box by 20 so it's not directly under the mouse cursor.
const int mouseCursorOffset = 20;
mCSSEditUtils->SetCSSPropertyPixels(*mResizingInfo, *nsGkAtoms::left,
RefPtr<Element> resizingInfo = mResizingInfo.get();
mCSSEditUtils->SetCSSPropertyPixels(*resizingInfo, *nsGkAtoms::left,
infoXPosition + mouseCursorOffset);
mCSSEditUtils->SetCSSPropertyPixels(*mResizingInfo, *nsGkAtoms::top,
mCSSEditUtils->SetCSSPropertyPixels(*resizingInfo, *nsGkAtoms::top,
infoYPosition + mouseCursorOffset);
nsCOMPtr<nsIContent> textInfo = mResizingInfo->GetFirstChild();
@ -887,13 +899,13 @@ nsresult HTMLEditor::OnMouseMove(MouseEvent* aMouseEvent) {
int32_t newWidth = GetNewResizingWidth(clientX, clientY);
int32_t newHeight = GetNewResizingHeight(clientX, clientY);
mCSSEditUtils->SetCSSPropertyPixels(*mResizingShadow, *nsGkAtoms::left,
RefPtr<Element> resizingShadow = mResizingShadow.get();
mCSSEditUtils->SetCSSPropertyPixels(*resizingShadow, *nsGkAtoms::left,
newX);
mCSSEditUtils->SetCSSPropertyPixels(*mResizingShadow, *nsGkAtoms::top,
newY);
mCSSEditUtils->SetCSSPropertyPixels(*mResizingShadow, *nsGkAtoms::width,
mCSSEditUtils->SetCSSPropertyPixels(*resizingShadow, *nsGkAtoms::top, newY);
mCSSEditUtils->SetCSSPropertyPixels(*resizingShadow, *nsGkAtoms::width,
newWidth);
mCSSEditUtils->SetCSSPropertyPixels(*mResizingShadow, *nsGkAtoms::height,
mCSSEditUtils->SetCSSPropertyPixels(*resizingShadow, *nsGkAtoms::height,
newHeight);
return SetResizingInfoPosition(newX, newY, newWidth, newHeight);
@ -928,9 +940,10 @@ nsresult HTMLEditor::OnMouseMove(MouseEvent* aMouseEvent) {
SnapToGrid(newX, newY);
mCSSEditUtils->SetCSSPropertyPixels(*mPositioningShadow, *nsGkAtoms::left,
RefPtr<Element> positioningShadow = mPositioningShadow.get();
mCSSEditUtils->SetCSSPropertyPixels(*positioningShadow, *nsGkAtoms::left,
newX);
mCSSEditUtils->SetCSSPropertyPixels(*mPositioningShadow, *nsGkAtoms::top,
mCSSEditUtils->SetCSSPropertyPixels(*positioningShadow, *nsGkAtoms::top,
newY);
}
return NS_OK;
@ -992,11 +1005,11 @@ void HTMLEditor::SetFinalSize(int32_t aX, int32_t aY) {
}
if (setWidth) {
mCSSEditUtils->SetCSSPropertyPixels(*mResizedObject, *nsGkAtoms::width,
mCSSEditUtils->SetCSSPropertyPixels(*resizedObject, *nsGkAtoms::width,
width);
}
if (setHeight) {
mCSSEditUtils->SetCSSPropertyPixels(*mResizedObject, *nsGkAtoms::height,
mCSSEditUtils->SetCSSPropertyPixels(*resizedObject, *nsGkAtoms::height,
height);
}
} else {

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

@ -8,9 +8,10 @@
[scriptable, uuid(050cdc00-3b8e-11d3-9ce4-a458f454fcbc)]
interface nsIDocumentStateListener : nsISupports
{
void NotifyDocumentCreated();
void NotifyDocumentWillBeDestroyed();
void NotifyDocumentStateChanged(in boolean nowDirty);
[can_run_script]
void NotifyDocumentCreated();
[can_run_script]
void NotifyDocumentWillBeDestroyed();
[can_run_script]
void NotifyDocumentStateChanged(in boolean nowDirty);
};

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

@ -121,6 +121,7 @@ interface nsIEditor : nsISupports
/** to be used ONLY when we need to override the doc's modification
* state (such as when it's saved).
*/
[can_run_script]
void resetModificationCount();
/** Gets the modification count of the document we are editing.
@ -134,6 +135,7 @@ interface nsIEditor : nsISupports
* @param aModCount the number of modifications by which
* to increase or decrease the count
*/
[can_run_script]
void incrementModificationCount(in long aModCount);
/* ------------ Transaction methods -------------- */
@ -149,6 +151,7 @@ interface nsIEditor : nsISupports
*
* @param aTxn the transaction to execute
*/
[can_run_script]
void doTransaction(in nsITransaction txn);
@ -220,6 +223,7 @@ interface nsIEditor : nsISupports
* Calls to beginTransaction can be nested, as long as endTransaction
* is called once per beginTransaction.
*/
[can_run_script]
void endTransaction();
/**

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

@ -12,6 +12,7 @@ interface nsIHTMLAbsPosEditor : nsISupports
/**
* true if Absolute Positioning handling is enabled in the editor
*/
[can_run_script] // Setter only.
attribute boolean absolutePositioningEnabled;
@ -35,5 +36,6 @@ interface nsIHTMLAbsPosEditor : nsISupports
* even hiding it.
* FYI: Current user in script is only BlueGriffon.
*/
[can_run_script]
void refreshGrabber();
};

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

@ -413,6 +413,7 @@ interface nsIHTMLEditor : nsISupports
* editor (and/or its document/window) could be broken by mutation observers.
* FYI: Current user in script is only BlueGriffon.
*/
[can_run_script]
void checkSelectionStateForAnonymousButtons();
boolean isAnonymousElement(in Element aElement);

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

@ -15,6 +15,7 @@ interface nsIHTMLInlineTableEditor : nsISupports
* contained in a table cell, special buttons allowing to add/remove
* a line/column are available on the cell's border.
*/
[can_run_script] // Setter only.
attribute boolean inlineTableEditingEnabled;
/**
@ -24,6 +25,7 @@ interface nsIHTMLInlineTableEditor : nsISupports
* one while this is called, this throws an exception.
* FYI: Current user in script is only BlueGriffon.
*/
[can_run_script]
void refreshInlineTableEditingUI();
};

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

@ -26,6 +26,7 @@ interface nsIHTMLObjectResizer : nsISupports
/**
* a boolean indicating if object resizing is enabled in the editor
*/
[can_run_script] // Setter only.
attribute boolean objectResizingEnabled;
/**
@ -39,6 +40,7 @@ interface nsIHTMLObjectResizer : nsISupports
* you need to refresh position of resizers with calling this.
* FYI: Current user in script is only BlueGriffon.
*/
[can_run_script]
void refreshResizers();
};

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

@ -1089,9 +1089,10 @@ nsresult TextServicesDocument::InsertText(const nsAString& aText) {
// AutoTransactionBatchExternal grabs mTextEditor, so, we don't need to grab
// the instance with local variable here.
AutoTransactionBatchExternal treatAsOneTransaction(*mTextEditor);
RefPtr<TextEditor> textEditor = mTextEditor;
AutoTransactionBatchExternal treatAsOneTransaction(*textEditor);
nsresult rv = mTextEditor->InsertTextAsAction(aText);
nsresult rv = textEditor->InsertTextAsAction(aText);
if (NS_FAILED(rv)) {
return rv;
}