/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* 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/. */
// Make the content type default to "text/html", we are a HTML // document, after all. Once we start getting data, this may be // changed.
SetContentType(nsDependentCString("text/html"));
}
if (aCharsetSource >= kCharsetFromOtherComponent) { return;
}
// mCharacterSet not updated yet for channel, so check aEncoding, too. if (WillIgnoreCharsetOverride() || !IsAsciiCompatible(aEncoding)) { return;
}
if (aDocShell && nsDocShell::Cast(aDocShell)->GetForcedAutodetection()) { // This is the Character Encoding menu code path in Firefox
aForceAutoDetection = true;
}
}
int32_t parentSource; const Encoding* parentCharset;
nsCOMPtr<nsIPrincipal> parentPrincipal;
aDocShell->GetParentCharset(parentCharset, &parentSource,
getter_AddRefs(parentPrincipal)); if (!parentCharset) { return;
} if (kCharsetFromInitialUserForcedAutoDetection == parentSource ||
kCharsetFromFinalUserForcedAutoDetection == parentSource) { if (WillIgnoreCharsetOverride() ||
!IsAsciiCompatible(aEncoding) || // if channel said UTF-16
!IsAsciiCompatible(parentCharset)) { return;
}
aEncoding = WrapNotNull(parentCharset);
aCharsetSource = kCharsetFromParentFrame;
aForceAutoDetection = true; return;
}
if (aCharsetSource >= kCharsetFromParentFrame) { return;
}
if (kCharsetFromInitialAutoDetectionASCII <= parentSource) { // Make sure that's OK if (!NodePrincipal()->Equals(parentPrincipal) ||
!IsAsciiCompatible(parentCharset)) { return;
}
// Using a prototype document is only allowed with chrome privilege. bool ShouldUsePrototypeDocument(nsIChannel* aChannel, Document* aDoc) { if (!aChannel || !aDoc ||
!StaticPrefs::dom_prototype_document_cache_enabled()) { returnfalse;
} return nsContentUtils::IsChromeDoc(aDoc);
}
nsresult nsHTMLDocument::StartDocumentLoad( constchar* aCommand, nsIChannel* aChannel, nsILoadGroup* aLoadGroup,
nsISupports* aContainer, nsIStreamListener** aDocListener, bool aReset) { if (!aCommand) {
MOZ_ASSERT(false, "Command is mandatory"); return NS_ERROR_INVALID_POINTER;
} if (mType != eHTML) {
MOZ_ASSERT(mType == eXHTML);
MOZ_ASSERT(false, "Must not set HTML doc to XHTML mode before load start."); return NS_ERROR_DOM_INVALID_STATE_ERR;
}
// TODO: Proper about:blank treatment is bug 543435 if (loadAsHtml5 && view) { // mDocumentURI hasn't been set, yet, so get the URI from the channel
nsCOMPtr<nsIURI> uri;
aChannel->GetURI(getter_AddRefs(uri)); if (NS_IsAboutBlankAllowQueryAndFragment(uri)) {
loadAsHtml5 = false;
}
}
// Look for the parent document. Note that at this point we don't have our // content viewer set up yet, and therefore do not have a useful // mParentDocument.
// in this block of code, if we get an error result, we return it // but if we get a null pointer, that's perfectly legal for parent // and parentViewer
nsCOMPtr<nsIDocShellTreeItem> parentAsItem; if (docShell) {
docShell->GetInProcessSameTypeParent(getter_AddRefs(parentAsItem));
}
// These are the charset source and charset for our document bool forceAutoDetection = false;
int32_t charsetSource = kCharsetUninitialized; auto encoding = UTF_8_ENCODING;
// For error reporting and referrer policy setting
nsHtml5TreeOpExecutor* executor = nullptr; if (loadAsHtml5) {
executor = static_cast<nsHtml5TreeOpExecutor*>(mParser->GetContentSink());
}
// The following will try to get the character encoding from various // sources. Each Try* function will return early if the source is already // at least as large as any of the sources it might look at. Some of // these functions (like TryReloadCharset and TryParentCharset) can set // charsetSource to various values depending on where the charset they // end up finding originally comes from.
// Try the channel's charset (e.g., charset from HTTP // "Content-Type" header) first. This way, we get to reject overrides in // TryParentCharset and TryUserForcedCharset if the channel said UTF-16. // This is to avoid socially engineered XSS by adding user-supplied // content to a UTF-16 site such that the byte have a dangerous // interpretation as ASCII and the user can be lured to using the // charset menu.
TryChannelCharset(aChannel, charsetSource, encoding, executor);
// Set the parser as the stream listener for the document loader...
rv = NS_OK;
nsCOMPtr<nsIStreamListener> listener = mParser->GetStreamListener();
listener.forget(aDocListener);
// parser the content of the URI
mParser->Parse(uri);
return rv;
}
bool nsHTMLDocument::UseWidthDeviceWidthFallbackViewport() const { if (mIsPlainText) { // Plain text documents are simple enough that font inflation doesn't offer // any appreciable advantage over defaulting to "width=device-width" and // subsequently turning on word-wrapping. returntrue;
} return Document::UseWidthDeviceWidthFallbackViewport();
}
Element* nsHTMLDocument::GetUnfocusedKeyEventTarget() { if (nsGenericHTMLElement* body = GetBody()) { return body;
} return Document::GetUnfocusedKeyEventTarget();
}
nsBaseContentList* list = entry->GetNameContentList();
uint32_t length = list ? list->Length() : 0;
nsIContent* node; if (length > 0) { if (length > 1) { // The list contains more than one element, return the whole list. if (!ToJSValue(aCx, list, aRetval)) {
aError.NoteJSContextException(aCx); returnfalse;
} returntrue;
}
// Only one element in the list, return the element instead of returning // the list.
node = list->Item(0);
} else { // No named items were found, see if there's one registerd by id for aName.
Element* e = entry->GetIdElement();
if (!e || !nsGenericHTMLElement::ShouldExposeIdAsHTMLDocumentProperty(e)) { returnfalse;
}
node = e;
}
if (!ToJSValue(aCx, node, aRetval)) {
aError.NoteJSContextException(aCx); returnfalse;
}
returntrue;
}
void nsHTMLDocument::GetSupportedNames(nsTArray<nsString>& aNames) { for (constauto& entry : mIdentifierMap) { if (entry.HasNameElement() ||
entry.HasIdElementExposedAsHTMLDocumentProperty()) {
aNames.AppendElement(entry.GetKeyAsString());
}
}
}
// Measurement of the following members may be added later if DMD finds it is // worthwhile: // - mLinks // - mAnchors
}
bool nsHTMLDocument::WillIgnoreCharsetOverride() { if (mEncodingMenuDisabled) { returntrue;
} if (mType != eHTML) {
MOZ_ASSERT(mType == eXHTML); returntrue;
} if (mCharacterSetSource >= kCharsetFromByteOrderMark) { returntrue;
} if (!mCharacterSet->IsAsciiCompatible() &&
mCharacterSet != ISO_2022_JP_ENCODING) { returntrue;
}
nsIURI* uri = GetOriginalURI(); if (uri) { if (uri->SchemeIs("about")) { returntrue;
} bool isResource;
nsresult rv = NS_URIChainHasFlags(
uri, nsIProtocolHandler::URI_IS_UI_RESOURCE, &isResource); if (NS_FAILED(rv) || isResource) { returntrue;
}
}
switch (mCharacterSetSource) { case kCharsetUninitialized: case kCharsetFromFallback: case kCharsetFromDocTypeDefault: case kCharsetFromInitialAutoDetectionWouldHaveBeenUTF8: case kCharsetFromInitialAutoDetectionWouldNotHaveBeenUTF8DependedOnTLD: case kCharsetFromFinalAutoDetectionWouldHaveBeenUTF8InitialWasASCII: case kCharsetFromFinalAutoDetectionWouldNotHaveBeenUTF8DependedOnTLD: case kCharsetFromParentFrame: case kCharsetFromXmlDeclaration: case kCharsetFromMetaTag: case kCharsetFromChannel: returnfalse;
}
void nsHTMLDocument::GetFormsAndFormControls(nsContentList** aFormList,
nsContentList** aFormControlList) {
RefPtr<ContentListHolder> holder = mContentListHolder; if (!holder) { // Flush our content model so it'll be up to date // If this becomes unnecessary and the following line is removed, // please also remove the corresponding flush operation from // nsHtml5TreeBuilderCppSupplement.h. (Look for "See bug 497861." there.) // XXXsmaug nsHtml5TreeBuilderCppSupplement doesn't seem to have such flush // anymore.
FlushPendingNotifications(FlushType::Content);
RefPtr<nsContentList> htmlForms = GetExistingForms(); if (!htmlForms) { // If the document doesn't have an existing forms content list, create a // new one which will be released soon by ContentListHolder. The idea is // that we don't have that list hanging around for a long time and slowing // down future DOM mutations. // // Please keep this in sync with Document::Forms().
htmlForms = new nsContentList(this, kNameSpaceID_XHTML, nsGkAtoms::form,
nsGkAtoms::form, /* aDeep = */ true, /* aLiveList = */ true);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.