1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/parser/html/nsHtml5DocumentBuilder.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,144 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim: set ts=2 sw=2 et tw=78: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#include "nsHtml5DocumentBuilder.h" 1.11 + 1.12 +#include "nsIStyleSheetLinkingElement.h" 1.13 +#include "nsStyleLinkElement.h" 1.14 +#include "nsScriptLoader.h" 1.15 +#include "nsIHTMLDocument.h" 1.16 + 1.17 +NS_IMPL_CYCLE_COLLECTION_INHERITED(nsHtml5DocumentBuilder, nsContentSink, 1.18 + mOwnedElements) 1.19 + 1.20 +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsHtml5DocumentBuilder) 1.21 +NS_INTERFACE_MAP_END_INHERITING(nsContentSink) 1.22 + 1.23 +NS_IMPL_ADDREF_INHERITED(nsHtml5DocumentBuilder, nsContentSink) 1.24 +NS_IMPL_RELEASE_INHERITED(nsHtml5DocumentBuilder, nsContentSink) 1.25 + 1.26 +nsHtml5DocumentBuilder::nsHtml5DocumentBuilder(bool aRunsToCompletion) 1.27 +{ 1.28 + mRunsToCompletion = aRunsToCompletion; 1.29 +} 1.30 + 1.31 +nsresult 1.32 +nsHtml5DocumentBuilder::Init(nsIDocument* aDoc, 1.33 + nsIURI* aURI, 1.34 + nsISupports* aContainer, 1.35 + nsIChannel* aChannel) 1.36 +{ 1.37 + return nsContentSink::Init(aDoc, aURI, aContainer, aChannel); 1.38 +} 1.39 + 1.40 +nsHtml5DocumentBuilder::~nsHtml5DocumentBuilder() 1.41 +{ 1.42 +} 1.43 + 1.44 +nsresult 1.45 +nsHtml5DocumentBuilder::MarkAsBroken(nsresult aReason) 1.46 +{ 1.47 + mBroken = aReason; 1.48 + return aReason; 1.49 +} 1.50 + 1.51 +void 1.52 +nsHtml5DocumentBuilder::SetDocumentCharsetAndSource(nsACString& aCharset, int32_t aCharsetSource) 1.53 +{ 1.54 + if (mDocument) { 1.55 + mDocument->SetDocumentCharacterSetSource(aCharsetSource); 1.56 + mDocument->SetDocumentCharacterSet(aCharset); 1.57 + } 1.58 +} 1.59 + 1.60 +void 1.61 +nsHtml5DocumentBuilder::UpdateStyleSheet(nsIContent* aElement) 1.62 +{ 1.63 + // Break out of the doc update created by Flush() to zap a runnable 1.64 + // waiting to call UpdateStyleSheet without the right observer 1.65 + EndDocUpdate(); 1.66 + 1.67 + if (MOZ_UNLIKELY(!mParser)) { 1.68 + // EndDocUpdate ran stuff that called nsIParser::Terminate() 1.69 + return; 1.70 + } 1.71 + 1.72 + nsCOMPtr<nsIStyleSheetLinkingElement> ssle(do_QueryInterface(aElement)); 1.73 + NS_ASSERTION(ssle, "Node didn't QI to style."); 1.74 + 1.75 + ssle->SetEnableUpdates(true); 1.76 + 1.77 + bool willNotify; 1.78 + bool isAlternate; 1.79 + nsresult rv = ssle->UpdateStyleSheet(mRunsToCompletion ? nullptr : this, 1.80 + &willNotify, 1.81 + &isAlternate); 1.82 + if (NS_SUCCEEDED(rv) && willNotify && !isAlternate && !mRunsToCompletion) { 1.83 + ++mPendingSheetCount; 1.84 + mScriptLoader->AddExecuteBlocker(); 1.85 + } 1.86 + 1.87 + if (aElement->IsHTML(nsGkAtoms::link)) { 1.88 + // look for <link rel="next" href="url"> 1.89 + nsAutoString relVal; 1.90 + aElement->GetAttr(kNameSpaceID_None, nsGkAtoms::rel, relVal); 1.91 + if (!relVal.IsEmpty()) { 1.92 + uint32_t linkTypes = nsStyleLinkElement::ParseLinkTypes(relVal); 1.93 + bool hasPrefetch = linkTypes & nsStyleLinkElement::ePREFETCH; 1.94 + if (hasPrefetch || (linkTypes & nsStyleLinkElement::eNEXT)) { 1.95 + nsAutoString hrefVal; 1.96 + aElement->GetAttr(kNameSpaceID_None, nsGkAtoms::href, hrefVal); 1.97 + if (!hrefVal.IsEmpty()) { 1.98 + PrefetchHref(hrefVal, aElement, hasPrefetch); 1.99 + } 1.100 + } 1.101 + if (linkTypes & nsStyleLinkElement::eDNS_PREFETCH) { 1.102 + nsAutoString hrefVal; 1.103 + aElement->GetAttr(kNameSpaceID_None, nsGkAtoms::href, hrefVal); 1.104 + if (!hrefVal.IsEmpty()) { 1.105 + PrefetchDNS(hrefVal); 1.106 + } 1.107 + } 1.108 + } 1.109 + } 1.110 + 1.111 + // Re-open update 1.112 + BeginDocUpdate(); 1.113 +} 1.114 + 1.115 +void 1.116 +nsHtml5DocumentBuilder::SetDocumentMode(nsHtml5DocumentMode m) 1.117 +{ 1.118 + nsCompatibility mode = eCompatibility_NavQuirks; 1.119 + switch (m) { 1.120 + case STANDARDS_MODE: 1.121 + mode = eCompatibility_FullStandards; 1.122 + break; 1.123 + case ALMOST_STANDARDS_MODE: 1.124 + mode = eCompatibility_AlmostStandards; 1.125 + break; 1.126 + case QUIRKS_MODE: 1.127 + mode = eCompatibility_NavQuirks; 1.128 + break; 1.129 + } 1.130 + nsCOMPtr<nsIHTMLDocument> htmlDocument = do_QueryInterface(mDocument); 1.131 + NS_ASSERTION(htmlDocument, "Document didn't QI into HTML document."); 1.132 + htmlDocument->SetCompatibilityMode(mode); 1.133 +} 1.134 + 1.135 +// nsContentSink overrides 1.136 + 1.137 +void 1.138 +nsHtml5DocumentBuilder::UpdateChildCounts() 1.139 +{ 1.140 + // No-op 1.141 +} 1.142 + 1.143 +nsresult 1.144 +nsHtml5DocumentBuilder::FlushTags() 1.145 +{ 1.146 + return NS_OK; 1.147 +}