Closed Bug 1818418 Opened 2 years ago Closed 1 year ago

[MSIX] Allow to use Windows UserChoice default mechanisms for MSIX packages

Categories

(Firefox :: Installer, enhancement, P3)

enhancement

Tracking

()

RESOLVED FIXED
121 Branch
Tracking Status
firefox121 --- wontfix
firefox122 --- fixed
firefox123 --- fixed

People

(Reporter: nalexander, Assigned: nrishel)

References

(Blocks 1 open bug)

Details

(Whiteboard: [fidedi-ope])

Attachments

(3 files, 4 obsolete files)

Set default by UserChoice doesn't work in MSIX packages. It would be nice if it did.

This sketches how to use reg.exe to delete and recreate the relevant
HKCU registry key-value pairs.

This needs at least three additional things:

  1. The appropriate Prog IDs need to be determined from the registry.

    In the JS console, something like the following snippet enumerates
    Prog IDs created by the MSIX installer for the given package.
    Doing this in C++ should allow to replace my hard-coded values
    present in this WIP.

  2. The WDBA needs to be taught to recognize when its run in an app
    package context and to alter its behaviour. I tested this
    outside of the app package bubble so that I could iterate
    quickly. I've not yet verified that invoking it from Firefox
    proper succeeds, although I'm pretty confident that it will.

  3. ShellService.jsm also checks that the Prog IDs exist and won't
    invoke default-browser-agent.exe from within the app package
    bubble. This might be updated as part of 2. automatically, but it
    might also need to share the registry enumeration of 1.

var testKey = Cc["@mozilla.org/windows-registry-key;1"].createInstance(Ci.nsIWindowsRegKey);

    testKey.open(
      Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
      "SOFTWARE\\Classes",
      Ci.nsIWindowsRegKey.ACCESS_ALL
    );

var winPackageFamilyName = Services.sysinfo.getProperty("winPackageFamilyName");

var [packageName, packageHash] = winPackageFamilyName.split("_");

for (var i = 0; i < testKey.childCount; i++) {
  var name = testKey.getChildName(i);
  if (name.startsWith("AppX")) {
  	var innerKey = Cc["@mozilla.org/windows-registry-key;1"].createInstance(Ci.nsIWindowsRegKey);
		try {
    innerKey.open(
      Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
      `SOFTWARE\\Classes\\${name}\\Shell\\open`,
      Ci.nsIWindowsRegKey.ACCESS_READ
    );
    var packageId = innerKey.readStringValue("PackageId");

    if (packageId.startsWith(packageName) && packageId.endsWith(packageHash)) {
      // Distinguish protocols (http, https) from file extensions (.html, .pdf).
      var contractId = innerKey.readStringValue("ContractId");

      var classKey = Cc["@mozilla.org/windows-registry-key;1"].createInstance(Ci.nsIWindowsRegKey);
      classKey.open(
          Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
          `SOFTWARE\\Classes\\${name}`,
          Ci.nsIWindowsRegKey.ACCESS_READ
      );

        try {
          protocol = "";
        var protocol = classKey.readStringValue("");
        } catch (ee) {
        }

      var commandKey = innerKey.openChild("command", Ci.nsIWindowsRegKey.ACCESS_READ);
      console.log(name, protocol, commandKey.readStringValue("DelegateExecute"));
    }
    } catch (e) {
      // console.log("error", name, e);
    }
    finally {
      innerKey.close();
    }
  }
}

Your application starts a utility to perform tasks. Avoid starting command utilities such as PowerShell and Cmd.exe. In fact, if users install your application onto a system that runs the Windows 10 S, then your application won't be able to start them at all. This could block your application from submission to the Microsoft Store because all apps submitted to the Microsoft Store must be compatible with Windows 10 S.

Starting a utility can often provide a convenient way to obtain information from the operating system, access the registry, or access system capabilities. However, you can use UWP APIs to accomplish these sorts of tasks instead. Those APIs are more performant because they don't need a separate executable to run, but more importantly, they keep the application from reaching outside of the package. The app's design stays consistent with the isolation, trust, and security that comes with an application that you've packaged, and your application will behave as expected on systems running Windows 10 S.

https://learn.microsoft.com/en-us/windows/msix/desktop/desktop-to-uwp-prepare

Looks like reaching outside of the package in this way is explicitly supported for non-S Mode packages even if it's frowned upon. Since the S Mode requirement has since been dropped from the Windows Store I think we can assume we're in the clear.

(In reply to Nick Rishel [:nrishel] from comment #2)

Looks like reaching outside of the package in this way is explicitly supported for non-S Mode packages even if it's frowned upon. Since the S Mode requirement has since been dropped from the Windows Store I think we can assume we're in the clear.

Great sleuthing!

Summary: [MSIX} Allow to use Windows UserChoice default mechanisms for MSIX packages → [MSIX] Allow to use Windows UserChoice default mechanisms for MSIX packages
Duplicate of this bug: 1736794
Priority: -- → P3
Assignee: nobody → nrishel
Status: NEW → ASSIGNED
Attachment #9321545 - Attachment is obsolete: true
Attachment #9319391 - Attachment description: WIP: Bug 1818418 - WIP on MSIX set-to-default. → Bug 1818418 - Use `reg.exe` to implement MSIX 1-click set-to-default. r=mhughes
Attachment #9361764 - Attachment is obsolete: true
Pushed by nalexander@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/e0f1fa408c70 Use `reg.exe` to implement MSIX 1-click set-to-default. r=mhughes

No need to keep this internal now that it's landed.

Group: mozilla-employee-confidential
Pushed by nalexander@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/45ab2db62a65 Use `reg.exe` to implement MSIX 1-click set-to-default. r=mhughes
Pushed by nalexander@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/c6d6218c85ae Use `reg.exe` to implement MSIX 1-click set-to-default. r=mhughes
Status: ASSIGNED → RESOLVED
Closed: 1 year ago
Resolution: --- → FIXED
Target Milestone: --- → 121 Branch

We did a spot check on the latest MSIX Nightly build in order to see if/how this works and we can confirm that MSIX build can be set as the default browser and behaves as one once it is added as default.

This approach uses reg.exe to delete and recreate the relevant HKCU
registry key-value pairs.

Original Revision: https://phabricator.services.mozilla.com/D170717

Attachment #9362488 - Flags: approval-mozilla-beta?

This approach uses reg.exe to delete and recreate the relevant HKCU
registry key-value pairs.

Original Revision: https://phabricator.services.mozilla.com/D170717

Attachment #9362489 - Flags: approval-mozilla-beta?

Uplift Approval Request

  • Needs manual QE test: yes
  • Explanation of risk level: This rearranges, but does not change, the non-MSIX functionality. QE has tested in Nightly, and there is very little difference in this functionality across release channels. Finally, failure of the 1-click set-to-default mechanism simply launches the Windows (multi-click) UI -- which is not a catastrophic outcome.
  • Fix verified in Nightly: yes
  • User impact if declined: No 1-click set-to-default in MSIX/Microsoft Store builds
  • Steps to reproduce for manual QE testing: QE is already aware of steps
  • String changes made/needed: No
  • Risk associated with taking this patch: Low
  • Code covered by automated testing: no
  • Is Android affected?: no
Flags: qe-verify+

Comment on attachment 9362488 [details]
Bug 1818418 - Use reg.exe to implement MSIX 1-click set-to-default. r=mhughes

i think this was an accidental duplicate

Attachment #9362488 - Flags: approval-mozilla-beta? → approval-mozilla-beta-
QA Whiteboard: [qa-triaged]
Flags: needinfo?(nrishel)
Attachment #9362489 - Flags: approval-mozilla-release?

Uplift Approval Request

  • Code covered by automated testing: no
  • Needs manual QE test: yes
  • String changes made/needed: No
  • Is Android affected?: no
  • User impact if declined: No 1-click set-to-default in MSIX/Microsoft Store builds
  • Fix verified in Nightly: yes
  • Steps to reproduce for manual QE testing: QE is already aware of steps
  • Explanation of risk level: his rearranges, but does not change, the non-MSIX functionality. QE has tested in Nightly, and there is very little difference in this functionality across release channels. Finally, failure of the 1-click set-to-default mechanism simply launches the Windows (multi-click) UI -- which is not a catastrophic outcome.
  • Risk associated with taking this patch: Low
Attachment #9362489 - Flags: approval-mozilla-beta?

Comment on attachment 9362489 [details]
Bug 1818418 - Use reg.exe to implement MSIX 1-click set-to-default. r=mhughes

this will ride the 121 train for now

Attachment #9362489 - Flags: approval-mozilla-release? → approval-mozilla-release-
Attachment #9362489 - Flags: approval-mozilla-release- → approval-mozilla-release?
Attachment #9362489 - Attachment is obsolete: true
Attachment #9362489 - Flags: approval-mozilla-release? → approval-mozilla-release-
Attachment #9362488 - Flags: approval-mozilla-beta- → approval-mozilla-beta?
Attachment #9362488 - Attachment is obsolete: true
Attachment #9362488 - Flags: approval-mozilla-beta? → approval-mozilla-beta-
Regressions: 1870895
No longer regressions: 1870895
No longer depends on: 1863980
Regressions: 1863980

FX 121 Release store build with the changes for this bug rolled back: ms-windows-store://pdp/?productid=9NFQ5K7N2T6C

(In reply to Michael Hughes from comment #23)

FX 121 Release store build with the changes for this bug rolled back: ms-windows-store://pdp/?productid=9NFQ5K7N2T6C

Any luck testing this?

Flags: needinfo?(bmaris)

(In reply to Ryan VanderMeulen [:RyanVM] from comment #24)

(In reply to Michael Hughes from comment #23)

FX 121 Release store build with the changes for this bug rolled back: ms-windows-store://pdp/?productid=9NFQ5K7N2T6C

Any luck testing this?

Yes, we tested this as soon as the build was available (only wrote in slack thread, sorry for that) and can confirm that using the build provided (Fx 121), 1-click set-to-default in MSIX does not work meaning that this is fixed using the build ms-windows-store://pdp/?productid=9NFQ5K7N2T6C.

Flags: needinfo?(bmaris)
No longer depends on: 1870047
See Also: → 1870047
No longer depends on: 1863977
No longer depends on: 1857490
See Also: → 1857490

:amir for tracking purposes, this was backed out in central and beta (at the time Fx123 and Fx122) see comments in https://phabricator.services.mozilla.com/D197747

For tracking purposes, you might want to reopen this?

Flags: needinfo?(ahabibi)

I am going ahead and drop the qa-verify+ flag for now since the work here is done at this time, if something changes and qa is needed again please re-add the flag.

Flags: qe-verify+
See Also: → 1882413
Flags: needinfo?(ahabibi)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: