content/html/document/src/nsHTMLDocument.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial