void nsHTMLTags::AddTag(int aEnum, const char *aTagName) { if (!kExpandedTagUnicodeTableInited) { memset(kExpandedTagUnicodeTable, 0, sizeof(kExpandedTagUnicodeTable)); kExpandedTagUnicodeTableInited = true; } int len = strlen(aTagName); NS_ASSERTION(len <= NS_HTMLTAG_NAME_MAX_LENGTH, "bad tag"); PRUnichar *buf = (PRUnichar*)malloc((NS_HTMLTAG_NAME_MAX_LENGTH + 1) * sizeof(PRUnichar)); PRUnichar *buf_under = (PRUnichar*)malloc((NS_HTMLTAG_NAME_MAX_LENGTH + 1) * sizeof(PRUnichar)); int i = 0; bool hasUnderScore = false; for (const char *p = aTagName; *p; p++) { char ch = *p; if (ch <= 'Z' && ch >= 'A') ch |= 0x20; if (ch == '_') ch = '-'; buf[i] = ch; if (ch == '-') { ch = '_'; hasUnderScore = true; } buf_under[i] = ch; if (++i >= NS_HTMLTAG_NAME_MAX_LENGTH - 1) break; } buf[i] = 0; buf_under[i] = 0; int index = aEnum - eHTMLTag_userdefined; if (index < 0 || index >= sizeof(kExpandedTagUnicodeTable)/sizeof(kExpandedTagUnicodeTable[0])) { free(buf); free(buf_under); return; } // remove old tags that are maapped to the enum RemoveExpandedTag(index); // add new tags PRUint32 tag = NS_PTR_TO_INT32(PL_HashTableLookupConst(gTagTable, buf)); if (tag == eHTMLTag_unknown) { kExpandedTagUnicodeTable[index] = buf; PL_HashTableAdd(gTagTable, buf, NS_INT32_TO_PTR(aEnum)); if (hasUnderScore) { kExpandedTagUnicodeUnderScoreTable[index] = buf_under; PL_HashTableAdd(gTagTable, buf_under, NS_INT32_TO_PTR(aEnum)); } else { free(buf_under); } } else { free(buf); free(buf_under); } if (len > sMaxTagNameLength) { sMaxTagNameLength = len; } }
nsresult JavaToXPTCStubMap::Add(jint aJavaObjectHashCode, nsJavaXPTCStub* aProxy) { nsAutoLock lock(gJavaXPCOMLock); Entry* e = static_cast<Entry*> (PL_DHashTableOperate(mHashTable, NS_INT32_TO_PTR(aJavaObjectHashCode), PL_DHASH_ADD)); if (!e) return NS_ERROR_FAILURE; NS_ASSERTION(e->key == nsnull, "XPTCStub for given Java object already exists in hash table"); e->key = aJavaObjectHashCode; e->xptcstub = aProxy; #ifdef DEBUG_JAVAXPCOM nsIInterfaceInfo* iface_info; aProxy->GetInterfaceInfo(&iface_info); nsIID* iid; iface_info->GetInterfaceIID(&iid); char* iid_str = iid->ToString(); LOG(("+ JavaToXPTCStubMap (Java=%08x | XPCOM=%08x | IID=%s)\n", (PRUint32) aJavaObjectHashCode, (PRUint32) aProxy, iid_str)); NS_Free(iid_str); nsMemory::Free(iid); NS_RELEASE(iface_info); #endif return NS_OK; }
bool SpanningCellSorter::AddCell(int32_t aColSpan, int32_t aRow, int32_t aCol) { NS_ASSERTION(mState == ADDING, "cannot call AddCell after GetNext"); NS_ASSERTION(aColSpan >= ARRAY_BASE, "cannot add cells with colspan<2"); Item *i = (Item*) mozilla::AutoStackArena::Allocate(sizeof(Item)); NS_ENSURE_TRUE(i != nullptr, false); i->row = aRow; i->col = aCol; if (UseArrayForSpan(aColSpan)) { int32_t index = SpanToIndex(aColSpan); i->next = mArray[index]; mArray[index] = i; } else { HashTableEntry *entry = static_cast<HashTableEntry*> (PL_DHashTableAdd(&mHashTable, NS_INT32_TO_PTR(aColSpan), fallible)); NS_ENSURE_TRUE(entry, false); NS_ASSERTION(entry->mColSpan == 0 || entry->mColSpan == aColSpan, "wrong entry"); NS_ASSERTION((entry->mColSpan == 0) == (entry->mItems == nullptr), "entry should be either new or properly initialized"); entry->mColSpan = aColSpan; i->next = entry->mItems; entry->mItems = i; } return true; }
nsresult JavaToXPTCStubMap::Find(jint aJavaObjectHashCode, const nsIID& aIID, nsJavaXPTCStub** aResult) { NS_PRECONDITION(aResult != nsnull, "null ptr"); if (!aResult) return NS_ERROR_FAILURE; nsAutoLock lock(gJavaXPCOMLock); *aResult = nsnull; Entry* e = static_cast<Entry*> (PL_DHashTableOperate(mHashTable, NS_INT32_TO_PTR(aJavaObjectHashCode), PL_DHASH_LOOKUP)); if (PL_DHASH_ENTRY_IS_FREE(e)) return NS_OK; nsresult rv = e->xptcstub->QueryInterface(aIID, (void**) aResult); #ifdef DEBUG_JAVAXPCOM if (NS_SUCCEEDED(rv)) { char* iid_str = aIID.ToString(); LOG(("< JavaToXPTCStubMap (Java=%08x | XPCOM=%08x | IID=%s)\n", (PRUint32) aJavaObjectHashCode, (PRUint32) *aResult, iid_str)); PR_Free(iid_str); } #endif // NS_NOINTERFACE is not an error condition if (rv == NS_NOINTERFACE) rv = NS_OK; return rv; }
static int DumpSerialNumbers(PLHashEntry* aHashEntry, int aIndex, void* aClosure) { serialNumberRecord* record = reinterpret_cast<serialNumberRecord *>(aHashEntry->value); #ifdef HAVE_CPP_DYNAMIC_CAST_TO_VOID_PTR fprintf((FILE*) aClosure, "%ld @%p (%d references; %d from COMPtrs)\n", record->serialNumber, NS_INT32_TO_PTR(aHashEntry->key), record->refCount, record->COMPtrCount); #else fprintf((FILE*) aClosure, "%ld @%p (%d references)\n", record->serialNumber, NS_INT32_TO_PTR(aHashEntry->key), record->refCount); #endif return HT_ENUMERATE_NEXT; }
// static nsresult nsHTMLTags::AddRefTable(void) { if (gTableRefCount++ == 0) { NS_ASSERTION(!gTagTable, "pre existing hash!"); gTagTable = PL_NewHashTable(64, HTMLTagsHashCodeUCPtr, HTMLTagsKeyCompareUCPtr, PL_CompareValues, nsnull, nsnull); NS_ENSURE_TRUE(gTagTable, NS_ERROR_OUT_OF_MEMORY); // Fill in gTagTable with the above static PRUnichar strings as // keys and the value of the corresponding enum as the value in // the table. PRInt32 i; for (i = 0; i < NS_HTML_TAG_MAX; ++i) { PRUint32 len = nsCRT::strlen(kTagUnicodeTable[i]); PL_HashTableAdd(gTagTable, kTagUnicodeTable[i], NS_INT32_TO_PTR(i + 1)); if (len > sMaxTagNameLength) { sMaxTagNameLength = len; } } //NS_ASSERTION(sMaxTagNameLength == NS_HTMLTAG_NAME_MAX_LENGTH, // "NS_HTMLTAG_NAME_MAX_LENGTH not set correctly!"); // Fill in our static atom pointers NS_RegisterStaticAtoms(kTagAtoms_info, NS_ARRAY_LENGTH(kTagAtoms_info)); #ifdef DEBUG { // let's verify that all names in the the table are lowercase... for (i = 0; i < NS_HTML_TAG_MAX; ++i) { nsCAutoString temp1(kTagAtoms_info[i].mString); nsCAutoString temp2(kTagAtoms_info[i].mString); ToLowerCase(temp1); NS_ASSERTION(temp1.Equals(temp2), "upper case char in table"); } // let's verify that all names in the unicode strings above are // correct. for (i = 0; i < NS_HTML_TAG_MAX; ++i) { nsAutoString temp1(kTagUnicodeTable[i]); nsAutoString temp2; temp2.AssignWithConversion(kTagAtoms_info[i].mString); NS_ASSERTION(temp1.Equals(temp2), "Bad unicode tag name!"); } } #endif } return NS_OK; }
void nsTraceRefcntImpl::SetActivityIsLegal(bool aLegal) { #ifdef NS_IMPL_REFCNT_LOGGING if (gActivityTLS == BAD_TLS_INDEX) PR_NewThreadPrivateIndex(&gActivityTLS, nullptr); PR_SetThreadPrivate(gActivityTLS, NS_INT32_TO_PTR(!aLegal)); #endif }
nsresult JavaToXPTCStubMap::Remove(jint aJavaObjectHashCode) { PL_DHashTableOperate(mHashTable, NS_INT32_TO_PTR(aJavaObjectHashCode), PL_DHASH_REMOVE); #ifdef DEBUG_JAVAXPCOM LOG(("- JavaToXPTCStubMap (Java=%08x)\n", (PRUint32) aJavaObjectHashCode)); #endif return NS_OK; }
bool SpanningCellSorter::AddCell(PRInt32 aColSpan, PRInt32 aRow, PRInt32 aCol) { NS_ASSERTION(mState == ADDING, "cannot call AddCell after GetNext"); NS_ASSERTION(aColSpan >= ARRAY_BASE, "cannot add cells with colspan<2"); Item *i = (Item*) mozilla::AutoStackArena::Allocate(sizeof(Item)); NS_ENSURE_TRUE(i != nsnull, false); i->row = aRow; i->col = aCol; if (UseArrayForSpan(aColSpan)) { PRInt32 index = SpanToIndex(aColSpan); i->next = mArray[index]; mArray[index] = i; } else { if (!mHashTable.entryCount && !PL_DHashTableInit(&mHashTable, &HashTableOps, nsnull, sizeof(HashTableEntry), PL_DHASH_MIN_SIZE)) { NS_NOTREACHED("table init failed"); mHashTable.entryCount = 0; return false; } HashTableEntry *entry = static_cast<HashTableEntry*> (PL_DHashTableOperate(&mHashTable, NS_INT32_TO_PTR(aColSpan), PL_DHASH_ADD)); NS_ENSURE_TRUE(entry, false); NS_ASSERTION(entry->mColSpan == 0 || entry->mColSpan == aColSpan, "wrong entry"); NS_ASSERTION((entry->mColSpan == 0) == (entry->mItems == nsnull), "entry should be either new or properly initialized"); entry->mColSpan = aColSpan; i->next = entry->mItems; entry->mItems = i; } return true; }
XPT_GetAddrForOffset(XPTCursor *cursor, uint32_t offset) { return XPT_HashTableLookup(cursor->state->pool->offset_map, NS_INT32_TO_PTR(offset)); }
NS_IMETHODIMP nsPluginStreamListenerPeer::OnDataAvailable(nsIRequest *request, nsISupports* aContext, nsIInputStream *aIStream, uint64_t sourceOffset, uint32_t aLength) { NS_ASSERTION(mRequests.IndexOfObject(GetBaseRequest(request)) != -1, "Received OnDataAvailable for untracked request."); if (mRequestFailed) return NS_ERROR_FAILURE; if (mAbort) { uint32_t magicNumber = 0; // set it to something that is not the magic number. nsCOMPtr<nsISupportsPRUint32> container = do_QueryInterface(aContext); if (container) container->GetData(&magicNumber); if (magicNumber != MAGIC_REQUEST_CONTEXT) { // this is not one of our range requests mAbort = false; return NS_BINDING_ABORTED; } } nsresult rv = NS_OK; if (!mPStreamListener) return NS_ERROR_FAILURE; const char * url = nullptr; GetURL(&url); PLUGIN_LOG(PLUGIN_LOG_NOISY, ("nsPluginStreamListenerPeer::OnDataAvailable this=%p request=%p, offset=%llu, length=%u, url=%s\n", this, request, sourceOffset, aLength, url ? url : "no url set")); // if the plugin has requested an AsFileOnly stream, then don't // call OnDataAvailable if (mStreamType != NP_ASFILEONLY) { // get the absolute offset of the request, if one exists. nsCOMPtr<nsIByteRangeRequest> brr = do_QueryInterface(request); if (brr) { if (!mDataForwardToRequest) return NS_ERROR_FAILURE; int64_t absoluteOffset64 = 0; brr->GetStartRange(&absoluteOffset64); // XXX handle 64-bit for real int32_t absoluteOffset = (int32_t)int64_t(absoluteOffset64); // we need to track how much data we have forwarded to the // plugin. // FIXME: http://bugzilla.mozilla.org/show_bug.cgi?id=240130 // // Why couldn't this be tracked on the plugin info, and not in a // *hash table*? nsPRUintKey key(absoluteOffset); int32_t amtForwardToPlugin = NS_PTR_TO_INT32(mDataForwardToRequest->Get(&key)); mDataForwardToRequest->Put(&key, NS_INT32_TO_PTR(amtForwardToPlugin + aLength)); SetStreamOffset(absoluteOffset + amtForwardToPlugin); } nsCOMPtr<nsIInputStream> stream = aIStream; // if we are caching the file ourselves to disk, we want to 'tee' off // the data as the plugin read from the stream. We do this by the magic // of an input stream tee. if (mFileCacheOutputStream) { rv = NS_NewInputStreamTee(getter_AddRefs(stream), aIStream, mFileCacheOutputStream); if (NS_FAILED(rv)) return rv; } rv = mPStreamListener->OnDataAvailable(this, stream, aLength); // if a plugin returns an error, the peer must kill the stream // else the stream and PluginStreamListener leak if (NS_FAILED(rv)) request->Cancel(rv); } else { // if we don't read from the stream, OnStopRequest will never be called char* buffer = new char[aLength]; uint32_t amountRead, amountWrote = 0; rv = aIStream->Read(buffer, aLength, &amountRead); // if we are caching this to disk ourselves, lets write the bytes out. if (mFileCacheOutputStream) { while (amountWrote < amountRead && NS_SUCCEEDED(rv)) { rv = mFileCacheOutputStream->Write(buffer, amountRead, &amountWrote); } } delete [] buffer; } return rv; }
//-------------------------------------------------------------- nsCharsetAlias2::nsCharsetAlias2() { mDelegate = nsnull; // delay the load of mDelegate untill we need it. } //-------------------------------------------------------------- nsCharsetAlias2::~nsCharsetAlias2() { if(mDelegate) delete mDelegate; } // static const char* kAliases[][3] = { // Triple with { lower-case test string, out string, length of out string } { "iso-8859-1", "ISO-8859-1", (const char*)NS_INT32_TO_PTR(10) }, { "utf-8", "UTF-8", (const char*)NS_INT32_TO_PTR(5) }, { "x-sjis", "Shift_JIS", (const char*)NS_INT32_TO_PTR(9) }, { "shift_jis", "Shift_JIS", (const char*)NS_INT32_TO_PTR(9) } }; //-------------------------------------------------------------- NS_IMETHODIMP nsCharsetAlias2::GetPreferred(const nsACString& aAlias, nsACString& oResult) { if (aAlias.IsEmpty()) return NS_ERROR_NULL_POINTER; NS_TIMELINE_START_TIMER("nsCharsetAlias2:GetPreferred"); // Delay loading charsetalias.properties by hardcoding the most // frequent aliases. Note that it's possible to recur in to this
nsresult txXSLTNumber::getValueList(Expr* aValueExpr, txPattern* aCountPattern, txPattern* aFromPattern, LevelType aLevel, txIEvalContext* aContext, txList& aValues, nsAString& aValueString) { aValueString.Truncate(); nsresult rv = NS_OK; // If the value attribute exists then use that if (aValueExpr) { nsRefPtr<txAExprResult> result; rv = aValueExpr->evaluate(aContext, getter_AddRefs(result)); NS_ENSURE_SUCCESS(rv, rv); double value = result->numberValue(); if (MOZ_DOUBLE_IS_INFINITE(value) || MOZ_DOUBLE_IS_NaN(value) || value < 0.5) { txDouble::toString(value, aValueString); return NS_OK; } aValues.add(NS_INT32_TO_PTR((int32_t)floor(value + 0.5))); return NS_OK; } // Otherwise use count/from/level txPattern* countPattern = aCountPattern; bool ownsCountPattern = false; const txXPathNode& currNode = aContext->getContextNode(); // Parse count- and from-attributes if (!aCountPattern) { ownsCountPattern = true; txNodeTest* nodeTest; uint16_t nodeType = txXPathNodeUtils::getNodeType(currNode); switch (nodeType) { case txXPathNodeType::ELEMENT_NODE: { nsCOMPtr<nsIAtom> localName = txXPathNodeUtils::getLocalName(currNode); int32_t namespaceID = txXPathNodeUtils::getNamespaceID(currNode); nodeTest = new txNameTest(0, localName, namespaceID, txXPathNodeType::ELEMENT_NODE); break; } case txXPathNodeType::TEXT_NODE: case txXPathNodeType::CDATA_SECTION_NODE: { nodeTest = new txNodeTypeTest(txNodeTypeTest::TEXT_TYPE); break; } case txXPathNodeType::PROCESSING_INSTRUCTION_NODE: { txNodeTypeTest* typeTest; typeTest = new txNodeTypeTest(txNodeTypeTest::PI_TYPE); if (typeTest) { nsAutoString nodeName; txXPathNodeUtils::getNodeName(currNode, nodeName); typeTest->setNodeName(nodeName); } nodeTest = typeTest; break; } case txXPathNodeType::COMMENT_NODE: { nodeTest = new txNodeTypeTest(txNodeTypeTest::COMMENT_TYPE); break; } case txXPathNodeType::DOCUMENT_NODE: case txXPathNodeType::ATTRIBUTE_NODE: default: { // this won't match anything as we walk up the tree // but it's what the spec says to do nodeTest = new txNameTest(0, nsGkAtoms::_asterix, 0, nodeType); break; } } NS_ENSURE_TRUE(nodeTest, NS_ERROR_OUT_OF_MEMORY); countPattern = new txStepPattern(nodeTest, false); if (!countPattern) { // XXX error reporting delete nodeTest; return NS_ERROR_OUT_OF_MEMORY; } } // Generate list of values depending on the value of the level-attribute // level = "single" if (aLevel == eLevelSingle) { txXPathTreeWalker walker(currNode); do { if (aFromPattern && !walker.isOnNode(currNode) && aFromPattern->matches(walker.getCurrentPosition(), aContext)) { break; } if (countPattern->matches(walker.getCurrentPosition(), aContext)) { aValues.add(NS_INT32_TO_PTR(getSiblingCount(walker, countPattern, aContext))); break; } } while (walker.moveToParent()); // Spec says to only match ancestors that are decendants of the // ancestor that matches the from-pattern, so keep going to make // sure that there is an ancestor that does. if (aFromPattern && aValues.getLength()) { bool hasParent; while ((hasParent = walker.moveToParent())) { if (aFromPattern->matches(walker.getCurrentPosition(), aContext)) { break; } } if (!hasParent) { aValues.clear(); } } } // level = "multiple" else if (aLevel == eLevelMultiple) { // find all ancestor-or-selfs that matches count until... txXPathTreeWalker walker(currNode); bool matchedFrom = false; do { if (aFromPattern && !walker.isOnNode(currNode) && aFromPattern->matches(walker.getCurrentPosition(), aContext)) { //... we find one that matches from matchedFrom = true; break; } if (countPattern->matches(walker.getCurrentPosition(), aContext)) { aValues.add(NS_INT32_TO_PTR(getSiblingCount(walker, countPattern, aContext))); } } while (walker.moveToParent()); // Spec says to only match ancestors that are decendants of the // ancestor that matches the from-pattern, so if none did then // we shouldn't search anything if (aFromPattern && !matchedFrom) { aValues.clear(); } } // level = "any" else if (aLevel == eLevelAny) { int32_t value = 0; bool matchedFrom = false; txXPathTreeWalker walker(currNode); do { if (aFromPattern && !walker.isOnNode(currNode) && aFromPattern->matches(walker.getCurrentPosition(), aContext)) { matchedFrom = true; break; } if (countPattern->matches(walker.getCurrentPosition(), aContext)) { ++value; } } while (getPrevInDocumentOrder(walker)); // Spec says to only count nodes that follows the first node that // matches the from pattern. So so if none did then we shouldn't // count any if (aFromPattern && !matchedFrom) { value = 0; } if (value) { aValues.add(NS_INT32_TO_PTR(value)); } } if (ownsCountPattern) { delete countPattern; } return NS_OK; }
nsresult txMozillaXMLOutput::startHTMLElement(nsIContent* aElement, PRBool aIsHTML) { nsresult rv = NS_OK; nsIAtom *atom = aElement->Tag(); if ((atom != txHTMLAtoms::tr || !aIsHTML) && NS_PTR_TO_INT32(mTableStateStack.peek()) == ADDED_TBODY) { PRUint32 last = mCurrentNodeStack.Count() - 1; NS_ASSERTION(last != (PRUint32)-1, "empty stack"); mCurrentNode = mCurrentNodeStack.SafeObjectAt(last); mCurrentNodeStack.RemoveObjectAt(last); mTableStateStack.pop(); } if (atom == txHTMLAtoms::table && aIsHTML) { mTableState = TABLE; } else if (atom == txHTMLAtoms::tr && aIsHTML && NS_PTR_TO_INT32(mTableStateStack.peek()) == TABLE) { nsCOMPtr<nsIContent> tbody; rv = createHTMLElement(nsGkAtoms::tbody, getter_AddRefs(tbody)); NS_ENSURE_SUCCESS(rv, rv); rv = mCurrentNode->AppendChildTo(tbody, PR_TRUE); NS_ENSURE_SUCCESS(rv, rv); rv = mTableStateStack.push(NS_INT32_TO_PTR(ADDED_TBODY)); NS_ENSURE_SUCCESS(rv, rv); if (!mCurrentNodeStack.AppendObject(tbody)) { return NS_ERROR_OUT_OF_MEMORY; } mCurrentNode = tbody; } else if (atom == txHTMLAtoms::head && mOutputFormat.mMethod == eHTMLOutput) { // Insert META tag, according to spec, 16.2, like // <META http-equiv="Content-Type" content="text/html; charset=EUC-JP"> nsCOMPtr<nsIContent> meta; rv = createHTMLElement(nsGkAtoms::meta, getter_AddRefs(meta)); NS_ENSURE_SUCCESS(rv, rv); rv = meta->SetAttr(kNameSpaceID_None, nsGkAtoms::httpEquiv, NS_LITERAL_STRING("Content-Type"), PR_FALSE); NS_ENSURE_SUCCESS(rv, rv); nsAutoString metacontent; metacontent.Append(mOutputFormat.mMediaType); metacontent.AppendLiteral("; charset="); metacontent.Append(mOutputFormat.mEncoding); rv = meta->SetAttr(kNameSpaceID_None, nsGkAtoms::content, metacontent, PR_FALSE); NS_ENSURE_SUCCESS(rv, rv); // No need to notify since aElement hasn't been inserted yet NS_ASSERTION(!aElement->IsInDoc(), "should not be in doc"); rv = aElement->AppendChildTo(meta, PR_FALSE); NS_ENSURE_SUCCESS(rv, rv); } return NS_OK; }
nsresult txMozillaXMLOutput::startElementInternal(nsIAtom* aPrefix, nsIAtom* aLocalName, PRInt32 aNsID) { TX_ENSURE_CURRENTNODE; if (mBadChildLevel) { ++mBadChildLevel; PR_LOG(txLog::xslt, PR_LOG_DEBUG, ("startElement, mBadChildLevel = %d\n", mBadChildLevel)); return NS_OK; } nsresult rv = closePrevious(PR_TRUE); NS_ENSURE_SUCCESS(rv, rv); // Push and init state if (mTreeDepth == MAX_REFLOW_DEPTH) { // eCloseElement couldn't add the parent so we fail as well or we've // reached the limit of the depth of the tree that we allow. ++mBadChildLevel; PR_LOG(txLog::xslt, PR_LOG_DEBUG, ("startElement, mBadChildLevel = %d\n", mBadChildLevel)); return NS_OK; } ++mTreeDepth; rv = mTableStateStack.push(NS_INT32_TO_PTR(mTableState)); NS_ENSURE_SUCCESS(rv, rv); if (!mCurrentNodeStack.AppendObject(mCurrentNode)) { return NS_ERROR_OUT_OF_MEMORY; } mTableState = NORMAL; mOpenedElementIsHTML = PR_FALSE; // Create the element nsCOMPtr<nsINodeInfo> ni; ni = mNodeInfoManager->GetNodeInfo(aLocalName, aPrefix, aNsID); NS_ENSURE_TRUE(ni, NS_ERROR_OUT_OF_MEMORY); NS_NewElement(getter_AddRefs(mOpenedElement), aNsID, ni.forget(), PR_FALSE); // Set up the element and adjust state if (!mNoFixup) { if (aNsID == kNameSpaceID_XHTML) { mOpenedElementIsHTML = (mOutputFormat.mMethod == eHTMLOutput); rv = startHTMLElement(mOpenedElement, mOpenedElementIsHTML); NS_ENSURE_SUCCESS(rv, rv); } } if (mCreatingNewDocument) { // Handle all sorts of stylesheets nsCOMPtr<nsIStyleSheetLinkingElement> ssle = do_QueryInterface(mOpenedElement); if (ssle) { ssle->InitStyleLinkElement(PR_FALSE); ssle->SetEnableUpdates(PR_FALSE); } } return NS_OK; }
void txMozillaXMLOutput::startHTMLElement(nsIDOMElement* aElement, PRBool aXHTML) { nsresult rv = NS_OK; nsCOMPtr<nsIContent> content = do_QueryInterface(aElement); nsIAtom *atom = content->Tag(); mDontAddCurrent = (atom == txHTMLAtoms::script); if ((atom != txHTMLAtoms::tr || aXHTML) && NS_PTR_TO_INT32(mTableStateStack.peek()) == ADDED_TBODY) { nsCOMPtr<nsIDOMNode> parent; mCurrentNode->GetParentNode(getter_AddRefs(parent)); mCurrentNode.swap(parent); mTableStateStack.pop(); } if (atom == txHTMLAtoms::table && !aXHTML) { mTableState = TABLE; } else if (atom == txHTMLAtoms::tr && !aXHTML && NS_PTR_TO_INT32(mTableStateStack.peek()) == TABLE) { nsCOMPtr<nsIDOMElement> elem; rv = createHTMLElement(NS_LITERAL_STRING("tbody"), getter_AddRefs(elem)); if (NS_FAILED(rv)) { return; } nsCOMPtr<nsIDOMNode> dummy; rv = mCurrentNode->AppendChild(elem, getter_AddRefs(dummy)); if (NS_FAILED(rv)) { return; } rv = mTableStateStack.push(NS_INT32_TO_PTR(ADDED_TBODY)); if (NS_FAILED(rv)) { return; } mCurrentNode = elem; } else if (atom == txHTMLAtoms::head && mOutputFormat.mMethod == eHTMLOutput) { // Insert META tag, according to spec, 16.2, like // <META http-equiv="Content-Type" content="text/html; charset=EUC-JP"> nsCOMPtr<nsIDOMElement> meta; rv = createHTMLElement(NS_LITERAL_STRING("meta"), getter_AddRefs(meta)); if (NS_FAILED(rv)) { return; } rv = meta->SetAttribute(NS_LITERAL_STRING("http-equiv"), NS_LITERAL_STRING("Content-Type")); NS_ASSERTION(NS_SUCCEEDED(rv), "Can't set http-equiv on meta"); nsAutoString metacontent; metacontent.Append(mOutputFormat.mMediaType); metacontent.AppendLiteral("; charset="); metacontent.Append(mOutputFormat.mEncoding); rv = meta->SetAttribute(NS_LITERAL_STRING("content"), metacontent); NS_ASSERTION(NS_SUCCEEDED(rv), "Can't set content on meta"); nsCOMPtr<nsIDOMNode> dummy; rv = aElement->AppendChild(meta, getter_AddRefs(dummy)); NS_ASSERTION(NS_SUCCEEDED(rv), "Can't append meta"); } }
void txMozillaXMLOutput::startElement(const nsAString& aName, const PRInt32 aNsID) { TX_ENSURE_CURRENTNODE; if (mBadChildLevel) { ++mBadChildLevel; PR_LOG(txLog::xslt, PR_LOG_DEBUG, ("startElement, mBadChildLevel = %d\n", mBadChildLevel)); return; } closePrevious(eCloseElement | eFlushText); if (mBadChildLevel || mTreeDepth == MAX_REFLOW_DEPTH) { // eCloseElement couldn't add the parent so we fail as well or we've // reached the limit of the depth of the tree that we allow. ++mBadChildLevel; PR_LOG(txLog::xslt, PR_LOG_DEBUG, ("startElement, mBadChildLevel = %d\n", mBadChildLevel)); return; } ++mTreeDepth; nsresult rv = mTableStateStack.push(NS_INT32_TO_PTR(mTableState)); if (NS_FAILED(rv)) { return; } mTableState = NORMAL; nsCOMPtr<nsIDOMElement> element; mDontAddCurrent = PR_FALSE; if ((mOutputFormat.mMethod == eHTMLOutput) && (aNsID == kNameSpaceID_None)) { if (mDocumentIsHTML) { rv = mDocument->CreateElement(aName, getter_AddRefs(element)); } else { nsAutoString lcname; ToLowerCase(aName, lcname); rv = mDocument->CreateElementNS(NS_LITERAL_STRING(kXHTMLNameSpaceURI), lcname, getter_AddRefs(element)); } if (NS_FAILED(rv)) { return; } startHTMLElement(element, PR_FALSE); } else { nsAutoString nsURI; gTxNameSpaceManager->GetNameSpaceURI(aNsID, nsURI); rv = mDocument->CreateElementNS(nsURI, aName, getter_AddRefs(element)); NS_ASSERTION(NS_SUCCEEDED(rv), "Can't create element"); if (NS_FAILED(rv)) { return; } if (aNsID == kNameSpaceID_XHTML) { startHTMLElement(element, PR_TRUE); } else if (aNsID == kNameSpaceID_SVG && txHTMLAtoms::script->Equals(aName)) { mDontAddCurrent = PR_TRUE; } } if (mCreatingNewDocument) { // Handle all sorts of stylesheets nsCOMPtr<nsIStyleSheetLinkingElement> ssle = do_QueryInterface(element); if (ssle) { ssle->InitStyleLinkElement(nsnull, PR_FALSE); ssle->SetEnableUpdates(PR_FALSE); } } mParentNode = mCurrentNode; mCurrentNode = do_QueryInterface(element); }
XPT_SetAddrForOffset(XPTCursor *cursor, uint32_t offset, void *addr) { return XPT_HashTableAdd(cursor->state->pool->offset_map, NS_INT32_TO_PTR(offset), addr) != NULL; }
XPT_SetOffsetForAddr(XPTCursor *cursor, void *addr, uint32_t offset) { return XPT_HashTableAdd(cursor->state->pool->offset_map, addr, NS_INT32_TO_PTR(offset)) != NULL; }