Closed Bug 1629313 Opened 5 years ago Closed 5 years ago

Set As Desktop Background fails on macOS

Categories

(Core :: Widget: Cocoa, defect, P2)

75 Branch
defect

Tracking

()

VERIFIED FIXED
mozilla77
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.

I reproduced this both on macOS Mojave (macOS 10.14.5), and Catalina (macOS 10.15.3).

Bugbug thinks this bug should belong to this component, but please revert this change in case of error.

Component: Untriaged → Widget: Cocoa
Product: Firefox → Core

Possibly sandboxing-related?

Flags: needinfo?(haftandilian)
Priority: -- → P2

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: nobody → haftandilian
See Also: → 1570581, 1576733

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.

Flags: needinfo?(haftandilian)

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.

  1. https://developer.apple.com/documentation/appkit/nsworkspace/1527228-setdesktopimageurl?language=objc
Attachment #9140887 - Attachment is obsolete: true

Resetting severity to default of --.

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.

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).

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

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.

Pushed by haftandilian@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/a0be8f02af46 Part 1 - Set As Desktop Background fails on macOS r=spohl https://hg.mozilla.org/integration/autoland/rev/8cd0c560c328 Part 2 - Avoid setting the desktop background twice for each request on Mac r=smaug
See Also: → 1549046
Status: UNCONFIRMED → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla77

Confirmed issue with 77.0a1 (2020-04-11) on macOS 10.15.3.
Fix verified with 77.0b3.

Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: