Set As Desktop Background fails on macOS
Categories
(Core :: Widget: Cocoa, defect, P2)
Tracking
()
Tracking | Status | |
---|---|---|
firefox77 | --- | verified |
People
(Reporter: mozilla, Assigned: haik)
References
Details
Attachments
(4 files, 1 obsolete file)
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:75.0) Gecko/20100101 Firefox/75.0
Steps to reproduce:
Visited an image: (example https://i.ytimg.com/vi/SuQvqaky68w/maxresdefault.jpg)
Right-clicked on image. A context menu appeared
Selected "Set As Desktop Background..." from the context menu. A dialog appeared with a preview and a "Set Desktop Background" button
Clicked "Set Desktop Background" button.
Actual results:
After a few seconds the button text changes to "Open Desktop Preferences".
The macOS Console app displays this error:
Finder (AE)
Subsystem: com.apple.appleevents Category: main
Since sending application [sess=100087 pid=5856 uid:502,502,502 g:20,20 pV:15716] is not permitted to send this AppleEvent to this process, returning an errAEEventNotPermitted reply.
If I click on the Open System Preferences button, it dumps me into System Preferences with no obvious way to use the image I was looking at.
Expected results:
The desktop background should have been set.
If it is impossible to set the background, Firefox should do something more helpful. For example, download the image, show an explanatory message about how to set the background from Finder, and then open a Finder window with the downloaded image.
Reporter | ||
Comment 1•5 years ago
|
||
I reproduced this both on macOS Mojave (macOS 10.14.5), and Catalina (macOS 10.15.3).
Comment 2•5 years ago
|
||
Bugbug thinks this bug should belong to this component, but please revert this change in case of error.
Comment 3•5 years ago
|
||
Possibly sandboxing-related?
Assignee | ||
Comment 4•5 years ago
|
||
Thanks for the report. The provided Console.app output indicates we need to add back the Apple Event entitlement com.apple.security.automation.apple-events
to the hardened runtime entitlement list to allow this to work. Taking the bug.
Assignee | ||
Comment 5•5 years ago
|
||
With the apple event entitlement, setting the desktop background works again. The user has to click through a dialog allowing Firefox to control Finder. For Firefox, it would appear as
"Firefox.app" wants to control "Finder.app". Allowing control will provide access to documents and data in "Finder.app", and to perform actions within that app.
Still looking into how this might be improved.
Assignee | ||
Comment 6•5 years ago
|
||
Assignee | ||
Comment 7•5 years ago
|
||
The NSWorkspace setDesktopImageURL[1] API allows the desktop background to be set and doesn't depend on the AppleEvents entitlement. I confirmed this on 10.15. I'll work on a patch replacing the current AppleEvent-based implementation with setDesktopImageURL. With this approach, we won't have to add an entitlement and users won't have to allow Firefox to control Finder via the dialog in comment 6.
At the time this code was written, the setDesktopImageURL API wasn't available on all supported macOS versions.
Assignee | ||
Updated•5 years ago
|
Comment 8•5 years ago
|
||
Resetting severity to default of --
.
Assignee | ||
Comment 9•5 years ago
|
||
While working on the fix, I noticed that nsMacShellService::OnStateChange() is called twice with aStateFlags containing STATE_STOP and therefore we try to set the desktop background twice. For a successful download, the OnStateChange() method is called a total of three times in my testing with the following flags.
1: aStateFlags = 327681:
STATE_START
STATE_IS_REQUEST
STATE_IS_NETWORK
STATE_IS_BROKEN
STATE_CERT_DISTRUST_IMMINENT
STATE_COOKIES_LOADED_TRACKER
STATE_BLOCKED_SOCIALTRACKING_CONTENT
2: aStateFlags = 327696:
STATE_STOP
STATE_IS_REQUEST
STATE_IS_NETWORK
STATE_BLOCKED_MIXED_ACTIVE_CONTENT
STATE_CERT_DISTRUST_IMMINENT
STATE_COOKIES_LOADED_TRACKER
STATE_BLOCKED_SOCIALTRACKING_CONTENT
3: aStateFlags = 262160:
STATE_STOP
STATE_IS_NETWORK
STATE_BLOCKED_MIXED_ACTIVE_CONTENT
STATE_COOKIES_LOADED_TRACKER
I'll fix the flags check in OnStateChange() to address this.
Assignee | ||
Comment 10•5 years ago
|
||
Change the nsMacShellService::SetDesktopBackground() implementation (specifically code in the OnStateChange handler) to use the Apple setDesktopImageURL API instead of Apple Events to allow the "Set As Desktop Background..." context menu option to work again.
Alternatively, to allow the AppleEvent-base implementation to work again, Firefox could be signed with the com.apple.security.automation.apple-events entitlement but this would also require the user to grant Firefox permission to control Finder. setDesktopImageURL requires Mac OS 10.6 or newer and hence was not an option originally.
The implementation only changes the background of the focused screen in the current workspace (which matches the behavior of Safari).
Assignee | ||
Comment 11•5 years ago
|
||
In addition to STATE_STOP, check for STATE_IS_REQUEST in the OnStateChange() state flags so that we only attempt to set the background image once.
Depends on D71426
Assignee | ||
Comment 12•5 years ago
|
||
These are the OnStateChange stack traces collected when setting the desktop background image using the "Set As Background Image..." right click option. Patch 2 changes the check in OnStateChange to fix a bug where the desktop background is set twice because OnStateChange is called twice with the STATE_STOP flag.
Comment 13•5 years ago
|
||
Comment 14•5 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/a0be8f02af46
https://hg.mozilla.org/mozilla-central/rev/8cd0c560c328
Comment 15•5 years ago
|
||
Confirmed issue with 77.0a1 (2020-04-11) on macOS 10.15.3.
Fix verified with 77.0b3.
Description
•