| 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 #include "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 "chrome/browser/web_applications/web_app.h" | 14 #include "chrome/browser/web_applications/web_app.h" |
| 15 #include "chrome/common/mac/app_mode_common.h" | 15 #include "chrome/common/mac/app_mode_common.h" |
| 16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 17 #include "grit/chromium_strings.h" | 17 #include "grit/chromium_strings.h" |
| 18 #include "ui/base/l10n/l10n_util_mac.h" | 18 #include "ui/base/l10n/l10n_util_mac.h" |
| 19 | 19 |
| 20 namespace web_app { | 20 namespace web_app { |
| 21 | 21 |
| 22 WebAppShortcutCreator::WebAppShortcutCreator( | 22 WebAppShortcutCreator::WebAppShortcutCreator( |
| 23 const FilePath& web_app_path, |
| 23 const ShellIntegration::ShortcutInfo& shortcut_info) | 24 const ShellIntegration::ShortcutInfo& shortcut_info) |
| 24 : info_(shortcut_info) { | 25 : web_app_path_(web_app_path), info_(shortcut_info) { |
| 25 } | 26 } |
| 26 | 27 |
| 27 WebAppShortcutCreator::~WebAppShortcutCreator() { | 28 WebAppShortcutCreator::~WebAppShortcutCreator() { |
| 28 } | 29 } |
| 29 | 30 |
| 30 bool WebAppShortcutCreator::CreateShortcut() { | 31 bool WebAppShortcutCreator::CreateShortcut() { |
| 31 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); | 32 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); |
| 32 FilePath app_name = internals::GetSanitizedFileName(info_.title); | 33 FilePath app_name = internals::GetSanitizedFileName(info_.title); |
| 33 FilePath app_file_name = app_name.ReplaceExtension("app"); | 34 FilePath app_file_name = app_name.ReplaceExtension("app"); |
| 34 ScopedTempDir scoped_temp_dir; | 35 ScopedTempDir scoped_temp_dir; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 app_path.Append("Contents").Append("Info.plist")); | 89 app_path.Append("Contents").Append("Info.plist")); |
| 89 NSMutableDictionary* dict = | 90 NSMutableDictionary* dict = |
| 90 [NSMutableDictionary dictionaryWithContentsOfFile:plist_path]; | 91 [NSMutableDictionary dictionaryWithContentsOfFile:plist_path]; |
| 91 | 92 |
| 92 [dict setObject:base::SysUTF8ToNSString(info_.extension_id) | 93 [dict setObject:base::SysUTF8ToNSString(info_.extension_id) |
| 93 forKey:app_mode::kCrAppModeShortcutIDKey]; | 94 forKey:app_mode::kCrAppModeShortcutIDKey]; |
| 94 [dict setObject:base::SysUTF16ToNSString(info_.title) | 95 [dict setObject:base::SysUTF16ToNSString(info_.title) |
| 95 forKey:app_mode::kCrAppModeShortcutNameKey]; | 96 forKey:app_mode::kCrAppModeShortcutNameKey]; |
| 96 [dict setObject:base::SysUTF8ToNSString(info_.url.spec()) | 97 [dict setObject:base::SysUTF8ToNSString(info_.url.spec()) |
| 97 forKey:app_mode::kCrAppModeShortcutURLKey]; | 98 forKey:app_mode::kCrAppModeShortcutURLKey]; |
| 99 [dict setObject:base::mac::FilePathToNSString(web_app_path_) |
| 100 forKey:app_mode::kCrAppModeUserDataDirKey]; |
| 98 return [dict writeToFile:plist_path atomically:YES]; | 101 return [dict writeToFile:plist_path atomically:YES]; |
| 99 } | 102 } |
| 100 | 103 |
| 101 bool WebAppShortcutCreator::UpdateIcon(const FilePath& app_path) const { | 104 bool WebAppShortcutCreator::UpdateIcon(const FilePath& app_path) const { |
| 102 // TODO:(sail) Need to implement this. | 105 // TODO:(sail) Need to implement this. |
| 103 return true; | 106 return true; |
| 104 } | 107 } |
| 105 | 108 |
| 106 } // namespace | 109 } // namespace |
| 107 | 110 |
| 108 namespace web_app { | 111 namespace web_app { |
| 109 namespace internals { | 112 namespace internals { |
| 110 | 113 |
| 111 void CreateShortcutTask(const FilePath& web_app_path, | 114 void CreateShortcutTask(const FilePath& web_app_path, |
| 112 const FilePath& profile_path, | 115 const FilePath& profile_path, |
| 113 const ShellIntegration::ShortcutInfo& shortcut_info) { | 116 const ShellIntegration::ShortcutInfo& shortcut_info) { |
| 114 WebAppShortcutCreator shortcut_creator(shortcut_info); | 117 WebAppShortcutCreator shortcut_creator(web_app_path, shortcut_info); |
| 115 shortcut_creator.CreateShortcut(); | 118 shortcut_creator.CreateShortcut(); |
| 116 } | 119 } |
| 117 | 120 |
| 118 } // namespace internals | 121 } // namespace internals |
| 119 } // namespace web_app | 122 } // namespace web_app |
| OLD | NEW |