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 #include "chrome/browser/web_applications/web_app.h" | 5 #include "chrome/browser/web_applications/web_app.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/i18n/file_util_icu.h" | 10 #include "base/i18n/file_util_icu.h" |
11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "base/threading/thread.h" | 14 #include "base/threading/thread.h" |
| 15 #include "chrome/browser/browser_process.h" |
15 #include "chrome/browser/extensions/extension_ui_util.h" | 16 #include "chrome/browser/extensions/extension_ui_util.h" |
16 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/profiles/profile_manager.h" |
17 #include "chrome/common/chrome_constants.h" | 19 #include "chrome/common/chrome_constants.h" |
18 #include "chrome/common/chrome_version_info.h" | 20 #include "chrome/common/chrome_version_info.h" |
19 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" | 21 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
20 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
21 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
22 #include "extensions/browser/extension_registry.h" | 24 #include "extensions/browser/extension_registry.h" |
23 #include "extensions/browser/image_loader.h" | 25 #include "extensions/browser/image_loader.h" |
24 #include "extensions/common/constants.h" | 26 #include "extensions/common/constants.h" |
25 #include "extensions/common/extension.h" | 27 #include "extensions/common/extension.h" |
26 #include "extensions/common/extension_set.h" | 28 #include "extensions/common/extension_set.h" |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 | 263 |
262 void GetShortcutInfoForApp(const extensions::Extension* extension, | 264 void GetShortcutInfoForApp(const extensions::Extension* extension, |
263 Profile* profile, | 265 Profile* profile, |
264 const ShortcutInfoCallback& callback) { | 266 const ShortcutInfoCallback& callback) { |
265 GetInfoForApp( | 267 GetInfoForApp( |
266 extension, profile, base::Bind(&IgnoreFileHandlersInfo, callback)); | 268 extension, profile, base::Bind(&IgnoreFileHandlersInfo, callback)); |
267 } | 269 } |
268 | 270 |
269 bool ShouldCreateShortcutFor(Profile* profile, | 271 bool ShouldCreateShortcutFor(Profile* profile, |
270 const extensions::Extension* extension) { | 272 const extensions::Extension* extension) { |
271 return extension->is_platform_app() && | 273 bool app_type_requires_shortcut = extension->is_platform_app(); |
272 extension->location() != extensions::Manifest::COMPONENT && | 274 |
273 extensions::ui_util::CanDisplayInAppLauncher(extension, profile); | 275 // An additional check here for OS X. We need app shims to be |
| 276 // able to show them in the dock. |
| 277 #if defined(OS_MACOSX) |
| 278 app_type_requires_shortcut = |
| 279 app_type_requires_shortcut || extension->is_hosted_app(); |
| 280 #endif |
| 281 |
| 282 return (app_type_requires_shortcut && |
| 283 extension->location() != extensions::Manifest::COMPONENT && |
| 284 extensions::ui_util::CanDisplayInAppLauncher(extension, profile)); |
274 } | 285 } |
275 | 286 |
276 base::FilePath GetWebAppDataDirectory(const base::FilePath& profile_path, | 287 base::FilePath GetWebAppDataDirectory(const base::FilePath& profile_path, |
277 const std::string& extension_id, | 288 const std::string& extension_id, |
278 const GURL& url) { | 289 const GURL& url) { |
279 DCHECK(!profile_path.empty()); | 290 DCHECK(!profile_path.empty()); |
280 base::FilePath app_data_dir(profile_path.Append(chrome::kWebAppDirname)); | 291 base::FilePath app_data_dir(profile_path.Append(chrome::kWebAppDirname)); |
281 | 292 |
282 if (!extension_id.empty()) { | 293 if (!extension_id.empty()) { |
283 return app_data_dir.AppendASCII( | 294 return app_data_dir.AppendASCII( |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 return app_name.substr(prefix.length()); | 347 return app_name.substr(prefix.length()); |
337 } | 348 } |
338 | 349 |
339 void CreateShortcutsWithInfo( | 350 void CreateShortcutsWithInfo( |
340 ShortcutCreationReason reason, | 351 ShortcutCreationReason reason, |
341 const ShortcutLocations& locations, | 352 const ShortcutLocations& locations, |
342 const ShortcutInfo& shortcut_info, | 353 const ShortcutInfo& shortcut_info, |
343 const extensions::FileHandlersInfo& file_handlers_info) { | 354 const extensions::FileHandlersInfo& file_handlers_info) { |
344 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 355 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
345 | 356 |
| 357 // It's possible for the extension to be deleted before we get here. |
| 358 // For example, creating a hosted app from a website. Double check that |
| 359 // it still exists. |
| 360 Profile* profile = g_browser_process->profile_manager()->GetProfileByPath( |
| 361 shortcut_info.profile_path); |
| 362 if (!profile) |
| 363 return; |
| 364 |
| 365 extensions::ExtensionRegistry* registry = |
| 366 extensions::ExtensionRegistry::Get(profile); |
| 367 const extensions::Extension* extension = registry->GetExtensionById( |
| 368 shortcut_info.extension_id, extensions::ExtensionRegistry::ENABLED); |
| 369 if (!extension) |
| 370 return; |
| 371 |
346 BrowserThread::PostTask( | 372 BrowserThread::PostTask( |
347 BrowserThread::FILE, | 373 BrowserThread::FILE, |
348 FROM_HERE, | 374 FROM_HERE, |
349 base::Bind(base::IgnoreResult(&internals::CreatePlatformShortcuts), | 375 base::Bind(base::IgnoreResult(&internals::CreatePlatformShortcuts), |
350 GetShortcutDataDir(shortcut_info), | 376 GetShortcutDataDir(shortcut_info), |
351 shortcut_info, | 377 shortcut_info, |
352 file_handlers_info, | 378 file_handlers_info, |
353 locations, | 379 locations, |
354 reason)); | 380 reason)); |
355 } | 381 } |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 | 452 |
427 #if defined(OS_LINUX) | 453 #if defined(OS_LINUX) |
428 std::string GetWMClassFromAppName(std::string app_name) { | 454 std::string GetWMClassFromAppName(std::string app_name) { |
429 base::i18n::ReplaceIllegalCharactersInPath(&app_name, '_'); | 455 base::i18n::ReplaceIllegalCharactersInPath(&app_name, '_'); |
430 base::TrimString(app_name, "_", &app_name); | 456 base::TrimString(app_name, "_", &app_name); |
431 return app_name; | 457 return app_name; |
432 } | 458 } |
433 #endif | 459 #endif |
434 | 460 |
435 } // namespace web_app | 461 } // namespace web_app |
OLD | NEW |