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.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=2 sw=2 et tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef nsHTMLDocument_h___
7 #define nsHTMLDocument_h___
9 #include "mozilla/Attributes.h"
10 #include "nsDocument.h"
11 #include "nsIHTMLDocument.h"
12 #include "nsIDOMHTMLDocument.h"
13 #include "nsIDOMHTMLCollection.h"
14 #include "nsIScriptElement.h"
15 #include "nsTArray.h"
17 #include "pldhash.h"
18 #include "nsIHttpChannel.h"
19 #include "nsHTMLStyleSheet.h"
21 #include "nsICommandManager.h"
22 #include "mozilla/dom/HTMLSharedElement.h"
24 class nsIEditor;
25 class nsIParser;
26 class nsIURI;
27 class nsIMarkupDocumentViewer;
28 class nsIDocShell;
29 class nsICachingChannel;
30 class nsIWyciwygChannel;
31 class nsILoadGroup;
33 namespace mozilla {
34 namespace dom {
35 class HTMLAllCollection;
36 } // namespace dom
37 } // namespace mozilla
39 class nsHTMLDocument : public nsDocument,
40 public nsIHTMLDocument,
41 public nsIDOMHTMLDocument
42 {
43 public:
44 using nsDocument::SetDocumentURI;
45 using nsDocument::GetPlugins;
47 nsHTMLDocument();
48 ~nsHTMLDocument();
49 virtual nsresult Init() MOZ_OVERRIDE;
51 NS_DECL_ISUPPORTS_INHERITED
52 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsHTMLDocument, nsDocument)
54 // nsIDocument
55 virtual void Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup) MOZ_OVERRIDE;
56 virtual void ResetToURI(nsIURI* aURI, nsILoadGroup* aLoadGroup,
57 nsIPrincipal* aPrincipal) MOZ_OVERRIDE;
59 virtual already_AddRefed<nsIPresShell> CreateShell(nsPresContext* aContext,
60 nsViewManager* aViewManager,
61 nsStyleSet* aStyleSet) MOZ_OVERRIDE;
63 virtual nsresult StartDocumentLoad(const char* aCommand,
64 nsIChannel* aChannel,
65 nsILoadGroup* aLoadGroup,
66 nsISupports* aContainer,
67 nsIStreamListener **aDocListener,
68 bool aReset = true,
69 nsIContentSink* aSink = nullptr) MOZ_OVERRIDE;
70 virtual void StopDocumentLoad() MOZ_OVERRIDE;
72 virtual void BeginLoad() MOZ_OVERRIDE;
73 virtual void EndLoad() MOZ_OVERRIDE;
75 // nsIHTMLDocument
76 virtual void SetCompatibilityMode(nsCompatibility aMode) MOZ_OVERRIDE;
78 virtual bool IsWriting() MOZ_OVERRIDE
79 {
80 return mWriteLevel != uint32_t(0);
81 }
83 virtual NS_HIDDEN_(nsContentList*) GetForms();
85 virtual NS_HIDDEN_(nsContentList*) GetFormControls();
87 // nsIDOMDocument interface
88 using nsDocument::CreateElement;
89 using nsDocument::CreateElementNS;
90 NS_FORWARD_NSIDOMDOCUMENT(nsDocument::)
92 // And explicitly import the things from nsDocument that we just shadowed
93 using nsDocument::GetImplementation;
94 using nsDocument::GetTitle;
95 using nsDocument::SetTitle;
96 using nsDocument::GetLastStyleSheetSet;
97 using nsDocument::MozSetImageElement;
98 using nsDocument::GetMozFullScreenElement;
100 // nsIDOMNode interface
101 NS_FORWARD_NSIDOMNODE_TO_NSINODE
103 // nsIDOMHTMLDocument interface
104 NS_DECL_NSIDOMHTMLDOCUMENT
106 mozilla::dom::HTMLAllCollection* All();
107 void GetAll(JSContext* aCx, JS::MutableHandle<JSObject*> aRetval,
108 mozilla::ErrorResult& aRv);
110 nsISupports* ResolveName(const nsAString& aName, nsWrapperCache **aCache);
112 virtual void AddedForm() MOZ_OVERRIDE;
113 virtual void RemovedForm() MOZ_OVERRIDE;
114 virtual int32_t GetNumFormsSynchronous() MOZ_OVERRIDE;
115 virtual void TearingDownEditor(nsIEditor *aEditor) MOZ_OVERRIDE;
116 virtual void SetIsXHTML(bool aXHTML) MOZ_OVERRIDE { mIsRegularHTML = !aXHTML; }
117 virtual void SetDocWriteDisabled(bool aDisabled) MOZ_OVERRIDE
118 {
119 mDisableDocWrite = aDisabled;
120 }
122 nsresult ChangeContentEditableCount(nsIContent *aElement, int32_t aChange) MOZ_OVERRIDE;
123 void DeferredContentEditableCountChange(nsIContent *aElement);
125 virtual EditingState GetEditingState() MOZ_OVERRIDE
126 {
127 return mEditingState;
128 }
130 virtual void DisableCookieAccess() MOZ_OVERRIDE
131 {
132 mDisableCookieAccess = true;
133 }
135 class nsAutoEditingState {
136 public:
137 nsAutoEditingState(nsHTMLDocument* aDoc, EditingState aState)
138 : mDoc(aDoc), mSavedState(aDoc->mEditingState)
139 {
140 aDoc->mEditingState = aState;
141 }
142 ~nsAutoEditingState() {
143 mDoc->mEditingState = mSavedState;
144 }
145 private:
146 nsHTMLDocument* mDoc;
147 EditingState mSavedState;
148 };
149 friend class nsAutoEditingState;
151 void EndUpdate(nsUpdateType aUpdateType) MOZ_OVERRIDE;
153 virtual nsresult SetEditingState(EditingState aState) MOZ_OVERRIDE;
155 virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const MOZ_OVERRIDE;
157 virtual NS_HIDDEN_(void) RemovedFromDocShell() MOZ_OVERRIDE;
159 virtual mozilla::dom::Element *GetElementById(const nsAString& aElementId)
160 {
161 return nsDocument::GetElementById(aElementId);
162 }
164 virtual void DocAddSizeOfExcludingThis(nsWindowSizes* aWindowSizes) const MOZ_OVERRIDE;
165 // DocAddSizeOfIncludingThis is inherited from nsIDocument.
167 virtual bool WillIgnoreCharsetOverride() MOZ_OVERRIDE;
169 // WebIDL API
170 virtual JSObject* WrapNode(JSContext* aCx)
171 MOZ_OVERRIDE;
172 void GetDomain(nsAString& aDomain, mozilla::ErrorResult& rv);
173 void SetDomain(const nsAString& aDomain, mozilla::ErrorResult& rv);
174 void GetCookie(nsAString& aCookie, mozilla::ErrorResult& rv);
175 void SetCookie(const nsAString& aCookie, mozilla::ErrorResult& rv);
176 void NamedGetter(JSContext* cx, const nsAString& aName, bool& aFound,
177 JS::MutableHandle<JSObject*> aRetval,
178 mozilla::ErrorResult& rv);
179 bool NameIsEnumerable(const nsAString& aName);
180 void GetSupportedNames(unsigned, nsTArray<nsString>& aNames);
181 nsGenericHTMLElement *GetBody();
182 void SetBody(nsGenericHTMLElement* aBody, mozilla::ErrorResult& rv);
183 mozilla::dom::HTMLSharedElement *GetHead() {
184 return static_cast<mozilla::dom::HTMLSharedElement*>(GetHeadElement());
185 }
186 nsIHTMLCollection* Images();
187 nsIHTMLCollection* Embeds();
188 nsIHTMLCollection* Plugins();
189 nsIHTMLCollection* Links();
190 nsIHTMLCollection* Forms()
191 {
192 return nsHTMLDocument::GetForms();
193 }
194 nsIHTMLCollection* Scripts();
195 already_AddRefed<nsContentList> GetElementsByName(const nsAString & aName)
196 {
197 return NS_GetFuncStringNodeList(this, MatchNameAttribute, nullptr,
198 UseExistingNameString, aName);
199 }
200 already_AddRefed<nsINodeList> GetItems(const nsAString& aTypeNames);
201 already_AddRefed<nsIDocument> Open(JSContext* cx,
202 const nsAString& aType,
203 const nsAString& aReplace,
204 mozilla::ErrorResult& rv);
205 already_AddRefed<nsIDOMWindow> Open(JSContext* cx,
206 const nsAString& aURL,
207 const nsAString& aName,
208 const nsAString& aFeatures,
209 bool aReplace,
210 mozilla::ErrorResult& rv);
211 void Close(mozilla::ErrorResult& rv);
212 void Write(JSContext* cx, const mozilla::dom::Sequence<nsString>& aText,
213 mozilla::ErrorResult& rv);
214 void Writeln(JSContext* cx, const mozilla::dom::Sequence<nsString>& aText,
215 mozilla::ErrorResult& rv);
216 // The XPCOM GetDesignMode() works OK for us, since it never throws.
217 void SetDesignMode(const nsAString& aDesignMode, mozilla::ErrorResult& rv);
218 bool ExecCommand(const nsAString& aCommandID, bool aDoShowUI,
219 const nsAString& aValue, mozilla::ErrorResult& rv);
220 bool QueryCommandEnabled(const nsAString& aCommandID,
221 mozilla::ErrorResult& rv);
222 bool QueryCommandIndeterm(const nsAString& aCommandID,
223 mozilla::ErrorResult& rv);
224 bool QueryCommandState(const nsAString& aCommandID, mozilla::ErrorResult& rv);
225 bool QueryCommandSupported(const nsAString& aCommandID);
226 void QueryCommandValue(const nsAString& aCommandID, nsAString& aValue,
227 mozilla::ErrorResult& rv);
228 // The XPCOM Get/SetFgColor work OK for us, since they never throw.
229 // The XPCOM Get/SetLinkColor work OK for us, since they never throw.
230 // The XPCOM Get/SetVLinkColor work OK for us, since they never throw.
231 // The XPCOM Get/SetALinkColor work OK for us, since they never throw.
232 // The XPCOM Get/SetBgColor work OK for us, since they never throw.
233 nsIHTMLCollection* Anchors();
234 nsIHTMLCollection* Applets();
235 void Clear() const
236 {
237 // Deprecated
238 }
239 mozilla::dom::Selection* GetSelection(mozilla::ErrorResult& aRv);
240 // The XPCOM CaptureEvents works fine for us.
241 // The XPCOM ReleaseEvents works fine for us.
242 // We're picking up GetLocation from Document
243 already_AddRefed<nsIDOMLocation> GetLocation() const {
244 return nsIDocument::GetLocation();
245 }
247 virtual nsHTMLDocument* AsHTMLDocument() MOZ_OVERRIDE { return this; }
249 protected:
250 nsresult GetBodySize(int32_t* aWidth,
251 int32_t* aHeight);
253 nsIContent *MatchId(nsIContent *aContent, const nsAString& aId);
255 static bool MatchLinks(nsIContent *aContent, int32_t aNamespaceID,
256 nsIAtom* aAtom, void* aData);
257 static bool MatchAnchors(nsIContent *aContent, int32_t aNamespaceID,
258 nsIAtom* aAtom, void* aData);
259 static bool MatchNameAttribute(nsIContent* aContent, int32_t aNamespaceID,
260 nsIAtom* aAtom, void* aData);
261 static void* UseExistingNameString(nsINode* aRootNode, const nsString* aName);
263 static void DocumentWriteTerminationFunc(nsISupports *aRef);
265 already_AddRefed<nsIURI> GetDomainURI();
267 nsresult WriteCommon(JSContext *cx, const nsAString& aText,
268 bool aNewlineTerminate);
269 // A version of WriteCommon used by WebIDL bindings
270 void WriteCommon(JSContext *cx,
271 const mozilla::dom::Sequence<nsString>& aText,
272 bool aNewlineTerminate,
273 mozilla::ErrorResult& rv);
275 nsresult CreateAndAddWyciwygChannel(void);
276 nsresult RemoveWyciwygChannel(void);
278 /**
279 * Like IsEditingOn(), but will flush as needed first.
280 */
281 bool IsEditingOnAfterFlush();
283 void *GenerateParserKey(void);
285 nsRefPtr<nsContentList> mImages;
286 nsRefPtr<nsContentList> mApplets;
287 nsRefPtr<nsContentList> mEmbeds;
288 nsRefPtr<nsContentList> mLinks;
289 nsRefPtr<nsContentList> mAnchors;
290 nsRefPtr<nsContentList> mScripts;
291 nsRefPtr<nsContentList> mForms;
292 nsRefPtr<nsContentList> mFormControls;
294 nsRefPtr<mozilla::dom::HTMLAllCollection> mAll;
296 /** # of forms in the document, synchronously set */
297 int32_t mNumForms;
299 static uint32_t gWyciwygSessionCnt;
301 static void TryHintCharset(nsIMarkupDocumentViewer* aMarkupDV,
302 int32_t& aCharsetSource,
303 nsACString& aCharset);
304 void TryUserForcedCharset(nsIMarkupDocumentViewer* aMarkupDV,
305 nsIDocShell* aDocShell,
306 int32_t& aCharsetSource,
307 nsACString& aCharset);
308 static void TryCacheCharset(nsICachingChannel* aCachingChannel,
309 int32_t& aCharsetSource,
310 nsACString& aCharset);
311 void TryParentCharset(nsIDocShell* aDocShell,
312 int32_t& charsetSource, nsACString& aCharset);
313 void TryTLD(int32_t& aCharsetSource, nsACString& aCharset);
314 static void TryFallback(int32_t& aCharsetSource, nsACString& aCharset);
316 // Override so we can munge the charset on our wyciwyg channel as needed.
317 virtual void SetDocumentCharacterSet(const nsACString& aCharSetID) MOZ_OVERRIDE;
319 // Tracks if we are currently processing any document.write calls (either
320 // implicit or explicit). Note that if a write call writes out something which
321 // would block the parser, then mWriteLevel will be incorrect until the parser
322 // finishes processing that script.
323 uint32_t mWriteLevel;
325 // Load flags of the document's channel
326 uint32_t mLoadFlags;
328 bool mTooDeepWriteRecursion;
330 bool mDisableDocWrite;
332 bool mWarnedWidthHeight;
334 nsCOMPtr<nsIWyciwygChannel> mWyciwygChannel;
336 /* Midas implementation */
337 nsresult GetMidasCommandManager(nsICommandManager** aCommandManager);
339 nsCOMPtr<nsICommandManager> mMidasCommandManager;
341 nsresult TurnEditingOff();
342 nsresult EditingStateChanged();
343 void MaybeEditingStateChanged();
345 uint32_t mContentEditableCount;
346 EditingState mEditingState;
348 // When false, the .cookies property is completely disabled
349 bool mDisableCookieAccess;
351 /**
352 * Temporary flag that is set in EndUpdate() to ignore
353 * MaybeEditingStateChanged() script runners from a nested scope.
354 */
355 bool mPendingMaybeEditingStateChanged;
356 };
358 #define NS_HTML_DOCUMENT_INTERFACE_TABLE_BEGIN(_class) \
359 NS_DOCUMENT_INTERFACE_TABLE_BEGIN(_class) \
360 NS_INTERFACE_TABLE_ENTRY(_class, nsIHTMLDocument) \
361 NS_INTERFACE_TABLE_ENTRY(_class, nsIDOMHTMLDocument)
363 #endif /* nsHTMLDocument_h___ */