From 08da4ec305e3c91eb597c0aedd88068d2ce4098c Mon Sep 17 00:00:00 2001 From: Sandor Molnar Date: Wed, 26 Feb 2025 14:24:49 +0200 Subject: [PATCH] Backed out 4 changesets (bug 1945566) for causing build bustages/py3 unit test failures/bugzilla lint failures CLOSED TREE Backed out changeset 6d69925d57ac (bug 1945566) Backed out changeset 1b2bd35ca71f (bug 1945566) Backed out changeset 9eba66d33006 (bug 1945566) Backed out changeset c19c6833ebdc (bug 1945566) --- .eslintrc.js | 6 - .../static/browser_all_files_referenced.js | 41 +-- browser/installer/package-manifest.in | 1 - docshell/base/BaseHistory.cpp | 3 +- dom/security/nsContentSecurityUtils.cpp | 4 - js/loader/ScriptLoadRequest.cpp | 2 +- js/xpconnect/loader/mozJSModuleLoader.cpp | 3 +- netwerk/base/nsIOService.cpp | 2 +- netwerk/base/nsNetUtil.cpp | 10 - netwerk/base/nsStandardURL.cpp | 1 - netwerk/build/components.conf | 17 -- .../protocol/res/MozSrcProtocolHandler.cpp | 69 ----- netwerk/protocol/res/MozSrcProtocolHandler.h | 49 ---- netwerk/protocol/res/moz.build | 2 - python/mach/mach/command_util.py | 1 - python/mozbuild/mozbuild/frontend/context.py | 8 - python/mozbuild/mozbuild/frontend/data.py | 19 -- python/mozbuild/mozbuild/frontend/emitter.py | 2 - python/mozbuild/mozbuild/frontend/reader.py | 19 +- python/mozbuild/mozpack/packager/formats.py | 1 - srcdir-resolver.js | 29 -- startupcache/StartupCacheUtils.cpp | 13 +- .../webrequest/WebNavigationContent.cpp | 6 +- toolkit/docs/index.rst | 1 - toolkit/docs/internal-urls.md | 138 --------- tools/@types/tsconfig.json | 6 +- tools/use-moz-src/mach_commands.py | 268 ------------------ 27 files changed, 27 insertions(+), 694 deletions(-) delete mode 100644 netwerk/protocol/res/MozSrcProtocolHandler.cpp delete mode 100644 netwerk/protocol/res/MozSrcProtocolHandler.h delete mode 100644 srcdir-resolver.js delete mode 100644 toolkit/docs/internal-urls.md delete mode 100644 tools/use-moz-src/mach_commands.py diff --git a/.eslintrc.js b/.eslintrc.js index 12079efc68c826..bedcdc7fca5637 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -50,10 +50,6 @@ const httpTestingPaths = [ module.exports = { settings: { "import/extensions": [".mjs"], - "import/resolver": { - [path.resolve(__dirname, "srcdir-resolver.js")]: {}, - node: {}, - }, }, ignorePatterns, // Ignore eslint configurations in parent directories. @@ -112,8 +108,6 @@ module.exports = { // *.config.js files are generally assumed to be configuration files // based for node. "*.config.?(m)js", - // The resolver for moz-src for eslint, vscode etc. - "srcdir-resolver.js", ], env: { node: true, diff --git a/browser/base/content/test/static/browser_all_files_referenced.js b/browser/base/content/test/static/browser_all_files_referenced.js index 1efab46a9324e0..857cde45b45a54 100644 --- a/browser/base/content/test/static/browser_all_files_referenced.js +++ b/browser/base/content/test/static/browser_all_files_referenced.js @@ -433,6 +433,7 @@ var gChromeReg = Cc["@mozilla.org/chrome/chrome-registry;1"].getService( ); var gChromeMap = new Map(); var gOverrideMap = new Map(); +var gComponentsSet = new Set(); // In this map when the value is a Set of URLs, the file is referenced if any // of the files in the Set is referenced. @@ -507,6 +508,8 @@ function parseManifest(manifestUri) { } } else if (type == "resource") { trackResourcePrefix(argv[0]); + } else if (type == "component") { + gComponentsSet.add(argv[1]); } } }); @@ -647,10 +650,6 @@ function parseCodeFile(fileUri) { /["'`]chrome:\/\/[a-zA-Z0-9-]+\/(content|skin|locale)\/[^"'` ]*["'`]/g ); - if (!urls) { - urls = line.match(/["']moz-src:\/\/\/[^"']+["']/g); - } - if (!urls) { urls = line.match(/["']resource:\/\/[^"']+["']/g); if ( @@ -738,10 +737,7 @@ function parseCodeFile(fileUri) { if (!/\.(properties|js|jsm|mjs|json|css)$/.test(url)) { url += ".js"; } - if ( - url.startsWith("resource://") || - url.startsWith("moz-src:///") - ) { + if (url.startsWith("resource://")) { addCodeReference(url, fileUri); } else { // if we end up with a chrome:// url here, it's likely because @@ -791,22 +787,13 @@ function parseCodeFile(fileUri) { function convertToCodeURI(fileUri) { let baseUri = fileUri; let path = ""; - while (baseUri) { + while (true) { let slashPos = baseUri.lastIndexOf("/", baseUri.length - 2); if (slashPos <= 0) { // File not accessible from chrome protocol, try resource:// for (let res of gResourceMap) { if (fileUri.startsWith(res[1])) { - let resourceUriString = fileUri.replace( - res[1], - `resource://${res[0]}/` - ); - // If inside moz-src, treat as moz-src url. - resourceUriString = resourceUriString.replace( - /^resource:\/\/gre\/moz-src\//, - "moz-src:///" - ); - return resourceUriString; + return fileUri.replace(res[1], "resource://" + res[0] + "/"); } } // Give up and return the original URL. @@ -818,7 +805,6 @@ function convertToCodeURI(fileUri) { return gChromeMap.get(baseUri) + path; } } - throw new Error(`Unparsable URI: ${fileUri}`); } async function chromeFileExists(aURI) { @@ -866,7 +852,6 @@ function findChromeUrlsFromArray(array, prefix) { // Only keep strings that look like real chrome or resource urls. if ( /chrome:\/\/[a-zA-Z09-]+\/(content|skin|locale)\//.test(string) || - /moz-src:\/\/\/\w+/.test(string) || /resource:\/\/[a-zA-Z09-]*\/.*\.[a-z]+/.test(string) ) { gReferencesFromCode.set(string, null); @@ -880,12 +865,10 @@ add_task(async function checkAllTheFiles() { const libxul = await IOUtils.read(PathUtils.xulLibraryPath); findChromeUrlsFromArray(libxul, "chrome://"); findChromeUrlsFromArray(libxul, "resource://"); - findChromeUrlsFromArray(libxul, "moz-src:///"); // Handle NS_LITERAL_STRING. let uint16 = new Uint16Array(libxul.buffer); findChromeUrlsFromArray(uint16, "chrome://"); findChromeUrlsFromArray(uint16, "resource://"); - findChromeUrlsFromArray(uint16, "moz-src:///"); const kCodeExtensions = [ ".xml", @@ -974,7 +957,6 @@ add_task(async function checkAllTheFiles() { // the non-devtools paths: let devtoolsPrefixes = [ "chrome://devtools", - "moz-src:///devtools/", "resource://devtools/", "resource://devtools-shared-images/", "resource://devtools-highlighter-styles/", @@ -989,9 +971,7 @@ add_task(async function checkAllTheFiles() { for (let uri of uris) { uri = convertToCodeURI(uri.spec); if ( - (uri.startsWith("chrome://") || - uri.startsWith("resource://") || - uri.startsWith("moz-src:///")) && + (uri.startsWith("chrome://") || uri.startsWith("resource://")) && isDevtools == hasDevtoolsPrefix(uri) ) { chromeFiles.push(uri); @@ -1048,6 +1028,9 @@ add_task(async function checkAllTheFiles() { if (rv && f.startsWith("resource://app/")) { rv = isUnreferenced(f.replace("resource://app/", "resource:///")); } + if (rv && /^resource:\/\/(?:app|gre)\/components\/[^/]+\.js$/.test(f)) { + rv = !gComponentsSet.has(f.replace(/.*\//, "")); + } if (!rv) { foundReference = true; if (useAllowlist) { @@ -1128,9 +1111,7 @@ add_task(async function checkAllTheFiles() { } if ( - (file.startsWith("chrome://") || - file.startsWith("resource://") || - file.startsWith("moz-src:///")) && + (file.startsWith("chrome://") || file.startsWith("resource://")) && !(await chromeFileExists(file)) ) { // Ignore chrome prefixes that have been automatically expanded. diff --git a/browser/installer/package-manifest.in b/browser/installer/package-manifest.in index c47e803ef1ffb1..89cff6b562a82b 100644 --- a/browser/installer/package-manifest.in +++ b/browser/installer/package-manifest.in @@ -203,7 +203,6 @@ ; Modules @RESPATH@/browser/modules/* @RESPATH@/modules/* -@RESPATH@/moz-src/* @RESPATH@/browser/actors/* @RESPATH@/actors/* diff --git a/docshell/base/BaseHistory.cpp b/docshell/base/BaseHistory.cpp index b7a7fa5577796d..f6666292539f4f 100644 --- a/docshell/base/BaseHistory.cpp +++ b/docshell/base/BaseHistory.cpp @@ -27,8 +27,7 @@ static constexpr nsLiteralCString kDisallowedSchemes[] = { "chrome"_ns, "data"_ns, "imap"_ns, "javascript"_ns, "mailbox"_ns, "news"_ns, "page-icon"_ns, "resource"_ns, "view-source"_ns, - "moz-extension"_ns, "moz-page-thumb"_ns, "moz-src"_ns, - "x-moz-ews"_ns, + "moz-extension"_ns, "moz-page-thumb"_ns, "x-moz-ews"_ns, }; bool BaseHistory::CanStore(nsIURI* aURI) { diff --git a/dom/security/nsContentSecurityUtils.cpp b/dom/security/nsContentSecurityUtils.cpp index 6d74552a4e53e0..cb005c8ae05b48 100644 --- a/dom/security/nsContentSecurityUtils.cpp +++ b/dom/security/nsContentSecurityUtils.cpp @@ -1903,10 +1903,6 @@ bool nsContentSecurityUtils::ValidateScriptFilename(JSContext* cx, // If it's a resource:// url, allow it return true; } - if (StringBeginsWith(filename, "moz-src://"_ns)) { - // If it's a moz-src:// url, allow it - return true; - } if (StringBeginsWith(filename, "file://"_ns)) { // We will temporarily allow all file:// URIs through for now return true; diff --git a/js/loader/ScriptLoadRequest.cpp b/js/loader/ScriptLoadRequest.cpp index eba7e9a2a4fd4b..b2e2777730e039 100644 --- a/js/loader/ScriptLoadRequest.cpp +++ b/js/loader/ScriptLoadRequest.cpp @@ -226,7 +226,7 @@ void ScriptLoadRequest::MarkScriptForBytecodeEncoding(JSScript* aScript) { static bool IsInternalURIScheme(nsIURI* uri) { return uri->SchemeIs("moz-extension") || uri->SchemeIs("resource") || - uri->SchemeIs("moz-src") || uri->SchemeIs("chrome"); + uri->SchemeIs("chrome"); } void ScriptLoadRequest::SetBaseURLFromChannelAndOriginalURI( diff --git a/js/xpconnect/loader/mozJSModuleLoader.cpp b/js/xpconnect/loader/mozJSModuleLoader.cpp index 473554eebbf13f..13f3b353ac1ece 100644 --- a/js/xpconnect/loader/mozJSModuleLoader.cpp +++ b/js/xpconnect/loader/mozJSModuleLoader.cpp @@ -1039,8 +1039,7 @@ nsresult mozJSModuleLoader::GetModuleImportStack(const nsACString& aLocation, /* static */ bool mozJSModuleLoader::IsTrustedScheme(nsIURI* aURI) { - return aURI->SchemeIs("resource") || aURI->SchemeIs("chrome") || - aURI->SchemeIs("moz-src"); + return aURI->SchemeIs("resource") || aURI->SchemeIs("chrome"); } nsresult mozJSModuleLoader::ImportESModule( diff --git a/netwerk/base/nsIOService.cpp b/netwerk/base/nsIOService.cpp index 3fb7e55cacf21f..c37b4a4639cce8 100644 --- a/netwerk/base/nsIOService.cpp +++ b/netwerk/base/nsIOService.cpp @@ -903,7 +903,7 @@ nsresult nsIOService::AsyncOnChannelRedirect( bool nsIOService::UsesExternalProtocolHandler(const nsACString& aScheme) { if (aScheme == "file"_ns || aScheme == "chrome"_ns || - aScheme == "resource"_ns || aScheme == "moz-src"_ns) { + aScheme == "resource"_ns) { // Don't allow file:, chrome: or resource: URIs to be handled with // nsExternalProtocolHandler, since internally we rely on being able to // use and read from these URIs. diff --git a/netwerk/base/nsNetUtil.cpp b/netwerk/base/nsNetUtil.cpp index 4d0767a8eab095..6c602cd5228bdb 100644 --- a/netwerk/base/nsNetUtil.cpp +++ b/netwerk/base/nsNetUtil.cpp @@ -102,7 +102,6 @@ #endif #include "nsAboutProtocolHandler.h" #include "nsResProtocolHandler.h" -#include "mozilla/net/MozSrcProtocolHandler.h" #include "mozilla/net/ExtensionProtocolHandler.h" #include "mozilla/net/PageThumbProtocolHandler.h" #include "mozilla/net/SFVService.h" @@ -1913,15 +1912,6 @@ nsresult NS_NewURI(nsIURI** aURI, const nsACString& aSpec, return handler->NewURI(aSpec, aCharset, aBaseURI, aURI); } - if (scheme.EqualsLiteral("moz-src")) { - RefPtr handler = - MozSrcProtocolHandler::GetSingleton(); - if (!handler) { - return NS_ERROR_NOT_AVAILABLE; - } - return handler->NewURI(aSpec, aCharset, aBaseURI, aURI); - } - if (scheme.EqualsLiteral("indexeddb") || scheme.EqualsLiteral("uuid")) { return NS_MutateURI(new nsStandardURL::Mutator()) .Apply(&nsIStandardURLMutator::Init, nsIStandardURL::URLTYPE_AUTHORITY, diff --git a/netwerk/base/nsStandardURL.cpp b/netwerk/base/nsStandardURL.cpp index b2778adf3610ec..ff9323639d34a2 100644 --- a/netwerk/base/nsStandardURL.cpp +++ b/netwerk/base/nsStandardURL.cpp @@ -579,7 +579,6 @@ nsresult nsStandardURL::BuildNormalizedSpec(const char* spec, nsDependentCSubstring tempHost(spec + mHost.mPos, mHost.mLen); nsresult rv; bool allowIp = !SegmentIs(spec, mScheme, "resource") && - !SegmentIs(spec, mScheme, "moz-src") && !SegmentIs(spec, mScheme, "chrome"); if (tempHost.First() == '[' && allowIp) { mCheckedIfHostA = true; diff --git a/netwerk/build/components.conf b/netwerk/build/components.conf index c80263f8e71d74..fb70d5672bae0e 100644 --- a/netwerk/build/components.conf +++ b/netwerk/build/components.conf @@ -466,23 +466,6 @@ Classes = [ ], }, }, - { - 'cid': '{4abd60aa-6b7d-4f3b-bf52-d7ce8ae6dd36}', - 'contract_ids': ['@mozilla.org/network/protocol;1?name=moz-src'], - 'singleton': True, - 'type': 'mozilla::net::MozSrcProtocolHandler', - 'headers': ['/netwerk/protocol/res/MozSrcProtocolHandler.h'], - 'constructor': 'mozilla::net::MozSrcProtocolHandler::GetSingleton', - 'protocol_config': { - 'scheme': 'moz-src', - 'flags': [ - 'URI_STD', - 'URI_IS_UI_RESOURCE', - 'URI_IS_LOCAL_RESOURCE', - 'URI_IS_POTENTIALLY_TRUSTWORTHY', - ], - }, - }, { 'cid': '{9c7ec5d1-23f9-11d5-aea8-8fcc0793e97f}', 'contract_ids': ['@mozilla.org/network/protocol;1?name=view-source'], diff --git a/netwerk/protocol/res/MozSrcProtocolHandler.cpp b/netwerk/protocol/res/MozSrcProtocolHandler.cpp deleted file mode 100644 index 2ace95741cd09c..00000000000000 --- a/netwerk/protocol/res/MozSrcProtocolHandler.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "mozilla/ModuleUtils.h" -#include "mozilla/ClearOnShutdown.h" -#include "mozilla/Omnijar.h" - -#include "MozSrcProtocolHandler.h" - -#define MOZSRC_SCHEME "moz-src" - -namespace mozilla { -namespace net { - -NS_IMPL_QUERY_INTERFACE(MozSrcProtocolHandler, nsISubstitutingProtocolHandler, - nsIProtocolHandler, nsISupportsWeakReference) -NS_IMPL_ADDREF_INHERITED(MozSrcProtocolHandler, SubstitutingProtocolHandler) -NS_IMPL_RELEASE_INHERITED(MozSrcProtocolHandler, SubstitutingProtocolHandler) - -mozilla::StaticRefPtr MozSrcProtocolHandler::sSingleton; - -already_AddRefed MozSrcProtocolHandler::GetSingleton() { - if (!sSingleton) { - RefPtr handler = new MozSrcProtocolHandler(); - if (NS_WARN_IF(NS_FAILED(handler->Init()))) { - return nullptr; - } - sSingleton = handler; - ClearOnShutdown(&sSingleton); - } - return do_AddRef(sSingleton); -} - -MozSrcProtocolHandler::MozSrcProtocolHandler() - : SubstitutingProtocolHandler(MOZSRC_SCHEME) {} - -nsresult MozSrcProtocolHandler::Init() { - nsresult rv = mozilla::Omnijar::GetURIString(mozilla::Omnijar::GRE, mGREURI); - NS_ENSURE_SUCCESS(rv, rv); - - mGREURI.AppendLiteral(MOZSRC_SCHEME); - - return NS_OK; -} - -bool MozSrcProtocolHandler::ResolveSpecialCases(const nsACString& aHost, - const nsACString& aPath, - const nsACString& aPathname, - nsACString& aResult) { - aResult = mGREURI; - aResult.Append(aPathname); - return true; -} - -nsresult MozSrcProtocolHandler::GetSubstitutionInternal(const nsACString& aRoot, - nsIURI** aResult) { - nsAutoCString uri; - - if (!ResolveSpecialCases(aRoot, "/"_ns, "/"_ns, uri)) { - return NS_ERROR_NOT_AVAILABLE; - } - - return NS_NewURI(aResult, uri); -} - -} // namespace net -} // namespace mozilla diff --git a/netwerk/protocol/res/MozSrcProtocolHandler.h b/netwerk/protocol/res/MozSrcProtocolHandler.h deleted file mode 100644 index 14845c7ef3aac7..00000000000000 --- a/netwerk/protocol/res/MozSrcProtocolHandler.h +++ /dev/null @@ -1,49 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef MozSrcProtocolHandler_h___ -#define MozSrcProtocolHandler_h___ - -#include "nsIProtocolHandler.h" -#include "nsISubstitutingProtocolHandler.h" -#include "SubstitutingProtocolHandler.h" - -namespace mozilla { -namespace net { - -class MozSrcProtocolHandler final : public nsISubstitutingProtocolHandler, - public SubstitutingProtocolHandler, - public nsSupportsWeakReference { - public: - NS_DECL_ISUPPORTS_INHERITED - NS_FORWARD_NSIPROTOCOLHANDLER(SubstitutingProtocolHandler::) - NS_FORWARD_NSISUBSTITUTINGPROTOCOLHANDLER(SubstitutingProtocolHandler::) - - static already_AddRefed GetSingleton(); - - MozSrcProtocolHandler(); - - protected: - ~MozSrcProtocolHandler() = default; - - [[nodiscard]] virtual bool ResolveSpecialCases(const nsACString& aHost, - const nsACString& aPath, - const nsACString& aPathname, - nsACString& aResult) override; - - [[nodiscard]] nsresult GetSubstitutionInternal(const nsACString& aRoot, - nsIURI** aResult) override; - - private: - static mozilla::StaticRefPtr sSingleton; - nsresult Init(); - - nsCString mGREURI; -}; - -} // namespace net -} // namespace mozilla - -#endif /* MozSrcProtocolHandler_h___ */ diff --git a/netwerk/protocol/res/moz.build b/netwerk/protocol/res/moz.build index e8d20f19a1b47a..63407eebd8b317 100644 --- a/netwerk/protocol/res/moz.build +++ b/netwerk/protocol/res/moz.build @@ -13,7 +13,6 @@ XPIDL_MODULE = "necko_res" EXPORTS.mozilla.net += [ "ExtensionProtocolHandler.h", - "MozSrcProtocolHandler.h", "PageThumbProtocolHandler.h", "RemoteStreamGetter.h", "SubstitutingJARURI.h", @@ -27,7 +26,6 @@ EXPORTS += [ UNIFIED_SOURCES += [ "ExtensionProtocolHandler.cpp", - "MozSrcProtocolHandler.cpp", "nsResProtocolHandler.cpp", "PageThumbProtocolHandler.cpp", "RemoteStreamGetter.cpp", diff --git a/python/mach/mach/command_util.py b/python/mach/mach/command_util.py index b6e61f5653b89c..3edf3debe65899 100644 --- a/python/mach/mach/command_util.py +++ b/python/mach/mach/command_util.py @@ -223,7 +223,6 @@ def __init__( "update-glean-tags": MachCommandReference( "toolkit/components/glean/build_scripts/mach_commands.py" ), - "use-moz-src": MachCommandReference("tools/use-moz-src/mach_commands.py"), "valgrind-test": MachCommandReference("build/valgrind/mach_commands.py"), "vcs-setup": MachCommandReference( "python/mozboot/mozboot/mach_commands.py", diff --git a/python/mozbuild/mozbuild/frontend/context.py b/python/mozbuild/mozbuild/frontend/context.py index 8eb51ab1882d98..9e1895d170243f 100644 --- a/python/mozbuild/mozbuild/frontend/context.py +++ b/python/mozbuild/mozbuild/frontend/context.py @@ -1686,14 +1686,6 @@ def aggregate(files): current locale is ``en-US``. """, ), - "MOZ_SRC_FILES": ( - ContextDerivedTypedHierarchicalStringList(Path), - list, - """This variable contains a list of files that need to be accessible - under the "moz-src" protocol. They are copied to the moz-src portion - of the omni.ja, maintaining the path that they have in the source dir. - """, - ), "OBJDIR_FILES": ( ContextDerivedTypedHierarchicalStringList(Path), list, diff --git a/python/mozbuild/mozbuild/frontend/data.py b/python/mozbuild/mozbuild/frontend/data.py index e96edb3756f540..7010e45062bb6d 100644 --- a/python/mozbuild/mozbuild/frontend/data.py +++ b/python/mozbuild/mozbuild/frontend/data.py @@ -1233,25 +1233,6 @@ def get_obj_basename(f): return basename -class MozSrcFiles(FinalTargetFiles): - """Sandbox container object for MOZ_SRC_FILES, which is a - HierarchicalStringList. - - We need an object derived from ContextDerived for use in the backend, so - this object fills that role. It just has a reference to the underlying - HierarchicalStringList, which is created when parsing MOZ_SRC_FILES. - """ - - __slots__ = ("files",) - - @property - def install_target(self): - # We don't use FINAL_TARGET here because it can include DIST_SUBDIR - # and/or XPI_NAME, whereas we want all moz-src content packaged in - # the same place. - return mozpath.join("dist/bin/moz-src", self._context.relsrcdir) - - class LocalizedFiles(FinalTargetFiles): """Sandbox container object for LOCALIZED_FILES, which is a HierarchicalStringList. diff --git a/python/mozbuild/mozbuild/frontend/emitter.py b/python/mozbuild/mozbuild/frontend/emitter.py index 3bd230f2a82cb2..94039c25dd18c9 100644 --- a/python/mozbuild/mozbuild/frontend/emitter.py +++ b/python/mozbuild/mozbuild/frontend/emitter.py @@ -50,7 +50,6 @@ LocalInclude, LocalizedFiles, LocalizedPreprocessedFiles, - MozSrcFiles, ObjdirFiles, ObjdirPreprocessedFiles, PerSourceFlag, @@ -1446,7 +1445,6 @@ def emit_from_context(self, context): ("FINAL_TARGET_PP_FILES", FinalTargetPreprocessedFiles), ("LOCALIZED_FILES", LocalizedFiles), ("LOCALIZED_PP_FILES", LocalizedPreprocessedFiles), - ("MOZ_SRC_FILES", MozSrcFiles), ("OBJDIR_FILES", ObjdirFiles), ("OBJDIR_PP_FILES", ObjdirPreprocessedFiles), ("TEST_HARNESS_FILES", TestHarnessFiles), diff --git a/python/mozbuild/mozbuild/frontend/reader.py b/python/mozbuild/mozbuild/frontend/reader.py index 2d934b42447084..714f4759d9f3f0 100644 --- a/python/mozbuild/mozbuild/frontend/reader.py +++ b/python/mozbuild/mozbuild/frontend/reader.py @@ -959,7 +959,7 @@ def should_include_dir(relpath, d): if "moz.build" in files: yield mozpath.join(relpath, "moz.build") - def find_variables_from_ast(self, variables, path=None, all_relevant_files=True): + def find_variables_from_ast(self, variables, path=None): """Finds all assignments to the specified variables by parsing moz.build abstract syntax trees. @@ -992,10 +992,6 @@ def find_variables_from_ast(self, variables, path=None, all_relevant_files=True) path (str): A path relative to the source dir. If specified, only `moz.build` files relevant to this path will be parsed. Otherwise all `moz.build` files are parsed. - all_relevant_files (bool): Whether to look at all relevant paths - (the default), or only look at the specific path passed in. - If you set this to False, `path` must also be specified and - point to a moz.build file. Returns: A generator that generates tuples of the form `(, @@ -1017,7 +1013,7 @@ def assigned_variable(node): else: target = node.target - if isinstance(target, (ast.Subscript, ast.Attribute)): + if isinstance(target, ast.Subscript): if not isinstance(target.value, ast.Name): return None, None name = target.value.id @@ -1041,9 +1037,6 @@ def assigned_variable(node): assert isinstance(target.slice, ast.Index) assert isinstance(target.slice.value, ast.Str) key = target.slice.value.s - elif isinstance(target, ast.Attribute): - assert isinstance(target.attr, str) - key = target.attr return name, key @@ -1074,13 +1067,7 @@ def visit_Assign(self, node): def visit_AugAssign(self, node): self.helper(node) - if not all_relevant_files: - if not path: - raise Exception( - "all_relevant_files was set to False but you did not pass a path." - ) - mozbuild_paths = [path] - elif path: + if path: mozbuild_paths = chain(*self._find_relevant_mozbuilds([path]).values()) else: mozbuild_paths = self.all_mozbuild_paths() diff --git a/python/mozbuild/mozpack/packager/formats.py b/python/mozbuild/mozpack/packager/formats.py index 2926f98ce09cf3..49aa9eff8884b2 100644 --- a/python/mozbuild/mozpack/packager/formats.py +++ b/python/mozbuild/mozpack/packager/formats.py @@ -345,7 +345,6 @@ def is_resource(self, path): return True return path[0] in [ "modules", - "moz-src", "actors", "dictionaries", "hyphenation", diff --git a/srcdir-resolver.js b/srcdir-resolver.js deleted file mode 100644 index 31301900105efd..00000000000000 --- a/srcdir-resolver.js +++ /dev/null @@ -1,29 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ - -const path = require("path"); -const fs = require("fs"); - -const PREFIX = "moz-src:///"; - -exports.interfaceVersion = 2; -exports.resolve = source => { - if (!source.startsWith(PREFIX)) { - return { found: false }; - } - - let result = path.resolve( - __dirname, - ...source.substring(PREFIX.length).split("/") - ); - let stats = fs.statSync(result, { throwIfNoEntry: false }); - if (!stats || !stats.isFile()) { - return { found: false }; - } - - return { - found: true, - path: result, - }; -}; diff --git a/startupcache/StartupCacheUtils.cpp b/startupcache/StartupCacheUtils.cpp index 84c919aa4ba15b..c8dcdd7f117312 100644 --- a/startupcache/StartupCacheUtils.cpp +++ b/startupcache/StartupCacheUtils.cpp @@ -7,7 +7,7 @@ #include "nsNetUtil.h" #include "nsIFileURL.h" #include "nsIJARURI.h" -#include "nsISubstitutingProtocolHandler.h" +#include "nsIResProtocolHandler.h" #include "nsIChromeRegistry.h" #include "nsStringStream.h" #include "StartupCacheUtils.h" @@ -136,20 +136,17 @@ static inline bool canonicalizeBase(nsAutoCString& spec, nsACString& out) { nsresult ResolveURI(nsIURI* in, nsIURI** out) { nsresult rv; - nsAutoCString scheme; - in->GetScheme(scheme); - // Resolve resource:// URIs. At the end of this if/else block, we // have both spec and uri variables identifying the same URI. - if (scheme.EqualsLiteral("resource") || scheme.EqualsLiteral("moz-src")) { + if (in->SchemeIs("resource")) { nsCOMPtr ioService = do_GetIOService(&rv); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr ph; - rv = ioService->GetProtocolHandler(scheme.get(), getter_AddRefs(ph)); + rv = ioService->GetProtocolHandler("resource", getter_AddRefs(ph)); NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr irph(do_QueryInterface(ph, &rv)); + nsCOMPtr irph(do_QueryInterface(ph, &rv)); NS_ENSURE_SUCCESS(rv, rv); nsAutoCString spec; @@ -158,7 +155,7 @@ nsresult ResolveURI(nsIURI* in, nsIURI** out) { return ioService->NewURI(spec, nullptr, nullptr, out); } - if (scheme.EqualsLiteral("chrome")) { + if (in->SchemeIs("chrome")) { nsCOMPtr chromeReg = mozilla::services::GetChromeRegistry(); if (!chromeReg) return NS_ERROR_UNEXPECTED; diff --git a/toolkit/components/extensions/webrequest/WebNavigationContent.cpp b/toolkit/components/extensions/webrequest/WebNavigationContent.cpp index dab7067ae34769..9b7a53a3bca8ad 100644 --- a/toolkit/components/extensions/webrequest/WebNavigationContent.cpp +++ b/toolkit/components/extensions/webrequest/WebNavigationContent.cpp @@ -197,14 +197,14 @@ WebNavigationContent::OnStateChange(nsIWebProgress* aWebProgress, nsCOMPtr uri; MOZ_TRY(channel->GetURI(getter_AddRefs(uri))); - // Prevent "about", "chrome", "resource", "moz-src", and "moz-extension" URIs - // being reported with the resolved "file" or "jar" URIs (see bug 1246125). + // Prevents "about", "chrome", "resource" and "moz-extension" URI schemes to + // be reported with the resolved "file" or "jar" URIs (see bug 1246125) if (uri->SchemeIs("file") || uri->SchemeIs("jar")) { nsCOMPtr originalURI; MOZ_TRY(channel->GetOriginalURI(getter_AddRefs(originalURI))); // FIXME: We probably actually want NS_GetFinalChannelURI here. if (originalURI->SchemeIs("about") || originalURI->SchemeIs("chrome") || - originalURI->SchemeIs("resource") || originalURI->SchemeIs("moz-src") || + originalURI->SchemeIs("resource") || originalURI->SchemeIs("moz-extension")) { uri = originalURI.forget(); } diff --git a/toolkit/docs/index.rst b/toolkit/docs/index.rst index 118e96b4e18e85..32b6a13b423847 100644 --- a/toolkit/docs/index.rst +++ b/toolkit/docs/index.rst @@ -13,7 +13,6 @@ This is the nascent documentation of the Toolkit code that is shared across Fire components/crashes/crash-manager/index crashreporter/crashreporter/index components/featuregates/featuregates/index - internal-urls search/index components/normandy/normandy/index components/nimbus/docs/index diff --git a/toolkit/docs/internal-urls.md b/toolkit/docs/internal-urls.md deleted file mode 100644 index b6fc25a5ebc798..00000000000000 --- a/toolkit/docs/internal-urls.md +++ /dev/null @@ -1,138 +0,0 @@ -# Internal URLs - -Firefox and other Gecko applications use several URL schemes (protocols) for -internal or "special" resources. - -The main ones are: - - - - [`moz-src` URLs](#moz-src-urls) - - [`resource` URLs](#resource-urls) - - [`chrome` URLs](#chrome-urls) - -There are other special protocols like `moz-icon` and various places URLs, -but at the moment they are not covered here. - -## `moz-src` URLs -URLs look like: `moz-src:///browser/components/BrowserGlue.sys.mjs`. - -Note that there is no "host" component (nothing between the second and third -slash). In future we may support non-empty hosts with specific meanings. For -now, always use a triple slash. - -Everything after this is the full source path of the file you are referencing. - -Of course this is an abstraction: the URL will only work if the file is actually - packaged. - -### Packaging - -To package a file for use via `moz-src`, include it in a -[`moz.build` file][mozbuild-files] inside a `MOZ_SRC_FILES` instruction. - -All files are packaged in the toolkit `omni.ja` file. Internally, the URL is -translated into a `jar:file` URL into the toolkit (`gre`) `omni.ja` file. - -### Security considerations - -Only privileged (system principal / "chrome" privileged) code can load -or link to `moz-src` URLs. - -The intention is that in future we make it possible to have more fine-grained -restrictions for `moz-src` URLs with non-empty "host" portions -(e.g. `moz-src://about/` for content only accessible to about: pages), but this -has not yet been implemented. - -## `resource` URLs -URLs look like `resource://mapping/optional/path/components/file.txt`. - -Here, `mapping` is an arbitrary identifier chosen elsewhere. There are -3 builtin mappings of note: - -- `gre` ("Gecko Runtime Environment") for some of the content inside the - "toolkit" omni.ja file -- `app`, for some of the content inside the "browser" (or other - application-specific) omni.ja file. -- `android`, on Android, for APK contents. - -The `app` mapping is the default, which means that if you use a resource URL -without a host component (`resource:///whatever`), it is equivalent to the -`app` URL: `resource://app/whatever`. - -Each mapping is resolved to a URL in the resource URL protocol handler, after -which any subsequent path/file components are resolved relative to that URL. - -Additional mappings can be added via a -[chrome.manifest instruction][resource-map]. Builtin extensions make use of -this, as do [some components][searchfox-res-reg]. - -### Packaging -The builtin `app` and `gre` mappings, as well as any additional mappings from -`jar.mn` files and other non-extension parts of the build, always resolve into -the app-specific and toolkit `omni.ja` file, respectively. - -To package files for access via `resource` URLs, use -[jar manifest file instructions][jar-manifest-files] to package files into -the mapped directory inside `omni.ja` . - -### Security considerations -By default `resource` URLs cannot be accessed by web content and are restricted -to privileged (system principal / "chrome" privileged) code. However, you can -register a `resource` mapping with `contentaccessible=yes` in order to -"holepunch" this restriction. Note that this means _everything_ packaged under -that path becomes linkable and loadable by all web content. With few exceptions -(like user agent stylesheets), that is not what you want. - -Unfortunately more fine-grained restrictions are not available for `resource` -URLs. - -## `chrome` URLs -`chrome` URLs take one of three forms: - -- `chrome://browser/content/browser.xhtml` -- `chrome://browser/skin/browser.css` -- `chrome://browser/locale/browser.properties` - -The first ("host") component after `chrome://` is the **package name**. Common -ones are `browser` (for front-end Desktop Firefox files) and `global` (for -content used by Gecko/toolkit code), but different parts of the codebase can and -do register their own packages. - -The second component after `chrome://{packagename}/` is always one of `content`, -`skin` or `locale`, known as "providers". They cater to JS and HTML (`content`), -style information (`skin`) and old-style `.properties` localization files -(`locale`). - -Any path portions after the provider are relative paths to where that particular -package & provider combination is pointing. - -More information is available in -[the build system's chrome registration docs][chrome-registration]. - -### Packaging -To package files for access via `chrome` URLs, use -[jar manifest file instructions][jar-manifest-files] to package files into -the mapped directory inside `omni.ja` . - -Depending on how and where [the chrome is registered][chrome-registration], -the files are typically packaged into either the app or toolkit `omni.ja` file, -though it is possible to use `chrome` URLs inside builtin extensions as well. - -### Security considerations -By default `chrome` URLs cannot be accessed by web content and are restricted -to privileged (system principal / "chrome" privileged) code. However, you can -register a chrome `content` mapping with `contentaccessible=yes` in order to -"holepunch" this restriction. Note that this means _everything_ packaged under -**the content, skin and locale packages for that identifier** becomes linkable -and loadable by all web content. Please do not use this functionality going -forward. - -Unfortunately more fine-grained restrictions are not available for `chrome` -URLs. - - -[chrome-registration]: ../build/buildsystem/chrome-registration -[resource-map]: ../build/buildsystem/chrome-registration#resource -[mozbuild-files]: ../build/buildsystem/mozbuild-files -[searchfox-res-reg]: https://searchfox.org/mozilla-central/search?q=%25+resource&path=jar.mn&case=false®exp=false -[jar-manifest-files]: ../build/buildsystem/jar-manifests diff --git a/tools/@types/tsconfig.json b/tools/@types/tsconfig.json index e0b2e07a878c82..b39e1e0ea9aa11 100644 --- a/tools/@types/tsconfig.json +++ b/tools/@types/tsconfig.json @@ -2,10 +2,6 @@ "compilerOptions": { "noEmit": true, "target": "es2022", - "types": ["gecko"], - "baseUrl": "../../", - "paths": { - "moz-src:///*": ["./*"] - } + "types": ["gecko"] } } diff --git a/tools/use-moz-src/mach_commands.py b/tools/use-moz-src/mach_commands.py deleted file mode 100644 index b860ae9b4bef59..00000000000000 --- a/tools/use-moz-src/mach_commands.py +++ /dev/null @@ -1,268 +0,0 @@ -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - -import asyncio -import logging -import os -import re -from shutil import which - -from mach.decorators import ( - Command, - CommandArgument, -) - -_log = logging.getLogger(__name__) - -NO_RIPGREP_MSG = """ -Could not find ripgrep. Perhaps it needs installing via your package manager - or `cargo install`. -""".strip() - -RIPGREP_ERROR_MSG = """ -An error occurred running ripgrep. Please check the following error messages: - -{} -""".strip() - -NO_MODULES_TO_REWRITE_MSG = """ -Found no EXTRA_JS_MODULES we could convert in the moz.build file(s) passed. -""".strip() - -CANNOT_CONVERT_ERROR_MSG = """ -Unfortunately {} cannot be automatically converted. - -The script isn't clever enough to convert everything else while leaving that -module alone. Consider (temporarily) removing this module from the moz.build -file, then running the script, and then re-adding the module into the -moz.build file in a copy of the original EXTRA_JS_MODULES instruction. - -The list of excluded module patterns is in tools/use-moz-src/mach_commands.py -and should have a comment explaining why it cannot be automatically moved to -moz-src:///. -""".strip() - -excluded_from_convert_re = list( - map( - re.compile, - [ - "BackgroundTask_.*\\.sys\\.mjs", # Depend on this resource: path. - "BrowserUsageTelemetry\\.sys\\.mjs", # Browser + Android duplicates. - "BuiltInThemes\\.sys\\.mjs", # Thunderbird override - "CrashManager\\.sys.\\.mjs", # Preprocessed. - "ExtensionBrowsingData\\.sys\\.mjs", # Browser + Android duplicates. - "policies/schema\\.sys\\.mjs", # Thunderbird override - "Policies\\.sys\\.mjs", # Thunderbird override - "PromiseWorker\\.m?js", # Preprocessed. - "RFPTargetConstants\\.sys\\.mjs", # Preprocessed. - "ThemeVariableMap\\.sys\\.mjs", # Thunderbird override - ], - ) -) - - -def is_excluded_from_convert(path): - """Returns true if the JSM file shouldn't be converted to ESM.""" - path_str = str(path) - for expr in excluded_from_convert_re: - if expr.search(path_str): - return True - - return False - - -def extract_info_from_mozbuild(command_context, paths): - mozbuilds_for_fixing = set() - urlmap = dict() - reader = command_context.mozbuild_reader(config_mode="empty") - for mozbuild_path in paths: - is_browser = mozbuild_path.startswith("browser") or ( - mozbuild_path.startswith("devtools") - and not mozbuild_path.startswith("devtools/platform") - ) - assignments = reader.find_variables_from_ast( - variables="EXTRA_JS_MODULES", path=mozbuild_path, all_relevant_files=False - ) - for path, _variable, key, value in assignments: - module_path = path.replace("moz.build", "") + value - if is_excluded_from_convert(module_path): - _log.log(logging.ERROR, CANNOT_CONVERT_ERROR_MSG.format(value)) - return [], dict() - - newurl = "moz-src:///" + module_path - module_name = os.path.basename(module_path) - keystr = "/".join(key.split(".")) + "/" if key else "" - resource_suffix = "modules/" + keystr + module_name - if is_browser: - urlmap["resource:///" + resource_suffix] = newurl - else: - urlmap["resource://gre/" + resource_suffix] = newurl - - mozbuilds_for_fixing.add(mozbuild_path) - - return mozbuilds_for_fixing, urlmap - - -extra_js_modules_re = re.compile('EXTRA_JS_MODULES(["\\.\\w/\\[\\]]*) ') - - -def rewrite_mozbuilds(mozbuilds): - for path in mozbuilds: - with open(path, "r+", encoding="utf-8", newline="\n") as f: - contents = f.read() - contents = re.sub(extra_js_modules_re, "MOZ_SRC_FILES ", contents) - f.seek(0) - f.write(contents) - f.truncate() - - -def _get_re_for_urls(urlmap): - old_urls = list(urlmap.keys()) - - prefix = os.path.commonprefix(old_urls) - prefixlen = len(prefix) - old_urls_without_prefix = map(lambda u: u[prefixlen:], old_urls) - - escaped_prefix = re.escape(prefix) - # Put the "app" option in if needed: - escaped_prefix = re.sub("resource:///", "resource://(app)?/", escaped_prefix) - suffixes = "|".join(map(re.escape, old_urls_without_prefix)) - return escaped_prefix + "(" + suffixes + ")" - - -def handle_matching_file(file, urlmap_re, replace_fn): - with open(file, "r+", encoding="utf-8", newline="\n") as f: - contents = f.read() - f.seek(0) - contents = re.sub(urlmap_re, replace_fn, contents) - f.write(contents) - f.truncate() - - -async def find_and_replace_refs(urlmap): - urlmap_re = _get_re_for_urls(urlmap) - - encoding = "utf-8" - - cmd_args = [which("rg"), "-l", "-e", urlmap_re] - - proc = await asyncio.subprocess.create_subprocess_exec( - *cmd_args, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE - ) - - pending_file_writes = set() - affected_files = set() - - def replace_fn(matchobj): - old_url = matchobj.group(0) - # Replace with the mapped URL or with itself if we can't find it. - return urlmap.get(old_url, old_url) - - async with asyncio.TaskGroup() as tg: - - async def handle_matching_files() -> None: - assert proc.stdout is not None - while matching_file := await proc.stdout.readline(): - matching_file = matching_file.decode(encoding, "replace") - if not matching_file.endswith("\n"): - continue - matching_file = matching_file.strip() - if not matching_file: - continue - _log.log(logging.INFO, "Rewriting {}".format(matching_file)) - affected_files.add(matching_file) - task = tg.create_task( - asyncio.to_thread( - handle_matching_file, matching_file, urlmap_re, replace_fn - ) - ) - pending_file_writes.add(task) - task.add_done_callback(pending_file_writes.discard) - - async def handle_errors() -> None: - assert proc.stderr is not None - while chunk := await proc.stderr.read(10000): - _log.log( - logging.ERROR, - RIPGREP_ERROR_MSG.format(chunk.decode("utf-8", "replace")), - ) - # We assume that if anything gets written to stderr by ripgrep, - # it'll also exit shortly and we don't need to deal with that - # separately by raising exceptions or whatever. - - await asyncio.gather(handle_matching_files(), handle_errors(), proc.wait()) - return affected_files - - -@Command( - "use-moz-src", - category="misc", - description="Convert use of EXTRA_JS_MODULES to MOZ_SRC_FILES", -) -@CommandArgument( - "paths", - nargs="+", - help="Path to the moz.build file(s) to convert.", -) -def use_moz_src(command_context, paths): - """ - This command does two things: - 1. replace use of EXTRA_JS_MODULES in the moz.build file passed with - MOZ_SRC_FILES. - 2. fix up consumers across the tree that rely on any files in - EXTRA_JS_MODULES using `resource` URLs to use `moz-src` ones - instead. - - Note that this only uses the moz.build file in question; it will not - recurse into `DIRS`. If you want to convert subdirectories, use - e.g. `find` to collect the moz.build files and pass all of them on - the commandline. - - Example: - - ./mach use-moz-src browser/components/moz.build - - Recursive example: - - find browser/components -iname 'moz.build' | xargs ./mach use-moz-src - - """ - if not which("rg"): - _log.log(logging.ERROR, NO_RIPGREP_MSG) - return - - mozbuilds_for_fixing, urlmap = extract_info_from_mozbuild(command_context, paths) - - if not mozbuilds_for_fixing: - _log.log(logging.INFO, NO_MODULES_TO_REWRITE_MSG) - return - - _log.log( - logging.INFO, - "Searching the tree and updating all references to:\n {}".format( - "\n ".join(urlmap.keys()) - ), - ) - updated_files = asyncio.run(find_and_replace_refs(urlmap)) - - _log.log( - logging.INFO, - "Updating build files:\n {}".format("\n ".join(mozbuilds_for_fixing)), - ) - - rewrite_mozbuilds(mozbuilds_for_fixing) - - _log.log(logging.INFO, "Formatting {} affected files...".format(len(updated_files))) - - command_context._mach_context.commands.dispatch( - "lint", - command_context._mach_context, - linters=["eslint"], - paths=updated_files, - fix=True, - ) - - _log.log( - logging.INFO, "Done. Make sure to test the result before submitting patches." - )