Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(378)

Side by Side Diff: chrome/browser/web_applications/web_app_mac.mm

Issue 14579006: Start app shim when app launched. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 8
9 #include "base/callback.h"
10 #include "base/command_line.h"
9 #include "base/file_util.h" 11 #include "base/file_util.h"
10 #include "base/files/scoped_temp_dir.h" 12 #include "base/files/scoped_temp_dir.h"
11 #include "base/mac/bundle_locations.h" 13 #include "base/mac/bundle_locations.h"
12 #include "base/mac/foundation_util.h" 14 #include "base/mac/foundation_util.h"
15 #include "base/mac/launch_services_util.h"
13 #include "base/mac/mac_logging.h" 16 #include "base/mac/mac_logging.h"
14 #include "base/mac/mac_util.h" 17 #include "base/mac/mac_util.h"
15 #include "base/mac/scoped_cftyperef.h" 18 #include "base/mac/scoped_cftyperef.h"
16 #include "base/memory/scoped_nsobject.h" 19 #include "base/memory/scoped_nsobject.h"
17 #include "base/strings/sys_string_conversions.h" 20 #include "base/strings/sys_string_conversions.h"
18 #include "base/utf_string_conversions.h" 21 #include "base/utf_string_conversions.h"
22 #include "chrome/common/chrome_switches.h"
23 #include "chrome/browser/profiles/profile.h"
24 #include "chrome/browser/ui/web_applications/web_app_ui.h"
19 #include "chrome/browser/web_applications/web_app.h" 25 #include "chrome/browser/web_applications/web_app.h"
20 #include "chrome/common/chrome_paths_internal.h" 26 #include "chrome/common/chrome_paths_internal.h"
21 #include "chrome/common/mac/app_mode_common.h" 27 #include "chrome/common/mac/app_mode_common.h"
22 #include "content/public/browser/browser_thread.h" 28 #include "content/public/browser/browser_thread.h"
23 #include "grit/chromium_strings.h" 29 #include "grit/chromium_strings.h"
24 #include "skia/ext/skia_utils_mac.h" 30 #include "skia/ext/skia_utils_mac.h"
25 #include "third_party/icon_family/IconFamily.h" 31 #include "third_party/icon_family/IconFamily.h"
26 #include "ui/base/l10n/l10n_util_mac.h" 32 #include "ui/base/l10n/l10n_util_mac.h"
27 #include "ui/gfx/image/image_family.h" 33 #include "ui/gfx/image/image_family.h"
28 34
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 if (base::mac::GetUserDirectory(NSApplicationDirectory, &path)) 100 if (base::mac::GetUserDirectory(NSApplicationDirectory, &path))
95 return path; 101 return path;
96 return base::FilePath(); 102 return base::FilePath();
97 } 103 }
98 104
99 } // namespace 105 } // namespace
100 106
101 107
102 namespace web_app { 108 namespace web_app {
103 109
110 const char kNoLaunchApp[] = "no-launch-app";
tapted 2013/05/16 04:51:00 we can't have this in 2 places
111
104 const char kChromeAppDirName[] = "Chrome Apps.localized"; 112 const char kChromeAppDirName[] = "Chrome Apps.localized";
tapted 2013/05/16 04:51:00 this either
105 113
106 WebAppShortcutCreator::WebAppShortcutCreator( 114 WebAppShortcutCreator::WebAppShortcutCreator(
107 const base::FilePath& user_data_dir, 115 const base::FilePath& user_data_dir,
108 const ShellIntegration::ShortcutInfo& shortcut_info, 116 const ShellIntegration::ShortcutInfo& shortcut_info,
109 const string16& chrome_bundle_id) 117 const string16& chrome_bundle_id)
110 : user_data_dir_(user_data_dir), 118 : user_data_dir_(user_data_dir),
111 info_(shortcut_info), 119 info_(shortcut_info),
112 chrome_bundle_id_(chrome_bundle_id) { 120 chrome_bundle_id_(chrome_bundle_id) {
113 } 121 }
114 122
115 WebAppShortcutCreator::~WebAppShortcutCreator() { 123 WebAppShortcutCreator::~WebAppShortcutCreator() {
116 } 124 }
117 125
126 base::FilePath WebAppShortcutCreator::GetShortcutPath() const {
127 base::FilePath dst_path = GetDestinationPath();
128 if (dst_path.empty())
129 return dst_path;
130
131 base::FilePath app_name = internals::GetSanitizedFileName(info_.title);
132 return dst_path.Append(app_name.ReplaceExtension("app"));
133 }
134
118 bool WebAppShortcutCreator::CreateShortcut() { 135 bool WebAppShortcutCreator::CreateShortcut() {
119 base::FilePath app_name = internals::GetSanitizedFileName(info_.title); 136 base::FilePath app_name = internals::GetSanitizedFileName(info_.title);
120 base::FilePath app_file_name = app_name.ReplaceExtension("app"); 137 base::FilePath app_file_name = app_name.ReplaceExtension("app");
121 base::FilePath dst_path = GetDestinationPath(); 138 base::FilePath dst_path = GetDestinationPath();
122 if (dst_path.empty() || !file_util::DirectoryExists(dst_path.DirName())) { 139 if (dst_path.empty() || !file_util::DirectoryExists(dst_path.DirName())) {
123 LOG(ERROR) << "Couldn't find an Applications directory to copy app to."; 140 LOG(ERROR) << "Couldn't find an Applications directory to copy app to.";
124 return false; 141 return false;
125 } 142 }
126 if (!file_util::CreateDirectory(dst_path)) { 143 if (!file_util::CreateDirectory(dst_path)) {
127 LOG(ERROR) << "Creating directory " << dst_path.value() << " failed."; 144 LOG(ERROR) << "Creating directory " << dst_path.value() << " failed.";
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 file_util::Delete(bundle_path, true); 341 file_util::Delete(bundle_path, true);
325 } 342 }
326 343
327 void UpdatePlatformShortcuts( 344 void UpdatePlatformShortcuts(
328 const base::FilePath& web_app_path, 345 const base::FilePath& web_app_path,
329 const ShellIntegration::ShortcutInfo& shortcut_info) { 346 const ShellIntegration::ShortcutInfo& shortcut_info) {
330 // TODO(benwells): Implement this when shortcuts / weblings are enabled on 347 // TODO(benwells): Implement this when shortcuts / weblings are enabled on
331 // mac. 348 // mac.
332 } 349 }
333 350
351 void LaunchShimOnFileThread(Profile* profile,
352 const extensions::Extension* extension,
353 base::Callback<void(bool)> completed) {
354 WebAppShortcutCreator shortcut_creator(
355 CommandLine::ForCurrentProcess()->
356 GetSwitchValuePath(switches::kUserDataDir),
357 web_app::ShortcutInfoForExtensionAndProfile(extension, profile),
358 UTF8ToUTF16(base::mac::BaseBundleID()));
359
360 base::FilePath shim_path = shortcut_creator.GetShortcutPath();
tapted 2013/05/16 04:51:00 can this logic be merged with the logic in FindAnd
361 LOG(INFO) << "LaunchShimOnFileThread " << shim_path.value();
362 if (shim_path.empty()) {
363 content::BrowserThread::PostTask(
364 content::BrowserThread::UI, FROM_HERE, base::Bind(completed, false));
365 return;
366 }
367 CommandLine command_line(CommandLine::NO_PROGRAM);
368 command_line.AppendSwitch(kNoLaunchApp);
369 base::mac::OpenApplicationWithPath(shim_path, command_line, NULL);
370 content::BrowserThread::PostTask(
371 content::BrowserThread::UI, FROM_HERE, base::Bind(completed, true));
372 }
373
374 void LaunchShim(Profile* profile,
375 const extensions::Extension* extension,
376 base::Callback<void(bool)> completed) {
377 content::BrowserThread::PostTask(
378 content::BrowserThread::FILE, FROM_HERE,
379 base::Bind(&LaunchShimOnFileThread, profile, extension, completed));
380 }
381
334 } // namespace internals 382 } // namespace internals
335 383
336 } // namespace web_app 384 } // namespace web_app
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698