From 77b61805556627f73a4166c8ba3e3fe34e501e64 Mon Sep 17 00:00:00 2001 From: Job Bautista Date: Sun, 12 Mar 2023 20:15:45 +0800 Subject: [PATCH 1/5] Issue #2046 - Follow-up: Fix deprot in RelativeTimeFormat. Found while building js/src deunified, with the exception of builtin/intl. Tag #80. --- js/src/builtin/intl/RelativeTimeFormat.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/js/src/builtin/intl/RelativeTimeFormat.cpp b/js/src/builtin/intl/RelativeTimeFormat.cpp index f811ff05e7..a6163829ff 100644 --- a/js/src/builtin/intl/RelativeTimeFormat.cpp +++ b/js/src/builtin/intl/RelativeTimeFormat.cpp @@ -29,6 +29,7 @@ using mozilla::RangedPtr; using js::intl::CallICU; using js::intl::GetAvailableLocales; using js::intl::IcuLocale; +using js::intl::INITIAL_CHAR_BUFFER_SIZE; using js::intl::StringsAreEqual; /**************** RelativeTimeFormat *****************/ From 261dc37ad8ac328f25180e8c6887b65ae98f49fd Mon Sep 17 00:00:00 2001 From: Job Bautista Date: Sun, 12 Mar 2023 20:17:08 +0800 Subject: [PATCH 2/5] Issue #80 - Fix deprot in js/ipc. I think we never deunified js/ipc before. But if we're going to build this tree deunified ever in the future, there's nothing stopping us now! --- js/ipc/JavaScriptShared.cpp | 3 +++ js/ipc/WrapperOwner.cpp | 2 ++ 2 files changed, 5 insertions(+) diff --git a/js/ipc/JavaScriptShared.cpp b/js/ipc/JavaScriptShared.cpp index 6dfb00bc5e..60ea1b8d12 100644 --- a/js/ipc/JavaScriptShared.cpp +++ b/js/ipc/JavaScriptShared.cpp @@ -5,6 +5,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "JavaScriptShared.h" +#include "JavaScriptChild.h" +#include "JavaScriptParent.h" #include "mozilla/dom/BindingUtils.h" #include "mozilla/dom/CPOWManagerGetter.h" #include "mozilla/dom/TabChild.h" @@ -16,6 +18,7 @@ using namespace js; using namespace JS; using namespace mozilla; +using namespace mozilla::dom; using namespace mozilla::jsipc; IdToObjectMap::IdToObjectMap() diff --git a/js/ipc/WrapperOwner.cpp b/js/ipc/WrapperOwner.cpp index 92c6e409be..2c16269adc 100644 --- a/js/ipc/WrapperOwner.cpp +++ b/js/ipc/WrapperOwner.cpp @@ -8,6 +8,7 @@ #include "JavaScriptLogging.h" #include "mozilla/Unused.h" #include "mozilla/dom/BindingUtils.h" +#include "GeckoProfiler.h" #include "jsfriendapi.h" #include "js/CharacterEncoding.h" #include "xpcprivate.h" @@ -20,6 +21,7 @@ using namespace js; using namespace JS; using namespace mozilla; +using namespace mozilla::dom; using namespace mozilla::jsipc; struct AuxCPOWData From 0b039ff7a6b5912ee9cce7e9f63ff5beecb23995 Mon Sep 17 00:00:00 2001 From: Job Bautista Date: Sun, 12 Mar 2023 20:19:37 +0800 Subject: [PATCH 3/5] Issue #80 - Fix deprot in js/xpconnect. I think we never deunified js/xpconnect before. But if we're going to ever build this tree deunified in the future, there's nothing stopping us now! --- js/xpconnect/public/xpc_map_end.h | 1 + js/xpconnect/src/Sandbox.cpp | 4 ++++ js/xpconnect/src/XPCJSContext.cpp | 3 +++ js/xpconnect/src/XPCJSID.cpp | 1 + js/xpconnect/src/XPCLocale.cpp | 2 ++ js/xpconnect/src/XPCWrappedNativeInfo.cpp | 2 ++ js/xpconnect/src/XPCWrappedNativeJSOps.cpp | 1 + js/xpconnect/src/XPCWrappedNativeScope.cpp | 1 + 8 files changed, 15 insertions(+) diff --git a/js/xpconnect/public/xpc_map_end.h b/js/xpconnect/public/xpc_map_end.h index 4e34267d7f..3186da8787 100644 --- a/js/xpconnect/public/xpc_map_end.h +++ b/js/xpconnect/public/xpc_map_end.h @@ -15,6 +15,7 @@ #endif #include "js/Id.h" +#include "xpc_make_class.h" /**************************************************************/ diff --git a/js/xpconnect/src/Sandbox.cpp b/js/xpconnect/src/Sandbox.cpp index e4e3de907f..b8a4859a46 100644 --- a/js/xpconnect/src/Sandbox.cpp +++ b/js/xpconnect/src/Sandbox.cpp @@ -54,8 +54,12 @@ using namespace mozilla; using namespace JS; using namespace xpc; +using mozilla::dom::ConvertExceptionToPromise; using mozilla::dom::DestroyProtoAndIfaceCache; using mozilla::dom::IndexedDatabaseManager; +using mozilla::dom::RequestOrUSVString; +using mozilla::dom::RequestOrUSVStringArgument; +using mozilla::dom::RootedDictionary; NS_IMPL_CYCLE_COLLECTION_CLASS(SandboxPrivate) diff --git a/js/xpconnect/src/XPCJSContext.cpp b/js/xpconnect/src/XPCJSContext.cpp index 7eca9846c8..e76cd9f9fe 100644 --- a/js/xpconnect/src/XPCJSContext.cpp +++ b/js/xpconnect/src/XPCJSContext.cpp @@ -22,6 +22,7 @@ #include "nsIObserverService.h" #include "nsIDebug2.h" #include "nsIDocShell.h" +#include "nsIInputStream.h" #include "nsIRunnable.h" #include "amIAddonManager.h" #include "nsPIDOMWindow.h" @@ -40,6 +41,7 @@ #include "mozilla/dom/GeneratedAtomList.h" #include "mozilla/dom/BindingUtils.h" #include "mozilla/dom/Element.h" +#include "mozilla/dom/Promise.h" #include "mozilla/dom/ScriptLoader.h" #include "mozilla/dom/WindowBinding.h" #include "mozilla/jsipc/CrossProcessObjectWrappers.h" @@ -71,6 +73,7 @@ #endif using namespace mozilla; +using namespace mozilla::dom; using namespace xpc; using namespace JS; using mozilla::dom::PerThreadAtomCache; diff --git a/js/xpconnect/src/XPCJSID.cpp b/js/xpconnect/src/XPCJSID.cpp index 2bf3939bf1..14525f115b 100644 --- a/js/xpconnect/src/XPCJSID.cpp +++ b/js/xpconnect/src/XPCJSID.cpp @@ -11,6 +11,7 @@ #include "mozilla/Attributes.h" #include "mozilla/jsipc/CrossProcessObjectWrappers.h" #include "mozilla/StaticPtr.h" +#include "nsContentUtils.h" using namespace mozilla::dom; using namespace JS; diff --git a/js/xpconnect/src/XPCLocale.cpp b/js/xpconnect/src/XPCLocale.cpp index 9a55c0ec82..8920dbd922 100644 --- a/js/xpconnect/src/XPCLocale.cpp +++ b/js/xpconnect/src/XPCLocale.cpp @@ -4,6 +4,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "mozilla/Assertions.h" +#include "mozilla/Preferences.h" #include "jsapi.h" @@ -23,6 +24,7 @@ using namespace JS; using mozilla::dom::EncodingUtils; +using mozilla::Preferences; /** * JS locale callbacks implemented by XPCOM modules. These are theoretically diff --git a/js/xpconnect/src/XPCWrappedNativeInfo.cpp b/js/xpconnect/src/XPCWrappedNativeInfo.cpp index a93b006f0f..13cffa5161 100644 --- a/js/xpconnect/src/XPCWrappedNativeInfo.cpp +++ b/js/xpconnect/src/XPCWrappedNativeInfo.cpp @@ -10,7 +10,9 @@ #include "mozilla/MemoryReporting.h" #include "mozilla/XPTInterfaceInfoManager.h" +#include "nsAppRunner.h" #include "nsIScriptError.h" +#include "nsJSUtils.h" #include "nsPrintfCString.h" using namespace JS; diff --git a/js/xpconnect/src/XPCWrappedNativeJSOps.cpp b/js/xpconnect/src/XPCWrappedNativeJSOps.cpp index 6c343e1e8f..ece0cf5076 100644 --- a/js/xpconnect/src/XPCWrappedNativeJSOps.cpp +++ b/js/xpconnect/src/XPCWrappedNativeJSOps.cpp @@ -10,6 +10,7 @@ #include "jsprf.h" #include "mozilla/dom/BindingUtils.h" #include "mozilla/Preferences.h" +#include "nsContentUtils.h" #include "nsIAddonInterposition.h" #include "AddonWrapper.h" #include "js/Class.h" diff --git a/js/xpconnect/src/XPCWrappedNativeScope.cpp b/js/xpconnect/src/XPCWrappedNativeScope.cpp index fdf27a5d62..40fb4201f7 100644 --- a/js/xpconnect/src/XPCWrappedNativeScope.cpp +++ b/js/xpconnect/src/XPCWrappedNativeScope.cpp @@ -7,6 +7,7 @@ #include "xpcprivate.h" #include "XPCWrapper.h" +#include "AccessCheck.h" #include "nsContentUtils.h" #include "nsCycleCollectionNoteRootCallback.h" #include "nsPrincipal.h" From c2c95eff9764b6c179a772bcc14d7c4d056186c2 Mon Sep 17 00:00:00 2001 From: Job Bautista Date: Sun, 12 Mar 2023 22:04:36 +0800 Subject: [PATCH 4/5] Issue #80 - Move implementation of CPOWTimer::CPOWTimer to header. Fixes link bustage in xul.dll Inline functions must be implemented in the header. --- js/ipc/CPOWTimer.cpp | 10 ---------- js/ipc/CPOWTimer.h | 11 ++++++++++- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/js/ipc/CPOWTimer.cpp b/js/ipc/CPOWTimer.cpp index ad39c3d32e..e84f04e79f 100644 --- a/js/ipc/CPOWTimer.cpp +++ b/js/ipc/CPOWTimer.cpp @@ -10,16 +10,6 @@ #include "jsapi.h" -CPOWTimer::CPOWTimer(JSContext* cx MOZ_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL) - : cx_(nullptr) - , startInterval_(0) -{ - MOZ_GUARD_OBJECT_NOTIFIER_INIT; - if (!js::GetStopwatchIsMonitoringCPOW(cx)) - return; - cx_ = cx; - startInterval_ = JS_Now(); -} CPOWTimer::~CPOWTimer() { if (!cx_) { diff --git a/js/ipc/CPOWTimer.h b/js/ipc/CPOWTimer.h index 173f87b107..2755ee14ad 100644 --- a/js/ipc/CPOWTimer.h +++ b/js/ipc/CPOWTimer.h @@ -21,7 +21,16 @@ */ class MOZ_RAII CPOWTimer final { public: - explicit inline CPOWTimer(JSContext* cx MOZ_GUARD_OBJECT_NOTIFIER_PARAM); + explicit inline + CPOWTimer(JSContext* cx MOZ_GUARD_OBJECT_NOTIFIER_PARAM) : cx_(nullptr) + , startInterval_(0) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + if (!js::GetStopwatchIsMonitoringCPOW(cx)) + return; + cx_ = cx; + startInterval_ = JS_Now(); + } ~CPOWTimer(); private: From 091a2aab80c992753981b9ce48dc5ea0ba71a792 Mon Sep 17 00:00:00 2001 From: FranklinDM Date: Wed, 4 May 2022 14:55:57 +0800 Subject: [PATCH 5/5] No issue - Make content-type on JAR channels behave the same as HTTP channels This ensures that the content type is also determined when opening JAR channels both synchronously and asynchronously. Current m-c modifies only the async portion, while the mentioned commit below modifies only the sync portion. This commit does it for both. Partially based on 425677ada7380f7c592dd01ddfbc9631ab2038a0 and bug 1757604. --- modules/libjar/nsJARChannel.cpp | 79 ++++++++++++++++++--------------- modules/libjar/nsJARChannel.h | 5 +++ 2 files changed, 48 insertions(+), 36 deletions(-) diff --git a/modules/libjar/nsJARChannel.cpp b/modules/libjar/nsJARChannel.cpp index ddcbfae2c7..195cd4b716 100644 --- a/modules/libjar/nsJARChannel.cpp +++ b/modules/libjar/nsJARChannel.cpp @@ -577,48 +577,47 @@ nsJARChannel::GetSecurityInfo(nsISupports **aSecurityInfo) return NS_OK; } +bool nsJARChannel::GetContentTypeGuess(nsACString& aResult) const { + const char *ext = nullptr, *fileName = mJarEntry.get(); + int32_t len = mJarEntry.Length(); + + // check if we're displaying a directory + // mJarEntry will be empty if we're trying to display + // the topmost directory in a zip, e.g. jar:foo.zip!/ + if (ENTRY_IS_DIRECTORY(mJarEntry)) { + aResult.AssignLiteral(APPLICATION_HTTP_INDEX_FORMAT); + return true; + } + + // Not a directory, take a guess by its extension + for (int32_t i = len - 1; i >= 0; i--) { + if (fileName[i] == '.') { + ext = &fileName[i + 1]; + break; + } + } + if (!ext) { + return false; + } + nsIMIMEService* mimeServ = gJarHandler->MimeService(); + if (!mimeServ) { + return false; + } + mimeServ->GetTypeFromExtension(nsDependentCString(ext), aResult); + return !aResult.IsEmpty(); +} + NS_IMETHODIMP -nsJARChannel::GetContentType(nsACString &result) +nsJARChannel::GetContentType(nsACString &aResult) { // If the Jar file has not been open yet, // We return application/x-unknown-content-type if (!mOpened) { - result.Assign(UNKNOWN_CONTENT_TYPE); + aResult.Assign(UNKNOWN_CONTENT_TYPE); return NS_OK; } - if (mContentType.IsEmpty()) { - - // - // generate content type and set it - // - const char *ext = nullptr, *fileName = mJarEntry.get(); - int32_t len = mJarEntry.Length(); - - // check if we're displaying a directory - // mJarEntry will be empty if we're trying to display - // the topmost directory in a zip, e.g. jar:foo.zip!/ - if (ENTRY_IS_DIRECTORY(mJarEntry)) { - mContentType.AssignLiteral(APPLICATION_HTTP_INDEX_FORMAT); - } - else { - // not a directory, take a guess by its extension - for (int32_t i = len-1; i >= 0; i--) { - if (fileName[i] == '.') { - ext = &fileName[i + 1]; - break; - } - } - if (ext) { - nsIMIMEService *mimeServ = gJarHandler->MimeService(); - if (mimeServ) - mimeServ->GetTypeFromExtension(nsDependentCString(ext), mContentType); - } - if (mContentType.IsEmpty()) - mContentType.AssignLiteral(UNKNOWN_CONTENT_TYPE); - } - } - result = mContentType; + aResult = mContentType; return NS_OK; } @@ -636,8 +635,8 @@ nsJARChannel::SetContentType(const nsACString &aContentType) NS_IMETHODIMP nsJARChannel::GetContentCharset(nsACString &aContentCharset) { - // If someone gives us a charset hint we should just use that charset. - // So we don't care when this is being called. + // We behave like HTTP channels (treat this as a hint if called before open, + // and override the charset if called after open). aContentCharset = mContentCharset; return NS_OK; } @@ -730,6 +729,10 @@ nsJARChannel::Open(nsIInputStream **stream) input.forget(stream); mOpened = true; + // Compute the content type now. + if (!GetContentTypeGuess(mContentType)) { + mContentType.Assign(UNKNOWN_CONTENT_TYPE); + } // local files are always considered safe mIsUnsafe = false; return NS_OK; @@ -827,6 +830,10 @@ nsJARChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *ctx) mLoadGroup->AddRequest(this, nullptr); mOpened = true; + // Compute the content type now. + if (!GetContentTypeGuess(mContentType)) { + mContentType.Assign(UNKNOWN_CONTENT_TYPE); + } return NS_OK; } diff --git a/modules/libjar/nsJARChannel.h b/modules/libjar/nsJARChannel.h index 5328d586ab..20afbcb2fc 100644 --- a/modules/libjar/nsJARChannel.h +++ b/modules/libjar/nsJARChannel.h @@ -59,6 +59,11 @@ private: nsresult OpenLocalFile(); void NotifyError(nsresult aError); void FireOnProgress(uint64_t aProgress); + + // Returns false if we don't know the content type of this channel, in which + // case we should use the content-type hint. + bool GetContentTypeGuess(nsACString&) const; + virtual void OnDownloadComplete(mozilla::net::MemoryDownloader* aDownloader, nsIRequest* aRequest, nsISupports* aCtxt,