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

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

Issue 23068021: Remove PerBrowser launcher, reland step 1 of 2 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/browser_shortcut_launcher_item_controll er.h" 5 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll er.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "ash/launcher/launcher.h" 9 #include "ash/launcher/launcher.h"
10 #include "ash/shell.h" 10 #include "ash/shell.h"
(...skipping 18 matching lines...) Expand all
29 #include "ui/base/l10n/l10n_util.h" 29 #include "ui/base/l10n/l10n_util.h"
30 #include "ui/base/resource/resource_bundle.h" 30 #include "ui/base/resource/resource_bundle.h"
31 #include "ui/gfx/image/image.h" 31 #include "ui/gfx/image/image.h"
32 #include "ui/views/corewm/window_animations.h" 32 #include "ui/views/corewm/window_animations.h"
33 33
34 #if defined(OS_CHROMEOS) 34 #if defined(OS_CHROMEOS)
35 #include "chrome/browser/chromeos/login/default_pinned_apps_field_trial.h" 35 #include "chrome/browser/chromeos/login/default_pinned_apps_field_trial.h"
36 #endif 36 #endif
37 37
38 BrowserShortcutLauncherItemController::BrowserShortcutLauncherItemController( 38 BrowserShortcutLauncherItemController::BrowserShortcutLauncherItemController(
39 ChromeLauncherControllerPerApp* launcher_controller, 39 ChromeLauncherController* launcher_controller,
40 Profile* profile) 40 Profile* profile)
41 : LauncherItemController(TYPE_SHORTCUT, 41 : LauncherItemController(TYPE_SHORTCUT,
42 extension_misc::kChromeAppId, 42 extension_misc::kChromeAppId,
43 launcher_controller), 43 launcher_controller),
44 app_controller_(launcher_controller),
45 profile_(profile) { 44 profile_(profile) {
46 } 45 }
47 46
48 BrowserShortcutLauncherItemController:: 47 BrowserShortcutLauncherItemController::
49 ~BrowserShortcutLauncherItemController() { 48 ~BrowserShortcutLauncherItemController() {
50 } 49 }
51 50
52 string16 BrowserShortcutLauncherItemController::GetTitle() { 51 string16 BrowserShortcutLauncherItemController::GetTitle() {
53 return l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); 52 return l10n_util::GetStringUTF16(IDS_PRODUCT_NAME);
54 } 53 }
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 it != ash_browser_list->end(); ++it) { 150 it != ash_browser_list->end(); ++it) {
152 Browser* browser = *it; 151 Browser* browser = *it;
153 // Make sure that the browser was already shown and it has a proper window. 152 // Make sure that the browser was already shown and it has a proper window.
154 if (std::find(ash_browser_list->begin_last_active(), 153 if (std::find(ash_browser_list->begin_last_active(),
155 ash_browser_list->end_last_active(), 154 ash_browser_list->end_last_active(),
156 browser) == ash_browser_list->end_last_active() || 155 browser) == ash_browser_list->end_last_active() ||
157 !browser->window()) 156 !browser->window())
158 continue; 157 continue;
159 if (browser->is_type_tabbed()) 158 if (browser->is_type_tabbed())
160 found_tabbed_browser = true; 159 found_tabbed_browser = true;
161 else if (!app_controller_->IsBrowserRepresentedInBrowserList(browser)) 160 else if (!launcher_controller()->IsBrowserRepresentedInBrowserList(browser))
162 continue; 161 continue;
163 TabStripModel* tab_strip = browser->tab_strip_model(); 162 TabStripModel* tab_strip = browser->tab_strip_model();
164 if (tab_strip->active_index() == -1) 163 if (tab_strip->active_index() == -1)
165 continue; 164 continue;
166 if (!(event_flags & ui::EF_SHIFT_DOWN)) { 165 if (!(event_flags & ui::EF_SHIFT_DOWN)) {
167 content::WebContents* web_contents = 166 content::WebContents* web_contents =
168 tab_strip->GetWebContentsAt(tab_strip->active_index()); 167 tab_strip->GetWebContentsAt(tab_strip->active_index());
169 gfx::Image app_icon = GetBrowserListIcon(web_contents); 168 gfx::Image app_icon = GetBrowserListIcon(web_contents);
170 string16 title = GetBrowserListTitle(web_contents); 169 string16 title = GetBrowserListTitle(web_contents);
171 items.push_back(new ChromeLauncherAppMenuItemBrowser( 170 items.push_back(new ChromeLauncherAppMenuItemBrowser(
172 title, &app_icon, browser, items.size() == 1)); 171 title, &app_icon, browser, items.size() == 1));
173 } else { 172 } else {
174 for (int index = 0; index < tab_strip->count(); ++index) { 173 for (int index = 0; index < tab_strip->count(); ++index) {
175 content::WebContents* web_contents = 174 content::WebContents* web_contents =
176 tab_strip->GetWebContentsAt(index); 175 tab_strip->GetWebContentsAt(index);
177 gfx::Image app_icon = app_controller_->GetAppListIcon(web_contents); 176 gfx::Image app_icon =
178 string16 title = app_controller_->GetAppListTitle(web_contents); 177 launcher_controller()->GetAppListIcon(web_contents);
178 string16 title = launcher_controller()->GetAppListTitle(web_contents);
179 // Check if we need to insert a separator in front. 179 // Check if we need to insert a separator in front.
180 bool leading_separator = !index; 180 bool leading_separator = !index;
181 items.push_back(new ChromeLauncherAppMenuItemTab( 181 items.push_back(new ChromeLauncherAppMenuItemTab(
182 title, &app_icon, web_contents, leading_separator)); 182 title, &app_icon, web_contents, leading_separator));
183 } 183 }
184 } 184 }
185 } 185 }
186 // If only windowed applications are open, we return an empty list to 186 // If only windowed applications are open, we return an empty list to
187 // enforce the creation of a new browser. 187 // enforce the creation of a new browser.
188 if (!found_tabbed_browser) 188 if (!found_tabbed_browser)
(...skipping 27 matching lines...) Expand all
216 void BrowserShortcutLauncherItemController::ActivateOrAdvanceToNextBrowser() { 216 void BrowserShortcutLauncherItemController::ActivateOrAdvanceToNextBrowser() {
217 // Create a list of all suitable running browsers. 217 // Create a list of all suitable running browsers.
218 std::vector<Browser*> items; 218 std::vector<Browser*> items;
219 // We use the list in the order of how the browsers got created - not the LRU 219 // We use the list in the order of how the browsers got created - not the LRU
220 // order. 220 // order.
221 const BrowserList* ash_browser_list = 221 const BrowserList* ash_browser_list =
222 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH); 222 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH);
223 for (BrowserList::const_iterator it = 223 for (BrowserList::const_iterator it =
224 ash_browser_list->begin(); 224 ash_browser_list->begin();
225 it != ash_browser_list->end(); ++it) { 225 it != ash_browser_list->end(); ++it) {
226 if (app_controller_->IsBrowserRepresentedInBrowserList(*it)) 226 if (launcher_controller()->IsBrowserRepresentedInBrowserList(*it))
227 items.push_back(*it); 227 items.push_back(*it);
228 } 228 }
229 // If there are no suitable browsers we create a new one. 229 // If there are no suitable browsers we create a new one.
230 if (!items.size()) { 230 if (!items.size()) {
231 launcher_controller()->CreateNewWindow(); 231 launcher_controller()->CreateNewWindow();
232 return; 232 return;
233 } 233 }
234 Browser* browser = chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow()); 234 Browser* browser = chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow());
235 if (items.size() == 1) { 235 if (items.size() == 1) {
236 // If there is only one suitable browser, we can either activate it, or 236 // If there is only one suitable browser, we can either activate it, or
(...skipping 10 matching lines...) Expand all
247 // if it can be used. 247 // if it can be used.
248 std::vector<Browser*>::iterator i = 248 std::vector<Browser*>::iterator i =
249 std::find(items.begin(), items.end(), browser); 249 std::find(items.begin(), items.end(), browser);
250 if (i != items.end()) { 250 if (i != items.end()) {
251 browser = (++i == items.end()) ? items[0] : *i; 251 browser = (++i == items.end()) ? items[0] : *i;
252 } else { 252 } else {
253 browser = chrome::FindTabbedBrowser(profile_, 253 browser = chrome::FindTabbedBrowser(profile_,
254 true, 254 true,
255 chrome::HOST_DESKTOP_TYPE_ASH); 255 chrome::HOST_DESKTOP_TYPE_ASH);
256 if (!browser || 256 if (!browser ||
257 !app_controller_->IsBrowserRepresentedInBrowserList(browser)) 257 !launcher_controller()->IsBrowserRepresentedInBrowserList(browser))
258 browser = items[0]; 258 browser = items[0];
259 } 259 }
260 } 260 }
261 DCHECK(browser); 261 DCHECK(browser);
262 browser->window()->Show(); 262 browser->window()->Show();
263 browser->window()->Activate(); 263 browser->window()->Activate();
264 } 264 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698