bool IDBTransaction::StartSavepoint() { NS_PRECONDITION(!NS_IsMainThread(), "Wrong thread!"); NS_PRECONDITION(mConnection, "No connection!"); nsresult rv; if (!mHasInitialSavepoint) { NS_NAMED_LITERAL_CSTRING(beginSavepoint, "SAVEPOINT " SAVEPOINT_INITIAL); rv = mConnection->ExecuteSimpleSQL(beginSavepoint); NS_ENSURE_SUCCESS(rv, false); mHasInitialSavepoint = true; } NS_ASSERTION(!mSavepointCount, "Mismatch!"); mSavepointCount = 1; // TODO try to cache this statement NS_NAMED_LITERAL_CSTRING(savepoint, "SAVEPOINT " SAVEPOINT_INTERMEDIATE); rv = mConnection->ExecuteSimpleSQL(savepoint); NS_ENSURE_SUCCESS(rv, false); return true; }
bool nsPluginsDir::IsPluginFile(nsIFile* file) { nsAutoCString filename; if (NS_FAILED(file->GetNativeLeafName(filename))) return false; #ifdef ANDROID // It appears that if you load // 'libstagefright_honeycomb.so' on froyo, or // 'libstagefright_froyo.so' on honeycomb, we will abort. // Since these are just helper libs, we can ignore. const char *cFile = filename.get(); if (strstr(cFile, "libstagefright") != NULL) return false; #endif NS_NAMED_LITERAL_CSTRING(dllSuffix, LOCAL_PLUGIN_DLL_SUFFIX); if (filename.Length() > dllSuffix.Length() && StringEndsWith(filename, dllSuffix)) return true; #ifdef LOCAL_PLUGIN_DLL_ALT_SUFFIX NS_NAMED_LITERAL_CSTRING(dllAltSuffix, LOCAL_PLUGIN_DLL_ALT_SUFFIX); if (filename.Length() > dllAltSuffix.Length() && StringEndsWith(filename, dllAltSuffix)) return true; #endif return false; }
nsresult CountHelper::DoDatabaseWork(mozIStorageConnection* aConnection) { nsCString table; if (mIndex->IsUnique()) { table.AssignLiteral("unique_index_data"); } else { table.AssignLiteral("index_data"); } NS_NAMED_LITERAL_CSTRING(lowerKeyName, "lower_key"); NS_NAMED_LITERAL_CSTRING(upperKeyName, "upper_key"); NS_NAMED_LITERAL_CSTRING(value, "value"); nsCAutoString keyRangeClause; if (mKeyRange) { if (!mKeyRange->Lower().IsUnset()) { AppendConditionClause(value, lowerKeyName, false, !mKeyRange->IsLowerOpen(), keyRangeClause); } if (!mKeyRange->Upper().IsUnset()) { AppendConditionClause(value, upperKeyName, true, !mKeyRange->IsUpperOpen(), keyRangeClause); } } nsCString query = NS_LITERAL_CSTRING("SELECT count(*) FROM ") + table + NS_LITERAL_CSTRING(" WHERE index_id = :id") + keyRangeClause; nsCOMPtr<mozIStorageStatement> stmt = mTransaction->GetCachedStatement(query); NS_ENSURE_TRUE(stmt, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR); mozStorageStatementScoper scoper(stmt); nsresult rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("id"), mIndex->Id()); NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR); if (mKeyRange) { if (!mKeyRange->Lower().IsUnset()) { rv = mKeyRange->Lower().BindToStatement(stmt, lowerKeyName); NS_ENSURE_SUCCESS(rv, rv); } if (!mKeyRange->Upper().IsUnset()) { rv = mKeyRange->Upper().BindToStatement(stmt, upperKeyName); NS_ENSURE_SUCCESS(rv, rv); } } bool hasResult; rv = stmt->ExecuteStep(&hasResult); NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR); NS_ENSURE_TRUE(hasResult, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR); mCount = stmt->AsInt64(0); return NS_OK; }
nsresult TestNativeXMLHttpRequest() { nsresult rv; nsCOMPtr<nsIXMLHttpRequest> xhr = do_CreateInstance(NS_XMLHTTPREQUEST_CONTRACTID, &rv); TEST_ENSURE_SUCCESS(rv, "Couldn't create nsIXMLHttpRequest instance!"); NS_NAMED_LITERAL_CSTRING(getString, "GET"); NS_NAMED_LITERAL_CSTRING(testURL, TEST_URL); const nsAString& empty = EmptyString(); printf("*** About to see an expected warning about mPrincipal:\n"); rv = xhr->OpenRequest(getString, testURL, PR_FALSE, empty, empty); printf("*** End of expected warning output.\n"); TEST_ENSURE_FAILED(rv, "OpenRequest should have failed!"); nsCOMPtr<nsIScriptSecurityManager> secman = do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv); TEST_ENSURE_SUCCESS(rv, "Couldn't get script security manager!"); nsCOMPtr<nsIPrincipal> systemPrincipal; rv = secman->GetSystemPrincipal(getter_AddRefs(systemPrincipal)); TEST_ENSURE_SUCCESS(rv, "Couldn't get system principal!"); rv = xhr->Init(systemPrincipal, nsnull, nsnull, nsnull); TEST_ENSURE_SUCCESS(rv, "Couldn't initialize the XHR!"); rv = xhr->OpenRequest(getString, testURL, PR_FALSE, empty, empty); TEST_ENSURE_SUCCESS(rv, "OpenRequest failed!"); rv = xhr->Send(nsnull); TEST_ENSURE_SUCCESS(rv, "Send failed!"); nsAutoString response; rv = xhr->GetResponseText(response); TEST_ENSURE_SUCCESS(rv, "GetResponse failed!"); if (!response.EqualsLiteral(TEST_URL_CONTENT)) { fail("Response text does not match!"); return NS_ERROR_FAILURE; } nsCOMPtr<nsIDOMDocument> dom; rv = xhr->GetResponseXML(getter_AddRefs(dom)); TEST_ENSURE_SUCCESS(rv, "GetResponseXML failed!"); if (!dom) { fail("No DOM document constructed!"); return NS_ERROR_FAILURE; } passed("Native XMLHttpRequest"); return NS_OK; }
nsresult nsResProtocolHandler::Init() { if (!mSubstitutions.Init(32)) return NS_ERROR_UNEXPECTED; nsresult rv; mIOService = do_GetIOService(&rv); NS_ENSURE_SUCCESS(rv, rv); #ifdef MOZ_OMNIJAR nsCOMPtr<nsIFile> omniJar(mozilla::OmnijarPath()); if (omniJar) return Init(omniJar); #endif // these entries should be kept in sync with the omnijar Init function // // make resource:/// point to the application directory // rv = AddSpecialDir(NS_OS_CURRENT_PROCESS_DIR, EmptyCString()); NS_ENSURE_SUCCESS(rv, rv); // // make resource://gre/ point to the GRE directory // rv = AddSpecialDir(NS_GRE_DIR, kGRE); NS_ENSURE_SUCCESS(rv, rv); // make resource://gre-resources/ point to gre toolkit[.jar]/res nsCOMPtr<nsIURI> greURI; nsCOMPtr<nsIURI> greResURI; GetSubstitution(kGRE, getter_AddRefs(greURI)); #ifdef MOZ_CHROME_FILE_FORMAT_JAR NS_NAMED_LITERAL_CSTRING(strGRE_RES_URL, "jar:chrome/toolkit.jar!/res/"); #else NS_NAMED_LITERAL_CSTRING(strGRE_RES_URL, "chrome/toolkit/res/"); #endif rv = mIOService->NewURI(strGRE_RES_URL, nsnull, greURI, getter_AddRefs(greResURI)); SetSubstitution(kGRE_RESOURCES, greResURI); //XXXbsmedberg Neil wants a resource://pchrome/ for the profile chrome dir... // but once I finish multiple chrome registration I'm not sure that it is needed // XXX dveditz: resource://pchrome/ defeats profile directory salting // if web content can load it. Tread carefully. return rv; }
NS_IMETHODIMP CommitHelper::Run() { if (NS_IsMainThread()) { NS_ASSERTION(mDoomedObjects.IsEmpty(), "Didn't release doomed objects!"); nsCOMPtr<nsIDOMEvent> event; if (mAborted) { event = IDBEvent::CreateGenericEvent(NS_LITERAL_STRING(ABORT_EVT_STR)); } else { event = IDBEvent::CreateGenericEvent(NS_LITERAL_STRING(COMPLETE_EVT_STR)); } NS_ENSURE_TRUE(event, NS_ERROR_FAILURE); PRBool dummy; if (NS_FAILED(mTransaction->DispatchEvent(event, &dummy))) { NS_WARNING("Dispatch failed!"); } mTransaction = nsnull; return NS_OK; } if (mAborted) { NS_ASSERTION(mConnection, "This had better not be null!"); NS_NAMED_LITERAL_CSTRING(rollback, "ROLLBACK TRANSACTION"); if (NS_FAILED(mConnection->ExecuteSimpleSQL(rollback))) { NS_WARNING("Failed to rollback transaction!"); } } else if (mHasInitialSavepoint) { NS_ASSERTION(mConnection, "This had better not be null!"); NS_NAMED_LITERAL_CSTRING(release, "RELEASE " SAVEPOINT_INITIAL); if (NS_FAILED(mConnection->ExecuteSimpleSQL(release))) { NS_WARNING("Failed to release transaction!"); } } mDoomedObjects.Clear(); mConnection->Close(); mConnection = nsnull; return NS_OK; }
bool IsVideoContentType(const nsCString& aContentType) { NS_NAMED_LITERAL_CSTRING(video, "video"); if (FindInReadable(video, aContentType)) { return true; } return false; }
/* static */ nsresult sbURIChecker::FixupPath( const nsACString& aPath, nsACString& _retval ) { // aPath may be empty if ( aPath.IsEmpty() ) { _retval.Truncate(); return NS_OK; } NS_NAMED_LITERAL_CSTRING( slashString, "/" ); // Construct a dummy URL that incorporates the path that the user passed in. nsCString dummyURL("http://dummy.com"); // Make sure that aPath begins with a slash. Otherwise we could end up with // something like "foo.combar" rather than "foo.com/bar". if ( !StringBeginsWith( aPath, slashString ) ) { dummyURL.Append(slashString); } dummyURL.Append(aPath); nsCOMPtr<nsIURI> uri; nsresult rv = NS_NewURI( getter_AddRefs(uri), dummyURL ); NS_ENSURE_SUCCESS( rv, rv ); // Hand off. return sbURIChecker::FixupPath( uri, _retval ); }
PRUint16 RemoveHelper::DoDatabaseWork(mozIStorageConnection* aConnection) { NS_PRECONDITION(aConnection, "Passed a null connection!"); nsCOMPtr<mozIStorageStatement> stmt = mTransaction->RemoveStatement(mAutoIncrement); NS_ENSURE_TRUE(stmt, nsIIDBDatabaseException::UNKNOWN_ERR); mozStorageStatementScoper scoper(stmt); nsresult rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("osid"), mOSID); NS_ENSURE_SUCCESS(rv, nsIIDBDatabaseException::UNKNOWN_ERR); NS_ASSERTION(!mKey.IsUnset() && !mKey.IsNull(), "Must have a key here!"); NS_NAMED_LITERAL_CSTRING(key_value, "key_value"); if (mKey.IsInt()) { rv = stmt->BindInt64ByName(key_value, mKey.IntValue()); } else if (mKey.IsString()) { rv = stmt->BindStringByName(key_value, mKey.StringValue()); } else { NS_NOTREACHED("Unknown key type!"); } NS_ENSURE_SUCCESS(rv, nsIIDBDatabaseException::UNKNOWN_ERR); // Search for it! rv = stmt->Execute(); NS_ENSURE_SUCCESS(rv, nsIIDBDatabaseException::UNKNOWN_ERR); return OK; }
nsresult nsDirIndexParser::Init() { mLineStart = 0; mHasDescription = PR_FALSE; mFormat = nsnull; // get default charset to be used for directory listings (fallback to // ISO-8859-1 if pref is unavailable). NS_NAMED_LITERAL_CSTRING(kFallbackEncoding, "ISO-8859-1"); nsXPIDLString defCharset; nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID)); if (prefs) { nsCOMPtr<nsIPrefLocalizedString> prefVal; prefs->GetComplexValue("intl.charset.default", NS_GET_IID(nsIPrefLocalizedString), getter_AddRefs(prefVal)); if (prefVal) prefVal->ToString(getter_Copies(defCharset)); } if (!defCharset.IsEmpty()) LossyCopyUTF16toASCII(defCharset, mEncoding); // charset labels are always ASCII else mEncoding.Assign(kFallbackEncoding); nsresult rv; // XXX not threadsafe if (gRefCntParser++ == 0) rv = CallGetService(NS_ITEXTTOSUBURI_CONTRACTID, &gTextToSubURI); else rv = NS_OK; return rv; }
nsresult IDBKeyRange::BindToStatement(mozIStorageStatement* aStatement) const { MOZ_ASSERT(aStatement); NS_NAMED_LITERAL_CSTRING(lowerKey, "lower_key"); if (IsOnly()) { return Lower().BindToStatement(aStatement, lowerKey); } nsresult rv; if (!Lower().IsUnset()) { rv = Lower().BindToStatement(aStatement, lowerKey); if (NS_WARN_IF(NS_FAILED(rv))) { return rv; } } if (!Upper().IsUnset()) { rv = Upper().BindToStatement(aStatement, NS_LITERAL_CSTRING("upper_key")); if (NS_WARN_IF(NS_FAILED(rv))) { return rv; } } return NS_OK; }
void Service::minimizeMemory() { nsTArray<nsRefPtr<Connection> > connections; getConnections(connections); for (uint32_t i = 0; i < connections.Length(); i++) { nsRefPtr<Connection> conn = connections[i]; if (conn->connectionReady()) { NS_NAMED_LITERAL_CSTRING(shrinkPragma, "PRAGMA shrink_memory"); nsCOMPtr<mozIStorageConnection> syncConn = do_QueryInterface( NS_ISUPPORTS_CAST(mozIStorageAsyncConnection*, conn)); DebugOnly<nsresult> rv; if (!syncConn) { nsCOMPtr<mozIStoragePendingStatement> ps; rv = connections[i]->ExecuteSimpleSQLAsync(shrinkPragma, nullptr, getter_AddRefs(ps)); } else { rv = connections[i]->ExecuteSimpleSQL(shrinkPragma); } MOZ_ASSERT(NS_SUCCEEDED(rv), "Should have been able to purge sqlite caches"); } }
nsresult net_GetURLSpecFromActualFile(nsIFile *aFile, nsACString &result) { nsresult rv; nsAutoString path; // construct URL spec from file path rv = aFile->GetPath(path); if (NS_FAILED(rv)) return rv; // Replace \ with / to convert to an url path.ReplaceChar(char16_t(0x5Cu), char16_t(0x2Fu)); nsAutoCString escPath; // Windows Desktop paths begin with a drive letter, so need an 'extra' // slash at the begining // C:\Windows => file:///C:/Windows NS_NAMED_LITERAL_CSTRING(prefix, "file:///"); // Escape the path with the directory mask NS_ConvertUTF16toUTF8 ePath(path); if (NS_EscapeURL(ePath.get(), -1, esc_Directory+esc_Forced, escPath)) escPath.Insert(prefix, 0); else escPath.Assign(prefix + ePath); // esc_Directory does not escape the semicolons, so if a filename // contains semicolons we need to manually escape them. // This replacement should be removed in bug #473280 escPath.ReplaceSubstring(";", "%3b"); result = escPath; return NS_OK; }
void nsMsgI18NConvertRawBytesToUTF8(const nsCString& inString, const char* charset, nsACString& outString) { if (MsgIsUTF8(inString)) { outString.Assign(inString); return; } nsAutoString utf16Text; nsresult rv = ConvertToUnicode(charset, inString, utf16Text); if (NS_SUCCEEDED(rv)) { CopyUTF16toUTF8(utf16Text, outString); return; } // EF BF BD (UTF-8 encoding of U+FFFD) NS_NAMED_LITERAL_CSTRING(utf8ReplacementChar, "\357\277\275"); const char* cur = inString.BeginReading(); const char* end = inString.EndReading(); outString.Truncate(); while (cur < end) { char c = *cur++; if (c & char(0x80)) outString.Append(utf8ReplacementChar); else outString.Append(c); } }
nsresult net_GetURLSpecFromActualFile(nsIFile *aFile, nsACString &result) { // NOTE: This is identical to the implementation in nsURLHelperUnix.cpp nsresult rv; nsCAutoString ePath; // construct URL spec from native file path rv = aFile->GetNativePath(ePath); if (NS_FAILED(rv)) return rv; nsCAutoString escPath; NS_NAMED_LITERAL_CSTRING(prefix, "file://"); // Escape the path with the directory mask if (NS_EscapeURL(ePath.get(), ePath.Length(), esc_Directory+esc_Forced, escPath)) escPath.Insert(prefix, 0); else escPath.Assign(prefix + ePath); // esc_Directory does not escape the semicolons, so if a filename // contains semicolons we need to manually escape them. // This replacement should be removed in bug #473280 escPath.ReplaceSubstring(";", "%3b"); result = escPath; return NS_OK; }
NS_IMETHODIMP sbScriptableFilterResult::GetClassName(char * *aClassName) { NS_ENSURE_ARG_POINTER(aClassName); NS_NAMED_LITERAL_CSTRING( kClassName, "sbScriptableFilterResult" ); *aClassName = ToNewCString(kClassName); return aClassName ? NS_OK : NS_ERROR_OUT_OF_MEMORY; }
bool nsCoreUtils::IsErrorPage(nsIDocument *aDocument) { nsIURI *uri = aDocument->GetDocumentURI(); bool isAboutScheme = false; uri->SchemeIs("about", &isAboutScheme); if (!isAboutScheme) return false; nsAutoCString path; uri->GetPath(path); NS_NAMED_LITERAL_CSTRING(neterror, "neterror"); NS_NAMED_LITERAL_CSTRING(certerror, "certerror"); return StringBeginsWith(path, neterror) || StringBeginsWith(path, certerror); }
nsresult GetKeyHelper::DoDatabaseWork(mozIStorageConnection* aConnection) { NS_ASSERTION(aConnection, "Passed a null connection!"); nsCOMPtr<mozIStorageStatement> stmt = mTransaction->IndexGetStatement(mIndex->IsUnique(), mIndex->IsAutoIncrement()); NS_ENSURE_TRUE(stmt, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR); mozStorageStatementScoper scoper(stmt); nsresult rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("index_id"), mIndex->Id()); NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR); NS_NAMED_LITERAL_CSTRING(value, "value"); if (mKey.IsInt()) { rv = stmt->BindInt64ByName(value, mKey.IntValue()); } else if (mKey.IsString()) { rv = stmt->BindStringByName(value, mKey.StringValue()); } else { NS_NOTREACHED("Bad key type!"); } NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR); mKey = Key::UNSETKEY; PRBool hasResult; rv = stmt->ExecuteStep(&hasResult); NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR); if (hasResult) { PRInt32 keyType; rv = stmt->GetTypeOfIndex(0, &keyType); NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR); NS_ASSERTION(keyType == mozIStorageStatement::VALUE_TYPE_INTEGER || keyType == mozIStorageStatement::VALUE_TYPE_TEXT, "Bad key type!"); if (keyType == mozIStorageStatement::VALUE_TYPE_INTEGER) { mKey = stmt->AsInt64(0); } else if (keyType == mozIStorageStatement::VALUE_TYPE_TEXT) { rv = stmt->GetString(0, mKey.ToString()); NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR); } else { NS_NOTREACHED("Bad SQLite type!"); } } return NS_OK; }
nsresult nsAboutCacheEntry::WriteCacheEntryUnavailable() { uint32_t n; NS_NAMED_LITERAL_CSTRING(buffer, "The cache entry you selected is not available."); mOutputStream->Write(buffer.get(), buffer.Length(), &n); return NS_OK; }
NS_IMETHODIMP nsIncrementalDownload::AsyncOnChannelRedirect(nsIChannel *oldChannel, nsIChannel *newChannel, uint32_t flags, nsIAsyncVerifyRedirectCallback *cb) { // In response to a redirect, we need to propagate the Range header. See bug // 311595. Any failure code returned from this function aborts the redirect. nsCOMPtr<nsIHttpChannel> http = do_QueryInterface(oldChannel); NS_ENSURE_STATE(http); nsCOMPtr<nsIHttpChannel> newHttpChannel = do_QueryInterface(newChannel); NS_ENSURE_STATE(newHttpChannel); NS_NAMED_LITERAL_CSTRING(rangeHdr, "Range"); nsresult rv = ClearRequestHeader(newHttpChannel); if (NS_FAILED(rv)) return rv; // If we didn't have a Range header, then we must be doing a full download. nsAutoCString rangeVal; http->GetRequestHeader(rangeHdr, rangeVal); if (!rangeVal.IsEmpty()) { rv = newHttpChannel->SetRequestHeader(rangeHdr, rangeVal, false); NS_ENSURE_SUCCESS(rv, rv); } // A redirection changes the validator mPartialValidator.Truncate(); if (mCacheBust) { newHttpChannel->SetRequestHeader(NS_LITERAL_CSTRING("Cache-Control"), NS_LITERAL_CSTRING("no-cache"), false); newHttpChannel->SetRequestHeader(NS_LITERAL_CSTRING("Pragma"), NS_LITERAL_CSTRING("no-cache"), false); } // Prepare to receive callback mRedirectCallback = cb; mNewRedirectChannel = newChannel; // Give the observer a chance to see this redirect notification. nsCOMPtr<nsIChannelEventSink> sink = do_GetInterface(mObserver); if (sink) { rv = sink->AsyncOnChannelRedirect(oldChannel, newChannel, flags, this); if (NS_FAILED(rv)) { mRedirectCallback = nullptr; mNewRedirectChannel = nullptr; } return rv; } (void) OnRedirectVerifyCallback(NS_OK); return NS_OK; }
PRBool nsPluginsDir::IsPluginFile(nsIFile* file) { nsCAutoString filename; if (NS_FAILED(file->GetNativeLeafName(filename))) return PR_FALSE; NS_NAMED_LITERAL_CSTRING(dllSuffix, LOCAL_PLUGIN_DLL_SUFFIX); if (filename.Length() > dllSuffix.Length() && StringEndsWith(filename, dllSuffix)) return PR_TRUE; #ifdef LOCAL_PLUGIN_DLL_ALT_SUFFIX NS_NAMED_LITERAL_CSTRING(dllAltSuffix, LOCAL_PLUGIN_DLL_ALT_SUFFIX); if (filename.Length() > dllAltSuffix.Length() && StringEndsWith(filename, dllAltSuffix)) return PR_TRUE; #endif return PR_FALSE; }
PRUint16 UpdateHelper::DoDatabaseWork(mozIStorageConnection* aConnection) { NS_PRECONDITION(aConnection, "Passed a null connection!"); nsresult rv; NS_ASSERTION(!mKey.IsUnset() && !mKey.IsNull(), "Badness!"); nsCOMPtr<mozIStorageStatement> stmt = mTransaction->AddStatement(false, true, mAutoIncrement); NS_ENSURE_TRUE(stmt, nsIIDBDatabaseException::UNKNOWN_ERR); mozStorageStatementScoper scoper(stmt); Savepoint savepoint(mTransaction); NS_NAMED_LITERAL_CSTRING(keyValue, "key_value"); rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("osid"), mOSID); NS_ENSURE_SUCCESS(rv, nsIIDBDatabaseException::UNKNOWN_ERR); if (mKey.IsInt()) { rv = stmt->BindInt64ByName(keyValue, mKey.IntValue()); } else if (mKey.IsString()) { rv = stmt->BindStringByName(keyValue, mKey.StringValue()); } else { NS_NOTREACHED("Unknown key type!"); } NS_ENSURE_SUCCESS(rv, nsIIDBDatabaseException::UNKNOWN_ERR); rv = stmt->BindStringByName(NS_LITERAL_CSTRING("data"), mValue); NS_ENSURE_SUCCESS(rv, nsIIDBDatabaseException::UNKNOWN_ERR); if (NS_FAILED(stmt->Execute())) { return nsIIDBDatabaseException::CONSTRAINT_ERR; } // Update our indexes if needed. if (!mIndexUpdateInfo.IsEmpty()) { PRInt64 objectDataId = mAutoIncrement ? mKey.IntValue() : LL_MININT; rv = IDBObjectStore::UpdateIndexes(mTransaction, mOSID, mKey, mAutoIncrement, true, objectDataId, mIndexUpdateInfo); if (rv == NS_ERROR_STORAGE_CONSTRAINT) { return nsIIDBDatabaseException::CONSTRAINT_ERR; } NS_ENSURE_SUCCESS(rv, nsIIDBDatabaseException::UNKNOWN_ERR); } rv = savepoint.Release(); return NS_SUCCEEDED(rv) ? OK : nsIIDBDatabaseException::UNKNOWN_ERR; }
void IDBKeyRange::GetBindingClause(const nsACString& aKeyColumnName, nsACString& _retval) const { NS_NAMED_LITERAL_CSTRING(andStr, " AND "); NS_NAMED_LITERAL_CSTRING(spacecolon, " :"); NS_NAMED_LITERAL_CSTRING(lowerKey, "lower_key"); if (IsOnly()) { // Both keys are set and they're equal. _retval = andStr + aKeyColumnName + NS_LITERAL_CSTRING(" =") + spacecolon + lowerKey; return; } nsAutoCString clause; if (!Lower().IsUnset()) { // Lower key is set. clause.Append(andStr + aKeyColumnName); clause.AppendLiteral(" >"); if (!LowerOpen()) { clause.Append('='); } clause.Append(spacecolon + lowerKey); } if (!Upper().IsUnset()) { // Upper key is set. clause.Append(andStr + aKeyColumnName); clause.AppendLiteral(" <"); if (!UpperOpen()) { clause.Append('='); } clause.Append(spacecolon + NS_LITERAL_CSTRING("upper_key")); } _retval = clause; }
NS_IMETHODIMP nsDOMMemoryMultiReporter::CollectReports(nsIMemoryMultiReporterCallback* aCb, nsISupports* aClosure) { nsGlobalWindow::WindowByIdTable* windowsById = nsGlobalWindow::GetWindowsTable(); NS_ENSURE_TRUE(windowsById, NS_OK); // Hold on to every window in memory so that window objects can't be // destroyed while we're calling the memory reporter callback. WindowArray windows; windowsById->Enumerate(GetWindows, &windows); // Collect window memory usage. nsRefPtr<nsGlobalWindow> *w = windows.Elements(); nsRefPtr<nsGlobalWindow> *end = w + windows.Length(); WindowTotals windowTotals; for (; w != end; ++w) { CollectWindowReports(*w, &windowTotals, aCb, aClosure); } NS_NAMED_LITERAL_CSTRING(kDomTotalWindowsDesc, "Memory used for the DOM within windows. This is the sum of all windows' " "'dom' numbers."); aCb->Callback(EmptyCString(), NS_LITERAL_CSTRING("dom-total-window"), nsIMemoryReporter::KIND_OTHER, nsIMemoryReporter::UNITS_BYTES, windowTotals.mDom, kDomTotalWindowsDesc, aClosure); NS_NAMED_LITERAL_CSTRING(kLayoutTotalWindowStyleSheetsDesc, "Memory used for style sheets within windows. This is the sum of all windows' " "'style-sheets' numbers."); aCb->Callback(EmptyCString(), NS_LITERAL_CSTRING("style-sheets-total-window"), nsIMemoryReporter::KIND_OTHER, nsIMemoryReporter::UNITS_BYTES, windowTotals.mStyleSheets, kLayoutTotalWindowStyleSheetsDesc, aClosure); return NS_OK; }
NS_IMETHODIMP nsLocalFile::SetRelativeDescriptor(nsIFile* aFromFile, const nsACString& aRelativeDesc) { NS_NAMED_LITERAL_CSTRING(kParentDirStr, "../"); nsCOMPtr<nsIFile> targetFile; nsresult rv = aFromFile->Clone(getter_AddRefs(targetFile)); if (NS_FAILED(rv)) { return rv; } // // aRelativeDesc is UTF-8 encoded // nsCString::const_iterator strBegin, strEnd; aRelativeDesc.BeginReading(strBegin); aRelativeDesc.EndReading(strEnd); nsCString::const_iterator nodeBegin(strBegin), nodeEnd(strEnd); nsCString::const_iterator pos(strBegin); nsCOMPtr<nsIFile> parentDir; while (FindInReadable(kParentDirStr, nodeBegin, nodeEnd)) { rv = targetFile->GetParent(getter_AddRefs(parentDir)); if (NS_FAILED(rv)) { return rv; } if (!parentDir) { return NS_ERROR_FILE_UNRECOGNIZED_PATH; } targetFile = parentDir; nodeBegin = nodeEnd; pos = nodeEnd; nodeEnd = strEnd; } nodeBegin = nodeEnd = pos; while (nodeEnd != strEnd) { FindCharInReadable('/', nodeEnd, strEnd); targetFile->Append(NS_ConvertUTF8toUTF16(Substring(nodeBegin, nodeEnd))); if (nodeEnd != strEnd) { // If there's more left in the string, inc over the '/' nodeEnd is on. ++nodeEnd; } nodeBegin = nodeEnd; } return InitWithFile(targetFile); }
void Service::minimizeMemory() { nsTArray<RefPtr<Connection> > connections; getConnections(connections); for (uint32_t i = 0; i < connections.Length(); i++) { RefPtr<Connection> conn = connections[i]; // For non-main-thread owning/opening threads, we may be racing against them // closing their connection or their thread. That's okay, see below. if (!conn->connectionReady()) continue; NS_NAMED_LITERAL_CSTRING(shrinkPragma, "PRAGMA shrink_memory"); nsCOMPtr<mozIStorageConnection> syncConn = do_QueryInterface( NS_ISUPPORTS_CAST(mozIStorageAsyncConnection*, conn)); bool onOpenedThread = false; if (!syncConn) { // This is a mozIStorageAsyncConnection, it can only be used on the main // thread, so we can do a straight API call. nsCOMPtr<mozIStoragePendingStatement> ps; DebugOnly<nsresult> rv = conn->ExecuteSimpleSQLAsync(shrinkPragma, nullptr, getter_AddRefs(ps)); MOZ_ASSERT(NS_SUCCEEDED(rv), "Should have purged sqlite caches"); } else if (NS_SUCCEEDED(conn->threadOpenedOn->IsOnCurrentThread(&onOpenedThread)) && onOpenedThread) { if (conn->isAsyncExecutionThreadAvailable()) { nsCOMPtr<mozIStoragePendingStatement> ps; DebugOnly<nsresult> rv = conn->ExecuteSimpleSQLAsync(shrinkPragma, nullptr, getter_AddRefs(ps)); MOZ_ASSERT(NS_SUCCEEDED(rv), "Should have purged sqlite caches"); } else { conn->ExecuteSimpleSQL(shrinkPragma); } } else { // We are on the wrong thread, the query should be executed on the // opener thread, so we must dispatch to it. // It's possible the connection is already closed or will be closed by the // time our runnable runs. ExecuteSimpleSQL will safely return with a // failure in that case. If the thread is shutting down or shut down, the // dispatch will fail and that's okay. nsCOMPtr<nsIRunnable> event = NewRunnableMethod<const nsCString>( "Connection::ExecuteSimpleSQL", conn, &Connection::ExecuteSimpleSQL, shrinkPragma); Unused << conn->threadOpenedOn->Dispatch(event, NS_DISPATCH_NORMAL); } } }
NS_IMETHODIMP nsViewSourceChannel::VisitResponseHeaders(nsIHttpHeaderVisitor *aVisitor) { if (!mHttpChannel) return NS_ERROR_NULL_POINTER; NS_NAMED_LITERAL_CSTRING(contentTypeStr, "Content-Type"); nsAutoCString contentType; nsresult rv = mHttpChannel->GetResponseHeader(contentTypeStr, contentType); if (NS_SUCCEEDED(rv)) aVisitor->VisitHeader(contentTypeStr, contentType); return NS_OK; }
nsresult nsProfileMigrator::GetDefaultMailMigratorKey( nsACString& aKey, nsCOMPtr<nsIMailProfileMigrator>& mailMigrator) { // look up the value of profile.force.migration in case we are supposed to // force migration using a particular migrator.... nsresult rv = NS_OK; nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); NS_ENSURE_SUCCESS(rv, rv); nsCString forceMigrationType; prefs->GetCharPref("profile.force.migration", forceMigrationType); // if we are being forced to migrate to a particular migration type, then // create an instance of that migrator and return it. NS_NAMED_LITERAL_CSTRING(migratorPrefix, NS_MAILPROFILEMIGRATOR_CONTRACTID_PREFIX); nsAutoCString migratorID; if (!forceMigrationType.IsEmpty()) { bool exists = false; migratorID = migratorPrefix; migratorID.Append(forceMigrationType); mailMigrator = do_CreateInstance(migratorID.get()); if (!mailMigrator) return NS_ERROR_NOT_AVAILABLE; mailMigrator->GetSourceExists(&exists); /* trying to force migration on a source which doesn't * have any profiles. */ if (!exists) return NS_ERROR_NOT_AVAILABLE; aKey = forceMigrationType; return NS_OK; } #define MAX_SOURCE_LENGTH 10 const char sources[][MAX_SOURCE_LENGTH] = {"seamonkey", "outlook", ""}; for (uint32_t i = 0; sources[i][0]; ++i) { migratorID = migratorPrefix; migratorID.Append(sources[i]); mailMigrator = do_CreateInstance(migratorID.get()); if (!mailMigrator) continue; bool exists = false; mailMigrator->GetSourceExists(&exists); if (exists) { mailMigrator = nullptr; return NS_OK; } } return NS_ERROR_NOT_AVAILABLE; }
void IDBTransaction::RollbackSavepoint() { NS_PRECONDITION(!NS_IsMainThread(), "Wrong thread!"); NS_PRECONDITION(mConnection, "No connection!"); NS_ASSERTION(mSavepointCount == 1, "Mismatch!"); mSavepointCount = 0; // TODO try to cache this statement NS_NAMED_LITERAL_CSTRING(savepoint, "ROLLBACK TO " SAVEPOINT_INTERMEDIATE); if (NS_FAILED(mConnection->ExecuteSimpleSQL(savepoint))) { NS_ERROR("Rollback failed!"); } }
nsresult IDBTransaction::ReleaseSavepoint() { NS_PRECONDITION(!NS_IsMainThread(), "Wrong thread!"); NS_PRECONDITION(mConnection, "No connection!"); NS_ASSERTION(mSavepointCount == 1, "Mismatch!"); mSavepointCount = 0; // TODO try to cache this statement NS_NAMED_LITERAL_CSTRING(savepoint, "RELEASE " SAVEPOINT_INTERMEDIATE); nsresult rv = mConnection->ExecuteSimpleSQL(savepoint); NS_ENSURE_SUCCESS(rv, rv); return NS_OK; }