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

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: Sync and rebase. 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 "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/extensions/extension_service.h" 10 #include "chrome/browser/extensions/extension_service.h"
11 #include "chrome/browser/extensions/extension_util.h" 11 #include "chrome/browser/extensions/extension_util.h"
12 #include "chrome/browser/extensions/launch_util.h" 12 #include "chrome/browser/extensions/launch_util.h"
13 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/profiles/profile_manager.h" 14 #include "chrome/browser/profiles/profile_manager.h"
15 #include "chrome/browser/ui/browser_finder.h" 15 #include "chrome/browser/ui/browser_finder.h"
(...skipping 10 matching lines...) Expand all
26 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" 26 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h"
27 #endif 27 #endif
28 28
29 namespace { 29 namespace {
30 30
31 const extensions::Extension* GetExtensionForTab(Profile* profile, 31 const extensions::Extension* GetExtensionForTab(Profile* profile,
32 content::WebContents* tab) { 32 content::WebContents* tab) {
33 ExtensionService* extension_service = 33 ExtensionService* extension_service =
34 extensions::ExtensionSystem::Get(profile)->extension_service(); 34 extensions::ExtensionSystem::Get(profile)->extension_service();
35 if (!extension_service || !extension_service->extensions_enabled()) 35 if (!extension_service || !extension_service->extensions_enabled())
36 return NULL; 36 return nullptr;
37 37
38 // Note: It is possible to come here after a tab got removed form the browser 38 // 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. 39 // before it gets destroyed, in which case there is no browser.
40 Browser* browser = chrome::FindBrowserWithWebContents(tab); 40 Browser* browser = chrome::FindBrowserWithWebContents(tab);
41 41
42 extensions::ExtensionRegistry* registry = 42 extensions::ExtensionRegistry* registry =
43 extensions::ExtensionRegistry::Get(profile); 43 extensions::ExtensionRegistry::Get(profile);
44 44
45 // Use the Browser's app name to determine the extension for app windows and 45 // Use the Browser's app name to determine the extension for app windows and
46 // use the tab's url for app tabs. 46 // use the tab's url for app tabs.
47 if (browser && browser->is_app()) { 47 if (browser && browser->is_app()) {
48 return registry->GetExtensionById( 48 return registry->GetExtensionById(
49 web_app::GetExtensionIdFromApplicationName(browser->app_name()), 49 web_app::GetExtensionIdFromApplicationName(browser->app_name()),
50 extensions::ExtensionRegistry::EVERYTHING); 50 extensions::ExtensionRegistry::EVERYTHING);
51 } 51 }
52 52
53 const GURL url = tab->GetURL(); 53 const GURL url = tab->GetURL();
54 const extensions::ExtensionSet& extensions = registry->enabled_extensions(); 54 const extensions::ExtensionSet& extensions = registry->enabled_extensions();
55 const extensions::Extension* extension = extensions.GetAppByURL(url); 55 const extensions::Extension* extension = extensions.GetAppByURL(url);
56 if (extension && !extensions::LaunchesInWindow(profile, extension)) 56 if (extension && !extensions::LaunchesInWindow(profile, extension))
57 return extension; 57 return extension;
58 58
59 // Bookmark app windows should match their launch url extension despite 59 // Bookmark app windows should match their launch url extension despite
60 // their web extents. 60 // their web extents.
61 if (extensions::util::IsNewBookmarkAppsEnabled()) { 61 if (extensions::util::IsNewBookmarkAppsEnabled()) {
62 for (extensions::ExtensionSet::const_iterator it = extensions.begin(); 62 for (const auto& i : extensions) {
63 it != extensions.end(); ++it) { 63 if (i.get()->from_bookmark() &&
64 if (it->get()->from_bookmark() && 64 extensions::AppLaunchInfo::GetLaunchWebURL(i.get()) == url &&
65 extensions::AppLaunchInfo::GetLaunchWebURL(it->get()) == url && 65 !extensions::LaunchesInWindow(profile, i.get())) {
66 !extensions::LaunchesInWindow(profile, it->get())) { 66 return i.get();
67 return it->get();
68 } 67 }
69 } 68 }
70 } 69 }
71 return NULL; 70 return nullptr;
72 } 71 }
73 72
74 const extensions::Extension* GetExtensionByID(Profile* profile, 73 const extensions::Extension* GetExtensionByID(Profile* profile,
75 const std::string& id) { 74 const std::string& id) {
76 return extensions::ExtensionRegistry::Get(profile)->GetExtensionById( 75 return extensions::ExtensionRegistry::Get(profile)->GetExtensionById(
77 id, extensions::ExtensionRegistry::EVERYTHING); 76 id, extensions::ExtensionRegistry::EVERYTHING);
78 } 77 }
79 78
80 } // namespace 79 } // namespace
81 80
82 LauncherAppTabHelper::LauncherAppTabHelper(Profile* profile) 81 LauncherControllerHelper::LauncherControllerHelper(Profile* profile)
83 : profile_(profile) { 82 : profile_(profile) {}
84 }
85 83
86 LauncherAppTabHelper::~LauncherAppTabHelper() { 84 LauncherControllerHelper::~LauncherControllerHelper() {}
87 }
88 85
89 std::string LauncherAppTabHelper::GetAppID(content::WebContents* tab) { 86 std::string LauncherControllerHelper::GetAppID(content::WebContents* tab) {
90 ProfileManager* profile_manager = g_browser_process->profile_manager(); 87 ProfileManager* profile_manager = g_browser_process->profile_manager();
91 if (profile_manager) { 88 if (profile_manager) {
92 const std::vector<Profile*> profile_list = 89 const std::vector<Profile*> profile_list =
93 profile_manager->GetLoadedProfiles(); 90 profile_manager->GetLoadedProfiles();
94 if (profile_list.size() > 0) { 91 if (!profile_list.empty()) {
95 for (std::vector<Profile*>::const_iterator it = profile_list.begin(); 92 for (const auto& i : profile_list) {
96 it != profile_list.end(); 93 const extensions::Extension* extension = GetExtensionForTab(i, tab);
97 ++it) {
98 const extensions::Extension* extension = GetExtensionForTab(*it, tab);
99 if (extension) 94 if (extension)
100 return extension->id(); 95 return extension->id();
101 } 96 }
102 return std::string(); 97 return std::string();
103 } 98 }
104 } 99 }
105 // If there is no profile manager we only use the known profile. 100 // If there is no profile manager we only use the known profile.
106 const extensions::Extension* extension = GetExtensionForTab(profile_, tab); 101 const extensions::Extension* extension = GetExtensionForTab(profile_, tab);
107 return extension ? extension->id() : std::string(); 102 return extension ? extension->id() : std::string();
108 } 103 }
109 104
110 bool LauncherAppTabHelper::IsValidIDForCurrentUser(const std::string& id) { 105 bool LauncherControllerHelper::IsValidIDForCurrentUser(const std::string& id) {
111 #if defined(OS_CHROMEOS) 106 #if defined(OS_CHROMEOS)
112 if (ArcAppListPrefs::Get(profile_)->IsRegistered(id)) 107 if (ArcAppListPrefs::Get(profile_)->IsRegistered(id))
113 return true; 108 return true;
114 #endif 109 #endif
115 return GetExtensionByID(profile_, id) != NULL; 110 return GetExtensionByID(profile_, id) != nullptr;
116 } 111 }
117 112
118 void LauncherAppTabHelper::SetCurrentUser(Profile* profile) { 113 void LauncherControllerHelper::SetCurrentUser(Profile* profile) {
119 profile_ = profile; 114 profile_ = profile;
120 } 115 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698