Backed out 3 changesets (bug 1884785, bug 1884265) for causing build bustages in nsLocalHandlerApp.cpp CLOSED TREE

Backed out changeset 08cb16bededc (bug 1884265)
Backed out changeset dc60eabb35ec (bug 1884785)
Backed out changeset 2de1412ec7e3 (bug 1884265)
This commit is contained in:
Cristian Tuns 2024-03-13 13:43:40 -04:00
Родитель 854f7bfe11
Коммит cc0efecf5c
12 изменённых файлов: 11 добавлений и 419 удалений

Просмотреть файл

@ -53,23 +53,18 @@ interface nsIHandlerInfo : nsISupports {
readonly attribute nsIMutableArray possibleApplicationHandlers;
/**
* Indicates whether a default OS application handler exists,
* Indicates whether a default application handler exists,
* i.e. whether launchWithFile with action = useSystemDefault is possible
* and defaultDescription will contain usable information.
*/
readonly attribute boolean hasDefaultHandler;
/**
* A pretty name description of the associated default OS application. Only
* A pretty name description of the associated default application. Only
* usable if hasDefaultHandler is true.
*/
readonly attribute AString defaultDescription;
/**
* The default OS application. Only usable if hasDefaultHandler is true.
*/
readonly attribute nsIFile defaultExecutable;
/**
* Launches the application with the specified URI, in a way that
* depends on the value of preferredAction. preferredAction must be
@ -285,24 +280,6 @@ interface nsILocalHandlerApp : nsIHandlerApp {
*/
readonly attribute unsigned long parameterCount;
/**
* Asynchronously returns the pretty (user friendly) name of the
* executable.
*
* On Linux and Mac, this is the same as the name
* property. On Mac, that happens to be a nicer name than
* the executable's name without the file extension.
*
* On Windows, this name will be nicer, looked up from the
* registry when it exists and falling back to the FileDescription
* getVersionFieldInfo when the registry data doesn't exist.
* This has the side effect that the prettyName returned
* generally will match the text returned by defaultDescription in
* nsIHandlerInfo.
*/
[implicit_jscontext]
Promise prettyNameAsync();
/**
* Clears the current list of command line parameters.
*/

Просмотреть файл

@ -110,10 +110,6 @@ NS_IMETHODIMP ProxyHandlerInfo::GetDefaultDescription(
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP ProxyHandlerInfo::GetDefaultExecutable(nsIFile** aExecutable) {
return NS_ERROR_NOT_IMPLEMENTED;
}
/* void launchWithURI (in nsIURI aURI,
[optional] in BrowsingContext aBrowsingContext); */
NS_IMETHODIMP ProxyHandlerInfo::LaunchWithURI(

Просмотреть файл

@ -95,7 +95,6 @@ elif CONFIG["MOZ_WIDGET_TOOLKIT"] == "android":
]
elif CONFIG["MOZ_WIDGET_TOOLKIT"] == "windows":
UNIFIED_SOURCES += [
"win/nsLocalHandlerAppWin.cpp",
"win/nsMIMEInfoWin.cpp",
]

Просмотреть файл

@ -8,8 +8,6 @@
#include "nsIURI.h"
#include "nsIProcess.h"
#include "nsComponentManagerUtils.h"
#include "mozilla/dom/Promise.h"
#include "nsProxyRelease.h"
// XXX why does nsMIMEInfoImpl have a threadsafe nsISupports? do we need one
// here too?
@ -30,100 +28,6 @@ NS_IMETHODIMP nsLocalHandlerApp::GetName(nsAString& aName) {
return NS_OK;
}
/**
* This method returns a std::function that will be executed on a thread other
* than the main thread. To facilitate things, it should effectively be a global
* function that does not maintain a reference to the this pointer. There should
* be no reference to any objects that will be shared across threads. Sub-class
* implementations should make local copies of everything they need and capture
* those in the callback.
*/
std::function<nsresult(nsString&)>
nsLocalHandlerApp::GetPrettyNameOnNonMainThreadCallback() {
nsString name;
// Calculate the name now, on the main thread, so as to avoid
// doing anything with the this pointer on the other thread
auto result = GetName(name);
return [name, result](nsString& aName) {
aName = name;
return result;
};
}
NS_IMETHODIMP
nsLocalHandlerApp::PrettyNameAsync(JSContext* aCx, dom::Promise** aPromise) {
NS_ENSURE_ARG_POINTER(aPromise);
*aPromise = nullptr;
if (!mExecutable) {
return NS_ERROR_FAILURE;
}
nsIGlobalObject* global = xpc::CurrentNativeGlobal(aCx);
if (NS_WARN_IF(!global)) {
return NS_ERROR_FAILURE;
}
ErrorResult err;
RefPtr<dom::Promise> outer = dom::Promise::Create(global, err);
if (NS_WARN_IF(err.Failed())) {
return err.StealNSResult();
}
outer.forget(aPromise);
nsAutoString executablePath;
nsresult result = mExecutable->GetPath(executablePath);
if (NS_FAILED(result) || executablePath.IsEmpty()) {
(*aPromise)->MaybeReject(result);
return NS_OK;
}
nsMainThreadPtrHandle<dom::Promise> promiseHolder(
new nsMainThreadPtrHolder<dom::Promise>(
"nsLocalHandlerApp::prettyExecutableName Promise", *aPromise));
auto prettyNameGetter = GetPrettyNameOnNonMainThreadCallback();
result = NS_DispatchBackgroundTask(
NS_NewRunnableFunction(
__func__,
[promiseHolder /* can't move this because if the dispatch fails, we
call reject on the promiseHolder */
,
prettyNameGetter = std::move(prettyNameGetter)]() mutable -> void {
nsAutoString prettyExecutableName;
nsresult result = prettyNameGetter(prettyExecutableName);
DebugOnly<nsresult> rv =
NS_DispatchToMainThread(NS_NewRunnableFunction(
__func__,
[promiseHolder = std::move(promiseHolder),
prettyExecutableName = std::move(prettyExecutableName),
result]() {
if (NS_FAILED(result)) {
promiseHolder.get()->MaybeReject(result);
} else {
promiseHolder.get()->MaybeResolve(prettyExecutableName);
}
}));
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
"NS_DispatchToMainThread failed");
}),
NS_DISPATCH_EVENT_MAY_BLOCK);
if (NS_FAILED(result)) {
promiseHolder.get()->MaybeReject(result);
}
return NS_OK;
}
NS_IMETHODIMP nsLocalHandlerApp::SetName(const nsAString& aName) {
mName.Assign(aName);

Просмотреть файл

@ -12,8 +12,6 @@
#include "nsIFile.h"
#include "nsTArray.h"
#include <functional>
class nsLocalHandlerApp : public nsILocalHandlerApp {
public:
NS_DECL_ISUPPORTS
@ -31,9 +29,6 @@ class nsLocalHandlerApp : public nsILocalHandlerApp {
protected:
virtual ~nsLocalHandlerApp() {}
virtual std::function<nsresult(nsString&)>
GetPrettyNameOnNonMainThreadCallback();
nsString mName;
nsString mDetailedDescription;
nsTArray<nsString> mParameters;
@ -57,11 +52,6 @@ class nsLocalHandlerApp : public nsILocalHandlerApp {
# include "mac/nsLocalHandlerAppMac.h"
typedef nsLocalHandlerAppMac PlatformLocalHandlerApp_t;
# endif
#elif XP_WIN
# ifndef NSLOCALHANDLERAPPWIN_H_
# include "win/nsLocalHandlerAppWin.h"
typedef nsLocalHandlerAppWin PlatformLocalHandlerApp_t;
# endif
#else
typedef nsLocalHandlerApp PlatformLocalHandlerApp_t;
#endif

Просмотреть файл

@ -230,11 +230,6 @@ nsMIMEInfoBase::GetDefaultDescription(nsAString& aDefaultDescription) {
return NS_OK;
}
NS_IMETHODIMP
nsMIMEInfoBase::GetDefaultExecutable(nsIFile** aExecutable) {
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsMIMEInfoBase::GetPreferredApplicationHandler(
nsIHandlerApp** aPreferredAppHandler) {
@ -488,16 +483,6 @@ nsMIMEInfoImpl::GetDefaultDescription(nsAString& aDefaultDescription) {
return NS_OK;
}
NS_IMETHODIMP nsMIMEInfoImpl::GetDefaultExecutable(nsIFile** aExecutable) {
nsCOMPtr<nsIFile> defaultApp = GetDefaultApplication();
if (defaultApp) {
defaultApp.forget(aExecutable);
return NS_OK;
}
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsMIMEInfoImpl::GetHasDefaultHandler(bool* _retval) {
*_retval = !mDefaultAppDescription.IsEmpty();

Просмотреть файл

@ -57,7 +57,6 @@ class nsMIMEInfoBase : public nsIMIMEInfo {
NS_IMETHOD GetPossibleApplicationHandlers(
nsIMutableArray** aPossibleAppHandlers) override;
NS_IMETHOD GetDefaultDescription(nsAString& aDefaultDescription) override;
NS_IMETHOD GetDefaultExecutable(nsIFile** aExecutable) override;
NS_IMETHOD LaunchWithFile(nsIFile* aFile) override;
NS_IMETHOD LaunchWithURI(
nsIURI* aURI, mozilla::dom::BrowsingContext* aBrowsingContext) override;
@ -188,7 +187,6 @@ class nsMIMEInfoImpl : public nsMIMEInfoBase {
// nsIMIMEInfo methods
NS_IMETHOD GetHasDefaultHandler(bool* _retval) override;
NS_IMETHOD GetDefaultDescription(nsAString& aDefaultDescription) override;
NS_IMETHOD GetDefaultExecutable(nsIFile** aExecutable) override;
NS_IMETHOD IsCurrentAppOSDefault(bool* _retval) override;
// additional methods

Просмотреть файл

@ -15,95 +15,3 @@ add_task(async function test_utf8_extension() {
Assert.equal(someMIME.primaryExtension, ".тест");
}
});
add_task(async function test_default_executable() {
const mimeService = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService);
let mimeInfo = mimeService.getFromTypeAndExtension("text/html", "html");
if (mimeInfo !== undefined) {
if (mimeInfo.hasDefaultHandler) {
let defaultExecutableFile = mimeInfo.defaultExecutable;
if (defaultExecutableFile) {
if (AppConstants.platform == "win") {
Assert.ok(
defaultExecutableFile.leafName.endsWith(".exe"),
"Default browser on Windows should end with .exe"
);
}
}
let foundDefaultInList = false;
let appList = mimeInfo.possibleLocalHandlers || [];
for (let index = 0; index < appList.length; index++) {
let app = appList.queryElementAt(index, Ci.nsILocalHandlerApp);
let executablePath = app.executable.path;
if (executablePath == defaultExecutableFile.path) {
foundDefaultInList = true;
break;
}
}
Assert.ok(
foundDefaultInList,
"The default browser must be returned in the list of executables from the mime info"
);
} else {
Assert.throws(
() => mimeInfo.defaultExecutable,
/NS_ERROR_FAILURE/,
"Fetching the defaultExecutable should generate an exception; this line should never be reached"
);
}
}
});
add_task(async function test_pretty_name_for_edge() {
if (AppConstants.platform == "win" && !AppConstants.IS_ESR) {
const mimeService = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService);
let mimeInfo = mimeService.getFromTypeAndExtension("text/html", "html");
let appList = mimeInfo?.possibleLocalHandlers || [];
for (let index = 0; index < appList.length; index++) {
let app = appList.queryElementAt(index, Ci.nsILocalHandlerApp);
let executableName = app.executable.displayName;
let prettyName = await app.prettyNameAsync();
// Hardcode Edge, as an extra test, when it's installed
if (executableName == "msedge.exe") {
Assert.equal(
prettyName,
"Microsoft Edge",
"The generated pretty name for MS Edge should match the expectation."
);
}
// The pretty name should always be something nicer than the executable name.
// This isn't testing that's nice, but should be good enough to validate that
// something other than the executable is found.
Assert.notEqual(executableName, prettyName);
}
}
});
add_task(async function test_pretty_names_match_names_on_non_windows() {
if (AppConstants.platform != "win") {
const mimeService = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService);
let mimeInfo = mimeService.getFromTypeAndExtension("text/html", "html");
let appList = mimeInfo?.possibleLocalHandlers || [];
for (let index = 0; index < appList.length; index++) {
let app = appList.queryElementAt(index, Ci.nsILocalHandlerApp);
let name = app.executable.name;
let prettyName = await app.prettyNameAsync();
Assert.equal(
prettyName,
name,
"On platforms other than windows, the prettyName and the name of file handlers should be the same."
);
}
}
});

Просмотреть файл

@ -1,116 +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/. */
#include "nsLocalHandlerAppWin.h"
#include "nsString.h"
#include "nsIWindowsRegKey.h"
static nsresult GetPrettyNameFromFileDescription(
const nsCOMPtr<nsILocalFileWin>& executableOnWindows,
const nsString& assignedName, nsString& aName) {
nsresult result = NS_ERROR_FAILURE;
if (executableOnWindows) {
result = executableOnWindows->GetVersionInfoField("FileDescription", aName);
if (NS_FAILED(result) || aName.IsEmpty()) {
if (!assignedName.IsEmpty()) {
aName = assignedName;
} else {
result = executableOnWindows->GetLeafName(aName);
}
if (!aName.IsEmpty()) {
result = NS_OK;
} else {
result = NS_ERROR_FAILURE;
}
}
}
return result;
}
static nsresult GetValueFromRegistry(nsString& aName,
const nsCOMPtr<nsIWindowsRegKey>& appKey,
const nsString& registryPath,
const nsString& valueName) {
nsresult rv =
appKey->Open(nsIWindowsRegKey::ROOT_KEY_CLASSES_ROOT, registryPath,
nsIWindowsRegKey::ACCESS_QUERY_VALUE);
if (NS_SUCCEEDED(rv)) {
nsAutoString applicationName;
if (NS_SUCCEEDED(appKey->ReadStringValue(valueName, applicationName))) {
aName = applicationName;
return NS_OK;
}
}
return NS_ERROR_FAILURE;
};
std::function<nsresult(nsString&)>
nsLocalHandlerAppWin::GetPrettyNameOnNonMainThreadCallback() {
// Make a copy of executable so that we don't have to worry about any other
// threads
nsCOMPtr<nsIFile> executable;
mExecutable->Clone(getter_AddRefs(executable));
// Get the windows interface to the file
nsCOMPtr<nsILocalFileWin> executableOnWindows(do_QueryInterface(executable));
auto appIdOrName = mAppIdOrName;
auto assignedName = mName;
std::function<nsresult(nsString&)> callback =
[assignedName, appIdOrName,
executableOnWindows = std::move(executableOnWindows)](nsString& aName) {
// On all platforms, we want a human readable name for an application.
// For example: msedge -> Microsoft Edge Browser
//
// This is generated on mac directly in nsLocalHandlerAppMac::GetName.
// The auto-test coverage for GetName isn't thorough enough to be
// confident that changing GetName on Windows won't cause problems.
//
// Besides that, this is a potentially slow thing to execute, and making
// it asynchronous is preferable. There's a fallback to GetName() in the
// nsLocalHandlerApp::PrettyNameAsync to cover Mac and Linux.
if (appIdOrName.IsEmpty()) {
return GetPrettyNameFromFileDescription(executableOnWindows,
assignedName, aName);
}
nsCOMPtr<nsIWindowsRegKey> appKey =
do_CreateInstance("@mozilla.org/windows-registry-key;1");
if (!appKey) {
return GetPrettyNameFromFileDescription(executableOnWindows,
assignedName, aName);
}
// Check for ApplicationName first. Path:
// HKEY_CLASSES_ROOT\${APP_ID}\Application, Value entry: ApplicationName
nsresult rv = GetValueFromRegistry(aName, appKey,
appIdOrName + u"\\Application"_ns,
u"ApplicationName"_ns);
if (NS_SUCCEEDED(rv) && !aName.IsEmpty()) {
return rv;
}
// Check for the default on the Applications entry next.
// Path: HKEY_CLASSES_ROOT\Applications\${APP_ID}, Value entry: ""
// (default)
rv = GetValueFromRegistry(aName, appKey,
u"Applications\\"_ns + appIdOrName, u""_ns);
if (NS_SUCCEEDED(rv) && !aName.IsEmpty()) {
return rv;
}
// Fallthrough to getting the name from the file description
return GetPrettyNameFromFileDescription(executableOnWindows,
assignedName, aName);
};
return callback;
}

Просмотреть файл

@ -1,34 +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/. */
#ifndef NSLOCALHANDLERAPPWIN_H_
#define NSLOCALHANDLERAPPWIN_H_
#include "nsLocalHandlerApp.h"
#include "nsString.h"
class nsLocalHandlerAppWin : public nsLocalHandlerApp {
public:
nsLocalHandlerAppWin() {}
nsLocalHandlerAppWin(const char16_t* aName, nsIFile* aExecutable)
: nsLocalHandlerApp(aName, aExecutable) {}
nsLocalHandlerAppWin(const nsAString& aName, nsIFile* aExecutable)
: nsLocalHandlerApp(aName, aExecutable) {}
virtual ~nsLocalHandlerAppWin() {}
void SetAppIdOrName(const nsString& appIdOrName) {
mAppIdOrName = appIdOrName;
}
protected:
std::function<nsresult(nsString&)> GetPrettyNameOnNonMainThreadCallback()
override;
private:
nsString mAppIdOrName;
};
#endif /*NSLOCALHANDLERAPPMAC_H_*/

Просмотреть файл

@ -221,16 +221,6 @@ nsMIMEInfoWin::GetHasDefaultHandler(bool* _retval) {
return NS_OK;
}
NS_IMETHODIMP nsMIMEInfoWin::GetDefaultExecutable(nsIFile** aExecutable) {
nsCOMPtr<nsIFile> defaultApp = GetDefaultApplication();
if (defaultApp) {
defaultApp.forget(aExecutable);
return NS_OK;
}
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsMIMEInfoWin::GetEnumerator(nsISimpleEnumerator** _retval) {
nsCOMArray<nsIVariant> properties;
@ -564,7 +554,6 @@ bool nsMIMEInfoWin::GetProgIDVerbCommandHandler(const nsAString& appProgIDName,
// entries to lower case and stores them in the trackList array.
void nsMIMEInfoWin::ProcessPath(nsCOMPtr<nsIMutableArray>& appList,
nsTArray<nsString>& trackList,
const nsAutoString& appIdOrName,
const nsAString& appFilesystemCommand) {
nsAutoString lower(appFilesystemCommand);
ToLowerCase(lower);
@ -580,9 +569,6 @@ void nsMIMEInfoWin::ProcessPath(nsCOMPtr<nsIMutableArray>& appList,
nsCOMPtr<nsILocalHandlerApp> aApp;
if (!GetLocalHandlerApp(appFilesystemCommand, aApp)) return;
// Track the app id so that the pretty name can be determined later
(static_cast<nsLocalHandlerAppWin*>(aApp.get()))->SetAppIdOrName(appIdOrName);
// Save in our main tracking arrays
appList->AppendElement(aApp);
trackList.AppendElement(lower);
@ -687,7 +673,7 @@ nsMIMEInfoWin::GetPossibleLocalHandlers(nsIArray** _retval) {
if (GetProgIDVerbCommandHandler(appProgId, appFilesystemCommand,
false) &&
!IsPathInList(appFilesystemCommand, trackList)) {
ProcessPath(appList, trackList, appProgId, appFilesystemCommand);
ProcessPath(appList, trackList, appFilesystemCommand);
}
}
}
@ -715,7 +701,7 @@ nsMIMEInfoWin::GetPossibleLocalHandlers(nsIArray** _retval) {
false) ||
IsPathInList(appFilesystemCommand, trackList))
continue;
ProcessPath(appList, trackList, appName, appFilesystemCommand);
ProcessPath(appList, trackList, appFilesystemCommand);
}
}
regKey->Close();
@ -743,7 +729,7 @@ nsMIMEInfoWin::GetPossibleLocalHandlers(nsIArray** _retval) {
false) ||
IsPathInList(appFilesystemCommand, trackList))
continue;
ProcessPath(appList, trackList, appProgId, appFilesystemCommand);
ProcessPath(appList, trackList, appFilesystemCommand);
}
}
regKey->Close();
@ -776,7 +762,7 @@ nsMIMEInfoWin::GetPossibleLocalHandlers(nsIArray** _retval) {
false) ||
IsPathInList(appFilesystemCommand, trackList))
continue;
ProcessPath(appList, trackList, appValue, appFilesystemCommand);
ProcessPath(appList, trackList, appFilesystemCommand);
}
}
}
@ -805,7 +791,7 @@ nsMIMEInfoWin::GetPossibleLocalHandlers(nsIArray** _retval) {
false) ||
IsPathInList(appFilesystemCommand, trackList))
continue;
ProcessPath(appList, trackList, appProgId, appFilesystemCommand);
ProcessPath(appList, trackList, appFilesystemCommand);
}
}
regKey->Close();
@ -843,7 +829,7 @@ nsMIMEInfoWin::GetPossibleLocalHandlers(nsIArray** _retval) {
false) ||
IsPathInList(appFilesystemCommand, trackList))
continue;
ProcessPath(appList, trackList, appName, appFilesystemCommand);
ProcessPath(appList, trackList, appFilesystemCommand);
}
}
}
@ -871,7 +857,7 @@ nsMIMEInfoWin::GetPossibleLocalHandlers(nsIArray** _retval) {
if (!GetAppsVerbCommandHandler(appName, appFilesystemCommand, false) ||
IsPathInList(appFilesystemCommand, trackList))
continue;
ProcessPath(appList, trackList, appName, appFilesystemCommand);
ProcessPath(appList, trackList, appFilesystemCommand);
}
}
regKey->Close();
@ -896,7 +882,7 @@ nsMIMEInfoWin::GetPossibleLocalHandlers(nsIArray** _retval) {
if (!GetAppsVerbCommandHandler(appName, appFilesystemCommand, false) ||
IsPathInList(appFilesystemCommand, trackList))
continue;
ProcessPath(appList, trackList, appName, appFilesystemCommand);
ProcessPath(appList, trackList, appFilesystemCommand);
}
}
}

Просмотреть файл

@ -22,7 +22,6 @@ class nsMIMEInfoWin : public nsMIMEInfoBase, public nsIPropertyBag {
NS_IMETHOD LaunchWithFile(nsIFile* aFile) override;
NS_IMETHOD GetHasDefaultHandler(bool* _retval) override;
NS_IMETHOD GetDefaultExecutable(nsIFile** aExecutable) override;
NS_IMETHOD GetPossibleLocalHandlers(nsIArray** _retval) override;
NS_IMETHOD IsCurrentAppOSDefault(bool* _retval) override;
@ -69,7 +68,7 @@ class nsMIMEInfoWin : public nsMIMEInfoBase, public nsIPropertyBag {
// Helper routine used in tracking app lists
void ProcessPath(nsCOMPtr<nsIMutableArray>& appList,
nsTArray<nsString>& trackList, const nsAutoString& appId,
nsTArray<nsString>& trackList,
const nsAString& appFilesystemCommand);
// Helper routine to call mozilla::ShellExecuteByExplorer