Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/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 ShellIntegration::DefaultSettingsChangePermission |
| 14 return chrome::VersionInfo::GetChannel() != | 14 ShellIntegration::CanSetAsDefaultBrowser() { |
| 15 chrome::VersionInfo::CHANNEL_CANARY; | 15 if (chrome::VersionInfo::GetChannel() != |
| 16 chrome::VersionInfo::CHANNEL_CANARY) { | |
| 17 return CHANGE_DEFAULT_UNATTENDED; | |
| 18 } | |
| 19 | |
| 20 return CHANGE_DEFAULT_NOT_ALLOWED; | |
| 16 } | 21 } |
| 17 | 22 |
| 18 // Sets Chromium as default browser to be used by the operating system. This | 23 // 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 | 24 // applies only for the current user. Returns false if this cannot be done, or |
| 20 // if the operation fails. | 25 // if the operation fails. |
| 21 bool ShellIntegration::SetAsDefaultBrowser() { | 26 bool ShellIntegration::SetAsDefaultBrowser() { |
| 22 if (!CanSetAsDefaultBrowser()) | 27 if (CanSetAsDefaultBrowser() != CHANGE_DEFAULT_UNATTENDED) |
| 23 return false; | 28 return false; |
| 24 | 29 |
| 25 // We really do want the outer bundle here, not the main bundle since setting | 30 // We really do want the outer bundle here, not the main bundle since setting |
| 26 // a shortcut to Chrome as the default browser doesn't make sense. | 31 // a shortcut to Chrome as the default browser doesn't make sense. |
| 27 NSString* identifier = [base::mac::OuterBundle() bundleIdentifier]; | 32 NSString* identifier = [base::mac::OuterBundle() bundleIdentifier]; |
| 28 if (!identifier) | 33 if (!identifier) |
| 29 return false; | 34 return false; |
| 30 | 35 |
| 31 [[NSWorkspace sharedWorkspace] setDefaultBrowserWithIdentifier:identifier]; | 36 [[NSWorkspace sharedWorkspace] setDefaultBrowserWithIdentifier:identifier]; |
| 32 return true; | 37 return true; |
| 33 } | 38 } |
| 34 | 39 |
| 35 // Sets Chromium as the default application to be used by the operating system | 40 // 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 | 41 // for the given protocol. This applies only for the current user. Returns false |
| 37 // if this cannot be done, or if the operation fails. | 42 // if this cannot be done, or if the operation fails. |
| 38 bool ShellIntegration::SetAsDefaultProtocolClient(const std::string& protocol) { | 43 bool ShellIntegration::SetAsDefaultProtocolClient(const std::string& protocol) { |
| 39 if (protocol.empty()) | 44 if (protocol.empty()) |
| 40 return false; | 45 return false; |
| 41 | 46 |
| 42 if (!CanSetAsDefaultProtocolClient()) | 47 if (CHANGE_DEFAULT_NOT_ALLOWED == CanSetAsDefaultProtocolClient()) |
|
grt (UTC plus 2)
2012/05/25 20:27:38
why is line 27 != _UNATTENDED and this one == NOT_
motek.
2012/05/28 17:40:33
It seemed natural to use a less constraining check
| |
| 43 return false; | 48 return false; |
| 44 | 49 |
| 45 // We really do want the main bundle here since it makes sense to set an | 50 // We really do want the main bundle here since it makes sense to set an |
| 46 // app shortcut as a default protocol handler. | 51 // app shortcut as a default protocol handler. |
| 47 NSString* identifier = [base::mac::MainBundle() bundleIdentifier]; | 52 NSString* identifier = [base::mac::MainBundle() bundleIdentifier]; |
| 48 if (!identifier) | 53 if (!identifier) |
| 49 return false; | 54 return false; |
| 50 | 55 |
| 51 NSString* protocol_ns = [NSString stringWithUTF8String:protocol.c_str()]; | 56 NSString* protocol_ns = [NSString stringWithUTF8String:protocol.c_str()]; |
| 52 OSStatus return_code = | 57 OSStatus return_code = |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 121 // We really do want the main bundle here since it makes sense to set an | 126 // We really do want the main bundle here since it makes sense to set an |
| 122 // app shortcut as a default protocol handler. | 127 // app shortcut as a default protocol handler. |
| 123 NSString* my_identifier = [base::mac::MainBundle() bundleIdentifier]; | 128 NSString* my_identifier = [base::mac::MainBundle() bundleIdentifier]; |
| 124 if (!my_identifier) | 129 if (!my_identifier) |
| 125 return UNKNOWN_DEFAULT_WEB_CLIENT; | 130 return UNKNOWN_DEFAULT_WEB_CLIENT; |
| 126 | 131 |
| 127 NSString* protocol_ns = [NSString stringWithUTF8String:protocol.c_str()]; | 132 NSString* protocol_ns = [NSString stringWithUTF8String:protocol.c_str()]; |
| 128 return IsIdentifierDefaultProtocolClient(my_identifier, protocol_ns) ? | 133 return IsIdentifierDefaultProtocolClient(my_identifier, protocol_ns) ? |
| 129 IS_DEFAULT_WEB_CLIENT : NOT_DEFAULT_WEB_CLIENT; | 134 IS_DEFAULT_WEB_CLIENT : NOT_DEFAULT_WEB_CLIENT; |
| 130 } | 135 } |
| OLD | NEW |