Index: chrome/browser/web_applications/web_app.cc |
diff --git a/chrome/browser/web_applications/web_app.cc b/chrome/browser/web_applications/web_app.cc |
index 1d8866712809f1d9d5700ce829f7147cac7c5d69..f2a6a99e09ebac8b832e4f56524ab2c6f827cc8f 100644 |
--- a/chrome/browser/web_applications/web_app.cc |
+++ b/chrome/browser/web_applications/web_app.cc |
@@ -12,18 +12,25 @@ |
#include "base/strings/string_util.h" |
#include "base/strings/utf_string_conversions.h" |
#include "base/threading/thread.h" |
+#include "chrome/browser/browser_process.h" |
+#include "chrome/browser/extensions/extension_service.h" |
+#include "chrome/browser/extensions/extension_ui_util.h" |
#include "chrome/browser/extensions/image_loader.h" |
#include "chrome/browser/extensions/tab_helper.h" |
#include "chrome/browser/favicon/favicon_tab_helper.h" |
#include "chrome/browser/profiles/profile.h" |
+#include "chrome/browser/profiles/profile_manager.h" |
#include "chrome/common/chrome_constants.h" |
#include "chrome/common/chrome_version_info.h" |
#include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
#include "chrome/common/pref_names.h" |
#include "chrome/common/url_constants.h" |
#include "content/public/browser/browser_thread.h" |
+#include "extensions/browser/extension_registry.h" |
+#include "extensions/browser/extension_system.h" |
#include "extensions/common/constants.h" |
#include "extensions/common/extension.h" |
+#include "extensions/common/extension_set.h" |
#include "extensions/common/manifest_handlers/icons_handler.h" |
#include "grit/theme_resources.h" |
#include "skia/ext/image_operations.h" |
@@ -74,6 +81,13 @@ base::FilePath GetShortcutDataDir(const web_app::ShortcutInfo& shortcut_info) { |
shortcut_info.url); |
} |
+bool ShouldCreateShortcutFor(Profile* profile, |
+ const extensions::Extension* extension) { |
+ return extension->is_platform_app() && |
+ extension->location() != extensions::Manifest::COMPONENT && |
+ extensions::ui_util::ShouldDisplayInAppLauncher(extension, profile); |
+} |
+ |
void CreateShortcutsWithInfo( |
web_app::ShortcutCreationReason reason, |
const web_app::ShortcutLocations& locations, |
@@ -203,6 +217,25 @@ static const char* kCrxAppPrefix = "_crx_"; |
namespace internals { |
+void CallForProfileAndAppId( |
+ const base::FilePath& profile_path, |
+ const std::string app_id, |
+ const ShortcutOperationCallback& callback) { |
+ ProfileManager* profile_manager = g_browser_process->profile_manager(); |
+ Profile* profile = profile_manager->GetProfileByPath(profile_path); |
+ if (!profile || !profile_manager->IsValidProfile(profile)) |
+ return; |
+ |
+ extensions::ExtensionRegistry* registry = |
+ extensions::ExtensionRegistry::Get(profile); |
+ const extensions::Extension* extension = registry->GetExtensionById( |
+ app_id, extensions::ExtensionRegistry::ENABLED); |
calamity
2014/05/29 03:03:10
Shouldn't we be excluding disabled/terminated exte
jackhou1
2014/05/29 04:23:47
I take it you mean including. UpdateShortcutsForAl
|
+ if (!extension || !extension->is_platform_app()) |
+ return; |
+ |
+ callback.Run(profile, extension); |
+} |
+ |
base::FilePath GetSanitizedFileName(const base::string16& name) { |
#if defined(OS_WIN) |
base::string16 file_name = name; |
@@ -374,6 +407,9 @@ void CreateShortcuts(ShortcutCreationReason reason, |
const extensions::Extension* app) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ if (!ShouldCreateShortcutFor(profile, app)) |
+ return; |
+ |
GetInfoForApp(app, |
profile, |
base::Bind(&CreateShortcutsWithInfo, reason, locations)); |
@@ -401,6 +437,36 @@ void UpdateAllShortcuts(const base::string16& old_app_title, |
base::Bind(&UpdateAllShortcutsForShortcutInfo, old_app_title)); |
} |
+void UpdateShortcutsForAllApps(Profile* profile) { |
+ // Check if extension system/service are available. They might not be in |
+ // tests. |
+ extensions::ExtensionSystem* extension_system = |
+ extensions::ExtensionSystem::Get(profile); |
+ if (!extension_system) |
+ return; |
+ |
+ ExtensionServiceInterface* extension_service = |
+ extension_system->extension_service(); |
+ if (!extension_service) |
+ return; |
+ |
+ // Get a set of app ids. |
+ const extensions::ExtensionSet* apps = extension_service->extensions(); |
+ std::set<std::string> app_ids; |
+ for (extensions::ExtensionSet::const_iterator it = apps->begin(); |
+ it != apps->end(); ++it) { |
+ if (ShouldCreateShortcutFor(profile, it->get())) |
+ app_ids.insert((*it)->id()); |
+ } |
+ |
+ BrowserThread::PostTask( |
+ BrowserThread::FILE, |
tapted
2014/05/29 08:56:40
I couldn't see why this needed to be on the file t
|
+ FROM_HERE, |
+ base::Bind( |
+ &web_app::internals::UpdateShortcutsForAllAppsForProfile, |
+ profile->GetPath(), app_ids)); |
+} |
+ |
bool IsValidUrl(const GURL& url) { |
static const char* const kValidUrlSchemes[] = { |
content::kFileScheme, |