1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef nsEditingSession_h__
7 #define nsEditingSession_h__
9 #include "nsCOMPtr.h" // for nsCOMPtr
10 #include "nsISupportsImpl.h" // for NS_DECL_ISUPPORTS
11 #include "nsIWeakReferenceUtils.h" // for nsWeakPtr
12 #include "nsWeakReference.h" // for nsSupportsWeakReference, etc
13 #include "nscore.h" // for nsresult
15 #ifndef __gen_nsIWebProgressListener_h__
16 # include "nsIWebProgressListener.h"
19 #ifndef __gen_nsIEditingSession_h__
20 # include "nsIEditingSession.h" // for NS_DECL_NSIEDITINGSESSION, etc
23 #include "nsString.h" // for nsCString
25 class mozIDOMWindowProxy
;
26 class nsBaseCommandController
;
36 class ComposerCommandsUpdater
;
38 } // namespace mozilla
40 class nsEditingSession final
: public nsIEditingSession
,
41 public nsIWebProgressListener
,
42 public nsSupportsWeakReference
{
49 // nsIWebProgressListener
50 NS_DECL_NSIWEBPROGRESSLISTENER
53 NS_DECL_NSIEDITINGSESSION
56 * Removes all the editor's controllers/listeners etc and makes the window
59 nsresult
DetachFromWindow(nsPIDOMWindowOuter
* aWindow
);
62 * Undos DetachFromWindow(), reattaches this editing session/editor
65 nsresult
ReattachToWindow(nsPIDOMWindowOuter
* aWindow
);
68 virtual ~nsEditingSession();
70 typedef already_AddRefed
<nsBaseCommandController
> (*ControllerCreatorFn
)();
72 nsresult
SetupEditorCommandController(
73 ControllerCreatorFn aControllerCreatorFn
, mozIDOMWindowProxy
* aWindow
,
74 nsISupports
* aContext
, uint32_t* aControllerId
);
76 nsresult
SetContextOnControllerById(nsIControllers
* aControllers
,
77 nsISupports
* aContext
, uint32_t aID
);
80 * Set the editor on the controller(s) for this window
82 nsresult
SetEditorOnControllers(nsPIDOMWindowOuter
& aWindow
,
83 mozilla::HTMLEditor
* aEditor
);
86 * Setup editor and related support objects
88 MOZ_CAN_RUN_SCRIPT nsresult
SetupEditorOnWindow(nsPIDOMWindowOuter
& aWindow
);
90 nsresult
PrepareForEditing(nsPIDOMWindowOuter
* aWindow
);
92 static void TimerCallback(nsITimer
* aTimer
, void* aClosure
);
93 nsCOMPtr
<nsITimer
> mLoadBlankDocTimer
;
95 // progress load stuff
96 nsresult
StartDocumentLoad(nsIWebProgress
* aWebProgress
,
97 bool isToBeMadeEditable
);
98 MOZ_CAN_RUN_SCRIPT_BOUNDARY
99 nsresult
EndDocumentLoad(nsIWebProgress
* aWebProgress
, nsIChannel
* aChannel
,
100 nsresult aStatus
, bool isToBeMadeEditable
);
101 nsresult
StartPageLoad(nsIChannel
* aChannel
);
102 nsresult
EndPageLoad(nsIWebProgress
* aWebProgress
, nsIChannel
* aChannel
,
105 bool IsProgressForTargetDocument(nsIWebProgress
* aWebProgress
);
107 void RemoveEditorControllers(nsPIDOMWindowOuter
* aWindow
);
108 void RemoveWebProgressListener(nsPIDOMWindowOuter
* aWindow
);
109 void RestoreAnimationMode(nsPIDOMWindowOuter
* aWindow
);
110 void RemoveListenersAndControllers(nsPIDOMWindowOuter
* aWindow
,
111 mozilla::HTMLEditor
* aHTMLEditor
);
114 * Disable scripts and plugins in aDocShell.
116 nsresult
DisableJSAndPlugins(nsIDocShell
& aDocShell
);
119 * Restore JS and plugins (enable/disable them) according to the state they
120 * were before the last call to disableJSAndPlugins.
122 nsresult
RestoreJSAndPlugins(nsPIDOMWindowOuter
* aWindow
);
125 bool mDoneSetup
; // have we prepared for editing yet?
127 // Used to prevent double creation of editor because nsIWebProgressListener
128 // receives a STATE_STOP notification before the STATE_START
129 // for our document, so we wait for the STATE_START, then STATE_STOP
130 // before creating an editor
131 bool mCanCreateEditor
;
134 bool mMakeWholeDocumentEditable
;
136 bool mDisabledJSAndPlugins
;
138 // True if scripts were enabled before the editor turned scripts
139 // off, otherwise false.
140 bool mScriptsEnabled
;
142 // True if plugins were enabled before the editor turned plugins
143 // off, otherwise false.
144 bool mPluginsEnabled
;
146 bool mProgressListenerRegistered
;
148 // The image animation mode before it was turned off.
149 uint16_t mImageAnimationMode
;
151 // THE REMAINING MEMBER VARIABLES WILL BECOME A SET WHEN WE EDIT
152 // MORE THAN ONE EDITOR PER EDITING SESSION
153 RefPtr
<mozilla::ComposerCommandsUpdater
> mComposerCommandsUpdater
;
155 // Save the editor type so we can create the editor after loading uri
156 nsCString mEditorType
;
157 uint32_t mEditorFlags
;
158 uint32_t mEditorStatus
;
159 uint32_t mBaseCommandControllerId
;
160 uint32_t mDocStateControllerId
;
161 uint32_t mHTMLCommandControllerId
;
163 // Make sure the docshell we use is safe
166 // See if we can reuse an existing editor
167 nsWeakPtr mExistingEditor
;
170 #endif // nsEditingSession_h__