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

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

Issue 9416012: Mac: Generate App Mode Loader bundle + cleanup (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Tweak Created 8 years, 10 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 #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
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
91 [dict setObject:base::SysUTF8ToNSString(info_.extension_id) 93 [dict setObject:GetBundleIdentifier(base::mac::ObjCCast<NSDictionary>(dict))
sail 2012/02/19 21:08:55 you don't need a base::mac::ObjCCast() here since
jeremy 2012/02/20 05:41:00 Done.
94 forKey:base::mac::CFToNSCast(kCFBundleIdentifierKey)];
95 NSString* extension_id = base::SysUTF8ToNSString(info_.extension_id);
sail 2012/02/19 21:08:55 you don't need this temp variable
jeremy 2012/02/20 05:41:00 Done.
96 [dict setObject:extension_id
92 forKey:app_mode::kCrAppModeShortcutIDKey]; 97 forKey:app_mode::kCrAppModeShortcutIDKey];
93 [dict setObject:base::SysUTF16ToNSString(info_.title) 98 [dict setObject:base::SysUTF16ToNSString(info_.title)
94 forKey:app_mode::kCrAppModeShortcutNameKey]; 99 forKey:app_mode::kCrAppModeShortcutNameKey];
95 [dict setObject:base::SysUTF8ToNSString(info_.url.spec()) 100 [dict setObject:base::SysUTF8ToNSString(info_.url.spec())
96 forKey:app_mode::kCrAppModeShortcutURLKey]; 101 forKey:app_mode::kCrAppModeShortcutURLKey];
102 [dict setObject:base::SysUTF16ToNSString(chrome_bundle_id_)
103 forKey:app_mode::kBrowserBundleIDKey];
97 return [dict writeToFile:plist_path atomically:YES]; 104 return [dict writeToFile:plist_path atomically:YES];
98 } 105 }
99 106
100 bool WebAppShortcutCreator::UpdateIcon(const FilePath& app_path) const { 107 bool WebAppShortcutCreator::UpdateIcon(const FilePath& app_path) const {
101 // TODO:(sail) Need to implement this. 108 // TODO:(sail) Need to implement this.
102 return true; 109 return true;
103 } 110 }
104 111
112 NSString* WebAppShortcutCreator::GetBundleIdentifier(NSDictionary* plist) const
113 {
114 NSString* bundle_id_template =
sail 2012/02/19 21:08:55 I didn't know about BaseBundleID(). That's very co
jeremy 2012/02/20 05:41:00 I prefer to keep it this way since: 1. It's easier
115 base::mac::ObjCCast<NSString>(
116 [plist objectForKey:base::mac::CFToNSCast(kCFBundleIdentifierKey)]);
117 NSString* extension_id = base::SysUTF8ToNSString(info_.extension_id);
118 NSString* bundle_id =
119 [bundle_id_template
120 stringByReplacingOccurrencesOfString:app_mode::kShortcutIdPlaceholder
121 withString:extension_id];
122 return bundle_id;
123 }
124
105 } // namespace 125 } // namespace
106 126
107 namespace web_app { 127 namespace web_app {
108 namespace internals { 128 namespace internals {
109 129
110 void CreateShortcutTask(const FilePath& web_app_path, 130 void CreateShortcutTask(const FilePath& web_app_path,
111 const FilePath& profile_path, 131 const FilePath& profile_path,
112 const ShellIntegration::ShortcutInfo& shortcut_info) { 132 const ShellIntegration::ShortcutInfo& shortcut_info) {
113 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); 133 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
114 WebAppShortcutCreator shortcut_creator(shortcut_info); 134 string16 bundle_id = UTF8ToUTF16(base::mac::BaseBundleID());
135 WebAppShortcutCreator shortcut_creator(shortcut_info, bundle_id);
115 shortcut_creator.CreateShortcut(); 136 shortcut_creator.CreateShortcut();
116 } 137 }
117 138
118 } // namespace internals 139 } // namespace internals
119 } // namespace web_app 140 } // namespace web_app
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698