| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/mac_util.h" | 8 #include "base/mac/mac_util.h" |
| 9 #include "base/mac/foundation_util.h" | 9 #include "base/mac/foundation_util.h" |
| 10 #include "chrome/common/chrome_version_info.h" | 10 #include "chrome/common/chrome_version_info.h" |
| 11 #import "third_party/mozilla/NSWorkspace+Utils.h" | 11 #import "third_party/mozilla/NSWorkspace+Utils.h" |
| 12 | 12 |
| 13 bool ShellIntegration::CanSetAsDefaultBrowser() { | 13 bool ShellIntegration::CanSetAsDefaultBrowser() { |
| 14 return chrome::VersionInfo::GetChannel() != | 14 return chrome::VersionInfo::GetChannel() != |
| 15 chrome::VersionInfo::CHANNEL_CANARY; | 15 chrome::VersionInfo::CHANNEL_CANARY; |
| 16 } | 16 } |
| 17 | 17 |
| 18 // Sets Chromium as default browser to be used by the operating system. This | 18 // Sets Chromium as default browser to be used by the operating system. This |
| 19 // applies only for the current user. Returns false if this cannot be done, or | 19 // applies only for the current user. Returns false if this cannot be done, or |
| 20 // if the operation fails. | 20 // if the operation fails. |
| 21 bool ShellIntegration::SetAsDefaultBrowser() { | 21 bool ShellIntegration::SetAsDefaultBrowser() { |
| 22 if (!CanSetAsDefaultBrowser()) | 22 if (!CanSetAsDefaultBrowser()) |
| 23 return false; | 23 return false; |
| 24 | 24 |
| 25 // We really do want the main bundle here, not base::mac::FrameworkBundle(), | 25 // We really do want the outer bundle here, not the main bundle since setting |
| 26 // which is the bundle for the framework. | 26 // a shortcut to Chrome as the default browser doesn't make sense. |
| 27 NSString* identifier = [[NSBundle mainBundle] bundleIdentifier]; | 27 NSString* identifier = [base::mac::OuterBundle() bundleIdentifier]; |
| 28 if (!identifier) | 28 if (!identifier) |
| 29 return false; | 29 return false; |
| 30 | 30 |
| 31 [[NSWorkspace sharedWorkspace] setDefaultBrowserWithIdentifier:identifier]; | 31 [[NSWorkspace sharedWorkspace] setDefaultBrowserWithIdentifier:identifier]; |
| 32 return true; | 32 return true; |
| 33 } | 33 } |
| 34 | 34 |
| 35 // Sets Chromium as the default application to be used by the operating system | 35 // Sets Chromium as the default application to be used by the operating system |
| 36 // for the given protocol. This applies only for the current user. Returns false | 36 // for the given protocol. This applies only for the current user. Returns false |
| 37 // if this cannot be done, or if the operation fails. | 37 // if this cannot be done, or if the operation fails. |
| 38 bool ShellIntegration::SetAsDefaultProtocolClient(const std::string& protocol) { | 38 bool ShellIntegration::SetAsDefaultProtocolClient(const std::string& protocol) { |
| 39 if (protocol.empty()) | 39 if (protocol.empty()) |
| 40 return false; | 40 return false; |
| 41 | 41 |
| 42 if (!CanSetAsDefaultProtocolClient()) | 42 if (!CanSetAsDefaultProtocolClient()) |
| 43 return false; | 43 return false; |
| 44 | 44 |
| 45 // We really do want the main bundle here, not base::mac::FrameworkBundle(), | 45 // We really do want the main bundle here since it makes sense to set an |
| 46 // which is the bundle for the framework. | 46 // app shortcut as a default protocol handler. |
| 47 NSString* identifier = [[NSBundle mainBundle] bundleIdentifier]; | 47 NSString* identifier = [base::mac::MainBundle() bundleIdentifier]; |
| 48 if (!identifier) | 48 if (!identifier) |
| 49 return false; | 49 return false; |
| 50 | 50 |
| 51 NSString* protocol_ns = [NSString stringWithUTF8String:protocol.c_str()]; | 51 NSString* protocol_ns = [NSString stringWithUTF8String:protocol.c_str()]; |
| 52 OSStatus return_code = | 52 OSStatus return_code = |
| 53 LSSetDefaultHandlerForURLScheme(base::mac::NSToCFCast(protocol_ns), | 53 LSSetDefaultHandlerForURLScheme(base::mac::NSToCFCast(protocol_ns), |
| 54 base::mac::NSToCFCast(identifier)); | 54 base::mac::NSToCFCast(identifier)); |
| 55 return return_code == noErr; | 55 return return_code == noErr; |
| 56 } | 56 } |
| 57 | 57 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 return result == NSOrderedSame; | 89 return result == NSOrderedSame; |
| 90 } | 90 } |
| 91 | 91 |
| 92 } // namespace | 92 } // namespace |
| 93 | 93 |
| 94 // Attempt to determine if this instance of Chrome is the default browser and | 94 // Attempt to determine if this instance of Chrome is the default browser and |
| 95 // return the appropriate state. (Defined as being the handler for HTTP/HTTPS | 95 // return the appropriate state. (Defined as being the handler for HTTP/HTTPS |
| 96 // protocols; we don't want to report "no" here if the user has simply chosen | 96 // protocols; we don't want to report "no" here if the user has simply chosen |
| 97 // to open HTML files in a text editor and FTP links with an FTP client.) | 97 // to open HTML files in a text editor and FTP links with an FTP client.) |
| 98 ShellIntegration::DefaultWebClientState ShellIntegration::IsDefaultBrowser() { | 98 ShellIntegration::DefaultWebClientState ShellIntegration::IsDefaultBrowser() { |
| 99 // We really do want the main bundle here, not base::mac::FrameworkBundle(), | 99 // We really do want the outer bundle here, since this we want to know the |
| 100 // which is the bundle for the framework. | 100 // status of the main Chrome bundle and not a shortcut. |
| 101 NSString* my_identifier = [[NSBundle mainBundle] bundleIdentifier]; | 101 NSString* my_identifier = [base::mac::OuterBundle() bundleIdentifier]; |
| 102 if (!my_identifier) | 102 if (!my_identifier) |
| 103 return UNKNOWN_DEFAULT_WEB_CLIENT; | 103 return UNKNOWN_DEFAULT_WEB_CLIENT; |
| 104 | 104 |
| 105 return IsIdentifierDefaultBrowser(my_identifier) ? IS_DEFAULT_WEB_CLIENT | 105 return IsIdentifierDefaultBrowser(my_identifier) ? IS_DEFAULT_WEB_CLIENT |
| 106 : NOT_DEFAULT_WEB_CLIENT; | 106 : NOT_DEFAULT_WEB_CLIENT; |
| 107 } | 107 } |
| 108 | 108 |
| 109 // Returns true if Firefox is the default browser for the current user. | 109 // Returns true if Firefox is the default browser for the current user. |
| 110 bool ShellIntegration::IsFirefoxDefaultBrowser() { | 110 bool ShellIntegration::IsFirefoxDefaultBrowser() { |
| 111 return IsIdentifierDefaultBrowser(@"org.mozilla.firefox"); | 111 return IsIdentifierDefaultBrowser(@"org.mozilla.firefox"); |
| 112 } | 112 } |
| 113 | 113 |
| 114 // Attempt to determine if this instance of Chrome is the default client | 114 // Attempt to determine if this instance of Chrome is the default client |
| 115 // application for the given protocol and return the appropriate state. | 115 // application for the given protocol and return the appropriate state. |
| 116 ShellIntegration::DefaultWebClientState | 116 ShellIntegration::DefaultWebClientState |
| 117 ShellIntegration::IsDefaultProtocolClient(const std::string& protocol) { | 117 ShellIntegration::IsDefaultProtocolClient(const std::string& protocol) { |
| 118 if (protocol.empty()) | 118 if (protocol.empty()) |
| 119 return UNKNOWN_DEFAULT_WEB_CLIENT; | 119 return UNKNOWN_DEFAULT_WEB_CLIENT; |
| 120 | 120 |
| 121 // We really do want the main bundle here, not base::mac::FrameworkBundle(), | 121 // We really do want the main bundle here since it makes sense to set an |
| 122 // which is the bundle for the framework. | 122 // app shortcut as a default protocol handler. |
| 123 NSString* my_identifier = [[NSBundle mainBundle] bundleIdentifier]; | 123 NSString* my_identifier = [base::mac::MainBundle() bundleIdentifier]; |
| 124 if (!my_identifier) | 124 if (!my_identifier) |
| 125 return UNKNOWN_DEFAULT_WEB_CLIENT; | 125 return UNKNOWN_DEFAULT_WEB_CLIENT; |
| 126 | 126 |
| 127 NSString* protocol_ns = [NSString stringWithUTF8String:protocol.c_str()]; | 127 NSString* protocol_ns = [NSString stringWithUTF8String:protocol.c_str()]; |
| 128 return IsIdentifierDefaultProtocolClient(my_identifier, protocol_ns) ? | 128 return IsIdentifierDefaultProtocolClient(my_identifier, protocol_ns) ? |
| 129 IS_DEFAULT_WEB_CLIENT : NOT_DEFAULT_WEB_CLIENT; | 129 IS_DEFAULT_WEB_CLIENT : NOT_DEFAULT_WEB_CLIENT; |
| 130 } | 130 } |
| OLD | NEW |