From a660713d2bc97abf257f5836d89e69df54fce9c6 Mon Sep 17 00:00:00 2001 From: David Major Date: Tue, 14 Mar 2017 15:26:27 +1300 Subject: [PATCH] Bug 1344629 - Part 6: Rewrite unnecessary uses of nsLiteralString. r=dbaron There's an antipattern where nsLiteralString is used as an unnecessary intermediary in converting from CharT* to CharT*, e.g. CallAFunctionThatTakesACharPointer(NS_LITERAL_CSTRING("foo").get()); or NS_NAMED_LITERAL_STRING(foo, "abc"); CallAFunctionThatTakesACharPointer(foo.get()); This patch rewrites the callsites that can be trivially changed to use char*/char16_t*. I'd somewhat like to remove nsTLiteralString::get() altogether, but in code that's less straightforward than these examples, get() is useful enough to keep. MozReview-Commit-ID: Kh1rUziVllo --- .../components/shell/nsWindowsShellService.cpp | 6 +++--- dom/base/nsJSEnvironment.cpp | 18 ++++++++---------- dom/html/ImageDocument.cpp | 3 +-- dom/html/MediaDocument.cpp | 3 +-- dom/power/PowerManagerService.cpp | 12 ++++++------ dom/security/nsCSPParser.cpp | 2 +- dom/xhr/XMLHttpRequestMainThread.cpp | 7 +++---- layout/generic/nsPageFrame.cpp | 12 ++++++------ .../src/peerconnection/PeerConnectionCtx.cpp | 6 ++---- netwerk/base/nsIOService.cpp | 17 ++++++++--------- netwerk/protocol/ftp/nsFtpConnectionThread.cpp | 3 +-- security/manager/ssl/nsNSSComponent.cpp | 8 +++----- security/manager/ssl/nsNSSU2FToken.cpp | 4 ++-- storage/VacuumManager.cpp | 8 ++++---- toolkit/components/find/nsWebBrowserFind.cpp | 4 +--- toolkit/components/startup/nsAppStartup.cpp | 5 +---- toolkit/xre/nsEmbedFunctions.cpp | 2 +- toolkit/xre/nsNativeAppSupportWin.cpp | 4 ++-- toolkit/xre/nsXREDirProvider.cpp | 6 +++--- widget/android/nsAppShell.cpp | 3 +-- widget/windows/WindowsUIUtils.cpp | 4 +--- widget/windows/nsFilePicker.cpp | 4 +--- widget/windows/nsWindow.cpp | 16 ++++++++-------- xpcom/base/nsSystemInfo.cpp | 4 +--- xpcom/io/SpecialSystemDirectory.cpp | 6 +++--- xpcom/tests/gtest/TestObserverService.cpp | 12 ++++++------ xpcom/threads/nsThread.cpp | 11 ++++------- 27 files changed, 82 insertions(+), 108 deletions(-) diff --git a/browser/components/shell/nsWindowsShellService.cpp b/browser/components/shell/nsWindowsShellService.cpp index 56d25c8ea47c..2301ee43d2bc 100644 --- a/browser/components/shell/nsWindowsShellService.cpp +++ b/browser/components/shell/nsWindowsShellService.cpp @@ -166,14 +166,14 @@ nsWindowsShellService::ShortcutMaintenance() if (NS_FAILED(taskbarInfo->GetDefaultGroupId(appId))) return NS_ERROR_UNEXPECTED; - NS_NAMED_LITERAL_CSTRING(prefName, "browser.taskbar.lastgroupid"); + const char* prefName = "browser.taskbar.lastgroupid"; nsCOMPtr prefs = do_GetService(NS_PREFSERVICE_CONTRACTID); if (!prefs) return NS_ERROR_UNEXPECTED; nsCOMPtr prefString; - rv = prefs->GetComplexValue(prefName.get(), + rv = prefs->GetComplexValue(prefName, NS_GET_IID(nsISupportsString), getter_AddRefs(prefString)); if (NS_SUCCEEDED(rv)) { @@ -191,7 +191,7 @@ nsWindowsShellService::ShortcutMaintenance() return rv; prefString->SetData(appId); - rv = prefs->SetComplexValue(prefName.get(), + rv = prefs->SetComplexValue(prefName, NS_GET_IID(nsISupportsString), prefString); if (NS_FAILED(rv)) { diff --git a/dom/base/nsJSEnvironment.cpp b/dom/base/nsJSEnvironment.cpp index 2e9b75a27045..615e7d4fc84c 100644 --- a/dom/base/nsJSEnvironment.cpp +++ b/dom/base/nsJSEnvironment.cpp @@ -1632,11 +1632,11 @@ nsJSContext::EndCycleCollectionCallback(CycleCollectorResults &aResults) gcMsg.AssignLiteral(", forced a GC"); } - NS_NAMED_LITERAL_STRING(kFmt, + const char16_t *kFmt = u"CC(T+%.1f)[%s-%i] max pause: %lums, total time: %lums, slices: %lu, suspected: %lu, visited: %lu RCed and %lu%s GCed, collected: %lu RCed and %lu GCed (%lu|%lu|%lu waiting for GC)%s\n" - u"ForgetSkippable %lu times before CC, min: %lu ms, max: %lu ms, avg: %lu ms, total: %lu ms, max sync: %lu ms, removed: %lu"); + u"ForgetSkippable %lu times before CC, min: %lu ms, max: %lu ms, avg: %lu ms, total: %lu ms, max sync: %lu ms, removed: %lu"; nsString msg; - msg.Adopt(nsTextFormatter::smprintf(kFmt.get(), double(delta) / PR_USEC_PER_SEC, + msg.Adopt(nsTextFormatter::smprintf(kFmt, double(delta) / PR_USEC_PER_SEC, ProcessNameForCollectorLog(), getpid(), gCCStats.mMaxSliceTime, gCCStats.mTotalSliceTime, aResults.mNumSlices, gCCStats.mSuspected, @@ -1664,7 +1664,7 @@ nsJSContext::EndCycleCollectionCallback(CycleCollectorResults &aResults) } if (sPostGCEventsToObserver) { - NS_NAMED_LITERAL_STRING(kJSONFmt, + const char16_t* kJSONFmt = u"{ \"timestamp\": %llu, " u"\"duration\": %lu, " u"\"max_slice_pause\": %lu, " @@ -1689,10 +1689,10 @@ nsJSContext::EndCycleCollectionCallback(CycleCollectorResults &aResults) u"\"avg\": %lu, " u"\"total\": %lu, " u"\"removed\": %lu } " - u"}"); + u"}"; nsString json; - json.Adopt(nsTextFormatter::smprintf(kJSONFmt.get(), PR_Now(), ccNowDuration, + json.Adopt(nsTextFormatter::smprintf(kJSONFmt, PR_Now(), ccNowDuration, gCCStats.mMaxSliceTime, gCCStats.mTotalSliceTime, gCCStats.mMaxGCDuration, @@ -2139,10 +2139,9 @@ DOMGCSliceCallback(JSContext* aCx, JS::GCProgress aProgress, const JS::GCDescrip PRTime delta = GetCollectionTimeDelta(); if (sPostGCEventsToConsole) { - NS_NAMED_LITERAL_STRING(kFmt, "GC(T+%.1f)[%s-%i] "); nsString prefix, gcstats; gcstats.Adopt(aDesc.formatSummaryMessage(aCx)); - prefix.Adopt(nsTextFormatter::smprintf(kFmt.get(), + prefix.Adopt(nsTextFormatter::smprintf(u"GC(T+%.1f)[%s-%i] ", double(delta) / PR_USEC_PER_SEC, ProcessNameForCollectorLog(), getpid())); @@ -2223,10 +2222,9 @@ DOMGCSliceCallback(JSContext* aCx, JS::GCProgress aProgress, const JS::GCDescrip } if (sPostGCEventsToConsole) { - NS_NAMED_LITERAL_STRING(kFmt, "[%s-%i] "); nsString prefix, gcstats; gcstats.Adopt(aDesc.formatSliceMessage(aCx)); - prefix.Adopt(nsTextFormatter::smprintf(kFmt.get(), + prefix.Adopt(nsTextFormatter::smprintf(u"[%s-%i] ", ProcessNameForCollectorLog(), getpid())); nsString msg = prefix + gcstats; diff --git a/dom/html/ImageDocument.cpp b/dom/html/ImageDocument.cpp index 2216ca04a68d..4b7008e57583 100644 --- a/dom/html/ImageDocument.cpp +++ b/dom/html/ImageDocument.cpp @@ -585,8 +585,7 @@ ImageDocument::OnLoadComplete(imgIRequest* aRequest, nsresult aStatus) NS_ConvertUTF8toUTF16 srcString(src); const char16_t* formatString[] = { srcString.get() }; nsXPIDLString errorMsg; - NS_NAMED_LITERAL_STRING(str, "InvalidImage"); - mStringBundle->FormatStringFromName(str.get(), formatString, 1, + mStringBundle->FormatStringFromName(u"InvalidImage", formatString, 1, getter_Copies(errorMsg)); mImageContent->SetAttr(kNameSpaceID_None, nsGkAtoms::alt, errorMsg, false); diff --git a/dom/html/MediaDocument.cpp b/dom/html/MediaDocument.cpp index 9e4b68e4bb43..61739457eb87 100644 --- a/dom/html/MediaDocument.cpp +++ b/dom/html/MediaDocument.cpp @@ -418,8 +418,7 @@ MediaDocument::UpdateTitleAndCharset(const nsACString& aTypeStr, nsXPIDLString titleWithStatus; const nsPromiseFlatString& status = PromiseFlatString(aStatus); const char16_t *formatStrings[2] = {title.get(), status.get()}; - NS_NAMED_LITERAL_STRING(fmtName, "TitleWithStatus"); - mStringBundle->FormatStringFromName(fmtName.get(), formatStrings, 2, + mStringBundle->FormatStringFromName(u"TitleWithStatus", formatStrings, 2, getter_Copies(titleWithStatus)); SetTitle(titleWithStatus); } diff --git a/dom/power/PowerManagerService.cpp b/dom/power/PowerManagerService.cpp index 40110aa677b8..1dfacb3a7123 100644 --- a/dom/power/PowerManagerService.cpp +++ b/dom/power/PowerManagerService.cpp @@ -124,12 +124,12 @@ PowerManagerService::SyncProfile() { nsCOMPtr obsServ = services::GetObserverService(); if (obsServ) { - NS_NAMED_LITERAL_STRING(context, "shutdown-persist"); - obsServ->NotifyObservers(nullptr, "profile-change-net-teardown", context.get()); - obsServ->NotifyObservers(nullptr, "profile-change-teardown", context.get()); - obsServ->NotifyObservers(nullptr, "profile-before-change", context.get()); - obsServ->NotifyObservers(nullptr, "profile-before-change-qm", context.get()); - obsServ->NotifyObservers(nullptr, "profile-before-change-telemetry", context.get()); + const char16_t* context = u"shutdown-persist"; + obsServ->NotifyObservers(nullptr, "profile-change-net-teardown", context); + obsServ->NotifyObservers(nullptr, "profile-change-teardown", context); + obsServ->NotifyObservers(nullptr, "profile-before-change", context); + obsServ->NotifyObservers(nullptr, "profile-before-change-qm", context); + obsServ->NotifyObservers(nullptr, "profile-before-change-telemetry", context); } } diff --git a/dom/security/nsCSPParser.cpp b/dom/security/nsCSPParser.cpp index 613c775443d5..17d13a852a38 100644 --- a/dom/security/nsCSPParser.cpp +++ b/dom/security/nsCSPParser.cpp @@ -1116,7 +1116,7 @@ nsCSPParser::directiveName() // if we have a frame-src, cache it so we can decide whether to use child-src if (CSP_IsDirective(mCurToken, nsIContentSecurityPolicy::FRAME_SRC_DIRECTIVE)) { - const char16_t* params[] = { mCurToken.get(), NS_LITERAL_STRING("child-src").get() }; + const char16_t* params[] = { mCurToken.get(), u"child-src" }; logWarningErrorToConsole(nsIScriptError::warningFlag, "deprecatedDirective", params, ArrayLength(params)); mFrameSrc = new nsCSPDirective(CSP_StringToCSPDirective(mCurToken)); diff --git a/dom/xhr/XMLHttpRequestMainThread.cpp b/dom/xhr/XMLHttpRequestMainThread.cpp index 84a60c2f6d27..cfe075ef4a31 100644 --- a/dom/xhr/XMLHttpRequestMainThread.cpp +++ b/dom/xhr/XMLHttpRequestMainThread.cpp @@ -2588,11 +2588,10 @@ XMLHttpRequestMainThread::InitiateFetch(nsIInputStream* aUploadStream, nsCOMPtr consoleService = do_GetService(NS_CONSOLESERVICE_CONTRACTID); if (consoleService) { - consoleService->LogStringMessage(NS_LITERAL_STRING( - "Http channel implementation doesn't support nsIUploadChannel2. " + consoleService->LogStringMessage( + u"Http channel implementation doesn't support nsIUploadChannel2. " "An extension has supplied a non-functional http protocol handler. " - "This will break behavior and in future releases not work at all." - ).get()); + "This will break behavior and in future releases not work at all."); } } diff --git a/layout/generic/nsPageFrame.cpp b/layout/generic/nsPageFrame.cpp index c24b4d15ff5a..17d5c1b21128 100644 --- a/layout/generic/nsPageFrame.cpp +++ b/layout/generic/nsPageFrame.cpp @@ -193,7 +193,7 @@ nsPageFrame::ProcessSpecialCodes(const nsString& aStr, nsString& aNewStr) // then subst in the current date/time NS_NAMED_LITERAL_STRING(kDate, "&D"); if (aStr.Find(kDate) != kNotFound) { - aNewStr.ReplaceSubstring(kDate.get(), mPD->mDateTimeStr.get()); + aNewStr.ReplaceSubstring(kDate, mPD->mDateTimeStr); } // NOTE: Must search for &PT before searching for &P @@ -204,7 +204,7 @@ nsPageFrame::ProcessSpecialCodes(const nsString& aStr, nsString& aNewStr) NS_NAMED_LITERAL_STRING(kPageAndTotal, "&PT"); if (aStr.Find(kPageAndTotal) != kNotFound) { char16_t * uStr = nsTextFormatter::smprintf(mPD->mPageNumAndTotalsFormat.get(), mPageNum, mTotNumPages); - aNewStr.ReplaceSubstring(kPageAndTotal.get(), uStr); + aNewStr.ReplaceSubstring(kPageAndTotal, nsDependentString(uStr)); free(uStr); } @@ -213,24 +213,24 @@ nsPageFrame::ProcessSpecialCodes(const nsString& aStr, nsString& aNewStr) NS_NAMED_LITERAL_STRING(kPage, "&P"); if (aStr.Find(kPage) != kNotFound) { char16_t * uStr = nsTextFormatter::smprintf(mPD->mPageNumFormat.get(), mPageNum); - aNewStr.ReplaceSubstring(kPage.get(), uStr); + aNewStr.ReplaceSubstring(kPage, nsDependentString(uStr)); free(uStr); } NS_NAMED_LITERAL_STRING(kTitle, "&T"); if (aStr.Find(kTitle) != kNotFound) { - aNewStr.ReplaceSubstring(kTitle.get(), mPD->mDocTitle.get()); + aNewStr.ReplaceSubstring(kTitle, mPD->mDocTitle); } NS_NAMED_LITERAL_STRING(kDocURL, "&U"); if (aStr.Find(kDocURL) != kNotFound) { - aNewStr.ReplaceSubstring(kDocURL.get(), mPD->mDocURL.get()); + aNewStr.ReplaceSubstring(kDocURL, mPD->mDocURL); } NS_NAMED_LITERAL_STRING(kPageTotal, "&L"); if (aStr.Find(kPageTotal) != kNotFound) { char16_t * uStr = nsTextFormatter::smprintf(mPD->mPageNumFormat.get(), mTotNumPages); - aNewStr.ReplaceSubstring(kPageTotal.get(), uStr); + aNewStr.ReplaceSubstring(kPageTotal, nsDependentString(uStr)); free(uStr); } } diff --git a/media/webrtc/signaling/src/peerconnection/PeerConnectionCtx.cpp b/media/webrtc/signaling/src/peerconnection/PeerConnectionCtx.cpp index 1fa612db3d5f..f17788020c96 100644 --- a/media/webrtc/signaling/src/peerconnection/PeerConnectionCtx.cpp +++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionCtx.cpp @@ -85,12 +85,10 @@ public: PeerConnectionCtx::gPeerConnectionCtxObserver = nullptr; } if (strcmp(aTopic, NS_IOSERVICE_OFFLINE_STATUS_TOPIC) == 0) { - const nsLiteralString onlineString(u"" NS_IOSERVICE_ONLINE); - const nsLiteralString offlineString(u"" NS_IOSERVICE_OFFLINE); - if (NS_strcmp(aData, offlineString.get()) == 0) { + if (NS_strcmp(aData, u"" NS_IOSERVICE_OFFLINE) == 0) { CSFLogDebug(logTag, "Updating network state to offline"); PeerConnectionCtx::UpdateNetworkState(false); - } else if(NS_strcmp(aData, onlineString.get()) == 0) { + } else if(NS_strcmp(aData, u"" NS_IOSERVICE_ONLINE) == 0) { CSFLogDebug(logTag, "Updating network state to online"); PeerConnectionCtx::UpdateNetworkState(true); } else { diff --git a/netwerk/base/nsIOService.cpp b/netwerk/base/nsIOService.cpp index 78bcd231d844..3a244c51bdea 100644 --- a/netwerk/base/nsIOService.cpp +++ b/netwerk/base/nsIOService.cpp @@ -834,9 +834,10 @@ nsIOService::NewChannelFromURIWithProxyFlagsInternal(nsIURI* aURI, nsCOMPtr consoleService = do_GetService(NS_CONSOLESERVICE_CONTRACTID); if (consoleService) { - consoleService->LogStringMessage(NS_LITERAL_STRING( - "Http channel implementation doesn't support nsIUploadChannel2. An extension has supplied a non-functional http protocol handler. This will break behavior and in future releases not work at all." - ).get()); + consoleService->LogStringMessage(u"Http channel implementation " + "doesn't support nsIUploadChannel2. An extension has " + "supplied a non-functional http protocol handler. This will " + "break behavior and in future releases not work at all."); } gHasWarnedUploadChannel2 = true; } @@ -1062,14 +1063,13 @@ nsIOService::SetOffline(bool offline) offline = mSetOfflineValue; if (offline && !mOffline) { - NS_NAMED_LITERAL_STRING(offlineString, NS_IOSERVICE_OFFLINE); mOffline = true; // indicate we're trying to shutdown // don't care if notifications fail if (observerService) observerService->NotifyObservers(subject, NS_IOSERVICE_GOING_OFFLINE_TOPIC, - offlineString.get()); + u"" NS_IOSERVICE_OFFLINE); if (mSocketTransportService) mSocketTransportService->SetOffline(true); @@ -1078,7 +1078,7 @@ nsIOService::SetOffline(bool offline) if (observerService) observerService->NotifyObservers(subject, NS_IOSERVICE_OFFLINE_STATUS_TOPIC, - offlineString.get()); + u"" NS_IOSERVICE_OFFLINE); } else if (!offline && mOffline) { // go online @@ -1193,13 +1193,12 @@ nsIOService::SetConnectivityInternal(bool aConnectivity) } else { // If we were previously online and lost connectivity // send the OFFLINE notification - const nsLiteralString offlineString(u"" NS_IOSERVICE_OFFLINE); observerService->NotifyObservers(static_cast(this), NS_IOSERVICE_GOING_OFFLINE_TOPIC, - offlineString.get()); + u"" NS_IOSERVICE_OFFLINE); observerService->NotifyObservers(static_cast(this), NS_IOSERVICE_OFFLINE_STATUS_TOPIC, - offlineString.get()); + u"" NS_IOSERVICE_OFFLINE); } return NS_OK; } diff --git a/netwerk/protocol/ftp/nsFtpConnectionThread.cpp b/netwerk/protocol/ftp/nsFtpConnectionThread.cpp index 8917451e2817..61c9d7fc1b1f 100644 --- a/netwerk/protocol/ftp/nsFtpConnectionThread.cpp +++ b/netwerk/protocol/ftp/nsFtpConnectionThread.cpp @@ -946,10 +946,9 @@ nsFtpState::R_syst() { char16_t* ucs2Response = ToNewUnicode(mResponseMsg); const char16_t *formatStrings[1] = { ucs2Response }; - NS_NAMED_LITERAL_STRING(name, "UnsupportedFTPServer"); nsXPIDLString formattedString; - rv = bundle->FormatStringFromName(name.get(), formatStrings, 1, + rv = bundle->FormatStringFromName(u"UnsupportedFTPServer", formatStrings, 1, getter_Copies(formattedString)); free(ucs2Response); if (NS_FAILED(rv)) diff --git a/security/manager/ssl/nsNSSComponent.cpp b/security/manager/ssl/nsNSSComponent.cpp index cd4cf4205e20..5fbbfceaa1f1 100644 --- a/security/manager/ssl/nsNSSComponent.cpp +++ b/security/manager/ssl/nsNSSComponent.cpp @@ -1848,12 +1848,10 @@ nsNSSComponent::Init() // - wrong thread: 'NS_IsMainThread()' in nsIOService.cpp // when loading error strings on the SSL threads. { - NS_NAMED_LITERAL_STRING(dummy_name, "dummy"); + const char16_t* dummy = u"dummy"; nsXPIDLString result; - mPIPNSSBundle->GetStringFromName(dummy_name.get(), - getter_Copies(result)); - mNSSErrorsBundle->GetStringFromName(dummy_name.get(), - getter_Copies(result)); + mPIPNSSBundle->GetStringFromName(dummy, getter_Copies(result)); + mNSSErrorsBundle->GetStringFromName(dummy, getter_Copies(result)); } diff --git a/security/manager/ssl/nsNSSU2FToken.cpp b/security/manager/ssl/nsNSSU2FToken.cpp index da3017157cd5..d48242f53d39 100644 --- a/security/manager/ssl/nsNSSU2FToken.cpp +++ b/security/manager/ssl/nsNSSU2FToken.cpp @@ -29,7 +29,7 @@ const nsCString nsNSSU2FToken::mSecretNickname = NS_LITERAL_CSTRING("U2F_NSSTOKEN"); const nsString nsNSSU2FToken::mVersion = NS_LITERAL_STRING("U2F_V2"); -NS_NAMED_LITERAL_CSTRING(kAttestCertSubjectName, "CN=Firefox U2F Soft Token"); +const char* kAttestCertSubjectName = "CN=Firefox U2F Soft Token"; // This U2F-compatible soft token uses FIDO U2F-compatible ECDSA keypairs // on the SEC_OID_SECG_EC_SECP256R1 curve. When asked to Register, it will @@ -256,7 +256,7 @@ GetAttestationCertificate(const UniquePK11SlotInfo& aSlot, } // Construct the Attestation Certificate itself - UniqueCERTName subjectName(CERT_AsciiToName(kAttestCertSubjectName.get())); + UniqueCERTName subjectName(CERT_AsciiToName(kAttestCertSubjectName)); if (!subjectName) { MOZ_LOG(gNSSTokenLog, LogLevel::Warning, ("Failed to set subject name, NSS error #%d", PORT_GetError())); diff --git a/storage/VacuumManager.cpp b/storage/VacuumManager.cpp index f35ded2d6e0f..77d94e96b470 100644 --- a/storage/VacuumManager.cpp +++ b/storage/VacuumManager.cpp @@ -29,8 +29,8 @@ // Used to notify begin and end of a heavy IO task. #define OBSERVER_TOPIC_HEAVY_IO "heavy-io-task" -#define OBSERVER_DATA_VACUUM_BEGIN NS_LITERAL_STRING("vacuum-begin") -#define OBSERVER_DATA_VACUUM_END NS_LITERAL_STRING("vacuum-end") +#define OBSERVER_DATA_VACUUM_BEGIN u"vacuum-begin" +#define OBSERVER_DATA_VACUUM_END u"vacuum-end" // This preferences root will contain last vacuum timestamps (in seconds) for // each database. The database filename is used as a key. @@ -191,7 +191,7 @@ Vacuumer::execute() if (os) { rv = os->NotifyObservers(nullptr, OBSERVER_TOPIC_HEAVY_IO, - OBSERVER_DATA_VACUUM_BEGIN.get()); + OBSERVER_DATA_VACUUM_BEGIN); MOZ_ASSERT(NS_SUCCEEDED(rv), "Should be able to notify"); } @@ -289,7 +289,7 @@ Vacuumer::notifyCompletion(bool aSucceeded) nsCOMPtr os = mozilla::services::GetObserverService(); if (os) { os->NotifyObservers(nullptr, OBSERVER_TOPIC_HEAVY_IO, - OBSERVER_DATA_VACUUM_END.get()); + OBSERVER_DATA_VACUUM_END); } nsresult rv = mParticipant->OnEndVacuum(aSucceeded); diff --git a/toolkit/components/find/nsWebBrowserFind.cpp b/toolkit/components/find/nsWebBrowserFind.cpp index 380066c5ea6c..a8e27a9bbc02 100644 --- a/toolkit/components/find/nsWebBrowserFind.cpp +++ b/toolkit/components/find/nsWebBrowserFind.cpp @@ -92,11 +92,9 @@ nsWebBrowserFind::FindNext(bool* aResult) NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr searchWindowSupports = do_QueryInterface(rootFrame); windowSupportsData->SetData(searchWindowSupports); - NS_NAMED_LITERAL_STRING(dnStr, "down"); - NS_NAMED_LITERAL_STRING(upStr, "up"); observerSvc->NotifyObservers(windowSupportsData, "nsWebBrowserFind_FindAgain", - mFindBackwards ? upStr.get() : dnStr.get()); + mFindBackwards ? u"up" : u"down"); windowSupportsData->GetData(getter_AddRefs(searchWindowSupports)); // findnext performed if search window data cleared out *aResult = searchWindowSupports == nullptr; diff --git a/toolkit/components/startup/nsAppStartup.cpp b/toolkit/components/startup/nsAppStartup.cpp index 4f9c0cd92945..706d11912bb2 100644 --- a/toolkit/components/startup/nsAppStartup.cpp +++ b/toolkit/components/startup/nsAppStartup.cpp @@ -458,11 +458,8 @@ nsAppStartup::Quit(uint32_t aMode) // No chance of the shutdown being cancelled from here on; tell people // we're shutting down for sure while all services are still available. if (obsService) { - NS_NAMED_LITERAL_STRING(shutdownStr, "shutdown"); - NS_NAMED_LITERAL_STRING(restartStr, "restart"); obsService->NotifyObservers(nullptr, "quit-application", - (mRestart || mRestartNotSameProfile) ? - restartStr.get() : shutdownStr.get()); + (mRestart || mRestartNotSameProfile) ? u"restart" : u"shutdown"); } if (!mRunning) { diff --git a/toolkit/xre/nsEmbedFunctions.cpp b/toolkit/xre/nsEmbedFunctions.cpp index 79c5b76c88d6..c4fc4819e4c6 100644 --- a/toolkit/xre/nsEmbedFunctions.cpp +++ b/toolkit/xre/nsEmbedFunctions.cpp @@ -583,7 +583,7 @@ XRE_InitChildProcess(int aArgc, nsString appId; appId.AssignWithConversion(nsDependentCString(appModelUserId)); // The version string is encased in quotes - appId.Trim(NS_LITERAL_CSTRING("\"").get()); + appId.Trim("\""); // Set the id SetTaskbarGroupId(appId); } diff --git a/toolkit/xre/nsNativeAppSupportWin.cpp b/toolkit/xre/nsNativeAppSupportWin.cpp index f0ba3f4dc332..8234b83e3aad 100644 --- a/toolkit/xre/nsNativeAppSupportWin.cpp +++ b/toolkit/xre/nsNativeAppSupportWin.cpp @@ -953,7 +953,7 @@ nsNativeAppSupportWin::HandleDDENotification( UINT uType, // transaction t do { // Get most recently used Nav window. nsCOMPtr navWin; - GetMostRecentWindow( NS_LITERAL_STRING( "navigator:browser" ).get(), + GetMostRecentWindow( u"navigator:browser", getter_AddRefs( navWin ) ); nsCOMPtr piNavWin = do_QueryInterface(navWin); if ( !piNavWin ) { @@ -1430,7 +1430,7 @@ nsNativeAppSupportWin::OpenBrowserWindow() // browser window. nsCOMPtr navWin; - GetMostRecentWindow( NS_LITERAL_STRING( "navigator:browser" ).get(), getter_AddRefs( navWin ) ); + GetMostRecentWindow( u"navigator:browser", getter_AddRefs( navWin ) ); // This isn't really a loop. We just use "break" statements to fall // out to the OpenWindow call when things go awry. diff --git a/toolkit/xre/nsXREDirProvider.cpp b/toolkit/xre/nsXREDirProvider.cpp index 7c0bbe7f8ae0..2c9a41b0feb6 100644 --- a/toolkit/xre/nsXREDirProvider.cpp +++ b/toolkit/xre/nsXREDirProvider.cpp @@ -1288,9 +1288,9 @@ static nsresult GetRegWindowsAppDataFolder(bool aLocal, nsAString& _retval) { HKEY key; - NS_NAMED_LITERAL_STRING(keyName, - "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders"); - DWORD res = ::RegOpenKeyExW(HKEY_CURRENT_USER, keyName.get(), 0, KEY_READ, + LPCWSTR keyName = + L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders"; + DWORD res = ::RegOpenKeyExW(HKEY_CURRENT_USER, keyName, 0, KEY_READ, &key); if (res != ERROR_SUCCESS) { _retval.SetLength(0); diff --git a/widget/android/nsAppShell.cpp b/widget/android/nsAppShell.cpp index 388f0321b47f..75ef581160e5 100644 --- a/widget/android/nsAppShell.cpp +++ b/widget/android/nsAppShell.cpp @@ -167,8 +167,7 @@ public: mozilla::services::GetObserverService(); obsServ->NotifyObservers(nullptr, "application-background", nullptr); - NS_NAMED_LITERAL_STRING(minimize, "heap-minimize"); - obsServ->NotifyObservers(nullptr, "memory-pressure", minimize.get()); + obsServ->NotifyObservers(nullptr, "memory-pressure", u"heap-minimize"); // If we are OOM killed with the disk cache enabled, the entire // cache will be cleared (bug 105843), so shut down the cache here diff --git a/widget/windows/WindowsUIUtils.cpp b/widget/windows/WindowsUIUtils.cpp index 1c270b5ec599..4d916d25cf1e 100644 --- a/widget/windows/WindowsUIUtils.cpp +++ b/widget/windows/WindowsUIUtils.cpp @@ -168,10 +168,8 @@ WindowsUIUtils::UpdateTabletModeState() if (mInTabletMode != oldTabletModeState) { nsCOMPtr observerService = mozilla::services::GetObserverService(); - NS_NAMED_LITERAL_STRING(tabletMode, "tablet-mode"); - NS_NAMED_LITERAL_STRING(normalMode, "normal-mode"); observerService->NotifyObservers(nullptr, "tablet-mode-change", - ((mInTabletMode == eTabletModeOn) ? tabletMode.get() : normalMode.get())); + ((mInTabletMode == eTabletModeOn) ? u"tablet-mode" : u"normal-mode")); } } } diff --git a/widget/windows/nsFilePicker.cpp b/widget/windows/nsFilePicker.cpp index a634acddef99..8d5a6b43ac4c 100644 --- a/widget/windows/nsFilePicker.cpp +++ b/widget/windows/nsFilePicker.cpp @@ -499,13 +499,11 @@ nsFilePicker::ShowFilePicker(const nsString& aInitialDir) dialog->SetFileName(mDefaultFilename.get()); } - NS_NAMED_LITERAL_STRING(htmExt, "html"); - // default extension to append to new files if (!mDefaultExtension.IsEmpty()) { dialog->SetDefaultExtension(mDefaultExtension.get()); } else if (IsDefaultPathHtml()) { - dialog->SetDefaultExtension(htmExt.get()); + dialog->SetDefaultExtension(L"html"); } // initial location diff --git a/widget/windows/nsWindow.cpp b/widget/windows/nsWindow.cpp index e14d0f6845f8..4e6f5df0adc9 100644 --- a/widget/windows/nsWindow.cpp +++ b/widget/windows/nsWindow.cpp @@ -5057,16 +5057,16 @@ nsWindow::ProcessMessage(UINT msg, WPARAM& wParam, LPARAM& lParam, // Windows won't let us do that. Bug 212316. nsCOMPtr obsServ = mozilla::services::GetObserverService(); - NS_NAMED_LITERAL_STRING(context, "shutdown-persist"); - NS_NAMED_LITERAL_STRING(syncShutdown, "syncShutdown"); - obsServ->NotifyObservers(nullptr, "quit-application-granted", syncShutdown.get()); + const char16_t* context = u"shutdown-persist"; + const char16_t* syncShutdown = u"syncShutdown"; + obsServ->NotifyObservers(nullptr, "quit-application-granted", syncShutdown); obsServ->NotifyObservers(nullptr, "quit-application-forced", nullptr); obsServ->NotifyObservers(nullptr, "quit-application", nullptr); - obsServ->NotifyObservers(nullptr, "profile-change-net-teardown", context.get()); - obsServ->NotifyObservers(nullptr, "profile-change-teardown", context.get()); - obsServ->NotifyObservers(nullptr, "profile-before-change", context.get()); - obsServ->NotifyObservers(nullptr, "profile-before-change-qm", context.get()); - obsServ->NotifyObservers(nullptr, "profile-before-change-telemetry", context.get()); + obsServ->NotifyObservers(nullptr, "profile-change-net-teardown", context); + obsServ->NotifyObservers(nullptr, "profile-change-teardown", context); + obsServ->NotifyObservers(nullptr, "profile-before-change", context); + obsServ->NotifyObservers(nullptr, "profile-before-change-qm", context); + obsServ->NotifyObservers(nullptr, "profile-before-change-telemetry", context); // Then a controlled but very quick exit. _exit(0); } diff --git a/xpcom/base/nsSystemInfo.cpp b/xpcom/base/nsSystemInfo.cpp index f420becabd5c..843ed11aea9a 100644 --- a/xpcom/base/nsSystemInfo.cpp +++ b/xpcom/base/nsSystemInfo.cpp @@ -183,9 +183,7 @@ nsresult GetInstallYear(uint32_t& aYear) { HKEY hKey; LONG status = RegOpenKeyExW(HKEY_LOCAL_MACHINE, - NS_LITERAL_STRING( - "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion" - ).get(), + L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", 0, KEY_READ | KEY_WOW64_64KEY, &hKey); if (status != ERROR_SUCCESS) { diff --git a/xpcom/io/SpecialSystemDirectory.cpp b/xpcom/io/SpecialSystemDirectory.cpp index 196a9e533107..1b77f76061f1 100644 --- a/xpcom/io/SpecialSystemDirectory.cpp +++ b/xpcom/io/SpecialSystemDirectory.cpp @@ -151,9 +151,9 @@ static nsresult GetRegWindowsAppDataFolder(bool aLocal, nsIFile** aFile) { HKEY key; - NS_NAMED_LITERAL_STRING(keyName, - "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders"); - DWORD res = ::RegOpenKeyExW(HKEY_CURRENT_USER, keyName.get(), 0, KEY_READ, + LPCWSTR keyName = + L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders"; + DWORD res = ::RegOpenKeyExW(HKEY_CURRENT_USER, keyName, 0, KEY_READ, &key); if (res != ERROR_SUCCESS) { return NS_ERROR_FAILURE; diff --git a/xpcom/tests/gtest/TestObserverService.cpp b/xpcom/tests/gtest/TestObserverService.cpp index d4eb51a7e1da..a2f5df016c73 100644 --- a/xpcom/tests/gtest/TestObserverService.cpp +++ b/xpcom/tests/gtest/TestObserverService.cpp @@ -252,19 +252,19 @@ TEST(ObserverService, TestNotify) testResult(svc->AddObserver(bObserver, topicB.get(), false)); // Notify topicA. - NS_NAMED_LITERAL_STRING(dataA, "Testing Notify(observer-A, topic-A)"); + const char16_t* dataA = u"Testing Notify(observer-A, topic-A)"; aObserver->mExpectedData = dataA; bObserver->mExpectedData = dataA; nsresult rv = - svc->NotifyObservers(ToSupports(aObserver), topicA.get(), dataA.get()); + svc->NotifyObservers(ToSupports(aObserver), topicA.get(), dataA); testResult(rv); ASSERT_EQ(aObserver->mObservations, 1); ASSERT_EQ(bObserver->mObservations, 1); // Notify topicB. - NS_NAMED_LITERAL_STRING(dataB, "Testing Notify(observer-B, topic-B)"); + const char16_t* dataB = u"Testing Notify(observer-B, topic-B)"; bObserver->mExpectedData = dataB; - rv = svc->NotifyObservers(ToSupports(bObserver), topicB.get(), dataB.get()); + rv = svc->NotifyObservers(ToSupports(bObserver), topicB.get(), dataB); testResult(rv); ASSERT_EQ(aObserver->mObservations, 1); ASSERT_EQ(bObserver->mObservations, 2); @@ -274,14 +274,14 @@ TEST(ObserverService, TestNotify) // Notify topicA, only bObserver is expected to be notified. bObserver->mExpectedData = dataA; - rv = svc->NotifyObservers(ToSupports(aObserver), topicA.get(), dataA.get()); + rv = svc->NotifyObservers(ToSupports(aObserver), topicA.get(), dataA); testResult(rv); ASSERT_EQ(aObserver->mObservations, 1); ASSERT_EQ(bObserver->mObservations, 3); // Remove the other topicA observer, make sure none are notified. testResult(svc->RemoveObserver(bObserver, topicA.get())); - rv = svc->NotifyObservers(ToSupports(aObserver), topicA.get(), dataA.get()); + rv = svc->NotifyObservers(ToSupports(aObserver), topicA.get(), dataA); testResult(rv); ASSERT_EQ(aObserver->mObservations, 1); ASSERT_EQ(bObserver->mObservations, 3); diff --git a/xpcom/threads/nsThread.cpp b/xpcom/threads/nsThread.cpp index f194223523bb..214befd2efcf 100644 --- a/xpcom/threads/nsThread.cpp +++ b/xpcom/threads/nsThread.cpp @@ -1493,15 +1493,12 @@ nsThread::DoMainThreadSpecificProcessing(bool aReallyWait) if (mpPending != MemPressure_None) { nsCOMPtr os = services::GetObserverService(); - // Use no-forward to prevent the notifications from being transferred to - // the children of this process. - NS_NAMED_LITERAL_STRING(lowMem, "low-memory-no-forward"); - NS_NAMED_LITERAL_STRING(lowMemOngoing, "low-memory-ongoing-no-forward"); - if (os) { + // Use no-forward to prevent the notifications from being transferred to + // the children of this process. os->NotifyObservers(nullptr, "memory-pressure", - mpPending == MemPressure_New ? lowMem.get() : - lowMemOngoing.get()); + mpPending == MemPressure_New ? u"low-memory-no-forward" : + u"low-memory-ongoing-no-forward"); } else { NS_WARNING("Can't get observer service!"); }