[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor-browser] 65/73: Bug 1787633 - Make nsTextToSubURI::UnEscapeNonAsciiURI static. r=m_kato, a=RyanVM



This is an automated email from the git hooks/post-receive script.

richard pushed a commit to branch geckoview-102.3.0esr-12.0-1
in repository tor-browser.

commit 628f4b80a2627a57a0140f6a43c851dbdb5bc953
Author: Masatoshi Kimura <VYV03354@xxxxxxxxxxx>
AuthorDate: Tue Sep 6 15:59:06 2022 +0000

    Bug 1787633 - Make nsTextToSubURI::UnEscapeNonAsciiURI static. r=m_kato, a=RyanVM
    
    Differential Revision: https://phabricator.services.mozilla.com/D156007
---
 dom/jsurl/nsJSProtocolHandler.cpp          | 12 +++---------
 intl/uconv/moz.build                       |  1 +
 intl/uconv/nsITextToSubURI.idl             |  1 +
 intl/uconv/nsTextToSubURI.cpp              | 14 +++++++++++---
 intl/uconv/nsTextToSubURI.h                | 10 ++++++++--
 uriloader/exthandler/win/nsMIMEInfoWin.cpp | 11 +++--------
 6 files changed, 27 insertions(+), 22 deletions(-)

diff --git a/dom/jsurl/nsJSProtocolHandler.cpp b/dom/jsurl/nsJSProtocolHandler.cpp
index 2cee247736efc..170342be7ed6b 100644
--- a/dom/jsurl/nsJSProtocolHandler.cpp
+++ b/dom/jsurl/nsJSProtocolHandler.cpp
@@ -36,10 +36,10 @@
 #include "mozilla/dom/Document.h"
 #include "nsIObjectInputStream.h"
 #include "nsIObjectOutputStream.h"
-#include "nsITextToSubURI.h"
 #include "nsIWritablePropertyBag2.h"
 #include "nsIContentSecurityPolicy.h"
 #include "nsSandboxFlags.h"
+#include "nsTextToSubURI.h"
 #include "mozilla/BasePrincipal.h"
 #include "mozilla/CycleCollectedJSContext.h"
 #include "mozilla/dom/AutoEntryScript.h"
@@ -1100,15 +1100,9 @@ NS_IMPL_ISUPPORTS(nsJSProtocolHandler, nsIProtocolHandler)
     const nsCString& aSpec, const char* aCharset, nsACString& aUTF8Spec) {
   aUTF8Spec.Truncate();
 
-  nsresult rv;
-
-  nsCOMPtr<nsITextToSubURI> txtToSubURI =
-      do_GetService(NS_ITEXTTOSUBURI_CONTRACTID, &rv);
-  NS_ENSURE_SUCCESS(rv, rv);
-
   nsAutoString uStr;
-  rv = txtToSubURI->UnEscapeNonAsciiURI(nsDependentCString(aCharset), aSpec,
-                                        uStr);
+  nsresult rv = nsTextToSubURI::UnEscapeNonAsciiURI(
+      nsDependentCString(aCharset), aSpec, uStr);
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (!IsAscii(uStr)) {
diff --git a/intl/uconv/moz.build b/intl/uconv/moz.build
index 8d9d6250a3b04..e83d8704d83f7 100644
--- a/intl/uconv/moz.build
+++ b/intl/uconv/moz.build
@@ -15,6 +15,7 @@ XPIDL_MODULE = "uconv"
 
 EXPORTS += [
     "nsConverterInputStream.h",
+    "nsTextToSubURI.h",
 ]
 
 UNIFIED_SOURCES += [
diff --git a/intl/uconv/nsITextToSubURI.idl b/intl/uconv/nsITextToSubURI.idl
index da709928a8f00..2b7598cc325fa 100644
--- a/intl/uconv/nsITextToSubURI.idl
+++ b/intl/uconv/nsITextToSubURI.idl
@@ -55,5 +55,6 @@ interface nsITextToSubURI : nsISupports
    * @throws NS_ERROR_UCONV_NOCONV when there is no decoder for aCharset
    *         or NS_ERROR_UDEC_ILLEGALINPUT in case of conversion failure
    */
+  [binaryname(UnEscapeNonAsciiURIJS)]
   AString unEscapeNonAsciiURI(in ACString aCharset, in AUTF8String aURIFragment);
 };
diff --git a/intl/uconv/nsTextToSubURI.cpp b/intl/uconv/nsTextToSubURI.cpp
index 86b71d21c60d9..e70d9ccbd8917 100644
--- a/intl/uconv/nsTextToSubURI.cpp
+++ b/intl/uconv/nsTextToSubURI.cpp
@@ -71,6 +71,7 @@ static bool statefulCharset(const char* charset) {
   return false;
 }
 
+// static
 nsresult nsTextToSubURI::convertURItoUnicode(const nsCString& aCharset,
                                              const nsCString& aURI,
                                              nsAString& aOut) {
@@ -141,9 +142,16 @@ NS_IMETHODIMP nsTextToSubURI::UnEscapeURIForUI(const nsACString& aURIFragment,
 }
 
 NS_IMETHODIMP
-nsTextToSubURI::UnEscapeNonAsciiURI(const nsACString& aCharset,
-                                    const nsACString& aURIFragment,
-                                    nsAString& _retval) {
+nsTextToSubURI::UnEscapeNonAsciiURIJS(const nsACString& aCharset,
+                                      const nsACString& aURIFragment,
+                                      nsAString& _retval) {
+  return UnEscapeNonAsciiURI(aCharset, aURIFragment, _retval);
+}
+
+// static
+nsresult nsTextToSubURI::UnEscapeNonAsciiURI(const nsACString& aCharset,
+                                             const nsACString& aURIFragment,
+                                             nsAString& _retval) {
   nsAutoCString unescapedSpec;
   NS_UnescapeURL(PromiseFlatCString(aURIFragment),
                  esc_AlwaysCopy | esc_OnlyNonASCII, unescapedSpec);
diff --git a/intl/uconv/nsTextToSubURI.h b/intl/uconv/nsTextToSubURI.h
index 6b2b742888b3e..1eaeb554dc89b 100644
--- a/intl/uconv/nsTextToSubURI.h
+++ b/intl/uconv/nsTextToSubURI.h
@@ -15,12 +15,18 @@ class nsTextToSubURI : public nsITextToSubURI {
   NS_DECL_ISUPPORTS
   NS_DECL_NSITEXTTOSUBURI
 
+  // Thread-safe function for C++ callers
+  static nsresult UnEscapeNonAsciiURI(const nsACString& aCharset,
+                                      const nsACString& aURIFragment,
+                                      nsAString& _retval);
+
  private:
   virtual ~nsTextToSubURI();
 
   // We assume that the URI is encoded as UTF-8.
-  nsresult convertURItoUnicode(const nsCString& aCharset, const nsCString& aURI,
-                               nsAString& _retval);
+  static nsresult convertURItoUnicode(const nsCString& aCharset,
+                                      const nsCString& aURI,
+                                      nsAString& _retval);
 
   // Characters defined in netwerk/dns/IDNCharacterBlocklist.inc or via the
   // network.IDN.extra_allowed_chars and network.IDN.extra_blocked_chars prefs.
diff --git a/uriloader/exthandler/win/nsMIMEInfoWin.cpp b/uriloader/exthandler/win/nsMIMEInfoWin.cpp
index ccc04ec96afcb..1eaf7f6567bf8 100644
--- a/uriloader/exthandler/win/nsMIMEInfoWin.cpp
+++ b/uriloader/exthandler/win/nsMIMEInfoWin.cpp
@@ -16,7 +16,7 @@
 #include <shlobj.h>
 #include "nsIWindowsRegKey.h"
 #include "nsUnicharUtils.h"
-#include "nsITextToSubURI.h"
+#include "nsTextToSubURI.h"
 #include "nsVariant.h"
 #include "mozilla/CmdLineAndEnvUtils.h"
 #include "mozilla/ShellHeaderOnlyUtils.h"
@@ -287,13 +287,8 @@ nsresult nsMIMEInfoWin::LoadUriInternal(nsIURI* aURL) {
 
     // Unescape non-ASCII characters in the URL
     nsAutoString utf16Spec;
-
-    nsCOMPtr<nsITextToSubURI> textToSubURI =
-        do_GetService(NS_ITEXTTOSUBURI_CONTRACTID, &rv);
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    if (NS_FAILED(textToSubURI->UnEscapeNonAsciiURI("UTF-8"_ns, urlSpec,
-                                                    utf16Spec))) {
+    if (NS_FAILED(nsTextToSubURI::UnEscapeNonAsciiURI("UTF-8"_ns, urlSpec,
+                                                      utf16Spec))) {
       CopyASCIItoUTF16(urlSpec, utf16Spec);
     }
 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits