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