Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(439)

Side by Side Diff: chrome/browser/shell_integration_mac.mm

Issue 1832853003: DefaultBrowserWorker now fully supports opening the settings for Win10 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix mac compilation Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/shell_integration.h" 5 #include "chrome/browser/shell_integration.h"
6 6
7 #include "base/mac/bundle_locations.h" 7 #include "base/mac/bundle_locations.h"
8 #include "base/mac/foundation_util.h" 8 #include "base/mac/foundation_util.h"
9 #include "base/strings/sys_string_conversions.h" 9 #include "base/strings/sys_string_conversions.h"
10 #include "chrome/common/channel_info.h" 10 #include "chrome/common/channel_info.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 [default_client caseInsensitiveCompare:identifier]; 46 [default_client caseInsensitiveCompare:identifier];
47 return result == NSOrderedSame; 47 return result == NSOrderedSame;
48 } 48 }
49 49
50 } // namespace 50 } // namespace
51 51
52 // Sets Chromium as default browser to be used by the operating system. This 52 // Sets Chromium as default browser to be used by the operating system. This
53 // applies only for the current user. Returns false if this cannot be done, or 53 // applies only for the current user. Returns false if this cannot be done, or
54 // if the operation fails. 54 // if the operation fails.
55 bool SetAsDefaultBrowser() { 55 bool SetAsDefaultBrowser() {
56 if (CanSetAsDefaultBrowser() != SET_DEFAULT_UNATTENDED) 56 if (CanSetAsDefaultBrowser())
57 return false; 57 return false;
58 58
59 // We really do want the outer bundle here, not the main bundle since setting 59 // We really do want the outer bundle here, not the main bundle since setting
60 // a shortcut to Chrome as the default browser doesn't make sense. 60 // a shortcut to Chrome as the default browser doesn't make sense.
61 NSString* identifier = [base::mac::OuterBundle() bundleIdentifier]; 61 NSString* identifier = [base::mac::OuterBundle() bundleIdentifier];
62 if (!identifier) 62 if (!identifier)
63 return false; 63 return false;
64 64
65 [[NSWorkspace sharedWorkspace] setDefaultBrowserWithIdentifier:identifier]; 65 [[NSWorkspace sharedWorkspace] setDefaultBrowserWithIdentifier:identifier];
66 return true; 66 return true;
67 } 67 }
68 68
69 // Sets Chromium as the default application to be used by the operating system 69 // Sets Chromium as the default application to be used by the operating system
70 // for the given protocol. This applies only for the current user. Returns false 70 // for the given protocol. This applies only for the current user. Returns false
71 // if this cannot be done, or if the operation fails. 71 // if this cannot be done, or if the operation fails.
72 bool SetAsDefaultProtocolClient(const std::string& protocol) { 72 bool SetAsDefaultProtocolClient(const std::string& protocol) {
73 if (protocol.empty()) 73 if (protocol.empty())
74 return false; 74 return false;
75 75
76 if (CanSetAsDefaultProtocolClient() != SET_DEFAULT_UNATTENDED) 76 if (GetDefaultWebClientSetPermission() != SET_DEFAULT_UNATTENDED)
77 return false; 77 return false;
78 78
79 // We really do want the main bundle here since it makes sense to set an 79 // We really do want the main bundle here since it makes sense to set an
80 // app shortcut as a default protocol handler. 80 // app shortcut as a default protocol handler.
81 NSString* identifier = [base::mac::MainBundle() bundleIdentifier]; 81 NSString* identifier = [base::mac::MainBundle() bundleIdentifier];
82 if (!identifier) 82 if (!identifier)
83 return false; 83 return false;
84 84
85 NSString* protocol_ns = [NSString stringWithUTF8String:protocol.c_str()]; 85 NSString* protocol_ns = [NSString stringWithUTF8String:protocol.c_str()];
86 OSStatus return_code = 86 OSStatus return_code =
87 LSSetDefaultHandlerForURLScheme(base::mac::NSToCFCast(protocol_ns), 87 LSSetDefaultHandlerForURLScheme(base::mac::NSToCFCast(protocol_ns),
88 base::mac::NSToCFCast(identifier)); 88 base::mac::NSToCFCast(identifier));
89 return return_code == noErr; 89 return return_code == noErr;
90 } 90 }
91 91
92 DefaultWebClientSetPermission CanSetAsDefaultBrowser() { 92 DefaultWebClientSetPermission GetDefaultWebClientSetPermission() {
93 if (chrome::GetChannel() != version_info::Channel::CANARY) { 93 if (chrome::GetChannel() == version_info::Channel::CANARY) {
94 return SET_DEFAULT_UNATTENDED; 94 return SET_DEFAULT_NOT_ALLOWED;
95 } 95 }
96 96
97 return SET_DEFAULT_NOT_ALLOWED; 97 return SET_DEFAULT_UNATTENDED;
98 } 98 }
99 99
100 base::string16 GetApplicationNameForProtocol(const GURL& url) { 100 base::string16 GetApplicationNameForProtocol(const GURL& url) {
101 NSURL* ns_url = [NSURL URLWithString: 101 NSURL* ns_url = [NSURL URLWithString:
102 base::SysUTF8ToNSString(url.possibly_invalid_spec())]; 102 base::SysUTF8ToNSString(url.possibly_invalid_spec())];
103 CFURLRef openingApp = NULL; 103 CFURLRef openingApp = NULL;
104 OSStatus status = LSGetApplicationForURL((CFURLRef)ns_url, 104 OSStatus status = LSGetApplicationForURL((CFURLRef)ns_url,
105 kLSRolesAll, 105 kLSRolesAll,
106 NULL, 106 NULL,
107 &openingApp); 107 &openingApp);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 NSString* my_identifier = [base::mac::MainBundle() bundleIdentifier]; 146 NSString* my_identifier = [base::mac::MainBundle() bundleIdentifier];
147 if (!my_identifier) 147 if (!my_identifier)
148 return UNKNOWN_DEFAULT; 148 return UNKNOWN_DEFAULT;
149 149
150 NSString* protocol_ns = [NSString stringWithUTF8String:protocol.c_str()]; 150 NSString* protocol_ns = [NSString stringWithUTF8String:protocol.c_str()];
151 return IsIdentifierDefaultProtocolClient(my_identifier, protocol_ns) ? 151 return IsIdentifierDefaultProtocolClient(my_identifier, protocol_ns) ?
152 IS_DEFAULT : NOT_DEFAULT; 152 IS_DEFAULT : NOT_DEFAULT;
153 } 153 }
154 154
155 } // namespace shell_integration 155 } // namespace shell_integration
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698