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 02c39bb82f2897601d3c259ea8701392e4d98a09..bdc1620844995a61e2f595fb95f66e2334d1d1cb 100644 |
--- a/chrome/browser/web_applications/web_app.cc |
+++ b/chrome/browser/web_applications/web_app.cc |
@@ -12,18 +12,24 @@ |
#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/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" |
@@ -68,6 +74,12 @@ bool IconPrecedes(const WebApplicationInfo::IconInfo& left, |
} |
#endif |
+bool ShouldCreateShortcutFor(const extensions::Extension* extension) { |
+ return extension->is_platform_app() && |
+ extension->location() != extensions::Manifest::COMPONENT && |
+ extension->ShouldDisplayInAppLauncher(); |
+} |
+ |
bool CreateShortcutsWithInfoOnFileThread( |
web_app::ShortcutCreationReason reason, |
const web_app::ShortcutLocations& locations, |
@@ -232,6 +244,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); |
+ 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; |
@@ -403,6 +434,9 @@ void CreateShortcuts(ShortcutCreationReason reason, |
const extensions::Extension* app) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ if (!ShouldCreateShortcutFor(app)) |
+ return; |
+ |
GetInfoForApp(app, |
profile, |
base::Bind(&CreateShortcutsWithInfo, reason, locations)); |
@@ -428,6 +462,32 @@ 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; |
+ ExtensionServiceInterface* extension_service; |
+ if (!(extension_system = extensions::ExtensionSystem::Get(profile)) || |
Matt Giuca
2014/05/23 07:01:57
Uh, != ?
jackhou1
2014/05/26 07:57:37
Get() and extension_service() both can return NULL
Matt Giuca
2014/05/26 08:07:36
Ohh.. wow, I totally didn't see that it was = inst
jackhou1
2014/05/27 01:03:57
Ok, changed to something simpler.
|
+ !(extension_service = extension_system->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(it->get())) |
+ app_ids.insert((*it)->id()); |
+ } |
+ |
+ BrowserThread::PostTask( |
+ BrowserThread::FILE, |
+ FROM_HERE, |
+ base::Bind( |
+ &web_app::internals::UpdateShortcutsForAllAppsForProfile, |
+ profile->GetPath(), app_ids)); |
+} |
+ |
bool IsValidUrl(const GURL& url) { |
static const char* const kValidUrlSchemes[] = { |
content::kFileScheme, |