void HTMLLinkElement::UpdateImport() { // 1. link node should be attached to the document. nsCOMPtr<nsIDocument> doc = GetCurrentDoc(); if (!doc) { // We might have been just removed from the document, so // let's remove ourself from the list of link nodes of // the import and reset mImportLoader. if (mImportLoader) { mImportLoader->RemoveLinkElement(this); mImportLoader = nullptr; } return; } // Until the script execution order is not sorted out for nested cases // let's not allow them. if (!doc->IsMasterDocument()) { nsContentUtils::LogSimpleConsoleError( NS_LITERAL_STRING("Nested imports are not supported yet"), "Imports"); return; } // 2. rel type should be import. nsAutoString rel; GetAttr(kNameSpaceID_None, nsGkAtoms::rel, rel); uint32_t linkTypes = nsStyleLinkElement::ParseLinkTypes(rel, NodePrincipal()); if (!(linkTypes & eHTMLIMPORT)) { mImportLoader = nullptr; return; } nsCOMPtr<nsIURI> uri = GetHrefURI(); if (!uri) { mImportLoader = nullptr; return; } if (!nsStyleLinkElement::IsImportEnabled(NodePrincipal())) { // For now imports are hidden behind a pref... return; } nsRefPtr<ImportManager> manager = doc->ImportManager(); MOZ_ASSERT(manager, "ImportManager should be created lazily when needed"); { // The load even might fire sooner than we could set mImportLoader so // we must use async event and a scriptBlocker here. nsAutoScriptBlocker scriptBlocker; // CORS check will happen at the start of the load. mImportLoader = manager->Get(uri, this, doc); } }
/* * This is a utility function. It will only fail if it can't get a * parser. This means it can return NS_OK without aURI or aCSSLoader * being initialized. */ nsresult nsDOMCSSAttributeDeclaration::GetCSSParsingEnvironment(nsIURI** aSheetURI, nsIURI** aBaseURI, nsIPrincipal** aSheetPrincipal, mozilla::css::Loader** aCSSLoader) { NS_ASSERTION(mElement, "Something is severely broken -- there should be an Element here!"); // null out the out params since some of them may not get initialized below *aSheetURI = nsnull; *aBaseURI = nsnull; *aSheetPrincipal = nsnull; *aCSSLoader = nsnull; nsIDocument* doc = mElement->GetOwnerDoc(); if (!doc) { // document has been destroyed return NS_ERROR_NOT_AVAILABLE; } nsCOMPtr<nsIURI> baseURI = mElement->GetBaseURI(); nsCOMPtr<nsIURI> sheetURI = doc->GetDocumentURI(); NS_ADDREF(*aCSSLoader = doc->CSSLoader()); baseURI.swap(*aBaseURI); sheetURI.swap(*aSheetURI); NS_ADDREF(*aSheetPrincipal = mElement->NodePrincipal()); return NS_OK; }
nsresult HTMLLinkElement::SetAttr(int32_t aNameSpaceID, nsIAtom* aName, nsIAtom* aPrefix, const nsAString& aValue, bool aNotify) { nsresult rv = nsGenericHTMLElement::SetAttr(aNameSpaceID, aName, aPrefix, aValue, aNotify); // The ordering of the parent class's SetAttr call and Link::ResetLinkState // is important here! The attribute is not set until SetAttr returns, and // we will need the updated attribute value because notifying the document // that content states have changed will call IntrinsicState, which will try // to get updated information about the visitedness from Link. if (aName == nsGkAtoms::href && kNameSpaceID_None == aNameSpaceID) { Link::ResetLinkState(!!aNotify, true); if (IsInUncomposedDoc()) { CreateAndDispatchEvent(OwnerDoc(), NS_LITERAL_STRING("DOMLinkChanged")); } } if (NS_SUCCEEDED(rv) && aNameSpaceID == kNameSpaceID_None && (aName == nsGkAtoms::href || aName == nsGkAtoms::rel || aName == nsGkAtoms::title || aName == nsGkAtoms::media || aName == nsGkAtoms::type)) { bool dropSheet = false; if (aName == nsGkAtoms::rel) { uint32_t linkTypes = nsStyleLinkElement::ParseLinkTypes(aValue, NodePrincipal()); if (GetSheet()) { dropSheet = !(linkTypes & nsStyleLinkElement::eSTYLESHEET); } else if (linkTypes & eHTMLIMPORT) { UpdateImport(); } else if ((linkTypes & ePRECONNECT) && IsInComposedDoc()) { UpdatePreconnect(); } } if (aName == nsGkAtoms::href) { UpdateImport(); if (IsInComposedDoc()) { UpdatePreconnect(); } } UpdateStyleSheetInternal(nullptr, nullptr, dropSheet || (aName == nsGkAtoms::title || aName == nsGkAtoms::media || aName == nsGkAtoms::type)); } return rv; }
void nsDOMCSSAttributeDeclaration::GetCSSParsingEnvironment(CSSParsingEnvironment& aCSSParseEnv) { NS_ASSERTION(mElement, "Something is severely broken -- there should be an Element here!"); nsIDocument* doc = mElement->OwnerDoc(); aCSSParseEnv.mSheetURI = doc->GetDocumentURI(); aCSSParseEnv.mBaseURI = mElement->GetBaseURI(); aCSSParseEnv.mPrincipal = mElement->NodePrincipal(); aCSSParseEnv.mCSSLoader = doc->CSSLoader(); }
bool HTMLLinkElement::HasDNSPrefetchRel() { nsAutoString rel; if (GetAttr(kNameSpaceID_None, nsGkAtoms::rel, rel)) { return !!(ParseLinkTypes(rel, NodePrincipal()) & nsStyleLinkElement::eDNS_PREFETCH); } return false; }
void HTMLLinkElement::GetStyleSheetInfo(nsAString& aTitle, nsAString& aType, nsAString& aMedia, bool* aIsScoped, bool* aIsAlternate) { aTitle.Truncate(); aType.Truncate(); aMedia.Truncate(); *aIsScoped = false; *aIsAlternate = false; nsAutoString rel; GetAttr(kNameSpaceID_None, nsGkAtoms::rel, rel); uint32_t linkTypes = nsStyleLinkElement::ParseLinkTypes(rel, NodePrincipal()); // Is it a stylesheet link? if (!(linkTypes & nsStyleLinkElement::eSTYLESHEET)) { return; } nsAutoString title; GetAttr(kNameSpaceID_None, nsGkAtoms::title, title); title.CompressWhitespace(); aTitle.Assign(title); // If alternate, does it have title? if (linkTypes & nsStyleLinkElement::eALTERNATE) { if (aTitle.IsEmpty()) { // alternates must have title return; } else { *aIsAlternate = true; } } GetAttr(kNameSpaceID_None, nsGkAtoms::media, aMedia); // The HTML5 spec is formulated in terms of the CSSOM spec, which specifies // that media queries should be ASCII lowercased during serialization. nsContentUtils::ASCIIToLower(aMedia); nsAutoString mimeType; nsAutoString notUsed; GetAttr(kNameSpaceID_None, nsGkAtoms::type, aType); nsContentUtils::SplitMimeType(aType, mimeType, notUsed); if (!mimeType.IsEmpty() && !mimeType.LowerCaseEqualsLiteral("text/css")) { return; } // If we get here we assume that we're loading a css file, so set the // type to 'text/css' aType.AssignLiteral("text/css"); return; }
nsresult MediaDocument::StartDocumentLoad(const char* aCommand, nsIChannel* aChannel, nsILoadGroup* aLoadGroup, nsISupports* aContainer, nsIStreamListener** aDocListener, bool aReset, nsIContentSink* aSink) { nsresult rv = nsDocument::StartDocumentLoad(aCommand, aChannel, aLoadGroup, aContainer, aDocListener, aReset, aSink); if (NS_FAILED(rv)) { return rv; } // We try to set the charset of the current document to that of the // 'genuine' (as opposed to an intervening 'chrome') parent document // that may be in a different window/tab. Even if we fail here, // we just return NS_OK because another attempt is made in // |UpdateTitleAndCharset| and the worst thing possible is a mangled // filename in the titlebar and the file picker. // Note that we // exclude UTF-8 as 'invalid' because UTF-8 is likely to be the charset // of a chrome document that has nothing to do with the actual content // whose charset we want to know. Even if "the actual content" is indeed // in UTF-8, we don't lose anything because the default empty value is // considered synonymous with UTF-8. nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(aContainer)); // not being able to set the charset is not critical. NS_ENSURE_TRUE(docShell, NS_OK); nsAutoCString charset; int32_t source; nsCOMPtr<nsIPrincipal> principal; // opening in a new tab docShell->GetParentCharset(charset, &source, getter_AddRefs(principal)); if (!charset.IsEmpty() && !charset.Equals("UTF-8") && NodePrincipal()->Equals(principal)) { SetDocumentCharacterSetSource(source); SetDocumentCharacterSet(charset); } return NS_OK; }
void HTMLLinkElement::UpdateImport() { // 1. link node should be attached to the document. nsCOMPtr<nsIDocument> doc = GetUncomposedDoc(); if (!doc) { // We might have been just removed from the document, so // let's remove ourself from the list of link nodes of // the import and reset mImportLoader. if (mImportLoader) { mImportLoader->RemoveLinkElement(this); mImportLoader = nullptr; } return; } // 2. rel type should be import. nsAutoString rel; GetAttr(kNameSpaceID_None, nsGkAtoms::rel, rel); uint32_t linkTypes = nsStyleLinkElement::ParseLinkTypes(rel, NodePrincipal()); if (!(linkTypes & eHTMLIMPORT)) { mImportLoader = nullptr; return; } nsCOMPtr<nsIURI> uri = GetHrefURI(); if (!uri) { mImportLoader = nullptr; return; } if (!nsStyleLinkElement::IsImportEnabled()) { // For now imports are hidden behind a pref... return; } nsRefPtr<ImportManager> manager = doc->ImportManager(); MOZ_ASSERT(manager, "ImportManager should be created lazily when needed"); { // The load even might fire sooner than we could set mImportLoader so // we must use async event and a scriptBlocker here. nsAutoScriptBlocker scriptBlocker; // CORS check will happen at the start of the load. mImportLoader = manager->Get(uri, this, doc); } }
bool MerchantValidationEvent::init(const MerchantValidationEventInit& aEventInitDict, ErrorResult& aRv) { // Check methodName is valid if (!aEventInitDict.mMethodName.IsEmpty()) { nsString errMsg; auto rv = PaymentRequest::IsValidPaymentMethodIdentifier( aEventInitDict.mMethodName, errMsg); if (NS_FAILED(rv)) { aRv.ThrowRangeError<MSG_ILLEGAL_RANGE_PR_CONSTRUCTOR>(errMsg); return false; } } SetMethodName(aEventInitDict.mMethodName); nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(GetParentObject()); auto doc = window->GetExtantDoc(); if (!doc) { aRv.Throw(NS_ERROR_UNEXPECTED); return false; } auto principal = doc->NodePrincipal(); nsCOMPtr<nsIURI> baseURI; principal->GetURI(getter_AddRefs(baseURI)); nsresult rv; nsCOMPtr<nsIURI> validationUri; rv = NS_NewURI(getter_AddRefs(validationUri), aEventInitDict.mValidationURL, nullptr, baseURI, nsContentUtils::GetIOService()); if (NS_WARN_IF(NS_FAILED(rv))) { aRv.ThrowTypeError<MSG_INVALID_URL>(aEventInitDict.mValidationURL); return false; } nsAutoCString utf8href; rv = validationUri->GetSpec(utf8href); if (NS_FAILED(rv)) { aRv.Throw(NS_ERROR_DOM_BAD_URI); return false; } CopyUTF8toUTF16(utf8href, mValidationURL); return true; }
void nsStyledElementNotElementCSSInlineStyle::ParseStyleAttribute(const nsAString& aValue, nsAttrValue& aResult, bool aForceInDataDoc) { nsIDocument* doc = OwnerDoc(); if (aForceInDataDoc || !doc->IsLoadedAsData() || doc->IsStaticDocument()) { bool isCSS = true; // assume CSS until proven otherwise if (!IsInNativeAnonymousSubtree()) { // native anonymous content // always assumes CSS nsAutoString styleType; doc->GetHeaderData(nsGkAtoms::headerContentStyleType, styleType); if (!styleType.IsEmpty()) { static const char textCssStr[] = "text/css"; isCSS = (styleType.EqualsIgnoreCase(textCssStr, sizeof(textCssStr) - 1)); } } if (isCSS) { css::Loader* cssLoader = doc->CSSLoader(); nsCSSParser cssParser(cssLoader); nsCOMPtr<nsIURI> baseURI = GetBaseURI(); nsRefPtr<css::StyleRule> rule; cssParser.ParseStyleAttribute(aValue, doc->GetDocumentURI(), baseURI, NodePrincipal(), getter_AddRefs(rule)); if (rule) { aResult.SetTo(rule, &aValue); return; } } } aResult.SetTo(aValue); }
void HTMLLinkElement::UpdatePreconnect() { // rel type should be preconnect nsAutoString rel; if (!GetAttr(kNameSpaceID_None, nsGkAtoms::rel, rel)) { return; } uint32_t linkTypes = nsStyleLinkElement::ParseLinkTypes(rel, NodePrincipal()); if (!(linkTypes & ePRECONNECT)) { return; } nsIDocument *owner = OwnerDoc(); if (owner) { nsCOMPtr<nsIURI> uri = GetHrefURI(); if (uri) { owner->MaybePreconnect(uri, GetCORSMode()); } } }
void HTMLLinkElement::UpdatePreconnect() { // rel type should be preconnect nsAutoString rel; if (!GetAttr(kNameSpaceID_None, nsGkAtoms::rel, rel)) { return; } uint32_t linkTypes = nsStyleLinkElement::ParseLinkTypes(rel, NodePrincipal()); if (!(linkTypes & ePRECONNECT)) { return; } nsCOMPtr<nsISpeculativeConnect> speculator(do_QueryInterface(nsContentUtils::GetIOService())); if (speculator) { nsCOMPtr<nsIURI> uri = GetHrefURI(); if (uri) { speculator->SpeculativeConnect(uri, nullptr); } } }
void HTMLTrackElement::LoadResource() { // Find our 'src' url nsAutoString src; if (!GetAttr(kNameSpaceID_None, nsGkAtoms::src, src)) { return; } nsCOMPtr<nsIURI> uri; nsresult rv = NewURIFromString(src, getter_AddRefs(uri)); NS_ENSURE_TRUE_VOID(NS_SUCCEEDED(rv)); LOG(PR_LOG_ALWAYS, ("%p Trying to load from src=%s", this, NS_ConvertUTF16toUTF8(src).get())); if (mChannel) { mChannel->Cancel(NS_BINDING_ABORTED); mChannel = nullptr; } rv = nsContentUtils::GetSecurityManager()-> CheckLoadURIWithPrincipal(NodePrincipal(), uri, nsIScriptSecurityManager::STANDARD); NS_ENSURE_TRUE_VOID(NS_SUCCEEDED(rv)); int16_t shouldLoad = nsIContentPolicy::ACCEPT; rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_MEDIA, uri, NodePrincipal(), static_cast<Element*>(this), NS_LITERAL_CSTRING("text/vtt"), // mime type nullptr, // extra &shouldLoad, nsContentUtils::GetContentPolicy(), nsContentUtils::GetSecurityManager()); NS_ENSURE_TRUE_VOID(NS_SUCCEEDED(rv)); if (NS_CP_REJECTED(shouldLoad)) { return; } CreateTextTrack(); // Check for a Content Security Policy to pass down to the channel // created to load the media content. nsCOMPtr<nsIChannelPolicy> channelPolicy; nsCOMPtr<nsIContentSecurityPolicy> csp; rv = NodePrincipal()->GetCsp(getter_AddRefs(csp)); NS_ENSURE_TRUE_VOID(NS_SUCCEEDED(rv)); if (csp) { channelPolicy = do_CreateInstance("@mozilla.org/nschannelpolicy;1"); if (!channelPolicy) { return; } channelPolicy->SetContentSecurityPolicy(csp); channelPolicy->SetLoadType(nsIContentPolicy::TYPE_MEDIA); } nsCOMPtr<nsIChannel> channel; nsCOMPtr<nsILoadGroup> loadGroup = OwnerDoc()->GetDocumentLoadGroup(); rv = NS_NewChannel(getter_AddRefs(channel), uri, nullptr, loadGroup, nullptr, nsIRequest::LOAD_NORMAL, channelPolicy); NS_ENSURE_TRUE_VOID(NS_SUCCEEDED(rv)); mLoadListener = new WebVTTLoadListener(this); rv = mLoadListener->LoadResource(); NS_ENSURE_TRUE_VOID(NS_SUCCEEDED(rv)); channel->SetNotificationCallbacks(mLoadListener); LOG(PR_LOG_DEBUG, ("opening webvtt channel")); rv = channel->AsyncOpen(mLoadListener, nullptr); NS_ENSURE_TRUE_VOID(NS_SUCCEEDED(rv)); mChannel = channel; }
void nsSVGElement::UpdateContentStyleRule() { NS_ASSERTION(!mContentStyleRule, "we already have a content style rule"); nsIDocument* doc = GetOwnerDoc(); if (!doc) { NS_ERROR("SVG element without owner document"); return; } nsCOMPtr<nsIURI> baseURI = GetBaseURI(); nsIURI *docURI = doc->GetDocumentURI(); nsICSSLoader* cssLoader = doc->CSSLoader(); nsCSSDeclaration* declaration = nsnull; nsCOMPtr<nsICSSParser> parser; nsresult rv = NS_OK; PRUint32 attrCount = mAttrsAndChildren.AttrCount(); for (PRUint32 i = 0; i < attrCount; ++i) { const nsAttrName* attrName = mAttrsAndChildren.AttrNameAt(i); if (!attrName->IsAtom() || !IsAttributeMapped(attrName->Atom())) continue; if (!declaration) { // Create the nsCSSDeclaration. declaration = new nsCSSDeclaration(); if (!declaration) { NS_WARNING("Failed to allocate nsCSSDeclaration"); return; } if (!declaration->InitializeEmpty()) { NS_WARNING("could not initialize nsCSSDeclaration"); declaration->RuleAbort(); // deletes declaration return; } // Try to fetch the CSS Parser from the document. rv = cssLoader->GetParserFor(nsnull, getter_AddRefs(parser)); if (NS_FAILED(rv)) { NS_WARNING("failed to get a css parser"); declaration->RuleAbort(); // deletes declaration return; } // SVG and CSS differ slightly in their interpretation of some of // the attributes. SVG allows attributes of the form: font-size="5" // (style="font-size: 5" if using a style attribute) // where CSS requires units: font-size="5pt" (style="font-size: 5pt") // Set a flag to pass information to the parser so that we can use // the CSS parser to parse the font-size attribute. Note that this // does *not* affect the use of CSS stylesheets, which will still // require units. parser->SetSVGMode(PR_TRUE); } nsAutoString name; attrName->Atom()->ToString(name); nsAutoString value; mAttrsAndChildren.AttrAt(i)->ToString(value); PRBool changed; parser->ParseProperty(nsCSSProps::LookupProperty(name), value, docURI, baseURI, NodePrincipal(), declaration, &changed); } if (declaration) { rv = NS_NewCSSStyleRule(getter_AddRefs(mContentStyleRule), nsnull, declaration); if (NS_FAILED(rv)) { NS_WARNING("could not create contentstylerule"); declaration->RuleAbort(); // deletes declaration } // Recycle the parser parser->SetSVGMode(PR_FALSE); cssLoader->RecycleParser(parser); } }
NS_IMETHODIMP nsXMLDocument::Load(const nsAString& aUrl, bool *aReturn) { bool hasHadScriptObject = true; nsIScriptGlobalObject* scriptObject = GetScriptHandlingObject(hasHadScriptObject); NS_ENSURE_STATE(scriptObject || !hasHadScriptObject); ReportUseOfDeprecatedMethod(this, "UseOfDOM3LoadMethodWarning"); NS_ENSURE_ARG_POINTER(aReturn); *aReturn = false; nsCOMPtr<nsIDocument> callingDoc = do_QueryInterface(nsContentUtils::GetDocumentFromContext()); nsIURI *baseURI = mDocumentURI; nsAutoCString charset; if (callingDoc) { baseURI = callingDoc->GetDocBaseURI(); charset = callingDoc->GetDocumentCharacterSet(); } // Create a new URI nsCOMPtr<nsIURI> uri; nsresult rv = NS_NewURI(getter_AddRefs(uri), aUrl, charset.get(), baseURI); if (NS_FAILED(rv)) { return rv; } // Check to see whether the current document is allowed to load this URI. // It's important to use the current document's principal for this check so // that we don't end up in a case where code with elevated privileges is // calling us and changing the principal of this document. // Enforce same-origin even for chrome loaders to avoid someone accidentally // using a document that content has a reference to and turn that into a // chrome document. nsCOMPtr<nsIPrincipal> principal = NodePrincipal(); if (!nsContentUtils::IsSystemPrincipal(principal)) { rv = principal->CheckMayLoad(uri, false, false); NS_ENSURE_SUCCESS(rv, rv); int16_t shouldLoad = nsIContentPolicy::ACCEPT; rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_XMLHTTPREQUEST, uri, principal, callingDoc ? callingDoc.get() : static_cast<nsIDocument*>(this), NS_LITERAL_CSTRING("application/xml"), nullptr, &shouldLoad, nsContentUtils::GetContentPolicy(), nsContentUtils::GetSecurityManager()); NS_ENSURE_SUCCESS(rv, rv); if (NS_CP_REJECTED(shouldLoad)) { return NS_ERROR_CONTENT_BLOCKED; } } else { // We're called from chrome, check to make sure the URI we're // about to load is also chrome. bool isChrome = false; if (NS_FAILED(uri->SchemeIs("chrome", &isChrome)) || !isChrome) { nsAutoCString spec; if (mDocumentURI) mDocumentURI->GetSpec(spec); nsAutoString error; error.AssignLiteral("Cross site loading using document.load is no " "longer supported. Use XMLHttpRequest instead."); nsCOMPtr<nsIScriptError> errorObject = do_CreateInstance(NS_SCRIPTERROR_CONTRACTID, &rv); NS_ENSURE_SUCCESS(rv, rv); rv = errorObject->InitWithWindowID(error, NS_ConvertUTF8toUTF16(spec), EmptyString(), 0, 0, nsIScriptError::warningFlag, "DOM", callingDoc ? callingDoc->InnerWindowID() : this->InnerWindowID()); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIConsoleService> consoleService = do_GetService(NS_CONSOLESERVICE_CONTRACTID); if (consoleService) { consoleService->LogMessage(errorObject); } return NS_ERROR_DOM_SECURITY_ERR; } } // Partial Reset, need to restore principal for security reasons and // event listener manager so that load listeners etc. will // remain. This should be done before the security check is done to // ensure that the document is reset even if the new document can't // be loaded. Note that we need to hold a strong ref to |principal| // here, because ResetToURI will null out our node principal before // setting the new one. nsRefPtr<nsEventListenerManager> elm(mListenerManager); mListenerManager = nullptr; // When we are called from JS we can find the load group for the page, // and add ourselves to it. This way any pending requests // will be automatically aborted if the user leaves the page. nsCOMPtr<nsILoadGroup> loadGroup; if (callingDoc) { loadGroup = callingDoc->GetDocumentLoadGroup(); } ResetToURI(uri, loadGroup, principal); mListenerManager = elm; // Create a channel nsCOMPtr<nsIInterfaceRequestor> req = nsContentUtils::GetSameOriginChecker(); NS_ENSURE_TRUE(req, NS_ERROR_OUT_OF_MEMORY); nsCOMPtr<nsIChannel> channel; // nsIRequest::LOAD_BACKGROUND prevents throbber from becoming active, // which in turn keeps STOP button from becoming active rv = NS_NewChannel(getter_AddRefs(channel), uri, nullptr, loadGroup, req, nsIRequest::LOAD_BACKGROUND); if (NS_FAILED(rv)) { return rv; } // StartDocumentLoad asserts that readyState is uninitialized, so // uninitialize it. SetReadyStateInternal make this transition invisible to // Web content. But before doing that, assert that the current readyState // is complete as it should be after the call to ResetToURI() above. MOZ_ASSERT(GetReadyStateEnum() == nsIDocument::READYSTATE_COMPLETE, "Bad readyState"); SetReadyStateInternal(nsIDocument::READYSTATE_UNINITIALIZED); // Prepare for loading the XML document "into oneself" nsCOMPtr<nsIStreamListener> listener; if (NS_FAILED(rv = StartDocumentLoad(kLoadAsData, channel, loadGroup, nullptr, getter_AddRefs(listener), false))) { NS_ERROR("nsXMLDocument::Load: Failed to start the document load."); return rv; } // After this point, if we error out of this method we should clear // mChannelIsPending. // Start an asynchronous read of the XML document rv = channel->AsyncOpen(listener, nullptr); if (NS_FAILED(rv)) { mChannelIsPending = false; return rv; } if (!mAsync) { nsCOMPtr<nsIThread> thread = do_GetCurrentThread(); nsAutoSyncOperation sync(this); mLoopingForSyncLoad = true; while (mLoopingForSyncLoad) { if (!NS_ProcessNextEvent(thread)) break; } // We set return to true unless there was a parsing error nsCOMPtr<nsIDOMNode> node = do_QueryInterface(GetRootElement()); if (node) { nsAutoString name, ns; if (NS_SUCCEEDED(node->GetLocalName(name)) && name.EqualsLiteral("parsererror") && NS_SUCCEEDED(node->GetNamespaceURI(ns)) && ns.EqualsLiteral("http://www.mozilla.org/newlayout/xml/parsererror.xml")) { //return is already false } else { *aReturn = true; } } } else { *aReturn = true; } return NS_OK; }
NS_IMETHODIMP WebBrowserPersistLocalDocument::GetPrincipal(nsIPrincipal** aPrincipal) { nsCOMPtr<nsIPrincipal> nodePrincipal = mDocument->NodePrincipal(); nodePrincipal.forget(aPrincipal); return NS_OK; }
void HTMLTrackElement::LoadResource() { // Find our 'src' url nsAutoString src; if (!GetAttr(kNameSpaceID_None, nsGkAtoms::src, src)) { return; } nsCOMPtr<nsIURI> uri; nsresult rv = NewURIFromString(src, getter_AddRefs(uri)); NS_ENSURE_TRUE_VOID(NS_SUCCEEDED(rv)); LOG(LogLevel::Info, ("%p Trying to load from src=%s", this, NS_ConvertUTF16toUTF8(src).get())); if (mChannel) { mChannel->Cancel(NS_BINDING_ABORTED); mChannel = nullptr; } rv = nsContentUtils::GetSecurityManager()-> CheckLoadURIWithPrincipal(NodePrincipal(), uri, nsIScriptSecurityManager::STANDARD); NS_ENSURE_TRUE_VOID(NS_SUCCEEDED(rv)); int16_t shouldLoad = nsIContentPolicy::ACCEPT; rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_MEDIA, uri, NodePrincipal(), static_cast<Element*>(this), NS_LITERAL_CSTRING("text/vtt"), // mime type nullptr, // extra &shouldLoad, nsContentUtils::GetContentPolicy(), nsContentUtils::GetSecurityManager()); NS_ENSURE_TRUE_VOID(NS_SUCCEEDED(rv)); if (NS_CP_REJECTED(shouldLoad)) { return; } // We may already have a TextTrack at this point if GetTrack() has already // been called. This happens, for instance, if script tries to get the // TextTrack before its mTrackElement has been bound to the DOM tree. if (!mTrack) { CreateTextTrack(); } nsCOMPtr<nsIChannel> channel; nsCOMPtr<nsILoadGroup> loadGroup = OwnerDoc()->GetDocumentLoadGroup(); rv = NS_NewChannel(getter_AddRefs(channel), uri, static_cast<Element*>(this), nsILoadInfo::SEC_NORMAL, nsIContentPolicy::TYPE_MEDIA, loadGroup); NS_ENSURE_TRUE_VOID(NS_SUCCEEDED(rv)); mListener = new WebVTTListener(this); rv = mListener->LoadResource(); NS_ENSURE_TRUE_VOID(NS_SUCCEEDED(rv)); channel->SetNotificationCallbacks(mListener); LOG(LogLevel::Debug, ("opening webvtt channel")); rv = channel->AsyncOpen(mListener, nullptr); NS_ENSURE_TRUE_VOID(NS_SUCCEEDED(rv)); mChannel = channel; }
nsresult HTMLLinkElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName, const nsAttrValue* aValue, bool aNotify) { // It's safe to call ResetLinkState here because our new attr value has // already been set or unset. ResetLinkState needs the updated attribute // value because notifying the document that content states have changed will // call IntrinsicState, which will try to get updated information about the // visitedness from Link. if (aName == nsGkAtoms::href && kNameSpaceID_None == aNameSpaceID) { bool hasHref = aValue; Link::ResetLinkState(!!aNotify, hasHref); if (IsInUncomposedDoc()) { CreateAndDispatchEvent(OwnerDoc(), NS_LITERAL_STRING("DOMLinkChanged")); } } if (aValue) { if (aNameSpaceID == kNameSpaceID_None && (aName == nsGkAtoms::href || aName == nsGkAtoms::rel || aName == nsGkAtoms::title || aName == nsGkAtoms::media || aName == nsGkAtoms::type)) { bool dropSheet = false; if (aName == nsGkAtoms::rel) { nsAutoString value; aValue->ToString(value); uint32_t linkTypes = nsStyleLinkElement::ParseLinkTypes(value, NodePrincipal()); if (GetSheet()) { dropSheet = !(linkTypes & nsStyleLinkElement::eSTYLESHEET); } else if (linkTypes & eHTMLIMPORT) { UpdateImport(); } else if ((linkTypes & ePRECONNECT) && IsInComposedDoc()) { UpdatePreconnect(); } } if (aName == nsGkAtoms::href) { UpdateImport(); if (IsInComposedDoc()) { UpdatePreconnect(); } } UpdateStyleSheetInternal(nullptr, nullptr, dropSheet || (aName == nsGkAtoms::title || aName == nsGkAtoms::media || aName == nsGkAtoms::type)); } } else { // Since removing href or rel makes us no longer link to a // stylesheet, force updates for those too. if (aNameSpaceID == kNameSpaceID_None) { if (aName == nsGkAtoms::href || aName == nsGkAtoms::rel || aName == nsGkAtoms::title || aName == nsGkAtoms::media || aName == nsGkAtoms::type) { UpdateStyleSheetInternal(nullptr, nullptr, true); } if (aName == nsGkAtoms::href || aName == nsGkAtoms::rel) { UpdateImport(); } } } return nsGenericHTMLElement::AfterSetAttr(aNameSpaceID, aName, aValue, aNotify); }