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/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
16 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" | 17 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
17 #include "content/public/browser/navigation_entry.h" | 18 #include "content/public/browser/navigation_entry.h" |
18 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
19 #include "extensions/browser/extension_registry.h" | 20 #include "extensions/browser/extension_registry.h" |
20 #include "extensions/common/extension.h" | 21 #include "extensions/common/extension.h" |
21 | 22 |
22 namespace { | 23 namespace { |
23 | 24 |
24 const extensions::Extension* GetExtensionForTab(Profile* profile, | 25 const extensions::Extension* GetExtensionForTab(Profile* profile, |
25 content::WebContents* tab) { | 26 content::WebContents* tab) { |
26 ExtensionService* extension_service = profile->GetExtensionService(); | 27 ExtensionService* extension_service = profile->GetExtensionService(); |
27 if (!extension_service || !extension_service->extensions_enabled()) | 28 if (!extension_service || !extension_service->extensions_enabled()) |
28 return NULL; | 29 return NULL; |
29 | 30 |
30 Browser* browser = chrome::FindBrowserWithWebContents(tab); | 31 Browser* browser = chrome::FindBrowserWithWebContents(tab); |
31 DCHECK(browser); | 32 DCHECK(browser); |
32 | 33 |
33 GURL url = tab->GetURL(); | 34 // Use the Browser's app name to determine the extension for app windows and |
35 // use the tab's url for app tabs. | |
34 if (browser->is_app()) { | 36 if (browser->is_app()) { |
35 // Only consider the original URL of an app window when determining its | 37 return extension_service->GetInstalledExtension( |
36 // associated extension. | 38 web_app::GetExtensionIdFromApplicationName(browser->app_name())); |
37 if (tab->GetController().GetEntryCount()) | 39 } |
38 url = tab->GetController().GetEntryAtIndex(0)->GetURL(); | |
39 | 40 |
40 // Bookmark app windows should match their launch url extension despite | 41 const GURL url = tab->GetURL(); |
41 // their web extents. | 42 if (extension_service->IsInstalledApp(url)) |
42 if (CommandLine::ForCurrentProcess()->HasSwitch( | 43 return extension_service->GetInstalledApp(url); |
43 switches::kEnableStreamlinedHostedApps)) { | 44 |
44 const extensions::ExtensionSet& extensions = | 45 // Bookmark app windows should match their launch url extension despite |
45 extensions::ExtensionRegistry::Get(profile)->enabled_extensions(); | 46 // their web extents. |
46 for (extensions::ExtensionSet::const_iterator it = extensions.begin(); | 47 if (CommandLine::ForCurrentProcess()->HasSwitch( |
47 it != extensions.end(); ++it) { | 48 switches::kEnableStreamlinedHostedApps)) { |
48 if (it->get()->from_bookmark() && | 49 const extensions::ExtensionSet& extensions = |
49 extensions::AppLaunchInfo::GetLaunchWebURL(it->get()) == url) { | 50 extensions::ExtensionRegistry::Get(profile)->enabled_extensions(); |
50 return it->get(); | 51 for (extensions::ExtensionSet::const_iterator it = extensions.begin(); |
51 } | 52 it != extensions.end(); ++it) { |
53 if (it->get()->from_bookmark() && | |
54 extensions::AppLaunchInfo::GetLaunchWebURL(it->get()) == url) { | |
55 return it->get(); | |
52 } | 56 } |
53 } | 57 } |
54 } | 58 } |
55 | 59 return NULL; |
Mr4D (OOO till 08-26)
2014/02/07 17:44:03
Same here. A tab might still be an "app".
calamity
2014/02/17 02:03:17
I just moved the app tab stuff up to line 43.
| |
56 return extension_service->GetInstalledApp(url); | |
57 } | 60 } |
58 | 61 |
59 const extensions::Extension* GetExtensionByID(Profile* profile, | 62 const extensions::Extension* GetExtensionByID(Profile* profile, |
60 const std::string& id) { | 63 const std::string& id) { |
61 ExtensionService* extension_service = profile->GetExtensionService(); | 64 ExtensionService* extension_service = profile->GetExtensionService(); |
62 if (!extension_service || !extension_service->extensions_enabled()) | 65 if (!extension_service || !extension_service->extensions_enabled()) |
63 return NULL; | 66 return NULL; |
64 return extension_service->GetInstalledExtension(id); | 67 return extension_service->GetInstalledExtension(id); |
65 } | 68 } |
66 | 69 |
(...skipping 27 matching lines...) Expand all Loading... | |
94 return extension ? extension->id() : std::string(); | 97 return extension ? extension->id() : std::string(); |
95 } | 98 } |
96 | 99 |
97 bool LauncherAppTabHelper::IsValidIDForCurrentUser(const std::string& id) { | 100 bool LauncherAppTabHelper::IsValidIDForCurrentUser(const std::string& id) { |
98 return GetExtensionByID(profile_, id) != NULL; | 101 return GetExtensionByID(profile_, id) != NULL; |
99 } | 102 } |
100 | 103 |
101 void LauncherAppTabHelper::SetCurrentUser(Profile* profile) { | 104 void LauncherAppTabHelper::SetCurrentUser(Profile* profile) { |
102 profile_ = profile; | 105 profile_ = profile; |
103 } | 106 } |
OLD | NEW |