parser/html/nsHtml5DocumentBuilder.cpp

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=78: */
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
michael@0 7 #include "nsHtml5DocumentBuilder.h"
michael@0 8
michael@0 9 #include "nsIStyleSheetLinkingElement.h"
michael@0 10 #include "nsStyleLinkElement.h"
michael@0 11 #include "nsScriptLoader.h"
michael@0 12 #include "nsIHTMLDocument.h"
michael@0 13
michael@0 14 NS_IMPL_CYCLE_COLLECTION_INHERITED(nsHtml5DocumentBuilder, nsContentSink,
michael@0 15 mOwnedElements)
michael@0 16
michael@0 17 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsHtml5DocumentBuilder)
michael@0 18 NS_INTERFACE_MAP_END_INHERITING(nsContentSink)
michael@0 19
michael@0 20 NS_IMPL_ADDREF_INHERITED(nsHtml5DocumentBuilder, nsContentSink)
michael@0 21 NS_IMPL_RELEASE_INHERITED(nsHtml5DocumentBuilder, nsContentSink)
michael@0 22
michael@0 23 nsHtml5DocumentBuilder::nsHtml5DocumentBuilder(bool aRunsToCompletion)
michael@0 24 {
michael@0 25 mRunsToCompletion = aRunsToCompletion;
michael@0 26 }
michael@0 27
michael@0 28 nsresult
michael@0 29 nsHtml5DocumentBuilder::Init(nsIDocument* aDoc,
michael@0 30 nsIURI* aURI,
michael@0 31 nsISupports* aContainer,
michael@0 32 nsIChannel* aChannel)
michael@0 33 {
michael@0 34 return nsContentSink::Init(aDoc, aURI, aContainer, aChannel);
michael@0 35 }
michael@0 36
michael@0 37 nsHtml5DocumentBuilder::~nsHtml5DocumentBuilder()
michael@0 38 {
michael@0 39 }
michael@0 40
michael@0 41 nsresult
michael@0 42 nsHtml5DocumentBuilder::MarkAsBroken(nsresult aReason)
michael@0 43 {
michael@0 44 mBroken = aReason;
michael@0 45 return aReason;
michael@0 46 }
michael@0 47
michael@0 48 void
michael@0 49 nsHtml5DocumentBuilder::SetDocumentCharsetAndSource(nsACString& aCharset, int32_t aCharsetSource)
michael@0 50 {
michael@0 51 if (mDocument) {
michael@0 52 mDocument->SetDocumentCharacterSetSource(aCharsetSource);
michael@0 53 mDocument->SetDocumentCharacterSet(aCharset);
michael@0 54 }
michael@0 55 }
michael@0 56
michael@0 57 void
michael@0 58 nsHtml5DocumentBuilder::UpdateStyleSheet(nsIContent* aElement)
michael@0 59 {
michael@0 60 // Break out of the doc update created by Flush() to zap a runnable
michael@0 61 // waiting to call UpdateStyleSheet without the right observer
michael@0 62 EndDocUpdate();
michael@0 63
michael@0 64 if (MOZ_UNLIKELY(!mParser)) {
michael@0 65 // EndDocUpdate ran stuff that called nsIParser::Terminate()
michael@0 66 return;
michael@0 67 }
michael@0 68
michael@0 69 nsCOMPtr<nsIStyleSheetLinkingElement> ssle(do_QueryInterface(aElement));
michael@0 70 NS_ASSERTION(ssle, "Node didn't QI to style.");
michael@0 71
michael@0 72 ssle->SetEnableUpdates(true);
michael@0 73
michael@0 74 bool willNotify;
michael@0 75 bool isAlternate;
michael@0 76 nsresult rv = ssle->UpdateStyleSheet(mRunsToCompletion ? nullptr : this,
michael@0 77 &willNotify,
michael@0 78 &isAlternate);
michael@0 79 if (NS_SUCCEEDED(rv) && willNotify && !isAlternate && !mRunsToCompletion) {
michael@0 80 ++mPendingSheetCount;
michael@0 81 mScriptLoader->AddExecuteBlocker();
michael@0 82 }
michael@0 83
michael@0 84 if (aElement->IsHTML(nsGkAtoms::link)) {
michael@0 85 // look for <link rel="next" href="url">
michael@0 86 nsAutoString relVal;
michael@0 87 aElement->GetAttr(kNameSpaceID_None, nsGkAtoms::rel, relVal);
michael@0 88 if (!relVal.IsEmpty()) {
michael@0 89 uint32_t linkTypes = nsStyleLinkElement::ParseLinkTypes(relVal);
michael@0 90 bool hasPrefetch = linkTypes & nsStyleLinkElement::ePREFETCH;
michael@0 91 if (hasPrefetch || (linkTypes & nsStyleLinkElement::eNEXT)) {
michael@0 92 nsAutoString hrefVal;
michael@0 93 aElement->GetAttr(kNameSpaceID_None, nsGkAtoms::href, hrefVal);
michael@0 94 if (!hrefVal.IsEmpty()) {
michael@0 95 PrefetchHref(hrefVal, aElement, hasPrefetch);
michael@0 96 }
michael@0 97 }
michael@0 98 if (linkTypes & nsStyleLinkElement::eDNS_PREFETCH) {
michael@0 99 nsAutoString hrefVal;
michael@0 100 aElement->GetAttr(kNameSpaceID_None, nsGkAtoms::href, hrefVal);
michael@0 101 if (!hrefVal.IsEmpty()) {
michael@0 102 PrefetchDNS(hrefVal);
michael@0 103 }
michael@0 104 }
michael@0 105 }
michael@0 106 }
michael@0 107
michael@0 108 // Re-open update
michael@0 109 BeginDocUpdate();
michael@0 110 }
michael@0 111
michael@0 112 void
michael@0 113 nsHtml5DocumentBuilder::SetDocumentMode(nsHtml5DocumentMode m)
michael@0 114 {
michael@0 115 nsCompatibility mode = eCompatibility_NavQuirks;
michael@0 116 switch (m) {
michael@0 117 case STANDARDS_MODE:
michael@0 118 mode = eCompatibility_FullStandards;
michael@0 119 break;
michael@0 120 case ALMOST_STANDARDS_MODE:
michael@0 121 mode = eCompatibility_AlmostStandards;
michael@0 122 break;
michael@0 123 case QUIRKS_MODE:
michael@0 124 mode = eCompatibility_NavQuirks;
michael@0 125 break;
michael@0 126 }
michael@0 127 nsCOMPtr<nsIHTMLDocument> htmlDocument = do_QueryInterface(mDocument);
michael@0 128 NS_ASSERTION(htmlDocument, "Document didn't QI into HTML document.");
michael@0 129 htmlDocument->SetCompatibilityMode(mode);
michael@0 130 }
michael@0 131
michael@0 132 // nsContentSink overrides
michael@0 133
michael@0 134 void
michael@0 135 nsHtml5DocumentBuilder::UpdateChildCounts()
michael@0 136 {
michael@0 137 // No-op
michael@0 138 }
michael@0 139
michael@0 140 nsresult
michael@0 141 nsHtml5DocumentBuilder::FlushTags()
michael@0 142 {
michael@0 143 return NS_OK;
michael@0 144 }

mercurial