// // FindURLFromLocalFile // // we are looking for a URL and couldn't find it, try again with looking for // a local file. If we have one, it may either be a normal file or an internet shortcut. // In both cases, however, we can get a URL (it will be a file:// url in the // local file case). // bool nsClipboard :: FindURLFromLocalFile ( IDataObject* inDataObject, UINT inIndex, void** outData, PRUint32* outDataLen ) { bool dataFound = false; nsresult loadResult = GetNativeDataOffClipboard(inDataObject, inIndex, GetFormat(kFileMime), nullptr, outData, outDataLen); if ( NS_SUCCEEDED(loadResult) && *outData ) { // we have a file path in |data|. Is it an internet shortcut or a normal file? const nsDependentString filepath(static_cast<PRUnichar*>(*outData)); nsCOMPtr<nsIFile> file; nsresult rv = NS_NewLocalFile(filepath, true, getter_AddRefs(file)); if (NS_FAILED(rv)) { nsMemory::Free(*outData); return dataFound; } if ( IsInternetShortcut(filepath) ) { nsMemory::Free(*outData); nsCAutoString url; ResolveShortcut( file, url ); if ( !url.IsEmpty() ) { // convert it to unicode and pass it out nsDependentString urlString(UTF8ToNewUnicode(url)); // the internal mozilla URL format, text/x-moz-url, contains // URL\ntitle. We can guess the title from the file's name. nsAutoString title; file->GetLeafName(title); // We rely on IsInternetShortcut check that file has a .url extension. title.SetLength(title.Length() - 4); if (title.IsEmpty()) title = urlString; *outData = ToNewUnicode(urlString + NS_LITERAL_STRING("\n") + title); *outDataLen = NS_strlen(static_cast<PRUnichar*>(*outData)) * sizeof(PRUnichar); dataFound = true; } } else { // we have a normal file, use some Necko objects to get our file path nsCAutoString urlSpec; NS_GetURLSpecFromFile(file, urlSpec); // convert it to unicode and pass it out nsMemory::Free(*outData); *outData = UTF8ToNewUnicode(urlSpec); *outDataLen = NS_strlen(static_cast<PRUnichar*>(*outData)) * sizeof(PRUnichar); dataFound = true; } // else regular file } return dataFound; } // FindURLFromLocalFile
// // FindURLFromLocalFile // // we are looking for a URL and couldn't find it, try again with looking for // a local file. If we have one, it may either be a normal file or an internet shortcut. // In both cases, however, we can get a URL (it will be a file:// url in the // local file case). // PRBool nsClipboard :: FindURLFromLocalFile ( IDataObject* inDataObject, UINT inIndex, void** outData, PRUint32* outDataLen ) { PRBool dataFound = PR_FALSE; nsresult loadResult = GetNativeDataOffClipboard(inDataObject, inIndex, GetFormat(kFileMime), outData, outDataLen); if ( NS_SUCCEEDED(loadResult) && *outData ) { // we have a file path in |data|. Is it an internet shortcut or a normal file? const nsDependentString filepath(static_cast<PRUnichar*>(*outData)); nsCOMPtr<nsILocalFile> file; nsresult rv = NS_NewLocalFile(filepath, PR_TRUE, getter_AddRefs(file)); if (NS_FAILED(rv)) return dataFound; if ( IsInternetShortcut(filepath) ) { nsCAutoString url; ResolveShortcut( file, url ); if ( !url.IsEmpty() ) { // convert it to unicode and pass it out nsMemory::Free(*outData); *outData = UTF8ToNewUnicode(url); *outDataLen = nsCRT::strlen(static_cast<PRUnichar*>(*outData)) * sizeof(PRUnichar); dataFound = PR_TRUE; } } else { // we have a normal file, use some Necko objects to get our file path nsCAutoString urlSpec; NS_GetURLSpecFromFile(file, urlSpec); // convert it to unicode and pass it out nsMemory::Free(*outData); *outData = UTF8ToNewUnicode(urlSpec); *outDataLen = nsCRT::strlen(static_cast<PRUnichar*>(*outData)) * sizeof(PRUnichar); dataFound = PR_TRUE; } // else regular file } return dataFound; } // FindURLFromLocalFile
// nsIConsoleMessage methods NS_IMETHODIMP nsScriptError::GetMessageMoz(PRUnichar **result) { nsresult rv; nsCAutoString message; rv = ToString(message); if (NS_FAILED(rv)) return rv; *result = UTF8ToNewUnicode(message); if (!*result) return NS_ERROR_OUT_OF_MEMORY; return NS_OK; }
// return the error string corresponding to GetLdErrno. // // XXX - deal with optional params // XXX - how does ldap_perror know to look at the global errno? // NS_IMETHODIMP nsLDAPConnection::GetErrorString(PRUnichar **_retval) { NS_ENSURE_ARG_POINTER(_retval); // get the error string // char *rv = ldap_err2string(ldap_get_lderrno(mConnectionHandle, 0, 0)); if (!rv) { return NS_ERROR_OUT_OF_MEMORY; } // make a copy using the XPCOM shared allocator // *_retval = UTF8ToNewUnicode(nsDependentCString(rv)); if (!*_retval) { return NS_ERROR_OUT_OF_MEMORY; } return NS_OK; }
nsresult mozSqlResultMysql::BuildRows() { MYSQL_ROW resultrow; while ((resultrow = mysql_fetch_row(mResult))){ nsCOMPtr<nsIRDFResource> resource; nsresult rv = gRDFService->GetAnonymousResource(getter_AddRefs(resource)); if (NS_FAILED(rv)) return rv; Row* row = Row::Create(mAllocator, resource, mColumnInfo); for (PRInt32 j = 0; j < mColumnInfo.Count(); j++) { char* value = resultrow[j]; if (value){ Cell* cell = row->mCells[j]; cell->SetNull(PR_FALSE); PRInt32 type = cell->GetType(); if (type == mozISqlResult::TYPE_STRING) cell->SetString(UTF8ToNewUnicode(nsDependentCString(value))); else if (type == mozISqlResult::TYPE_INT) PR_sscanf(value, "%d", &cell->mInt); else if (type == mozISqlResult::TYPE_FLOAT) PR_sscanf(value, "%f", &cell->mFloat); else if (type == mozISqlResult::TYPE_DECIMAL) PR_sscanf(value, "%f", &cell->mFloat); else if (type == mozISqlResult::TYPE_DATE || type == mozISqlResult::TYPE_TIME || type == mozISqlResult::TYPE_DATETIME) PR_ParseTimeString(value, PR_FALSE, &cell->mDate); else if (type == mozISqlResult::TYPE_BOOL) cell->mBool = !strcmp(value, "t"); } } mRows.AppendElement(row); nsVoidKey key(resource); mSources.Put(&key, row); } return NS_OK; }
nsresult mozSqlResultMysql::BuildColumnInfo() { MYSQL_FIELD *field; while ((field = mysql_fetch_field(mResult))){ PRUnichar* name = UTF8ToNewUnicode(nsDependentCString(field->name)); PRInt32 type = GetColType(field); nsCAutoString uri(NS_LITERAL_CSTRING("http://www.mozilla.org/SQL-rdf#")); uri.Append(field->name); nsCOMPtr<nsIRDFResource> property; gRDFService->GetResource(uri, getter_AddRefs(property)); ColumnInfo* columnInfo = ColumnInfo::Create(mAllocator, name, type, (PRInt32)field->length, (PRInt32)field->length, (field->flags & PRI_KEY_FLAG), property); mColumnInfo.AppendElement(columnInfo); } return NS_OK; }
// Override a web page NS_IMETHODIMP nsParentalControlsServiceWin::RequestURIOverrides(nsIArray *aTargets, nsIInterfaceRequestor *aWindowContext, bool *_retval) { *_retval = false; if (!mEnabled) return NS_ERROR_NOT_AVAILABLE; NS_ENSURE_ARG_POINTER(aTargets); uint32_t arrayLength = 0; aTargets->GetLength(&arrayLength); if (!arrayLength) return NS_ERROR_INVALID_ARG; if (arrayLength == 1) { nsCOMPtr<nsIURI> uri = do_QueryElementAt(aTargets, 0); if (!uri) return NS_ERROR_INVALID_ARG; return RequestURIOverride(uri, aWindowContext, _retval); } HWND hWnd = nullptr; // If we have a native window, use its handle instead nsCOMPtr<nsIWidget> widget(do_GetInterface(aWindowContext)); if (widget) hWnd = (HWND)widget->GetNativeData(NS_NATIVE_WINDOW); if (hWnd == nullptr) hWnd = GetDesktopWindow(); // The first entry should be the root uri nsAutoCString rootSpec; nsCOMPtr<nsIURI> rootURI = do_QueryElementAt(aTargets, 0); if (!rootURI) return NS_ERROR_INVALID_ARG; rootURI->GetSpec(rootSpec); if (rootSpec.IsEmpty()) return NS_ERROR_INVALID_ARG; // Allocate an array of sub uri int32_t count = arrayLength - 1; nsAutoArrayPtr<LPCWSTR> arrUrls(new LPCWSTR[count]); if (!arrUrls) return NS_ERROR_OUT_OF_MEMORY; uint32_t uriIdx = 0, idx; for (idx = 1; idx < arrayLength; idx++) { nsCOMPtr<nsIURI> uri = do_QueryElementAt(aTargets, idx); if (!uri) continue; nsAutoCString subURI; if (NS_FAILED(uri->GetSpec(subURI))) continue; arrUrls[uriIdx] = (LPCWSTR)UTF8ToNewUnicode(subURI); // allocation if (!arrUrls[uriIdx]) continue; uriIdx++; } if (!uriIdx) return NS_ERROR_INVALID_ARG; BOOL ret; nsRefPtr<IWPCWebSettings> wpcws; if (SUCCEEDED(mPC->GetWebSettings(NULL, getter_AddRefs(wpcws)))) { wpcws->RequestURLOverride(hWnd, NS_ConvertUTF8toUTF16(rootSpec).get(), uriIdx, (LPCWSTR*)arrUrls.get(), &ret); *_retval = ret; } // Free up the allocated strings in our array for (idx = 0; idx < uriIdx; idx++) NS_Free((void*)arrUrls[idx]); return NS_OK; }
nsresult GetSlotWithMechanism(uint32_t aMechanism, nsIInterfaceRequestor* m_ctx, PK11SlotInfo** aSlot, nsNSSShutDownPreventionLock& /*proofOfLock*/) { PK11SlotList * slotList = nullptr; char16_t** tokenNameList = nullptr; nsITokenDialogs * dialogs; char16_t *unicodeTokenChosen; PK11SlotListElement *slotElement, *tmpSlot; uint32_t numSlots = 0, i = 0; bool canceled; nsresult rv = NS_OK; *aSlot = nullptr; // Get the slot slotList = PK11_GetAllTokens(MapGenMechToAlgoMech(aMechanism), true, true, m_ctx); if (!slotList || !slotList->head) { rv = NS_ERROR_FAILURE; goto loser; } if (!slotList->head->next) { /* only one slot available, just return it */ *aSlot = slotList->head->slot; } else { // Gerenate a list of slots and ask the user to choose // tmpSlot = slotList->head; while (tmpSlot) { numSlots++; tmpSlot = tmpSlot->next; } // Allocate the slot name buffer // tokenNameList = static_cast<char16_t**>(moz_xmalloc(sizeof(char16_t *) * numSlots)); if (!tokenNameList) { rv = NS_ERROR_OUT_OF_MEMORY; goto loser; } i = 0; slotElement = PK11_GetFirstSafe(slotList); while (slotElement) { tokenNameList[i] = UTF8ToNewUnicode(nsDependentCString(PK11_GetTokenName(slotElement->slot))); slotElement = PK11_GetNextSafe(slotList, slotElement, false); if (tokenNameList[i]) i++; else { // OOM. adjust numSlots so we don't free unallocated memory. numSlots = i; PK11_FreeSlotListElement(slotList, slotElement); rv = NS_ERROR_OUT_OF_MEMORY; goto loser; } } /* Throw up the token list dialog and get back the token */ rv = getNSSDialogs((void**)&dialogs, NS_GET_IID(nsITokenDialogs), NS_TOKENDIALOGS_CONTRACTID); if (NS_FAILED(rv)) goto loser; if (!tokenNameList || !*tokenNameList) { rv = NS_ERROR_OUT_OF_MEMORY; } else { rv = dialogs->ChooseToken(m_ctx, (const char16_t**)tokenNameList, numSlots, &unicodeTokenChosen, &canceled); } NS_RELEASE(dialogs); if (NS_FAILED(rv)) goto loser; if (canceled) { rv = NS_ERROR_NOT_AVAILABLE; goto loser; } // Get the slot // slotElement = PK11_GetFirstSafe(slotList); nsAutoString tokenStr(unicodeTokenChosen); while (slotElement) { if (tokenStr.Equals(NS_ConvertUTF8toUTF16(PK11_GetTokenName(slotElement->slot)))) { *aSlot = slotElement->slot; PK11_FreeSlotListElement(slotList, slotElement); break; } slotElement = PK11_GetNextSafe(slotList, slotElement, false); } if(!(*aSlot)) { rv = NS_ERROR_FAILURE; goto loser; } } // Get a reference to the slot // PK11_ReferenceSlot(*aSlot); loser: if (slotList) { PK11_FreeSlotList(slotList); } if (tokenNameList) { NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(numSlots, tokenNameList); } return rv; }
void EmbedPrompter::GetPassword(PRUnichar **aPass) { *aPass = UTF8ToNewUnicode(mPass); }
void EmbedPrompter::GetUser(PRUnichar **aUser) { *aUser = UTF8ToNewUnicode(mUser); }
void EmbedPrompter::GetTextValue(PRUnichar **aTextValue) { *aTextValue = UTF8ToNewUnicode(mTextValue); }