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

Side by Side Diff: chrome/browser/web_applications/web_app_mac.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
« no previous file with comments | « chrome/browser/web_applications/web_app_mac.h ('k') | chrome/chrome.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <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"
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/files/file_enumerator.h" 12 #include "base/files/file_enumerator.h"
13 #include "base/files/scoped_temp_dir.h" 13 #include "base/files/scoped_temp_dir.h"
14 #include "base/mac/foundation_util.h" 14 #include "base/mac/foundation_util.h"
15 #include "base/mac/launch_services_util.h" 15 #include "base/mac/launch_services_util.h"
16 #include "base/mac/mac_util.h" 16 #include "base/mac/mac_util.h"
17 #include "base/mac/scoped_cftyperef.h" 17 #include "base/mac/scoped_cftyperef.h"
18 #include "base/mac/scoped_nsobject.h" 18 #include "base/mac/scoped_nsobject.h"
19 #include "base/path_service.h" 19 #include "base/path_service.h"
20 #include "base/process/process_handle.h" 20 #include "base/process/process_handle.h"
21 #include "base/strings/string16.h" 21 #include "base/strings/string16.h"
22 #include "base/strings/string_number_conversions.h" 22 #include "base/strings/string_number_conversions.h"
23 #include "base/strings/string_split.h"
23 #include "base/strings/string_util.h" 24 #include "base/strings/string_util.h"
24 #include "base/strings/sys_string_conversions.h" 25 #include "base/strings/sys_string_conversions.h"
25 #include "base/strings/utf_string_conversions.h" 26 #include "base/strings/utf_string_conversions.h"
27 #include "chrome/browser/browser_process.h"
26 #import "chrome/browser/mac/dock.h" 28 #import "chrome/browser/mac/dock.h"
27 #include "chrome/browser/browser_process.h" 29 #include "chrome/browser/browser_process.h"
28 #include "chrome/browser/profiles/profile.h" 30 #include "chrome/browser/profiles/profile.h"
29 #include "chrome/browser/profiles/profile_manager.h" 31 #include "chrome/browser/profiles/profile_manager.h"
30 #include "chrome/browser/shell_integration.h" 32 #include "chrome/browser/shell_integration.h"
33 #include "chrome/browser/ui/app_list/app_list_service.h"
31 #include "chrome/common/chrome_constants.h" 34 #include "chrome/common/chrome_constants.h"
32 #include "chrome/common/chrome_paths.h" 35 #include "chrome/common/chrome_paths.h"
33 #include "chrome/common/chrome_switches.h" 36 #include "chrome/common/chrome_switches.h"
34 #include "chrome/common/chrome_version_info.h" 37 #include "chrome/common/chrome_version_info.h"
35 #import "chrome/common/mac/app_mode_common.h" 38 #import "chrome/common/mac/app_mode_common.h"
36 #include "content/public/browser/browser_thread.h" 39 #include "content/public/browser/browser_thread.h"
37 #include "extensions/browser/extension_registry.h" 40 #include "extensions/browser/extension_registry.h"
38 #include "extensions/common/extension.h" 41 #include "extensions/common/extension.h"
39 #include "grit/chrome_unscaled_resources.h" 42 #include "grit/chrome_unscaled_resources.h"
40 #include "grit/chromium_strings.h" 43 #include "grit/chromium_strings.h"
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 base::FilePath user_data_dir; 210 base::FilePath user_data_dir;
208 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); 211 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
209 DCHECK(!user_data_dir.empty()); 212 DCHECK(!user_data_dir.empty());
210 return StartsWithASCII( 213 return StartsWithASCII(
211 base::SysNSStringToUTF8( 214 base::SysNSStringToUTF8(
212 [plist valueForKey:app_mode::kCrAppModeUserDataDirKey]), 215 [plist valueForKey:app_mode::kCrAppModeUserDataDirKey]),
213 user_data_dir.value(), 216 user_data_dir.value(),
214 true /* case_sensitive */); 217 true /* case_sensitive */);
215 } 218 }
216 219
217 void LaunchShimOnFileThread( 220 void LaunchShimOnFileThread(const web_app::ShortcutInfo& shortcut_info,
218 const web_app::ShortcutInfo& shortcut_info) { 221 bool launched_after_rebuild) {
219 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); 222 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
220 base::FilePath shim_path = web_app::GetAppInstallPath(shortcut_info); 223 base::FilePath shim_path = web_app::GetAppInstallPath(shortcut_info);
221 224
222 if (shim_path.empty() || 225 if (shim_path.empty() ||
223 !base::PathExists(shim_path) || 226 !base::PathExists(shim_path) ||
224 !HasSameUserDataDir(shim_path)) { 227 !HasSameUserDataDir(shim_path)) {
225 // The user may have deleted the copy in the Applications folder, use the 228 // The user may have deleted the copy in the Applications folder, use the
226 // one in the web app's |app_data_dir_|. 229 // one in the web app's |app_data_dir_|.
227 base::FilePath app_data_dir = web_app::GetWebAppDataDirectory( 230 base::FilePath app_data_dir = web_app::GetWebAppDataDirectory(
228 shortcut_info.profile_path, shortcut_info.extension_id, GURL()); 231 shortcut_info.profile_path, shortcut_info.extension_id, GURL());
229 shim_path = app_data_dir.Append(shim_path.BaseName()); 232 shim_path = app_data_dir.Append(shim_path.BaseName());
230 } 233 }
231 234
232 if (!base::PathExists(shim_path)) 235 if (!base::PathExists(shim_path))
233 return; 236 return;
234 237
235 CommandLine command_line(CommandLine::NO_PROGRAM); 238 CommandLine command_line(CommandLine::NO_PROGRAM);
236 command_line.AppendSwitchASCII( 239 command_line.AppendSwitchASCII(
237 app_mode::kLaunchedByChromeProcessId, 240 app_mode::kLaunchedByChromeProcessId,
238 base::IntToString(base::GetCurrentProcId())); 241 base::IntToString(base::GetCurrentProcId()));
242 if (launched_after_rebuild)
243 command_line.AppendSwitch(app_mode::kLaunchedAfterRebuild);
239 // Launch without activating (kLSLaunchDontSwitch). 244 // Launch without activating (kLSLaunchDontSwitch).
240 base::mac::OpenApplicationWithPath( 245 base::mac::OpenApplicationWithPath(
241 shim_path, command_line, kLSLaunchDefaults | kLSLaunchDontSwitch, NULL); 246 shim_path, command_line, kLSLaunchDefaults | kLSLaunchDontSwitch, NULL);
242 } 247 }
243 248
244 base::FilePath GetAppLoaderPath() { 249 base::FilePath GetAppLoaderPath() {
245 return base::mac::PathForFrameworkBundleResource( 250 return base::mac::PathForFrameworkBundleResource(
246 base::mac::NSToCFCast(@"app_mode_loader.app")); 251 base::mac::NSToCFCast(@"app_mode_loader.app"));
247 } 252 }
248 253
254 void UpdateAndLaunchShimOnFileThread(
255 const web_app::ShortcutInfo& shortcut_info,
256 const extensions::FileHandlersInfo& file_handlers_info) {
257 base::FilePath shortcut_data_dir = web_app::GetWebAppDataDirectory(
258 shortcut_info.profile_path, shortcut_info.extension_id, GURL());
259 web_app::internals::UpdatePlatformShortcuts(
260 shortcut_data_dir, base::string16(), shortcut_info, file_handlers_info);
261 LaunchShimOnFileThread(shortcut_info, true);
262 }
263
264 void UpdateAndLaunchShim(
265 const web_app::ShortcutInfo& shortcut_info,
266 const extensions::FileHandlersInfo& file_handlers_info) {
267 content::BrowserThread::PostTask(
268 content::BrowserThread::FILE,
269 FROM_HERE,
270 base::Bind(
271 &UpdateAndLaunchShimOnFileThread, shortcut_info, file_handlers_info));
272 }
273
274 void RebuildAppAndLaunch(const web_app::ShortcutInfo& shortcut_info) {
275 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
276 if (shortcut_info.extension_id == app_mode::kAppListModeId) {
277 AppListService* app_list_service =
278 AppListService::Get(chrome::HOST_DESKTOP_TYPE_NATIVE);
279 app_list_service->CreateShortcut();
280 app_list_service->Show();
281 return;
282 }
283
284 ProfileManager* profile_manager = g_browser_process->profile_manager();
285 Profile* profile =
286 profile_manager->GetProfileByPath(shortcut_info.profile_path);
287 if (!profile || !profile_manager->IsValidProfile(profile))
288 return;
289
290 extensions::ExtensionRegistry* registry =
291 extensions::ExtensionRegistry::Get(profile);
292 const extensions::Extension* extension = registry->GetExtensionById(
293 shortcut_info.extension_id, extensions::ExtensionRegistry::ENABLED);
294 if (!extension || !extension->is_platform_app())
295 return;
296
297 web_app::internals::GetInfoForApp(
298 extension, profile, base::Bind(&UpdateAndLaunchShim));
299 }
300
249 base::FilePath GetLocalizableAppShortcutsSubdirName() { 301 base::FilePath GetLocalizableAppShortcutsSubdirName() {
250 static const char kChromiumAppDirName[] = "Chromium Apps.localized"; 302 static const char kChromiumAppDirName[] = "Chromium Apps.localized";
251 static const char kChromeAppDirName[] = "Chrome Apps.localized"; 303 static const char kChromeAppDirName[] = "Chrome Apps.localized";
252 static const char kChromeCanaryAppDirName[] = "Chrome Canary Apps.localized"; 304 static const char kChromeCanaryAppDirName[] = "Chrome Canary Apps.localized";
253 305
254 switch (chrome::VersionInfo::GetChannel()) { 306 switch (chrome::VersionInfo::GetChannel()) {
255 case chrome::VersionInfo::CHANNEL_UNKNOWN: 307 case chrome::VersionInfo::CHANNEL_UNKNOWN:
256 return base::FilePath(kChromiumAppDirName); 308 return base::FilePath(kChromiumAppDirName);
257 309
258 case chrome::VersionInfo::CHANNEL_CANARY: 310 case chrome::VersionInfo::CHANNEL_CANARY:
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after
868 return shortcut_creator.GetApplicationsShortcutPath(); 920 return shortcut_creator.GetApplicationsShortcutPath();
869 } 921 }
870 922
871 void MaybeLaunchShortcut(const ShortcutInfo& shortcut_info) { 923 void MaybeLaunchShortcut(const ShortcutInfo& shortcut_info) {
872 if (AppShimsDisabledForTest() && 924 if (AppShimsDisabledForTest() &&
873 !g_app_shims_allow_update_and_launch_in_tests) { 925 !g_app_shims_allow_update_and_launch_in_tests) {
874 return; 926 return;
875 } 927 }
876 928
877 content::BrowserThread::PostTask( 929 content::BrowserThread::PostTask(
878 content::BrowserThread::FILE, FROM_HERE, 930 content::BrowserThread::FILE,
879 base::Bind(&LaunchShimOnFileThread, shortcut_info)); 931 FROM_HERE,
932 base::Bind(&LaunchShimOnFileThread, shortcut_info, false));
933 }
934
935 bool MaybeRebuildShortcut(const CommandLine& command_line) {
936 if (!command_line.HasSwitch(app_mode::kAppShimError))
937 return false;
938
939 base::PostTaskAndReplyWithResult(
940 content::BrowserThread::GetBlockingPool(),
941 FROM_HERE,
942 base::Bind(&BuildShortcutInfoFromBundle,
943 command_line.GetSwitchValuePath(app_mode::kAppShimError)),
944 base::Bind(&RebuildAppAndLaunch));
945 return true;
880 } 946 }
881 947
882 // Called when the app's ShortcutInfo (with icon) is loaded when creating app 948 // Called when the app's ShortcutInfo (with icon) is loaded when creating app
883 // shortcuts. 949 // shortcuts.
884 void CreateAppShortcutInfoLoaded( 950 void CreateAppShortcutInfoLoaded(
885 Profile* profile, 951 Profile* profile,
886 const extensions::Extension* app, 952 const extensions::Extension* app,
887 const base::Callback<void(bool)>& close_callback, 953 const base::Callback<void(bool)>& close_callback,
888 const ShortcutInfo& shortcut_info) { 954 const ShortcutInfo& shortcut_info) {
889 base::scoped_nsobject<NSAlert> alert([[NSAlert alloc] init]); 955 base::scoped_nsobject<NSAlert> alert([[NSAlert alloc] init]);
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
1023 web_app::UpdateShortcutInfoAndIconForApp( 1089 web_app::UpdateShortcutInfoAndIconForApp(
1024 app, 1090 app,
1025 profile, 1091 profile,
1026 base::Bind(&web_app::CreateAppShortcutInfoLoaded, 1092 base::Bind(&web_app::CreateAppShortcutInfoLoaded,
1027 profile, 1093 profile,
1028 app, 1094 app,
1029 close_callback)); 1095 close_callback));
1030 } 1096 }
1031 1097
1032 } // namespace chrome 1098 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/web_applications/web_app_mac.h ('k') | chrome/chrome.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698