nsresult rv; NS_WITH_SERVICE(nsIScriptSecurityManager, secMan, NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv); if (NS_FAILED(rv)) return rv; nsIURI* docURI; rv = mDocument->GetBaseURL(docURI); if (NS_FAILED(rv) || !docURI) return NS_ERROR_FAILURE; rv = secMan->CheckLoadURI(docURI, aURL, nsIScriptSecurityManager::ALLOW_CHROME); NS_IF_RELEASE(docURI); if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
PRBool isForViewSource = PR_FALSE; if (aParserToUnblock) { nsAutoString command; aParserToUnblock->GetCommand(command); isForViewSource = command.Equals(NS_LITERAL_STRING("view-source")); } if (!isForViewSource) { nsresult rv; NS_WITH_SERVICE(nsIScriptSecurityManager, secMan, NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv); if (NS_FAILED(rv)) return rv; nsIURI* docURI; rv = mDocument->GetBaseURL(docURI); if (NS_FAILED(rv) || !docURI) return NS_ERROR_FAILURE; rv = secMan->CheckLoadURI(docURI, aURL, nsIScriptSecurityManager::ALLOW_CHROME); NS_IF_RELEASE(docURI); if (NS_FAILED(rv)) return rv; }
CSSLoaderImpl::LoadStyleLink(nsIContent* aElement,                             nsIURI* aURL,                              const nsString& aTitle,                              const nsString& aMedia,                              PRInt32 aDefaultNameSpaceID,                             PRInt32 aDocIndex,                             nsIParser* aParserToUnblock,                             PRBool& aCompleted,                             nsICSSLoaderObserver* aObserver){  NS_ASSERTION(mDocument, "not initialized");  if (! mDocument) {    return NS_ERROR_NOT_INITIALIZED;  }  //-- Make sure this page is allowed to load this URL  nsresult rv;  NS_WITH_SERVICE(nsIScriptSecurityManager, secMan, NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);  if (NS_FAILED(rv)) return rv;  nsIURI* docURI;  rv = mDocument->GetBaseURL(docURI);  if (NS_FAILED(rv) || !docURI) return NS_ERROR_FAILURE;  rv = secMan->CheckLoadURI(docURI, aURL, nsIScriptSecurityManager::ALLOW_CHROME);  NS_IF_RELEASE(docURI);  if (NS_FAILED(rv)) return NS_ERROR_FAILURE;  // XXX need to add code to cancel any pending sheets for element  nsresult result = NS_ERROR_NULL_POINTER;  aCompleted = PR_TRUE;  if (aURL) {    URLKey  key(aURL);    PRBool  sheetModified = PR_FALSE;    nsICSSStyleSheet* sheet = (nsICSSStyleSheet*)mLoadedSheets.Get(&key);#ifdef INCLUDE_XUL    if (!sheet && IsChromeURI(aURL)) {      nsCOMPtr<nsIXULPrototypeCache> cache(do_GetService("@mozilla.org/xul/xul-prototype-cache;1"));      if (cache) {        PRBool enabled;        cache->GetEnabled(&enabled);        if (enabled) {          nsCOMPtr<nsICSSStyleSheet> cachedSheet;          cache->GetStyleSheet(aURL, getter_AddRefs(cachedSheet));          if (cachedSheet)            sheet = cachedSheet;        }      }    }#endif    if (sheet && (NS_OK == sheet->IsModified(&sheetModified)) && sheetModified) {  // if dirty, forget it      sheet = nsnull;    }    if (sheet) {  // already have one fully loaded and unmodified      nsICSSStyleSheet* clone = nsnull;      result = sheet->Clone(clone);      if (NS_SUCCEEDED(result)) {        PrepareSheet(clone, aTitle, aMedia);        if (aParserToUnblock || (0 == mLoadingSheets.Count())) {           // we either have a parser that needs the sheet now, or we aren't currently          // busy.  go ahead and put the sheet right into the doc.          result = InsertSheetInDoc(clone, aDocIndex, aElement, PR_TRUE, aObserver);        }        else {  // add to pending list          result = AddPendingSheet(clone, aDocIndex, aElement, aObserver);        }        NS_RELEASE(clone);      }    }    else {  // need to load it      SheetLoadData* data = new SheetLoadData(this, aURL, aTitle, aMedia, aDefaultNameSpaceID,                                              aElement, aDocIndex,                                               aParserToUnblock, PR_FALSE,                                              aObserver);      if (data == nsnull) {        result = NS_ERROR_OUT_OF_MEMORY;      }      else {        NS_ADDREF(data);        if (IsAlternate(aTitle) && mLoadingSheets.Count() &&            (! mLoadingSheets.Get(&key)) && (! aParserToUnblock)) {          // this is an alternate, and we're already loading others, but not loading this, defer it          mPendingAlternateSheets.AppendElement(data);          result = NS_OK;        }        else {          if (aParserToUnblock) {            data->mDidBlockParser = PR_TRUE;          }          result = LoadSheet(key, data);        }      }      aCompleted = PR_FALSE;    }  }  return result;}