Chromium Code Reviews| 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 #import "chrome/browser/web_applications/web_app_mac.h" | 5 #import "chrome/browser/web_applications/web_app_mac.h" |
| 6 | 6 |
| 7 #import <Carbon/Carbon.h> | 7 #import <Carbon/Carbon.h> |
| 8 #import <Cocoa/Cocoa.h> | 8 #import <Cocoa/Cocoa.h> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 188 } | 188 } |
| 189 | 189 |
| 190 bool WebAppShortcutCreator::CreateShortcut() { | 190 bool WebAppShortcutCreator::CreateShortcut() { |
| 191 base::FilePath app_path = GetShortcutPath(); | 191 base::FilePath app_path = GetShortcutPath(); |
| 192 base::FilePath app_name = app_path.BaseName(); | 192 base::FilePath app_name = app_path.BaseName(); |
| 193 base::FilePath dst_path = app_path.DirName(); | 193 base::FilePath dst_path = app_path.DirName(); |
| 194 if (app_path.empty() || !file_util::DirectoryExists(dst_path.DirName())) { | 194 if (app_path.empty() || !file_util::DirectoryExists(dst_path.DirName())) { |
| 195 LOG(ERROR) << "Couldn't find an Applications directory to copy app to."; | 195 LOG(ERROR) << "Couldn't find an Applications directory to copy app to."; |
| 196 return false; | 196 return false; |
| 197 } | 197 } |
| 198 if (!file_util::CreateDirectory(user_data_dir_)) { | |
| 199 LOG(ERROR) << "Creating user_data_dir " << user_data_dir_.value() | |
| 200 << " failed."; | |
| 201 return false; | |
| 202 } | |
| 198 if (!file_util::CreateDirectory(dst_path)) { | 203 if (!file_util::CreateDirectory(dst_path)) { |
| 199 LOG(ERROR) << "Creating directory " << dst_path.value() << " failed."; | 204 LOG(ERROR) << "Creating directory " << dst_path.value() << " failed."; |
| 200 return false; | 205 return false; |
| 201 } | 206 } |
| 202 | 207 |
| 203 base::ScopedTempDir scoped_temp_dir; | 208 base::ScopedTempDir scoped_temp_dir; |
| 204 if (!scoped_temp_dir.CreateUniqueTempDir()) | 209 if (!scoped_temp_dir.CreateUniqueTempDir()) |
| 205 return false; | 210 return false; |
| 206 base::FilePath staging_path = scoped_temp_dir.path().Append(app_name); | 211 base::FilePath staging_path = scoped_temp_dir.path().Append(app_name); |
| 207 | 212 |
| 208 // Update the app's plist and icon in a temp directory. This works around | 213 // Update the app's plist and icon in a temp directory. This works around |
| 209 // a Finder bug where the app's icon doesn't properly update. | 214 // a Finder bug where the app's icon doesn't properly update. |
| 210 if (!file_util::CopyDirectory(GetAppLoaderPath(), staging_path, true)) { | 215 if (!file_util::CopyDirectory(GetAppLoaderPath(), staging_path, true)) { |
| 211 LOG(ERROR) << "Copying app to staging path: " << staging_path.value() | 216 LOG(ERROR) << "Copying app to staging path: " << staging_path.value() |
| 212 << " failed"; | 217 << " failed."; |
| 213 return false; | 218 return false; |
| 214 } | 219 } |
| 215 | 220 |
| 216 if (!UpdatePlist(staging_path)) | 221 if (!UpdatePlist(staging_path)) |
| 217 return false; | 222 return false; |
| 218 | 223 |
| 219 if (!UpdateDisplayName(staging_path)) | 224 if (!UpdateDisplayName(staging_path)) |
| 220 return false; | 225 return false; |
| 221 | 226 |
| 222 if (!UpdateIcon(staging_path)) | 227 if (!UpdateIcon(staging_path)) |
| 223 return false; | 228 return false; |
| 224 | 229 |
| 225 if (!file_util::CopyDirectory(staging_path, dst_path, true)) { | 230 // Put one copy in the app's user_data_dir so we can still run it if the user |
| 226 LOG(ERROR) << "Copying app to dst path: " << dst_path.value() << " failed"; | 231 // deletes the one in the applications folder. |
| 232 if (!file_util::CopyDirectory(staging_path, user_data_dir_, true)) { | |
| 233 NOTREACHED(); | |
| 227 return false; | 234 return false; |
| 228 } | 235 } |
| 236 base::mac::RemoveQuarantineAttribute(user_data_dir_.Append(app_name)); | |
| 237 | |
| 238 if (!file_util::CopyDirectory(staging_path, dst_path, true)) | |
| 239 return false; | |
| 229 | 240 |
| 230 base::mac::RemoveQuarantineAttribute(app_path); | 241 base::mac::RemoveQuarantineAttribute(app_path); |
| 242 | |
| 231 RevealGeneratedBundleInFinder(app_path); | 243 RevealGeneratedBundleInFinder(app_path); |
| 232 | 244 |
| 233 return true; | 245 return true; |
| 234 } | 246 } |
| 235 | 247 |
| 236 base::FilePath WebAppShortcutCreator::GetAppLoaderPath() const { | 248 base::FilePath WebAppShortcutCreator::GetAppLoaderPath() const { |
| 237 return base::mac::PathForFrameworkBundleResource( | 249 return base::mac::PathForFrameworkBundleResource( |
| 238 base::mac::NSToCFCast(@"app_mode_loader.app")); | 250 base::mac::NSToCFCast(@"app_mode_loader.app")); |
| 239 } | 251 } |
| 240 | 252 |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 375 const base::FilePath& generated_bundle) const { | 387 const base::FilePath& generated_bundle) const { |
| 376 [[NSWorkspace sharedWorkspace] | 388 [[NSWorkspace sharedWorkspace] |
| 377 selectFile:base::mac::FilePathToNSString(generated_bundle) | 389 selectFile:base::mac::FilePathToNSString(generated_bundle) |
| 378 inFileViewerRootedAtPath:nil]; | 390 inFileViewerRootedAtPath:nil]; |
| 379 } | 391 } |
| 380 | 392 |
| 381 void LaunchShimOnFileThread( | 393 void LaunchShimOnFileThread( |
| 382 const ShellIntegration::ShortcutInfo& shortcut_info) { | 394 const ShellIntegration::ShortcutInfo& shortcut_info) { |
| 383 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); | 395 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); |
| 384 base::FilePath shim_path = web_app::GetAppInstallPath(shortcut_info); | 396 base::FilePath shim_path = web_app::GetAppInstallPath(shortcut_info); |
| 385 if (shim_path.empty()) | 397 |
| 386 return; | 398 if (!file_util::PathExists(shim_path)) { |
|
tapted
2013/06/12 08:37:56
This should be
if (shim_path.empty() || !file_ut
jackhou1
2013/06/12 09:05:18
Done.
| |
| 399 // The user may have deleted the copy in the Applications folder, use the | |
| 400 // one in the web app's user_data_dir. | |
| 401 base::FilePath shortcut_data_dir = GetWebAppDataDirectory( | |
| 402 shortcut_info.profile_path, shortcut_info.extension_id, GURL()); | |
| 403 shim_path = shortcut_data_dir.Append(shim_path.BaseName()); | |
| 404 } | |
| 387 | 405 |
| 388 CommandLine command_line(CommandLine::NO_PROGRAM); | 406 CommandLine command_line(CommandLine::NO_PROGRAM); |
| 389 command_line.AppendSwitch(app_mode::kNoLaunchApp); | 407 command_line.AppendSwitch(app_mode::kNoLaunchApp); |
| 390 base::mac::OpenApplicationWithPath(shim_path, command_line, NULL); | 408 base::mac::OpenApplicationWithPath(shim_path, command_line, NULL); |
| 391 } | 409 } |
| 392 | 410 |
| 393 } // namespace | 411 } // namespace |
| 394 | 412 |
| 395 namespace web_app { | 413 namespace web_app { |
| 396 | 414 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 456 const base::FilePath& web_app_path, | 474 const base::FilePath& web_app_path, |
| 457 const string16& old_app_title, | 475 const string16& old_app_title, |
| 458 const ShellIntegration::ShortcutInfo& shortcut_info) { | 476 const ShellIntegration::ShortcutInfo& shortcut_info) { |
| 459 // TODO(benwells): Implement this when shortcuts / weblings are enabled on | 477 // TODO(benwells): Implement this when shortcuts / weblings are enabled on |
| 460 // mac. | 478 // mac. |
| 461 } | 479 } |
| 462 | 480 |
| 463 } // namespace internals | 481 } // namespace internals |
| 464 | 482 |
| 465 } // namespace web_app | 483 } // namespace web_app |
| OLD | NEW |