| OLD | NEW | 
|---|
|  | (Empty) | 
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |  | 
| 2 // Use of this source code is governed by a BSD-style license that can be |  | 
| 3 // found in the LICENSE file. |  | 
| 4 |  | 
| 5 #include "chrome/common/platform_util.h" |  | 
| 6 |  | 
| 7 #import <Cocoa/Cocoa.h> |  | 
| 8 |  | 
| 9 #include "app/l10n_util.h" |  | 
| 10 #include "app/l10n_util_mac.h" |  | 
| 11 #include "base/file_path.h" |  | 
| 12 #include "base/logging.h" |  | 
| 13 #include "base/mac_util.h" |  | 
| 14 #include "base/sys_string_conversions.h" |  | 
| 15 #include "googleurl/src/gurl.h" |  | 
| 16 #include "grit/generated_resources.h" |  | 
| 17 |  | 
| 18 namespace platform_util { |  | 
| 19 |  | 
| 20 void ShowItemInFolder(const FilePath& full_path) { |  | 
| 21   DCHECK_EQ([NSThread currentThread], [NSThread mainThread]); |  | 
| 22   NSString* path_string = base::SysUTF8ToNSString(full_path.value()); |  | 
| 23   if (!path_string || ![[NSWorkspace sharedWorkspace] selectFile:path_string |  | 
| 24                                         inFileViewerRootedAtPath:nil]) |  | 
| 25     LOG(WARNING) << "NSWorkspace failed to select file " << full_path.value(); |  | 
| 26 } |  | 
| 27 |  | 
| 28 void OpenItem(const FilePath& full_path) { |  | 
| 29   DCHECK_EQ([NSThread currentThread], [NSThread mainThread]); |  | 
| 30   NSString* path_string = base::SysUTF8ToNSString(full_path.value()); |  | 
| 31   if (!path_string || ![[NSWorkspace sharedWorkspace] openFile:path_string]) |  | 
| 32     LOG(WARNING) << "NSWorkspace failed to open file " << full_path.value(); |  | 
| 33 } |  | 
| 34 |  | 
| 35 void OpenExternal(const GURL& url) { |  | 
| 36   DCHECK_EQ([NSThread currentThread], [NSThread mainThread]); |  | 
| 37   NSString* url_string = base::SysUTF8ToNSString(url.spec()); |  | 
| 38   NSURL* ns_url = [NSURL URLWithString:url_string]; |  | 
| 39   if (!ns_url || ![[NSWorkspace sharedWorkspace] openURL:ns_url]) |  | 
| 40     LOG(WARNING) << "NSWorkspace failed to open URL " << url; |  | 
| 41 } |  | 
| 42 |  | 
| 43 gfx::NativeWindow GetTopLevel(gfx::NativeView view) { |  | 
| 44   return [view window]; |  | 
| 45 } |  | 
| 46 |  | 
| 47 bool IsWindowActive(gfx::NativeWindow window) { |  | 
| 48   return [window isKeyWindow] || [window isMainWindow]; |  | 
| 49 } |  | 
| 50 |  | 
| 51 bool IsVisible(gfx::NativeView view) { |  | 
| 52   // A reasonable approximation of how you'd expect this to behave. |  | 
| 53   return (view && |  | 
| 54           ![view isHiddenOrHasHiddenAncestor] && |  | 
| 55           [view window] && |  | 
| 56           [[view window] isVisible]); |  | 
| 57 } |  | 
| 58 |  | 
| 59 void SimpleErrorBox(gfx::NativeWindow parent, |  | 
| 60                     const string16& title, |  | 
| 61                     const string16& message) { |  | 
| 62   NSAlert* alert = [[[NSAlert alloc] init] autorelease]; |  | 
| 63   [alert addButtonWithTitle:l10n_util::GetNSString(IDS_OK)]; |  | 
| 64   [alert setMessageText:base::SysUTF16ToNSString(title)]; |  | 
| 65   [alert setInformativeText:base::SysUTF16ToNSString(message)]; |  | 
| 66   [alert setAlertStyle:NSWarningAlertStyle]; |  | 
| 67   [alert runModal]; |  | 
| 68 } |  | 
| 69 |  | 
| 70 string16 GetVersionStringModifier() { |  | 
| 71 #if defined(GOOGLE_CHROME_BUILD) |  | 
| 72   NSBundle* bundle = mac_util::MainAppBundle(); |  | 
| 73   NSString* channel = [bundle objectForInfoDictionaryKey:@"KSChannelID"]; |  | 
| 74   // Only ever return "", "unknown", "beta" or "dev" in a branded build. |  | 
| 75   if ([channel isEqual:@"stable"]) { |  | 
| 76     channel = @""; |  | 
| 77   } else if ([channel isEqual:@"beta"] || [channel isEqual:@"dev"]) { |  | 
| 78     // do nothing. |  | 
| 79   } else { |  | 
| 80     channel = @"unknown"; |  | 
| 81   } |  | 
| 82 |  | 
| 83   return base::SysNSStringToUTF16(channel); |  | 
| 84 #else |  | 
| 85   return string16(); |  | 
| 86 #endif |  | 
| 87 } |  | 
| 88 |  | 
| 89 }  // namespace platform_util |  | 
| OLD | NEW | 
|---|