Chromium Code Reviews| Index: chrome/browser/shell_integration_mac.mm |
| diff --git a/chrome/browser/shell_integration_mac.mm b/chrome/browser/shell_integration_mac.mm |
| index 7bf1dcb3fcdedd489248398b9d703fe6027b2ebc..94bd1e3cbe13a4ac812f1a9633b18fb6a9eb435c 100644 |
| --- a/chrome/browser/shell_integration_mac.mm |
| +++ b/chrome/browser/shell_integration_mac.mm |
| @@ -8,6 +8,33 @@ |
| #include "chrome/browser/platform_util.h" |
| #import "third_party/mozilla/NSWorkspace+Utils.h" |
| +// FIXME: These functions should be rolled into |
|
Mark Mentovai
2011/05/23 00:23:52
Unless you actually plan to upstream this code and
benwells
2011/05/23 06:08:37
OK, will make the change to remove the objective c
benwells
2011/05/24 06:10:38
Done.
|
| +// third_party/mozilla/NSWorkspace+Utils.h |
| + |
| +@interface NSWorkspace(ChromiumDefaultProtocolClientAdditions) |
|
Mark Mentovai
2011/05/23 00:23:52
http://google-styleguide.googlecode.com/svn/trunk/
|
| + |
| +- (NSString*)defaultClientIdentifierForProtocol:(NSString*)protocol; |
|
Mark Mentovai
2011/05/23 00:23:52
You should define what this does if nothing’s regi
|
| +- (void)setDefaultClientWithIdentifier:(NSString*)bundleID |
|
Mark Mentovai
2011/05/23 00:23:52
http://google-styleguide.googlecode.com/svn/trunk/
|
| + forProtocol:(NSString*)protocol; |
| + |
| +@end |
| + |
| +@implementation NSWorkspace(ChromiumDefaultProtocolClientAdditions) |
| + |
| +- (NSString*)defaultClientIdentifierForProtocol:(NSString*)protocol |
|
Mark Mentovai
2011/05/23 00:23:52
Objective-C follows C++ style unless otherwise spe
|
| +{ |
| + return [(NSString*)LSCopyDefaultHandlerForURLScheme((CFStringRef)protocol) |
|
Mark Mentovai
2011/05/23 00:23:52
Familiarize yourself with NSToCFCast and CFToNSCas
benwells
2011/05/24 06:10:38
Done. Please check that I've used these correctly
|
| + autorelease]; |
| +} |
| + |
| +- (void)setDefaultClientWithIdentifier:(NSString*)bundleID |
| + forProtocol:(NSString*)protocol |
| +{ |
| + LSSetDefaultHandlerForURLScheme((CFStringRef)protocol, (CFStringRef)bundleID); |
|
Mark Mentovai
2011/05/23 00:23:52
Make this method return a BOOL, and return |YourCo
benwells
2011/05/24 06:10:38
Done.
|
| +} |
| + |
| +@end |
| + |
| // Sets Chromium as default browser (only for current user). Returns false if |
| // this operation fails. |
| bool ShellIntegration::SetAsDefaultBrowser() { |
| @@ -21,6 +48,22 @@ bool ShellIntegration::SetAsDefaultBrowser() { |
| return true; |
| } |
| +// Sets Chromium as client application for the provided protocol (only for |
|
Mark Mentovai
2011/05/23 00:23:52
Revise this comment. Just because the comment you’
benwells
2011/05/24 06:10:38
Done. Also revised comment for SetAsDefaultBrowser
|
| +// current user). Returns false if this operation fails. |
| +bool ShellIntegration::SetAsDefaultProtocolClient(const std::string& protocol) { |
|
Mark Mentovai
2011/05/23 00:23:52
I think you should return false if |protocol| is e
benwells
2011/05/24 06:10:38
Done.
|
| + if (!platform_util::CanSetAsDefaultProtocolClient(protocol)) |
| + return false; |
| + |
| + // We really do want the main bundle here, not base::mac::MainAppBundle(), |
| + // which is the bundle for the framework. |
| + NSString* identifier = [[NSBundle mainBundle] bundleIdentifier]; |
|
Mark Mentovai
2011/05/23 00:23:52
IsDefaultProtocolClient specifically handles the c
benwells
2011/05/24 06:10:38
Done. It was like this because I had copied the te
|
| + NSString* nsProtocol = [NSString stringWithCString: protocol.c_str() |
|
Mark Mentovai
2011/05/23 00:23:52
In Chrome (at least at this layer), std::string is
benwells
2011/05/24 06:10:38
Done.
|
| + encoding:[NSString defaultCStringEncoding]]; |
| + [[NSWorkspace sharedWorkspace] setDefaultClientWithIdentifier:identifier |
|
Mark Mentovai
2011/05/23 00:23:52
http://google-styleguide.googlecode.com/svn/trunk/
benwells
2011/05/24 06:10:38
Done (or more accurately, no longer needed).
|
| + forProtocol: nsProtocol]; |
|
Mark Mentovai
2011/05/23 00:23:52
There’s never a space between a colon and an argum
benwells
2011/05/24 06:10:38
Done.
|
| + return true; |
| +} |
| + |
| namespace { |
| // Returns true if |identifier| is the bundle id of the default browser. |
| @@ -36,22 +79,52 @@ bool IsIdentifierDefaultBrowser(NSString* identifier) { |
| return result == NSOrderedSame; |
| } |
| +// Returns true if |identifier| is the bundle id of the default client |
| +// application for the given protocol. |
| +bool IsIdentifierDefaultProtocolClient(NSString* identifier, |
| + NSString* protocol) { |
| + NSString* defaultProtocolClient = |
| + [[NSWorkspace sharedWorkspace] defaultClientIdentifierForProtocol:protocol]; |
|
Mark Mentovai
2011/05/23 00:23:52
The continuation line needs to be indented somehow
benwells
2011/05/24 06:10:38
Done.
|
| + if (!defaultProtocolClient) |
| + return false; |
| + // We need to ensure we do the comparison case-insensitive as LS doesn't |
|
Mark Mentovai
2011/05/23 00:23:52
I like a blank line before a new comment other tha
benwells
2011/05/24 06:10:38
Done.
|
| + // persist the case of our bundle id. |
| + NSComparisonResult result = |
| + [defaultProtocolClient caseInsensitiveCompare:identifier]; |
|
Mark Mentovai
2011/05/23 00:23:52
As above with respect to indenting continuation li
benwells
2011/05/24 06:10:38
Done.
|
| + return result == NSOrderedSame; |
| +} |
| + |
| } // namespace |
| // Attempt to determine if this instance of Chrome is the default browser and |
| // return the appropriate state. (Defined as being the handler for HTTP/HTTPS |
| // protocols; we don't want to report "no" here if the user has simply chosen |
| // to open HTML files in a text editor and FTP links with an FTP client.) |
| -ShellIntegration::DefaultBrowserState ShellIntegration::IsDefaultBrowser() { |
| +ShellIntegration::DefaultClientAppState ShellIntegration::IsDefaultBrowser() { |
| // As above, we want to use the real main bundle. |
| NSString* myIdentifier = [[NSBundle mainBundle] bundleIdentifier]; |
| if (!myIdentifier) |
| - return UNKNOWN_DEFAULT_BROWSER; |
| - return IsIdentifierDefaultBrowser(myIdentifier) ? IS_DEFAULT_BROWSER |
| - : NOT_DEFAULT_BROWSER; |
| + return UNKNOWN_DEFAULT_CLIENT_APP; |
| + return IsIdentifierDefaultBrowser(myIdentifier) ? IS_DEFAULT_CLIENT_APP |
| + : NOT_DEFAULT_CLIENT_APP; |
| } |
| // Returns true if Firefox is the default browser for the current user. |
| bool ShellIntegration::IsFirefoxDefaultBrowser() { |
| return IsIdentifierDefaultBrowser(@"org.mozilla.firefox"); |
| } |
| + |
| + // Attempt to determine if this instance of Chrome is the default client |
|
Mark Mentovai
2011/05/23 00:23:52
Odd indentation on the comment.
|
| + // application for the given protocol and return the appropriate state. |
| +ShellIntegration::DefaultClientAppState |
| + ShellIntegration::IsDefaultProtocolClient(const std::string& protocol) { |
| + // As above, we want to use the real main bundle. |
|
Mark Mentovai
2011/05/23 00:23:52
“Above” and “below” are relative, subject to chang
benwells
2011/05/24 06:10:38
Done.
|
| + NSString* myIdentifier = [[NSBundle mainBundle] bundleIdentifier]; |
|
Mark Mentovai
2011/05/23 00:23:52
Since this is a C++ method, use c++ style_naming a
benwells
2011/05/24 06:10:38
Done. As these are all C++ methods (please correct
|
| + if (!myIdentifier) |
| + return UNKNOWN_DEFAULT_CLIENT_APP; |
| + NSString* nsProtocol = [NSString stringWithCString: protocol.c_str() |
|
Mark Mentovai
2011/05/23 00:23:52
Encodings and conversions as on line 60.
Mark Mentovai
2011/05/23 00:23:52
As on line 122, this should be ns_protocol, or I’d
Mark Mentovai
2011/05/23 00:23:52
Blank line before an early return as on line 90.
benwells
2011/05/24 06:10:38
Done.
benwells
2011/05/24 06:10:38
Done.
|
| + encoding:[NSString defaultCStringEncoding]]; |
| + return IsIdentifierDefaultProtocolClient(myIdentifier, |
|
Mark Mentovai
2011/05/23 00:23:52
This whole statement is eating up a lot of vertica
benwells
2011/05/24 06:10:38
Done.
|
| + nsProtocol) ? IS_DEFAULT_CLIENT_APP |
| + : NOT_DEFAULT_CLIENT_APP; |
| +} |