gecko-dev/dom/html/nsHTMLDocument.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

373 строки
13 KiB
C
Исходник Обычный вид История

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
2012-05-21 15:12:37 +04:00
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
1998-04-14 00:24:54 +04:00
#ifndef nsHTMLDocument_h___
#define nsHTMLDocument_h___
#include "mozilla/Attributes.h"
#include "nsContentList.h"
#include "mozilla/dom/Document.h"
1998-04-14 00:24:54 +04:00
#include "nsIHTMLDocument.h"
#include "nsIHTMLCollection.h"
#include "nsIScriptElement.h"
#include "nsTArray.h"
#include "PLDHashTable.h"
#include "nsIHttpChannel.h"
#include "nsThreadUtils.h"
#include "mozilla/dom/HTMLSharedElement.h"
#include "mozilla/dom/BindingDeclarations.h"
class nsCommandManager;
class nsIURI;
class nsIDocShell;
class nsICachingChannel;
class nsILoadGroup;
1998-04-14 00:24:54 +04:00
namespace mozilla {
namespace dom {
class HTMLAllCollection;
template <typename T>
struct Nullable;
class WindowProxyHolder;
} // namespace dom
} // namespace mozilla
class nsHTMLDocument : public mozilla::dom::Document, public nsIHTMLDocument {
protected:
typedef mozilla::net::ReferrerPolicy ReferrerPolicy;
typedef mozilla::dom::Document Document;
typedef mozilla::Encoding Encoding;
template <typename T>
using NotNull = mozilla::NotNull<T>;
1998-04-14 00:24:54 +04:00
public:
using Document::GetPlugins;
using Document::SetDocumentURI;
nsHTMLDocument();
virtual nsresult Init() override;
1998-04-14 00:24:54 +04:00
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsHTMLDocument, Document)
// Document
virtual void Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup) override;
virtual void ResetToURI(nsIURI* aURI, nsILoadGroup* aLoadGroup,
nsIPrincipal* aPrincipal) override;
virtual nsresult StartDocumentLoad(const char* aCommand, nsIChannel* aChannel,
nsILoadGroup* aLoadGroup,
nsISupports* aContainer,
nsIStreamListener** aDocListener,
bool aReset = true,
nsIContentSink* aSink = nullptr) override;
1998-04-14 00:24:54 +04:00
virtual void BeginLoad() override;
virtual void EndLoad() override;
protected:
virtual bool UseWidthDeviceWidthFallbackViewport() const override;
public:
// nsIHTMLDocument
virtual void SetCompatibilityMode(nsCompatibility aMode) override;
1998-09-02 06:07:42 +04:00
virtual bool IsWriting() override { return mWriteLevel != uint32_t(0); }
virtual Element* GetUnfocusedKeyEventTarget() override;
nsContentList* GetExistingForms() const { return mForms; }
mozilla::dom::HTMLAllCollection* All();
// Returns whether an object was found for aName.
bool ResolveName(JSContext* aCx, const nsAString& aName,
JS::MutableHandle<JS::Value> aRetval,
mozilla::ErrorResult& aError);
virtual void AddedForm() override;
virtual void RemovedForm() override;
virtual int32_t GetNumFormsSynchronous() override;
virtual void TearingDownEditor() override;
virtual void SetIsXHTML(bool aXHTML) override {
mType = (aXHTML ? eXHTML : eHTML);
}
virtual void SetDocWriteDisabled(bool aDisabled) override {
mDisableDocWrite = aDisabled;
}
nsresult ChangeContentEditableCount(nsIContent* aElement,
int32_t aChange) override;
void DeferredContentEditableCountChange(nsIContent* aElement);
virtual EditingState GetEditingState() override { return mEditingState; }
virtual void DisableCookieAccess() override { mDisableCookieAccess = true; }
class nsAutoEditingState {
public:
nsAutoEditingState(nsHTMLDocument* aDoc, EditingState aState)
: mDoc(aDoc), mSavedState(aDoc->mEditingState) {
aDoc->mEditingState = aState;
}
~nsAutoEditingState() { mDoc->mEditingState = mSavedState; }
private:
nsHTMLDocument* mDoc;
EditingState mSavedState;
};
friend class nsAutoEditingState;
void EndUpdate() override;
virtual void SetMayStartLayout(bool aMayStartLayout) override;
virtual nsresult SetEditingState(EditingState aState) override;
virtual nsresult Clone(mozilla::dom::NodeInfo*,
nsINode** aResult) const override;
virtual void RemovedFromDocShell() override;
using mozilla::dom::DocumentOrShadowRoot::GetElementById;
virtual void DocAddSizeOfExcludingThis(
nsWindowSizes& aWindowSizes) const override;
// DocAddSizeOfIncludingThis is inherited from Document.
virtual bool WillIgnoreCharsetOverride() override;
// WebIDL API
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv The only manual changes here are to BindingUtils.h, BindingUtils.cpp, Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp, dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp, Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp, Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The rest of this diff was generated by running the following commands: find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g' find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g' find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g' find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g' find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g' find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
virtual JSObject* WrapNode(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) override;
void GetDomain(nsAString& aDomain);
void SetDomain(const nsAString& aDomain, mozilla::ErrorResult& rv);
bool IsRegistrableDomainSuffixOfOrEqualTo(const nsAString& aHostSuffixString,
const nsACString& aOrigHost);
void GetCookie(nsAString& aCookie, mozilla::ErrorResult& rv);
void SetCookie(const nsAString& aCookie, mozilla::ErrorResult& rv);
void NamedGetter(JSContext* cx, const nsAString& aName, bool& aFound,
JS::MutableHandle<JSObject*> aRetval,
mozilla::ErrorResult& rv) {
JS::Rooted<JS::Value> v(cx);
if ((aFound = ResolveName(cx, aName, &v, rv))) {
aRetval.set(v.toObjectOrNull());
}
}
void GetSupportedNames(nsTArray<nsString>& aNames);
Document* Open(const mozilla::dom::Optional<nsAString>& /* unused */,
Bug 1489308 part 5. Align the work we do on document.open with the spec. r=mccr8,smaug The main behavior changes are: 1) We no longer create a new Window when doing document.open(). We use the same Window but remove all the event listeners on it and on the existing DOM tree before removing the document's existing kids. 2) We no longer create a new session history entry. The existing one always gets replaced instead. 3) We now support document.open on documents that are not in a Window. The reasons for the various test changes are as follows: The change to browser_modifiedclick_inherit_principal.js is because we no longer set the docshell to a wyciwyg URL when document.open() happens and the test was depending on that to terminate. browser_wyciwyg_urlbarCopying.js is being removed because it's trying to test wyciwyg URIs, which no longer exist. The changes in docshell/test/navigation are because document.open() no longer affects session history. One of the tests was testing the interactions there and is being removed; another is being repurposed to just test that document.open() does not affect history.length. The change to test_x-frame-options.html is because document.open() now removes event listeners on the window, which it didn't use to do (and in the specific case in this test reused the existing inner too, so the listener was still around in practice). The new behavior matches other browsers. The removal of test_bug172261.html is because document.open() no longer affects session history, so you can't go back across it or forward to the "opened" state, so the situation that test is trying to test no longer exists. The changes to test_bug255820.html are because reloading a document after document.open() will now just load the URL of the document that was the entry document for the open() call, not reload the written content. So there's not much point testing reload behavior, and in this test it was just reloading the toplevel test file inside the frames. The change to test_bug346659.html is because now we no longer create a new Window on document.open(). The change to test_bug1232829.html is because document.open() (implicit in this test) no longer adds history entries, so the back() was just leaving the test page instead of going back across the document.open(). The test is a crashtest in practice, so might still be testing something useful about how document.open() interacts with animations. The change to test_bug715739.html is because the URL of the document after document.open() is now the URL of the entry document, not a wyciwyg URL, so reload() has different behavior than it used to. The change to test_bug329869.html is because now when we go back we're reloading the original document we had, not doing a wyciwyg load, and the security info now doesn't include the untrusted script. The changes to the wpt expectations are removing a bunch of expected failures now that we pass those tests and disabling some tests that are fundamentally racy and hence fail randomly. The latter all have github issues filed for the test problem. The change to testing/web-platform/tests/common/object-association.js is fixing tests that were not matching the spec (and were failing in other browsers). The change to parser-uses-registry-of-owner-document.html is fixing tests that were not matching the spec (and were failing in other browsers). The change to document-write.tentative.html is because the test was buggy: it was using the same iframe element for all its tests and racing loads from some tests against API calls from other tests, etc. It's a wonder it ever managed to pass, independent of these patches (and in fact it doesn't pass according to wpt.fyi data, even in Firefox). The changes in html/browsers/history/the-history-interface are because document.open() no longer adds history entries. The test was failing in all other browsers for the same reason. The changes in html/browsers/history/the-location-interface are because reloading a document.open()-created thing now loads the URL of the page that was the entry document for the open() call. The test was failing in all other browsers. The change to reload_document_open_write.html is because we now reload the url of the document that entered the script that called open() when we reload, not the written content. Other browsers were failing this test too; Gecko with the old document.open implementation was the only one that passed. The change to http-refresh.py is to fix a test bug: it was not returning a Content-Type header, so we were putting up helper app dialogs, etc. The change to test_ext_contentscript.js is because we no create a new global for document.open() calls. Kris Maglione OKed this part. Differential Revision: https://phabricator.services.mozilla.com/D17323 --HG-- extra : moz-landing-system : lando
2019-02-28 02:24:48 +03:00
const nsAString& /* unused */, mozilla::ErrorResult& aError);
mozilla::dom::Nullable<mozilla::dom::WindowProxyHolder> Open(
const nsAString& aURL, const nsAString& aName, const nsAString& aFeatures,
bool aReplace, mozilla::ErrorResult& rv);
void Close(mozilla::ErrorResult& rv);
void Write(const mozilla::dom::Sequence<nsString>& aText,
mozilla::ErrorResult& rv);
void Writeln(const mozilla::dom::Sequence<nsString>& aText,
mozilla::ErrorResult& rv);
void GetDesignMode(nsAString& aDesignMode);
void SetDesignMode(const nsAString& aDesignMode,
nsIPrincipal& aSubjectPrincipal, mozilla::ErrorResult& rv);
void SetDesignMode(const nsAString& aDesignMode,
const mozilla::Maybe<nsIPrincipal*>& aSubjectPrincipal,
mozilla::ErrorResult& rv);
MOZ_CAN_RUN_SCRIPT
bool ExecCommand(const nsAString& aCommandID, bool aDoShowUI,
const nsAString& aValue, nsIPrincipal& aSubjectPrincipal,
mozilla::ErrorResult& rv);
bool QueryCommandEnabled(const nsAString& aCommandID,
nsIPrincipal& aSubjectPrincipal,
mozilla::ErrorResult& rv);
bool QueryCommandIndeterm(const nsAString& aCommandID,
mozilla::ErrorResult& rv);
bool QueryCommandState(const nsAString& aCommandID, mozilla::ErrorResult& rv);
bool QueryCommandSupported(const nsAString& aCommandID,
mozilla::dom::CallerType aCallerType);
MOZ_CAN_RUN_SCRIPT
void QueryCommandValue(const nsAString& aCommandID, nsAString& aValue,
mozilla::ErrorResult& rv);
void GetFgColor(nsAString& aFgColor);
void SetFgColor(const nsAString& aFgColor);
void GetLinkColor(nsAString& aLinkColor);
void SetLinkColor(const nsAString& aLinkColor);
void GetVlinkColor(nsAString& aAvlinkColor);
void SetVlinkColor(const nsAString& aVlinkColor);
void GetAlinkColor(nsAString& aAlinkColor);
void SetAlinkColor(const nsAString& aAlinkColor);
void GetBgColor(nsAString& aBgColor);
void SetBgColor(const nsAString& aBgColor);
void Clear() const {
// Deprecated
}
void CaptureEvents();
void ReleaseEvents();
// We're picking up GetLocation from Document
already_AddRefed<mozilla::dom::Location> GetLocation() const {
return Document::GetLocation();
}
static bool MatchFormControls(Element* aElement, int32_t aNamespaceID,
nsAtom* aAtom, void* aData);
void GetFormsAndFormControls(nsContentList** aFormList,
nsContentList** aFormControlList);
void UserInteractionForTesting();
void SetKeyPressEventModel(uint16_t aKeyPressEventModel);
protected:
~nsHTMLDocument();
nsresult GetBodySize(int32_t* aWidth, int32_t* aHeight);
nsIContent* MatchId(nsIContent* aContent, const nsAString& aId);
static void DocumentWriteTerminationFunc(nsISupports* aRef);
already_AddRefed<nsIURI> GetDomainURI();
already_AddRefed<nsIURI> CreateInheritingURIForHost(
const nsACString& aHostString);
already_AddRefed<nsIURI> RegistrableDomainSuffixOfInternal(
const nsAString& aHostSuffixString, nsIURI* aOrigHost);
void WriteCommon(const nsAString& aText, bool aNewlineTerminate,
mozilla::ErrorResult& aRv);
// A version of WriteCommon used by WebIDL bindings
void WriteCommon(const mozilla::dom::Sequence<nsString>& aText,
bool aNewlineTerminate, mozilla::ErrorResult& rv);
// This should *ONLY* be used in GetCookie/SetCookie.
already_AddRefed<nsIChannel> CreateDummyChannelForCookies(
nsIURI* aCodebaseURI);
/**
* Like IsEditingOn(), but will flush as needed first.
*/
bool IsEditingOnAfterFlush();
void* GenerateParserKey(void);
// A helper class to keep nsContentList objects alive for a short period of
// time. Note, when the final Release is called on an nsContentList object, it
// removes itself from MutationObserver list.
class ContentListHolder : public mozilla::Runnable {
public:
ContentListHolder(nsHTMLDocument* aDocument, nsContentList* aFormList,
nsContentList* aFormControlList)
: mozilla::Runnable("ContentListHolder"),
mDocument(aDocument),
mFormList(aFormList),
mFormControlList(aFormControlList) {}
~ContentListHolder() {
MOZ_ASSERT(!mDocument->mContentListHolder ||
mDocument->mContentListHolder == this);
mDocument->mContentListHolder = nullptr;
}
RefPtr<nsHTMLDocument> mDocument;
RefPtr<nsContentList> mFormList;
RefPtr<nsContentList> mFormControlList;
};
friend class ContentListHolder;
ContentListHolder* mContentListHolder;
Bug 1207245 - part 6 - rename nsRefPtr<T> to RefPtr<T>; r=ehsan; a=Tomcat The bulk of this commit was generated with a script, executed at the top level of a typical source code checkout. The only non-machine-generated part was modifying MFBT's moz.build to reflect the new naming. CLOSED TREE makes big refactorings like this a piece of cake. # The main substitution. find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \ xargs perl -p -i -e ' s/nsRefPtr\.h/RefPtr\.h/g; # handle includes s/nsRefPtr ?</RefPtr</g; # handle declarations and variables ' # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h. perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h # Handle nsRefPtr.h itself, a couple places that define constructors # from nsRefPtr, and code generators specially. We do this here, rather # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename # things like nsRefPtrHashtable. perl -p -i -e 's/nsRefPtr/RefPtr/g' \ mfbt/nsRefPtr.h \ xpcom/glue/nsCOMPtr.h \ xpcom/base/OwningNonNull.h \ ipc/ipdl/ipdl/lower.py \ ipc/ipdl/ipdl/builtin.py \ dom/bindings/Codegen.py \ python/lldbutils/lldbutils/utils.py # In our indiscriminate substitution above, we renamed # nsRefPtrGetterAddRefs, the class behind getter_AddRefs. Fix that up. find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \ xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g' if [ -d .git ]; then git mv mfbt/nsRefPtr.h mfbt/RefPtr.h else hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h fi --HG-- rename : mfbt/nsRefPtr.h => mfbt/RefPtr.h
2015-10-18 08:24:48 +03:00
RefPtr<mozilla::dom::HTMLAllCollection> mAll;
/** # of forms in the document, synchronously set */
int32_t mNumForms;
static void TryHintCharset(nsIContentViewer* aContentViewer,
int32_t& aCharsetSource,
NotNull<const Encoding*>& aEncoding);
void TryUserForcedCharset(nsIContentViewer* aCv, nsIDocShell* aDocShell,
int32_t& aCharsetSource,
NotNull<const Encoding*>& aEncoding);
static void TryCacheCharset(nsICachingChannel* aCachingChannel,
int32_t& aCharsetSource,
NotNull<const Encoding*>& aEncoding);
void TryParentCharset(nsIDocShell* aDocShell, int32_t& charsetSource,
NotNull<const Encoding*>& aEncoding);
void TryTLD(int32_t& aCharsetSource, NotNull<const Encoding*>& aCharset);
static void TryFallback(int32_t& aCharsetSource,
NotNull<const Encoding*>& aEncoding);
/**
* MaybeDispatchCheckKeyPressEventModelEvent() dispatches
* "CheckKeyPressEventModel" event to check whether we should dispatch
* keypress events in confluent model or split model. This should be
* called only when mEditingState is changed to eDesignMode or
* eConentEditable at first time.
*/
void MaybeDispatchCheckKeyPressEventModelEvent();
// Tracks if we are currently processing any document.write calls (either
// implicit or explicit). Note that if a write call writes out something which
// would block the parser, then mWriteLevel will be incorrect until the parser
// finishes processing that script.
uint32_t mWriteLevel;
// Load flags of the document's channel
uint32_t mLoadFlags;
bool mTooDeepWriteRecursion;
bool mDisableDocWrite;
bool mWarnedWidthHeight;
/* Midas implementation */
nsCommandManager* GetMidasCommandManager();
RefPtr<nsCommandManager> mMidasCommandManager;
nsresult TurnEditingOff();
// MOZ_CAN_RUN_SCRIPT_BOUNDARY because this is called from all sorts
// of places, and I'm pretty sure the exact ExecCommand call it
// makes cannot actually run script.
MOZ_CAN_RUN_SCRIPT_BOUNDARY nsresult EditingStateChanged();
2009-01-31 15:53:01 +03:00
void MaybeEditingStateChanged();
uint32_t mContentEditableCount;
EditingState mEditingState;
// When false, the .cookies property is completely disabled
bool mDisableCookieAccess;
/**
* Temporary flag that is set in EndUpdate() to ignore
* MaybeEditingStateChanged() script runners from a nested scope.
*/
bool mPendingMaybeEditingStateChanged;
// mHasBeenEditable is set to true when mEditingState is firstly set to
// eDesignMode or eContentEditable.
bool mHasBeenEditable;
/**
* Set to true once we know that we are loading plain text content.
*/
bool mIsPlainText;
1998-04-14 00:24:54 +04:00
};
namespace mozilla {
namespace dom {
inline nsHTMLDocument* Document::AsHTMLDocument() {
MOZ_ASSERT(IsHTMLOrXHTML());
return static_cast<nsHTMLDocument*>(this);
}
} // namespace dom
} // namespace mozilla
#define NS_HTML_DOCUMENT_INTERFACE_TABLE_BEGIN(_class) \
NS_DOCUMENT_INTERFACE_TABLE_BEGIN(_class) \
NS_INTERFACE_TABLE_ENTRY(_class, nsIHTMLDocument)
1998-04-14 00:24:54 +04:00
#endif /* nsHTMLDocument_h___ */