OLD | NEW |
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" |
11 #include "ash/wm/window_util.h" | 11 #include "ash/wm/window_util.h" |
12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h" | 13 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h" |
14 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_browser.h
" | 14 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_browser.h
" |
15 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_tab.h" | 15 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_tab.h" |
16 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.h" | 16 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
17 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
18 #include "chrome/browser/ui/browser_finder.h" | 18 #include "chrome/browser/ui/browser_finder.h" |
19 #include "chrome/browser/ui/browser_list.h" | 19 #include "chrome/browser/ui/browser_list.h" |
20 #include "chrome/browser/ui/browser_window.h" | 20 #include "chrome/browser/ui/browser_window.h" |
21 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 21 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
22 #include "chrome/common/extensions/extension_constants.h" | 22 #include "chrome/common/extensions/extension_constants.h" |
23 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
24 #include "grit/ash_resources.h" | 24 #include "grit/ash_resources.h" |
25 #include "grit/chromium_strings.h" | 25 #include "grit/chromium_strings.h" |
26 #include "grit/generated_resources.h" | 26 #include "grit/generated_resources.h" |
27 #include "ui/aura/window.h" | 27 #include "ui/aura/window.h" |
28 #include "ui/base/events/event.h" | 28 #include "ui/base/events/event.h" |
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 Loading... |
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 Loading... |
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 Loading... |
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 } |
OLD | NEW |