Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #ifndef nsTextEditRules_h__ |
michael@0 | 7 | #define nsTextEditRules_h__ |
michael@0 | 8 | |
michael@0 | 9 | #include "nsCOMPtr.h" |
michael@0 | 10 | #include "nsCycleCollectionParticipant.h" |
michael@0 | 11 | #include "nsEditRules.h" |
michael@0 | 12 | #include "nsEditor.h" |
michael@0 | 13 | #include "nsIEditor.h" |
michael@0 | 14 | #include "nsISupportsImpl.h" |
michael@0 | 15 | #include "nsITimer.h" |
michael@0 | 16 | #include "nsPlaintextEditor.h" |
michael@0 | 17 | #include "nsString.h" |
michael@0 | 18 | #include "nscore.h" |
michael@0 | 19 | |
michael@0 | 20 | class nsIDOMElement; |
michael@0 | 21 | class nsIDOMNode; |
michael@0 | 22 | class nsISelection; |
michael@0 | 23 | namespace mozilla { |
michael@0 | 24 | namespace dom { |
michael@0 | 25 | class Selection; |
michael@0 | 26 | } // namespace dom |
michael@0 | 27 | } // namespace mozilla |
michael@0 | 28 | |
michael@0 | 29 | /** Object that encapsulates HTML text-specific editing rules. |
michael@0 | 30 | * |
michael@0 | 31 | * To be a good citizen, edit rules must live by these restrictions: |
michael@0 | 32 | * 1. All data manipulation is through the editor. |
michael@0 | 33 | * Content nodes in the document tree must <B>not</B> be manipulated directly. |
michael@0 | 34 | * Content nodes in document fragments that are not part of the document itself |
michael@0 | 35 | * may be manipulated at will. Operations on document fragments must <B>not</B> |
michael@0 | 36 | * go through the editor. |
michael@0 | 37 | * 2. Selection must not be explicitly set by the rule method. |
michael@0 | 38 | * Any manipulation of Selection must be done by the editor. |
michael@0 | 39 | */ |
michael@0 | 40 | class nsTextEditRules : public nsIEditRules, public nsITimerCallback |
michael@0 | 41 | { |
michael@0 | 42 | public: |
michael@0 | 43 | NS_DECL_NSITIMERCALLBACK |
michael@0 | 44 | NS_DECL_CYCLE_COLLECTING_ISUPPORTS |
michael@0 | 45 | NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsTextEditRules, nsIEditRules) |
michael@0 | 46 | |
michael@0 | 47 | nsTextEditRules(); |
michael@0 | 48 | virtual ~nsTextEditRules(); |
michael@0 | 49 | |
michael@0 | 50 | // nsIEditRules methods |
michael@0 | 51 | NS_IMETHOD Init(nsPlaintextEditor *aEditor); |
michael@0 | 52 | NS_IMETHOD SetInitialValue(const nsAString& aValue); |
michael@0 | 53 | NS_IMETHOD DetachEditor(); |
michael@0 | 54 | NS_IMETHOD BeforeEdit(EditAction action, |
michael@0 | 55 | nsIEditor::EDirection aDirection); |
michael@0 | 56 | NS_IMETHOD AfterEdit(EditAction action, |
michael@0 | 57 | nsIEditor::EDirection aDirection); |
michael@0 | 58 | NS_IMETHOD WillDoAction(mozilla::dom::Selection* aSelection, |
michael@0 | 59 | nsRulesInfo* aInfo, bool* aCancel, bool* aHandled); |
michael@0 | 60 | NS_IMETHOD DidDoAction(nsISelection *aSelection, nsRulesInfo *aInfo, nsresult aResult); |
michael@0 | 61 | NS_IMETHOD DocumentIsEmpty(bool *aDocumentIsEmpty); |
michael@0 | 62 | NS_IMETHOD DocumentModified(); |
michael@0 | 63 | |
michael@0 | 64 | public: |
michael@0 | 65 | void ResetIMETextPWBuf(); |
michael@0 | 66 | |
michael@0 | 67 | /** |
michael@0 | 68 | * Handles the newline characters either according to aNewLineHandling |
michael@0 | 69 | * or to the default system prefs if aNewLineHandling is negative. |
michael@0 | 70 | * |
michael@0 | 71 | * @param aString the string to be modified in place. |
michael@0 | 72 | * @param aNewLineHandling determine the desired type of newline handling: |
michael@0 | 73 | * * negative values: |
michael@0 | 74 | * handle newlines according to platform defaults. |
michael@0 | 75 | * * nsIPlaintextEditor::eNewlinesReplaceWithSpaces: |
michael@0 | 76 | * replace newlines with spaces. |
michael@0 | 77 | * * nsIPlaintextEditor::eNewlinesStrip: |
michael@0 | 78 | * remove newlines from the string. |
michael@0 | 79 | * * nsIPlaintextEditor::eNewlinesReplaceWithCommas: |
michael@0 | 80 | * replace newlines with commas. |
michael@0 | 81 | * * nsIPlaintextEditor::eNewlinesStripSurroundingWhitespace: |
michael@0 | 82 | * collapse newlines and surrounding whitespace characters and |
michael@0 | 83 | * remove them from the string. |
michael@0 | 84 | * * nsIPlaintextEditor::eNewlinesPasteIntact: |
michael@0 | 85 | * only remove the leading and trailing newlines. |
michael@0 | 86 | * * nsIPlaintextEditor::eNewlinesPasteToFirst or any other value: |
michael@0 | 87 | * remove the first newline and all characters following it. |
michael@0 | 88 | */ |
michael@0 | 89 | static void HandleNewLines(nsString &aString, int32_t aNewLineHandling); |
michael@0 | 90 | |
michael@0 | 91 | /** |
michael@0 | 92 | * Prepare a string buffer for being displayed as the contents of a password |
michael@0 | 93 | * field. This function uses the platform-specific character for representing |
michael@0 | 94 | * characters entered into password fields. |
michael@0 | 95 | * |
michael@0 | 96 | * @param aOutString the output string. When this function returns, |
michael@0 | 97 | * aOutString will contain aLength password characters. |
michael@0 | 98 | * @param aLength the number of password characters that aOutString should |
michael@0 | 99 | * contain. |
michael@0 | 100 | */ |
michael@0 | 101 | static void FillBufWithPWChars(nsAString *aOutString, int32_t aLength); |
michael@0 | 102 | |
michael@0 | 103 | protected: |
michael@0 | 104 | |
michael@0 | 105 | void InitFields(); |
michael@0 | 106 | |
michael@0 | 107 | // nsTextEditRules implementation methods |
michael@0 | 108 | nsresult WillInsertText( EditAction aAction, |
michael@0 | 109 | mozilla::dom::Selection* aSelection, |
michael@0 | 110 | bool *aCancel, |
michael@0 | 111 | bool *aHandled, |
michael@0 | 112 | const nsAString *inString, |
michael@0 | 113 | nsAString *outString, |
michael@0 | 114 | int32_t aMaxLength); |
michael@0 | 115 | nsresult DidInsertText(nsISelection *aSelection, nsresult aResult); |
michael@0 | 116 | nsresult GetTopEnclosingPre(nsIDOMNode *aNode, nsIDOMNode** aOutPreNode); |
michael@0 | 117 | |
michael@0 | 118 | nsresult WillInsertBreak(mozilla::dom::Selection* aSelection, bool* aCancel, |
michael@0 | 119 | bool *aHandled, int32_t aMaxLength); |
michael@0 | 120 | nsresult DidInsertBreak(nsISelection *aSelection, nsresult aResult); |
michael@0 | 121 | |
michael@0 | 122 | nsresult WillInsert(nsISelection *aSelection, bool *aCancel); |
michael@0 | 123 | nsresult DidInsert(nsISelection *aSelection, nsresult aResult); |
michael@0 | 124 | |
michael@0 | 125 | nsresult WillDeleteSelection(mozilla::dom::Selection* aSelection, |
michael@0 | 126 | nsIEditor::EDirection aCollapsedAction, |
michael@0 | 127 | bool *aCancel, |
michael@0 | 128 | bool *aHandled); |
michael@0 | 129 | nsresult DidDeleteSelection(nsISelection *aSelection, |
michael@0 | 130 | nsIEditor::EDirection aCollapsedAction, |
michael@0 | 131 | nsresult aResult); |
michael@0 | 132 | |
michael@0 | 133 | nsresult WillSetTextProperty(nsISelection *aSelection, bool *aCancel, bool *aHandled); |
michael@0 | 134 | nsresult DidSetTextProperty(nsISelection *aSelection, nsresult aResult); |
michael@0 | 135 | |
michael@0 | 136 | nsresult WillRemoveTextProperty(nsISelection *aSelection, bool *aCancel, bool *aHandled); |
michael@0 | 137 | nsresult DidRemoveTextProperty(nsISelection *aSelection, nsresult aResult); |
michael@0 | 138 | |
michael@0 | 139 | nsresult WillUndo(nsISelection *aSelection, bool *aCancel, bool *aHandled); |
michael@0 | 140 | nsresult DidUndo(nsISelection *aSelection, nsresult aResult); |
michael@0 | 141 | |
michael@0 | 142 | nsresult WillRedo(nsISelection *aSelection, bool *aCancel, bool *aHandled); |
michael@0 | 143 | nsresult DidRedo(nsISelection *aSelection, nsresult aResult); |
michael@0 | 144 | |
michael@0 | 145 | /** called prior to nsIEditor::OutputToString |
michael@0 | 146 | * @param aSelection |
michael@0 | 147 | * @param aInFormat the format requested for the output, a MIME type |
michael@0 | 148 | * @param aOutText the string to use for output, if aCancel is set to true |
michael@0 | 149 | * @param aOutCancel if set to true, the caller should cancel the operation |
michael@0 | 150 | * and use aOutText as the result. |
michael@0 | 151 | */ |
michael@0 | 152 | nsresult WillOutputText(nsISelection *aSelection, |
michael@0 | 153 | const nsAString *aInFormat, |
michael@0 | 154 | nsAString *aOutText, |
michael@0 | 155 | bool *aOutCancel, |
michael@0 | 156 | bool *aHandled); |
michael@0 | 157 | |
michael@0 | 158 | nsresult DidOutputText(nsISelection *aSelection, nsresult aResult); |
michael@0 | 159 | |
michael@0 | 160 | |
michael@0 | 161 | // helper functions |
michael@0 | 162 | |
michael@0 | 163 | /** check for and replace a redundant trailing break */ |
michael@0 | 164 | nsresult RemoveRedundantTrailingBR(); |
michael@0 | 165 | |
michael@0 | 166 | /** creates a trailing break in the text doc if there is not one already */ |
michael@0 | 167 | nsresult CreateTrailingBRIfNeeded(); |
michael@0 | 168 | |
michael@0 | 169 | /** creates a bogus text node if the document has no editable content */ |
michael@0 | 170 | nsresult CreateBogusNodeIfNeeded(nsISelection *aSelection); |
michael@0 | 171 | |
michael@0 | 172 | /** returns a truncated insertion string if insertion would place us |
michael@0 | 173 | over aMaxLength */ |
michael@0 | 174 | nsresult TruncateInsertionIfNeeded(mozilla::dom::Selection* aSelection, |
michael@0 | 175 | const nsAString *aInString, |
michael@0 | 176 | nsAString *aOutString, |
michael@0 | 177 | int32_t aMaxLength, |
michael@0 | 178 | bool *aTruncated); |
michael@0 | 179 | |
michael@0 | 180 | /** Remove IME composition text from password buffer */ |
michael@0 | 181 | void RemoveIMETextFromPWBuf(int32_t &aStart, nsAString *aIMEString); |
michael@0 | 182 | |
michael@0 | 183 | nsresult CreateMozBR(nsIDOMNode* inParent, int32_t inOffset, |
michael@0 | 184 | nsIDOMNode** outBRNode = nullptr); |
michael@0 | 185 | |
michael@0 | 186 | nsresult CheckBidiLevelForDeletion(nsISelection *aSelection, |
michael@0 | 187 | nsIDOMNode *aSelNode, |
michael@0 | 188 | int32_t aSelOffset, |
michael@0 | 189 | nsIEditor::EDirection aAction, |
michael@0 | 190 | bool *aCancel); |
michael@0 | 191 | |
michael@0 | 192 | nsresult HideLastPWInput(); |
michael@0 | 193 | |
michael@0 | 194 | nsresult CollapseSelectionToTrailingBRIfNeeded(nsISelection *aSelection); |
michael@0 | 195 | |
michael@0 | 196 | bool IsPasswordEditor() const |
michael@0 | 197 | { |
michael@0 | 198 | return mEditor ? mEditor->IsPasswordEditor() : false; |
michael@0 | 199 | } |
michael@0 | 200 | bool IsSingleLineEditor() const |
michael@0 | 201 | { |
michael@0 | 202 | return mEditor ? mEditor->IsSingleLineEditor() : false; |
michael@0 | 203 | } |
michael@0 | 204 | bool IsPlaintextEditor() const |
michael@0 | 205 | { |
michael@0 | 206 | return mEditor ? mEditor->IsPlaintextEditor() : false; |
michael@0 | 207 | } |
michael@0 | 208 | bool IsReadonly() const |
michael@0 | 209 | { |
michael@0 | 210 | return mEditor ? mEditor->IsReadonly() : false; |
michael@0 | 211 | } |
michael@0 | 212 | bool IsDisabled() const |
michael@0 | 213 | { |
michael@0 | 214 | return mEditor ? mEditor->IsDisabled() : false; |
michael@0 | 215 | } |
michael@0 | 216 | bool IsMailEditor() const |
michael@0 | 217 | { |
michael@0 | 218 | return mEditor ? mEditor->IsMailEditor() : false; |
michael@0 | 219 | } |
michael@0 | 220 | bool DontEchoPassword() const |
michael@0 | 221 | { |
michael@0 | 222 | return mEditor ? mEditor->DontEchoPassword() : false; |
michael@0 | 223 | } |
michael@0 | 224 | |
michael@0 | 225 | // data members |
michael@0 | 226 | nsPlaintextEditor *mEditor; // note that we do not refcount the editor |
michael@0 | 227 | nsString mPasswordText; // a buffer we use to store the real value of password editors |
michael@0 | 228 | nsString mPasswordIMEText; // a buffer we use to track the IME composition string |
michael@0 | 229 | uint32_t mPasswordIMEIndex; |
michael@0 | 230 | nsCOMPtr<nsIDOMNode> mBogusNode; // magic node acts as placeholder in empty doc |
michael@0 | 231 | nsCOMPtr<nsIDOMNode> mCachedSelectionNode; // cached selected node |
michael@0 | 232 | int32_t mCachedSelectionOffset; // cached selected offset |
michael@0 | 233 | uint32_t mActionNesting; |
michael@0 | 234 | bool mLockRulesSniffing; |
michael@0 | 235 | bool mDidExplicitlySetInterline; |
michael@0 | 236 | bool mDeleteBidiImmediately; // in bidirectional text, delete |
michael@0 | 237 | // characters not visually |
michael@0 | 238 | // adjacent to the caret without |
michael@0 | 239 | // moving the caret first. |
michael@0 | 240 | EditAction mTheAction; // the top level editor action |
michael@0 | 241 | nsCOMPtr<nsITimer> mTimer; |
michael@0 | 242 | uint32_t mLastStart, mLastLength; |
michael@0 | 243 | |
michael@0 | 244 | // friends |
michael@0 | 245 | friend class nsAutoLockRulesSniffing; |
michael@0 | 246 | |
michael@0 | 247 | }; |
michael@0 | 248 | |
michael@0 | 249 | |
michael@0 | 250 | |
michael@0 | 251 | class nsTextRulesInfo : public nsRulesInfo |
michael@0 | 252 | { |
michael@0 | 253 | public: |
michael@0 | 254 | |
michael@0 | 255 | nsTextRulesInfo(EditAction aAction) : |
michael@0 | 256 | nsRulesInfo(aAction), |
michael@0 | 257 | inString(0), |
michael@0 | 258 | outString(0), |
michael@0 | 259 | outputFormat(0), |
michael@0 | 260 | maxLength(-1), |
michael@0 | 261 | collapsedAction(nsIEditor::eNext), |
michael@0 | 262 | stripWrappers(nsIEditor::eStrip), |
michael@0 | 263 | bOrdered(false), |
michael@0 | 264 | entireList(false), |
michael@0 | 265 | bulletType(0), |
michael@0 | 266 | alignType(0), |
michael@0 | 267 | blockType(0), |
michael@0 | 268 | insertElement(0) |
michael@0 | 269 | {} |
michael@0 | 270 | |
michael@0 | 271 | virtual ~nsTextRulesInfo() {} |
michael@0 | 272 | |
michael@0 | 273 | // kInsertText |
michael@0 | 274 | const nsAString *inString; |
michael@0 | 275 | nsAString *outString; |
michael@0 | 276 | const nsAString *outputFormat; |
michael@0 | 277 | int32_t maxLength; |
michael@0 | 278 | |
michael@0 | 279 | // kDeleteSelection |
michael@0 | 280 | nsIEditor::EDirection collapsedAction; |
michael@0 | 281 | nsIEditor::EStripWrappers stripWrappers; |
michael@0 | 282 | |
michael@0 | 283 | // kMakeList |
michael@0 | 284 | bool bOrdered; |
michael@0 | 285 | bool entireList; |
michael@0 | 286 | const nsAString *bulletType; |
michael@0 | 287 | |
michael@0 | 288 | // kAlign |
michael@0 | 289 | const nsAString *alignType; |
michael@0 | 290 | |
michael@0 | 291 | // kMakeBasicBlock |
michael@0 | 292 | const nsAString *blockType; |
michael@0 | 293 | |
michael@0 | 294 | // kInsertElement |
michael@0 | 295 | const nsIDOMElement* insertElement; |
michael@0 | 296 | }; |
michael@0 | 297 | |
michael@0 | 298 | |
michael@0 | 299 | /*************************************************************************** |
michael@0 | 300 | * stack based helper class for StartOperation()/EndOperation() sandwich. |
michael@0 | 301 | * this class sets a bool letting us know to ignore any rules sniffing |
michael@0 | 302 | * that tries to occur reentrantly. |
michael@0 | 303 | */ |
michael@0 | 304 | class nsAutoLockRulesSniffing |
michael@0 | 305 | { |
michael@0 | 306 | public: |
michael@0 | 307 | |
michael@0 | 308 | nsAutoLockRulesSniffing(nsTextEditRules *rules) : mRules(rules) |
michael@0 | 309 | {if (mRules) mRules->mLockRulesSniffing = true;} |
michael@0 | 310 | ~nsAutoLockRulesSniffing() |
michael@0 | 311 | {if (mRules) mRules->mLockRulesSniffing = false;} |
michael@0 | 312 | |
michael@0 | 313 | protected: |
michael@0 | 314 | nsTextEditRules *mRules; |
michael@0 | 315 | }; |
michael@0 | 316 | |
michael@0 | 317 | |
michael@0 | 318 | |
michael@0 | 319 | /*************************************************************************** |
michael@0 | 320 | * stack based helper class for turning on/off the edit listener. |
michael@0 | 321 | */ |
michael@0 | 322 | class nsAutoLockListener |
michael@0 | 323 | { |
michael@0 | 324 | public: |
michael@0 | 325 | |
michael@0 | 326 | nsAutoLockListener(bool *enabled) : mEnabled(enabled) |
michael@0 | 327 | {if (mEnabled) { mOldState=*mEnabled; *mEnabled = false;}} |
michael@0 | 328 | ~nsAutoLockListener() |
michael@0 | 329 | {if (mEnabled) *mEnabled = mOldState;} |
michael@0 | 330 | |
michael@0 | 331 | protected: |
michael@0 | 332 | bool *mEnabled; |
michael@0 | 333 | bool mOldState; |
michael@0 | 334 | }; |
michael@0 | 335 | |
michael@0 | 336 | #endif //nsTextEditRules_h__ |