This source file includes following definitions.
- GetExtensionForTab
- GetExtensionByID
- GetAppID
- IsValidIDForCurrentUser
- SetCurrentUser
#include "chrome/browser/ui/ash/launcher/launcher_app_tab_helper.h"
#include <vector>
#include "base/command_line.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/web_applications/web_app.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/web_contents.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/common/extension.h"
namespace {
const extensions::Extension* GetExtensionForTab(Profile* profile,
content::WebContents* tab) {
ExtensionService* extension_service = profile->GetExtensionService();
if (!extension_service || !extension_service->extensions_enabled())
return NULL;
Browser* browser = chrome::FindBrowserWithWebContents(tab);
if (browser && browser->is_app()) {
return extension_service->GetInstalledExtension(
web_app::GetExtensionIdFromApplicationName(browser->app_name()));
}
const GURL url = tab->GetURL();
if (extension_service->IsInstalledApp(url))
return extension_service->GetInstalledApp(url);
if (CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableStreamlinedHostedApps)) {
const extensions::ExtensionSet& extensions =
extensions::ExtensionRegistry::Get(profile)->enabled_extensions();
for (extensions::ExtensionSet::const_iterator it = extensions.begin();
it != extensions.end(); ++it) {
if (it->get()->from_bookmark() &&
extensions::AppLaunchInfo::GetLaunchWebURL(it->get()) == url) {
return it->get();
}
}
}
return NULL;
}
const extensions::Extension* GetExtensionByID(Profile* profile,
const std::string& id) {
ExtensionService* extension_service = profile->GetExtensionService();
if (!extension_service || !extension_service->extensions_enabled())
return NULL;
return extension_service->GetInstalledExtension(id);
}
}
LauncherAppTabHelper::LauncherAppTabHelper(Profile* profile)
: profile_(profile) {
}
LauncherAppTabHelper::~LauncherAppTabHelper() {
}
std::string LauncherAppTabHelper::GetAppID(content::WebContents* tab) {
ProfileManager* profile_manager = g_browser_process->profile_manager();
if (profile_manager) {
const std::vector<Profile*> profile_list =
profile_manager->GetLoadedProfiles();
if (profile_list.size() > 0) {
for (std::vector<Profile*>::const_iterator it = profile_list.begin();
it != profile_list.end();
++it) {
const extensions::Extension* extension = GetExtensionForTab(*it, tab);
if (extension)
return extension->id();
}
return std::string();
}
}
const extensions::Extension* extension = GetExtensionForTab(profile_, tab);
return extension ? extension->id() : std::string();
}
bool LauncherAppTabHelper::IsValidIDForCurrentUser(const std::string& id) {
return GetExtensionByID(profile_, id) != NULL;
}
void LauncherAppTabHelper::SetCurrentUser(Profile* profile) {
profile_ = profile;
}