/*static*/ PRBool nsSVGFeatures::HaveFeature(const nsAString& aFeature) { if (!NS_SVGEnabled()) { return PR_FALSE; } #define SVG_SUPPORTED_FEATURE(str) if (aFeature.Equals(NS_LITERAL_STRING(str).get())) return PR_TRUE; #define SVG_UNSUPPORTED_FEATURE(str) #include "nsSVGFeaturesList.h" #undef SVG_SUPPORTED_FEATURE #undef SVG_UNSUPPORTED_FEATURE return PR_FALSE; }
nsresult NS_NewElement(nsIContent** aResult, PRInt32 aElementType, already_AddRefed<nsINodeInfo> aNodeInfo, PRUint32 aFromParser) { if (aElementType == kNameSpaceID_XHTML) { return NS_NewHTMLElement(aResult, aNodeInfo, aFromParser); } #ifdef MOZ_XUL if (aElementType == kNameSpaceID_XUL) { return NS_NewXULElement(aResult, aNodeInfo); } #endif #ifdef MOZ_MATHML if (aElementType == kNameSpaceID_MathML) { return NS_NewMathMLElement(aResult, aNodeInfo); } #endif #ifdef MOZ_SVG if (aElementType == kNameSpaceID_SVG && NS_SVGEnabled()) { return NS_NewSVGElement(aResult, aNodeInfo, aFromParser); } #endif if (aElementType == kNameSpaceID_XMLEvents) { return NS_NewXMLEventsElement(aResult, aNodeInfo); } #ifdef MOZ_XTF if (aElementType > kNameSpaceID_LastBuiltin) { nsIXTFService* xtfService = nsContentUtils::GetXTFService(); NS_ASSERTION(xtfService, "could not get xtf service"); if (xtfService && NS_SUCCEEDED(xtfService->CreateElement(aResult, aNodeInfo))) return NS_OK; } #endif return NS_NewXMLElement(aResult, aNodeInfo); }
NS_IMETHODIMP nsContentDLF::CreateInstance(const char* aCommand, nsIChannel* aChannel, nsILoadGroup* aLoadGroup, const char* aContentType, nsISupports* aContainer, nsISupports* aExtraInfo, nsIStreamListener** aDocListener, nsIContentViewer** aDocViewer) { EnsureUAStyleSheet(); // Are we viewing source? #ifdef MOZ_VIEW_SOURCE nsCOMPtr<nsIViewSourceChannel> viewSourceChannel = do_QueryInterface(aChannel); if (viewSourceChannel) { aCommand = "view-source"; // The parser freaks out when it sees the content-type that a // view-source channel normally returns. Get the actual content // type of the data. If it's known, use it; otherwise use // text/plain. nsCAutoString type; viewSourceChannel->GetOriginalContentType(type); PRBool knownType = PR_FALSE; PRInt32 typeIndex; for (typeIndex = 0; gHTMLTypes[typeIndex] && !knownType; ++typeIndex) { if (type.Equals(gHTMLTypes[typeIndex]) && !type.EqualsLiteral("application/x-view-source")) { knownType = PR_TRUE; } } for (typeIndex = 0; gXMLTypes[typeIndex] && !knownType; ++typeIndex) { if (type.Equals(gXMLTypes[typeIndex])) { knownType = PR_TRUE; } } #ifdef MOZ_SVG if (NS_SVGEnabled()) { for (typeIndex = 0; gSVGTypes[typeIndex] && !knownType; ++typeIndex) { if (type.Equals(gSVGTypes[typeIndex])) { knownType = PR_TRUE; } } } #endif // MOZ_SVG for (typeIndex = 0; gXULTypes[typeIndex] && !knownType; ++typeIndex) { if (type.Equals(gXULTypes[typeIndex])) { knownType = PR_TRUE; } } if (knownType) { viewSourceChannel->SetContentType(type); } else { viewSourceChannel->SetContentType(NS_LITERAL_CSTRING("text/plain")); } } else if (0 == PL_strcmp("application/x-view-source", aContentType)) { aChannel->SetContentType(NS_LITERAL_CSTRING("text/plain")); aContentType = "text/plain"; } #endif // Try html int typeIndex=0; while(gHTMLTypes[typeIndex]) { if (0 == PL_strcmp(gHTMLTypes[typeIndex++], aContentType)) { return CreateDocument(aCommand, aChannel, aLoadGroup, aContainer, kHTMLDocumentCID, aDocListener, aDocViewer); } } // Try XML typeIndex = 0; while(gXMLTypes[typeIndex]) { if (0== PL_strcmp(gXMLTypes[typeIndex++], aContentType)) { return CreateDocument(aCommand, aChannel, aLoadGroup, aContainer, kXMLDocumentCID, aDocListener, aDocViewer); } } #ifdef MOZ_SVG if (NS_SVGEnabled()) { // Try SVG typeIndex = 0; while(gSVGTypes[typeIndex]) { if (!PL_strcmp(gSVGTypes[typeIndex++], aContentType)) { return CreateDocument(aCommand, aChannel, aLoadGroup, aContainer, kSVGDocumentCID, aDocListener, aDocViewer); } } } #endif // Try XUL typeIndex = 0; while (gXULTypes[typeIndex]) { if (0 == PL_strcmp(gXULTypes[typeIndex++], aContentType)) { return CreateXULDocument(aCommand, aChannel, aLoadGroup, aContentType, aContainer, aExtraInfo, aDocListener, aDocViewer); } } // Try image types nsCOMPtr<imgILoader> loader(do_GetService("@mozilla.org/image/loader;1")); PRBool isReg = PR_FALSE; loader->SupportImageWithMimeType(aContentType, &isReg); if (isReg) { return CreateDocument(aCommand, aChannel, aLoadGroup, aContainer, kImageDocumentCID, aDocListener, aDocViewer); } nsCOMPtr<nsIPluginHost> ph (do_GetService(kPluginManagerCID)); if(ph && NS_SUCCEEDED(ph->IsPluginEnabledForType(aContentType))) { return CreateDocument(aCommand, aChannel, aLoadGroup, aContainer, kPluginDocumentCID, aDocListener, aDocViewer); } // If we get here, then we weren't able to create anything. Sorry! return NS_ERROR_FAILURE; }
nsresult NS_NewSVGElement(nsIContent** aResult, nsINodeInfo *aNodeInfo, PRBool aFromParser) { NS_PRECONDITION(NS_SVGEnabled(), "creating an SVG element while SVG disabled"); static const char kSVGStyleSheetURI[] = "resource://gre/res/svg.css"; // this bit of code is to load svg.css on demand nsIDocument *doc = aNodeInfo->GetDocument(); if (doc) doc->EnsureCatalogStyleSheet(kSVGStyleSheetURI); nsIAtom *name = aNodeInfo->NameAtom(); if (name == nsGkAtoms::a) return NS_NewSVGAElement(aResult, aNodeInfo); if (name == nsGkAtoms::polyline) return NS_NewSVGPolylineElement(aResult, aNodeInfo); if (name == nsGkAtoms::polygon) return NS_NewSVGPolygonElement(aResult, aNodeInfo); if (name == nsGkAtoms::circle) return NS_NewSVGCircleElement(aResult, aNodeInfo); if (name == nsGkAtoms::ellipse) return NS_NewSVGEllipseElement(aResult, aNodeInfo); if (name == nsGkAtoms::line) return NS_NewSVGLineElement(aResult, aNodeInfo); if (name == nsGkAtoms::rect) return NS_NewSVGRectElement(aResult, aNodeInfo); if (name == nsGkAtoms::svg) return NS_NewSVGSVGElement(aResult, aNodeInfo, aFromParser); if (name == nsGkAtoms::g) return NS_NewSVGGElement(aResult, aNodeInfo); if (name == nsGkAtoms::foreignObject) return NS_NewSVGForeignObjectElement(aResult, aNodeInfo); if (name == nsGkAtoms::path) return NS_NewSVGPathElement(aResult, aNodeInfo); if (name == nsGkAtoms::text) return NS_NewSVGTextElement(aResult, aNodeInfo); if (name == nsGkAtoms::tspan) return NS_NewSVGTSpanElement(aResult, aNodeInfo); if (name == nsGkAtoms::image) return NS_NewSVGImageElement(aResult, aNodeInfo); if (name == nsGkAtoms::style) return NS_NewSVGStyleElement(aResult, aNodeInfo); if (name == nsGkAtoms::linearGradient) return NS_NewSVGLinearGradientElement(aResult, aNodeInfo); if (name == nsGkAtoms::metadata) return NS_NewSVGMetadataElement(aResult, aNodeInfo); if (name == nsGkAtoms::radialGradient) return NS_NewSVGRadialGradientElement(aResult, aNodeInfo); if (name == nsGkAtoms::stop) return NS_NewSVGStopElement(aResult, aNodeInfo); if (name == nsGkAtoms::defs) return NS_NewSVGDefsElement(aResult, aNodeInfo); if (name == nsGkAtoms::desc) return NS_NewSVGDescElement(aResult, aNodeInfo); if (name == nsGkAtoms::script) return NS_NewSVGScriptElement(aResult, aNodeInfo); if (name == nsGkAtoms::use) return NS_NewSVGUseElement(aResult, aNodeInfo); if (name == nsGkAtoms::symbol) return NS_NewSVGSymbolElement(aResult, aNodeInfo); if (name == nsGkAtoms::marker) return NS_NewSVGMarkerElement(aResult, aNodeInfo); if (name == nsGkAtoms::title) return NS_NewSVGTitleElement(aResult, aNodeInfo); if (name == nsGkAtoms::clipPath) return NS_NewSVGClipPathElement(aResult, aNodeInfo); if (name == nsGkAtoms::textPath) return NS_NewSVGTextPathElement(aResult, aNodeInfo); if (name == nsGkAtoms::filter) return NS_NewSVGFilterElement(aResult, aNodeInfo); if (name == nsGkAtoms::feBlend) return NS_NewSVGFEBlendElement(aResult, aNodeInfo); if (name == nsGkAtoms::feColorMatrix) return NS_NewSVGFEColorMatrixElement(aResult, aNodeInfo); if (name == nsGkAtoms::feComponentTransfer) return NS_NewSVGFEComponentTransferElement(aResult, aNodeInfo); if (name == nsGkAtoms::feComposite) return NS_NewSVGFECompositeElement(aResult, aNodeInfo); if (name == nsGkAtoms::feFuncR) return NS_NewSVGFEFuncRElement(aResult, aNodeInfo); if (name == nsGkAtoms::feFuncG) return NS_NewSVGFEFuncGElement(aResult, aNodeInfo); if (name == nsGkAtoms::feFuncB) return NS_NewSVGFEFuncBElement(aResult, aNodeInfo); if (name == nsGkAtoms::feFuncA) return NS_NewSVGFEFuncAElement(aResult, aNodeInfo); if (name == nsGkAtoms::feGaussianBlur) return NS_NewSVGFEGaussianBlurElement(aResult, aNodeInfo); if (name == nsGkAtoms::feMerge) return NS_NewSVGFEMergeElement(aResult, aNodeInfo); if (name == nsGkAtoms::feMergeNode) return NS_NewSVGFEMergeNodeElement(aResult, aNodeInfo); if (name == nsGkAtoms::feMorphology) return NS_NewSVGFEMorphologyElement(aResult, aNodeInfo); if (name == nsGkAtoms::feOffset) return NS_NewSVGFEOffsetElement(aResult, aNodeInfo); if (name == nsGkAtoms::feFlood) return NS_NewSVGFEFloodElement(aResult, aNodeInfo); if (name == nsGkAtoms::feTile) return NS_NewSVGFETileElement(aResult, aNodeInfo); if (name == nsGkAtoms::feTurbulence) return NS_NewSVGFETurbulenceElement(aResult, aNodeInfo); if (name == nsGkAtoms::feConvolveMatrix) return NS_NewSVGFEConvolveMatrixElement(aResult, aNodeInfo); if (name == nsGkAtoms::feDistantLight) return NS_NewSVGFEDistantLightElement(aResult, aNodeInfo); if (name == nsGkAtoms::fePointLight) return NS_NewSVGFEPointLightElement(aResult, aNodeInfo); if (name == nsGkAtoms::feSpotLight) return NS_NewSVGFESpotLightElement(aResult, aNodeInfo); if (name == nsGkAtoms::feDiffuseLighting) return NS_NewSVGFEDiffuseLightingElement(aResult, aNodeInfo); if (name == nsGkAtoms::feSpecularLighting) return NS_NewSVGFESpecularLightingElement(aResult, aNodeInfo); if (name == nsGkAtoms::feImage) return NS_NewSVGFEImageElement(aResult, aNodeInfo); if (name == nsGkAtoms::feDisplacementMap) return NS_NewSVGFEDisplacementMapElement(aResult, aNodeInfo); if (name == nsGkAtoms::pattern) return NS_NewSVGPatternElement(aResult, aNodeInfo); if (name == nsGkAtoms::mask) return NS_NewSVGMaskElement(aResult, aNodeInfo); if (name == nsGkAtoms::svgSwitch) return NS_NewSVGSwitchElement(aResult, aNodeInfo); #ifdef MOZ_SMIL if (NS_SMILEnabled()) { if (name == nsGkAtoms::animate) return NS_NewSVGAnimateElement(aResult, aNodeInfo); if (name == nsGkAtoms::animateTransform) return NS_NewSVGAnimateTransformElement(aResult, aNodeInfo); if (name == nsGkAtoms::set) return NS_NewSVGSetElement(aResult, aNodeInfo); } #endif // MOZ_SMIL // if we don't know what to create, just create a standard xml element: return NS_NewXMLElement(aResult, aNodeInfo); }
NS_IMETHODIMP nsContentDLF::CreateInstance(const char* aCommand, nsIChannel* aChannel, nsILoadGroup* aLoadGroup, const char* aContentType, nsISupports* aContainer, nsISupports* aExtraInfo, nsIStreamListener** aDocListener, nsIContentViewer** aDocViewer) { // Declare "type" here. This is because although the variable itself only // needs limited scope, we need to use the raw string memory -- as returned // by "type.get()" farther down in the function. nsCAutoString type; // Are we viewing source? #ifdef MOZ_VIEW_SOURCE nsCOMPtr<nsIViewSourceChannel> viewSourceChannel = do_QueryInterface(aChannel); if (viewSourceChannel) { aCommand = "view-source"; // The parser freaks out when it sees the content-type that a // view-source channel normally returns. Get the actual content // type of the data. If it's known, use it; otherwise use // text/plain. viewSourceChannel->GetOriginalContentType(type); PRBool knownType = PR_FALSE; PRInt32 typeIndex; for (typeIndex = 0; gHTMLTypes[typeIndex] && !knownType; ++typeIndex) { if (type.Equals(gHTMLTypes[typeIndex]) && !type.EqualsLiteral(VIEWSOURCE_CONTENT_TYPE)) { knownType = PR_TRUE; } } for (typeIndex = 0; gXMLTypes[typeIndex] && !knownType; ++typeIndex) { if (type.Equals(gXMLTypes[typeIndex])) { knownType = PR_TRUE; } } #ifdef MOZ_SVG if (NS_SVGEnabled()) { for (typeIndex = 0; gSVGTypes[typeIndex] && !knownType; ++typeIndex) { if (type.Equals(gSVGTypes[typeIndex])) { knownType = PR_TRUE; } } } #endif // MOZ_SVG for (typeIndex = 0; gXULTypes[typeIndex] && !knownType; ++typeIndex) { if (type.Equals(gXULTypes[typeIndex])) { knownType = PR_TRUE; } } if (knownType) { viewSourceChannel->SetContentType(type); } else if (IsImageContentType(type.get())) { // If it's an image, we want to display it the same way we normally would. // Also note the lifetime of "type" allows us to safely use "get()" here. aContentType = type.get(); } else { viewSourceChannel->SetContentType(NS_LITERAL_CSTRING(TEXT_PLAIN)); } } else if (0 == PL_strcmp(VIEWSOURCE_CONTENT_TYPE, aContentType)) { aChannel->SetContentType(NS_LITERAL_CSTRING(TEXT_PLAIN)); aContentType = TEXT_PLAIN; } #endif // Try html int typeIndex=0; while(gHTMLTypes[typeIndex]) { if (0 == PL_strcmp(gHTMLTypes[typeIndex++], aContentType)) { return CreateDocument(aCommand, aChannel, aLoadGroup, aContainer, kHTMLDocumentCID, aDocListener, aDocViewer); } } // Try XML typeIndex = 0; while(gXMLTypes[typeIndex]) { if (0== PL_strcmp(gXMLTypes[typeIndex++], aContentType)) { return CreateDocument(aCommand, aChannel, aLoadGroup, aContainer, kXMLDocumentCID, aDocListener, aDocViewer); } } #ifdef MOZ_SVG if (NS_SVGEnabled()) { // Try SVG typeIndex = 0; while(gSVGTypes[typeIndex]) { if (!PL_strcmp(gSVGTypes[typeIndex++], aContentType)) { return CreateDocument(aCommand, aChannel, aLoadGroup, aContainer, kSVGDocumentCID, aDocListener, aDocViewer); } } } #endif // Try XUL typeIndex = 0; while (gXULTypes[typeIndex]) { if (0 == PL_strcmp(gXULTypes[typeIndex++], aContentType)) { return CreateXULDocument(aCommand, aChannel, aLoadGroup, aContentType, aContainer, aExtraInfo, aDocListener, aDocViewer); } } #ifdef MOZ_MEDIA if (nsHTMLMediaElement::ShouldHandleMediaType(aContentType)) { return CreateDocument(aCommand, aChannel, aLoadGroup, aContainer, kVideoDocumentCID, aDocListener, aDocViewer); } #endif // Try image types if (IsImageContentType(aContentType)) { return CreateDocument(aCommand, aChannel, aLoadGroup, aContainer, kImageDocumentCID, aDocListener, aDocViewer); } nsCOMPtr<nsIPluginHost> ph (do_GetService(MOZ_PLUGIN_HOST_CONTRACTID)); if(ph && NS_SUCCEEDED(ph->IsPluginEnabledForType(aContentType))) { return CreateDocument(aCommand, aChannel, aLoadGroup, aContainer, kPluginDocumentCID, aDocListener, aDocViewer); } // If we get here, then we weren't able to create anything. Sorry! return NS_ERROR_FAILURE; }
nsresult nsLayoutStatics::Initialize() { NS_ASSERTION(sLayoutStaticRefcnt == 0, "nsLayoutStatics isn't zero!"); sLayoutStaticRefcnt = 1; NS_LOG_ADDREF(&sLayoutStaticRefcnt, sLayoutStaticRefcnt, "nsLayoutStatics", 1); nsresult rv; // Register all of our atoms once nsCSSAnonBoxes::AddRefAtoms(); nsCSSPseudoClasses::AddRefAtoms(); nsCSSPseudoElements::AddRefAtoms(); nsCSSKeywords::AddRefTable(); nsCSSProps::AddRefTable(); nsColorNames::AddRefTable(); nsGkAtoms::AddRefAtoms(); nsDOMScriptObjectFactory::Startup(); rv = nsContentUtils::Init(); if (NS_FAILED(rv)) { NS_ERROR("Could not initialize nsContentUtils"); return rv; } rv = nsAttrValue::Init(); if (NS_FAILED(rv)) { NS_ERROR("Could not initialize nsAttrValue"); return rv; } rv = nsTextFragment::Init(); if (NS_FAILED(rv)) { NS_ERROR("Could not initialize nsTextFragment"); return rv; } rv = nsCellMap::Init(); if (NS_FAILED(rv)) { NS_ERROR("Could not initialize nsCellMap"); return rv; } rv = nsCSSRendering::Init(); if (NS_FAILED(rv)) { NS_ERROR("Could not initialize nsCSSRendering"); return rv; } rv = nsTextFrameTextRunCache::Init(); if (NS_FAILED(rv)) { NS_ERROR("Could not initialize textframe textrun cache"); return rv; } #ifdef MOZ_XUL rv = nsXULContentUtils::Init(); if (NS_FAILED(rv)) { NS_ERROR("Could not initialize nsXULContentUtils"); return rv; } #ifndef MOZ_NO_INSPECTOR_APIS inDOMView::InitAtoms(); #endif #endif #ifdef MOZ_MATHML nsMathMLOperators::AddRefTable(); #endif #ifdef MOZ_SVG if (NS_SVGEnabled()) nsContentDLF::RegisterSVG(); #endif #ifndef MOZILLA_PLAINTEXT_EDITOR_ONLY nsEditProperty::RegisterAtoms(); nsTextServicesDocument::RegisterAtoms(); #endif #ifdef DEBUG nsFrame::DisplayReflowStartup(); #endif nsDOMAttribute::Initialize(); rv = txMozillaXSLTProcessor::Startup(); if (NS_FAILED(rv)) { NS_ERROR("Could not initialize txMozillaXSLTProcessor"); return rv; } rv = nsDOMStorageManager::Initialize(); if (NS_FAILED(rv)) { NS_ERROR("Could not initialize nsDOMStorageManager"); return rv; } #ifndef DEBUG_CC rv = nsCCUncollectableMarker::Init(); if (NS_FAILED(rv)) { NS_ERROR("Could not initialize nsCCUncollectableMarker"); return rv; } #endif #ifdef MOZ_XUL rv = nsXULPopupManager::Init(); if (NS_FAILED(rv)) { NS_ERROR("Could not initialize nsXULPopupManager"); return rv; } #endif return NS_OK; }