nsresult        rv;  const char      *uri = nsnull; if (NS_SUCCEEDED(rv = busyResource->GetValueConst(&uri)) && (uri)) { #ifdef  DEBUG_BOOKMARK_PING_OUTPUT printf("Finished polling '%s'\n", uri); #endif } nsCOMPtr<nsIChannel> channel = do_QueryInterface(request); nsCOMPtr<nsIHttpChannel>    httpChannel = do_QueryInterface(channel); if (httpChannel) { nsAutoString            eTagValue, lastModValue, contentLengthValue;  nsCAutoString val; if (NS_SUCCEEDED(httpChannel->GetResponseHeader(NS_LITERAL_CSTRING("ETag"), val))) CopyASCIItoUCS2(val, eTagValue); if (NS_SUCCEEDED(httpChannel->GetResponseHeader(NS_LITERAL_CSTRING("Last-Modified"), val))) CopyASCIItoUCS2(val, lastModValue); if (NS_SUCCEEDED(httpChannel->GetResponseHeader(NS_LITERAL_CSTRING("Content-Length"), val))) CopyASCIItoUCS2(val, contentLengthValue); val.Truncate();  PRBool      changedFlag = PR_FALSE;  PRUint32    respStatus; if (NS_SUCCEEDED(rv = httpChannel->GetResponseStatus(&respStatus))) { if ((respStatus >= 200) && (respStatus <= 299)) { if (!eTagValue.IsEmpty()) { #ifdef  DEBUG_BOOKMARK_PING_OUTPUT printf("eTag: '%s'\n", NS_LossyConvertASCIItoUCS2(eTagValue).get()); #endif nsAutoString        eTagStr; nsCOMPtr<nsIRDFNode>    currentETagNode; if (NS_SUCCEEDED(rv = mInner->GetTarget(busyResource, kWEB_LastPingETag, PR_TRUE, getter_AddRefs(currentETagNode))) && (rv != NS_RDF_NO_VALUE)) { nsCOMPtr<nsIRDFLiteral> currentETagLit = do_QueryInterface(currentETagNode); if (currentETagLit) { const PRUnichar* currentETagStr = nsnull; currentETagLit->GetValueConst(&currentETagStr); if ((currentETagStr) && !eTagValue.Equals(nsDependentString(currentETagStr), nsCaseInsensitiveStringComparator())) { changedFlag = PR_TRUE; } eTagStr.Assign(eTagValue); nsCOMPtr<nsIRDFLiteral> newETagLiteral; if (NS_SUCCEEDED(rv = gRDF->GetLiteral(eTagStr.get(), getter_AddRefs(newETagLiteral)))) { rv = mInner->Change(busyResource, kWEB_LastPingETag, currentETagNode, newETagLiteral); } } } else { eTagStr.Assign(eTagValue); nsCOMPtr<nsIRDFLiteral> newETagLiteral; if (NS_SUCCEEDED(rv = gRDF->GetLiteral(eTagStr.get(), getter_AddRefs(newETagLiteral)))) { rv = mInner->Assert(busyResource, kWEB_LastPingETag, newETagLiteral, PR_TRUE); } } } } }  if ((changedFlag == PR_FALSE) && (!lastModValue.IsEmpty())) { #ifdef  DEBUG_BOOKMARK_PING_OUTPUT printf("Last-Modified: '%s'\n", lastModValue.get()); #endif nsAutoString        lastModStr; nsCOMPtr<nsIRDFNode>    currentLastModNode; if (NS_SUCCEEDED(rv = mInner->GetTarget(busyResource, kWEB_LastPingModDate, PR_TRUE, getter_AddRefs(currentLastModNode))) && (rv != NS_RDF_NO_VALUE)) { nsCOMPtr<nsIRDFLiteral> currentLastModLit = do_QueryInterface(currentLastModNode); if (currentLastModLit) { const PRUnichar* currentLastModStr = nsnull; currentLastModLit->GetValueConst(&currentLastModStr); if ((currentLastModStr) && !lastModValue.Equals(nsDependentString(currentLastModStr), nsCaseInsensitiveStringComparator())) { changedFlag = PR_TRUE; } lastModStr.Assign(lastModValue); nsCOMPtr<nsIRDFLiteral> newLastModLiteral; if (NS_SUCCEEDED(rv = gRDF->GetLiteral(lastModStr.get(), getter_AddRefs(newLastModLiteral)))) { rv = mInner->Change(busyResource, kWEB_LastPingModDate, currentLastModNode, newLastModLiteral); } } } else { lastModStr.Assign(lastModValue); nsCOMPtr<nsIRDFLiteral> newLastModLiteral; if (NS_SUCCEEDED(rv = gRDF->GetLiteral(lastModStr.get(), getter_AddRefs(newLastModLiteral)))) { rv = mInner->Assert(busyResource, kWEB_LastPingModDate, newLastModLiteral, PR_TRUE); } } }  if ((changedFlag == PR_FALSE) && (!contentLengthValue.IsEmpty())) { #ifdef  DEBUG_BOOKMARK_PING_OUTPUT printf("Content-Length: '%s'\n", contentLengthValue.get()); #endif nsAutoString        contentLenStr; nsCOMPtr<nsIRDFNode>    currentContentLengthNode; if (NS_SUCCEEDED(rv = mInner->GetTarget(busyResource, kWEB_LastPingContentLen, PR_TRUE, getter_AddRefs(currentContentLengthNode))) && (rv != NS_RDF_NO_VALUE)) { nsCOMPtr<nsIRDFLiteral> currentContentLengthLit = do_QueryInterface(currentContentLengthNode); if (currentContentLengthLit) { const PRUnichar *currentContentLengthStr = nsnull; currentContentLengthLit->GetValueConst(&currentContentLengthStr); if ((currentContentLengthStr) && !contentLengthValue.Equals(nsDependentString(currentContentLengthStr), nsCaseInsensitiveStringComparator())) { changedFlag = PR_TRUE; } contentLenStr.Assign(contentLengthValue); nsCOMPtr<nsIRDFLiteral> newContentLengthLiteral; if (NS_SUCCEEDED(rv = gRDF->GetLiteral(contentLenStr.get(), getter_AddRefs(newContentLengthLiteral)))) { rv = mInner->Change(busyResource, kWEB_LastPingContentLen, currentContentLengthNode, newContentLengthLiteral); } } } else { contentLenStr.Assign(contentLengthValue); nsCOMPtr<nsIRDFLiteral> newContentLengthLiteral; if (NS_SUCCEEDED(rv = gRDF->GetLiteral(contentLenStr.get(), getter_AddRefs(newContentLengthLiteral)))) { rv = mInner->Assert(busyResource, kWEB_LastPingContentLen, newContentLengthLiteral, PR_TRUE); } } }   nsCOMPtr<nsIRDFDate>    dateLiteral; if (NS_SUCCEEDED(rv = gRDF->GetDateLiteral(PR_Now(), getter_AddRefs(dateLiteral)))) { nsCOMPtr<nsIRDFNode>    lastPingNode; if (NS_SUCCEEDED(rv = mInner->GetTarget(busyResource, kWEB_LastPingDate, PR_TRUE, getter_AddRefs(lastPingNode))) && (rv != NS_RDF_NO_VALUE)) { rv = mInner->Change(busyResource, kWEB_LastPingDate, lastPingNode, dateLiteral); } else { rv = mInner->Assert(busyResource, kWEB_LastPingDate, dateLiteral, PR_TRUE); } NS_ASSERTION(rv == NS_RDF_ASSERTION_ACCEPTED, "unable to assert new time");   } else { NS_ERROR("unable to get date literal for now"); }   if (changedFlag == PR_TRUE) { #ifdef  DEBUG_BOOKMARK_PING_OUTPUT printf("URL has changed!\n\n"); #endif  nsAutoString        schedule;  nsCOMPtr<nsIRDFNode>    scheduleNode; if (NS_SUCCEEDED(rv = mInner->GetTarget(busyResource, kWEB_Schedule, PR_TRUE, getter_AddRefs(scheduleNode))) && (rv != NS_RDF_NO_VALUE)) { nsCOMPtr<nsIRDFLiteral> scheduleLiteral = do_QueryInterface(scheduleNode); if (scheduleLiteral) { const PRUnichar     *scheduleUni = nsnull; if (NS_SUCCEEDED(rv = scheduleLiteral->GetValueConst(&scheduleUni)) && (scheduleUni)) { schedule = scheduleUni; } } }   if (FindInReadable(NS_LITERAL_STRING("icon"), schedule, nsCaseInsensitiveStringComparator())) { nsCOMPtr<nsIRDFLiteral> statusLiteral; if (NS_SUCCEEDED(rv = gRDF->GetLiteral(NS_LITERAL_STRING("new").get(), getter_AddRefs(statusLiteral)))) { nsCOMPtr<nsIRDFNode>    currentStatusNode; if (NS_SUCCEEDED(rv = mInner->GetTarget(busyResource, kWEB_Status, PR_TRUE, getter_AddRefs(currentStatusNode))) && (rv != NS_RDF_NO_VALUE)) { rv = mInner->Change(busyResource, kWEB_Status, currentStatusNode, statusLiteral); } else { rv = mInner->Assert(busyResource, kWEB_Status, statusLiteral, PR_TRUE); } NS_ASSERTION(rv == NS_RDF_ASSERTION_ACCEPTED, "unable to assert changed status"); } }   if (FindInReadable(NS_LITERAL_STRING("sound"), schedule, nsCaseInsensitiveStringComparator())) { nsCOMPtr<nsISound>  soundInterface; rv = nsComponentManager::CreateInstance(kSoundCID, nsnull, NS_GET_IID(nsISound), getter_AddRefs(soundInterface)); if (NS_SUCCEEDED(rv)) {  soundInterface->Beep(); } }  PRBool      openURLFlag = PR_FALSE;   if (FindInReadable(NS_LITERAL_STRING("alert"), schedule, nsCaseInsensitiveStringComparator())) { nsCOMPtr<nsIInterfaceRequestor> interfaces; nsCOMPtr<nsIPrompt> prompter;  channel->GetNotificationCallbacks(getter_AddRefs(interfaces)); if (interfaces) interfaces->GetInterface(NS_GET_IID(nsIPrompt), getter_AddRefs(prompter)); if (!prompter) { nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService(NS_WINDOWWATCHER_CONTRACTID)); if (wwatch) wwatch->GetNewPrompter(0, getter_AddRefs(prompter)); }  if (prompter) { nsAutoString    promptStr; getLocaleString("WebPageUpdated", promptStr); if (!promptStr.IsEmpty())   promptStr.Append(NS_LITERAL_STRING("\n\n"));  nsCOMPtr<nsIRDFNode>    nameNode; if (NS_SUCCEEDED(mInner->GetTarget(busyResource, kNC_Name, PR_TRUE, getter_AddRefs(nameNode)))) { nsCOMPtr<nsIRDFLiteral> nameLiteral = do_QueryInterface(nameNode); if (nameLiteral) { const PRUnichar *nameUni = nsnull; if (NS_SUCCEEDED(rv = nameLiteral->GetValueConst(&nameUni)) && (nameUni)) { nsAutoString    info; getLocaleString("WebPageTitle", info); promptStr += info; promptStr.Append(NS_LITERAL_STRING(" ")); promptStr += nameUni; promptStr.Append(NS_LITERAL_STRING("\n")); getLocaleString("WebPageURL", info); promptStr += info; promptStr.Append(NS_LITERAL_STRING(" ")); } } } promptStr.AppendWithConversion(uri);  nsAutoString    temp; getLocaleString("WebPageAskDisplay", temp); if (!temp.IsEmpty()) { promptStr.Append(NS_LITERAL_STRING("\n\n")); promptStr += temp; }  nsAutoString    stopOption; getLocaleString("WebPageAskStopOption", stopOption); PRBool      stopCheckingFlag = PR_FALSE; rv = prompter->ConfirmCheck(nsnull, promptStr.get(), stopOption.get(), &stopCheckingFlag, &openURLFlag); if (NS_FAILED(rv)) { openURLFlag = PR_FALSE; stopCheckingFlag = PR_FALSE; } if (stopCheckingFlag == PR_TRUE) { #ifdef  DEBUG_BOOKMARK_PING_OUTPUT printf("\nStop checking this URL.\n"); #endif rv = mInner->Unassert(busyResource, kWEB_Schedule, scheduleNode); NS_ASSERTION(NS_SUCCEEDED(rv), "unable to unassert kWEB_Schedule"); } } }   if ((openURLFlag == PR_TRUE) || FindInReadable(NS_LITERAL_STRING("open"), schedule, nsCaseInsensitiveStringComparator())) { if (NS_SUCCEEDED(rv)) { nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService(NS_WINDOWWATCHER_CONTRACTID)); if (wwatch) { nsCOMPtr<nsIDOMWindow> newWindow; nsCOMPtr<nsISupportsArray> suppArray; rv = NS_NewISupportsArray(getter_AddRefs(suppArray)); if (NS_FAILED(rv)) return rv; nsCOMPtr<nsISupportsCString> suppString(do_CreateInstance("@mozilla.org/supports-cstring;1", &rv)); if (!suppString) return rv; rv = suppString->SetData(nsDependentCString(uri)); if (NS_FAILED(rv)) return rv; suppArray->AppendElement(suppString);  nsCOMPtr<nsICmdLineHandler> handler(do_GetService("@mozilla.org/commandlinehandler/general-startup;1?type=browser", &rv)); if (NS_FAILED(rv)) return rv;  nsXPIDLCString url; rv = handler->GetChromeUrlForTask(getter_Copies(url)); if (NS_FAILED(rv)) return rv;  wwatch->OpenWindow(0, url, "_blank", "chrome,dialog=no,all", suppArray, getter_AddRefs(newWindow)); } } } } #ifdef  DEBUG_BOOKMARK_PING_OUTPUT else { printf("URL has not changed status.\n\n"); } #endif }  busyResource = nsnull; busySchedule = PR_FALSE;  return NS_OK;
nsresult		rv;  const char		*uri = nsnull; if (NS_SUCCEEDED(rv = busyResource->GetValueConst(&uri)) && (uri)) { #ifdef	DEBUG_BOOKMARK_PING_OUTPUT printf("Finished polling '%s'\n", uri); #endif }  nsCOMPtr<nsIHTTPChannel>	httpChannel = do_QueryInterface(channel); if (httpChannel) { nsAutoString			eTagValue, lastModValue, contentLengthValue; nsCOMPtr<nsISimpleEnumerator>	enumerator; if (NS_SUCCEEDED(rv = httpChannel->GetResponseHeaderEnumerator(getter_AddRefs(enumerator)))) { PRBool			bMoreHeaders;  while (NS_SUCCEEDED(rv = enumerator->HasMoreElements(&bMoreHeaders)) && (bMoreHeaders == PR_TRUE)) { nsCOMPtr<nsISupports>   item; enumerator->GetNext(getter_AddRefs(item)); nsCOMPtr<nsIHTTPHeader>	header = do_QueryInterface(item); NS_ASSERTION(header, "nsBookmarksService::OnStopRequest - Bad HTTP header."); if (header) { nsCOMPtr<nsIAtom>       headerAtom; header->GetField(getter_AddRefs(headerAtom)); nsAutoString		headerStr; headerAtom->ToString(headerStr);  char	*val = nsnull;  if (headerStr.EqualsIgnoreCase("eTag")) { header->GetValue(&val); if (val) { eTagValue.AssignWithConversion(val); nsCRT::free(val); } } else if (headerStr.EqualsIgnoreCase("Last-Modified")) { header->GetValue(&val); if (val) { lastModValue.AssignWithConversion(val); nsCRT::free(val); } } else if (headerStr.EqualsIgnoreCase("Content-Length")) { header->GetValue(&val); if (val) { contentLengthValue.AssignWithConversion(val); nsCRT::free(val); } } } } }  PRBool		changedFlag = PR_FALSE;  PRUint32	respStatus; if (NS_SUCCEEDED(rv = httpChannel->GetResponseStatus(&respStatus))) { if ((respStatus >= 200) && (respStatus <= 299)) { if (eTagValue.Length() > 0) { #ifdef	DEBUG_BOOKMARK_PING_OUTPUT const char *eTagVal = nsCAutoString(eTagValue); printf("eTag: '%s'\n", eTagVal); #endif nsCOMPtr<nsIRDFNode>	currentETagNode; if (NS_SUCCEEDED(rv = mInner->GetTarget(busyResource, kWEB_LastPingETag, PR_TRUE, getter_AddRefs(currentETagNode))) && (rv != NS_RDF_NO_VALUE)) { nsCOMPtr<nsIRDFLiteral>	currentETagLit = do_QueryInterface(currentETagNode); if (currentETagLit) { const PRUnichar	*currentETagStr = nsnull; currentETagLit->GetValueConst(&currentETagStr); if ((currentETagStr) && (!eTagValue.EqualsIgnoreCase(currentETagStr))) { changedFlag = PR_TRUE; } nsCOMPtr<nsIRDFLiteral>	newETagLiteral; if (NS_SUCCEEDED(rv = gRDF->GetLiteral(eTagValue.GetUnicode(), getter_AddRefs(newETagLiteral)))) { rv = mInner->Change(busyResource, kWEB_LastPingETag, currentETagNode, newETagLiteral); } } } else { nsCOMPtr<nsIRDFLiteral>	newETagLiteral; if (NS_SUCCEEDED(rv = gRDF->GetLiteral(eTagValue.GetUnicode(), getter_AddRefs(newETagLiteral)))) { rv = mInner->Assert(busyResource, kWEB_LastPingETag, newETagLiteral, PR_TRUE); } } } } }  if ((changedFlag == PR_FALSE) && (lastModValue.Length() > 0)) { #ifdef	DEBUG_BOOKMARK_PING_OUTPUT const char *lastModVal = nsCAutoString(lastModValue); printf("Last-Modified: '%s'\n", lastModVal); #endif nsCOMPtr<nsIRDFNode>	currentLastModNode; if (NS_SUCCEEDED(rv = mInner->GetTarget(busyResource, kWEB_LastPingModDate, PR_TRUE, getter_AddRefs(currentLastModNode))) && (rv != NS_RDF_NO_VALUE)) { nsCOMPtr<nsIRDFLiteral>	currentLastModLit = do_QueryInterface(currentLastModNode); if (currentLastModLit) { const PRUnichar	*currentLastModStr = nsnull; currentLastModLit->GetValueConst(&currentLastModStr); if ((currentLastModStr) && (!lastModValue.EqualsIgnoreCase(currentLastModStr))) { changedFlag = PR_TRUE; } nsCOMPtr<nsIRDFLiteral>	newLastModLiteral; if (NS_SUCCEEDED(rv = gRDF->GetLiteral(lastModValue.GetUnicode(), getter_AddRefs(newLastModLiteral)))) { rv = mInner->Change(busyResource, kWEB_LastPingModDate, currentLastModNode, newLastModLiteral); } } } else { nsCOMPtr<nsIRDFLiteral>	newLastModLiteral; if (NS_SUCCEEDED(rv = gRDF->GetLiteral(lastModValue.GetUnicode(), getter_AddRefs(newLastModLiteral)))) { rv = mInner->Assert(busyResource, kWEB_LastPingModDate, newLastModLiteral, PR_TRUE); } } }  if ((changedFlag == PR_FALSE) && (contentLengthValue.Length() > 0)) { #ifdef	DEBUG_BOOKMARK_PING_OUTPUT const char *contentLengthVal = nsCAutoString(contentLengthValue); printf("Content-Length: '%s'\n", contentLengthVal); #endif nsCOMPtr<nsIRDFNode>	currentContentLengthNode; if (NS_SUCCEEDED(rv = mInner->GetTarget(busyResource, kWEB_LastPingContentLen, PR_TRUE, getter_AddRefs(currentContentLengthNode))) && (rv != NS_RDF_NO_VALUE)) { nsCOMPtr<nsIRDFLiteral>	currentContentLengthLit = do_QueryInterface(currentContentLengthNode); if (currentContentLengthLit) { const PRUnichar	*currentContentLengthStr = nsnull; currentContentLengthLit->GetValueConst(&currentContentLengthStr); if ((currentContentLengthStr) && (!contentLengthValue.EqualsIgnoreCase(currentContentLengthStr))) { changedFlag = PR_TRUE; } nsCOMPtr<nsIRDFLiteral>	newContentLengthLiteral; if (NS_SUCCEEDED(rv = gRDF->GetLiteral(contentLengthValue.GetUnicode(), getter_AddRefs(newContentLengthLiteral)))) { rv = mInner->Change(busyResource, kWEB_LastPingContentLen, currentContentLengthNode, newContentLengthLiteral); } } } else { nsCOMPtr<nsIRDFLiteral>	newContentLengthLiteral; if (NS_SUCCEEDED(rv = gRDF->GetLiteral(contentLengthValue.GetUnicode(), getter_AddRefs(newContentLengthLiteral)))) { rv = mInner->Assert(busyResource, kWEB_LastPingContentLen, newContentLengthLiteral, PR_TRUE); } } }   nsCOMPtr<nsIRDFDate>	dateLiteral; if (NS_SUCCEEDED(rv = gRDF->GetDateLiteral(PR_Now(), getter_AddRefs(dateLiteral)))) { nsCOMPtr<nsIRDFNode>	lastPingNode; if (NS_SUCCEEDED(rv = mInner->GetTarget(busyResource, kWEB_LastPingDate, PR_TRUE, getter_AddRefs(lastPingNode))) && (rv != NS_RDF_NO_VALUE)) { rv = mInner->Change(busyResource, kWEB_LastPingDate, lastPingNode, dateLiteral); } else { rv = mInner->Assert(busyResource, kWEB_LastPingDate, dateLiteral, PR_TRUE); } NS_ASSERTION(rv == NS_RDF_ASSERTION_ACCEPTED, "unable to assert new time");   } else { NS_ERROR("unable to get date literal for now"); }   if (changedFlag == PR_TRUE) { #ifdef	DEBUG_BOOKMARK_PING_OUTPUT printf("URL has changed!\n\n"); #endif  nsAutoString		schedule;  nsCOMPtr<nsIRDFNode>	scheduleNode; if (NS_SUCCEEDED(rv = mInner->GetTarget(busyResource, kWEB_Schedule, PR_TRUE, getter_AddRefs(scheduleNode))) && (rv != NS_RDF_NO_VALUE)) { nsCOMPtr<nsIRDFLiteral>	scheduleLiteral = do_QueryInterface(scheduleNode); if (scheduleLiteral) { const PRUnichar		*scheduleUni = nsnull; if (NS_SUCCEEDED(rv = scheduleLiteral->GetValueConst(&scheduleUni)) && (scheduleUni)) { schedule = scheduleUni; } } }   if (schedule.Find(NS_ConvertASCIItoUCS2("icon"), PR_TRUE, 0) >= 0) { nsCOMPtr<nsIRDFLiteral>	statusLiteral; if (NS_SUCCEEDED(rv = gRDF->GetLiteral(NS_ConvertASCIItoUCS2("new").GetUnicode(), getter_AddRefs(statusLiteral)))) { nsCOMPtr<nsIRDFNode>	currentStatusNode; if (NS_SUCCEEDED(rv = mInner->GetTarget(busyResource, kWEB_Status, PR_TRUE, getter_AddRefs(currentStatusNode))) && (rv != NS_RDF_NO_VALUE)) { rv = mInner->Change(busyResource, kWEB_Status, currentStatusNode, statusLiteral); } else { rv = mInner->Assert(busyResource, kWEB_Status, statusLiteral, PR_TRUE); } NS_ASSERTION(rv == NS_RDF_ASSERTION_ACCEPTED, "unable to assert changed status"); } }   if (schedule.Find(NS_ConvertASCIItoUCS2("sound"), PR_TRUE, 0) >= 0) {  }  PRBool		openURLFlag = PR_FALSE;   if (schedule.Find(NS_ConvertASCIItoUCS2("alert"), PR_TRUE, 0) >= 0) { NS_WITH_SERVICE(nsIPrompt, dialog, kNetSupportDialogCID, &rv); if (NS_SUCCEEDED(rv)) { nsAutoString	promptStr; getLocaleString("WebPageUpdated", promptStr); if (promptStr.Length() > 0)	promptStr.AppendWithConversion("\n\n");  nsCOMPtr<nsIRDFNode>	nameNode; if (NS_SUCCEEDED(mInner->GetTarget(busyResource, kNC_Name, PR_TRUE, getter_AddRefs(nameNode)))) { nsCOMPtr<nsIRDFLiteral>	nameLiteral = do_QueryInterface(nameNode); if (nameLiteral) { const PRUnichar	*nameUni = nsnull; if (NS_SUCCEEDED(rv = nameLiteral->GetValueConst(&nameUni)) && (nameUni)) { nsAutoString	info; getLocaleString("WebPageTitle", info); promptStr += info; promptStr.AppendWithConversion(" "); promptStr += nameUni; promptStr.AppendWithConversion("\n"); getLocaleString("WebPageURL", info); promptStr += info; promptStr.AppendWithConversion(" "); } } } promptStr.AppendWithConversion(uri);  nsAutoString	temp; getLocaleString("WebPageAskDisplay", temp); if (temp.Length() > 0) { promptStr.AppendWithConversion("\n\n"); promptStr += temp; }  nsAutoString	stopOption; getLocaleString("WebPageAskStopOption", stopOption); PRBool		stopCheckingFlag = PR_FALSE; rv = dialog->ConfirmCheck(promptStr.GetUnicode(), stopOption.GetUnicode(), &stopCheckingFlag, &openURLFlag); if (NS_FAILED(rv)) { openURLFlag = PR_FALSE; stopCheckingFlag = PR_FALSE; } if (stopCheckingFlag == PR_TRUE) { #ifdef	DEBUG_BOOKMARK_PING_OUTPUT printf("\nStop checking this URL.\n"); #endif rv = mInner->Unassert(busyResource, kWEB_Schedule, scheduleNode); NS_ASSERTION(NS_SUCCEEDED(rv), "unable to unassert kWEB_Schedule"); } } }   if ((openURLFlag == PR_TRUE) || (schedule.Find(NS_ConvertASCIItoUCS2("open"), PR_TRUE, 0) >= 0)) { NS_WITH_SERVICE(nsIAppShellService, appShell, kAppShellServiceCID, &rv); if (NS_SUCCEEDED(rv)) {  nsCOMPtr<nsIXULWindow>	parent; appShell->GetHiddenWindow(getter_AddRefs(parent));   nsCOMPtr<nsIDocShell>	docShell; if (parent) { parent->GetDocShell(getter_AddRefs(docShell)); } nsCOMPtr<nsIDOMWindow>	domParent(do_GetInterface(docShell)); nsCOMPtr<nsIScriptGlobalObject>	sgo(do_QueryInterface(domParent));  nsCOMPtr<nsIScriptContext>	context; if (sgo) { sgo->GetContext(getter_AddRefs(context)); } if (context) { JSContext *jsContext = (JSContext*)context->GetNativeContext(); if (jsContext) { void	*stackPtr; jsval	*argv = JS_PushArguments(jsContext, &stackPtr, "s", uri); if (argv) {  nsIDOMWindow	*newWindow; domParent->Open(jsContext, argv, 1, &newWindow); JS_PopArguments(jsContext, stackPtr); } } } } } } #ifdef	DEBUG_BOOKMARK_PING_OUTPUT else { printf("URL has not changed status.\n\n"); } #endif }  busyResource = null_nsCOMPtr(); busySchedule = PR_FALSE;  return(NS_OK);
nsBookmarksService::OnStopRequest(nsIRequest* request, nsISupports *ctxt,                    nsresult status){    nsresult        rv;    const char      *uri = nsnull;    if (NS_SUCCEEDED(rv = busyResource->GetValueConst(&uri)) && (uri))    {#ifdef  DEBUG_BOOKMARK_PING_OUTPUT        printf("Finished polling '%s'\n", uri);#endif    }    nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);    nsCOMPtr<nsIHttpChannel>    httpChannel = do_QueryInterface(channel);    if (httpChannel)    {        nsAutoString            eTagValue, lastModValue, contentLengthValue;        nsCAutoString val;        if (NS_SUCCEEDED(httpChannel->GetResponseHeader(NS_LITERAL_CSTRING("ETag"), val)))            CopyASCIItoUCS2(val, eTagValue);        if (NS_SUCCEEDED(httpChannel->GetResponseHeader(NS_LITERAL_CSTRING("Last-Modified"), val)))            CopyASCIItoUCS2(val, lastModValue);        if (NS_SUCCEEDED(httpChannel->GetResponseHeader(NS_LITERAL_CSTRING("Content-Length"), val)))            CopyASCIItoUCS2(val, contentLengthValue);        val.Truncate();        PRBool      changedFlag = PR_FALSE;        PRUint32    respStatus;        if (NS_SUCCEEDED(rv = httpChannel->GetResponseStatus(&respStatus)))        {            if ((respStatus >= 200) && (respStatus <= 299))            {                if (!eTagValue.IsEmpty())                {#ifdef  DEBUG_BOOKMARK_PING_OUTPUT                    printf("eTag: '%s'\n", NS_LossyConvertASCIItoUCS2(eTagValue).get());#endif                    nsAutoString        eTagStr;                    nsCOMPtr<nsIRDFNode>    currentETagNode;                    if (NS_SUCCEEDED(rv = mInner->GetTarget(busyResource, kWEB_LastPingETag,                        PR_TRUE, getter_AddRefs(currentETagNode))) && (rv != NS_RDF_NO_VALUE))                    {                        nsCOMPtr<nsIRDFLiteral> currentETagLit = do_QueryInterface(currentETagNode);                        if (currentETagLit)                        {                            const PRUnichar* currentETagStr = nsnull;                            currentETagLit->GetValueConst(&currentETagStr);                            if ((currentETagStr) &&                                !eTagValue.Equals(nsDependentString(currentETagStr),                                                  nsCaseInsensitiveStringComparator()))                            {                                changedFlag = PR_TRUE;                            }                            eTagStr.Assign(eTagValue);                            nsCOMPtr<nsIRDFLiteral> newETagLiteral;                            if (NS_SUCCEEDED(rv = gRDF->GetLiteral(eTagStr.get(),                                getter_AddRefs(newETagLiteral))))                            {                                rv = mInner->Change(busyResource, kWEB_LastPingETag,                                    currentETagNode, newETagLiteral);                            }                        }                    }                    else                    {                        eTagStr.Assign(eTagValue);                        nsCOMPtr<nsIRDFLiteral> newETagLiteral;                        if (NS_SUCCEEDED(rv = gRDF->GetLiteral(eTagStr.get(),                            getter_AddRefs(newETagLiteral))))                        {                            rv = mInner->Assert(busyResource, kWEB_LastPingETag,                                newETagLiteral, PR_TRUE);                        }                    }                }            }        }        if ((changedFlag == PR_FALSE) && (!lastModValue.IsEmpty()))        {#ifdef  DEBUG_BOOKMARK_PING_OUTPUT            printf("Last-Modified: '%s'\n", lastModValue.get());#endif            nsAutoString        lastModStr;            nsCOMPtr<nsIRDFNode>    currentLastModNode;            if (NS_SUCCEEDED(rv = mInner->GetTarget(busyResource, kWEB_LastPingModDate,                PR_TRUE, getter_AddRefs(currentLastModNode))) && (rv != NS_RDF_NO_VALUE))            {                nsCOMPtr<nsIRDFLiteral> currentLastModLit = do_QueryInterface(currentLastModNode);                if (currentLastModLit)                {                    const PRUnichar* currentLastModStr = nsnull;                    currentLastModLit->GetValueConst(&currentLastModStr);                    if ((currentLastModStr) &&                        !lastModValue.Equals(nsDependentString(currentLastModStr),                                             nsCaseInsensitiveStringComparator()))                    {                        changedFlag = PR_TRUE;                    }                    lastModStr.Assign(lastModValue);                    nsCOMPtr<nsIRDFLiteral> newLastModLiteral;                    if (NS_SUCCEEDED(rv = gRDF->GetLiteral(lastModStr.get(),                        getter_AddRefs(newLastModLiteral))))                    {                        rv = mInner->Change(busyResource, kWEB_LastPingModDate,                            currentLastModNode, newLastModLiteral);                    }                }            }            else            {                lastModStr.Assign(lastModValue);                nsCOMPtr<nsIRDFLiteral> newLastModLiteral;                if (NS_SUCCEEDED(rv = gRDF->GetLiteral(lastModStr.get(),                    getter_AddRefs(newLastModLiteral))))                {                    rv = mInner->Assert(busyResource, kWEB_LastPingModDate,                        newLastModLiteral, PR_TRUE);                }            }        }        if ((changedFlag == PR_FALSE) && (!contentLengthValue.IsEmpty()))        {#ifdef  DEBUG_BOOKMARK_PING_OUTPUT            printf("Content-Length: '%s'\n", contentLengthValue.get());#endif            nsAutoString        contentLenStr;            nsCOMPtr<nsIRDFNode>    currentContentLengthNode;            if (NS_SUCCEEDED(rv = mInner->GetTarget(busyResource, kWEB_LastPingContentLen,                PR_TRUE, getter_AddRefs(currentContentLengthNode))) && (rv != NS_RDF_NO_VALUE))            {                nsCOMPtr<nsIRDFLiteral> currentContentLengthLit = do_QueryInterface(currentContentLengthNode);                if (currentContentLengthLit)                {                    const PRUnichar *currentContentLengthStr = nsnull;                    currentContentLengthLit->GetValueConst(&currentContentLengthStr);                    if ((currentContentLengthStr) &&                        !contentLengthValue.Equals(nsDependentString(currentContentLengthStr),                                                   nsCaseInsensitiveStringComparator()))                    {                        changedFlag = PR_TRUE;                    }                    contentLenStr.Assign(contentLengthValue);                    nsCOMPtr<nsIRDFLiteral> newContentLengthLiteral;                    if (NS_SUCCEEDED(rv = gRDF->GetLiteral(contentLenStr.get(),                        getter_AddRefs(newContentLengthLiteral))))                    {                        rv = mInner->Change(busyResource, kWEB_LastPingContentLen,                            currentContentLengthNode, newContentLengthLiteral);                    }                }            }            else            {                contentLenStr.Assign(contentLengthValue);                nsCOMPtr<nsIRDFLiteral> newContentLengthLiteral;                if (NS_SUCCEEDED(rv = gRDF->GetLiteral(contentLenStr.get(),                    getter_AddRefs(newContentLengthLiteral))))                {                    rv = mInner->Assert(busyResource, kWEB_LastPingContentLen,                        newContentLengthLiteral, PR_TRUE);                }            }        }        // update last poll date        nsCOMPtr<nsIRDFDate>    dateLiteral;        if (NS_SUCCEEDED(rv = gRDF->GetDateLiteral(PR_Now(), getter_AddRefs(dateLiteral))))        {            nsCOMPtr<nsIRDFNode>    lastPingNode;            if (NS_SUCCEEDED(rv = mInner->GetTarget(busyResource, kWEB_LastPingDate, PR_TRUE,                getter_AddRefs(lastPingNode))) && (rv != NS_RDF_NO_VALUE))            {                rv = mInner->Change(busyResource, kWEB_LastPingDate, lastPingNode, dateLiteral);            }            else            {                rv = mInner->Assert(busyResource, kWEB_LastPingDate, dateLiteral, PR_TRUE);            }            NS_ASSERTION(rv == NS_RDF_ASSERTION_ACCEPTED, "unable to assert new time");//          mDirty = PR_TRUE;        }        else        {            NS_ERROR("unable to get date literal for now");        }        // If its changed, set the appropriate info        if (changedFlag == PR_TRUE)        {#ifdef  DEBUG_BOOKMARK_PING_OUTPUT            printf("URL has changed!\n\n");#endif            nsAutoString        schedule;            nsCOMPtr<nsIRDFNode>    scheduleNode;            if (NS_SUCCEEDED(rv = mInner->GetTarget(busyResource, kWEB_Schedule, PR_TRUE,                getter_AddRefs(scheduleNode))) && (rv != NS_RDF_NO_VALUE))            {                nsCOMPtr<nsIRDFLiteral> scheduleLiteral = do_QueryInterface(scheduleNode);                if (scheduleLiteral)                {                    const PRUnichar     *scheduleUni = nsnull;                    if (NS_SUCCEEDED(rv = scheduleLiteral->GetValueConst(&scheduleUni))                        && (scheduleUni))                    {                        schedule = scheduleUni;                    }                }            }            // update icon?            if (FindInReadable(NS_LITERAL_STRING("icon"),                               schedule,                               nsCaseInsensitiveStringComparator()))            {                nsCOMPtr<nsIRDFLiteral> statusLiteral;                if (NS_SUCCEEDED(rv = gRDF->GetLiteral(NS_LITERAL_STRING("new").get(), getter_AddRefs(statusLiteral))))                {                    nsCOMPtr<nsIRDFNode>    currentStatusNode;                    if (NS_SUCCEEDED(rv = mInner->GetTarget(busyResource, kWEB_Status, PR_TRUE,                        getter_AddRefs(currentStatusNode))) && (rv != NS_RDF_NO_VALUE))                    {                        rv = mInner->Change(busyResource, kWEB_Status, currentStatusNode, statusLiteral);                    }                    else                    {                        rv = mInner->Assert(busyResource, kWEB_Status, statusLiteral, PR_TRUE);                    }                    NS_ASSERTION(rv == NS_RDF_ASSERTION_ACCEPTED, "unable to assert changed status");                }            }                        // play a sound?            if (FindInReadable(NS_LITERAL_STRING("sound"),                               schedule,                               nsCaseInsensitiveStringComparator()))            {                nsCOMPtr<nsISound>  soundInterface;                rv = nsComponentManager::CreateInstance(kSoundCID,                        nsnull, NS_GET_IID(nsISound),                        getter_AddRefs(soundInterface));                if (NS_SUCCEEDED(rv))                {                    // for the moment, just beep                    soundInterface->Beep();                }            }                        PRBool      openURLFlag = PR_FALSE;            // show an alert?            if (FindInReadable(NS_LITERAL_STRING("alert"),                               schedule,                               nsCaseInsensitiveStringComparator()))            {                nsCOMPtr<nsIInterfaceRequestor> interfaces;                nsCOMPtr<nsIPrompt> prompter;                channel->GetNotificationCallbacks(getter_AddRefs(interfaces));                if (interfaces)                    interfaces->GetInterface(NS_GET_IID(nsIPrompt), getter_AddRefs(prompter));                if (!prompter)                {                    nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService(NS_WINDOWWATCHER_CONTRACTID));                    if (wwatch)                        wwatch->GetNewPrompter(0, getter_AddRefs(prompter));                }                if (prompter)                {                    nsAutoString    promptStr;                    getLocaleString("WebPageUpdated", promptStr);                    if (!promptStr.IsEmpty())   promptStr.Append(NS_LITERAL_STRING("\n\n"));                    nsCOMPtr<nsIRDFNode>    nameNode;                    if (NS_SUCCEEDED(mInner->GetTarget(busyResource, kNC_Name,                        PR_TRUE, getter_AddRefs(nameNode))))                    {                        nsCOMPtr<nsIRDFLiteral> nameLiteral = do_QueryInterface(nameNode);                        if (nameLiteral)                        {                            const PRUnichar *nameUni = nsnull;                            if (NS_SUCCEEDED(rv = nameLiteral->GetValueConst(&nameUni))                                && (nameUni))                            {                                nsAutoString    info;                                getLocaleString("WebPageTitle", info);                                promptStr += info;                                promptStr.Append(NS_LITERAL_STRING(" "));                                promptStr += nameUni;                                promptStr.Append(NS_LITERAL_STRING("\n"));                                getLocaleString("WebPageURL", info);                                promptStr += info;                                promptStr.Append(NS_LITERAL_STRING(" "));                            }                        }                    }                    promptStr.AppendWithConversion(uri);                                        nsAutoString    temp;                    getLocaleString("WebPageAskDisplay", temp);                    if (!temp.IsEmpty())                    {                        promptStr.Append(NS_LITERAL_STRING("\n\n"));                        promptStr += temp;                    }                    nsAutoString    stopOption;                    getLocaleString("WebPageAskStopOption", stopOption);                    PRBool      stopCheckingFlag = PR_FALSE;                    rv = prompter->ConfirmCheck(nsnull, promptStr.get(), stopOption.get(),                                  &stopCheckingFlag, &openURLFlag);                    if (NS_FAILED(rv))                    {                        openURLFlag = PR_FALSE;                        stopCheckingFlag = PR_FALSE;                    }                    if (stopCheckingFlag == PR_TRUE)                    {#ifdef  DEBUG_BOOKMARK_PING_OUTPUT                        printf("\nStop checking this URL.\n");#endif                        rv = mInner->Unassert(busyResource, kWEB_Schedule, scheduleNode);                        NS_ASSERTION(NS_SUCCEEDED(rv), "unable to unassert kWEB_Schedule");                    }                }            }            // open the URL in a new window?            if ((openURLFlag == PR_TRUE) ||                FindInReadable(NS_LITERAL_STRING("open"),                               schedule,                               nsCaseInsensitiveStringComparator()))            {                if (NS_SUCCEEDED(rv))                {                    nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService(NS_WINDOWWATCHER_CONTRACTID));                    if (wwatch)                    {                        nsCOMPtr<nsIDOMWindow> newWindow;            nsCOMPtr<nsISupportsArray> suppArray;            rv = NS_NewISupportsArray(getter_AddRefs(suppArray));            if (NS_FAILED(rv)) return rv;            nsCOMPtr<nsISupportsCString> suppString(do_CreateInstance("@mozilla.org/supports-cstring;1", &rv));            if (!suppString) return rv;            rv = suppString->SetData(nsDependentCString(uri));            if (NS_FAILED(rv)) return rv;            suppArray->AppendElement(suppString);                nsCOMPtr<nsICmdLineHandler> handler(do_GetService("@mozilla.org/commandlinehandler/general-startup;1?type=browser", &rv));                if (NS_FAILED(rv)) return rv;               nsXPIDLCString url;            rv = handler->GetChromeUrlForTask(getter_Copies(url));            if (NS_FAILED(rv)) return rv;            wwatch->OpenWindow(0, url, "_blank", "chrome,dialog=no,all",                                suppArray, getter_AddRefs(newWindow));                    }                }            }        }#ifdef  DEBUG_BOOKMARK_PING_OUTPUT        else        {            printf("URL has not changed status.\n\n");        }#endif    }    busyResource = nsnull;    busySchedule = PR_FALSE;    return NS_OK;}