Bug 233015 - [Cocoa] Web Inspector: fix bundle identifier lookup for enabling remote inspection
Summary: [Cocoa] Web Inspector: fix bundle identifier lookup for enabling remote inspe...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (show other bugs)
Version: WebKit Nightly Build
Hardware: All All
: P2 Normal
Assignee: BJ Burg
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-11-11 14:21 PST by BJ Burg
Modified: 2021-11-30 12:10 PST (History)
8 users (show)

See Also:


Attachments
Patch v1.0 (1.70 KB, patch)
2021-11-11 14:24 PST, BJ Burg
no flags Details | Formatted Diff | Diff
Patch v1.1 (5.87 KB, patch)
2021-11-11 15:12 PST, BJ Burg
no flags Details | Formatted Diff | Diff
Patch v1.2 (5.77 KB, patch)
2021-11-15 12:39 PST, BJ Burg
no flags Details | Formatted Diff | Diff
Patch for Landing (5.79 KB, patch)
2021-11-30 10:44 PST, BJ Burg
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description BJ Burg 2021-11-11 14:21:10 PST
.
Comment 1 BJ Burg 2021-11-11 14:21:39 PST
<rdar://85277115>
Comment 2 BJ Burg 2021-11-11 14:24:49 PST
Created attachment 444001 [details]
Patch v1.0
Comment 3 BJ Burg 2021-11-11 15:12:36 PST
Created attachment 444008 [details]
Patch v1.1
Comment 4 Darin Adler 2021-11-11 17:05:14 PST
Comment on attachment 444008 [details]
Patch v1.1

View in context: https://bugs.webkit.org/attachment.cgi?id=444008&action=review

> Source/WebKit/UIProcess/Inspector/WebInspectorUtilities.h:48
> +String bundleIdentifierForSandboxBroker();

I think this should return a CFStringRef. Also, could return ASCIILiteral if you really want to stick with WTF instead of platform-specific.
Comment 5 Patrick Angle 2021-11-12 11:09:29 PST
Comment on attachment 444008 [details]
Patch v1.1

View in context: https://bugs.webkit.org/attachment.cgi?id=444008&action=review

> Source/WebKit/UIProcess/Inspector/WebInspectorUtilities.cpp:119
> +    auto sandboxBrokerBundleIdentifier = "com.apple.Safari.SandboxBroker"_s;

Nit: Now that this logic is in a standalone function, can we just return the correct string inside the conditionals instead of setting a local variable?
Comment 6 BJ Burg 2021-11-15 12:39:09 PST
Created attachment 444296 [details]
Patch v1.2
Comment 7 Darin Adler 2021-11-15 14:37:17 PST
Comment on attachment 444296 [details]
Patch v1.2

View in context: https://bugs.webkit.org/attachment.cgi?id=444296&action=review

> Source/WebKit/UIProcess/Cocoa/WebInspectorPreferenceObserver.mm:53
> +    String sandboxBrokerBundleIdentifier = WebKit::bundleIdentifierForSandboxBroker();

I suggest not involving WTF::String at all:

    auto sandboxBrokerBundleIdentifier = WebKit::bundleIdentifierForSandboxBroker();
    m_userDefaults = adoptNS([[NSUserDefaults alloc] initWithSuiteName:bridge_cast(sandboxBrokerBundleIdentifier)]);
    if (!m_userDefaults) {
        WTFLogAlways("Could not init user defaults instance for domain %@.", sandboxBrokerBundleIdentifier);
Comment 8 Darin Adler 2021-11-15 17:07:13 PST
Comment on attachment 444296 [details]
Patch v1.2

View in context: https://bugs.webkit.org/attachment.cgi?id=444296&action=review

> Source/WebKit/UIProcess/Inspector/WebInspectorUtilities.cpp:122
> +    if (WebCore::applicationBundleIdentifier() == "com.apple.SafariTechnologyPreview"_s)
> +        return CFSTR("com.apple.SafariTechnologyPreview.SandboxBroker");
> +    if (WebCore::applicationBundleIdentifier() == "com.apple.Safari.automation"_s)
> +        return CFSTR("com.apple.Safari.automation.SandboxBroker");

One other thought: Since bundle identifiers are not case sensitive, it might be safer to call equalLettersIgnoringASCIICase instead of using ==.
Comment 9 BJ Burg 2021-11-30 10:44:01 PST
Created attachment 445440 [details]
Patch for Landing
Comment 10 Joseph Pecoraro 2021-11-30 10:53:10 PST
Comment on attachment 445440 [details]
Patch for Landing

View in context: https://bugs.webkit.org/attachment.cgi?id=445440&action=review

> Source/WebKit/UIProcess/Inspector/WebInspectorUtilities.cpp:119
> +    if (WebCore::applicationBundleIdentifier() == "com.apple.SafariTechnologyPreview"_s)

Perhaps avoid calling `WebCore::applicationBundleIdentifier` twice with a local?

Is the result always `applicationBundleIdentifier() + ".SandboxBroker"?
Comment 11 EWS 2021-11-30 12:10:40 PST
Committed r286314 (244673@main): <https://commits.webkit.org/244673@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 445440 [details].