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 #include "chrome/browser/ui/ash/launcher/launcher_app_tab_helper.h" | 5 #include "chrome/browser/ui/ash/launcher/launcher_app_tab_helper.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
11 #include "chrome/browser/extensions/extension_service.h" | 11 #include "chrome/browser/extensions/extension_service.h" |
12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/profiles/profile_manager.h" | 13 #include "chrome/browser/profiles/profile_manager.h" |
14 #include "chrome/browser/ui/browser_finder.h" | 14 #include "chrome/browser/ui/browser_finder.h" |
15 #include "chrome/browser/web_applications/web_app.h" | 15 #include "chrome/browser/web_applications/web_app.h" |
16 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
17 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" | 17 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
18 #include "content/public/browser/navigation_entry.h" | 18 #include "content/public/browser/navigation_entry.h" |
19 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
20 #include "extensions/browser/extension_registry.h" | 20 #include "extensions/browser/extension_registry.h" |
| 21 #include "extensions/browser/extension_system.h" |
21 #include "extensions/common/extension.h" | 22 #include "extensions/common/extension.h" |
| 23 #include "extensions/common/extension_set.h" |
22 | 24 |
23 namespace { | 25 namespace { |
24 | 26 |
25 const extensions::Extension* GetExtensionForTab(Profile* profile, | 27 const extensions::Extension* GetExtensionForTab(Profile* profile, |
26 content::WebContents* tab) { | 28 content::WebContents* tab) { |
27 ExtensionService* extension_service = profile->GetExtensionService(); | 29 ExtensionService* extension_service = |
| 30 extensions::ExtensionSystem::Get(profile)->extension_service(); |
28 if (!extension_service || !extension_service->extensions_enabled()) | 31 if (!extension_service || !extension_service->extensions_enabled()) |
29 return NULL; | 32 return NULL; |
30 | 33 |
31 // Note: It is possible to come here after a tab got removed form the browser | 34 // Note: It is possible to come here after a tab got removed form the browser |
32 // before it gets destroyed, in which case there is no browser. | 35 // before it gets destroyed, in which case there is no browser. |
33 Browser* browser = chrome::FindBrowserWithWebContents(tab); | 36 Browser* browser = chrome::FindBrowserWithWebContents(tab); |
34 | 37 |
| 38 extensions::ExtensionRegistry* registry = |
| 39 extensions::ExtensionRegistry::Get(profile); |
| 40 |
35 // Use the Browser's app name to determine the extension for app windows and | 41 // Use the Browser's app name to determine the extension for app windows and |
36 // use the tab's url for app tabs. | 42 // use the tab's url for app tabs. |
37 if (browser && browser->is_app()) { | 43 if (browser && browser->is_app()) { |
38 return extension_service->GetInstalledExtension( | 44 return registry->GetExtensionById( |
39 web_app::GetExtensionIdFromApplicationName(browser->app_name())); | 45 web_app::GetExtensionIdFromApplicationName(browser->app_name()), |
| 46 extensions::ExtensionRegistry::EVERYTHING); |
40 } | 47 } |
41 | 48 |
42 const GURL url = tab->GetURL(); | 49 const GURL url = tab->GetURL(); |
43 if (extension_service->IsInstalledApp(url)) | 50 const extensions::ExtensionSet& extensions = registry->enabled_extensions(); |
44 return extension_service->GetInstalledApp(url); | 51 const extensions::Extension* extension = extensions.GetAppByURL(url); |
| 52 if (extension) |
| 53 return extension; |
45 | 54 |
46 // Bookmark app windows should match their launch url extension despite | 55 // Bookmark app windows should match their launch url extension despite |
47 // their web extents. | 56 // their web extents. |
48 if (CommandLine::ForCurrentProcess()->HasSwitch( | 57 if (CommandLine::ForCurrentProcess()->HasSwitch( |
49 switches::kEnableStreamlinedHostedApps)) { | 58 switches::kEnableStreamlinedHostedApps)) { |
50 const extensions::ExtensionSet& extensions = | |
51 extensions::ExtensionRegistry::Get(profile)->enabled_extensions(); | |
52 for (extensions::ExtensionSet::const_iterator it = extensions.begin(); | 59 for (extensions::ExtensionSet::const_iterator it = extensions.begin(); |
53 it != extensions.end(); ++it) { | 60 it != extensions.end(); ++it) { |
54 if (it->get()->from_bookmark() && | 61 if (it->get()->from_bookmark() && |
55 extensions::AppLaunchInfo::GetLaunchWebURL(it->get()) == url) { | 62 extensions::AppLaunchInfo::GetLaunchWebURL(it->get()) == url) { |
56 return it->get(); | 63 return it->get(); |
57 } | 64 } |
58 } | 65 } |
59 } | 66 } |
60 return NULL; | 67 return NULL; |
61 } | 68 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 return extension ? extension->id() : std::string(); | 105 return extension ? extension->id() : std::string(); |
99 } | 106 } |
100 | 107 |
101 bool LauncherAppTabHelper::IsValidIDForCurrentUser(const std::string& id) { | 108 bool LauncherAppTabHelper::IsValidIDForCurrentUser(const std::string& id) { |
102 return GetExtensionByID(profile_, id) != NULL; | 109 return GetExtensionByID(profile_, id) != NULL; |
103 } | 110 } |
104 | 111 |
105 void LauncherAppTabHelper::SetCurrentUser(Profile* profile) { | 112 void LauncherAppTabHelper::SetCurrentUser(Profile* profile) { |
106 profile_ = profile; | 113 profile_ = profile; |
107 } | 114 } |
OLD | NEW |