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

Side by Side Diff: chrome/common/mac/app_mode_chrome_locator.mm

Issue 265163006: [Mac] Rebuild app shims when they fail to dyload Chrome Framework. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix compile on android Created 6 years, 6 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/common/mac/app_mode_chrome_locator.h" 5 #import "chrome/common/mac/app_mode_chrome_locator.h"
6 6
7 #import <AppKit/AppKit.h> 7 #import <AppKit/AppKit.h>
8 #include <CoreFoundation/CoreFoundation.h> 8 #include <CoreFoundation/CoreFoundation.h>
9 9
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/mac/foundation_util.h" 11 #include "base/mac/foundation_util.h"
12 #include "base/strings/sys_string_conversions.h" 12 #include "base/strings/sys_string_conversions.h"
13 #include "chrome/common/chrome_constants.h" 13 #include "chrome/common/chrome_constants.h"
14 14
15 namespace app_mode { 15 namespace app_mode {
16 16
17 bool FindBundleById(NSString* bundle_id, base::FilePath* out_bundle) { 17 bool FindBundleById(NSString* bundle_id, base::FilePath* out_bundle) {
18 NSWorkspace* ws = [NSWorkspace sharedWorkspace]; 18 NSWorkspace* ws = [NSWorkspace sharedWorkspace];
19 NSString *bundlePath = [ws absolutePathForAppBundleWithIdentifier:bundle_id]; 19 NSString *bundlePath = [ws absolutePathForAppBundleWithIdentifier:bundle_id];
20 if (!bundlePath) 20 if (!bundlePath)
21 return false; 21 return false;
22 22
23 *out_bundle = base::mac::NSStringToFilePath(bundlePath); 23 *out_bundle = base::mac::NSStringToFilePath(bundlePath);
24 return true; 24 return true;
25 } 25 }
26 26
27 bool GetChromeBundleInfo(const base::FilePath& chrome_bundle, 27 bool GetChromeBundleInfo(const base::FilePath& chrome_bundle,
28 base::FilePath* executable_path,
28 base::string16* raw_version_str, 29 base::string16* raw_version_str,
29 base::FilePath* version_path, 30 base::FilePath* version_path,
30 base::FilePath* framework_shlib_path) { 31 base::FilePath* framework_shlib_path) {
31 using base::mac::ObjCCast; 32 using base::mac::ObjCCast;
32 33
33 NSString* cr_bundle_path = base::mac::FilePathToNSString(chrome_bundle); 34 NSString* cr_bundle_path = base::mac::FilePathToNSString(chrome_bundle);
34 NSBundle* cr_bundle = [NSBundle bundleWithPath:cr_bundle_path]; 35 NSBundle* cr_bundle = [NSBundle bundleWithPath:cr_bundle_path];
35 36
36 if (!cr_bundle) 37 if (!cr_bundle)
37 return false; 38 return false;
(...skipping 12 matching lines...) Expand all
50 @"Versions", 51 @"Versions",
51 cr_version, 52 cr_version,
52 nil]; 53 nil];
53 NSString* cr_versioned_path = 54 NSString* cr_versioned_path =
54 [NSString pathWithComponents:cr_versioned_path_components]; 55 [NSString pathWithComponents:cr_versioned_path_components];
55 56
56 // Get the framework path. 57 // Get the framework path.
57 NSString* cr_bundle_exe = 58 NSString* cr_bundle_exe =
58 ObjCCast<NSString>( 59 ObjCCast<NSString>(
59 [cr_bundle objectForInfoDictionaryKey:@"CFBundleExecutable"]); 60 [cr_bundle objectForInfoDictionaryKey:@"CFBundleExecutable"]);
61 // Essentially we want chrome::kFrameworkName which looks like
62 // "$PRODUCT_STRING Framework.framework". The library itself is at
63 // "$PRODUCT_STRING Framework.framework/$PRODUCT_STRING Framework". Note that
64 // $PRODUCT_STRING is not |cr_bundle_exe| because in Canary the framework is
65 // still called "Google Chrome Framework".
66 // However, we want the shims to be agnostic to distribution and operate based
67 // on the data in their plist, so encode the framework names here.
68 NSDictionary* framework_for_exe = @{
69 @"Chromium": @"Chromium",
70 @"Google Chrome": @"Google Chrome",
71 @"Google Chrome Canary": @"Google Chrome",
72 };
73 NSString* framework_name = [framework_for_exe objectForKey:cr_bundle_exe];
60 NSString* cr_framework_shlib_path = 74 NSString* cr_framework_shlib_path =
61 [cr_versioned_path stringByAppendingPathComponent: 75 [cr_versioned_path stringByAppendingPathComponent:
62 base::SysUTF8ToNSString(chrome::kFrameworkName)]; 76 [framework_name stringByAppendingString:@" Framework.framework"]];
63 // chrome::kFrameworkName looks like "$PRODUCT_STRING Framework.framework".
64 // The library itself is at
65 // "$PRODUCT_STRING Framework.framework/$PRODUCT_STRING Framework", so we cut
66 // off the .framework extension here and append it to the path.
67 // It's important to build the path to the framework this way because
68 // in Canary the framework is still called "Google Chrome Framework".
69 cr_framework_shlib_path = 77 cr_framework_shlib_path =
70 [cr_framework_shlib_path stringByAppendingPathComponent: 78 [cr_framework_shlib_path stringByAppendingPathComponent:
71 [base::SysUTF8ToNSString(chrome::kFrameworkName) 79 [framework_name stringByAppendingString:@" Framework"]];
72 stringByDeletingPathExtension]];
73 if (!cr_bundle_exe || !cr_framework_shlib_path) 80 if (!cr_bundle_exe || !cr_framework_shlib_path)
74 return false; 81 return false;
75 82
76 // A few more sanity checks. 83 // A few more sanity checks.
77 BOOL is_directory; 84 BOOL is_directory;
78 BOOL exists = [[NSFileManager defaultManager] 85 BOOL exists = [[NSFileManager defaultManager]
79 fileExistsAtPath:cr_framework_shlib_path 86 fileExistsAtPath:cr_framework_shlib_path
80 isDirectory:&is_directory]; 87 isDirectory:&is_directory];
81 if (!exists || is_directory) 88 if (!exists || is_directory)
82 return false; 89 return false;
83 90
84 // Everything OK, copy output parameters. 91 // Everything OK, copy output parameters.
92 *executable_path = base::mac::NSStringToFilePath([cr_bundle executablePath]);
85 *raw_version_str = base::SysNSStringToUTF16(cr_version); 93 *raw_version_str = base::SysNSStringToUTF16(cr_version);
86 *version_path = base::mac::NSStringToFilePath(cr_versioned_path); 94 *version_path = base::mac::NSStringToFilePath(cr_versioned_path);
87 *framework_shlib_path = 95 *framework_shlib_path =
88 base::mac::NSStringToFilePath(cr_framework_shlib_path); 96 base::mac::NSStringToFilePath(cr_framework_shlib_path);
89 return true; 97 return true;
90 } 98 }
91 99
92 } // namespace app_mode 100 } // namespace app_mode
OLDNEW
« no previous file with comments | « chrome/common/mac/app_mode_chrome_locator.h ('k') | chrome/common/mac/app_mode_chrome_locator_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698