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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/ash/launcher/launcher_app_tab_helper.h"
9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/extensions/extension_service.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/profiles/profile_manager.h"
13 #include "chrome/browser/ui/browser_finder.h"
14 #include "content/public/browser/navigation_entry.h"
15 #include "content/public/browser/web_contents.h"
16 #include "extensions/common/extension.h"
20 const extensions::Extension
* GetExtensionForTab(Profile
* profile
,
21 content::WebContents
* tab
) {
22 ExtensionService
* extension_service
= profile
->GetExtensionService();
23 if (!extension_service
|| !extension_service
->extensions_enabled())
25 Browser
* browser
= chrome::FindBrowserWithWebContents(tab
);
27 GURL url
= tab
->GetURL();
28 if (browser
->is_app() && tab
->GetController().GetEntryCount())
29 url
= tab
->GetController().GetEntryAtIndex(0)->GetURL();
30 return extension_service
->GetInstalledApp(url
);
33 const extensions::Extension
* GetExtensionByID(Profile
* profile
,
34 const std::string
& id
) {
35 ExtensionService
* extension_service
= profile
->GetExtensionService();
36 if (!extension_service
|| !extension_service
->extensions_enabled())
38 return extension_service
->GetInstalledExtension(id
);
43 LauncherAppTabHelper::LauncherAppTabHelper(Profile
* profile
)
47 LauncherAppTabHelper::~LauncherAppTabHelper() {
50 std::string
LauncherAppTabHelper::GetAppID(content::WebContents
* tab
) {
51 ProfileManager
* profile_manager
= g_browser_process
->profile_manager();
52 if (profile_manager
) {
53 const std::vector
<Profile
*> profile_list
=
54 profile_manager
->GetLoadedProfiles();
55 if (profile_list
.size() > 0) {
56 for (std::vector
<Profile
*>::const_iterator it
= profile_list
.begin();
57 it
!= profile_list
.end();
59 const extensions::Extension
* extension
= GetExtensionForTab(*it
, tab
);
61 return extension
->id();
66 // If there is no profile manager we only use the known profile.
67 const extensions::Extension
* extension
= GetExtensionForTab(profile_
, tab
);
68 return extension
? extension
->id() : std::string();
71 bool LauncherAppTabHelper::IsValidIDForCurrentUser(const std::string
& id
) {
72 return GetExtensionByID(profile_
, id
) != NULL
;
75 void LauncherAppTabHelper::SetCurrentUser(Profile
* profile
) {