Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(213)

Side by Side Diff: chrome/browser/ui/ash/launcher/launcher_controller_helper.cc

Issue 1921403002: Pin apps from prefs on the mash shelf. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Only use ChromeMashShelfController with use_ash=1. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_controller_helper.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/extensions/extension_service.h" 11 #include "chrome/browser/extensions/extension_service.h"
11 #include "chrome/browser/extensions/extension_util.h" 12 #include "chrome/browser/extensions/extension_util.h"
12 #include "chrome/browser/extensions/launch_util.h" 13 #include "chrome/browser/extensions/launch_util.h"
13 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/profiles/profile_manager.h" 15 #include "chrome/browser/profiles/profile_manager.h"
15 #include "chrome/browser/ui/browser_finder.h" 16 #include "chrome/browser/ui/browser_finder.h"
16 #include "chrome/browser/web_applications/web_app.h" 17 #include "chrome/browser/web_applications/web_app.h"
17 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" 18 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
18 #include "content/public/browser/navigation_entry.h" 19 #include "content/public/browser/navigation_entry.h"
19 #include "content/public/browser/web_contents.h" 20 #include "content/public/browser/web_contents.h"
20 #include "extensions/browser/extension_registry.h" 21 #include "extensions/browser/extension_registry.h"
21 #include "extensions/browser/extension_system.h" 22 #include "extensions/browser/extension_system.h"
22 #include "extensions/common/extension.h" 23 #include "extensions/common/extension.h"
23 #include "extensions/common/extension_set.h" 24 #include "extensions/common/extension_set.h"
24 25
25 #if defined(OS_CHROMEOS) 26 #if defined(OS_CHROMEOS)
26 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" 27 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h"
27 #endif 28 #endif
28 29
29 namespace { 30 namespace {
30 31
31 const extensions::Extension* GetExtensionForTab(Profile* profile, 32 const extensions::Extension* GetExtensionForTab(Profile* profile,
32 content::WebContents* tab) { 33 content::WebContents* tab) {
33 ExtensionService* extension_service = 34 ExtensionService* extension_service =
34 extensions::ExtensionSystem::Get(profile)->extension_service(); 35 extensions::ExtensionSystem::Get(profile)->extension_service();
35 if (!extension_service || !extension_service->extensions_enabled()) 36 if (!extension_service || !extension_service->extensions_enabled())
36 return NULL; 37 return nullptr;
37 38
38 // Note: It is possible to come here after a tab got removed form the browser 39 // Note: It is possible to come here after a tab got removed form the browser
39 // before it gets destroyed, in which case there is no browser. 40 // before it gets destroyed, in which case there is no browser.
40 Browser* browser = chrome::FindBrowserWithWebContents(tab); 41 Browser* browser = chrome::FindBrowserWithWebContents(tab);
41 42
42 extensions::ExtensionRegistry* registry = 43 extensions::ExtensionRegistry* registry =
43 extensions::ExtensionRegistry::Get(profile); 44 extensions::ExtensionRegistry::Get(profile);
44 45
45 // Use the Browser's app name to determine the extension for app windows and 46 // Use the Browser's app name to determine the extension for app windows and
46 // use the tab's url for app tabs. 47 // use the tab's url for app tabs.
47 if (browser && browser->is_app()) { 48 if (browser && browser->is_app()) {
48 return registry->GetExtensionById( 49 return registry->GetExtensionById(
49 web_app::GetExtensionIdFromApplicationName(browser->app_name()), 50 web_app::GetExtensionIdFromApplicationName(browser->app_name()),
50 extensions::ExtensionRegistry::EVERYTHING); 51 extensions::ExtensionRegistry::EVERYTHING);
51 } 52 }
52 53
53 const GURL url = tab->GetURL(); 54 const GURL url = tab->GetURL();
54 const extensions::ExtensionSet& extensions = registry->enabled_extensions(); 55 const extensions::ExtensionSet& extensions = registry->enabled_extensions();
55 const extensions::Extension* extension = extensions.GetAppByURL(url); 56 const extensions::Extension* extension = extensions.GetAppByURL(url);
56 if (extension && !extensions::LaunchesInWindow(profile, extension)) 57 if (extension && !extensions::LaunchesInWindow(profile, extension))
57 return extension; 58 return extension;
58 59
59 // Bookmark app windows should match their launch url extension despite 60 // Bookmark app windows should match their launch url extension despite
60 // their web extents. 61 // their web extents.
61 if (extensions::util::IsNewBookmarkAppsEnabled()) { 62 if (extensions::util::IsNewBookmarkAppsEnabled()) {
62 for (extensions::ExtensionSet::const_iterator it = extensions.begin(); 63 for (const auto& i : extensions) {
63 it != extensions.end(); ++it) { 64 if (i.get()->from_bookmark() &&
64 if (it->get()->from_bookmark() && 65 extensions::AppLaunchInfo::GetLaunchWebURL(i.get()) == url &&
65 extensions::AppLaunchInfo::GetLaunchWebURL(it->get()) == url && 66 !extensions::LaunchesInWindow(profile, i.get())) {
66 !extensions::LaunchesInWindow(profile, it->get())) { 67 return i.get();
67 return it->get();
68 } 68 }
69 } 69 }
70 } 70 }
71 return NULL; 71 return nullptr;
72 } 72 }
73 73
74 const extensions::Extension* GetExtensionByID(Profile* profile, 74 const extensions::Extension* GetExtensionByID(Profile* profile,
75 const std::string& id) { 75 const std::string& id) {
76 return extensions::ExtensionRegistry::Get(profile)->GetExtensionById( 76 return extensions::ExtensionRegistry::Get(profile)->GetExtensionById(
77 id, extensions::ExtensionRegistry::EVERYTHING); 77 id, extensions::ExtensionRegistry::EVERYTHING);
78 } 78 }
79 79
80 } // namespace 80 } // namespace
81 81
82 LauncherAppTabHelper::LauncherAppTabHelper(Profile* profile) 82 LauncherControllerHelper::LauncherControllerHelper(Profile* profile)
83 : profile_(profile) { 83 : profile_(profile) {}
84
85 LauncherControllerHelper::~LauncherControllerHelper() {}
86
87 // static
88 base::string16 LauncherControllerHelper::GetAppTitle(
89 Profile* profile,
90 const std::string& app_id) {
91 base::string16 title;
92 if (app_id.empty())
93 return title;
94
95 #if defined(OS_CHROMEOS)
96 // Get title if the app is an Arc app.
97 ArcAppListPrefs* arc_prefs = ArcAppListPrefs::Get(profile);
98 DCHECK(arc_prefs);
99 if (arc_prefs->IsRegistered(app_id)) {
100 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info =
101 arc_prefs->GetApp(app_id);
102 DCHECK(app_info.get());
103 if (app_info)
104 title = base::UTF8ToUTF16(app_info->name);
105 return title;
106 }
107 #endif // defined(OS_CHROMEOS)
108
109 const extensions::Extension* extension =
110 extensions::ExtensionRegistry::Get(profile)->GetExtensionById(
111 app_id, extensions::ExtensionRegistry::EVERYTHING);
112 if (extension)
113 title = base::UTF8ToUTF16(extension->name());
114 return title;
84 } 115 }
85 116
86 LauncherAppTabHelper::~LauncherAppTabHelper() { 117 std::string LauncherControllerHelper::GetAppID(content::WebContents* tab) {
87 }
88
89 std::string LauncherAppTabHelper::GetAppID(content::WebContents* tab) {
90 ProfileManager* profile_manager = g_browser_process->profile_manager(); 118 ProfileManager* profile_manager = g_browser_process->profile_manager();
91 if (profile_manager) { 119 if (profile_manager) {
92 const std::vector<Profile*> profile_list = 120 const std::vector<Profile*> profile_list =
93 profile_manager->GetLoadedProfiles(); 121 profile_manager->GetLoadedProfiles();
94 if (profile_list.size() > 0) { 122 if (!profile_list.empty()) {
95 for (std::vector<Profile*>::const_iterator it = profile_list.begin(); 123 for (const auto& i : profile_list) {
96 it != profile_list.end(); 124 const extensions::Extension* extension = GetExtensionForTab(i, tab);
97 ++it) {
98 const extensions::Extension* extension = GetExtensionForTab(*it, tab);
99 if (extension) 125 if (extension)
100 return extension->id(); 126 return extension->id();
101 } 127 }
102 return std::string(); 128 return std::string();
103 } 129 }
104 } 130 }
105 // If there is no profile manager we only use the known profile. 131 // If there is no profile manager we only use the known profile.
106 const extensions::Extension* extension = GetExtensionForTab(profile_, tab); 132 const extensions::Extension* extension = GetExtensionForTab(profile_, tab);
107 return extension ? extension->id() : std::string(); 133 return extension ? extension->id() : std::string();
108 } 134 }
109 135
110 bool LauncherAppTabHelper::IsValidIDForCurrentUser(const std::string& id) { 136 bool LauncherControllerHelper::IsValidIDForCurrentUser(const std::string& id) {
111 #if defined(OS_CHROMEOS) 137 #if defined(OS_CHROMEOS)
112 if (ArcAppListPrefs::Get(profile_)->IsRegistered(id)) 138 if (ArcAppListPrefs::Get(profile_)->IsRegistered(id))
113 return true; 139 return true;
114 #endif 140 #endif
115 return GetExtensionByID(profile_, id) != NULL; 141 return GetExtensionByID(profile_, id) != nullptr;
116 } 142 }
117 143
118 void LauncherAppTabHelper::SetCurrentUser(Profile* profile) { 144 void LauncherControllerHelper::SetCurrentUser(Profile* profile) {
119 profile_ = profile; 145 profile_ = profile;
120 } 146 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/ash/launcher/launcher_controller_helper.h ('k') | chrome/browser/ui/ash/launcher/launcher_item_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698