-
Notifications
You must be signed in to change notification settings - Fork 15.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add app.getApplicationNameForProtocol API #20399
feat: add app.getApplicationNameForProtocol API #20399
Conversation
Also ensure we allow blocking calls here to avoid errant DCHECKing.
base::ScopedCFTypeRef<CFURLRef> openingApp(LSCopyDefaultApplicationURLForURL( | ||
(CFURLRef)ns_url, kLSRolesAll, out_err.InitializeInto())); | ||
if (out_err) { | ||
// likely kLSApplicationNotFoundErr |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's LOG(ERROR)
this error here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is copied verbatim from Chromium, and I think there's some value in maintaining that. If you think the log here is worth that loss, I'm happy to add it. Let me know.
I am not sure if this API belongs to the app module, it does not operate on the current application instance. What about moving it to |
Co-Authored-By: Shelley Vohr <codebytere@github.com>
…ctron into ajm-get-app-name-for-protocol
I can see your point, and in a vacuum, I agree, it seems like this new API would be a better fit for |
Hello fine reviewers: any more thoughts on my comments? Happy to discuss further if you disagree! |
Sorry should have @codebytere and @miniak in the last comment ^ 🙇 |
@codebytere, @miniak any comments on this? I'd like to land it, but am happy to discuss further changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation looks solid to me.
I agree this API should be grouped together with other protocol APIs. We should probably move protocol APIs from app
to systemPreferences
as these APIs are more about changing system settings instead of changing things about the app itself. But for now I'm good keeping this API in app
.
@zcbenz would you be OK with landing this, or would you prefer to wait for @codebytere and @miniak's approval? |
If no opposition I would like to land this. @ajmacd Do you mind rebasing this branch on master as there is conflict? |
I actually chatted quickly with @codebytere about this today. She mentioned wanting to bring it up at the API working group meeting. |
…for-protocol Conflicts: shell/browser/browser_linux.cc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved on behalf of the API WG!
@ajmacd this needs a final conflict fix:
|
@codebytere I think we're good to go here. The build-linux failure is unrelated to this change. |
Release Notes Persisted
|
Approved by the Releases WG for backport to 8-x-y |
/trop run backport-to 8-x-y |
The backport process for this PR has been manually initiated - |
I was unable to backport this PR to "8-x-y" cleanly; |
* Add GetApplicationNameForProtocol. * Fix Windows implementation. * Fix up test. * Add documentation. * Implement for real on Linux using xdg-mime. Also ensure we allow blocking calls here to avoid errant DCHECKing. * Improve docs for Linux. * Clean up tests. * Add a note about not relying on the precise format. * Update docs/api/app.md Co-Authored-By: Shelley Vohr <codebytere@github.com> * Remove needless `done()`s from tests. * Use vector list initialization. * Add a simple test for isDefaultProtocolClient. * Remove unneeded include and skip a test on Linux CI. * We no longer differentiate between CI and non-CI test runs.
* Add GetApplicationNameForProtocol. * Fix Windows implementation. * Fix up test. * Add documentation. * Implement for real on Linux using xdg-mime. Also ensure we allow blocking calls here to avoid errant DCHECKing. * Improve docs for Linux. * Clean up tests. * Add a note about not relying on the precise format. * Update docs/api/app.md Co-Authored-By: Shelley Vohr <codebytere@github.com> * Remove needless `done()`s from tests. * Use vector list initialization. * Add a simple test for isDefaultProtocolClient. * Remove unneeded include and skip a test on Linux CI. * We no longer differentiate between CI and non-CI test runs.
Description of Change
This API returns the name of the application registered as the default handler for a protocol (e.g.
irc://
). We're going to use this functionality in Slack to enable a "native app linking" feature, whereby Slack apps will optionally provide URLs to native applications alongside http URLs, which we'll attempt to launch if the correct native application is installed on the user's machine.It fits well with the other protocol functionality provided by the
Browser
class.GetApplicationNameForUrl
is an existing method in Chromium:https://chromium.googlesource.com/chromium/src/+/ed716f08f330dda84f38b7f40f3e381cd6af571a/chrome/browser/shell_integration.h#65
and my initial attempt was simply to call down to it. Sadly, this would appear to require depending on the entire
//chrome/browser
module, which brings in something like a highly undesirable 3k files. Instead I copied the implementations out to Electron, which again is consistent with some of the other methods having similar or identical implementations in Chromium:SetAsDefaultProtocolClient
IsDefaultProtocolClient
The Chromium Linux implementation is fairly useless, simply returning
"xdg-open"
:https://chromium.googlesource.com/chromium/src/+/eaa08411bd1f60a4e9d4b3253ba4710ae05bff3c/chrome/browser/shell_integration_linux.cc#720
but I discovered a useful implementation relying on
xdg-mime
wasn't all that hard. I'd like to upstream this to Chromium later. (Again, we won't be relying on that implementation, but just to share the spoils as it were.) This also avoids someDCHECK
s I hit around disallowed blocking calls on Linux, in both the new and existing functionality.Checklist
npm test
passesRelease Notes
notes: Added
app.getApplicationNameForProtocol()
API