Closed Bug 1467695 Opened 6 years ago Closed 6 years ago

System theme is not applied in the browser when enabled while a static theme is active

Categories

(WebExtensions :: Themes, defect, P2)

62 Branch
defect

Tracking

(firefox-esr52 unaffected, firefox-esr60 unaffected, firefox61 unaffected, firefox62 verified, firefox63 verified)

VERIFIED FIXED
mozilla63
Tracking Status
firefox-esr52 --- unaffected
firefox-esr60 --- unaffected
firefox61 --- unaffected
firefox62 --- verified
firefox63 --- verified

People

(Reporter: LexaSV, Assigned: kmag)

References

Details

(Keywords: regression)

Attachments

(3 files)

Attached image default auto.gif
[Affected versions]:
- Firefox 62.0a1(20180607220114)

[Affected Platforms]:
- Windows 10x64


[Steps to reproduce]:
1. Log in to AMO-dev
2. Go to a static theme details page and install it (i.e. https://addons-dev.allizom.org/en-US/firefox/addon/pattern-for-st-11/)
3. Go to about:addons - Themes - and look at the list of available themes
4. With the static theme still being your active theme, click on 'Enable' for a system theme (i.e. Dark)
5. Check the theme applied in the browser

[Expected results]:
The Dark theme is applied in the browser

[Actual results]:
The Default theme is applied in the browser

Notes:
Reproduced only when enabling a predefined system theme (i.e Light or Dark) while a static theme is active
This is due to theme code that applies an "empty" theme when a theme is uninstalled:
https://searchfox.org/mozilla-central/rev/c621276fbdd9591f52009042d959b9e19b66d49f/toolkit/components/extensions/parent/ext-theme.js#321-323

This code used to run synchronously during the switch from a static theme to a LWT, but in bug 1461146 enabling and disabling became asynchronous so this code can accidentally run after the new theme has been applied.

Jared, you originally wrote that unload() code.  Since we have the invariant that exactly one theme is always active, a theme can only be disabled when another one is being simultaneously enabled.  If we agree that the new theme just takes over and the old one doesn't have to do any cleanup, our lives will be much simpler.  The alternative is to fix the theme update plumbing to fully wait for the old theme to disable before enabling the new one, but that code is still pretty hairy as a legacy of the days of complete themes.  I'd certainly prefer the first option.  Am I overlooking some reason that wouldn't work?
Component: Add-ons Manager → WebExtensions: Themes
Flags: needinfo?(jaws)
Comment on attachment 8984564 [details]
Bug 1467695: Wait for async disable operations to finish when calling addonChanged listeners.

https://reviewboard.mozilla.org/r/250440/#review257656

::: toolkit/mozapps/extensions/AddonManager.jsm:1536
(Diff revision 1)
> +      if (result) {
> +        await result;
> +      }

do you need the if?  i thought await on a primitive value like null or undefined was effectively a no-op
Attachment #8984564 - Flags: review?(aswan) → review+
Comment on attachment 8984564 [details]
Bug 1467695: Wait for async disable operations to finish when calling addonChanged listeners.

https://reviewboard.mozilla.org/r/250440/#review257656

> do you need the if?  i thought await on a primitive value like null or undefined was effectively a no-op

Calling `await` always makes a trip through the microtask queue. If the value you `await` isn't a promise, it just gets passed through `Promise.resolve` and turned into one:

    js> async function meh() { print("a"); await null; print("b"); } meh(); print("c");
    a
    c
    b

It *probably* doesn't make a difference in this case, but this way is less risky.
(In reply to Andrew Swan [:aswan] (on PTO until 6/25) from comment #1)
> This is due to theme code that applies an "empty" theme when a theme is
> uninstalled:
> https://searchfox.org/mozilla-central/rev/
> c621276fbdd9591f52009042d959b9e19b66d49f/toolkit/components/extensions/
> parent/ext-theme.js#321-323
> 
> This code used to run synchronously during the switch from a static theme to
> a LWT, but in bug 1461146 enabling and disabling became asynchronous so this
> code can accidentally run after the new theme has been applied.
> 
> Jared, you originally wrote that unload() code.  Since we have the invariant
> that exactly one theme is always active, a theme can only be disabled when
> another one is being simultaneously enabled.  If we agree that the new theme
> just takes over and the old one doesn't have to do any cleanup, our lives
> will be much simpler.  The alternative is to fix the theme update plumbing
> to fully wait for the old theme to disable before enabling the new one, but
> that code is still pretty hairy as a legacy of the days of complete themes. 
> I'd certainly prefer the first option.  Am I overlooking some reason that
> wouldn't work?

I'm not sure how the timing will work for themes that have background scripts. That might be the only thing to be concerned about. If we can rule that out then I think the first option would work.
Flags: needinfo?(jaws)
Product: Toolkit → WebExtensions
Priority: -- → P2
Kris, is this patch in a state ready to land?
Flags: needinfo?(kmaglione+bmo)
Yup, sorry. I have too many balls in the air right now...
Assignee: nobody → kmaglione+bmo
Flags: needinfo?(kmaglione+bmo)
https://hg.mozilla.org/integration/mozilla-inbound/rev/46e5404ad50cf39cfe8b10bbd9c45b4325d95d6e
Bug 1467695: Wait for async disable operations to finish when calling addonChanged listeners. r=aswan
Backed out for failing browser chrome at browser/base/content/test/general/browser_compacttheme.js and xpcshell at toolkit/mozapps/extensions/test/xpcshell/test_LightweightThemeManager.js

Push that caused the failures: https://treeherder.mozilla.org/#/jobs?repo=mozilla-inbound&revision=46e5404ad50cf39cfe8b10bbd9c45b4325d95d6e

Failure logs: bc: https://treeherder.mozilla.org/logviewer.html#?job_id=185279189&repo=mozilla-inbound&lineNumber=1950
xpcshell: https://treeherder.mozilla.org/logviewer.html#?job_id=185279452&repo=mozilla-inbound&lineNumber=1877

Backout: https://hg.mozilla.org/integration/mozilla-inbound/rev/efa8bcee4bdf153e9b9393e633e55c800a0f41d5
Flags: needinfo?(kmaglione+bmo)
https://hg.mozilla.org/integration/mozilla-inbound/rev/c0ebdd0be6ba6f9748690d0ae5479977e2ea54bb
Bug 1467695: Wait for async disable operations to finish when calling addonChanged listeners. r=aswan
https://hg.mozilla.org/integration/mozilla-inbound/rev/510b02c8eb4c30437fd06058a6d46b827f0f1d78
Bug 1467695: Wait for async disable operations to finish when calling addonChanged listeners. r=aswan
https://hg.mozilla.org/mozilla-central/rev/510b02c8eb4c
Status: NEW → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla63
Verified fixed with Nightly 63.0a1 (Build ID 20180629100106) Windows 10x64
Status: RESOLVED → VERIFIED
Hi Kris, are you considering having this patch uplifted to 62 beta or can I change the tracking flag for Firefox 62 from affected to wontfix and let it ride the trains?

Thanks
If this is an edge case it might be better to let this ride with 63. Mike, what do you think?
Flags: needinfo?(mdeboer)
This patch looks low-risk to me and fixes a regression in 62 - so I'd take it if Andrew and/ or Kris agrees.
Blocks: 1461146
Flags: needinfo?(mdeboer) → needinfo?(aswan)
I agree this is low risk.  I'm pretty sure this patch doesn't depend on any other patches that aren't in 62, but it would be good for Kris to confirm that.
Flags: needinfo?(aswan)
Flags: needinfo?(kmaglione+bmo)
Flags: needinfo?(kmaglione+bmo)
Comment on attachment 8984564 [details]
Bug 1467695: Wait for async disable operations to finish when calling addonChanged listeners.

Approval Request Comment
[Feature/Bug causing the regression]: Bug 1461146
[User impact if declined]: This prevents users from switching between WebExtension themes and lightweight themes such as the built-in compact and dark themes.
[Is this code covered by automated tests?]: Yes
[Has the fix been verified in Nightly?]: Yes
[Needs manual test from QE? If yes, steps to reproduce]: No
[List of other uplifts needed for the feature/fix]: None
[Is the change risky?]: No
[Why is the change risky/not risky?]: It's a pretty trivial change that just waits for async operations to finish before starting operations which conflict with them.
[String changes made/needed]: None
Flags: needinfo?(kmaglione+bmo)
Attachment #8984564 - Flags: approval-mozilla-beta?
Comment on attachment 8984564 [details]
Bug 1467695: Wait for async disable operations to finish when calling addonChanged listeners.

Fix for regression in 62, sounds low risk from several developers' judgement. Let's uplift for beta 16.
Attachment #8984564 - Flags: approval-mozilla-beta? → approval-mozilla-beta+
Verified fixed in Beta 62.0b20 (20180823143155) with Win10x64 and macOS High Sierra 10.13.2
Depends on: 1487525
Depends on: 1494014
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: