Backed out 2 changesets (bug 1801954, bug 1863980) for bc failures on browser_setDefaultBrowser.js. CLOSED TREE

Backed out changeset b96506a6d950 (bug 1801954)
Backed out changeset 306a649fcc00 (bug 1863980)
This commit is contained in:
Cosmin Sabou
2023-12-01 02:34:26 +02:00
parent 04a658d456
commit e276c6b6b9
8 changed files with 24 additions and 46 deletions

View File

@@ -613,13 +613,7 @@ nsBrowserContentHandler.prototype = {
} }
} }
if (cmdLine.handleFlag("setDefaultBrowser", false)) { if (cmdLine.handleFlag("setDefaultBrowser", false)) {
// Note that setDefaultBrowser is an async function, but "handle" (the method being executed) lazy.ShellService.setDefaultBrowser(true);
// is an implementation of an interface method and changing it to be async would be complicated
// and ultimately nothing here needs the result of setDefaultBrowser, so we do not bother doing
// an await.
lazy.ShellService.setDefaultBrowser(true).catch(e => {
console.error("setDefaultBrowser failed:", e);
});
} }
if (cmdLine.handleFlag("first-startup", false)) { if (cmdLine.handleFlag("first-startup", false)) {

View File

@@ -5488,12 +5488,7 @@ export var DefaultBrowserCheck = {
let buttonNumClicked = rv.get("buttonNumClicked"); let buttonNumClicked = rv.get("buttonNumClicked");
let checkboxState = rv.get("checked"); let checkboxState = rv.get("checked");
if (buttonNumClicked == 0) { if (buttonNumClicked == 0) {
try { shellService.setAsDefault();
await shellService.setAsDefault();
} catch (e) {
this.log.error("Failed to set the default browser", e);
}
shellService.pinToTaskbar(); shellService.pinToTaskbar();
} }
if (checkboxState) { if (checkboxState) {

View File

@@ -1734,7 +1734,7 @@ var gMainPane = {
/** /**
* Set browser as the operating system default browser. * Set browser as the operating system default browser.
*/ */
async setDefaultBrowser() { setDefaultBrowser() {
if (AppConstants.HAVE_SHELL_SERVICE) { if (AppConstants.HAVE_SHELL_SERVICE) {
let alwaysCheckPref = Preferences.get( let alwaysCheckPref = Preferences.get(
"browser.shell.checkDefaultBrowser" "browser.shell.checkDefaultBrowser"
@@ -1748,20 +1748,11 @@ var gMainPane = {
if (!shellSvc) { if (!shellSvc) {
return; return;
} }
// Disable the set default button, so that the user doesn't try to hit it again
// while awaiting on setDefaultBrowser
let setDefaultButton = document.getElementById("setDefaultButton");
setDefaultButton.disabled = true;
try { try {
await shellSvc.setDefaultBrowser(false); shellSvc.setDefaultBrowser(false);
} catch (ex) { } catch (ex) {
console.error(ex); console.error(ex);
return; return;
} finally {
// Make sure to re-enable the default button when we're finished, regardless of the outcome
setDefaultButton.disabled = false;
} }
let isDefault = shellSvc.isDefaultBrowser(false, true); let isDefault = shellSvc.isDefaultBrowser(false, true);

View File

@@ -164,7 +164,7 @@ async function test_with_mock_shellservice(options, testFn) {
isDefaultBrowser() { isDefaultBrowser() {
return this._isDefault; return this._isDefault;
}, },
async setDefaultBrowser() { setDefaultBrowser() {
this._isDefault = true; this._isDefault = true;
}, },
}; };

View File

@@ -253,7 +253,7 @@ let ShellServiceInternal = {
} }
} }
try { try {
await this.defaultAgent.setDefaultBrowserUserChoiceAsync( this.defaultAgent.setDefaultBrowserUserChoice(
aumi, aumi,
extraFileExtensions extraFileExtensions
); );
@@ -314,7 +314,7 @@ let ShellServiceInternal = {
}, },
// override nsIShellService.setDefaultBrowser() on the ShellService proxy. // override nsIShellService.setDefaultBrowser() on the ShellService proxy.
async setDefaultBrowser(forAllUsers) { setDefaultBrowser(forAllUsers) {
// On Windows, our best chance is to set UserChoice, so try that first. // On Windows, our best chance is to set UserChoice, so try that first.
if ( if (
AppConstants.platform == "win" && AppConstants.platform == "win" &&
@@ -322,26 +322,24 @@ let ShellServiceInternal = {
"setDefaultBrowserUserChoice" "setDefaultBrowserUserChoice"
) )
) { ) {
try { // nsWindowsShellService::SetDefaultBrowser() kicks off several
await this.setAsDefaultUserChoice(); // operations, but doesn't wait for their result. So we don't need to
return; // await the result of setAsDefaultUserChoice() here, either, we just need
} catch (err) { // to fall back in case it fails.
lazy.log.warn( this.setAsDefaultUserChoice().catch(err => {
"Error thrown during setAsDefaultUserChoice. Full exception:", console.error(err);
err this.shellService.setDefaultBrowser(forAllUsers);
); });
return;
// intentionally fall through to setting via the non-user choice pathway on error
}
} }
this.shellService.setDefaultBrowser(forAllUsers); this.shellService.setDefaultBrowser(forAllUsers);
}, },
async setAsDefault() { setAsDefault() {
let setAsDefaultError = false; let setAsDefaultError = false;
try { try {
await ShellService.setDefaultBrowser(false); ShellService.setDefaultBrowser(false);
} catch (ex) { } catch (ex) {
setAsDefaultError = true; setAsDefaultError = true;
console.error(ex); console.error(ex);

View File

@@ -1666,7 +1666,7 @@ export var UITour = {
try { try {
let shell = aWindow.getShellService(); let shell = aWindow.getShellService();
if (shell) { if (shell) {
await shell.setDefaultBrowser(false); shell.setDefaultBrowser(false);
} }
} catch (e) {} } catch (e) {}
break; break;

View File

@@ -97,8 +97,8 @@ export const SpecialMessageActions = {
* *
* @param {Window} window Reference to a window object * @param {Window} window Reference to a window object
*/ */
async setDefaultBrowser(window) { setDefaultBrowser(window) {
await window.getShellService().setAsDefault(); window.getShellService().setAsDefault();
}, },
/** /**
@@ -442,10 +442,10 @@ export const SpecialMessageActions = {
break; break;
case "PIN_AND_DEFAULT": case "PIN_AND_DEFAULT":
await this.pinFirefoxToTaskbar(window, action.data?.privatePin); await this.pinFirefoxToTaskbar(window, action.data?.privatePin);
await this.setDefaultBrowser(window); this.setDefaultBrowser(window);
break; break;
case "SET_DEFAULT_BROWSER": case "SET_DEFAULT_BROWSER":
await this.setDefaultBrowser(window); this.setDefaultBrowser(window);
break; break;
case "SET_DEFAULT_PDF_HANDLER": case "SET_DEFAULT_PDF_HANDLER":
this.setDefaultPDFHandler( this.setDefaultPDFHandler(

View File

@@ -7,7 +7,7 @@
#define DEFAULT_BROWSER_SET_DEFAULT_BROWSER_H__ #define DEFAULT_BROWSER_SET_DEFAULT_BROWSER_H__
#include "nsStringFwd.h" #include "nsStringFwd.h"
#include "nsArray.h" #include "nsTArrayForwardDeclare.h"
#include <functional> #include <functional>
namespace mozilla::default_agent { namespace mozilla::default_agent {