nsEditingSession.h (5345B)
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/. */ 5 6 #ifndef nsEditingSession_h__ 7 #define nsEditingSession_h__ 8 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 14 15 #ifndef __gen_nsIWebProgressListener_h__ 16 # include "nsIWebProgressListener.h" 17 #endif 18 19 #ifndef __gen_nsIEditingSession_h__ 20 # include "nsIEditingSession.h" // for NS_DECL_NSIEDITINGSESSION, etc 21 #endif 22 23 #include "nsString.h" // for nsCString 24 25 class mozIDOMWindowProxy; 26 class nsBaseCommandController; 27 class nsIDOMWindow; 28 class nsISupports; 29 class nsITimer; 30 class nsIChannel; 31 class nsIControllers; 32 class nsIDocShell; 33 class nsIWebProgress; 34 class nsIPIDOMWindowOuter; 35 class nsIPIDOMWindowInner; 36 37 namespace mozilla { 38 class ComposerCommandsUpdater; 39 class HTMLEditor; 40 } // namespace mozilla 41 42 class nsEditingSession final : public nsIEditingSession, 43 public nsIWebProgressListener, 44 public nsSupportsWeakReference { 45 public: 46 nsEditingSession(); 47 48 // nsISupports 49 NS_DECL_ISUPPORTS 50 51 // nsIWebProgressListener 52 NS_DECL_NSIWEBPROGRESSLISTENER 53 54 // nsIEditingSession 55 NS_DECL_NSIEDITINGSESSION 56 57 /** 58 * Removes all the editor's controllers/listeners etc and makes the window 59 * uneditable. 60 */ 61 nsresult DetachFromWindow(nsPIDOMWindowOuter* aWindow); 62 63 /** 64 * Undos DetachFromWindow(), reattaches this editing session/editor 65 * to the window. 66 */ 67 nsresult ReattachToWindow(nsPIDOMWindowOuter* aWindow); 68 69 protected: 70 virtual ~nsEditingSession(); 71 72 typedef already_AddRefed<nsBaseCommandController> (*ControllerCreatorFn)(); 73 74 nsresult SetupEditorCommandController( 75 ControllerCreatorFn aControllerCreatorFn, mozIDOMWindowProxy* aWindow, 76 nsISupportsWeakReference* aContext, uint32_t* aControllerId); 77 78 nsresult SetContextOnControllerById(nsIControllers* aControllers, 79 nsISupportsWeakReference* aContext, 80 uint32_t aID); 81 82 /** 83 * Set the editor on the controller(s) for this window 84 */ 85 nsresult SetEditorOnControllers(nsPIDOMWindowOuter& aWindow, 86 mozilla::HTMLEditor* aEditor); 87 88 /** 89 * Setup editor and related support objects 90 */ 91 MOZ_CAN_RUN_SCRIPT nsresult SetupEditorOnWindow(nsPIDOMWindowOuter& aWindow); 92 93 nsresult PrepareForEditing(nsPIDOMWindowOuter* aWindow); 94 95 static void TimerCallback(nsITimer* aTimer, void* aClosure); 96 nsCOMPtr<nsITimer> mLoadBlankDocTimer; 97 98 // progress load stuff 99 nsresult StartDocumentLoad(nsIWebProgress* aWebProgress, 100 bool isToBeMadeEditable); 101 MOZ_CAN_RUN_SCRIPT_BOUNDARY 102 nsresult EndDocumentLoad(nsIWebProgress* aWebProgress, nsIChannel* aChannel, 103 nsresult aStatus, bool isToBeMadeEditable); 104 nsresult StartPageLoad(nsIChannel* aChannel); 105 nsresult EndPageLoad(nsIWebProgress* aWebProgress, nsIChannel* aChannel, 106 nsresult aStatus); 107 108 bool IsProgressForTargetDocument(nsIWebProgress* aWebProgress); 109 110 void RemoveEditorControllers(nsPIDOMWindowOuter* aWindow); 111 void RemoveWebProgressListener(nsPIDOMWindowOuter* aWindow); 112 void RestoreAnimationMode(nsPIDOMWindowOuter* aWindow); 113 void RemoveListenersAndControllers(nsPIDOMWindowOuter* aWindow, 114 mozilla::HTMLEditor* aHTMLEditor); 115 116 /** 117 * Disable scripts in aDocShell. 118 */ 119 nsresult DisableJS(nsPIDOMWindowInner* aWindow); 120 121 /** 122 * Restore JS (enable/disable) according to the state it 123 * was before the last call to DisableJS. 124 */ 125 nsresult RestoreJS(nsPIDOMWindowInner* aWindow); 126 127 protected: 128 bool mDoneSetup; // have we prepared for editing yet? 129 130 // Used to prevent double creation of editor because nsIWebProgressListener 131 // receives a STATE_STOP notification before the STATE_START 132 // for our document, so we wait for the STATE_START, then STATE_STOP 133 // before creating an editor 134 bool mCanCreateEditor; 135 136 bool mInteractive; 137 bool mMakeWholeDocumentEditable; 138 139 bool mDisabledJS; 140 141 // True if scripts were enabled before the editor turned scripts 142 // off, otherwise false. 143 bool mScriptsEnabled; 144 145 bool mProgressListenerRegistered; 146 147 // The image animation mode before it was turned off. 148 uint16_t mImageAnimationMode; 149 150 // THE REMAINING MEMBER VARIABLES WILL BECOME A SET WHEN WE EDIT 151 // MORE THAN ONE EDITOR PER EDITING SESSION 152 RefPtr<mozilla::ComposerCommandsUpdater> mComposerCommandsUpdater; 153 154 // Save the editor type so we can create the editor after loading uri 155 nsCString mEditorType; 156 uint32_t mEditorFlags; 157 uint32_t mEditorStatus; 158 uint32_t mBaseCommandControllerId; 159 uint32_t mDocStateControllerId; 160 uint32_t mHTMLCommandControllerId; 161 162 // Make sure the docshell we use is safe 163 nsWeakPtr mDocShell; 164 165 // See if we can reuse an existing editor 166 nsWeakPtr mExistingEditor; 167 }; 168 169 #endif // nsEditingSession_h__