зеркало из https://github.com/mozilla/gecko-dev.git
Backed out 4 changesets (bug 1805509, bug 1805511) for causing node newtab failures. CLOSED TREE
Backed out changeset 1c1d335d4ef5 (bug 1805509) Backed out changeset 0bf2579bccd7 (bug 1805509) Backed out changeset a87f459f2caa (bug 1805509) Backed out changeset ae16a9890f22 (bug 1805511)
This commit is contained in:
Родитель
b261ba96c8
Коммит
dcf64fc565
|
@ -1140,25 +1140,13 @@ class _ASRouter {
|
|||
* and ASRouter._getMessagesContext parameters and values
|
||||
*/
|
||||
async getTargetingParameters(environment, localContext) {
|
||||
// Resolve objects that may contain promises.
|
||||
async function resolve(object) {
|
||||
const target = {};
|
||||
|
||||
for (const param of Object.keys(object)) {
|
||||
target[param] = await object[param];
|
||||
|
||||
if (typeof target[param] === "object" && target[param] !== null) {
|
||||
target[param] = await resolve(target[param]);
|
||||
}
|
||||
}
|
||||
|
||||
return target;
|
||||
const targetingParameters = {};
|
||||
for (const param of Object.keys(environment)) {
|
||||
targetingParameters[param] = await environment[param];
|
||||
}
|
||||
for (const param of Object.keys(localContext)) {
|
||||
targetingParameters[param] = await localContext[param];
|
||||
}
|
||||
|
||||
const targetingParameters = {
|
||||
...(await resolve(environment)),
|
||||
...(await resolve(localContext)),
|
||||
};
|
||||
|
||||
return targetingParameters;
|
||||
}
|
||||
|
|
|
@ -290,26 +290,6 @@ const QueryCache = {
|
|||
FRECENT_SITES_UPDATE_INTERVAL,
|
||||
lazy.AddonManager // eslint-disable-line mozilla/valid-lazy
|
||||
),
|
||||
isDefaultHandler: {
|
||||
pdf: new CachedTargetingGetter(
|
||||
"isDefaultHandlerFor",
|
||||
[".pdf"],
|
||||
FRECENT_SITES_UPDATE_INTERVAL,
|
||||
ShellService
|
||||
),
|
||||
html: new CachedTargetingGetter(
|
||||
"isDefaultHandlerFor",
|
||||
[".html"],
|
||||
FRECENT_SITES_UPDATE_INTERVAL,
|
||||
ShellService
|
||||
),
|
||||
},
|
||||
defaultPDFHandler: new CachedTargetingGetter(
|
||||
"getDefaultPDFHandler",
|
||||
null,
|
||||
FRECENT_SITES_UPDATE_INTERVAL,
|
||||
ShellService
|
||||
),
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -837,19 +817,6 @@ const TargetingGetters = {
|
|||
let button = lazy.CustomizableUI.getWidget("firefox-view-button");
|
||||
return button.areaType;
|
||||
},
|
||||
|
||||
isDefaultHandler: {
|
||||
get html() {
|
||||
return QueryCache.getters.isDefaultHandler.html.get();
|
||||
},
|
||||
get pdf() {
|
||||
return QueryCache.getters.isDefaultHandler.pdf.get();
|
||||
},
|
||||
},
|
||||
|
||||
get defaultPDFHandler() {
|
||||
return QueryCache.getters.defaultPDFHandler.get();
|
||||
},
|
||||
};
|
||||
|
||||
const ASRouterTargeting = {
|
||||
|
@ -866,39 +833,26 @@ const ASRouterTargeting = {
|
|||
* integer.
|
||||
*/
|
||||
async getEnvironmentSnapshot(target = ASRouterTargeting.Environment) {
|
||||
async function resolveRecursive(object) {
|
||||
// One promise for each named property. Label promises with property name.
|
||||
const promises = Object.keys(object).map(async key => {
|
||||
// Each promise needs to check if we're shutting down when it is evaluated.
|
||||
if (Services.startup.shuttingDown) {
|
||||
throw new Error(
|
||||
"shutting down, so not querying targeting environment"
|
||||
);
|
||||
}
|
||||
|
||||
let value = await object[key];
|
||||
|
||||
if (typeof value === "object" && object !== null) {
|
||||
value = await resolveRecursive(value);
|
||||
}
|
||||
|
||||
return [key, value];
|
||||
});
|
||||
|
||||
const resolved = {};
|
||||
for (const result of await Promise.allSettled(promises)) {
|
||||
// Ignore properties that are rejected.
|
||||
if (result.status === "fulfilled") {
|
||||
const [key, value] = result.value;
|
||||
resolved[key] = value;
|
||||
}
|
||||
// One promise for each named property. Label promises with property name.
|
||||
let promises = Object.keys(target).map(async name => {
|
||||
// Each promise needs to check if we're shutting down when it is evaluated.
|
||||
if (Services.startup.shuttingDown) {
|
||||
throw new Error("shutting down, so not querying targeting environment");
|
||||
}
|
||||
return [name, await target[name]];
|
||||
});
|
||||
|
||||
return resolved;
|
||||
// Ignore properties that are rejected.
|
||||
let results = await Promise.allSettled(promises);
|
||||
|
||||
let environment = {};
|
||||
for (let result of results) {
|
||||
if (result.status === "fulfilled") {
|
||||
let [name, value] = result.value;
|
||||
environment[name] = value;
|
||||
}
|
||||
}
|
||||
|
||||
const environment = await resolveRecursive(target);
|
||||
|
||||
// Should we need to migrate in the future.
|
||||
const snapshot = { environment, version: 1 };
|
||||
|
||||
|
|
|
@ -20,62 +20,9 @@ add_task(async function should_ignore_rejections() {
|
|||
};
|
||||
|
||||
let snapshot = await ASRouterTargeting.getEnvironmentSnapshot(target);
|
||||
Assert.deepEqual(snapshot, { environment: { foo: 1 }, version: 1 });
|
||||
deepEqual(snapshot, { environment: { foo: 1 }, version: 1 });
|
||||
});
|
||||
|
||||
add_task(async function nested_objects() {
|
||||
const target = {
|
||||
get foo() {
|
||||
return Promise.resolve("foo");
|
||||
},
|
||||
get bar() {
|
||||
return Promise.reject(new Error("bar"));
|
||||
},
|
||||
baz: {
|
||||
get qux() {
|
||||
return Promise.resolve("qux");
|
||||
},
|
||||
get quux() {
|
||||
return Promise.reject(new Error("quux"));
|
||||
},
|
||||
get corge() {
|
||||
return {
|
||||
get grault() {
|
||||
return Promise.resolve("grault");
|
||||
},
|
||||
get garply() {
|
||||
return Promise.reject(new Error("garply"));
|
||||
},
|
||||
};
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const snapshot = await ASRouterTargeting.getEnvironmentSnapshot(target);
|
||||
|
||||
Assert.deepEqual(
|
||||
snapshot,
|
||||
{
|
||||
environment: {
|
||||
foo: "foo",
|
||||
baz: {
|
||||
qux: "qux",
|
||||
corge: {
|
||||
grault: "grault",
|
||||
},
|
||||
},
|
||||
},
|
||||
version: 1,
|
||||
},
|
||||
"getEnvironmentSnapshot should resolve nested promises"
|
||||
);
|
||||
});
|
||||
|
||||
/*
|
||||
* NB: This test is last because it manipulates shutdown phases.
|
||||
*
|
||||
* Adding tests after this one will result in failures.
|
||||
*/
|
||||
add_task(async function should_ignore_rejections() {
|
||||
// The order that `ASRouterTargeting.getEnvironmentSnapshot`
|
||||
// enumerates the target object matters here, but it's guaranteed to
|
||||
|
@ -103,5 +50,5 @@ add_task(async function should_ignore_rejections() {
|
|||
|
||||
let snapshot = await ASRouterTargeting.getEnvironmentSnapshot(target);
|
||||
// `baz` is dropped since we're shutting down by the time it's processed.
|
||||
Assert.deepEqual(snapshot, { environment: { foo: 1, bar: 2 }, version: 1 });
|
||||
deepEqual(snapshot, { environment: { foo: 1, bar: 2 }, version: 1 });
|
||||
});
|
||||
|
|
|
@ -184,41 +184,6 @@ let ShellServiceInternal = {
|
|||
return true;
|
||||
}
|
||||
|
||||
const handler = this.getDefaultPDFHandler();
|
||||
if (handler === null) {
|
||||
// We only get an exception when something went really wrong. Fail
|
||||
// safely: don't set Firefox as default PDF handler.
|
||||
lazy.log.warn(
|
||||
"Could not determine default PDF handler: not setting Firefox as " +
|
||||
"default PDF handler!"
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!handler.registered) {
|
||||
lazy.log.debug(
|
||||
"Current default PDF handler has no registered association; " +
|
||||
"should set as default PDF handler."
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (handler.knownBrowser) {
|
||||
lazy.log.debug(
|
||||
"Current default PDF handler progID matches known browser; should " +
|
||||
"set as default PDF handler."
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
lazy.log.debug(
|
||||
"Current default PDF handler progID does not match known browser " +
|
||||
"prefix; should not set as default PDF handler."
|
||||
);
|
||||
return false;
|
||||
},
|
||||
|
||||
getDefaultPDFHandler() {
|
||||
const knownBrowserPrefixes = [
|
||||
"AppXq0fevzme2pys62n3e0fbqa7peapykr8v", // Edge before Blink, per https://stackoverflow.com/a/32724723.
|
||||
"Brave", // For "BraveFile".
|
||||
|
@ -229,7 +194,6 @@ let ShellServiceInternal = {
|
|||
"Opera", // For "OperaStable", presumably varying with channel.
|
||||
"Yandex", // For "YandexPDF.IHKFKZEIOKEMR6BGF62QXCRIKM", presumably varying with installation.
|
||||
];
|
||||
|
||||
let currentProgID = "";
|
||||
try {
|
||||
// Returns the empty string when no association is registered, in
|
||||
|
@ -239,26 +203,37 @@ let ShellServiceInternal = {
|
|||
} catch (e) {
|
||||
// We only get an exception when something went really wrong. Fail
|
||||
// safely: don't set Firefox as default PDF handler.
|
||||
lazy.log.warn("Failed to queryCurrentDefaultHandlerFor:");
|
||||
return null;
|
||||
lazy.log.warn(
|
||||
"Failed to queryCurrentDefaultHandlerFor: " +
|
||||
"not setting Firefox as default PDF handler!"
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (currentProgID == "") {
|
||||
return { registered: false, knownBrowser: false };
|
||||
lazy.log.debug(
|
||||
`Current default PDF handler has no registered association; ` +
|
||||
`should set as default PDF handler.`
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
const knownBrowserPrefix = knownBrowserPrefixes.find(it =>
|
||||
let knownBrowserPrefix = knownBrowserPrefixes.find(it =>
|
||||
currentProgID.startsWith(it)
|
||||
);
|
||||
|
||||
if (knownBrowserPrefix) {
|
||||
lazy.log.debug(`Found known browser prefix: ${knownBrowserPrefix}`);
|
||||
lazy.log.debug(
|
||||
`Current default PDF handler progID matches known browser prefix: ` +
|
||||
`'${knownBrowserPrefix}'; should set as default PDF handler.`
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
return {
|
||||
registered: true,
|
||||
knownBrowser: !!knownBrowserPrefix,
|
||||
};
|
||||
lazy.log.debug(
|
||||
`Current default PDF handler progID does not match known browser prefix; ` +
|
||||
`should not set as default PDF handler.`
|
||||
);
|
||||
return false;
|
||||
},
|
||||
|
||||
/*
|
||||
|
@ -314,13 +289,40 @@ let ShellServiceInternal = {
|
|||
arguments: exeArgs,
|
||||
});
|
||||
telemetryResult = "ErrOther";
|
||||
this._handleWDBAResult(exeProcess);
|
||||
} catch (ex) {
|
||||
if (ex instanceof WDBAError) {
|
||||
telemetryResult = ex.telemetryResult;
|
||||
|
||||
// Exit codes, see toolkit/mozapps/defaultagent/SetDefaultBrowser.h
|
||||
const S_OK = 0;
|
||||
const STILL_ACTIVE = 0x103;
|
||||
const MOZ_E_NO_PROGID = 0xa0000001;
|
||||
const MOZ_E_HASH_CHECK = 0xa0000002;
|
||||
const MOZ_E_REJECTED = 0xa0000003;
|
||||
const MOZ_E_BUILD = 0xa0000004;
|
||||
|
||||
const exeWaitTimeoutMs = 2000; // 2 seconds
|
||||
const exeWaitPromise = exeProcess.wait();
|
||||
const timeoutPromise = new Promise(function(resolve, reject) {
|
||||
lazy.setTimeout(
|
||||
() => resolve({ exitCode: STILL_ACTIVE }),
|
||||
exeWaitTimeoutMs
|
||||
);
|
||||
});
|
||||
const { exitCode } = await Promise.race([exeWaitPromise, timeoutPromise]);
|
||||
|
||||
if (exitCode != S_OK) {
|
||||
telemetryResult =
|
||||
new Map([
|
||||
[STILL_ACTIVE, "ErrExeTimeout"],
|
||||
[MOZ_E_NO_PROGID, "ErrExeProgID"],
|
||||
[MOZ_E_HASH_CHECK, "ErrExeHash"],
|
||||
[MOZ_E_REJECTED, "ErrExeRejected"],
|
||||
[MOZ_E_BUILD, "ErrBuild"],
|
||||
]).get(exitCode) ?? "ErrExeOther";
|
||||
throw new Error(
|
||||
`WDBA nonzero exit code ${exitCode}: ${telemetryResult}`
|
||||
);
|
||||
}
|
||||
|
||||
throw ex;
|
||||
telemetryResult = "Success";
|
||||
} finally {
|
||||
try {
|
||||
const histogram = Services.telemetry.getHistogramById(
|
||||
|
@ -331,43 +333,6 @@ let ShellServiceInternal = {
|
|||
}
|
||||
},
|
||||
|
||||
async setAsDefaultPDFHandlerUserChoice() {
|
||||
if (AppConstants.platform != "win") {
|
||||
throw new Error("Windows-only");
|
||||
}
|
||||
|
||||
// See comment in setAsDefaultUserChoice for an explanation of why we shell
|
||||
// out to WDBA.
|
||||
let telemetryResult = "ErrOther";
|
||||
|
||||
try {
|
||||
const aumi = lazy.XreDirProvider.getInstallHash();
|
||||
const exeProcess = await this._callExternalDefaultBrowserAgent({
|
||||
arguments: [
|
||||
"set-default-extension-handlers-user-choice",
|
||||
aumi,
|
||||
".pdf",
|
||||
"FirefoxPDF",
|
||||
],
|
||||
});
|
||||
telemetryResult = "ErrOther";
|
||||
this._handleWDBAResult(exeProcess);
|
||||
} catch (ex) {
|
||||
if (ex instanceof WDBAError) {
|
||||
telemetryResult = ex.telemetryResult;
|
||||
}
|
||||
|
||||
throw ex;
|
||||
} finally {
|
||||
try {
|
||||
const histogram = Services.telemetry.getHistogramById(
|
||||
"BROWSER_SET_DEFAULT_PDF_HANDLER_USER_CHOICE_RESULT"
|
||||
);
|
||||
histogram.add(telemetryResult);
|
||||
} catch (ex) {}
|
||||
}
|
||||
},
|
||||
|
||||
// override nsIShellService.setDefaultBrowser() on the ShellService proxy.
|
||||
setDefaultBrowser(claimAllTypes, forAllUsers) {
|
||||
// On Windows 10, our best chance is to set UserChoice, so try that first.
|
||||
|
@ -422,16 +387,6 @@ let ShellServiceInternal = {
|
|||
.add(setAsDefaultError);
|
||||
},
|
||||
|
||||
setAsDefaultPDFHandler(onlyIfKnownBrowser = false) {
|
||||
if (onlyIfKnownBrowser && !this.getDefaultPDFHandler().knownBrowser) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (AppConstants.isPlatformAndVersionAtLeast("win", "10")) {
|
||||
this.setAsDefaultPDFHandlerUserChoice();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Determine if we're the default handler for the given file extension (like
|
||||
* ".pdf") or protocol (like "https"). Windows-only for now.
|
||||
|
@ -512,39 +467,6 @@ let ShellServiceInternal = {
|
|||
}
|
||||
}
|
||||
},
|
||||
|
||||
async _handleWDBAResult(exeProcess, exeWaitTimeoutMs = 2000) {
|
||||
// Exit codes, see toolkit/mozapps/defaultagent/SetDefaultBrowser.h
|
||||
const S_OK = 0;
|
||||
const STILL_ACTIVE = 0x103;
|
||||
const MOZ_E_NO_PROGID = 0xa0000001;
|
||||
const MOZ_E_HASH_CHECK = 0xa0000002;
|
||||
const MOZ_E_REJECTED = 0xa0000003;
|
||||
const MOZ_E_BUILD = 0xa0000004;
|
||||
|
||||
const exeWaitPromise = exeProcess.wait();
|
||||
const timeoutPromise = new Promise(function(resolve) {
|
||||
lazy.setTimeout(
|
||||
() => resolve({ exitCode: STILL_ACTIVE }),
|
||||
exeWaitTimeoutMs
|
||||
);
|
||||
});
|
||||
|
||||
const { exitCode } = await Promise.race([exeWaitPromise, timeoutPromise]);
|
||||
|
||||
if (exitCode != S_OK) {
|
||||
const telemetryResult =
|
||||
new Map([
|
||||
[STILL_ACTIVE, "ErrExeTimeout"],
|
||||
[MOZ_E_NO_PROGID, "ErrExeProgID"],
|
||||
[MOZ_E_HASH_CHECK, "ErrExeHash"],
|
||||
[MOZ_E_REJECTED, "ErrExeRejected"],
|
||||
[MOZ_E_BUILD, "ErrBuild"],
|
||||
]).get(exitCode) ?? "ErrExeOther";
|
||||
|
||||
throw new WDBAError(exitCode, telemetryResult);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetters(ShellServiceInternal, {
|
||||
|
@ -569,12 +491,3 @@ var ShellService = new Proxy(ShellServiceInternal, {
|
|||
return undefined;
|
||||
},
|
||||
});
|
||||
|
||||
class WDBAError extends Error {
|
||||
constructor(exitCode, telemetryResult) {
|
||||
super(`WDBA nonzero exit code ${exitCode}: ${telemetryResult}`);
|
||||
|
||||
this.exitCode = exitCode;
|
||||
this.telemetryResult = telemetryResult;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -219,71 +219,3 @@ add_task(async function remoteDisable() {
|
|||
|
||||
await doCleanup();
|
||||
});
|
||||
|
||||
add_task(async function test_setAsDefaultPDFHandler_knownBrowser() {
|
||||
const sandbox = sinon.createSandbox();
|
||||
|
||||
const aumi = XreDirProvider.getInstallHash();
|
||||
const expectedArguments = [
|
||||
"set-default-extension-handlers-user-choice",
|
||||
aumi,
|
||||
".pdf",
|
||||
"FirefoxPDF",
|
||||
];
|
||||
|
||||
try {
|
||||
const pdfHandlerResult = { registered: true, knownBrowser: true };
|
||||
sinon.stub(ShellService, "getDefaultPDFHandler").returns(pdfHandlerResult);
|
||||
|
||||
info("Testing setAsDefaultPDFHandler(true) when knownBrowser = true");
|
||||
ShellService.setAsDefaultPDFHandler(true);
|
||||
Assert.ok(
|
||||
_callExternalDefaultBrowserAgentStub.called,
|
||||
"Called default browser agent"
|
||||
);
|
||||
Assert.deepEqual(
|
||||
_callExternalDefaultBrowserAgentStub.firstCall.args,
|
||||
[{ arguments: expectedArguments }],
|
||||
"Called default browser agent with expected arguments"
|
||||
);
|
||||
_callExternalDefaultBrowserAgentStub.resetHistory();
|
||||
|
||||
info("Testing setAsDefaultPDFHandler(false) when knownBrowser = true");
|
||||
ShellService.setAsDefaultPDFHandler(false);
|
||||
Assert.ok(
|
||||
_callExternalDefaultBrowserAgentStub.called,
|
||||
"Called default browser agent"
|
||||
);
|
||||
Assert.deepEqual(
|
||||
_callExternalDefaultBrowserAgentStub.firstCall.args,
|
||||
[{ arguments: expectedArguments }],
|
||||
"Called default browser agent with expected arguments"
|
||||
);
|
||||
_callExternalDefaultBrowserAgentStub.resetHistory();
|
||||
|
||||
pdfHandlerResult.knownBrowser = false;
|
||||
|
||||
info("Testing setAsDefaultPDFHandler(true) when knownBrowser = false");
|
||||
ShellService.setAsDefaultPDFHandler(true);
|
||||
Assert.ok(
|
||||
_callExternalDefaultBrowserAgentStub.notCalled,
|
||||
"Did not call default browser agent"
|
||||
);
|
||||
_callExternalDefaultBrowserAgentStub.resetHistory();
|
||||
|
||||
info("Testing setAsDefaultPDFHandler(false) when knownBrowser = false");
|
||||
ShellService.setAsDefaultPDFHandler(false);
|
||||
Assert.ok(
|
||||
_callExternalDefaultBrowserAgentStub.called,
|
||||
"Called default browser agent"
|
||||
);
|
||||
Assert.deepEqual(
|
||||
_callExternalDefaultBrowserAgentStub.firstCall.args,
|
||||
[{ arguments: expectedArguments }],
|
||||
"Called default browser agent with expected arguments"
|
||||
);
|
||||
_callExternalDefaultBrowserAgentStub.resetHistory();
|
||||
} finally {
|
||||
sandbox.restore();
|
||||
}
|
||||
});
|
||||
|
|
|
@ -104,15 +104,6 @@ const SpecialMessageActions = {
|
|||
window.getShellService().setAsDefault();
|
||||
},
|
||||
|
||||
/**
|
||||
* Set browser as the default PDF handler.
|
||||
*
|
||||
* @param {Window} window Reference to a window object
|
||||
*/
|
||||
setDefaultPDFHandler(window, onlyIfKnownBrowser = false) {
|
||||
window.getShellService().setAsDefaultPDFHandler(onlyIfKnownBrowser);
|
||||
},
|
||||
|
||||
/**
|
||||
* Reset browser homepage and newtab to default with a certain section configuration
|
||||
*
|
||||
|
@ -314,12 +305,6 @@ const SpecialMessageActions = {
|
|||
case "SET_DEFAULT_BROWSER":
|
||||
this.setDefaultBrowser(window);
|
||||
break;
|
||||
case "SET_DEFAULT_PDF_HANDLER":
|
||||
this.setDefaultPDFHandler(
|
||||
window,
|
||||
action.data?.onlyIfKnownBrowser ?? false
|
||||
);
|
||||
break;
|
||||
case "PIN_CURRENT_TAB":
|
||||
let tab = window.gBrowser.selectedTab;
|
||||
window.gBrowser.pinTab(tab);
|
||||
|
|
|
@ -367,28 +367,6 @@
|
|||
"additionalProperties": false,
|
||||
"description": "Message action to set Firefox as default browser"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"type": {
|
||||
"type": "string",
|
||||
"enum": ["SET_DEFAULT_PDF_HANDLER"]
|
||||
},
|
||||
"data": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"onlyIfKnownBrowser": {
|
||||
"type": "boolean",
|
||||
"description": "Only set Firefox as the default PDF handler if the current PDF handler is a known browser."
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
}
|
||||
},
|
||||
"required": ["type"],
|
||||
"additionalProperties": false,
|
||||
"description": "Message action to set Firefox as the default PDF handler"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
|
|
@ -245,23 +245,10 @@ Action for pinning Firefox to the user's taskbar.
|
|||
|
||||
### `SET_DEFAULT_BROWSER`
|
||||
|
||||
Action for setting the default browser to Firefox on the user's system.
|
||||
Action for configuring the default browser to Firefox on the user's system.
|
||||
|
||||
- args: (none)
|
||||
|
||||
### `SET_DEFAULT_PDF_HANDLER`
|
||||
|
||||
Action for setting the default PDF handler to Firefox on the user's system.
|
||||
|
||||
- args:
|
||||
```ts
|
||||
{
|
||||
// Only set Firefox as the default PDF handler if the current PDF handler is a
|
||||
// known browser.
|
||||
onlyIfKnownBrowser?: boolean;
|
||||
}
|
||||
```
|
||||
|
||||
### `SHOW_SPOTLIGHT`
|
||||
|
||||
Action for opening a spotlight tab or window modal using the content passed to the dialog.
|
||||
|
|
|
@ -27,7 +27,6 @@ skip-if = os != "win"
|
|||
[browser_sma_cfrmessageprovider.js]
|
||||
[browser_sma_configure_homepage.js]
|
||||
[browser_sma_default_browser.js]
|
||||
[browser_sma_default_pdf_handler.js]
|
||||
[browser_sma_set_prefs.js]
|
||||
[browser_sma_click_element.js]
|
||||
[browser_sma_handle_multiaction.js]
|
||||
|
|
|
@ -1,92 +0,0 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
"use strict";
|
||||
|
||||
add_task(async function test_set_default_pdf_handler_no_data() {
|
||||
const sandbox = sinon.createSandbox();
|
||||
const stub = sandbox.stub();
|
||||
|
||||
await SMATestUtils.executeAndValidateAction(
|
||||
{ type: "SET_DEFAULT_PDF_HANDLER" },
|
||||
{
|
||||
ownerGlobal: {
|
||||
getShellService: () => ({
|
||||
setAsDefaultPDFHandler: stub,
|
||||
}),
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
Assert.equal(
|
||||
stub.callCount,
|
||||
1,
|
||||
"setAsDefaultPDFHandler was called by the action"
|
||||
);
|
||||
Assert.ok(
|
||||
stub.calledWithExactly(false),
|
||||
"setAsDefaultPDFHandler called with onlyIfKnownBrowser = false"
|
||||
);
|
||||
});
|
||||
|
||||
add_task(async function test_set_default_pdf_handler_data_false() {
|
||||
const sandbox = sinon.createSandbox();
|
||||
const stub = sandbox.stub();
|
||||
|
||||
await SMATestUtils.executeAndValidateAction(
|
||||
{
|
||||
type: "SET_DEFAULT_PDF_HANDLER",
|
||||
data: {
|
||||
onlyIfKnownBrowser: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
ownerGlobal: {
|
||||
getShellService: () => ({
|
||||
setAsDefaultPDFHandler: stub,
|
||||
}),
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
Assert.equal(
|
||||
stub.callCount,
|
||||
1,
|
||||
"setAsDefaultPDFHandler was called by the action"
|
||||
);
|
||||
Assert.ok(
|
||||
stub.calledWithExactly(false),
|
||||
"setAsDefaultPDFHandler called with onlyIfKnownBrowser = false"
|
||||
);
|
||||
});
|
||||
|
||||
add_task(async function test_set_default_pdf_handler_data_true() {
|
||||
const sandbox = sinon.createSandbox();
|
||||
const stub = sandbox.stub();
|
||||
|
||||
await SMATestUtils.executeAndValidateAction(
|
||||
{
|
||||
type: "SET_DEFAULT_PDF_HANDLER",
|
||||
data: {
|
||||
onlyIfKnownBrowser: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
ownerGlobal: {
|
||||
getShellService: () => ({
|
||||
setAsDefaultPDFHandler: stub,
|
||||
}),
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
Assert.equal(
|
||||
stub.callCount,
|
||||
1,
|
||||
"setAsDefaultPDFHandler was called by the action"
|
||||
);
|
||||
Assert.ok(
|
||||
stub.calledWithExactly(true),
|
||||
"setAsDefaultPDFHandler called with onlyIfKnownBrowser = true"
|
||||
);
|
||||
});
|
|
@ -12273,23 +12273,11 @@
|
|||
"releaseChannelCollection": "opt-out",
|
||||
"description": "True if the browser was unable to set Firefox as the default browser"
|
||||
},
|
||||
"BROWSER_SET_DEFAULT_PDF_HANDLER_USER_CHOICE_RESULT": {
|
||||
"record_in_processes": ["main"],
|
||||
"products": ["firefox"],
|
||||
"operating_systems": ["windows"],
|
||||
"expires_in_version": "120",
|
||||
"kind": "categorical",
|
||||
"labels": ["Success", "ErrProgID", "ErrHash", "ErrLaunchExe", "ErrExeTimeout", "ErrExeProgID", "ErrExeHash", "ErrExeRejected", "ErrExeOther", "ErrOther", "ErrBuild"],
|
||||
"releaseChannelCollection": "opt-out",
|
||||
"bug_numbers": [1805509],
|
||||
"alert_emails": ["application-update-telemetry-alerts@mozilla.com"],
|
||||
"description": "Result of each attempt to set the default browser with SetDefaultExtensionHandlersUserChoice() for pdf extension"
|
||||
},
|
||||
"BROWSER_SET_DEFAULT_USER_CHOICE_RESULT": {
|
||||
"record_in_processes": ["main"],
|
||||
"products": ["firefox"],
|
||||
"operating_systems": ["windows"],
|
||||
"expires_in_version": "118",
|
||||
"expires_in_version": "120",
|
||||
"kind": "categorical",
|
||||
"labels": ["Success", "ErrProgID", "ErrHash", "ErrLaunchExe", "ErrExeTimeout", "ErrExeProgID", "ErrExeHash", "ErrExeRejected", "ErrExeOther", "ErrOther", "ErrBuild"],
|
||||
"releaseChannelCollection": "opt-out",
|
||||
|
|
|
@ -16,28 +16,6 @@
|
|||
#include "EventLog.h"
|
||||
#include "SetDefaultBrowser.h"
|
||||
|
||||
/*
|
||||
* The implementation for setting extension handlers by writing UserChoice.
|
||||
*
|
||||
* This is used by both SetDefaultBrowserUserChoice and
|
||||
* SetDefaultExtensionHandlersUserChoice.
|
||||
*
|
||||
* @param aAumi The AUMI of the installation to set as default.
|
||||
*
|
||||
* @param aSid Current user's string SID
|
||||
*
|
||||
* @param aFileExtensions Optional null-terminated list of file association
|
||||
* pairs to set as default, like `{ L".pdf", "FirefoxPDF", nullptr }`.
|
||||
*
|
||||
* @returns S_OK All associations set and checked successfully.
|
||||
* MOZ_E_REJECTED UserChoice was set, but checking the default did not
|
||||
* return our ProgID.
|
||||
* E_FAIL Failed to set at least one association.
|
||||
*/
|
||||
static HRESULT SetDefaultExtensionHandlersUserChoiceImpl(
|
||||
const wchar_t* aAumi, const wchar_t* const aSid,
|
||||
const wchar_t* const* aFileExtensions);
|
||||
|
||||
static bool AddMillisecondsToSystemTime(SYSTEMTIME& aSystemTime,
|
||||
ULONGLONG aIncrementMS) {
|
||||
FILETIME fileTime;
|
||||
|
@ -280,86 +258,35 @@ HRESULT SetDefaultBrowserUserChoice(
|
|||
}
|
||||
}
|
||||
|
||||
if (ok) {
|
||||
HRESULT hr = SetDefaultExtensionHandlersUserChoiceImpl(
|
||||
aAumi, sid.get(), aExtraFileExtensions);
|
||||
if (hr == MOZ_E_REJECTED) {
|
||||
ok = false;
|
||||
defaultRejected = true;
|
||||
} else if (hr == E_FAIL) {
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Notify shell to refresh icons
|
||||
::SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nullptr, nullptr);
|
||||
|
||||
if (!ok) {
|
||||
LOG_ERROR_MESSAGE(L"Failed setting default with %s", aAumi);
|
||||
if (defaultRejected) {
|
||||
return MOZ_E_REJECTED;
|
||||
}
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT SetDefaultExtensionHandlersUserChoice(
|
||||
const wchar_t* aAumi, const wchar_t* const* aFileExtensions) {
|
||||
auto sid = GetCurrentUserStringSid();
|
||||
if (!sid) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
bool ok = true;
|
||||
bool defaultRejected = false;
|
||||
|
||||
HRESULT hr = SetDefaultExtensionHandlersUserChoiceImpl(aAumi, sid.get(),
|
||||
aFileExtensions);
|
||||
if (hr == MOZ_E_REJECTED) {
|
||||
ok = false;
|
||||
defaultRejected = true;
|
||||
} else if (hr == E_FAIL) {
|
||||
ok = false;
|
||||
}
|
||||
|
||||
// Notify shell to refresh icons
|
||||
::SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nullptr, nullptr);
|
||||
|
||||
if (!ok) {
|
||||
LOG_ERROR_MESSAGE(L"Failed setting default with %s", aAumi);
|
||||
if (defaultRejected) {
|
||||
return MOZ_E_REJECTED;
|
||||
}
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT SetDefaultExtensionHandlersUserChoiceImpl(
|
||||
const wchar_t* aAumi, const wchar_t* const aSid,
|
||||
const wchar_t* const* aFileExtensions) {
|
||||
const wchar_t* const* extraFileExtension = aFileExtensions;
|
||||
const wchar_t* const* extraProgIDRoot = aFileExtensions + 1;
|
||||
while (extraFileExtension && *extraFileExtension && extraProgIDRoot &&
|
||||
const wchar_t* const* extraFileExtension = aExtraFileExtensions;
|
||||
const wchar_t* const* extraProgIDRoot = aExtraFileExtensions + 1;
|
||||
while (ok && extraFileExtension && *extraFileExtension && extraProgIDRoot &&
|
||||
*extraProgIDRoot) {
|
||||
// Formatting the ProgID here prevents using this helper to target arbitrary
|
||||
// ProgIDs.
|
||||
auto extraProgID = FormatProgID(*extraProgIDRoot, aAumi);
|
||||
|
||||
if (!SetUserChoice(*extraFileExtension, aSid, extraProgID.get())) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
if (!VerifyUserDefault(*extraFileExtension, extraProgID.get())) {
|
||||
return MOZ_E_REJECTED;
|
||||
if (!SetUserChoice(*extraFileExtension, sid.get(), extraProgID.get())) {
|
||||
ok = false;
|
||||
} else if (!VerifyUserDefault(*extraFileExtension, extraProgID.get())) {
|
||||
defaultRejected = true;
|
||||
ok = false;
|
||||
}
|
||||
|
||||
extraFileExtension += 2;
|
||||
extraProgIDRoot += 2;
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
// Notify shell to refresh icons
|
||||
::SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nullptr, nullptr);
|
||||
|
||||
if (!ok) {
|
||||
LOG_ERROR_MESSAGE(L"Failed setting default with %s", aAumi);
|
||||
if (defaultRejected) {
|
||||
return MOZ_E_REJECTED;
|
||||
}
|
||||
return E_FAIL;
|
||||
} else {
|
||||
return S_OK;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,23 +34,6 @@
|
|||
HRESULT SetDefaultBrowserUserChoice(
|
||||
const wchar_t* aAumi, const wchar_t* const* aExtraFileExtensions = nullptr);
|
||||
|
||||
/*
|
||||
* Set the default extension handlers for the given file extensions by writing
|
||||
* the UserChoice registry keys.
|
||||
*
|
||||
* @param aAumi The AUMI of the installation to set as default.
|
||||
*
|
||||
* @param aFileExtensions Optional null-terminated list of file association
|
||||
* pairs to set as default, like `{ L".pdf", "FirefoxPDF", nullptr }`.
|
||||
*
|
||||
* @returns S_OK All associations set and checked successfully.
|
||||
* MOZ_E_REJECTED UserChoice was set, but checking the default did not
|
||||
* return our ProgID.
|
||||
* E_FAIL Failed to set at least one association.
|
||||
*/
|
||||
HRESULT SetDefaultExtensionHandlersUserChoice(
|
||||
const wchar_t* aAumi, const wchar_t* const* aFileExtensions = nullptr);
|
||||
|
||||
/*
|
||||
* Additional HRESULT error codes from SetDefaultBrowserUserChoice
|
||||
*
|
||||
|
|
|
@ -408,14 +408,6 @@ int wmain(int argc, wchar_t** argv) {
|
|||
// `argv` is itself null-terminated, so we can safely pass the tail of the
|
||||
// array here.
|
||||
return SetDefaultBrowserUserChoice(argv[2], &argv[3]);
|
||||
} else if (!wcscmp(argv[1], L"set-default-extension-handlers-user-choice")) {
|
||||
if (argc < 3 || !argv[2]) {
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
|
||||
// `argv` is itself null-terminated, so we can safely pass the tail of the
|
||||
// array here.
|
||||
return SetDefaultExtensionHandlersUserChoice(argv[2], &argv[3]);
|
||||
} else {
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче