Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit ba8662d

Browse files
committed
Bug 1533250 - Remove *JSAndPlugins* methods from nsIEditingSession. r=masayuki
Firefox, comm-central and bluegriffon don't use `*JSAndPlugin*` methods of `nsIEditingSession` from script. Let's remove or move to `nsEditingSession`. Differential Revision: https://phabricator.services.mozilla.com/D22465 --HG-- extra : rebase_source : 256fb4025fe8c6f5a61d5b015af942ff65759c23
1 parent d348fe8 commit ba8662d

File tree

3 files changed

+26
-41
lines changed

3 files changed

+26
-41
lines changed

editor/composer/nsEditingSession.cpp

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ nsEditingSession::MakeWindowEditable(mozIDOMWindowProxy* aWindow,
126126

127127
nsresult rv;
128128
if (!mInteractive) {
129-
rv = DisableJSAndPlugins(aWindow);
129+
rv = DisableJSAndPlugins(*docShell);
130130
NS_ENSURE_SUCCESS(rv, rv);
131131
}
132132

@@ -178,42 +178,39 @@ nsEditingSession::MakeWindowEditable(mozIDOMWindowProxy* aWindow,
178178
return rv;
179179
}
180180

181-
NS_IMETHODIMP
182-
nsEditingSession::DisableJSAndPlugins(mozIDOMWindowProxy* aWindow) {
183-
NS_ENSURE_TRUE(aWindow, NS_ERROR_FAILURE);
184-
nsIDocShell* docShell = nsPIDOMWindowOuter::From(aWindow)->GetDocShell();
185-
NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
186-
181+
nsresult nsEditingSession::DisableJSAndPlugins(nsIDocShell& aDocShell) {
187182
bool tmp;
188-
nsresult rv = docShell->GetAllowJavascript(&tmp);
183+
nsresult rv = aDocShell.GetAllowJavascript(&tmp);
189184
NS_ENSURE_SUCCESS(rv, rv);
190185

191186
mScriptsEnabled = tmp;
192187

193-
rv = docShell->SetAllowJavascript(false);
188+
rv = aDocShell.SetAllowJavascript(false);
194189
NS_ENSURE_SUCCESS(rv, rv);
195190

196191
// Disable plugins in this document:
197-
mPluginsEnabled = docShell->PluginsAllowedInCurrentDoc();
192+
mPluginsEnabled = aDocShell.PluginsAllowedInCurrentDoc();
198193

199-
rv = docShell->SetAllowPlugins(false);
194+
rv = aDocShell.SetAllowPlugins(false);
200195
NS_ENSURE_SUCCESS(rv, rv);
201196

202197
mDisabledJSAndPlugins = true;
203198

204199
return NS_OK;
205200
}
206201

207-
NS_IMETHODIMP
208-
nsEditingSession::RestoreJSAndPlugins(mozIDOMWindowProxy* aWindow) {
202+
nsresult nsEditingSession::RestoreJSAndPlugins(nsPIDOMWindowOuter* aWindow) {
209203
if (!mDisabledJSAndPlugins) {
210204
return NS_OK;
211205
}
212206

213207
mDisabledJSAndPlugins = false;
214208

215-
NS_ENSURE_TRUE(aWindow, NS_ERROR_FAILURE);
216-
nsIDocShell* docShell = nsPIDOMWindowOuter::From(aWindow)->GetDocShell();
209+
if (NS_WARN_IF(!aWindow)) {
210+
// DetachFromWindow may call this method with nullptr.
211+
return NS_ERROR_FAILURE;
212+
}
213+
nsIDocShell* docShell = aWindow->GetDocShell();
217214
NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
218215

219216
nsresult rv = docShell->SetAllowJavascript(mScriptsEnabled);
@@ -223,13 +220,6 @@ nsEditingSession::RestoreJSAndPlugins(mozIDOMWindowProxy* aWindow) {
223220
return docShell->SetAllowPlugins(mPluginsEnabled);
224221
}
225222

226-
NS_IMETHODIMP
227-
nsEditingSession::GetJsAndPluginsDisabled(bool* aResult) {
228-
NS_ENSURE_ARG_POINTER(aResult);
229-
*aResult = mDisabledJSAndPlugins;
230-
return NS_OK;
231-
}
232-
233223
/*---------------------------------------------------------------------------
234224
235225
WindowIsEditable
@@ -541,7 +531,7 @@ nsEditingSession::TearDownEditorOnWindow(mozIDOMWindowProxy* aWindow) {
541531

542532
if (stopEditing) {
543533
// Make things the way they were before we started editing.
544-
RestoreJSAndPlugins(aWindow);
534+
RestoreJSAndPlugins(window);
545535
RestoreAnimationMode(window);
546536

547537
if (mMakeWholeDocumentEditable) {
@@ -1239,7 +1229,7 @@ nsresult nsEditingSession::DetachFromWindow(mozIDOMWindowProxy* aWindow) {
12391229
// make things the way they were before we started editing.
12401230
RemoveEditorControllers(window);
12411231
RemoveWebProgressListener(window);
1242-
RestoreJSAndPlugins(aWindow);
1232+
RestoreJSAndPlugins(window);
12431233
RestoreAnimationMode(window);
12441234

12451235
// Kill our weak reference to our original window, in case
@@ -1267,7 +1257,7 @@ nsresult nsEditingSession::ReattachToWindow(mozIDOMWindowProxy* aWindow) {
12671257

12681258
// Disable plugins.
12691259
if (!mInteractive) {
1270-
rv = DisableJSAndPlugins(aWindow);
1260+
rv = DisableJSAndPlugins(*docShell);
12711261
NS_ENSURE_SUCCESS(rv, rv);
12721262
}
12731263

editor/composer/nsEditingSession.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,17 @@ class nsEditingSession final : public nsIEditingSession,
8686
void RemoveListenersAndControllers(nsPIDOMWindowOuter* aWindow,
8787
mozilla::HTMLEditor* aHTMLEditor);
8888

89+
/**
90+
* Disable scripts and plugins in aDocShell.
91+
*/
92+
nsresult DisableJSAndPlugins(nsIDocShell& aDocShell);
93+
94+
/**
95+
* Restore JS and plugins (enable/disable them) according to the state they
96+
* were before the last call to disableJSAndPlugins.
97+
*/
98+
nsresult RestoreJSAndPlugins(nsPIDOMWindowOuter* aWindow);
99+
89100
protected:
90101
bool mDoneSetup; // have we prepared for editing yet?
91102

editor/composer/nsIEditingSession.idl

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,6 @@ interface nsIEditingSession : nsISupports
8080
void setEditorOnControllers(in mozIDOMWindowProxy aWindow,
8181
in nsIEditor aEditor);
8282

83-
/**
84-
* Disable scripts and plugins in aWindow.
85-
*/
86-
void disableJSAndPlugins(in mozIDOMWindowProxy aWindow);
87-
88-
/**
89-
* Restore JS and plugins (enable/disable them) according to the state they
90-
* were before the last call to disableJSAndPlugins.
91-
*/
92-
void restoreJSAndPlugins(in mozIDOMWindowProxy aWindow);
93-
9483
/**
9584
* Removes all the editor's controllers/listeners etc and makes the window
9685
* uneditable.
@@ -103,11 +92,6 @@ interface nsIEditingSession : nsISupports
10392
*/
10493
void reattachToWindow(in mozIDOMWindowProxy aWindow);
10594

106-
/**
107-
* Whether this session has disabled JS and plugins.
108-
*/
109-
readonly attribute boolean jsAndPluginsDisabled;
110-
11195
%{C++
11296
/**
11397
* This method is implemented with nsIDocShell::GetHTMLEditor(). I.e.,

0 commit comments

Comments
 (0)