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 #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_util.h" | 23 #include "base/strings/string_util.h" |
24 #include "base/strings/sys_string_conversions.h" | 24 #include "base/strings/sys_string_conversions.h" |
25 #include "base/strings/utf_string_conversions.h" | 25 #include "base/strings/utf_string_conversions.h" |
26 #import "chrome/browser/mac/dock.h" | 26 #import "chrome/browser/mac/dock.h" |
| 27 #include "chrome/browser/browser_process.h" |
27 #include "chrome/browser/profiles/profile.h" | 28 #include "chrome/browser/profiles/profile.h" |
| 29 #include "chrome/browser/profiles/profile_manager.h" |
28 #include "chrome/browser/shell_integration.h" | 30 #include "chrome/browser/shell_integration.h" |
29 #include "chrome/common/chrome_constants.h" | 31 #include "chrome/common/chrome_constants.h" |
30 #include "chrome/common/chrome_paths.h" | 32 #include "chrome/common/chrome_paths.h" |
31 #include "chrome/common/chrome_switches.h" | 33 #include "chrome/common/chrome_switches.h" |
32 #include "chrome/common/chrome_version_info.h" | 34 #include "chrome/common/chrome_version_info.h" |
33 #import "chrome/common/mac/app_mode_common.h" | 35 #import "chrome/common/mac/app_mode_common.h" |
34 #include "content/public/browser/browser_thread.h" | 36 #include "content/public/browser/browser_thread.h" |
| 37 #include "extensions/browser/extension_registry.h" |
35 #include "extensions/common/extension.h" | 38 #include "extensions/common/extension.h" |
36 #include "grit/chrome_unscaled_resources.h" | 39 #include "grit/chrome_unscaled_resources.h" |
37 #include "grit/chromium_strings.h" | 40 #include "grit/chromium_strings.h" |
38 #include "grit/generated_resources.h" | 41 #include "grit/generated_resources.h" |
39 #import "skia/ext/skia_utils_mac.h" | 42 #import "skia/ext/skia_utils_mac.h" |
40 #include "third_party/skia/include/core/SkBitmap.h" | 43 #include "third_party/skia/include/core/SkBitmap.h" |
41 #include "third_party/skia/include/core/SkColor.h" | 44 #include "third_party/skia/include/core/SkColor.h" |
42 #include "ui/base/l10n/l10n_util.h" | 45 #include "ui/base/l10n/l10n_util.h" |
43 #import "ui/base/l10n/l10n_util_mac.h" | 46 #import "ui/base/l10n/l10n_util_mac.h" |
44 #include "ui/base/resource/resource_bundle.h" | 47 #include "ui/base/resource/resource_bundle.h" |
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 app_mode::kCFBundleTypeMIMETypesKey : mime_types, | 478 app_mode::kCFBundleTypeMIMETypesKey : mime_types, |
476 app_mode::kCFBundleTypeRoleKey : app_mode::kBundleTypeRoleViewer | 479 app_mode::kCFBundleTypeRoleKey : app_mode::kBundleTypeRoleViewer |
477 }; | 480 }; |
478 [document_types addObject:type_dictionary]; | 481 [document_types addObject:type_dictionary]; |
479 } | 482 } |
480 | 483 |
481 [plist setObject:document_types | 484 [plist setObject:document_types |
482 forKey:app_mode::kCFBundleDocumentTypesKey]; | 485 forKey:app_mode::kCFBundleDocumentTypesKey]; |
483 } | 486 } |
484 | 487 |
| 488 void UpdateShortcutsOnUIThread( |
| 489 const base::FilePath& profile_path, |
| 490 const std::string app_id) { |
| 491 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 492 Profile* profile = profile_manager->GetProfileByPath(profile_path); |
| 493 if (!profile || !profile_manager->IsValidProfile(profile)) |
| 494 return; |
| 495 |
| 496 extensions::ExtensionRegistry* registry = |
| 497 extensions::ExtensionRegistry::Get(profile); |
| 498 const extensions::Extension* extension = registry->GetExtensionById( |
| 499 app_id, extensions::ExtensionRegistry::EVERYTHING); |
| 500 if (!extension || !extension->is_platform_app()) |
| 501 return; |
| 502 |
| 503 web_app::UpdateAllShortcuts(base::string16(), profile, extension); |
| 504 } |
| 505 |
485 } // namespace | 506 } // namespace |
486 | 507 |
487 namespace web_app { | 508 namespace web_app { |
488 | 509 |
489 WebAppShortcutCreator::WebAppShortcutCreator( | 510 WebAppShortcutCreator::WebAppShortcutCreator( |
490 const base::FilePath& app_data_dir, | 511 const base::FilePath& app_data_dir, |
491 const ShortcutInfo& shortcut_info, | 512 const ShortcutInfo& shortcut_info, |
492 const extensions::FileHandlersInfo& file_handlers_info) | 513 const extensions::FileHandlersInfo& file_handlers_info) |
493 : app_data_dir_(app_data_dir), | 514 : app_data_dir_(app_data_dir), |
494 info_(shortcut_info), | 515 info_(shortcut_info), |
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
962 for (std::vector<base::FilePath>::const_iterator it = bundles.begin(); | 983 for (std::vector<base::FilePath>::const_iterator it = bundles.begin(); |
963 it != bundles.end(); ++it) { | 984 it != bundles.end(); ++it) { |
964 web_app::ShortcutInfo shortcut_info = | 985 web_app::ShortcutInfo shortcut_info = |
965 BuildShortcutInfoFromBundle(*it); | 986 BuildShortcutInfoFromBundle(*it); |
966 WebAppShortcutCreator shortcut_creator( | 987 WebAppShortcutCreator shortcut_creator( |
967 it->DirName(), shortcut_info, extensions::FileHandlersInfo()); | 988 it->DirName(), shortcut_info, extensions::FileHandlersInfo()); |
968 shortcut_creator.DeleteShortcuts(); | 989 shortcut_creator.DeleteShortcuts(); |
969 } | 990 } |
970 } | 991 } |
971 | 992 |
| 993 void UpdateShortcutsForAllAppsForProfile(const base::FilePath& profile_path, |
| 994 const std::set<std::string>& app_ids) { |
| 995 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); |
| 996 for (std::set<std::string>::const_iterator it = app_ids.begin(); |
| 997 it != app_ids.end(); |
| 998 ++it) { |
| 999 content::BrowserThread::PostTask( |
| 1000 content::BrowserThread::UI, |
| 1001 FROM_HERE, |
| 1002 base::Bind(&UpdateShortcutsOnUIThread, profile_path, *it)); |
| 1003 } |
| 1004 } |
| 1005 |
972 } // namespace internals | 1006 } // namespace internals |
973 | 1007 |
974 } // namespace web_app | 1008 } // namespace web_app |
975 | 1009 |
976 namespace chrome { | 1010 namespace chrome { |
977 | 1011 |
978 void ShowCreateChromeAppShortcutsDialog( | 1012 void ShowCreateChromeAppShortcutsDialog( |
979 gfx::NativeWindow /*parent_window*/, | 1013 gfx::NativeWindow /*parent_window*/, |
980 Profile* profile, | 1014 Profile* profile, |
981 const extensions::Extension* app, | 1015 const extensions::Extension* app, |
982 const base::Callback<void(bool)>& close_callback) { | 1016 const base::Callback<void(bool)>& close_callback) { |
983 web_app::UpdateShortcutInfoAndIconForApp( | 1017 web_app::UpdateShortcutInfoAndIconForApp( |
984 app, | 1018 app, |
985 profile, | 1019 profile, |
986 base::Bind(&web_app::CreateAppShortcutInfoLoaded, | 1020 base::Bind(&web_app::CreateAppShortcutInfoLoaded, |
987 profile, | 1021 profile, |
988 app, | 1022 app, |
989 close_callback)); | 1023 close_callback)); |
990 } | 1024 } |
991 | 1025 |
992 } // namespace chrome | 1026 } // namespace chrome |
OLD | NEW |