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() | |
|
tapted
2013/06/11 06:15:12
I think this block can be omitted -- user_data_dir
jackhou1
2013/06/12 06:54:46
The user_data_dir_ here belongs to the app. I.e. <
tapted
2013/06/12 08:26:39
Eep. Let's fix the name. And the header comment --
jackhou1
2013/06/12 09:05:18
Done.
| |
| 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 LOG(ERROR) << "Copying app to user_data_dir: " << user_data_dir_.value() | |
|
tapted
2013/06/11 06:15:12
Here, I think `NOTREACHED(); return false;` -- web
jackhou1
2013/06/12 06:54:46
Done.
| |
| 234 << " failed."; | |
| 227 return false; | 235 return false; |
| 228 } | 236 } |
| 237 base::mac::RemoveQuarantineAttribute(user_data_dir_.Append(app_name)); | |
| 229 | 238 |
| 239 if (!file_util::CopyDirectory(staging_path, dst_path, true)) { | |
| 240 LOG(ERROR) << "Copying app to applications directory: " << dst_path.value() | |
|
tapted
2013/06/11 06:15:12
Logging probably isn't desirable here either -- no
jackhou1
2013/06/12 06:54:46
Done.
| |
| 241 << " failed."; | |
| 242 return false; | |
| 243 } | |
| 230 base::mac::RemoveQuarantineAttribute(app_path); | 244 base::mac::RemoveQuarantineAttribute(app_path); |
| 245 | |
| 231 RevealGeneratedBundleInFinder(app_path); | 246 RevealGeneratedBundleInFinder(app_path); |
| 232 | 247 |
| 233 return true; | 248 return true; |
| 234 } | 249 } |
| 235 | 250 |
| 236 base::FilePath WebAppShortcutCreator::GetAppLoaderPath() const { | 251 base::FilePath WebAppShortcutCreator::GetAppLoaderPath() const { |
| 237 return base::mac::PathForFrameworkBundleResource( | 252 return base::mac::PathForFrameworkBundleResource( |
| 238 base::mac::NSToCFCast(@"app_mode_loader.app")); | 253 base::mac::NSToCFCast(@"app_mode_loader.app")); |
| 239 } | 254 } |
| 240 | 255 |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 375 const base::FilePath& generated_bundle) const { | 390 const base::FilePath& generated_bundle) const { |
| 376 [[NSWorkspace sharedWorkspace] | 391 [[NSWorkspace sharedWorkspace] |
| 377 selectFile:base::mac::FilePathToNSString(generated_bundle) | 392 selectFile:base::mac::FilePathToNSString(generated_bundle) |
| 378 inFileViewerRootedAtPath:nil]; | 393 inFileViewerRootedAtPath:nil]; |
| 379 } | 394 } |
| 380 | 395 |
| 381 void LaunchShimOnFileThread( | 396 void LaunchShimOnFileThread( |
| 382 const ShellIntegration::ShortcutInfo& shortcut_info) { | 397 const ShellIntegration::ShortcutInfo& shortcut_info) { |
| 383 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); | 398 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); |
| 384 base::FilePath shim_path = web_app::GetAppInstallPath(shortcut_info); | 399 base::FilePath shim_path = web_app::GetAppInstallPath(shortcut_info); |
| 385 if (shim_path.empty()) | 400 if (shim_path.empty()) |
|
tapted
2013/06/11 06:15:12
can this still be true for cases we can recover fr
jackhou1
2013/06/12 06:54:46
Done.
| |
| 386 return; | 401 return; |
| 387 | 402 |
| 403 // If it's not there, the user may have deleted it, use the one in the app's | |
| 404 // user_data_dir. | |
|
tapted
2013/06/11 06:15:12
nit: maybe more correct to say "the web app's data
jackhou1
2013/06/12 06:54:46
Done.
| |
| 405 if (!file_util::PathExists(shim_path)) { | |
| 406 base::FilePath shortcut_data_dir = GetWebAppDataDirectory( | |
| 407 shortcut_info.profile_path, shortcut_info.extension_id, GURL()); | |
| 408 shim_path = shortcut_data_dir.Append(shim_path.BaseName()); | |
| 409 } | |
| 410 | |
| 388 CommandLine command_line(CommandLine::NO_PROGRAM); | 411 CommandLine command_line(CommandLine::NO_PROGRAM); |
| 389 command_line.AppendSwitch(app_mode::kNoLaunchApp); | 412 command_line.AppendSwitch(app_mode::kNoLaunchApp); |
| 390 base::mac::OpenApplicationWithPath(shim_path, command_line, NULL); | 413 base::mac::OpenApplicationWithPath(shim_path, command_line, NULL); |
| 391 } | 414 } |
| 392 | 415 |
| 393 } // namespace | 416 } // namespace |
| 394 | 417 |
| 395 namespace web_app { | 418 namespace web_app { |
| 396 | 419 |
| 397 base::FilePath GetAppInstallPath( | 420 base::FilePath GetAppInstallPath( |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 456 const base::FilePath& web_app_path, | 479 const base::FilePath& web_app_path, |
| 457 const string16& old_app_title, | 480 const string16& old_app_title, |
| 458 const ShellIntegration::ShortcutInfo& shortcut_info) { | 481 const ShellIntegration::ShortcutInfo& shortcut_info) { |
| 459 // TODO(benwells): Implement this when shortcuts / weblings are enabled on | 482 // TODO(benwells): Implement this when shortcuts / weblings are enabled on |
| 460 // mac. | 483 // mac. |
| 461 } | 484 } |
| 462 | 485 |
| 463 } // namespace internals | 486 } // namespace internals |
| 464 | 487 |
| 465 } // namespace web_app | 488 } // namespace web_app |
| OLD | NEW |