Commit e2dc9772 authored by Avi Drissman's avatar Avi Drissman Committed by Commit Bot

Mac SxS: Don't ask to take default from other Chromium channels

If another channel of Chromium is already default, don't ask to
become default.

This re-lands e2d335fb with a fix.

Bug: 1109417
Change-Id: Ib0c699ebbbc15e0bb636f6d49ea6082c3208f423
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2323824Reviewed-by: default avatarMark Mentovai <mark@chromium.org>
Commit-Queue: Avi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#792347}
parent 52337087
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/mac/mac_util.h" #include "base/mac/mac_util.h"
#include "base/mac/scoped_cftyperef.h" #include "base/mac/scoped_cftyperef.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "build/branding_buildflags.h"
#include "chrome/common/channel_info.h" #include "chrome/common/channel_info.h"
#include "components/version_info/version_info.h" #include "components/version_info/version_info.h"
#import "third_party/mozilla/NSWorkspace+Utils.h" #import "third_party/mozilla/NSWorkspace+Utils.h"
...@@ -17,20 +18,6 @@ namespace shell_integration { ...@@ -17,20 +18,6 @@ namespace shell_integration {
namespace { namespace {
// Returns true if |identifier| is the bundle id of the default browser.
bool IsIdentifierDefaultBrowser(NSString* identifier) {
NSString* default_browser =
[[NSWorkspace sharedWorkspace] defaultBrowserIdentifier];
if (!default_browser)
return false;
// We need to ensure we do the comparison case-insensitive as LS doesn't
// persist the case of our bundle id.
NSComparisonResult result =
[default_browser caseInsensitiveCompare:identifier];
return result == NSOrderedSame;
}
// Returns true if |identifier| is the bundle id of the default client // Returns true if |identifier| is the bundle id of the default client
// application for the given protocol. // application for the given protocol.
bool IsIdentifierDefaultProtocolClient(NSString* identifier, bool IsIdentifierDefaultProtocolClient(NSString* identifier,
...@@ -40,8 +27,7 @@ bool IsIdentifierDefaultProtocolClient(NSString* identifier, ...@@ -40,8 +27,7 @@ bool IsIdentifierDefaultProtocolClient(NSString* identifier,
if (!default_client) if (!default_client)
return false; return false;
// We need to ensure we do the comparison case-insensitive as LS doesn't // Do the comparison case-insensitively as LS smashes the case.
// persist the case of our bundle id.
NSComparisonResult result = NSComparisonResult result =
[base::mac::CFToNSCast(default_client) caseInsensitiveCompare:identifier]; [base::mac::CFToNSCast(default_client) caseInsensitiveCompare:identifier];
return result == NSOrderedSame; return result == NSOrderedSame;
...@@ -142,12 +128,51 @@ DefaultWebClientState GetDefaultBrowser() { ...@@ -142,12 +128,51 @@ DefaultWebClientState GetDefaultBrowser() {
if (!my_identifier) if (!my_identifier)
return UNKNOWN_DEFAULT; return UNKNOWN_DEFAULT;
return IsIdentifierDefaultBrowser(my_identifier) ? IS_DEFAULT : NOT_DEFAULT; base::ScopedCFTypeRef<CFStringRef> default_browser_cf(
LSCopyDefaultHandlerForURLScheme(CFSTR("http")));
if (!default_browser_cf)
return NOT_DEFAULT;
NSString* default_browser = base::mac::CFToNSCast(default_browser_cf);
// Do the comparison case-insensitively as LS smashes the case.
if ([default_browser caseInsensitiveCompare:my_identifier] == NSOrderedSame)
return IS_DEFAULT;
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
// Flavors of Chrome are of the constructions "com.google.Chrome" and
// "com.google.Chrome.beta". If the first three components match, then these
// are variant flavors.
auto three_components_only_lopper = [](NSString* bundle_id) {
NSMutableArray<NSString*>* parts =
[[bundle_id componentsSeparatedByString:@"."] mutableCopy];
while ([parts count] > 3)
[parts removeLastObject];
return [parts componentsJoinedByString:@"."];
};
NSString* my_identifier_lopped = three_components_only_lopper(my_identifier);
NSString* default_browser_lopped =
three_components_only_lopper(default_browser);
// Do the comparisons case-insensitively as LS smashes the case.
if ([my_identifier_lopped caseInsensitiveCompare:default_browser_lopped] ==
NSOrderedSame) {
return OTHER_MODE_IS_DEFAULT;
}
#endif // BUILDFLAG(GOOGLE_CHROME_BRANDING)
return NOT_DEFAULT;
} }
// Returns true if Firefox is the default browser for the current user. // Returns true if Firefox is the default browser for the current user.
bool IsFirefoxDefaultBrowser() { bool IsFirefoxDefaultBrowser() {
return IsIdentifierDefaultBrowser(@"org.mozilla.firefox"); base::ScopedCFTypeRef<CFStringRef> default_browser(
LSCopyDefaultHandlerForURLScheme(CFSTR("http")));
if (!default_browser)
return false;
// Do the comparison case-insensitively as LS smashes the case.
return CFStringCompare(default_browser, CFSTR("org.mozilla.firefox"),
kCFCompareCaseInsensitive) == kCFCompareEqualTo;
} }
// Attempt to determine if this instance of Chrome is the default client // Attempt to determine if this instance of Chrome is the default client
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment