| 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/web_applications/web_app_mac.h" |    5 #import "chrome/browser/web_applications/web_app_mac.h" | 
|    6  |    6  | 
|    7 #import <Cocoa/Cocoa.h> |    7 #import <Cocoa/Cocoa.h> | 
|    8  |    8  | 
|    9 #include "base/file_util.h" |    9 #include "base/file_util.h" | 
|   10 #include "base/mac/bundle_locations.h" |   10 #include "base/mac/bundle_locations.h" | 
|   11 #include "base/mac/foundation_util.h" |   11 #include "base/mac/foundation_util.h" | 
|   12 #include "base/scoped_temp_dir.h" |   12 #include "base/scoped_temp_dir.h" | 
|   13 #include "base/sys_string_conversions.h" |   13 #include "base/sys_string_conversions.h" | 
 |   14 #include "base/utf_string_conversions.h" | 
|   14 #include "chrome/browser/web_applications/web_app.h" |   15 #include "chrome/browser/web_applications/web_app.h" | 
 |   16 #include "chrome/common/chrome_paths_internal.h" | 
|   15 #include "chrome/common/mac/app_mode_common.h" |   17 #include "chrome/common/mac/app_mode_common.h" | 
|   16 #include "content/public/browser/browser_thread.h" |   18 #include "content/public/browser/browser_thread.h" | 
|   17 #include "grit/chromium_strings.h" |   19 #include "grit/chromium_strings.h" | 
|   18 #include "ui/base/l10n/l10n_util_mac.h" |   20 #include "ui/base/l10n/l10n_util_mac.h" | 
|   19  |   21  | 
|   20 namespace web_app { |   22 namespace web_app { | 
|   21  |   23  | 
|   22 WebAppShortcutCreator::WebAppShortcutCreator( |   24 WebAppShortcutCreator::WebAppShortcutCreator( | 
|   23     const ShellIntegration::ShortcutInfo& shortcut_info) |   25     const ShellIntegration::ShortcutInfo& shortcut_info, | 
|   24     : info_(shortcut_info) { |   26     const string16& chrome_bundle_id) | 
 |   27     : info_(shortcut_info), | 
 |   28       chrome_bundle_id_(chrome_bundle_id) { | 
|   25 } |   29 } | 
|   26  |   30  | 
|   27 WebAppShortcutCreator::~WebAppShortcutCreator() { |   31 WebAppShortcutCreator::~WebAppShortcutCreator() { | 
|   28 } |   32 } | 
|   29  |   33  | 
|   30 bool WebAppShortcutCreator::CreateShortcut() { |   34 bool WebAppShortcutCreator::CreateShortcut() { | 
|   31   FilePath app_name = internals::GetSanitizedFileName(info_.title); |   35   FilePath app_name = internals::GetSanitizedFileName(info_.title); | 
|   32   FilePath app_file_name = app_name.ReplaceExtension("app"); |   36   FilePath app_file_name = app_name.ReplaceExtension("app"); | 
|   33   ScopedTempDir scoped_temp_dir; |   37   ScopedTempDir scoped_temp_dir; | 
|   34   if (!scoped_temp_dir.CreateUniqueTempDir()) |   38   if (!scoped_temp_dir.CreateUniqueTempDir()) | 
| (...skipping 20 matching lines...) Expand all  Loading... | 
|   55     return false; |   59     return false; | 
|   56   } |   60   } | 
|   57  |   61  | 
|   58   [[NSWorkspace sharedWorkspace] |   62   [[NSWorkspace sharedWorkspace] | 
|   59       selectFile:base::mac::FilePathToNSString(dst_path) |   63       selectFile:base::mac::FilePathToNSString(dst_path) | 
|   60       inFileViewerRootedAtPath:nil]; |   64       inFileViewerRootedAtPath:nil]; | 
|   61   return true; |   65   return true; | 
|   62 } |   66 } | 
|   63  |   67  | 
|   64 FilePath WebAppShortcutCreator::GetAppLoaderPath() const { |   68 FilePath WebAppShortcutCreator::GetAppLoaderPath() const { | 
|   65   NSString* app_loader = [l10n_util::GetNSString(IDS_PRODUCT_NAME) |  | 
|   66       stringByAppendingString:@" App Mode Loader.app"]; |  | 
|   67   return base::mac::PathForFrameworkBundleResource( |   69   return base::mac::PathForFrameworkBundleResource( | 
|   68       base::mac::NSToCFCast(app_loader)); |   70       base::mac::NSToCFCast(@"app_mode_loader.app")); | 
|   69 } |   71 } | 
|   70  |   72  | 
|   71 FilePath WebAppShortcutCreator::GetDestinationPath( |   73 FilePath WebAppShortcutCreator::GetDestinationPath( | 
|   72     const FilePath& app_file_name) const { |   74     const FilePath& app_file_name) const { | 
|   73   FilePath path; |   75   FilePath path; | 
|   74   if (base::mac::GetLocalDirectory(NSApplicationDirectory, &path) && |   76   if (base::mac::GetLocalDirectory(NSApplicationDirectory, &path) && | 
|   75       file_util::PathIsWritable(path)) { |   77       file_util::PathIsWritable(path)) { | 
|   76     return path; |   78     return path; | 
|   77   } |   79   } | 
|   78  |   80  | 
|   79   if (base::mac::GetUserDirectory(NSApplicationDirectory, &path)) |   81   if (base::mac::GetUserDirectory(NSApplicationDirectory, &path)) | 
|   80     return path; |   82     return path; | 
|   81  |   83  | 
|   82   return FilePath(); |   84   return FilePath(); | 
|   83 } |   85 } | 
|   84  |   86  | 
|   85 bool WebAppShortcutCreator::UpdatePlist(const FilePath& app_path) const { |   87 bool WebAppShortcutCreator::UpdatePlist(const FilePath& app_path) const { | 
|   86   NSString* plist_path = base::mac::FilePathToNSString( |   88   NSString* plist_path = base::mac::FilePathToNSString( | 
|   87       app_path.Append("Contents").Append("Info.plist")); |   89       app_path.Append("Contents").Append("Info.plist")); | 
|   88   NSMutableDictionary* dict = |   90   NSMutableDictionary* dict = | 
|   89       [NSMutableDictionary dictionaryWithContentsOfFile:plist_path]; |   91       [NSMutableDictionary dictionaryWithContentsOfFile:plist_path]; | 
|   90  |   92  | 
 |   93   [dict setObject:GetBundleIdentifier(dict) | 
 |   94            forKey:base::mac::CFToNSCast(kCFBundleIdentifierKey)]; | 
|   91   [dict setObject:base::SysUTF8ToNSString(info_.extension_id) |   95   [dict setObject:base::SysUTF8ToNSString(info_.extension_id) | 
|   92            forKey:app_mode::kCrAppModeShortcutIDKey]; |   96            forKey:app_mode::kCrAppModeShortcutIDKey]; | 
|   93   [dict setObject:base::SysUTF16ToNSString(info_.title) |   97   [dict setObject:base::SysUTF16ToNSString(info_.title) | 
|   94            forKey:app_mode::kCrAppModeShortcutNameKey]; |   98            forKey:app_mode::kCrAppModeShortcutNameKey]; | 
|   95   [dict setObject:base::SysUTF8ToNSString(info_.url.spec()) |   99   [dict setObject:base::SysUTF8ToNSString(info_.url.spec()) | 
|   96            forKey:app_mode::kCrAppModeShortcutURLKey]; |  100            forKey:app_mode::kCrAppModeShortcutURLKey]; | 
 |  101   [dict setObject:base::SysUTF16ToNSString(chrome_bundle_id_) | 
 |  102            forKey:app_mode::kBrowserBundleIDKey]; | 
|   97   return [dict writeToFile:plist_path atomically:YES]; |  103   return [dict writeToFile:plist_path atomically:YES]; | 
|   98 } |  104 } | 
|   99  |  105  | 
|  100 bool WebAppShortcutCreator::UpdateIcon(const FilePath& app_path) const { |  106 bool WebAppShortcutCreator::UpdateIcon(const FilePath& app_path) const { | 
|  101   // TODO:(sail) Need to implement this. |  107   // TODO:(sail) Need to implement this. | 
|  102   return true; |  108   return true; | 
|  103 } |  109 } | 
|  104  |  110  | 
 |  111 NSString* WebAppShortcutCreator::GetBundleIdentifier(NSDictionary* plist) const | 
 |  112 { | 
 |  113   NSString* bundle_id_template = | 
 |  114     base::mac::ObjCCast<NSString>( | 
 |  115         [plist objectForKey:base::mac::CFToNSCast(kCFBundleIdentifierKey)]); | 
 |  116   NSString* extension_id = base::SysUTF8ToNSString(info_.extension_id); | 
 |  117   NSString* bundle_id = | 
 |  118       [bundle_id_template | 
 |  119           stringByReplacingOccurrencesOfString:app_mode::kShortcutIdPlaceholder | 
 |  120                                     withString:extension_id]; | 
 |  121   return bundle_id; | 
 |  122 } | 
 |  123  | 
|  105 }  // namespace |  124 }  // namespace | 
|  106  |  125  | 
|  107 namespace web_app { |  126 namespace web_app { | 
|  108 namespace internals { |  127 namespace internals { | 
|  109  |  128  | 
|  110 void CreateShortcutTask(const FilePath& web_app_path, |  129 void CreateShortcutTask(const FilePath& web_app_path, | 
|  111                         const FilePath& profile_path, |  130                         const FilePath& profile_path, | 
|  112                         const ShellIntegration::ShortcutInfo& shortcut_info) { |  131                         const ShellIntegration::ShortcutInfo& shortcut_info) { | 
|  113   DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); |  132   DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); | 
|  114   WebAppShortcutCreator shortcut_creator(shortcut_info); |  133   string16 bundle_id = UTF8ToUTF16(base::mac::BaseBundleID()); | 
 |  134   WebAppShortcutCreator shortcut_creator(shortcut_info, bundle_id); | 
|  115   shortcut_creator.CreateShortcut(); |  135   shortcut_creator.CreateShortcut(); | 
|  116 } |  136 } | 
|  117  |  137  | 
|  118 }  // namespace internals |  138 }  // namespace internals | 
|  119 }  // namespace web_app |  139 }  // namespace web_app | 
| OLD | NEW |