OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
Mark Mentovai
2011/05/23 00:23:52
You should familiarize yourself with the Objective
| |
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/mac_util.h" | 7 #include "base/mac/mac_util.h" |
8 #include "chrome/browser/platform_util.h" | 8 #include "chrome/browser/platform_util.h" |
9 #import "third_party/mozilla/NSWorkspace+Utils.h" | 9 #import "third_party/mozilla/NSWorkspace+Utils.h" |
10 | 10 |
11 // 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.
| |
12 // third_party/mozilla/NSWorkspace+Utils.h | |
13 | |
14 @interface NSWorkspace(ChromiumDefaultProtocolClientAdditions) | |
Mark Mentovai
2011/05/23 00:23:52
http://google-styleguide.googlecode.com/svn/trunk/
| |
15 | |
16 - (NSString*)defaultClientIdentifierForProtocol:(NSString*)protocol; | |
Mark Mentovai
2011/05/23 00:23:52
You should define what this does if nothing’s regi
| |
17 - (void)setDefaultClientWithIdentifier:(NSString*)bundleID | |
Mark Mentovai
2011/05/23 00:23:52
http://google-styleguide.googlecode.com/svn/trunk/
| |
18 forProtocol:(NSString*)protocol; | |
19 | |
20 @end | |
21 | |
22 @implementation NSWorkspace(ChromiumDefaultProtocolClientAdditions) | |
23 | |
24 - (NSString*)defaultClientIdentifierForProtocol:(NSString*)protocol | |
Mark Mentovai
2011/05/23 00:23:52
Objective-C follows C++ style unless otherwise spe
| |
25 { | |
26 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
| |
27 autorelease]; | |
28 } | |
29 | |
30 - (void)setDefaultClientWithIdentifier:(NSString*)bundleID | |
31 forProtocol:(NSString*)protocol | |
32 { | |
33 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.
| |
34 } | |
35 | |
36 @end | |
37 | |
11 // Sets Chromium as default browser (only for current user). Returns false if | 38 // Sets Chromium as default browser (only for current user). Returns false if |
12 // this operation fails. | 39 // this operation fails. |
13 bool ShellIntegration::SetAsDefaultBrowser() { | 40 bool ShellIntegration::SetAsDefaultBrowser() { |
14 if (!platform_util::CanSetAsDefaultBrowser()) | 41 if (!platform_util::CanSetAsDefaultBrowser()) |
15 return false; | 42 return false; |
16 | 43 |
17 // We really do want the main bundle here, not base::mac::MainAppBundle(), | 44 // We really do want the main bundle here, not base::mac::MainAppBundle(), |
18 // which is the bundle for the framework. | 45 // which is the bundle for the framework. |
19 NSString* identifier = [[NSBundle mainBundle] bundleIdentifier]; | 46 NSString* identifier = [[NSBundle mainBundle] bundleIdentifier]; |
20 [[NSWorkspace sharedWorkspace] setDefaultBrowserWithIdentifier:identifier]; | 47 [[NSWorkspace sharedWorkspace] setDefaultBrowserWithIdentifier:identifier]; |
21 return true; | 48 return true; |
22 } | 49 } |
23 | 50 |
51 // 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
| |
52 // current user). Returns false if this operation fails. | |
53 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.
| |
54 if (!platform_util::CanSetAsDefaultProtocolClient(protocol)) | |
55 return false; | |
56 | |
57 // We really do want the main bundle here, not base::mac::MainAppBundle(), | |
58 // which is the bundle for the framework. | |
59 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
| |
60 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.
| |
61 encoding:[NSString defaultCStringEncoding]]; | |
62 [[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).
| |
63 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.
| |
64 return true; | |
65 } | |
66 | |
24 namespace { | 67 namespace { |
25 | 68 |
26 // Returns true if |identifier| is the bundle id of the default browser. | 69 // Returns true if |identifier| is the bundle id of the default browser. |
27 bool IsIdentifierDefaultBrowser(NSString* identifier) { | 70 bool IsIdentifierDefaultBrowser(NSString* identifier) { |
28 NSString* defaultBrowser = | 71 NSString* defaultBrowser = |
29 [[NSWorkspace sharedWorkspace] defaultBrowserIdentifier]; | 72 [[NSWorkspace sharedWorkspace] defaultBrowserIdentifier]; |
30 if (!defaultBrowser) | 73 if (!defaultBrowser) |
31 return false; | 74 return false; |
32 // We need to ensure we do the comparison case-insensitive as LS doesn't | 75 // We need to ensure we do the comparison case-insensitive as LS doesn't |
33 // persist the case of our bundle id. | 76 // persist the case of our bundle id. |
34 NSComparisonResult result = | 77 NSComparisonResult result = |
35 [defaultBrowser caseInsensitiveCompare:identifier]; | 78 [defaultBrowser caseInsensitiveCompare:identifier]; |
36 return result == NSOrderedSame; | 79 return result == NSOrderedSame; |
37 } | 80 } |
38 | 81 |
82 // Returns true if |identifier| is the bundle id of the default client | |
83 // application for the given protocol. | |
84 bool IsIdentifierDefaultProtocolClient(NSString* identifier, | |
85 NSString* protocol) { | |
86 NSString* defaultProtocolClient = | |
87 [[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.
| |
88 if (!defaultProtocolClient) | |
89 return false; | |
90 // 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.
| |
91 // persist the case of our bundle id. | |
92 NSComparisonResult result = | |
93 [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.
| |
94 return result == NSOrderedSame; | |
95 } | |
96 | |
39 } // namespace | 97 } // namespace |
40 | 98 |
41 // Attempt to determine if this instance of Chrome is the default browser and | 99 // Attempt to determine if this instance of Chrome is the default browser and |
42 // return the appropriate state. (Defined as being the handler for HTTP/HTTPS | 100 // return the appropriate state. (Defined as being the handler for HTTP/HTTPS |
43 // protocols; we don't want to report "no" here if the user has simply chosen | 101 // protocols; we don't want to report "no" here if the user has simply chosen |
44 // to open HTML files in a text editor and FTP links with an FTP client.) | 102 // to open HTML files in a text editor and FTP links with an FTP client.) |
45 ShellIntegration::DefaultBrowserState ShellIntegration::IsDefaultBrowser() { | 103 ShellIntegration::DefaultClientAppState ShellIntegration::IsDefaultBrowser() { |
46 // As above, we want to use the real main bundle. | 104 // As above, we want to use the real main bundle. |
47 NSString* myIdentifier = [[NSBundle mainBundle] bundleIdentifier]; | 105 NSString* myIdentifier = [[NSBundle mainBundle] bundleIdentifier]; |
48 if (!myIdentifier) | 106 if (!myIdentifier) |
49 return UNKNOWN_DEFAULT_BROWSER; | 107 return UNKNOWN_DEFAULT_CLIENT_APP; |
50 return IsIdentifierDefaultBrowser(myIdentifier) ? IS_DEFAULT_BROWSER | 108 return IsIdentifierDefaultBrowser(myIdentifier) ? IS_DEFAULT_CLIENT_APP |
51 : NOT_DEFAULT_BROWSER; | 109 : NOT_DEFAULT_CLIENT_APP; |
52 } | 110 } |
53 | 111 |
54 // Returns true if Firefox is the default browser for the current user. | 112 // Returns true if Firefox is the default browser for the current user. |
55 bool ShellIntegration::IsFirefoxDefaultBrowser() { | 113 bool ShellIntegration::IsFirefoxDefaultBrowser() { |
56 return IsIdentifierDefaultBrowser(@"org.mozilla.firefox"); | 114 return IsIdentifierDefaultBrowser(@"org.mozilla.firefox"); |
57 } | 115 } |
116 | |
117 // 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.
| |
118 // application for the given protocol and return the appropriate state. | |
119 ShellIntegration::DefaultClientAppState | |
120 ShellIntegration::IsDefaultProtocolClient(const std::string& protocol) { | |
121 // 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.
| |
122 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
| |
123 if (!myIdentifier) | |
124 return UNKNOWN_DEFAULT_CLIENT_APP; | |
125 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.
| |
126 encoding:[NSString defaultCStringEncoding]]; | |
127 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.
| |
128 nsProtocol) ? IS_DEFAULT_CLIENT_APP | |
129 : NOT_DEFAULT_CLIENT_APP; | |
130 } | |
OLD | NEW |